Add shortcuts for email/ gmail
Change-Id: Id040760a5fa27d85f535f28a293df1a7ad98582a
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6973c41..675099d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -575,4 +575,8 @@
<string name="retry">Retry</string>
<!-- Button at bottom of conversation list screen if the folder for which contents are being shown supports loading more on demand [CHAR LIMIT=20]-->
<string name="load_more">Load more</string>
+
+ <!-- Shortcut strings -->
+ <!-- Title for shortcut naming dialog [CHAR LIMIT=100]-->
+ <string name="shortcut_name_title">Name folder shortcut</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 47e6c01..ba00156 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -391,4 +391,5 @@
<item name="android:actionDropDownStyle">@style/PlainSpinnerDropdown</item>
<item name="android:listViewWhiteStyle">@android:style/Widget.Holo.Light.ListView</item>
</style>
+
</resources>
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 1c1e3e7..0bb8ba9 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -785,13 +785,24 @@
mActionBarView.setAccount(mAccount);
restartOptionalLoader(LOADER_ACCOUNT_SETTINGS, null /* args */);
mActivity.invalidateOptionsMenu();
+ } else if (intent.hasExtra(Utils.EXTRA_ACCOUNT_STRING)) {
+ mAccount = Account.newinstance(intent
+ .getStringExtra(Utils.EXTRA_ACCOUNT_STRING));
+ mActionBarView.setAccount(mAccount);
+ restartOptionalLoader(LOADER_ACCOUNT_SETTINGS, null /* args */);
+ mActivity.invalidateOptionsMenu();
}
+
if (intent.hasExtra(Utils.EXTRA_FOLDER)) {
// Open the folder.
LogUtils.d(LOG_TAG, "SHOW THE FOLDER at %s",
intent.getParcelableExtra(Utils.EXTRA_FOLDER));
onFolderChanged((Folder) intent.getParcelableExtra(Utils.EXTRA_FOLDER));
+ } else if (intent.hasExtra(Utils.EXTRA_FOLDER_STRING)) {
+ // Open the folder.
+ onFolderChanged(new Folder(intent.getStringExtra(Utils.EXTRA_FOLDER_STRING)));
}
+
if (intent.hasExtra(Utils.EXTRA_CONVERSATION)) {
// Open the conversation.
LogUtils.d(LOG_TAG, "SHOW THE CONVERSATION at %s",
@@ -805,8 +816,8 @@
final String query = intent.getStringExtra(SearchManager.QUERY);
final String AUTHORITY = mContext.getPackageName()
+ SuggestionsProvider.AUTHORITY_TRAILING;
- SearchRecentSuggestions suggestions = new SearchRecentSuggestions(
- mContext, AUTHORITY, SuggestionsProvider.MODE);
+ SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mContext,
+ AUTHORITY, SuggestionsProvider.MODE);
suggestions.saveRecentQuery(query, null);
mViewMode.enterSearchResultsListMode();
diff --git a/src/com/android/mail/ui/CreateShortcutActivity.java b/src/com/android/mail/ui/CreateShortcutActivity.java
new file mode 100644
index 0000000..dc5d4d7
--- /dev/null
+++ b/src/com/android/mail/ui/CreateShortcutActivity.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2012 Google Inc.
+ * Licensed to 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.mail.ui;
+
+import com.android.mail.providers.Account;
+import com.android.mail.utils.AccountUtils;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class CreateShortcutActivity extends Activity {
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ Account[] cachedAccounts = AccountUtils.getSyncingAccounts(this);
+ Intent intent = getIntent();
+ if (cachedAccounts != null && cachedAccounts.length == 1) {
+ intent.setClass(this, FolderSelectionActivity.class);
+ intent.setFlags(
+ Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
+ intent.putExtra(FolderSelectionActivity.EXTRA_ACCOUNT_SHORTCUT, cachedAccounts[0]);
+ } else {
+ intent.setClass(this, MailboxSelectionActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ }
+ startActivity(intent);
+ finish();
+ }
+}
diff --git a/src/com/android/mail/ui/FolderSelectionActivity.java b/src/com/android/mail/ui/FolderSelectionActivity.java
index 575712f..bdb956d 100644
--- a/src/com/android/mail/ui/FolderSelectionActivity.java
+++ b/src/com/android/mail/ui/FolderSelectionActivity.java
@@ -173,7 +173,8 @@
* account, calculate the human readable name of the folder and
* use it as the shortcut name, etc...
*/
- final Intent clickIntent = Utils.createViewFolderIntent(mSelectedFolder, mAccount);
+ final Intent clickIntent = Utils.createViewFolderIntent(mSelectedFolder, mAccount,
+ true);
resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, clickIntent);
resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this,
diff --git a/src/com/android/mail/utils/Utils.java b/src/com/android/mail/utils/Utils.java
index 87cfa34..a57b2f2 100644
--- a/src/com/android/mail/utils/Utils.java
+++ b/src/com/android/mail/utils/Utils.java
@@ -72,9 +72,11 @@
public static String[] sSenderFragments = new String[8];
public static final String EXTRA_ACCOUNT = "account";
+ public static final String EXTRA_ACCOUNT_STRING = "accountString";
public static final String EXTRA_COMPOSE_URI = "composeUri";
public static final String EXTRA_CONVERSATION = "conversationUri";
public static final String EXTRA_FOLDER = "folder";
+ public static final String EXTRA_FOLDER_STRING = "folderString";
/*
* Notifies that changes happened. Certain UI components, e.g., widgets, can
* register for this {@link Intent} and update accordingly. However, this
@@ -586,16 +588,25 @@
/**
* Create an intent to open a folder.
+ *
* @param folder Folder to open.
* @param account
+ * @param pendingIntent If this will be used as a pending intent we need to
+ * send strings not parcelables.
* @return
*/
- public static Intent createViewFolderIntent(Folder folder, Account account) {
+ public static Intent createViewFolderIntent(Folder folder, Account account,
+ boolean pendingIntent) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setDataAndType(folder.uri, account.mimeType);
- intent.putExtra(Utils.EXTRA_ACCOUNT, account);
- intent.putExtra(Utils.EXTRA_FOLDER, folder);
+ if (pendingIntent) {
+ intent.putExtra(Utils.EXTRA_ACCOUNT_STRING, account.serialize());
+ intent.putExtra(Utils.EXTRA_FOLDER_STRING, folder.serialize());
+ } else {
+ intent.putExtra(Utils.EXTRA_ACCOUNT, account);
+ intent.putExtra(Utils.EXTRA_FOLDER, folder);
+ }
return intent;
}
diff --git a/src/com/android/mail/widget/BaseWidgetProvider.java b/src/com/android/mail/widget/BaseWidgetProvider.java
index bb060a0..1704c6e 100644
--- a/src/com/android/mail/widget/BaseWidgetProvider.java
+++ b/src/com/android/mail/widget/BaseWidgetProvider.java
@@ -315,7 +315,7 @@
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setRemoteAdapter(R.id.conversation_list, intent);
// Open mail app when click on header
- final Intent mailIntent = Utils.createViewFolderIntent(folder, account);
+ final Intent mailIntent = Utils.createViewFolderIntent(folder, account, false);
clickIntent = PendingIntent.getActivity(context, 0, mailIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent);
diff --git a/src/com/android/mail/widget/WidgetService.java b/src/com/android/mail/widget/WidgetService.java
index 81d542a..ec1b82a 100644
--- a/src/com/android/mail/widget/WidgetService.java
+++ b/src/com/android/mail/widget/WidgetService.java
@@ -221,7 +221,7 @@
view.setTextViewText(
R.id.loading_text, mContext.getText(R.string.view_more_conversations));
view.setOnClickFillInIntent(R.id.widget_loading,
- Utils.createViewFolderIntent(mFolder, mAccount));
+ Utils.createViewFolderIntent(mFolder, mAccount, false));
return view;
}