Commit ddfdd7ae authored by cco3's avatar cco3 Committed by Commit bot

Use BasicNativePage in PhysicalWebDiagnostics

The recently created BasicNativePage is perfect for
chrome://physical-web.  Moreover, it gets rid of a nasty bug which
displays things poorly on tablets.

BUG=639349

Review-Url: https://codereview.chromium.org/2261883002
Cr-Commit-Position: refs/heads/master@{#413476}
parent 1329d0ac
......@@ -52,8 +52,8 @@ public class NativePageFactory {
return new RecentTabsPage(activity, recentTabsManager);
}
protected NativePage buildPhysicalWebDiagnosticsPage(Activity activity) {
return new PhysicalWebDiagnosticsPage(activity);
protected NativePage buildPhysicalWebDiagnosticsPage(Activity activity, Tab tab) {
return new PhysicalWebDiagnosticsPage(activity, tab);
}
}
......@@ -137,7 +137,7 @@ public class NativePageFactory {
page = sNativePageBuilder.buildRecentTabsPage(activity, tab);
break;
case PHYSICAL_WEB:
page = sNativePageBuilder.buildPhysicalWebDiagnosticsPage(activity);
page = sNativePageBuilder.buildPhysicalWebDiagnosticsPage(activity, tab);
break;
default:
assert false;
......
......@@ -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
}
}
......@@ -233,9 +233,9 @@ public class PhysicalWebUma {
handleEnum(context, createStateString(LOCATION_PERMISSION, actionName),
locationUtils.hasAndroidLocationPermission() ? 1 : 0, BOOLEAN_BOUNDARY);
handleEnum(context, createStateString(BLUETOOTH, actionName),
Utils.getBluetoothEnabledStatus(context), TRISTATE_BOUNDARY);
Utils.getBluetoothEnabledStatus(), TRISTATE_BOUNDARY);
handleEnum(context, createStateString(DATA_CONNECTION, actionName),
Utils.isDataConnectionActive(context) ? 1 : 0, BOOLEAN_BOUNDARY);
Utils.isDataConnectionActive() ? 1 : 0, BOOLEAN_BOUNDARY);
int preferenceState = 2;
if (!PhysicalWeb.isOnboarding()) {
preferenceState = PhysicalWeb.isPhysicalWebPreferenceEnabled() ? 1 : 0;
......
......@@ -11,6 +11,8 @@ import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.support.v4.content.PermissionChecker;
import org.chromium.base.ContextUtils;
/**
* This class provides basic static utilities for the Physical Web.
......@@ -20,21 +22,22 @@ class Utils {
public static final int RESULT_SUCCESS = 1;
public static final int RESULT_INDETERMINATE = 2;
public static boolean isDataConnectionActive(Context context) {
ConnectivityManager cm =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
public static boolean isDataConnectionActive() {
ConnectivityManager cm = (ConnectivityManager) ContextUtils.getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
return (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isConnectedOrConnecting());
}
public static boolean isBluetoothPermissionGranted(Context context) {
return PermissionChecker.checkSelfPermission(context, Manifest.permission.BLUETOOTH)
public static boolean isBluetoothPermissionGranted() {
return PermissionChecker.checkSelfPermission(
ContextUtils.getApplicationContext(), Manifest.permission.BLUETOOTH)
== PackageManager.PERMISSION_GRANTED;
}
public static int getBluetoothEnabledStatus(Context context) {
public static int getBluetoothEnabledStatus() {
int statusResult = RESULT_INDETERMINATE;
if (isBluetoothPermissionGranted(context)) {
if (isBluetoothPermissionGranted()) {
BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter();
statusResult = (bt != null && bt.isEnabled()) ? RESULT_SUCCESS : RESULT_FAILURE;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment