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; 9import android.widget.CompoundButton.OnCheckedChangeListener; 10 11import org.chromium.chrome.R; 12 13/** 14 * A check box used to determine if a page should always be translated. 15 */ 16public class TranslateCheckBox extends CheckBox implements OnCheckedChangeListener { 17 private static final int TEXT_SIZE_SP = 13; 18 19 private final SubPanelListener mListener; 20 private final TranslateOptions mOptions; 21 22 public TranslateCheckBox(Context context, TranslateOptions options, SubPanelListener listener) { 23 super(context); 24 mOptions = options; 25 mListener = listener; 26 27 setId(R.id.infobar_extra_check); 28 setText(context.getString(R.string.translate_always_text, mOptions.sourceLanguage())); 29 setTextColor(context.getResources().getColor(R.color.infobar_text)); 30 setTextSize(TEXT_SIZE_SP); 31 setChecked(mOptions.alwaysTranslateLanguageState()); 32 setOnCheckedChangeListener(this); 33 } 34 35 @Override 36 public void onCheckedChanged(CompoundButton view, boolean isChecked) { 37 mOptions.toggleAlwaysTranslateLanguageState(isChecked); 38 if (isChecked) { 39 mListener.onPanelClosed(InfoBar.ACTION_TYPE_NONE); 40 } else { 41 mListener.onOptionsChanged(); 42 } 43 } 44} 45