OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser; |
| 6 |
| 7 import android.app.ActionBar; |
| 8 import android.app.Activity; |
| 9 import android.content.Context; |
| 10 import android.content.Intent; |
| 11 import android.net.Uri; |
| 12 import android.view.Menu; |
| 13 import android.view.MenuItem; |
| 14 import android.view.View; |
| 15 |
| 16 import com.google.android.apps.chrome.R; |
| 17 |
| 18 import org.chromium.chrome.browser.firstrun.FirstRunStatus; |
| 19 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; |
| 20 import org.chromium.chrome.browser.webapps.FullScreenActivity; |
| 21 import org.chromium.content_public.browser.LoadUrlParams; |
| 22 import org.chromium.ui.base.PageTransition; |
| 23 |
| 24 /** |
| 25 * An activity that shows a webpage with a title above it. No navigation control
s or menu is |
| 26 * provided. This is useful for showing a webpage without disrupting with the us
er's current |
| 27 * task or their list of tabs, e.g. for showing Terms of Service during first ru
n. |
| 28 */ |
| 29 public class EmbedContentViewActivity extends FullScreenActivity { |
| 30 private static final String TAG = "EmbedContentViewActivity"; |
| 31 |
| 32 /** An intent extra that will determine what URL is to be loaded initially.
*/ |
| 33 protected static final String URL_INTENT_EXTRA = "url"; |
| 34 /** An intent extra that will determine what title is to be set for the acti
vity. */ |
| 35 protected static final String TITLE_INTENT_EXTRA = "title"; |
| 36 |
| 37 /** |
| 38 * Starts an EmbedContentViewActivity that shows title and URL for the given |
| 39 * resource IDs. |
| 40 */ |
| 41 public static void show(Context context, int titleResId, int urlResId) { |
| 42 if (context == null) return; |
| 43 |
| 44 Intent intent = new Intent(Intent.ACTION_VIEW); |
| 45 intent.setClassName(context, EmbedContentViewActivity.class.getName()); |
| 46 if (context instanceof Activity) { |
| 47 intent.setFlags( |
| 48 Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY
_SINGLE_TOP); |
| 49 } else { |
| 50 // Required to handle the case when this is triggered from tests. |
| 51 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 52 } |
| 53 intent.putExtra(TITLE_INTENT_EXTRA, titleResId); |
| 54 intent.putExtra(URL_INTENT_EXTRA, urlResId); |
| 55 context.startActivity(intent); |
| 56 } |
| 57 |
| 58 @Override |
| 59 public void finishNativeInitialization() { |
| 60 super.finishNativeInitialization(); |
| 61 getSupportActionBar().setDisplayOptions( |
| 62 ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); |
| 63 |
| 64 final int titleResId = getIntent().getIntExtra(TITLE_INTENT_EXTRA, 0); |
| 65 if (titleResId != 0) { |
| 66 setTitle(getString(titleResId)); |
| 67 } |
| 68 |
| 69 final int urlResId = getIntent().getIntExtra(URL_INTENT_EXTRA, 0); |
| 70 if (urlResId != 0) { |
| 71 final String url = getString(urlResId); |
| 72 getActivityTab().loadUrl(new LoadUrlParams(url, PageTransition.AUTO_
TOPLEVEL)); |
| 73 } |
| 74 } |
| 75 |
| 76 @Override |
| 77 protected final ChromeFullscreenManager createFullscreenManager(View control
Container) { |
| 78 return null; |
| 79 } |
| 80 |
| 81 @Override |
| 82 public boolean onCreateOptionsMenu(Menu menu) { |
| 83 boolean retVal = super.onCreateOptionsMenu(menu); |
| 84 if (!FirstRunStatus.getFirstRunFlowComplete(this)) return retVal; |
| 85 menu.add(Menu.NONE, R.id.menu_id_open_in_chrome, Menu.NONE, R.string.men
u_open_in_chrome); |
| 86 return true; |
| 87 } |
| 88 |
| 89 @Override |
| 90 public boolean onOptionsItemSelected(MenuItem item) { |
| 91 int itemId = item.getItemId(); |
| 92 if (itemId == android.R.id.home) { |
| 93 // Handles up navigation |
| 94 finish(); |
| 95 return true; |
| 96 } else if (itemId == R.id.menu_id_open_in_chrome && getActivityTab() !=
null) { |
| 97 Intent chromeIntent = new Intent( |
| 98 Intent.ACTION_VIEW, Uri.parse(getActivityTab().getUrl())); |
| 99 chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 100 IntentHandler.startChromeLauncherActivityForTrustedIntent( |
| 101 chromeIntent, getApplicationContext()); |
| 102 return true; |
| 103 } |
| 104 return super.onOptionsItemSelected(item); |
| 105 } |
| 106 |
| 107 @Override |
| 108 protected boolean isContextualSearchAllowed() { |
| 109 return false; |
| 110 } |
| 111 } |
OLD | NEW |