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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkManagedActivity.java

Issue 1989283002: Upstream: Launch WebApkActivity from WebAPK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. Created 4 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 /** 7 /**
8 * Type of WebappActivity that has the ability to swap out the webapp it is curr ently showing for a 8 * Type of WebApkActivity and it is targeted on Android versions older than L, s imilar to
9 * new one. This is necessary on Android versions older than L because the frame work had no way of 9 * WebappManagedActivity for WebappActivity.
10 * allowing multiple instances of an Activity to be launched and show up as diff erent tasks.
11 * Anything extending this class must be named WebappActivity0, WebappActivity1, etc.
12 */ 10 */
13 public abstract class WebappManagedActivity extends WebappActivity { 11 public abstract class WebApkManagedActivity extends WebApkActivity {
14 private final int mActivityIndex; 12 private final int mActivityIndex;
15 13
16 public WebappManagedActivity() { 14 public WebApkManagedActivity() {
17 mActivityIndex = getActivityIndex(); 15 mActivityIndex = getActivityIndex();
18 } 16 }
19 17
20 @Override 18 @Override
21 public void onStartWithNative() { 19 public void onStartWithNative() {
22 super.onStartWithNative(); 20 super.onStartWithNative();
23 21
24 if (!isFinishing()) { 22 if (!isFinishing()) {
25 markActivityUsed(); 23 markActivityUsed();
26 } 24 }
27 } 25 }
28 26
29 @Override 27 @Override
30 protected String getId() { 28 protected String getId() {
31 return String.valueOf(mActivityIndex); 29 return String.valueOf(mActivityIndex);
32 } 30 }
33 31
34 /** 32 /**
35 * Marks that this WebappActivity is recently used to prevent other webapps from using it. 33 * Marks that this WebApkActivity is recently used to prevent other webapps from using it.
36 */ 34 */
37 private void markActivityUsed() { 35 private void markActivityUsed() {
38 ActivityAssigner.instance(this).markActivityUsed(mActivityIndex, getWeba ppInfo().id()); 36 ActivityAssigner.instance(getWebappInfo().id()).markActivityUsed(
37 mActivityIndex, getWebappInfo().id());
39 } 38 }
40 39
41 /** 40 /**
42 * Pulls out the index of the WebappActivity subclass that is being used. 41 * Pulls out the index of the WebApkActivity subclass that is being used.
43 * e.g. WebappActivity0.getActivityIndex() will return 0. 42 * e.g. WebApkActivity0.getActivityIndex() will return 0.
44 * @return The index corresponding to this WebappActivity. 43 * @return The index corresponding to this WebApkActivity0.
45 */ 44 */
46 private int getActivityIndex() { 45 private int getActivityIndex() {
47 // Cull out the activity index from the class name. 46 // Cull out the activity index from the class name.
48 String baseClassName = WebappActivity.class.getSimpleName(); 47 String baseClassName = WebApkActivity.class.getSimpleName();
49 String className = this.getClass().getSimpleName(); 48 String className = this.getClass().getSimpleName();
50 assert className.matches("^" + baseClassName + "[0-9]+$"); 49 assert className.matches("^" + baseClassName + "[0-9]+$");
51 String indexString = className.substring(baseClassName.length()); 50 String indexString = className.substring(baseClassName.length());
52 return Integer.parseInt(indexString); 51 return Integer.parseInt(indexString);
53 } 52 }
54 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698