Index: webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
diff --git a/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java b/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
deleted file mode 100644 |
index 54a21399b25e0b25290e10a536ca24edba1db753..0000000000000000000000000000000000000000 |
--- a/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
+++ /dev/null |
@@ -1,122 +0,0 @@ |
-// Copyright 2015 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
-// found in the LICENSE file. |
- |
-package org.chromium.webapk.shell_apk; |
- |
-import android.app.Activity; |
-import android.content.ComponentName; |
-import android.content.Intent; |
-import android.content.pm.ApplicationInfo; |
-import android.content.pm.PackageManager; |
-import android.content.pm.PackageManager.NameNotFoundException; |
-import android.graphics.Bitmap; |
-import android.graphics.BitmapFactory; |
-import android.os.Bundle; |
-import android.util.Base64; |
-import android.util.Log; |
- |
-import org.chromium.webapk.lib.common.WebApkConstants; |
-import org.chromium.webapk.lib.common.WebApkUtils; |
- |
-import java.io.ByteArrayOutputStream; |
- |
-/** |
- * Example client activity for a minted APK. |
- */ |
-public class MainActivity extends Activity { |
- private static final String EXTRA_ID = "org.chromium.chrome.browser.webapp_id"; |
- private static final String EXTRA_ICON = "org.chromium.chrome.browser.webapp_icon"; |
- private static final String EXTRA_NAME = "org.chromium.chrome.browser.webapp_name"; |
- private static final String EXTRA_SHORT_NAME = "org.chromium.chrome.browser.webapp_name"; |
- private static final String EXTRA_URL = "org.chromium.chrome.browser.webapp_url"; |
- private static final String EXTRA_MAC = "org.chromium.chrome.browser.webapp_mac"; |
- private static final String EXTRA_SCOPE = "org.chromium.chrome.browser.webapp_scope"; |
- private static final String EXTRA_MINTING_PACKAGE_NAME = "EXTRA_MINTING_PACKAGE_NAME"; |
- private static final String META_DATA_HOST_URL = "hostUrl"; |
- private static final String META_DATA_MAC = "mac"; |
- private static final String META_DATA_SCOPE = "scope"; |
- |
- private static final String TAG = "cr_MainActivity"; |
- |
- @Override |
- protected void onCreate(Bundle savedInstanceState) { |
- super.onCreate(savedInstanceState); |
- |
- Intent intent = getIntent(); |
- String packageName = getPackageName(); |
- String webappId = null; |
- String mac = null; |
- String name = null; |
- String url = null; |
- String scope = null; |
- String encodedIcon = null; |
- try { |
- ApplicationInfo appInfo = getPackageManager().getApplicationInfo( |
- packageName, PackageManager.GET_META_DATA); |
- Bundle bundle = appInfo.metaData; |
- url = bundle.getString(META_DATA_HOST_URL); |
- |
- String overrideUrl = intent.getDataString(); |
- // TODO(pkotwicz): Use same logic as {@code IntentHandler#shouldIgnoreIntent()} |
- if (isUrlValid(overrideUrl)) { |
- url = overrideUrl; |
- } |
- |
- scope = bundle.getString(META_DATA_SCOPE); |
- webappId = WebApkConstants.WEB_APK_ID_PREFIX + packageName; |
- mac = bundle.getString(META_DATA_MAC); |
- name = (String) getPackageManager().getApplicationLabel(appInfo); |
- // TODO(hanxi): find a neat solution to avoid encode/decode each time launch the |
- // activity. |
- Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.app_icon); |
- encodedIcon = encodeBitmapAsString(icon); |
- Log.w(TAG, "Url of the WebAPK: " + url); |
- Log.w(TAG, "webappId of the WebAPK: " + webappId); |
- Log.w(TAG, "name of the WebAPK:" + name); |
- } catch (NameNotFoundException e) { |
- e.printStackTrace(); |
- } |
- |
- Intent newIntent = new Intent(); |
- newIntent.setComponent(new ComponentName(WebApkUtils.getHostBrowserPackageName(this), |
- "org.chromium.chrome.browser.webapps.WebappLauncherActivity")); |
- newIntent.putExtra(EXTRA_ID, webappId); |
- newIntent.putExtra(EXTRA_NAME, name); |
- newIntent.putExtra(EXTRA_SHORT_NAME, name); |
- newIntent.putExtra(EXTRA_MINTING_PACKAGE_NAME, packageName); |
- newIntent.putExtra(EXTRA_SCOPE, scope); |
- newIntent.putExtra(EXTRA_URL, url); |
- newIntent.putExtra(EXTRA_MAC, mac); |
- newIntent.putExtra(EXTRA_ICON, encodedIcon); |
- startActivity(newIntent); |
- finish(); |
- } |
- |
- |
- /** |
- * Compresses a bitmap into a PNG and converts into a Base64 encoded string. |
- * The encoded string can be decoded using {@link decodeBitmapFromString(String)}. |
- * @param bitmap The Bitmap to compress and encode. |
- * @return the String encoding the Bitmap. |
- */ |
- private static String encodeBitmapAsString(Bitmap bitmap) { |
- if (bitmap == null) return ""; |
- ByteArrayOutputStream output = new ByteArrayOutputStream(); |
- bitmap.compress(Bitmap.CompressFormat.PNG, 100, output); |
- return Base64.encodeToString(output.toByteArray(), Base64.DEFAULT); |
- } |
- |
- /** |
- * Returns whether a url is valid. |
- * @param url The url to check. |
- * @return Whether the url is valid. |
- */ |
- private static boolean isUrlValid(String url) { |
- if (url == null) { |
- return false; |
- } |
- |
- return url.startsWith("http:") || url.startsWith("https:"); |
- } |
-} |