FileDocCategorySizeDatePackage
CharacterPickerDialog.javaAPI DocAndroid 5.1 API4570Thu Mar 12 22:22:10 GMT 2015android.text.method

CharacterPickerDialog

public class CharacterPickerDialog extends android.app.Dialog implements android.widget.AdapterView.OnItemClickListener, android.view.View.OnClickListener
Dialog for choosing accented characters related to a base character.

Fields Summary
private android.view.View
mView
private Editable
mText
private String
mOptions
private boolean
mInsert
private android.view.LayoutInflater
mInflater
private android.widget.Button
mCancelButton
Constructors Summary
public CharacterPickerDialog(android.content.Context context, android.view.View view, Editable text, String options, boolean insert)
Creates a new CharacterPickerDialog that presents the specified options for insertion or replacement (depending on the sense of insert) into text.

        super(context, com.android.internal.R.style.Theme_Panel);

        mView = view;
        mText = text;
        mOptions = options;
        mInsert = insert;
        mInflater = LayoutInflater.from(context);
    
Methods Summary
public voidonClick(android.view.View v)
Handles clicks on the Cancel button.

        if (v == mCancelButton) {
            dismiss();
        } else if (v instanceof Button) {
            CharSequence result = ((Button) v).getText();
            replaceCharacterAndClose(result);
        }
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.token = mView.getApplicationWindowToken();
        params.type = params.TYPE_APPLICATION_ATTACHED_DIALOG;
        params.flags = params.flags | Window.FEATURE_NO_TITLE;

        setContentView(R.layout.character_picker);

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

        mCancelButton = (Button) findViewById(R.id.cancel);
        mCancelButton.setOnClickListener(this);
    
public voidonItemClick(android.widget.AdapterView parent, android.view.View view, int position, long id)
Handles clicks on the character buttons.

        String result = String.valueOf(mOptions.charAt(position));
        replaceCharacterAndClose(result);
    
private voidreplaceCharacterAndClose(java.lang.CharSequence replace)

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

        dismiss();