Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

In this page you can find the example usage for android.view KeyEvent ACTION_DOWN.

Prototype

int ACTION_DOWN

To view the source code for android.view KeyEvent ACTION_DOWN.

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:org.catrobat.catroid.ui.fragment.FormulaEditorDataFragment.java

@Override
public void onListItemClick(int position) {
    if (!inContextMode) {
        FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity()
                .getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
        if (formulaEditor != null) {
            Object itemToAdd = adapter.getItem(position);
            if (itemToAdd instanceof UserVariable) {
                formulaEditor.addUserVariableToActiveFormula(((UserVariable) itemToAdd).getName());
            } else if (itemToAdd instanceof UserList) {
                formulaEditor.addUserListToActiveFormula(((UserList) itemToAdd).getName());
            }/*from   w  w w.j av  a  2  s  . c o  m*/
            formulaEditor.updateButtonsOnKeyboardAndInvalidateOptionsMenu();
        }
        KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
        onKey(null, keyEvent.getKeyCode(), keyEvent);
    }
}

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}//from  ww w .  j  a  v  a2  s  . co  m
 */
public void sendMediaAction(int action) {
    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    // TODO We should think about sending these up/down events accurately with touch up/down
    // on the buttons, but in the near term this will interfere with the long press behavior.
    RemoteController rc = mService.getRemoteController();
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
}

From source file:com.farmerbb.taskbar.activity.DashboardActivity.java

@Override
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        event.getKeyCode();/* w w  w  .  ja v a 2s.c  o m*/

        return true;
    }
    return super.dispatchKeyShortcutEvent(event);
}

From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*from   ww  w  . j av a  2  s . c  om*/
 */
public void sendMediaAction(int action) {
    if (mService == null) {
        Log.w(TAG, "Sending a media action on stopped controller.");
        return;
    }

    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    // TODO We should think about sending these up/down events accurately with touch up/down
    // on the buttons, but in the near term this will interfere with the long press behavior.
    RemoteController rc = mService.getRemoteController();
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
}

From source file:com.vmihalachi.turboeditor.fragment.EditorFragment.java

/**
 * {@inheritDoc}/*from  w ww .j a v  a2 s  .c o  m*/
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == R.id.im_save) {
        new SaveFile().execute();
    } else if (i == R.id.im_undo) {
        this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Z, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Z));
    } else if (i == R.id.im_redo) {
        this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Y, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Y));
    } else if (i == R.id.im_editor_encoding) {
        EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.Encoding,
                this.mCurrentEncoding);
        dialogFrag.setTargetFragment(this, 0);
        dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
    } else if (i == R.id.im_text_size) {
        int fontMax = 36;
        float scaledDensity = getResources().getDisplayMetrics().scaledDensity;
        int fontCurrent = (int) (mEditor.getTextSize() / scaledDensity);
        SeekbarDialogFragment dialogFrag = SeekbarDialogFragment
                .newInstance(SeekbarDialogFragment.Actions.FileSize, fontCurrent, fontMax);
        dialogFrag.setTargetFragment(this, 0);
        dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
    } else if (i == R.id.im_syntax_highlight) {
        item.setChecked(!item.isChecked());
        PreferenceHelper.setSyntaxHiglight(getActivity(), item.isChecked());
        updateTextEditor();
    } else if (i == R.id.im_line_numbers) {
        item.setChecked(!item.isChecked());
        PreferenceHelper.setLineNumbers(getActivity(), item.isChecked());
        updateTextEditor();
    } else if (i == R.id.im_use_monospace) {
        item.setChecked(!item.isChecked());
        PreferenceHelper.setUseMonospace(getActivity(), item.isChecked());
        updateTextEditor();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.av.remusic.receiver.MediaButtonIntentReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        if (true)
            startService(context, MediaService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }/*w w w .j  a  v  a2 s.  c  o m*/

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MediaService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MediaService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MediaService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MediaService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MediaService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MediaService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MediaService.CMDTOGGLEPAUSE.equals(command) || MediaService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {

                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:org.catrobat.catroid.ui.dialogs.OverwriteRenameMediaDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_overwrite_media, null);

    replaceButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_media_radio_replace);
    replaceButton.setOnClickListener(this);
    renameButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_media_radio_rename);
    renameButton.setOnClickListener(this);
    mediaText = (EditText) dialogView.findViewById(R.id.dialog_overwrite_media_edit);
    mediaText.setText(mediaName);/*from   w w w . j  a v  a2s  .  co  m*/
    mediaTextView = (TextView) dialogView.findViewById(R.id.dialog_overwrite_media_edit_text);
    mediaTextLine = dialogView.findViewById(R.id.dialog_overwrite_media_edit_line);

    final int header;
    final int replaceText;
    final int renameText;
    final int renameHeaderText;
    switch (mediaType) {
    case Constants.MEDIA_TYPE_LOOK:
        header = R.string.look_rename_overwrite;
        replaceText = R.string.overwrite_replace_look;
        renameText = R.string.overwrite_rename_look;
        renameHeaderText = R.string.new_look_name;
        break;
    case Constants.MEDIA_TYPE_SOUND:
        header = R.string.rename_sound_overwrite;
        replaceText = R.string.overwrite_replace_sound;
        renameText = R.string.overwrite_rename_sound;
        renameHeaderText = R.string.new_sound_name;
        break;
    default:
        header = R.string.rename_sprite_dialog;
        replaceText = R.string.overwrite_replace_default;
        renameText = R.string.overwrite_rename_default;
        renameHeaderText = R.string.new_sound_name;
    }

    replaceButton.setText(replaceText);
    renameButton.setText(renameText);
    mediaTextView.setText(renameHeaderText);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(header)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).create();

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleOkButton();
                }
            });
        }
    });

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                if (!okButtonResult) {
                    return false;
                } else {
                    dismiss();
                }
                return okButtonResult;
            } else if (keyCode == KeyEvent.KEYCODE_BACK) {
                dismiss();
                return true;
            }
            return false;
        }
    });

    return dialog;
}

