Commit afec1c91 authored by ianwen's avatar ianwen Committed by Commit bot

Show search engine promo dialog for special locale

In some locales we will set Sogou as default search engine. This CL adds
a dialog to notify the users of such change.

BUG=638062

Review-Url: https://codereview.chromium.org/2380133002
Cr-Commit-Position: refs/heads/master@{#422891}
parent d38f6b0a
...@@ -375,7 +375,7 @@ by a child template that "extends" this file. ...@@ -375,7 +375,7 @@ by a child template that "extends" this file.
android:autoRemoveFromRecents="true"> android:autoRemoveFromRecents="true">
</activity> </activity>
<activity android:name="org.chromium.chrome.browser.firstrun.LightweightFirstRunActivity" <activity android:name="org.chromium.chrome.browser.firstrun.LightweightFirstRunActivity"
android:theme="@style/LightweightFreDialog" android:theme="@style/SimpleDialog"
android:launchMode="singleTop" android:launchMode="singleTop"
android:autoRemoveFromRecents="true" android:autoRemoveFromRecents="true"
android:windowSoftInputMode="stateHidden|adjustPan" android:windowSoftInputMode="stateHidden|adjustPan"
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 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. -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:chrome="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FAFAFA" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="20dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="22dp"
android:contentDescription="@null"
android:src="@drawable/search_sogou" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:text="@string/search_with_sogou"
android:textColor="@color/default_text_color"
android:textSize="16sp" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:lineSpacingMultiplier="1.3"
android:textColor="#646464"
android:textSize="14sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:gravity="end"
android:orientation="horizontal" >
<Button
android:id="@+id/keep_google_button"
style="@style/ButtonCompatBorderless"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:minHeight="40dp"
android:text="@string/keep_google"
android:textAllCaps="true"
android:textColor="@color/light_active_color"
android:textSize="13sp" />
<org.chromium.ui.widget.ButtonCompat
android:id="@+id/ok_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:elevation="0dp"
android:minHeight="30dp"
android:text="@string/ok"
android:textAllCaps="true"
android:textColor="#FFFFFF"
android:textSize="13sp"
chrome:buttonColor="@color/light_active_color"
chrome:buttonRaised="false" />
</LinearLayout>
</LinearLayout>
</ScrollView>
\ No newline at end of file
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
<item name="tint">@color/dark_mode_tint</item> <item name="tint">@color/dark_mode_tint</item>
</style> </style>
<style name="LightweightFreDialog" parent="AlertDialogTheme"> <style name="SimpleDialog" parent="AlertDialogTheme">
<item name="windowNoTitle">true</item> <item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
</style> </style>
......
...@@ -63,6 +63,7 @@ import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor; ...@@ -63,6 +63,7 @@ import org.chromium.chrome.browser.firstrun.FirstRunSignInProcessor;
import org.chromium.chrome.browser.firstrun.FirstRunStatus; import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.incognito.IncognitoNotificationManager; import org.chromium.chrome.browser.incognito.IncognitoNotificationManager;
import org.chromium.chrome.browser.infobar.DataReductionPromoInfoBar; import org.chromium.chrome.browser.infobar.DataReductionPromoInfoBar;
import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.metrics.ActivityStopMetrics; import org.chromium.chrome.browser.metrics.ActivityStopMetrics;
import org.chromium.chrome.browser.metrics.LaunchMetrics; import org.chromium.chrome.browser.metrics.LaunchMetrics;
import org.chromium.chrome.browser.metrics.StartupMetrics; import org.chromium.chrome.browser.metrics.StartupMetrics;
...@@ -202,6 +203,8 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -202,6 +203,8 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
private Boolean mIsAccessibilityEnabled; private Boolean mIsAccessibilityEnabled;
private LocaleManager mLocaleManager;
/** /**
* Keeps track of whether or not a specific tab was created based on the startup intent. * Keeps track of whether or not a specific tab was created based on the startup intent.
*/ */
...@@ -347,6 +350,10 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -347,6 +350,10 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
int incognitoCount = TabWindowManager.getInstance().getIncognitoTabCount(); int incognitoCount = TabWindowManager.getInstance().getIncognitoTabCount();
if (incognitoCount == 0) IncognitoNotificationManager.dismissIncognitoNotification(); if (incognitoCount == 0) IncognitoNotificationManager.dismissIncognitoNotification();
// LocaleManager can only function after the native library is loaded.
mLocaleManager = LocaleManager.getInstance();
mLocaleManager.showSearchEnginePromoIfNeeded(this);
super.finishNativeInitialization(); super.finishNativeInitialization();
} finally { } finally {
TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization"); TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization");
...@@ -523,6 +530,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -523,6 +530,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
// This assumes that the keyboard can not be seen at the same time as the // This assumes that the keyboard can not be seen at the same time as the
// newtab button on the toolbar. // newtab button on the toolbar.
getCurrentTabCreator().launchNTP(); getCurrentTabCreator().launchNTP();
mLocaleManager.showSearchEnginePromoIfNeeded(ChromeTabbedActivity.this);
} }
}; };
OnClickListener bookmarkClickHandler = new OnClickListener() { OnClickListener bookmarkClickHandler = new OnClickListener() {
...@@ -653,6 +661,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -653,6 +661,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
mIsOnFirstRun = false; mIsOnFirstRun = false;
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
refreshSignIn(); refreshSignIn();
mLocaleManager.showSearchEnginePromoIfNeeded(this);
} else { } else {
if (data != null && data.getBooleanExtra( if (data != null && data.getBooleanExtra(
FirstRunActivity.RESULT_CLOSE_APP, false)) { FirstRunActivity.RESULT_CLOSE_APP, false)) {
...@@ -1031,6 +1040,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -1031,6 +1040,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
RecordUserAction.record("MobileNewTabOpened"); RecordUserAction.record("MobileNewTabOpened");
reportNewTabShortcutUsed(false); reportNewTabShortcutUsed(false);
getTabCreator(false).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI); getTabCreator(false).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
mLocaleManager.showSearchEnginePromoIfNeeded(this);
} else if (id == R.id.new_incognito_tab_menu_id) { } else if (id == R.id.new_incognito_tab_menu_id) {
if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) { if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
getTabModelSelector().getModel(false).commitAllTabClosures(); getTabModelSelector().getModel(false).commitAllTabClosures();
......
...@@ -76,7 +76,6 @@ public class DeferredStartupHandler { ...@@ -76,7 +76,6 @@ public class DeferredStartupHandler {
private long mDeferredStartupDuration; private long mDeferredStartupDuration;
private long mMaxTaskDuration; private long mMaxTaskDuration;
private final Context mAppContext; private final Context mAppContext;
private final LocaleManager mLocaleManager;
private final Queue<Runnable> mDeferredTasks; private final Queue<Runnable> mDeferredTasks;
...@@ -91,7 +90,6 @@ public class DeferredStartupHandler { ...@@ -91,7 +90,6 @@ public class DeferredStartupHandler {
private DeferredStartupHandler() { private DeferredStartupHandler() {
mAppContext = ContextUtils.getApplicationContext(); mAppContext = ContextUtils.getApplicationContext();
mDeferredTasks = new LinkedList<>(); mDeferredTasks = new LinkedList<>();
mLocaleManager = ((ChromeApplication) mAppContext).createLocaleManager();
} }
/** /**
...@@ -138,7 +136,7 @@ public class DeferredStartupHandler { ...@@ -138,7 +136,7 @@ public class DeferredStartupHandler {
"UMA.Debug.EnableCrashUpload.DeferredStartUpCompleteTime", "UMA.Debug.EnableCrashUpload.DeferredStartUpCompleteTime",
SystemClock.uptimeMillis() - UmaUtils.getForegroundStartTime(), SystemClock.uptimeMillis() - UmaUtils.getForegroundStartTime(),
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
mLocaleManager.recordStartupMetrics(); LocaleManager.getInstance().recordStartupMetrics();
} }
/** /**
......
...@@ -4,16 +4,37 @@ ...@@ -4,16 +4,37 @@
package org.chromium.chrome.browser.locale; package org.chromium.chrome.browser.locale;
import android.content.Context;
import android.content.SharedPreferences;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
/** /**
* Manager for some locale specific logics. * Manager for some locale specific logics.
*/ */
public class LocaleManager { public class LocaleManager {
public static final String PREF_PROMO_SHOWN = "LocaleManager_PREF_PROMO_SHOWN";
public static final String SPECIAL_LOCALE_ID = "US"; public static final String SPECIAL_LOCALE_ID = "US";
private static LocaleManager sInstance;
private SpecialLocaleHandler mLocaleHandler; private SpecialLocaleHandler mLocaleHandler;
/**
* @return An instance of the {@link LocaleManager}. This should only be called on UI thread.
*/
public static LocaleManager getInstance() {
assert ThreadUtils.runningOnUiThread();
if (sInstance == null) {
sInstance = ((ChromeApplication) ContextUtils.getApplicationContext())
.createLocaleManager();
}
return sInstance;
}
/** /**
* Starts recording metrics in deferred startup. * Starts recording metrics in deferred startup.
*/ */
...@@ -52,7 +73,6 @@ public class LocaleManager { ...@@ -52,7 +73,6 @@ public class LocaleManager {
* no-op if the user has changed DSP settings before. * no-op if the user has changed DSP settings before.
*/ */
public void overrideDefaultSearchEngine() { public void overrideDefaultSearchEngine() {
// TODO(ianwen): Let this method be called in promotion.
// TODO(ianwen): Implement search engine auto switching. // TODO(ianwen): Implement search engine auto switching.
if (!isSpecialLocaleEnabled()) return; if (!isSpecialLocaleEnabled()) return;
getSpecialLocaleHandler().overrideDefaultSearchProvider(); getSpecialLocaleHandler().overrideDefaultSearchProvider();
...@@ -67,6 +87,25 @@ public class LocaleManager { ...@@ -67,6 +87,25 @@ public class LocaleManager {
getSpecialLocaleHandler().removeTemplateUrls(); getSpecialLocaleHandler().removeTemplateUrls();
} }
/**
* Shows a promotion dialog saying the default search engine will be set to Sogou. No-op if
* device is not in special locale.
*
* @return Whether such dialog is needed.
*/
public boolean showSearchEnginePromoIfNeeded(Context context) {
if (!isSpecialLocaleEnabled()) return false;
SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
if (preferences.getBoolean(PREF_PROMO_SHOWN, false)) {
return false;
}
new SearchEnginePromoDialog(context, this).show();
preferences.edit().putBoolean(PREF_PROMO_SHOWN, true).apply();
return true;
}
/** /**
* Does some extra checking about whether the user is in special locale. * Does some extra checking about whether the user is in special locale.
* @param inSpecialLocale Whether the variation service thinks the client is in special locale. * @param inSpecialLocale Whether the variation service thinks the client is in special locale.
......
// Copyright 2016 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.chrome.browser.locale;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.SearchEnginePreference;
import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.text.SpanApplier;
import org.chromium.ui.text.SpanApplier.SpanInfo;
/**
* A promotion dialog showing that the default search provider will be set to Sogou.
*/
public class SearchEnginePromoDialog extends Dialog implements View.OnClickListener {
private final LocaleManager mLocaleManager;
private final ClickableSpan mSpan = new NoUnderlineClickableSpan() {
@Override
public void onClick(View widget) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(getContext(),
SearchEnginePreference.class.getName());
getContext().startActivity(intent);
}
};
/**
* Creates an instance of the dialog.
*/
public SearchEnginePromoDialog(Context context, LocaleManager localeManager) {
super(context, R.style.SimpleDialog);
mLocaleManager = localeManager;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// Do not allow this dialog to be reconstructed because it requires native side loaded.
if (savedInstanceState != null) {
dismiss();
return;
}
setContentView(R.layout.search_engine_promo);
View keepGoogleButton = findViewById(R.id.keep_google_button);
View okButton = findViewById(R.id.ok_button);
keepGoogleButton.setOnClickListener(this);
okButton.setOnClickListener(this);
TextView textView = (TextView) findViewById(R.id.description);
SpannableString description = SpanApplier.applySpans(
getContext().getString(R.string.sogou_explanation),
new SpanInfo("<link>", "</link>", mSpan));
textView.setText(description);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.keep_google_button) {
keepGoogle();
} else if (view.getId() == R.id.ok_button) {
useSogou();
}
dismiss();
}
private void keepGoogle() {
mLocaleManager.addSpecialSearchEngines();
// TODO(ianwen): Disable search engine auto switching here.
}
private void useSogou() {
mLocaleManager.addSpecialSearchEngines();
mLocaleManager.overrideDefaultSearchEngine();
}
}
...@@ -2593,6 +2593,17 @@ You can control the Physical Web in Chrome Settings. ...@@ -2593,6 +2593,17 @@ You can control the Physical Web in Chrome Settings.
Tap this button for quick access to your tabs. Tap this button for quick access to your tabs.
</message> </message>
<!-- Special locale UI strings -->
<message name="IDS_SEARCH_WITH_SOGOU" desc="Text telling the user that the search engine will be switched to Sogou.">
Search with Sogou
</message>
<message name="IDS_SOGOU_EXPLANATION" desc="Text explaining why Sogou should be used as default search engine.">
Chrome can use Sogou for search in China. You can change this in <ph name="BEGIN_LINK">&lt;link&gt;</ph>Settings<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>
<message name="IDS_KEEP_GOOGLE" desc="Text representing the option that the user wants to keep Google as the default search engine.">
Keep Google
</message>
<!-- Item Chooser UI strings --> <!-- Item Chooser UI strings -->
<message name="IDS_ITEM_CHOOSER_ITEM_NAME_WITH_ID" desc="To distinguish items with the same name, the item chooser shows the item name with id."> <message name="IDS_ITEM_CHOOSER_ITEM_NAME_WITH_ID" desc="To distinguish items with the same name, the item chooser shows the item name with id.">
<ph name="ITEM_NAME">%1$s<ex>item_name</ex></ph> (<ph name="ITEM_ID">%2$s<ex>item id</ex></ph>) <ph name="ITEM_NAME">%1$s<ex>item_name</ex></ph> (<ph name="ITEM_ID">%2$s<ex>item id</ex></ph>)
......
...@@ -449,6 +449,7 @@ chrome_java_sources = [ ...@@ -449,6 +449,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java", "java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java",
"java/src/org/chromium/chrome/browser/invalidation/UniqueIdInvalidationClientNameGenerator.java", "java/src/org/chromium/chrome/browser/invalidation/UniqueIdInvalidationClientNameGenerator.java",
"java/src/org/chromium/chrome/browser/locale/LocaleManager.java", "java/src/org/chromium/chrome/browser/locale/LocaleManager.java",
"java/src/org/chromium/chrome/browser/locale/SearchEnginePromoDialog.java",
"java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java", "java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java",
"java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java", "java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java",
"java/src/org/chromium/chrome/browser/media/cdm/MediaDrmCredentialManager.java", "java/src/org/chromium/chrome/browser/media/cdm/MediaDrmCredentialManager.java",
......
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