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

Side by Side Diff: web_apks/minting_example/src/org/chromium/minting/MainActivity.java

Issue 1953543002: Rename WebAPK related classes to be of the format *WebApk*.java (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2015 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.minting; 5 package org.chromium.minting;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.content.ComponentName; 8 import android.content.ComponentName;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.SharedPreferences;
11 import android.content.pm.ApplicationInfo; 10 import android.content.pm.ApplicationInfo;
12 import android.content.pm.PackageManager; 11 import android.content.pm.PackageManager;
13 import android.content.pm.PackageManager.NameNotFoundException; 12 import android.content.pm.PackageManager.NameNotFoundException;
14 import android.graphics.Bitmap; 13 import android.graphics.Bitmap;
15 import android.graphics.BitmapFactory; 14 import android.graphics.BitmapFactory;
16 import android.os.Bundle; 15 import android.os.Bundle;
17 import android.util.Base64; 16 import android.util.Base64;
18 import android.util.Log; 17 import android.util.Log;
19 import android.view.View;
20 import android.view.View.OnClickListener;
21 18
22 import org.chromium.minting.lib.common.WebAPKConstants; 19 import org.chromium.minting.lib.common.WebApkConstants;
23 import org.chromium.minting.lib.common.WebAPKUtils; 20 import org.chromium.minting.lib.common.WebApkUtils;
24 21
25 import java.io.ByteArrayOutputStream; 22 import java.io.ByteArrayOutputStream;
26 23
27 /** 24 /**
28 * Example client activity for a minted APK. 25 * Example client activity for a minted APK.
29 */ 26 */
30 public class MainActivity extends Activity { 27 public class MainActivity extends Activity {
31 private static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_i d"; 28 private static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_i d";
32 private static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp _icon"; 29 private static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp _icon";
33 private static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp _name"; 30 private static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp _name";
(...skipping 26 matching lines...) Expand all
60 Bundle bundle = appInfo.metaData; 57 Bundle bundle = appInfo.metaData;
61 url = bundle.getString(META_DATA_HOST_URL); 58 url = bundle.getString(META_DATA_HOST_URL);
62 59
63 String overrideUrl = intent.getDataString(); 60 String overrideUrl = intent.getDataString();
64 // TODO(pkotwicz): Use same logic as {@code IntentHandler#shouldIgno reIntent()} 61 // TODO(pkotwicz): Use same logic as {@code IntentHandler#shouldIgno reIntent()}
65 if (isUrlValid(overrideUrl)) { 62 if (isUrlValid(overrideUrl)) {
66 url = overrideUrl; 63 url = overrideUrl;
67 } 64 }
68 65
69 scope = bundle.getString(META_DATA_SCOPE); 66 scope = bundle.getString(META_DATA_SCOPE);
70 webappId = WebAPKConstants.WEB_APK_ID_PREFIX + packageName; 67 webappId = WebApkConstants.WEB_APK_ID_PREFIX + packageName;
71 mac = bundle.getString(META_DATA_MAC); 68 mac = bundle.getString(META_DATA_MAC);
72 name = (String) getPackageManager().getApplicationLabel(appInfo); 69 name = (String) getPackageManager().getApplicationLabel(appInfo);
73 // TODO(hanxi): find a neat solution to avoid encode/decode each tim e launch the 70 // TODO(hanxi): find a neat solution to avoid encode/decode each tim e launch the
74 // activity. 71 // activity.
75 Bitmap icon = BitmapFactory.decodeResource(getResources(), 72 Bitmap icon = BitmapFactory.decodeResource(getResources(),
76 org.chromium.minting.R.drawable.app_icon); 73 org.chromium.minting.R.drawable.app_icon);
77 encodedIcon = encodeBitmapAsString(icon); 74 encodedIcon = encodeBitmapAsString(icon);
78 Log.w(TAG, "Url of the WebAPK: " + url); 75 Log.w(TAG, "Url of the WebAPK: " + url);
79 Log.w(TAG, "webappId of the WebAPK: " + webappId); 76 Log.w(TAG, "webappId of the WebAPK: " + webappId);
80 Log.w(TAG, "name of the WebAPK:" + name); 77 Log.w(TAG, "name of the WebAPK:" + name);
81 } catch (NameNotFoundException e) { 78 } catch (NameNotFoundException e) {
82 e.printStackTrace(); 79 e.printStackTrace();
83 } 80 }
84 81
85 Intent newIntent = new Intent(); 82 Intent newIntent = new Intent();
86 newIntent.setComponent(new ComponentName(WebAPKUtils.getHostBrowserPacka geName(this), 83 newIntent.setComponent(new ComponentName(WebApkUtils.getHostBrowserPacka geName(this),
87 "org.chromium.chrome.browser.webapps.WebappLauncherActivity")); 84 "org.chromium.chrome.browser.webapps.WebappLauncherActivity"));
88 newIntent.putExtra(EXTRA_ID, webappId); 85 newIntent.putExtra(EXTRA_ID, webappId);
89 newIntent.putExtra(EXTRA_NAME, name); 86 newIntent.putExtra(EXTRA_NAME, name);
90 newIntent.putExtra(EXTRA_SHORT_NAME, name); 87 newIntent.putExtra(EXTRA_SHORT_NAME, name);
91 newIntent.putExtra(EXTRA_MINTING_PACKAGE_NAME, packageName); 88 newIntent.putExtra(EXTRA_MINTING_PACKAGE_NAME, packageName);
92 newIntent.putExtra(EXTRA_SCOPE, scope); 89 newIntent.putExtra(EXTRA_SCOPE, scope);
93 newIntent.putExtra(EXTRA_URL, url); 90 newIntent.putExtra(EXTRA_URL, url);
94 newIntent.putExtra(EXTRA_MAC, mac); 91 newIntent.putExtra(EXTRA_MAC, mac);
95 newIntent.putExtra(EXTRA_ICON, encodedIcon); 92 newIntent.putExtra(EXTRA_ICON, encodedIcon);
96 startActivity(newIntent); 93 startActivity(newIntent);
(...skipping 20 matching lines...) Expand all
117 * @return Whether the url is valid. 114 * @return Whether the url is valid.
118 */ 115 */
119 private static boolean isUrlValid(String url) { 116 private static boolean isUrlValid(String url) {
120 if (url == null) { 117 if (url == null) {
121 return false; 118 return false;
122 } 119 }
123 120
124 return url.startsWith("http:") || url.startsWith("https:"); 121 return url.startsWith("http:") || url.startsWith("https:");
125 } 122 }
126 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698