From source file:com.vuze.android.remote.fragment.OpenOptionsFilesFragment.java

public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container,
        Bundle savedInstanceState) {//  ww w. j  ava 2 s.  c o m

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "onCreateview " + this);
    }

    FragmentActivity activity = getActivity();
    Intent intent = activity.getIntent();

    final Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.e(TAG, "No extras!");
    } else {

        String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY);
        if (remoteProfileID != null) {
            sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity);
        }

        torrentID = extras.getLong("TorrentID");
    }

    Map<?, ?> torrent = sessionInfo.getTorrent(torrentID);
    if (torrent == null) {
        // In theory TorrentOpenOptionsActivity handled this NPE already
        return null;
    }

    View topView = inflater.inflate(R.layout.frag_fileselection, container, false);
    tvScrollTitle = (TextView) topView.findViewById(R.id.files_scrolltitle);
    tvSummary = (TextView) topView.findViewById(R.id.files_summary);

    listview = (RecyclerView) topView.findViewById(R.id.files_list);
    listview.setLayoutManager(new PreCachingLayoutManager(getContext()));
    listview.setAdapter(adapter);

    FlexibleRecyclerSelectionListener rs = new FlexibleRecyclerSelectionListener<FilesTreeAdapter, FilesAdapterDisplayObject>() {
        @Override
        public void onItemClick(FilesTreeAdapter adapter, int position) {
            if (AndroidUtils.usesNavigationControl()) {
                FilesAdapterDisplayObject oItem = adapter.getItem(position);
                if (adapter.isInEditMode()) {
                    adapter.flipWant(oItem);
                    return;
                }
                if (oItem instanceof FilesAdapterDisplayFolder) {
                    FilesAdapterDisplayFolder oFolder = (FilesAdapterDisplayFolder) oItem;
                    oFolder.expand = !oFolder.expand;
                    adapter.getFilter().filter("");
                }
            }
        }

        @Override
        public boolean onItemLongClick(FilesTreeAdapter adapter, int position) {
            return false;
        }

        @Override
        public void onItemSelected(FilesTreeAdapter adapter, int position, boolean isChecked) {

        }

        @Override
        public void onItemCheckedChanged(FilesTreeAdapter adapter, FilesAdapterDisplayObject item,
                boolean isChecked) {
        }
    };

    adapter = new FilesTreeAdapter(this.getActivity(), rs);
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeChanged(int positionStart, int itemCount) {
            if (tvSummary != null) {
                tvSummary.setText(DisplayFormatters.formatByteCountToKiBEtc(adapter.getTotalSizeWanted()));
            }
        }

        @Override
        public void onChanged() {
            super.onChanged();
            if (tvSummary != null) {
                tvSummary.setText(DisplayFormatters.formatByteCountToKiBEtc(adapter.getTotalSizeWanted()));
            }
        }
    });
    adapter.setInEditMode(true);
    adapter.setSessionInfo(sessionInfo);
    adapter.setCheckOnSelectedAfterMS(0);
    listview.setAdapter(adapter);

    listview.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            {
                if (event.getAction() != KeyEvent.ACTION_DOWN) {
                    return false;
                }
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_RIGHT: {
                    // expand
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (!((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = true;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }

                case KeyEvent.KEYCODE_DPAD_LEFT: {
                    // collapse
                    int i = adapter.getSelectedPosition();
                    FilesAdapterDisplayObject item = adapter.getItem(i);
                    if (item instanceof FilesAdapterDisplayFolder) {
                        if (((FilesAdapterDisplayFolder) item).expand) {
                            ((FilesAdapterDisplayFolder) item).expand = false;
                            adapter.getFilter().filter("");
                            return true;
                        }
                    }
                    break;
                }
                }

                return false;
            }
        }
    });

    listview.setOnScrollListener(new RecyclerView.OnScrollListener() {
        int firstVisibleItem = 0;

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            LinearLayoutManager lm = (LinearLayoutManager) listview.getLayoutManager();
            int firstVisibleItem = lm.findFirstCompletelyVisibleItemPosition();
            if (firstVisibleItem != this.firstVisibleItem) {
                this.firstVisibleItem = firstVisibleItem;
                FilesAdapterDisplayObject itemAtPosition = adapter.getItem(firstVisibleItem);

                if (itemAtPosition == null) {
                    return;
                }
                if (itemAtPosition.parent != null) {
                    if (tvScrollTitle != null) {
                        tvScrollTitle.setText(itemAtPosition.parent.folder);
                    }
                } else {
                    if (tvScrollTitle != null) {
                        tvScrollTitle.setText("");
                    }
                }
            }
        }
    });

    if (torrent.containsKey("files")) {
        adapter.setTorrentID(torrentID);
    } else {
        sessionInfo.executeRpc(new RpcExecuter() {
            @Override
            public void executeRpc(TransmissionRPC rpc) {
                rpc.getTorrentFileInfo(TAG, torrentID, null, new TorrentListReceivedListener() {

                    @Override
                    public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps,
                            List<?> removedTorrentIDs) {
                        AndroidUtils.runOnUIThread(OpenOptionsFilesFragment.this, new Runnable() {
                            @Override
                            public void run() {
                                adapter.setTorrentID(torrentID);
                            }
                        });
                    }
                });
            }
        });
    }

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "set " + adapter + " for " + listview + " to " + sessionInfo + "/" + torrentID);
    }

    return topView;
}

