Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38d838d3 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Make the hardkeyboard long press dialog look the same as that of soft keyboard.

New assets for transparent buttons and background.
parent 1ab3ebad
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -25,15 +25,14 @@ import android.text.*;
import android.view.LayoutInflater;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

/**
 * Dialog for choosing accented characters related to a base character.
@@ -45,6 +44,7 @@ public class CharacterPickerDialog extends Dialog
    private String mOptions;
    private boolean mInsert;
    private LayoutInflater mInflater;
    private Button mCancelButton;

    /**
     * Creates a new CharacterPickerDialog that presents the specified
@@ -54,7 +54,7 @@ public class CharacterPickerDialog extends Dialog
    public CharacterPickerDialog(Context context, View view,
                                 Editable text, String options,
                                 boolean insert) {
        super(context);
        super(context, com.android.internal.R.style.Theme_Panel);

        mView = view;
        mText = text;
@@ -70,28 +70,32 @@ public class CharacterPickerDialog extends Dialog
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.token = mView.getApplicationWindowToken();
        params.type = params.TYPE_APPLICATION_ATTACHED_DIALOG;
        params.flags = params.flags | Window.FEATURE_NO_TITLE;

        setTitle(R.string.select_character);
        setContentView(R.layout.character_picker);

        GridView grid = (GridView) findViewById(R.id.characterPicker);
        grid.setAdapter(new OptionsAdapter(getContext()));
        grid.setOnItemClickListener(this);

        findViewById(R.id.cancel).setOnClickListener(this);
        mCancelButton = (Button) findViewById(R.id.cancel);
        mCancelButton.setOnClickListener(this);
    }

    /**
     * Handles clicks on the character buttons.
     */
    public void onItemClick(AdapterView parent, View view, int position, long id) {
        int selEnd = Selection.getSelectionEnd(mText);
        String result = String.valueOf(mOptions.charAt(position));
        replaceCharacterAndClose(result);
    }

    private void replaceCharacterAndClose(CharSequence replace) {
        int selEnd = Selection.getSelectionEnd(mText);
        if (mInsert || selEnd == 0) {
            mText.insert(selEnd, result);
            mText.insert(selEnd, replace);
        } else {
            mText.replace(selEnd - 1, selEnd, result);
            mText.replace(selEnd - 1, selEnd, replace);
        }

        dismiss();
@@ -101,21 +105,25 @@ public class CharacterPickerDialog extends Dialog
     * Handles clicks on the Cancel button.
     */
    public void onClick(View v) {
        if (v == mCancelButton) {
            dismiss();
        } else if (v instanceof Button) {
            CharSequence result = ((Button) v).getText();
            replaceCharacterAndClose(result);
        }
    }

    private class OptionsAdapter extends BaseAdapter {
        private Context mContext;

        public OptionsAdapter(Context context) {
            super();
            mContext = context;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            Button b = (Button)
                mInflater.inflate(R.layout.character_picker_button, null);
            b.setText(String.valueOf(mOptions.charAt(position)));
            b.setOnClickListener(CharacterPickerDialog.this);
            return b;
        }

+203 B (1.84 KiB)
Loading image diff...
+308 B (2.67 KiB)
Loading image diff...
+2.74 KiB
Loading image diff...
+1.17 KiB
Loading image diff...
Loading