1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.quicksearchbox;
17 
18 import android.content.Context;
19 import android.content.Intent;
20 import android.net.Uri;
21 import android.view.Menu;
22 import android.view.MenuInflater;
23 import android.view.MenuItem;
24 
25 /**
26  * Handles app help.
27  */
28 public class Help {
29 
30     private final Context mContext;
31     private final Config mConfig;
32 
Help(Context context, Config config)33     public Help(Context context, Config config) {
34         mContext = context;
35         mConfig = config;
36     }
37 
addHelpMenuItem(Menu menu, String activityName)38     public void addHelpMenuItem(Menu menu, String activityName) {
39         addHelpMenuItem(menu, activityName, false);
40     }
41 
addHelpMenuItem(Menu menu, String activityName, boolean showAsAction)42     public void addHelpMenuItem(Menu menu, String activityName, boolean showAsAction) {
43         Intent helpIntent = getHelpIntent(activityName);
44         if (helpIntent != null) {
45             MenuInflater inflater = new MenuInflater(mContext);
46             inflater.inflate(R.menu.help, menu);
47             MenuItem item = menu.findItem(R.id.menu_help);
48             item.setIntent(helpIntent);
49             if (showAsAction) {
50                 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
51             }
52         }
53     }
54 
getHelpIntent(String activityName)55     private Intent getHelpIntent(String activityName) {
56         Uri helpUrl = mConfig.getHelpUrl(activityName);
57         if (helpUrl == null) return null;
58         return new Intent(Intent.ACTION_VIEW, helpUrl);
59     }
60 
61 }
62