| Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebDiagnosticsPage.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebDiagnosticsPage.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebDiagnosticsPage.java
|
| index 1ea7eda7195d86d929bbd4c9262817ae4fc190e0..32a7d7a12b421d8a5583fcf9a2ccba67436b8f2a 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebDiagnosticsPage.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebDiagnosticsPage.java
|
| @@ -4,7 +4,7 @@
|
|
|
| package org.chromium.chrome.browser.physicalweb;
|
|
|
| -import android.content.Context;
|
| +import android.app.Activity;
|
| import android.content.Intent;
|
| import android.content.res.Resources;
|
| import android.os.Build;
|
| @@ -16,9 +16,11 @@ import android.widget.Button;
|
| import android.widget.TextView;
|
|
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| +import org.chromium.base.ContextUtils;
|
| import org.chromium.chrome.R;
|
| -import org.chromium.chrome.browser.NativePage;
|
| +import org.chromium.chrome.browser.BasicNativePage;
|
| import org.chromium.chrome.browser.UrlConstants;
|
| +import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.components.location.LocationUtils;
|
|
|
| import java.util.HashSet;
|
| @@ -27,23 +29,26 @@ import java.util.Set;
|
| /**
|
| * Provides diagnostic information about the Physical Web feature.
|
| */
|
| -public class PhysicalWebDiagnosticsPage implements NativePage {
|
| - private final Context mContext;
|
| - private final int mBackgroundColor;
|
| - private final int mThemeColor;
|
| - private final String mSuccessColor;
|
| - private final String mFailureColor;
|
| - private final String mIndeterminateColor;
|
| - private final View mPageView;
|
| - private final Button mLaunchButton;
|
| - private final TextView mDiagnosticsText;
|
| -
|
| - public PhysicalWebDiagnosticsPage(Context context) {
|
| - mContext = context;
|
| -
|
| - Resources resources = mContext.getResources();
|
| - mBackgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.ntp_bg);
|
| - mThemeColor = ApiCompatibilityUtils.getColor(resources, R.color.default_primary_color);
|
| +public class PhysicalWebDiagnosticsPage extends BasicNativePage {
|
| + private String mSuccessColor;
|
| + private String mFailureColor;
|
| + private String mIndeterminateColor;
|
| + private View mPageView;
|
| + private Button mLaunchButton;
|
| + private TextView mDiagnosticsText;
|
| +
|
| + /**
|
| + * Create a new instance of the Physical Web diagnostics page.
|
| + * @param activity The activity to get context and manage fragments.
|
| + * @param tab The tab to load urls.
|
| + */
|
| + public PhysicalWebDiagnosticsPage(Activity activity, Tab tab) {
|
| + super(activity, tab);
|
| + }
|
| +
|
| + @Override
|
| + protected void initialize(Activity activity, Tab tab) {
|
| + Resources resources = activity.getResources();
|
| mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
|
| R.color.physical_web_diags_success_color));
|
| mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
|
| @@ -51,14 +56,14 @@ public class PhysicalWebDiagnosticsPage implements NativePage {
|
| mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
|
| R.color.physical_web_diags_indeterminate_color));
|
|
|
| - LayoutInflater inflater = LayoutInflater.from(mContext);
|
| + LayoutInflater inflater = LayoutInflater.from(activity);
|
| mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null);
|
|
|
| mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch);
|
| mLaunchButton.setOnClickListener(new View.OnClickListener() {
|
| @Override
|
| public void onClick(View v) {
|
| - mContext.startActivity(createListUrlsIntent(mContext));
|
| + ContextUtils.getApplicationContext().startActivity(createListUrlsIntent());
|
| }
|
| });
|
|
|
| @@ -67,6 +72,21 @@ public class PhysicalWebDiagnosticsPage implements NativePage {
|
| mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml()));
|
| }
|
|
|
| + @Override
|
| + public String getTitle() {
|
| + return "Physical Web Diagnostics";
|
| + }
|
| +
|
| + @Override
|
| + public String getHost() {
|
| + return UrlConstants.PHYSICAL_WEB_HOST;
|
| + }
|
| +
|
| + @Override
|
| + public View getView() {
|
| + return mPageView;
|
| + }
|
| +
|
| private void appendResult(StringBuilder sb, boolean success, String successMessage,
|
| String failureMessage) {
|
| int successValue = (success ? Utils.RESULT_SUCCESS : Utils.RESULT_FAILURE);
|
| @@ -99,8 +119,8 @@ public class PhysicalWebDiagnosticsPage implements NativePage {
|
|
|
| private void appendPrerequisitesReport(StringBuilder sb) {
|
| boolean isSdkVersionCorrect = isSdkVersionCorrect();
|
| - boolean isDataConnectionActive = Utils.isDataConnectionActive(mContext);
|
| - int bluetoothStatus = Utils.getBluetoothEnabledStatus(mContext);
|
| + boolean isDataConnectionActive = Utils.isDataConnectionActive();
|
| + int bluetoothStatus = Utils.getBluetoothEnabledStatus();
|
| LocationUtils locationUtils = LocationUtils.getInstance();
|
| boolean isLocationServicesEnabled = locationUtils.isSystemLocationSettingEnabled();
|
| boolean isLocationPermissionGranted = locationUtils.hasAndroidLocationPermission();
|
| @@ -195,60 +215,12 @@ public class PhysicalWebDiagnosticsPage implements NativePage {
|
| return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT);
|
| }
|
|
|
| - private static Intent createListUrlsIntent(Context context) {
|
| - Intent intent = new Intent(context, ListUrlsActivity.class);
|
| - intent.putExtra(ListUrlsActivity.REFERER_KEY, ListUrlsActivity.DIAGNOSTICS_REFERER);
|
| - return intent;
|
| + private static Intent createListUrlsIntent() {
|
| + return new Intent(ContextUtils.getApplicationContext(), ListUrlsActivity.class)
|
| + .putExtra(ListUrlsActivity.REFERER_KEY, ListUrlsActivity.DIAGNOSTICS_REFERER);
|
| }
|
|
|
| private static String colorToHexValue(int color) {
|
| return "#" + Integer.toHexString(color & 0x00ffffff);
|
| }
|
| -
|
| - // NativePage overrides
|
| -
|
| - @Override
|
| - public void destroy() {
|
| - // nothing to do
|
| - }
|
| -
|
| - @Override
|
| - public String getUrl() {
|
| - return UrlConstants.PHYSICAL_WEB_URL;
|
| - }
|
| -
|
| - @Override
|
| - public String getTitle() {
|
| - return "Physical Web Diagnostics";
|
| - }
|
| -
|
| - @Override
|
| - public int getBackgroundColor() {
|
| - return mBackgroundColor;
|
| - }
|
| -
|
| - @Override
|
| - public int getThemeColor() {
|
| - return mThemeColor;
|
| - }
|
| -
|
| - @Override
|
| - public boolean needsToolbarShadow() {
|
| - return true;
|
| - }
|
| -
|
| - @Override
|
| - public View getView() {
|
| - return mPageView;
|
| - }
|
| -
|
| - @Override
|
| - public String getHost() {
|
| - return UrlConstants.PHYSICAL_WEB_HOST;
|
| - }
|
| -
|
| - @Override
|
| - public void updateForUrl(String url) {
|
| - // nothing to do
|
| - }
|
| }
|
|
|