Make home icon on action bar clickable

- Make the home icon on action bar clickable, and show the back arrow with it.
- When clicked, it'll navigate you back to the main screen.

Bug 3138037

Change-Id: Ice783e6b594347bd73b94e71d29a61ad4f5ef972
This commit is contained in:
Makoto Onuki 2010-11-18 16:52:50 -08:00
parent 6143d026c0
commit 9f04fdc555
1 changed files with 37 additions and 3 deletions

View File

@ -95,6 +95,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
private static final String EXTRA_ACCOUNT_ID = "account_id";
private static final String EXTRA_MESSAGE_ID = "message_id";
/** If the intent is sent from the email app itself, it should have this boolean extra. */
private static final String EXTRA_FROM_WITHIN_APP = "from_within_app";
private static final String STATE_KEY_CC_SHOWN =
"com.android.email.activity.MessageCompose.ccShown";
private static final String STATE_KEY_QUOTED_TEXT_SHOWN =
@ -168,6 +171,12 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
/** Whether the save command should be enabled. */
private boolean mSaveEnabled;
private static Intent getBaseIntent(Context context) {
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_FROM_WITHIN_APP, true);
return i;
}
/**
* Compose a new message using the given account. If account is -1 the default account
* will be used.
@ -176,7 +185,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
*/
public static void actionCompose(Context context, long accountId) {
try {
Intent i = new Intent(context, MessageCompose.class);
Intent i = getBaseIntent(context);
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
context.startActivity(i);
} catch (ActivityNotFoundException anfe) {
@ -196,7 +205,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
*/
public static boolean actionCompose(Context context, String uriString, long accountId) {
try {
Intent i = new Intent(context, MessageCompose.class);
Intent i = getBaseIntent(context);
i.setAction(Intent.ACTION_SEND);
i.setData(Uri.parse(uriString));
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
@ -243,7 +252,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
}
private static void startActivityWithMessage(Context context, String action, long messageId) {
Intent i = new Intent(context, MessageCompose.class);
Intent i = getBaseIntent(context);
i.putExtra(EXTRA_MESSAGE_ID, messageId);
i.setAction(action);
context.startActivity(i);
@ -292,6 +301,10 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
draftId = savedInstanceState.getLong(STATE_KEY_DRAFT_ID, -1);
}
// Show the back arrow on the action bar.
getActionBar().setDisplayOptions(
ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP);
Intent intent = getIntent();
mAction = intent.getAction();
@ -425,6 +438,14 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
setDraftNeedsSaving(false);
}
/**
* @return true if the activity was opened by the email app itself.
*/
private boolean isOpenedFromWithinApp() {
Intent i = getIntent();
return (i != null && i.getBooleanExtra(EXTRA_FROM_WITHIN_APP, false));
}
private void setDraftNeedsSaving(boolean needsSaving) {
mDraftNeedsSaving = needsSaving;
mSaveEnabled = needsSaving;
@ -1210,6 +1231,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
private boolean handleCommand(int viewId) {
switch (viewId) {
case android.R.id.home:
onActionBarHomePressed();
return true;
case R.id.send:
onSend();
return true;
@ -1232,6 +1256,16 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
return false;
}
private void onActionBarHomePressed() {
finish();
if (isOpenedFromWithinApp()) {
// If opend from within the app, we just close it.
} else {
// Otherwise, need to open the main screen. Let Welcome do that.
Welcome.actionStart(this);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);