diff options
author | David Braun <dabraun@google.com> | 2013-10-01 23:00:37 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-10-01 23:00:37 +0000 |
commit | 9499fc6f9a922b69dd1478fdd63203499a8ec203 (patch) | |
tree | 4f322f582ae18345c1138d7edcf694511743cb63 | |
parent | 4303bdcb3df1d2a866a6796bda9cd36e1085ed59 (diff) | |
parent | a8ec27f7ab554745e1e1c4700455fdfd6a1048e9 (diff) | |
download | Mms-9499fc6f9a922b69dd1478fdd63203499a8ec203.tar.gz |
Merge "Improve Messaging app behavior when not default SMS app." into klp-dev
-rw-r--r-- | res/layout/banner_sms_promo.xml | 91 | ||||
-rw-r--r-- | res/layout/compose_message_activity.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 10 | ||||
-rw-r--r-- | res/values/styles.xml | 13 | ||||
-rw-r--r-- | src/com/android/mms/ui/ComposeMessageActivity.java | 42 | ||||
-rw-r--r-- | src/com/android/mms/ui/ConversationList.java | 99 |
6 files changed, 138 insertions, 118 deletions
diff --git a/res/layout/banner_sms_promo.xml b/res/layout/banner_sms_promo.xml index f778fbdc..860747b6 100644 --- a/res/layout/banner_sms_promo.xml +++ b/res/layout/banner_sms_promo.xml @@ -2,80 +2,47 @@ <!-- Copyright (C) 2013 Google Inc. --> -<!-- - The outer FrameLayout required so we can set a background image with a drop shadow. If - we set that background image on the LinearLayout, the drop shadow is incorrectly displayed as - part of the LinearLayout itself. ---> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/banner_sms_promo" - android:orientation="vertical" - android:paddingLeft="16dip" - android:paddingRight="16dip" - android:paddingTop="@dimen/banner_s_space" - android:paddingBottom="@dimen/banner_s_space" + android:orientation="horizontal" + android:paddingLeft="8dip" + android:paddingRight="8dip" + android:paddingTop="16dip" + android:paddingBottom="16dip" android:layout_width="match_parent" android:layout_gravity="center_vertical" android:layout_height="wrap_content" android:background="@drawable/class_zero_background" > - - <TextView + <ImageView + android:id="@+id/banner_sms_default_app_icon" android:layout_width="wrap_content" - android:layout_height="0dip" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:src="@drawable/ic_launcher_smsmms" android:gravity="center_vertical" - android:paddingLeft="16dip" - android:paddingTop="@dimen/banner_s_space" - android:paddingBottom="@dimen/banner_s_space" - android:singleLine="false" - android:text="@string/banner_sms_promo_message" - android:layout_weight="1" - android:textStyle="normal" - style="@style/BannerWindowText" - /> - - <View - android:background="@color/translucent_white" - android:layout_marginTop="@dimen/banner_s_space" - android:layout_marginBottom="@dimen/banner_s_space" - android:layout_width="match_parent" - android:layout_height="1dip" /> - + android:importantForAccessibility="no" /> <LinearLayout - android:orientation="horizontal" + android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" + android:paddingLeft="8dip" android:gravity="center_vertical" > - - <Button - android:id="@+id/dismiss_banner_sms_promo" - android:paddingLeft="@dimen/banner_m_space" - android:paddingRight="@dimen/banner_m_space" - android:layout_marginRight="@dimen/banner_s_space" - android:text="@string/banner_sms_promo_decline" - android:background="@drawable/banner_button_selectable" - android:layout_width="wrap_content" - android:layout_height="36dip" - android:textStyle="normal" - android:layout_weight=".5" - style="@style/BannerWindowText" /> - - <View - android:background="@color/translucent_white" - android:layout_width="1dip" - android:layout_height="16dip" /> - - <Button - android:id="@+id/accept_banner_sms_promo" - android:paddingLeft="@dimen/banner_m_space" - android:paddingRight="@dimen/banner_m_space" - android:layout_marginLeft="@dimen/banner_s_space" - android:text="@string/banner_sms_promo_accept" - android:background="@drawable/banner_button_selectable" - android:layout_width="wrap_content" - android:layout_height="36dip" - android:textStyle="normal" - android:layout_weight=".5" - style="@style/BannerWindowText" /> + <TextView + android:id="@+id/banner_sms_promo_title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:paddingBottom="@dimen/banner_s_space" + android:singleLine="true" + android:text="@string/banner_sms_promo_title_initial" + style="@style/BannerTitleText" /> + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:singleLine="false" + android:text="@string/banner_sms_promo_message" + style="@style/BannerContentText" /> </LinearLayout> </LinearLayout> diff --git a/res/layout/compose_message_activity.xml b/res/layout/compose_message_activity.xml index f6d48b26..2c653f83 100644 --- a/res/layout/compose_message_activity.xml +++ b/res/layout/compose_message_activity.xml @@ -122,7 +122,6 @@ <LinearLayout android:id="@+id/bottom_panel" - android:visibility="gone" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/res/values/strings.xml b/res/values/strings.xml index f4a87194..2c16f3ea 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -173,6 +173,10 @@ <string name="type_to_compose_text_enter_to_send">Type message</string> <!-- Hint text in message body field when keyboard is hidden --> <string name="open_keyboard_to_compose_message">Open keyboard to type message</string> + <!-- Hint text when we are not the default SMS app --> + <string name="sending_disabled_not_default_app">Sending disabled</string> + <!-- Toast text when user tries to compose while we are not the default SMS app --> + <string name="compose_disabled_toast">Can\'t compose. Not default SMS app.</string> <!-- Toast message while an image is being resized --> <string name="compressing">Picture too large. Compressing\u2026</string> @@ -793,8 +797,8 @@ <string name="desc_mms_send_outbox_msg">Sends out all MMSs from the outbox to the network</string> <!-- Banner in conversation list for making Messaging the default SMS app --> - <string name="banner_sms_promo_message">Would you like to use Messaging as your default SMS app?</string> - <string name="banner_sms_promo_decline">No, thanks</string> - <string name="banner_sms_promo_accept">Yes!</string> + <string name="banner_sms_promo_title_initial">Messaging is not your SMS app</string> + <string name="banner_sms_promo_title_application"><xliff:g id="appName">%s</xliff:g> is your SMS app</string> + <string name="banner_sms_promo_message">You can change this in Settings</string> </resources> diff --git a/res/values/styles.xml b/res/values/styles.xml index d3792d12..2a6501af 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -44,16 +44,25 @@ <item name="android:textColor">#999999</item> </style> - <style name="BannerWindowText"> + <style name="TextShadowLight"> <item name="android:textColor">@color/solid_white</item> <item name="android:shadowColor">@color/text_shadow_color_light</item> <item name="android:shadowDx">1</item> <item name="android:shadowDy">2</item> <item name="android:shadowRadius">1</item> + </style> + + <style name="BannerTitleText" parent="TextShadowLight"> + <item name="android:textSize">18sp</item> + <item name="android:ellipsize">end</item> + <item name="android:singleLine">true</item> + <item name="android:textStyle">bold</item> + </style> + + <style name="BannerContentText" parent="TextShadowLight"> <item name="android:textSize">14sp</item> <item name="android:ellipsize">end</item> <item name="android:singleLine">true</item> - <item name="android:textStyle">italic</item> </style> </resources> diff --git a/src/com/android/mms/ui/ComposeMessageActivity.java b/src/com/android/mms/ui/ComposeMessageActivity.java index bfc8f89a..eaa56712 100644 --- a/src/com/android/mms/ui/ComposeMessageActivity.java +++ b/src/com/android/mms/ui/ComposeMessageActivity.java @@ -1863,6 +1863,7 @@ public class ComposeMessageActivity extends Activity @Override protected void onCreate(Bundle savedInstanceState) { + mIsSmsEnabled = MmsConfig.isSmsEnabled(this); super.onCreate(savedInstanceState); resetConfiguration(getResources().getConfiguration()); @@ -1978,7 +1979,7 @@ public class ComposeMessageActivity extends Activity drawBottomPanel(); } - onKeyboardStateChanged(mIsKeyboardOpen); + onKeyboardStateChanged(); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("update title, mConversation=" + mConversation.toString()); @@ -2369,7 +2370,7 @@ public class ComposeMessageActivity extends Activity Log.v(TAG, "CMA.onConfigurationChanged: " + newConfig + ", mIsKeyboardOpen=" + mIsKeyboardOpen); } - onKeyboardStateChanged(mIsKeyboardOpen); + onKeyboardStateChanged(); } // returns true if landscape/portrait configuration has changed @@ -2383,10 +2384,20 @@ public class ComposeMessageActivity extends Activity return false; } - private void onKeyboardStateChanged(boolean isKeyboardOpen) { + private void onKeyboardStateChanged() { // If the keyboard is hidden, don't show focus highlights for // things that cannot receive input. - if (isKeyboardOpen) { + mTextEditor.setEnabled(mIsSmsEnabled); + if (!mIsSmsEnabled) { + if (mRecipientsEditor != null) { + mRecipientsEditor.setFocusableInTouchMode(false); + } + if (mSubjectTextEditor != null) { + mSubjectTextEditor.setFocusableInTouchMode(false); + } + mTextEditor.setFocusableInTouchMode(false); + mTextEditor.setHint(R.string.sending_disabled_not_default_app); + } else if (mIsKeyboardOpen) { if (mRecipientsEditor != null) { mRecipientsEditor.setFocusableInTouchMode(true); } @@ -3322,12 +3333,6 @@ public class ComposeMessageActivity extends Activity * draw the compose view at the bottom of the screen. */ private void drawBottomPanel() { - // If we are not the default SMS app, the bottom panel is always gone. - if (!mIsSmsEnabled) { - mBottomPanel.setVisibility(View.GONE); - return; - } - // Reset the counter for text editor. resetCounter(); @@ -3345,7 +3350,7 @@ public class ComposeMessageActivity extends Activity CharSequence text = mWorkingMessage.getText(); // TextView.setTextKeepState() doesn't like null input. - if (text != null) { + if (text != null && mIsSmsEnabled) { mTextEditor.setTextKeepState(text); // Set the edit caret to the end of the text. @@ -3353,15 +3358,10 @@ public class ComposeMessageActivity extends Activity } else { mTextEditor.setText(""); } + onKeyboardStateChanged(); } private void hideBottomPanel() { - // If we are not the default SMS app, the bottom panel is always gone. - if (!mIsSmsEnabled) { - mBottomPanel.setVisibility(View.GONE); - return; - } - if (LOCAL_LOGV) { Log.v(TAG, "CMA.hideBottomPanel"); } @@ -3374,6 +3374,7 @@ public class ComposeMessageActivity extends Activity showSubjectEditor(showSubjectEditor || mWorkingMessage.hasSubject()); invalidateOptionsMenu(); + onKeyboardStateChanged(); } //========================================================== @@ -3696,9 +3697,10 @@ public class ComposeMessageActivity extends Activity private boolean isPreparedForSending() { int recipientCount = recipientCount(); - return recipientCount > 0 && recipientCount <= MmsConfig.getRecipientLimit() && - (mWorkingMessage.hasAttachment() || - mWorkingMessage.hasText() || + return recipientCount > 0 && + recipientCount <= MmsConfig.getRecipientLimit() && + mIsSmsEnabled && + (mWorkingMessage.hasAttachment() || mWorkingMessage.hasText() || mWorkingMessage.hasSubject()); } diff --git a/src/com/android/mms/ui/ConversationList.java b/src/com/android/mms/ui/ConversationList.java index fbf3726a..afbc456a 100644 --- a/src/com/android/mms/ui/ConversationList.java +++ b/src/com/android/mms/ui/ConversationList.java @@ -17,10 +17,6 @@ package com.android.mms.ui; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; - import android.app.ActionBar; import android.app.AlertDialog; import android.app.ListActivity; @@ -35,17 +31,20 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.database.Cursor; import android.database.sqlite.SQLiteException; import android.database.sqlite.SqliteWrapper; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.provider.ContactsContract; -import android.provider.Telephony; import android.provider.ContactsContract.Contacts; +import android.provider.Telephony; import android.provider.Telephony.Mms; import android.provider.Telephony.Threads; import android.util.Log; @@ -63,11 +62,12 @@ import android.view.View.OnCreateContextMenuListener; import android.view.View.OnKeyListener; import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.Button; import android.widget.CheckBox; +import android.widget.ImageView; import android.widget.ListView; import android.widget.SearchView; import android.widget.TextView; +import android.widget.Toast; import com.android.mms.LogTag; import com.android.mms.MmsConfig; @@ -83,6 +83,10 @@ import com.android.mms.util.Recycler; import com.android.mms.widget.MmsWidgetProvider; import com.google.android.mms.pdu.PduHeaders; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; + /** * This activity provides a list view of existing conversations. */ @@ -90,7 +94,6 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft private static final String TAG = "ConversationList"; private static final boolean DEBUG = false; private static final boolean DEBUGCLEANUP = true; - private static final boolean LOCAL_LOGV = DEBUG; private static final int THREAD_LIST_QUERY_TOKEN = 1701; private static final int UNREAD_THREADS_QUERY_TOKEN = 1702; @@ -125,6 +128,7 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft // Whether or not we are currently enabled for SMS. This field is updated in onResume to make // sure we notice if the user has changed the default SMS app. private boolean mIsSmsEnabled; + private Toast mComposeDisabledToast; @Override protected void onCreate(Bundle savedInstanceState) { @@ -133,7 +137,6 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft setContentView(R.layout.conversation_list_screen); mSmsPromoBannerView = findViewById(R.id.banner_sms_promo); - initSmsPromoBanner(); mQueryHandler = new ThreadListQueryHandler(getContentResolver()); @@ -215,6 +218,7 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft if (mIsSmsEnabled || MmsConfig.isSmsPromoDismissed(this)) { mSmsPromoBannerView.setVisibility(View.GONE); } else { + initSmsPromoBanner(); mSmsPromoBannerView.setVisibility(View.VISIBLE); } @@ -252,26 +256,51 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft } private void initSmsPromoBanner() { - Button declineButton = (Button) mSmsPromoBannerView.findViewById( - R.id.dismiss_banner_sms_promo); - declineButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - MmsConfig.setSmsPromoDismissed(ConversationList.this); - mSmsPromoBannerView.setVisibility(View.GONE); - } - }); - - Button acceptButton = (Button) mSmsPromoBannerView.findViewById( - R.id.accept_banner_sms_promo); - acceptButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // Request being the default SMS app using a system settings intent - final Intent intent = MmsConfig.getRequestDefaultSmsAppActivity(); - startActivity(intent); - } - }); + final PackageManager packageManager = getPackageManager(); + final String smsAppPackage = Telephony.Sms.getDefaultSmsPackage(this); + + // Get all the data we need about the default app to properly render the promo banner. We + // try to show the icon and name of the user's selected SMS app and have the banner link + // to that app. If we can't read that information for any reason we leave the fallback + // text that links to Messaging settings where the user can change the default. + Drawable smsAppIcon = null; + ApplicationInfo smsAppInfo = null; + try { + smsAppIcon = packageManager.getApplicationIcon(smsAppPackage); + smsAppInfo = packageManager.getApplicationInfo(smsAppPackage, 0); + } catch (NameNotFoundException e) { + } + final Intent smsAppIntent = packageManager.getLaunchIntentForPackage(smsAppPackage); + + // If we got all the info we needed + if (smsAppIcon != null && smsAppInfo != null && smsAppIntent != null) { + ImageView defaultSmsAppIconImageView = + (ImageView)mSmsPromoBannerView.findViewById(R.id.banner_sms_default_app_icon); + defaultSmsAppIconImageView.setImageDrawable(smsAppIcon); + TextView smsPromoBannerTitle = + (TextView)mSmsPromoBannerView.findViewById(R.id.banner_sms_promo_title); + String message = getResources().getString(R.string.banner_sms_promo_title_application, + smsAppInfo.loadLabel(packageManager)); + smsPromoBannerTitle.setText(message); + + mSmsPromoBannerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(smsAppIntent); + } + }); + } else { + // Otherwise the banner will be left alone and will launch settings + mSmsPromoBannerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // Launch settings + Intent settingsIntent = new Intent(ConversationList.this, + MessagingPreferenceActivity.class); + startActivityIfNeeded(settingsIntent, -1); + } + }); + } } /** @@ -486,7 +515,8 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft } item = menu.findItem(R.id.action_compose_new); if (item != null ){ - item.setVisible(mIsSmsEnabled); + // Dim compose if SMS is disabled because it will not work (will show a toast) + item.getIcon().setAlpha(mIsSmsEnabled ? 255 : 127); } if (!LogTag.DEBUG_DUMP) { item = menu.findItem(R.id.action_debug_dump); @@ -509,7 +539,16 @@ public class ConversationList extends ListActivity implements DraftCache.OnDraft public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.action_compose_new: - createNewMessage(); + if (mIsSmsEnabled) { + createNewMessage(); + } else { + // Display a toast letting the user know they can not compose. + if (mComposeDisabledToast == null) { + mComposeDisabledToast = Toast.makeText(this, + R.string.compose_disabled_toast, Toast.LENGTH_SHORT); + } + mComposeDisabledToast.show(); + } break; case R.id.action_delete_all: // The invalid threadId of -1 means all threads here. |