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