Help.java revision 71f9f8ccd3c12d7d48e2fee4c55cd57e1970b797
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 */
16package com.android.quicksearchbox;
17
18import android.content.Context;
19import android.content.Intent;
20import android.net.Uri;
21import android.view.Menu;
22import android.view.MenuInflater;
23import android.view.MenuItem;
24
25/**
26 * Handles app help.
27 */
28public class Help {
29
30    private final Context mContext;
31    private final Config mConfig;
32
33    public Help(Context context, Config config) {
34        mContext = context;
35        mConfig = config;
36    }
37
38    public void addHelpMenuItem(Menu menu, String activityName) {
39        Intent helpIntent = getHelpIntent(activityName);
40        if (helpIntent != null) {
41            MenuInflater inflater = new MenuInflater(mContext);
42            inflater.inflate(R.menu.help, menu);
43            MenuItem item = menu.findItem(R.id.menu_help);
44            item.setIntent(helpIntent);
45        }
46    }
47
48    private Intent getHelpIntent(String activityName) {
49        Uri helpUrl = mConfig.getHelpUrl(activityName);
50        if (helpUrl == null) return null;
51        return new Intent(Intent.ACTION_VIEW, helpUrl);
52    }
53
54}
55