From source file:org.mdc.chess.SeekBarPreference.java

@Override
protected View onCreateView(ViewGroup parent) {
    TextView name = new TextView(getContext());
    name.setText(getTitle());/*w w w  .  j  a  v  a 2  s . co  m*/
    //name.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
    TextViewCompat.setTextAppearance(name, android.R.style.TextAppearance_Large);
    name.setGravity(Gravity.START);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.START;
    lp.weight = 1.0f;
    name.setLayoutParams(lp);

    currValBox = new TextView(getContext());
    currValBox.setTextSize(12);
    currValBox.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC);
    currValBox.setPadding(2, 5, 0, 0);
    currValBox.setText(valToString());
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.CENTER;
    currValBox.setLayoutParams(lp);

    LinearLayout row1 = new LinearLayout(getContext());
    row1.setOrientation(LinearLayout.HORIZONTAL);
    row1.addView(name);
    row1.addView(currValBox);

    final SeekBar bar = new SeekBar(getContext());
    bar.setMax(maxValue);
    bar.setProgress(currVal);
    bar.setOnSeekBarChangeListener(this);
    lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.END;
    bar.setLayoutParams(lp);

    CharSequence summaryCharSeq = getSummary();
    boolean haveSummary = (summaryCharSeq != null) && (summaryCharSeq.length() > 0);
    TextView summary = null;
    if (haveSummary) {
        summary = new TextView(getContext());
        summary.setText(getSummary());
        //            summary.setTextAppearance(getContext(), android.R.style.TextAppearance_Large);
        summary.setGravity(Gravity.START);
        lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.START;
        lp.weight = 1.0f;
        summary.setLayoutParams(lp);
    }

    LinearLayout layout = new LinearLayout(getContext());
    layout.setPadding(25, 5, 25, 5);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(row1);
    layout.addView(bar);
    if (summary != null) {
        layout.addView(summary);
    }
    layout.setId(android.R.id.widget_frame);

    currValBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            View content = View.inflate(SeekBarPreference.this.getContext(), R.layout.select_percentage, null);
            final AlertDialog.Builder builder = new AlertDialog.Builder(SeekBarPreference.this.getContext());
            builder.setView(content);
            String title = "";
            String key = getKey();
            if (key.equals("strength")) {
                title = getContext().getString(R.string.edit_strength);
            } else if (key.equals("bookRandom")) {
                title = getContext().getString(R.string.edit_randomization);
            }
            builder.setTitle(title);
            final EditText valueView = (EditText) content.findViewById(R.id.selpercentage_number);
            valueView.setText(currValBox.getText().toString().replaceAll("%", "").replaceAll(",", "."));
            final Runnable selectValue = new Runnable() {
                public void run() {
                    try {
                        String txt = valueView.getText().toString();
                        int value = (int) (Double.parseDouble(txt) * 10 + 0.5);
                        if (value < 0)
                            value = 0;
                        if (value > maxValue)
                            value = maxValue;
                        onProgressChanged(bar, value, false);
                    } catch (NumberFormatException ignored) {

                    }
                }
            };
            valueView.setOnKeyListener(new OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        selectValue.run();
                        return true;
                    }
                    return false;
                }
            });
            builder.setPositiveButton("Ok", new Dialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    selectValue.run();
                }
            });
            builder.setNegativeButton("Cancel", null);

            builder.create().show();
        }
    });

    return layout;
}

