Add set default browser option in settings
This commit is contained in:
@@ -6,6 +6,16 @@
|
||||
package org.chromium.chrome.browser;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.chromium.base.CommandLine;
|
||||
import org.chromium.base.ContextUtils;
|
||||
@@ -17,6 +27,7 @@ import org.chromium.chrome.browser.preferences.BraveSearchEngineUtils;
|
||||
import org.chromium.chrome.browser.preferences.Pref;
|
||||
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
|
||||
import org.chromium.chrome.browser.tab.Tab;
|
||||
import org.chromium.ui.widget.Toast;
|
||||
|
||||
/**
|
||||
* Brave's extension for ChromeActivity
|
||||
@@ -25,6 +36,12 @@ import org.chromium.chrome.browser.tab.Tab;
|
||||
public abstract class BraveActivity extends ChromeActivity {
|
||||
private static final String PREF_CLOSE_TABS_ON_EXIT = "close_tabs_on_exit";
|
||||
|
||||
/**
|
||||
* Settings for sending local notification reminders.
|
||||
*/
|
||||
public static final String BRAVE_PRODUCTION_PACKAGE_NAME = "com.brave.browser";
|
||||
public static final String BRAVE_DEVELOPMENT_PACKAGE_NAME = "com.brave.browser_default";
|
||||
|
||||
@Override
|
||||
public void onResumeWithNative() {
|
||||
super.onResumeWithNative();
|
||||
@@ -51,7 +68,7 @@ public abstract class BraveActivity extends ChromeActivity {
|
||||
} else if (id == R.id.exit_id) {
|
||||
ApplicationLifetime.terminate(false);
|
||||
} else if (id == R.id.set_default_browser) {
|
||||
// Implement handler.
|
||||
handleBraveSetDefaultBrowserDialog();
|
||||
} else if (id == R.id.brave_rewards_id) {
|
||||
// Implement handler.
|
||||
} else {
|
||||
@@ -103,5 +120,69 @@ public abstract class BraveActivity extends ChromeActivity {
|
||||
return ContextUtils.getAppSharedPreferences().getBoolean(PREF_CLOSE_TABS_ON_EXIT, false);
|
||||
}
|
||||
|
||||
public boolean isBraveSetAsDefaultBrowser() {
|
||||
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));
|
||||
boolean supportsDefault = Build.VERSION.SDK_INT >= 24;
|
||||
ResolveInfo resolveInfo = getPackageManager().resolveActivity(
|
||||
browserIntent, supportsDefault ? PackageManager.MATCH_DEFAULT_ONLY : 0);
|
||||
return resolveInfo.activityInfo.packageName.equals(BRAVE_PRODUCTION_PACKAGE_NAME)
|
||||
|| resolveInfo.activityInfo.packageName.equals(BRAVE_DEVELOPMENT_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
private void handleBraveSetDefaultBrowserDialog() {
|
||||
/* (Albert Wang): Default app settings didn't get added until API 24
|
||||
* https://developer.android.com/reference/android/provider/Settings#ACTION_MANAGE_DEFAULT_APPS_SETTINGS
|
||||
*/
|
||||
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));
|
||||
boolean supportsDefault = Build.VERSION.SDK_INT >= 24;
|
||||
ResolveInfo resolveInfo = getPackageManager().resolveActivity(
|
||||
browserIntent, supportsDefault ? PackageManager.MATCH_DEFAULT_ONLY : 0);
|
||||
Context context = ContextUtils.getApplicationContext();
|
||||
if (isBraveSetAsDefaultBrowser()) {
|
||||
Toast toast = Toast.makeText(
|
||||
context, R.string.brave_already_set_as_default_browser, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
return;
|
||||
}
|
||||
if (supportsDefault) {
|
||||
if (resolveInfo.activityInfo.packageName.equals("com.google.android.setupwizard")
|
||||
|| resolveInfo.activityInfo.packageName.equals("android")) {
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
View layout = inflater.inflate(R.layout.brave_set_default_browser_dialog,
|
||||
(ViewGroup) findViewById(R.id.brave_set_default_browser_toast_container));
|
||||
|
||||
Toast toast = new Toast(context);
|
||||
toast.setDuration(Toast.LENGTH_LONG);
|
||||
toast.setView(layout);
|
||||
toast.setGravity(Gravity.TOP, 0, 40);
|
||||
toast.show();
|
||||
Intent intent =
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.brave.com/blog"));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
} else {
|
||||
if (resolveInfo.activityInfo.packageName.equals("com.google.android.setupwizard")
|
||||
|| resolveInfo.activityInfo.packageName.equals("android")) {
|
||||
// (Albert Wang): From what I've experimented on 6.0,
|
||||
// default browser popup is in the middle of the screen for
|
||||
// these versions. So we shouldn't show the toast.
|
||||
Intent intent =
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.brave.com/blog"));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(
|
||||
context, R.string.brave_default_browser_go_to_settings, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private native void nativeRestartStatsUpdater();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/brave_set_default_browser_toast_container"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="8dp"
|
||||
android:background="#FFF">
|
||||
<ImageView
|
||||
android:src="@drawable/btn_brave"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
tools:ignore="ContentDescription"/>
|
||||
<TextView
|
||||
android:text="@string/brave_set_default_browser_dialog_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#222"/>
|
||||
</LinearLayout>
|
||||
@@ -231,6 +231,15 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
|
||||
<message name="IDS_MENU_SET_DEFAULT_BROWSER" desc="Title for set default browser menu item">
|
||||
Set as default browser
|
||||
</message>
|
||||
<message name="IDS_BRAVE_SET_DEFAULT_BROWSER_DIALOG_TEXT" desc="Dialog for setting default browser">
|
||||
Select Brave Browser from the list and tap 'Always'
|
||||
</message>
|
||||
<message name="IDS_BRAVE_ALREADY_SET_AS_DEFAULT_BROWSER" desc="Toast message for those whom have already set Brave as default browser">
|
||||
Brave is already set as your default browser.
|
||||
</message>
|
||||
<message name="IDS_BRAVE_DEFAULT_BROWSER_GO_TO_SETTINGS" desc="Toast message for those without 7.0 to go to settings to change default browser">
|
||||
You've already set a default browser. You may change the default browser in your app settings.
|
||||
</message>
|
||||
<message name="IDS_MENU_BRAVE_REWARDS" desc="Title for brave rewards menu item">
|
||||
Brave Rewards
|
||||
</message>
|
||||
|
||||
Reference in New Issue
Block a user