Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.multiwindow;
6
7 import android.annotation.TargetApi;
8 import android.app.Activity;
9 import android.content.Intent;
10 import android.os.Build;
11 import android.text.TextUtils;
12
13 import org.chromium.base.ApplicationStatus;
14 import org.chromium.chrome.browser.ChromeMobileApplication;
15 import org.chromium.chrome.browser.ChromeTabbedActivity;
16 import org.chromium.chrome.browser.document.ChromeLauncherActivity;
17
18 import java.util.concurrent.atomic.AtomicReference;
19
20 /**
21 * Utilities for detecting multi-window/multi-instance support.
22 *
23 * Thread-safe: This class may be accessed from any thread.
24 */
25 public class MultiWindowUtils {
26
27 private static AtomicReference<MultiWindowUtils> sInstance =
28 new AtomicReference<MultiWindowUtils>();
29
30 /**
31 * Returns the singleton instance of MultiWindowUtils, creating it if needed .
32 */
33 public static MultiWindowUtils getInstance() {
34 if (sInstance.get() == null) {
35 ChromeMobileApplication application =
36 (ChromeMobileApplication) ApplicationStatus.getApplicationCo ntext();
37 sInstance.compareAndSet(null, application.createMultiWindowUtils());
38 }
39 return sInstance.get();
40 }
41
42 /**
43 * @param activity The {@link Activity} to check.
44 * @return Whether or not {@code activity} is currently in multi-window mode .
45 */
46 public boolean isMultiWindow(Activity activity) {
47 // This logic is overridden in a subclass.
48 return false;
49 }
50
51 /**
52 * @param activity The {@link Activity} to check.
53 * @return Whether or not {@code activity} should run in multi-instance mode .
54 */
55 public boolean shouldRunInMultiInstanceMode(ChromeLauncherActivity activity) {
56 return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
57 && TextUtils.equals(activity.getIntent().getAction(), Intent.ACT ION_MAIN)
58 && isMultiWindow(activity)
59 && activity.isChromeBrowserActivityRunning();
60 }
61
62 /**
63 * Makes |intent| able to support multi-instance in multi-window mode.
64 */
65 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
66 public void makeMultiInstanceIntent(Activity activity, Intent intent) {
67 if (activity instanceof ChromeLauncherActivity && isMultiWindow(activity )) {
68 if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
69 intent.getComponent().getClassName())) {
70 intent.setClassName(activity, MultiInstanceChromeTabbedActivity. class.getName());
71 }
72 intent.setFlags(intent.getFlags()
73 & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW _DOCUMENT));
74 }
75 }
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698