Merge "Always pop back to main app from widget."
This commit is contained in:
commit
1f6769facc
@ -117,7 +117,9 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
private static final String EXTRA_ACCOUNT_ID = "account_id";
|
private static final String EXTRA_ACCOUNT_ID = "account_id";
|
||||||
private static final String EXTRA_MESSAGE_ID = "message_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. */
|
/** 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";
|
public static final String EXTRA_FROM_WITHIN_APP = "from_within_app";
|
||||||
|
/** If the intent is sent from thw widget. */
|
||||||
|
public static final String EXTRA_FROM_WIDGET = "from_widget";
|
||||||
|
|
||||||
private static final String STATE_KEY_CC_SHOWN =
|
private static final String STATE_KEY_CC_SHOWN =
|
||||||
"com.android.email.activity.MessageCompose.ccShown";
|
"com.android.email.activity.MessageCompose.ccShown";
|
||||||
@ -226,9 +228,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static Intent getBaseIntent(Context context) {
|
private static Intent getBaseIntent(Context context) {
|
||||||
Intent i = new Intent(context, MessageCompose.class);
|
return new Intent(context, MessageCompose.class);
|
||||||
i.putExtra(EXTRA_FROM_WITHIN_APP, true);
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,14 +242,27 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compose a new message using the given account. If account is -1 the default account
|
* Creates an {@link Intent} that can start the message compose activity from the main Email
|
||||||
* will be used.
|
* activity. This should not be used for Intents to be fired from outside of the main Email
|
||||||
|
* activity, such as from widgets, as the behavior of the compose screen differs subtly from
|
||||||
|
* those cases.
|
||||||
|
*/
|
||||||
|
private static Intent getMainAppIntent(Context context, long accountId) {
|
||||||
|
Intent result = getMessageComposeIntent(context, accountId);
|
||||||
|
result.putExtra(EXTRA_FROM_WITHIN_APP, true);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compose a new message using the given account. If account is {@link Account#NO_ACCOUNT}
|
||||||
|
* the default account will be used.
|
||||||
|
* This should only be called from the main Email application.
|
||||||
* @param context
|
* @param context
|
||||||
* @param accountId
|
* @param accountId
|
||||||
*/
|
*/
|
||||||
public static void actionCompose(Context context, long accountId) {
|
public static void actionCompose(Context context, long accountId) {
|
||||||
try {
|
try {
|
||||||
Intent i = getMessageComposeIntent(context, accountId);
|
Intent i = getMainAppIntent(context, accountId);
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
} catch (ActivityNotFoundException anfe) {
|
} catch (ActivityNotFoundException anfe) {
|
||||||
// Swallow it - this is usually a race condition, especially under automated test.
|
// Swallow it - this is usually a race condition, especially under automated test.
|
||||||
@ -261,6 +274,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
/**
|
/**
|
||||||
* Compose a new message using a uri (mailto:) and a given account. If account is -1 the
|
* Compose a new message using a uri (mailto:) and a given account. If account is -1 the
|
||||||
* default account will be used.
|
* default account will be used.
|
||||||
|
* This should only be called from the main Email application.
|
||||||
* @param context
|
* @param context
|
||||||
* @param uriString
|
* @param uriString
|
||||||
* @param accountId
|
* @param accountId
|
||||||
@ -268,7 +282,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
*/
|
*/
|
||||||
public static boolean actionCompose(Context context, String uriString, long accountId) {
|
public static boolean actionCompose(Context context, String uriString, long accountId) {
|
||||||
try {
|
try {
|
||||||
Intent i = getMessageComposeIntent(context, accountId);
|
Intent i = getMainAppIntent(context, accountId);
|
||||||
i.setAction(Intent.ACTION_SEND);
|
i.setAction(Intent.ACTION_SEND);
|
||||||
i.setData(Uri.parse(uriString));
|
i.setData(Uri.parse(uriString));
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
@ -538,6 +552,11 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
outState.putLong(STATE_KEY_LAST_SAVE_TASK_ID, mLastSaveTaskId);
|
outState.putLong(STATE_KEY_LAST_SAVE_TASK_ID, mLastSaveTaskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
onBack(true /* systemKey */);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the current message being edited has a source message (i.e. is a reply,
|
* Whether or not the current message being edited has a source message (i.e. is a reply,
|
||||||
* or forward) that is loaded.
|
* or forward) that is loaded.
|
||||||
@ -554,6 +573,11 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
return (i != null && i.getBooleanExtra(EXTRA_FROM_WITHIN_APP, false));
|
return (i != null && i.getBooleanExtra(EXTRA_FROM_WITHIN_APP, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isOpenedFromWidget() {
|
||||||
|
Intent i = getIntent();
|
||||||
|
return (i != null && i.getBooleanExtra(EXTRA_FROM_WIDGET, false));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets message as loaded and then initializes the TextWatchers.
|
* Sets message as loaded and then initializes the TextWatchers.
|
||||||
* @param isLoaded - value to which to set mMessageLoaded
|
* @param isLoaded - value to which to set mMessageLoaded
|
||||||
@ -1718,7 +1742,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
private boolean handleCommand(int viewId) {
|
private boolean handleCommand(int viewId) {
|
||||||
switch (viewId) {
|
switch (viewId) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
onActionBarHomePressed();
|
onBack(false /* systemKey */);
|
||||||
return true;
|
return true;
|
||||||
case R.id.send:
|
case R.id.send:
|
||||||
onSend();
|
onSend();
|
||||||
@ -1749,11 +1773,18 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onActionBarHomePressed() {
|
/**
|
||||||
|
* Handle a tap to the system back key, or the "app up" button in the action bar.
|
||||||
|
* @param systemKey whether or not the system key was pressed
|
||||||
|
*/
|
||||||
|
private void onBack(boolean systemKey) {
|
||||||
finish();
|
finish();
|
||||||
if (isOpenedFromWithinApp()) {
|
if (isOpenedFromWithinApp()) {
|
||||||
// If opened from within the app, we just close it.
|
// If opened from within the app, we just close it.
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isOpenedFromWidget() || !systemKey) {
|
||||||
// Otherwise, need to open the main screen for the appropriate account.
|
// Otherwise, need to open the main screen for the appropriate account.
|
||||||
// Note that mAccount should always be set by the time the action bar is set up.
|
// Note that mAccount should always be set by the time the action bar is set up.
|
||||||
startActivity(Welcome.createOpenAccountInboxIntent(this, mAccount.mId));
|
startActivity(Welcome.createOpenAccountInboxIntent(this, mAccount.mId));
|
||||||
|
@ -312,6 +312,7 @@ public class EmailWidget implements RemoteViewsService.RemoteViewsFactory,
|
|||||||
views.setViewVisibility(R.id.tap_to_configure, View.GONE);
|
views.setViewVisibility(R.id.tap_to_configure, View.GONE);
|
||||||
// Create click intent for "compose email" target
|
// Create click intent for "compose email" target
|
||||||
intent = MessageCompose.getMessageComposeIntent(mContext, mAccountId);
|
intent = MessageCompose.getMessageComposeIntent(mContext, mAccountId);
|
||||||
|
intent.putExtra(MessageCompose.EXTRA_FROM_WIDGET, true);
|
||||||
setActivityIntent(views, R.id.widget_compose, intent);
|
setActivityIntent(views, R.id.widget_compose, intent);
|
||||||
// Create click intent for logo to open inbox
|
// Create click intent for logo to open inbox
|
||||||
intent = Welcome.createOpenAccountInboxIntent(mContext, mAccountId);
|
intent = Welcome.createOpenAccountInboxIntent(mContext, mAccountId);
|
||||||
|
Loading…
Reference in New Issue
Block a user