OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.locale; | |
6 | |
7 import android.app.Dialog; | |
8 import android.content.Context; | |
9 import android.content.Intent; | |
10 import android.os.Bundle; | |
11 import android.text.SpannableString; | |
12 import android.text.method.LinkMovementMethod; | |
13 import android.text.style.ClickableSpan; | |
14 import android.view.View; | |
15 import android.widget.TextView; | |
16 | |
17 import org.chromium.chrome.R; | |
18 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | |
19 import org.chromium.chrome.browser.preferences.SearchEnginePreference; | |
20 import org.chromium.ui.text.NoUnderlineClickableSpan; | |
21 import org.chromium.ui.text.SpanApplier; | |
22 import org.chromium.ui.text.SpanApplier.SpanInfo; | |
23 | |
24 /** | |
25 * A promotion dialog showing that the default search provider will be set to So gou. | |
26 */ | |
27 public class SearchEnginePromoDialog extends Dialog implements View.OnClickListe ner { | |
28 | |
29 private LocaleManager mLocaleManager; | |
30 private ClickableSpan mSpan = new NoUnderlineClickableSpan() { | |
Maria
2016/10/01 00:00:46
final
Ian Wen
2016/10/03 17:05:37
Done.
| |
31 @Override | |
32 public void onClick(View widget) { | |
33 Intent intent = PreferencesLauncher.createIntentForSettingsPage(getC ontext(), | |
34 SearchEnginePreference.class.getName()); | |
35 getContext().startActivity(intent); | |
36 } | |
37 }; | |
38 | |
39 /** | |
40 * Creates an instance of the dialog. | |
41 */ | |
42 public SearchEnginePromoDialog(Context context, LocaleManager localeManager) { | |
43 super(context, R.style.SimpleDialog); | |
44 mLocaleManager = localeManager; | |
45 } | |
46 | |
47 @Override | |
48 protected void onCreate(Bundle savedInstanceState) { | |
49 // Specificaly disable auto reconstruction of the dialog. | |
50 if (savedInstanceState != null) { | |
51 dismiss(); | |
Maria
2016/10/01 00:00:46
so the dialog won't work in landscape mode?
Ian Wen
2016/10/03 17:05:37
It will work if orientation changes because Chrome
Maria
2016/10/04 03:42:22
Can you mention this in the comment above?
| |
52 return; | |
53 } | |
54 setContentView(R.layout.search_engine_promo); | |
55 | |
56 View keepGoogleButton = findViewById(R.id.keep_google_button); | |
57 View okButton = findViewById(R.id.ok_button); | |
58 keepGoogleButton.setOnClickListener(this); | |
59 okButton.setOnClickListener(this); | |
60 | |
61 TextView textView = (TextView) findViewById(R.id.description); | |
62 SpannableString description = SpanApplier.applySpans( | |
63 getContext().getString(R.string.sogou_explanation), | |
64 new SpanInfo("<link>", "</link>", mSpan)); | |
65 textView.setText(description); | |
66 textView.setMovementMethod(LinkMovementMethod.getInstance()); | |
67 } | |
68 | |
69 @Override | |
70 public void onClick(View view) { | |
71 if (view.getId() == R.id.keep_google_button) { | |
72 keepGoogle(); | |
73 } else if (view.getId() == R.id.ok_button) { | |
74 useSogou(); | |
75 } | |
76 dismiss(); | |
77 } | |
78 | |
79 private void keepGoogle() { | |
80 mLocaleManager.addSpecialSearchEngines(); | |
81 // TODO(ianwen): Disable search engine auto switching here. | |
82 } | |
83 | |
84 private void useSogou() { | |
85 mLocaleManager.addSpecialSearchEngines(); | |
86 mLocaleManager.overrideDefaultSearchEngine(); | |
87 } | |
88 } | |
OLD | NEW |