abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java
blob: d0734b915b647dbceee454a82de0f38b018dcce1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package juloo.keyboard2;

import android.content.Context;
import android.content.res.TypedArray;
import android.content.SharedPreferences;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import java.util.HashSet;
import java.util.Set;

public class ExtraKeyCheckBoxPreference extends CheckBoxPreference
{
  public static String[] extra_keys = new String[]
  {
    "alt",
    "meta",
    "accent_aigu",
    "accent_grave",
    "accent_double_aigu",
    "accent_dot_above",
    "accent_circonflexe",
    "accent_tilde",
    "accent_cedille",
    "accent_trema",
    "accent_ring",
    "accent_caron",
    "accent_macron",
    "accent_ogonek",
    "accent_breve",
    "€",
    "ß",
    "£",
    "switch_greekmath",
  };

  public static boolean default_checked(String name)
  {
    switch (name)
    {
      case "alt":
      case "meta":
        return true;
      default:
        return false;
    }
  }

  boolean _key_font;

  public ExtraKeyCheckBoxPreference(Context context, AttributeSet attrs)
  {
    super(context, attrs);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ExtraKeyCheckBoxPreference);
    int index = a.getInteger(R.styleable.ExtraKeyCheckBoxPreference_index, 0);
    a.recycle();
    String key_name = extra_keys[index];
    setKey(pref_key_of_key_name(key_name));
    setDefaultValue(default_checked(key_name));
    KeyValue kv = KeyValue.getKeyByName(key_name);
    setTitle(kv.getString());
    _key_font = kv.hasFlags(KeyValue.FLAG_KEY_FONT);
  }

  @Override
  protected void onBindView(View view)
  {
    super.onBindView(view);
    TextView title = (TextView)view.findViewById(android.R.id.title);
    title.setTypeface(_key_font ? Theme.getKeyFont(getContext()) : null);
  }

  static String pref_key_of_key_name(String key_name)
  {
    return "extra_key_" + key_name;
  }

  public static Set<KeyValue> get_extra_keys(SharedPreferences prefs)
  {
    HashSet<KeyValue> ks = new HashSet<KeyValue>();
    for (String key_name : extra_keys)
    {
      if (prefs.getBoolean(pref_key_of_key_name(key_name), default_checked(key_name)))
        ks.add(KeyValue.getKeyByName(key_name));
    }
    return ks;
  }
}