From source file:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON);
    }/*w w w  . j ava2  s. com*/

    // Retrieve session object
    checkSession();

    if (getArguments() != null && getArguments().containsKey(ARGUMENT_MODE)) {
        fieldId = getArguments().getString(ARGUMENT_FIELD_ID);
        keywords = getArguments().getString(ARGUMENT_KEYWORD);
        title = getArguments().getString(ARGUMENT_TITLE);
        mode = getArguments().getInt(ARGUMENT_MODE);
        singleChoice = getArguments().getBoolean(ARGUMENT_SINGLE_CHOICE);
        String pickFragmentTag = getArguments().getString(ARGUMENT_FRAGMENT_TAG);
        fragmentPick = getFragmentManager().findFragmentByTag(pickFragmentTag);
        if (fragmentPick != null && fragmentPick instanceof UserPickerCallback) {
            selectedItems = ((UserPickerCallback) fragmentPick).retrieveSelection();
        } else if (fragmentPick instanceof onPickAuthorityFragment && fieldId != null) {
            selectedItems = ((onPickAuthorityFragment) fragmentPick).getPersonSelected(fieldId);
        }
    }

    // Create View
    setRootView(inflater.inflate(R.layout.app_pick_person, container, false));
    if (getSession() == null) {
        return getRootView();
    }

    // Init list
    init(getRootView(), R.string.person_not_found);
    gv.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
    setListShown(true);

    if (keywords != null && !keywords.isEmpty()) {
        search(keywords);
        hide(R.id.search_form_group);
    } else {
        // Init form search
        searchForm = (EditText) viewById(R.id.search_query);
        searchForm.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

        searchForm.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                        && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                                || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                    if (searchForm.getText().length() > 0) {
                        keywords = searchForm.getText().toString();
                        search(keywords);
                    } else {
                        AlfrescoNotificationManager.getInstance(getActivity())
                                .showLongToast(getString(R.string.search_form_hint));
                    }
                    return true;
                }
                return false;
            }
        });

        // Speech to Text
        Boolean hasTextToSpeech = ActionUtils.hasSpeechToText(getActivity());
        ImageButton speechToText = (ImageButton) viewById(R.id.search_microphone);
        if (hasTextToSpeech) {
            speechToText.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    speechToText();
                }
            });
        } else {
            hide(R.id.search_microphone);
        }
    }

    if (getMode() == MODE_PICK) {
        show(R.id.validation_panel);
        validation = UIUtils.initValidation(getRootView(), R.string.done);
        updatePickButton();
        validation.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                onSelect(selectedItems);
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });

        Button cancel = UIUtils.initCancel(getRootView(), R.string.cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getDialog() != null) {
                    getDialog().dismiss();
                } else {
                    getFragmentManager().popBackStack();
                }
            }
        });
    } else {
        hide(R.id.validation_panel);
    }

    return getRootView();
}