2023-07-18 00:31:32 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.preference.PreferenceCategory;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
|
|
|
|
/** Allows to enter custom keys to be added to the keyboard. This shows up at
|
|
|
|
the top of the "Add keys to the keyboard" option. */
|
2023-07-29 18:31:26 +02:00
|
|
|
public class CustomExtraKeysPreference extends ListGroupPreference
|
2023-07-18 00:31:32 +02:00
|
|
|
{
|
|
|
|
/** This pref stores a list of strings encoded as JSON. */
|
2023-07-29 18:31:26 +02:00
|
|
|
static final String KEY = "custom_extra_keys";
|
2023-07-18 00:31:32 +02:00
|
|
|
|
|
|
|
public CustomExtraKeysPreference(Context context, AttributeSet attrs)
|
|
|
|
{
|
|
|
|
super(context, attrs);
|
|
|
|
setKey(KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<KeyValue> get(SharedPreferences prefs)
|
|
|
|
{
|
|
|
|
List<KeyValue> kvs = new ArrayList<KeyValue>();
|
2023-07-29 18:31:26 +02:00
|
|
|
List<String> key_names = load_from_preferences(KEY, prefs, null);
|
|
|
|
if (key_names != null)
|
2023-07-18 00:31:32 +02:00
|
|
|
{
|
2023-07-29 18:31:26 +02:00
|
|
|
for (String key_name : key_names)
|
|
|
|
kvs.add(KeyValue.makeStringKey(key_name));
|
2023-07-18 00:31:32 +02:00
|
|
|
}
|
2023-07-29 18:31:26 +02:00
|
|
|
return kvs;
|
2023-07-18 00:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-29 18:31:26 +02:00
|
|
|
void select(final SelectionCallback callback)
|
|
|
|
{
|
|
|
|
new AlertDialog.Builder(getContext())
|
|
|
|
.setView(R.layout.custom_extra_key_add_dialog)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
|
|
|
|
public void onClick(DialogInterface dialog, int which)
|
|
|
|
{
|
|
|
|
EditText input = (EditText)((AlertDialog)dialog).findViewById(R.id.key_name);
|
|
|
|
final String k = input.getText().toString();
|
|
|
|
if (!k.equals(""))
|
|
|
|
callback.select(k);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.show();
|
2023-07-18 00:31:32 +02:00
|
|
|
}
|
|
|
|
}
|