2023-07-09 18:06:12 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.preference.CheckBoxPreference;
|
2023-07-12 18:35:16 +02:00
|
|
|
import android.preference.PreferenceCategory;
|
2023-07-09 18:06:12 +02:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.TextView;
|
2023-09-15 18:00:27 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2023-07-09 18:06:12 +02:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
/** This class implements the "extra keys" preference but also defines the
|
|
|
|
possible extra keys. */
|
2023-07-12 18:35:16 +02:00
|
|
|
public class ExtraKeysPreference extends PreferenceCategory
|
2023-07-09 18:06:12 +02:00
|
|
|
{
|
2023-08-05 16:45:57 +02:00
|
|
|
/** Array of the keys that can be selected. */
|
2023-07-09 18:06:12 +02:00
|
|
|
public static String[] extra_keys = new String[]
|
|
|
|
{
|
|
|
|
"alt",
|
|
|
|
"meta",
|
|
|
|
"voice_typing",
|
|
|
|
"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",
|
|
|
|
"accent_slash",
|
|
|
|
"accent_bar",
|
|
|
|
"accent_dot_below",
|
|
|
|
"accent_hook_above",
|
|
|
|
"accent_horn",
|
|
|
|
"€",
|
|
|
|
"ß",
|
|
|
|
"£",
|
2023-07-29 18:42:20 +02:00
|
|
|
"§",
|
|
|
|
"†",
|
2023-08-06 19:23:42 +02:00
|
|
|
"ª",
|
|
|
|
"º",
|
2023-10-20 12:15:50 +02:00
|
|
|
"page_up",
|
|
|
|
"page_down",
|
|
|
|
"home",
|
|
|
|
"end",
|
2023-07-09 18:06:12 +02:00
|
|
|
"switch_greekmath",
|
|
|
|
"capslock",
|
|
|
|
"copy",
|
|
|
|
"paste",
|
|
|
|
"cut",
|
|
|
|
"selectAll",
|
|
|
|
"shareText",
|
|
|
|
"pasteAsPlainText",
|
|
|
|
"undo",
|
|
|
|
"redo",
|
2023-08-06 19:23:42 +02:00
|
|
|
"superscript",
|
|
|
|
"subscript",
|
2023-07-09 18:06:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Whether an extra key is enabled by default. */
|
|
|
|
public static boolean default_checked(String name)
|
|
|
|
{
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "voice_typing":
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-05 16:45:57 +02:00
|
|
|
/** Text that describe a key. Might be null. */
|
|
|
|
static String key_description(Resources res, String name)
|
|
|
|
{
|
|
|
|
int id = 0;
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "capslock": id = R.string.key_descr_capslock; break;
|
|
|
|
case "switch_greekmath": id = R.string.key_descr_switch_greekmath; break;
|
|
|
|
case "voice_typing": id = R.string.key_descr_voice_typing; break;
|
2023-08-06 19:35:06 +02:00
|
|
|
case "copy": id = R.string.key_descr_copy; break;
|
|
|
|
case "paste": id = R.string.key_descr_paste; break;
|
|
|
|
case "cut": id = R.string.key_descr_cut; break;
|
|
|
|
case "selectAll": id = R.string.key_descr_selectAll; break;
|
|
|
|
case "shareText": id = R.string.key_descr_shareText; break;
|
|
|
|
case "pasteAsPlainText": id = R.string.key_descr_pasteAsPlainText; break;
|
|
|
|
case "undo": id = R.string.key_descr_undo; break;
|
|
|
|
case "redo": id = R.string.key_descr_redo; break;
|
2023-08-06 19:23:42 +02:00
|
|
|
case "ª": id = R.string.key_descr_ª; break;
|
|
|
|
case "º": id = R.string.key_descr_º; break;
|
|
|
|
case "superscript": id = R.string.key_descr_superscript; break;
|
|
|
|
case "subscript": id = R.string.key_descr_subscript; break;
|
2023-10-20 12:15:50 +02:00
|
|
|
case "page_up": id = R.string.key_descr_page_up; break;
|
|
|
|
case "page_down": id = R.string.key_descr_page_down; break;
|
|
|
|
case "home": id = R.string.key_descr_home; break;
|
|
|
|
case "end": id = R.string.key_descr_end; break;
|
2023-08-05 16:45:57 +02:00
|
|
|
}
|
|
|
|
if (id == 0)
|
|
|
|
return null;
|
|
|
|
return res.getString(id);
|
|
|
|
}
|
|
|
|
|
2023-07-09 18:06:12 +02:00
|
|
|
/** Get the set of enabled extra keys. */
|
2023-09-15 18:00:27 +02:00
|
|
|
public static Map<KeyValue, KeyboardData.PreferredPos> get_extra_keys(SharedPreferences prefs)
|
2023-07-09 18:06:12 +02:00
|
|
|
{
|
2023-09-15 18:00:27 +02:00
|
|
|
Map<KeyValue, KeyboardData.PreferredPos> ks =
|
|
|
|
new HashMap<KeyValue, KeyboardData.PreferredPos>();
|
2023-07-09 18:06:12 +02:00
|
|
|
for (String key_name : extra_keys)
|
|
|
|
{
|
|
|
|
if (prefs.getBoolean(pref_key_of_key_name(key_name),
|
|
|
|
default_checked(key_name)))
|
2023-09-15 18:00:27 +02:00
|
|
|
ks.put(KeyValue.getKeyByName(key_name), KeyboardData.PreferredPos.DEFAULT);
|
2023-07-09 18:06:12 +02:00
|
|
|
}
|
|
|
|
return ks;
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:31:32 +02:00
|
|
|
boolean _attached = false; /** Whether it has already been attached. */
|
2023-07-09 18:06:12 +02:00
|
|
|
|
|
|
|
public ExtraKeysPreference(Context context, AttributeSet attrs)
|
|
|
|
{
|
|
|
|
super(context, attrs);
|
|
|
|
setOrderingAsAdded(true);
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:31:32 +02:00
|
|
|
@Override
|
2023-07-09 18:06:12 +02:00
|
|
|
protected void onAttachedToActivity()
|
|
|
|
{
|
|
|
|
if (_attached)
|
|
|
|
return;
|
|
|
|
_attached = true;
|
|
|
|
for (String key_name : extra_keys)
|
|
|
|
addPreference(new ExtraKeyCheckBoxPreference(getContext(), key_name,
|
|
|
|
default_checked(key_name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String pref_key_of_key_name(String key_name)
|
|
|
|
{
|
|
|
|
return "extra_key_" + key_name;
|
|
|
|
}
|
|
|
|
|
2023-07-18 00:31:32 +02:00
|
|
|
static class ExtraKeyCheckBoxPreference extends CheckBoxPreference
|
2023-07-09 18:06:12 +02:00
|
|
|
{
|
|
|
|
boolean _key_font;
|
|
|
|
|
2023-08-05 16:45:57 +02:00
|
|
|
public ExtraKeyCheckBoxPreference(Context ctx, String key_name,
|
2023-07-09 18:06:12 +02:00
|
|
|
boolean default_checked)
|
|
|
|
{
|
2023-08-05 16:45:57 +02:00
|
|
|
super(ctx);
|
2023-07-09 18:06:12 +02:00
|
|
|
KeyValue kv = KeyValue.getKeyByName(key_name);
|
|
|
|
String title = kv.getString();
|
2023-08-05 16:45:57 +02:00
|
|
|
String descr = key_description(ctx.getResources(), key_name);
|
2023-07-09 18:06:12 +02:00
|
|
|
if (descr != null)
|
|
|
|
title += " (" + descr + ")";
|
|
|
|
setKey(pref_key_of_key_name(key_name));
|
|
|
|
setDefaultValue(default_checked);
|
|
|
|
setTitle(title);
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|