Add WebViewClient to specialize link-click behaviors.
* If external, set FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET * If mailto: always open the composer Fixes bugs 1631784 and 2122326
This commit is contained in:
parent
386153695b
commit
9d249df5b8
@ -176,7 +176,7 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus
|
||||
* Compose a new message using the given account. If account is -1 the default account
|
||||
* will be used.
|
||||
* @param context
|
||||
* @param account
|
||||
* @param accountId
|
||||
*/
|
||||
public static void actionCompose(Context context, long accountId) {
|
||||
try {
|
||||
@ -190,6 +190,30 @@ 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
|
||||
* default account will be used.
|
||||
* @param context
|
||||
* @param uriString
|
||||
* @param accountId
|
||||
* @return true if startActivity() succeeded
|
||||
*/
|
||||
public static boolean actionCompose(Context context, String uriString, long accountId) {
|
||||
try {
|
||||
Intent i = new Intent(context, MessageCompose.class);
|
||||
i.setAction(Intent.ACTION_SEND);
|
||||
i.setData(Uri.parse(uriString));
|
||||
i.putExtra(EXTRA_ACCOUNT_ID, accountId);
|
||||
context.startActivity(i);
|
||||
return true;
|
||||
} catch (ActivityNotFoundException anfe) {
|
||||
// Swallow it - this is usually a race condition, especially under automated test.
|
||||
// (The message composer might have been disabled)
|
||||
Email.log(anfe.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a new message as a reply to the given message. If replyAll is true the function
|
||||
* is reply all instead of simply reply.
|
||||
|
@ -51,6 +51,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.provider.Browser;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.CommonDataKinds;
|
||||
import android.provider.ContactsContract.FastTrack;
|
||||
@ -65,6 +66,7 @@ import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
@ -342,6 +344,7 @@ public class MessageView extends Activity implements OnClickListener {
|
||||
mMessageContentView.setVerticalScrollBarEnabled(false);
|
||||
mMessageContentView.getSettings().setBlockNetworkImage(true);
|
||||
mMessageContentView.getSettings().setSupportZoom(false);
|
||||
mMessageContentView.setWebViewClient(new CustomWebViewClient());
|
||||
|
||||
mProgressDialog = new ProgressDialog(this);
|
||||
mProgressDialog.setIndeterminate(true);
|
||||
@ -457,6 +460,42 @@ public class MessageView extends Activity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides for various WebView behaviors.
|
||||
*/
|
||||
private class CustomWebViewClient extends WebViewClient {
|
||||
/**
|
||||
* This is intended to mirror the operation of the original
|
||||
* (see android.webkit.CallbackProxy) with one addition of intent flags
|
||||
* "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET". This improves behavior when sublaunching
|
||||
* other apps via embedded URI's.
|
||||
*
|
||||
* We also use this hook to catch "mailto:" links and handle them locally.
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
// hijack mailto: uri's and handle locally
|
||||
if (url != null && url.toLowerCase().startsWith("mailto:")) {
|
||||
return MessageCompose.actionCompose(MessageView.this, url, mAccountId);
|
||||
}
|
||||
|
||||
// Handle most uri's via intent launch
|
||||
boolean result = false;
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
intent.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
try {
|
||||
startActivity(intent);
|
||||
result = true;
|
||||
} catch (ActivityNotFoundException ex) {
|
||||
// If no application can handle the URL, assume that the
|
||||
// caller can handle it.
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clicks on sender, which shows {@link FastTrack} or prompts to add
|
||||
* the sender as a contact.
|
||||
|
Loading…
Reference in New Issue
Block a user