summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorBrian Attwell <brianattwell@google.com>2014-05-15 21:55:02 +0000
committerBrian Attwell <brianattwell@google.com>2014-05-15 21:55:29 +0000
commit8bb3d1ee5bc37f31051638c1e1303fd829662087 (patch)
tree8f5a269110d0cd70e4050ddc35962dea6a8486f3 /src/com
parentf49a823175cd1201e30410977f33992749de0bb6 (diff)
downloadpackages_apps_Contacts-8bb3d1ee5bc37f31051638c1e1303fd829662087.tar.gz
packages_apps_Contacts-8bb3d1ee5bc37f31051638c1e1303fd829662087.tar.bz2
packages_apps_Contacts-8bb3d1ee5bc37f31051638c1e1303fd829662087.zip
Revert "Remove "Help" action from Contacts app"
I committed the previous CL thinking it was a different CL. This reverts commit f49a823175cd1201e30410977f33992749de0bb6. Change-Id: I33c24687b1fba1287b944e607cd2b284fef97bad
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/contacts/activities/PeopleActivity.java5
-rw-r--r--src/com/android/contacts/editor/ContactEditorFragment.java15
-rw-r--r--src/com/android/contacts/util/HelpUtils.java141
3 files changed, 160 insertions, 1 deletions
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index c7c188ce5..a1699bf75 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -88,7 +88,7 @@ import com.android.contacts.common.util.AccountFilterUtil;
import com.android.contacts.util.AccountPromptUtils;
import com.android.contacts.common.util.Constants;
import com.android.contacts.util.DialogManager;
-import com.android.contacts.util.DialogManager;
+import com.android.contacts.util.HelpUtils;
import com.android.contacts.util.PhoneCapabilityTester;
import com.android.contacts.common.util.UriUtils;
import com.android.contacts.widget.TransitionAnimationView;
@@ -1429,6 +1429,7 @@ public class PeopleActivity extends ContactsActivity
MenuItem addGroupMenu = menu.findItem(R.id.menu_add_group);
final MenuItem clearFrequentsMenu = menu.findItem(R.id.menu_clear_frequents);
+ final MenuItem helpMenu = menu.findItem(R.id.menu_help);
final boolean isSearchMode = mActionBarAdapter.isSearchMode();
if (isSearchMode) {
@@ -1436,6 +1437,7 @@ public class PeopleActivity extends ContactsActivity
addGroupMenu.setVisible(false);
contactsFilterMenu.setVisible(false);
clearFrequentsMenu.setVisible(false);
+ helpMenu.setVisible(false);
} else {
switch (mActionBarAdapter.getCurrentTab()) {
case TabState.FAVORITES:
@@ -1462,6 +1464,7 @@ public class PeopleActivity extends ContactsActivity
clearFrequentsMenu.setVisible(false);
break;
}
+ HelpUtils.prepareHelpMenuItem(this, helpMenu, R.string.help_url_people_main);
}
final boolean showMiscOptions = !isSearchMode;
makeMenuItemVisible(menu, R.id.menu_search, showMiscOptions);
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 783e8ef71..40b5553ed 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -85,10 +85,12 @@ import com.android.contacts.common.model.RawContactDelta;
import com.android.contacts.common.model.RawContactDeltaList;
import com.android.contacts.common.model.RawContactModifier;
import com.android.contacts.util.ContactPhotoUtils;
+import com.android.contacts.util.HelpUtils;
import com.android.contacts.util.UiClosables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
@@ -1016,6 +1018,7 @@ public class ContactEditorFragment extends Fragment implements
final MenuItem doneMenu = menu.findItem(R.id.menu_done);
final MenuItem splitMenu = menu.findItem(R.id.menu_split);
final MenuItem joinMenu = menu.findItem(R.id.menu_join);
+ final MenuItem helpMenu = menu.findItem(R.id.menu_help);
final MenuItem discardMenu = menu.findItem(R.id.menu_discard);
// Set visibility of menus
@@ -1031,6 +1034,18 @@ public class ContactEditorFragment extends Fragment implements
discardMenu.setVisible(mState != null &&
mState.getFirstWritableRawContact(mContext) != null);
+ // help menu depending on whether this is inserting or editing
+ if (Intent.ACTION_INSERT.equals(mAction)) {
+ // inserting
+ HelpUtils.prepareHelpMenuItem(mContext, helpMenu, R.string.help_url_people_add);
+ } else if (Intent.ACTION_EDIT.equals(mAction)) {
+ // editing
+ HelpUtils.prepareHelpMenuItem(mContext, helpMenu, R.string.help_url_people_edit);
+ } else {
+ // something else, so don't show the help menu
+ helpMenu.setVisible(false);
+ }
+
int size = menu.size();
for (int i = 0; i < size; i++) {
menu.getItem(i).setEnabled(mEnabled);
diff --git a/src/com/android/contacts/util/HelpUtils.java b/src/com/android/contacts/util/HelpUtils.java
new file mode 100644
index 000000000..814e3abae
--- /dev/null
+++ b/src/com/android/contacts/util/HelpUtils.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.util;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.MenuItem;
+
+import java.util.Locale;
+
+/**
+ * Functions to easily prepare contextual help menu option items with an intent that opens up the
+ * browser to a particular URL, while taking into account the preferred language and app version.
+ */
+public class HelpUtils {
+ private final static String TAG = HelpUtils.class.getName();
+
+ /**
+ * Help URL query parameter key for the preferred language.
+ */
+ private final static String PARAM_LANGUAGE_CODE = "hl";
+
+ /**
+ * Help URL query parameter key for the app version.
+ */
+ private final static String PARAM_VERSION = "version";
+
+ /**
+ * Cached version code to prevent repeated calls to the package manager.
+ */
+ private static String sCachedVersionCode = null;
+
+ /** Static helper that is not instantiable*/
+ private HelpUtils() { }
+
+ /**
+ * Prepares the help menu item by doing the following.
+ * - If the string corresponding to the helpUrlResourceId is empty or null, then the help menu
+ * item is made invisible.
+ * - Otherwise, this makes the help menu item visible and sets the intent for the help menu
+ * item to view the URL.
+ *
+ * @return returns whether the help menu item has been made visible.
+ */
+ public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem,
+ int helpUrlResourceId) {
+ String helpUrlString = context.getResources().getString(helpUrlResourceId);
+ return prepareHelpMenuItem(context, helpMenuItem, helpUrlString);
+ }
+
+ /**
+ * Prepares the help menu item by doing the following.
+ * - If the helpUrlString is empty or null, the help menu item is made invisible.
+ * - Otherwise, this makes the help menu item visible and sets the intent for the help menu
+ * item to view the URL.
+ *
+ * @return returns whether the help menu item has been made visible.
+ */
+ public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem,
+ String helpUrlString) {
+ if (TextUtils.isEmpty(helpUrlString)) {
+ // The help url string is empty or null, so set the help menu item to be invisible.
+ helpMenuItem.setVisible(false);
+
+ // return that the help menu item is not visible (i.e. false)
+ return false;
+ } else {
+ // The help url string exists, so first add in some extra query parameters.
+ final Uri fullUri = uriWithAddedParameters(context, Uri.parse(helpUrlString));
+
+ // Then, create an intent that will be fired when the user
+ // selects this help menu item.
+ Intent intent = new Intent(Intent.ACTION_VIEW, fullUri);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+
+ // Set the intent to the help menu item, show the help menu item in the overflow
+ // menu, and make it visible.
+ helpMenuItem.setIntent(intent);
+ helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ helpMenuItem.setVisible(true);
+
+ // return that the help menu item is visible (i.e., true)
+ return true;
+ }
+ }
+
+ /**
+ * Adds two query parameters into the Uri, namely the language code and the version code
+ * of the app's package as gotten via the context.
+ * @return the uri with added query parameters
+ */
+ private static Uri uriWithAddedParameters(Context context, Uri baseUri) {
+ Uri.Builder builder = baseUri.buildUpon();
+
+ // Add in the preferred language
+ builder.appendQueryParameter(PARAM_LANGUAGE_CODE, Locale.getDefault().toString());
+
+ // Add in the package version code
+ if (sCachedVersionCode == null) {
+ // There is no cached version code, so try to get it from the package manager.
+ try {
+ // cache the version code
+ PackageInfo info = context.getPackageManager().getPackageInfo(
+ context.getPackageName(), 0);
+ sCachedVersionCode = Integer.toString(info.versionCode);
+
+ // append the version code to the uri
+ builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode);
+ } catch (NameNotFoundException e) {
+ // Cannot find the package name, so don't add in the version parameter
+ // This shouldn't happen.
+ Log.wtf(TAG, "Invalid package name for context", e);
+ }
+ } else {
+ builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode);
+ }
+
+ // Build the full uri and return it
+ return builder.build();
+ }
+}