| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 package org.chromium.chrome.browser.infobar; | 4 package org.chromium.chrome.browser.infobar; |
| 5 | 5 |
| 6 import android.content.Context; | 6 import android.content.Context; |
| 7 import android.widget.CheckBox; | 7 import android.widget.CheckBox; |
| 8 import android.widget.CompoundButton; | 8 import android.widget.CompoundButton; |
| 9 import android.widget.CompoundButton.OnCheckedChangeListener; |
| 9 | 10 |
| 10 import org.chromium.chrome.R; | 11 import org.chromium.chrome.R; |
| 11 | 12 |
| 12 /** | 13 /** |
| 13 * A check box used to determine if a page should always be translated. | 14 * A check box used to determine if a page should always be translated. |
| 14 */ | 15 */ |
| 15 public class TranslateCheckBox { | 16 public class TranslateCheckBox extends CheckBox implements OnCheckedChangeListen
er { |
| 16 private final SubPanelListener mListener; | 17 private final SubPanelListener mListener; |
| 17 private final TranslateOptions mOptions; | 18 private final TranslateOptions mOptions; |
| 18 | 19 |
| 19 public TranslateCheckBox(TranslateOptions options, SubPanelListener listener
) { | 20 public TranslateCheckBox(Context context, TranslateOptions options, SubPanel
Listener listener) { |
| 21 super(context); |
| 20 mOptions = options; | 22 mOptions = options; |
| 21 mListener = listener; | 23 mListener = listener; |
| 24 |
| 25 setId(R.id.infobar_extra_check); |
| 26 setText(context.getString(R.string.translate_always_text, mOptions.sourc
eLanguage())); |
| 27 setChecked(mOptions.alwaysTranslateLanguageState()); |
| 28 setOnCheckedChangeListener(this); |
| 22 } | 29 } |
| 23 | 30 |
| 24 public void createContent(Context context, InfoBarLayout layout) { | 31 @Override |
| 25 CheckBox checkBox = new CheckBox(context); | 32 public void onCheckedChanged(CompoundButton view, boolean isChecked) { |
| 26 checkBox.setId(R.id.infobar_extra_check); | 33 mOptions.toggleAlwaysTranslateLanguageState(isChecked); |
| 27 checkBox.setText(context.getString(R.string.translate_always_text, | 34 if (isChecked) { |
| 28 mOptions.sourceLanguage())); | 35 mListener.onPanelClosed(InfoBar.ACTION_TYPE_NONE); |
| 29 checkBox.setChecked(mOptions.alwaysTranslateLanguageState()); | 36 } else { |
| 30 checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeLi
stener() { | 37 mListener.onOptionsChanged(); |
| 31 @Override | 38 } |
| 32 public void onCheckedChanged(CompoundButton view, boolean isChecked)
{ | |
| 33 mOptions.toggleAlwaysTranslateLanguageState(isChecked); | |
| 34 if (isChecked) { | |
| 35 mListener.onPanelClosed(InfoBar.ACTION_TYPE_NONE); | |
| 36 } else { | |
| 37 mListener.onOptionsChanged(); | |
| 38 } | |
| 39 } | |
| 40 }); | |
| 41 layout.addGroup(checkBox); | |
| 42 } | 39 } |
| 43 } | 40 } |
| OLD | NEW |