Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / infobar / TranslateCheckBox.java
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.
4 package org.chromium.chrome.browser.infobar;
5
6 import android.content.Context;
7 import android.widget.CheckBox;
8 import android.widget.CompoundButton;
9 import android.widget.CompoundButton.OnCheckedChangeListener;
10
11 import org.chromium.chrome.R;
12
13 /**
14  * A check box used to determine if a page should always be translated.
15  */
16 public 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.default_text_color));
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 }