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