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 3// found in the LICENSE file. 4package org.chromium.chrome.browser.infobar; 5 6import android.content.Context; 7import android.widget.CheckBox; 8import android.widget.CompoundButton; 9 10import org.chromium.chrome.R; 11 12/** 13 * A check box used to determine if a page should always be translated. 14 */ 15public class TranslateCheckBox { 16 private final SubPanelListener mListener; 17 private final TranslateOptions mOptions; 18 19 public TranslateCheckBox(TranslateOptions options, SubPanelListener listener) { 20 mOptions = options; 21 mListener = listener; 22 } 23 24 public void createContent(Context context, InfoBarLayout layout) { 25 CheckBox checkBox = new CheckBox(context); 26 checkBox.setId(R.id.infobar_extra_check); 27 checkBox.setText(context.getString(R.string.translate_always_text, 28 mOptions.sourceLanguage())); 29 checkBox.setChecked(mOptions.alwaysTranslateLanguageState()); 30 checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 31 @Override 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 } 43} 44