1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.email.activity; 18 19import android.app.Activity; 20import android.content.ActivityNotFoundException; 21import android.content.Intent; 22import android.net.Uri; 23import android.provider.Browser; 24import android.view.WindowManager; 25 26import com.android.email.activity.setup.AccountSecurity; 27import com.android.email2.ui.MailActivityEmail; 28import com.android.emailcommon.provider.Account; 29 30/** 31 * Various methods that are used by both 1-pane and 2-pane activities. 32 * 33 * Common code used by the activities and the fragments. 34 */ 35public final class ActivityHelper { 36 private ActivityHelper() { 37 } 38 39 /** 40 * Open an URL in a message. 41 * 42 * This is intended to mirror the operation of the original 43 * (see android.webkit.CallbackProxy) with one addition of intent flags 44 * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET". This improves behavior when sublaunching 45 * other apps via embedded URI's. 46 * 47 * We also use this hook to catch "mailto:" links and handle them locally. 48 * 49 * @param activity parent activity 50 * @param url URL to open 51 * @param senderAccountId if the URL is mailto:, we use this account as the sender. 52 * TODO When MessageCompose implements the account selector, this won't be necessary. 53 * Pass {@link Account#NO_ACCOUNT} to use the default account. 54 * @return true if the URI has successfully been opened. 55 */ 56 public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) { 57 // hijack mailto: uri's and handle locally 58 //*** 59 //if (url != null && url.toLowerCase().startsWith("mailto:")) { 60 // return MessageCompose.actionCompose(activity, url, senderAccountId); 61 //} 62 63 // Handle most uri's via intent launch 64 boolean result = false; 65 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 66 intent.addCategory(Intent.CATEGORY_BROWSABLE); 67 intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName()); 68 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 69 try { 70 activity.startActivity(intent); 71 result = true; 72 } catch (ActivityNotFoundException ex) { 73 // No applications can handle it. Ignore. 74 } 75 return result; 76 } 77 78 /** 79 * If configured via debug flags, inhibit hardware graphics acceleration. Must be called 80 * early in onCreate(). 81 * 82 * NOTE: Currently, this only works if HW accel is *not* enabled via the manifest. 83 */ 84 public static void debugSetWindowFlags(Activity activity) { 85 if (MailActivityEmail.sDebugInhibitGraphicsAcceleration) { 86 // Clear the flag in the activity's window 87 activity.getWindow().setFlags(0, 88 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); 89 } else { 90 // Set the flag in the activity's window 91 activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 92 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); 93 } 94 } 95 96 public static void showSecurityHoldDialog(Activity callerActivity, long accountId) { 97 callerActivity.startActivity( 98 AccountSecurity.actionUpdateSecurityIntent(callerActivity, accountId, true)); 99 } 100 101} 102