Example usage for android.view KeyEvent ACTION_UP

List of usage examples for android.view KeyEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

#getAction value: the key has been released.

Usage

From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java

/**
 * Get image from photo library.//  w w  w. ja  v  a  2s  . c o  m
 * 
 * @param quality
 *            Compression quality hint (0-100: 0=low quality & high
 *            compression, 100=compress of max quality)
 * @param srcType
 *            The album to get image from.
 * @param returnType
 *            Set the type of image to return.
 */
// TODO: Images selected from SDCARD don't display correctly, but from
// CAMERA ALBUM do!
public void getImage(int srcType, int returnType) {

    final int srcTypeFinal = srcType;
    final int returnTypeFinal = returnType;

    String[] choices = { "Upload a Photo", "Upload a Video" };

    AlertDialog.Builder builder = new AlertDialog.Builder(this.cordova.getActivity());
    builder.setItems(choices, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Log.d(LOG_TAG, "Index #" + which + " chosen.");
            Intent intent = new Intent();
            if (which == 0) {
                // set up photo intent
                WsiCameraLauncher.this.mediaType = PICTURE;
                intent.setType("image/*");
            } else if (which == 1) {
                // set up video intent
                WsiCameraLauncher.this.mediaType = VIDEO;
                intent.setType("video/*");
            } else {
                WsiCameraLauncher.this.failPicture("Selection cancelled.");
                return;
            }
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            if (WsiCameraLauncher.this.cordova != null) {
                WsiCameraLauncher.this.cordova.startActivityForResult((CordovaPlugin) WsiCameraLauncher.this,
                        Intent.createChooser(intent, new String("Pick")),
                        (srcTypeFinal + 1) * 16 + returnTypeFinal + 1);
            }
        }
    });
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                    && !event.isCanceled()) {
                dialog.cancel();
                WsiCameraLauncher.this.failPicture("Selection cancelled.");
                return true;
            }
            return false;
        }
    });
    builder.show();
}

From source file:ayushi.view.fragment.ProductDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.frag_product_detail, container, false);

    mToolbar = (Toolbar) rootView.findViewById(R.id.htab_toolbar);
    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).setSupportActionBar(mToolbar);
    }/*w  w w  .j a va2  s  .c  o  m*/

    if (mToolbar != null) {
        ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mToolbar.setNavigationIcon(R.drawable.ic_drawer);

    }

    mToolbar.setTitleTextColor(Color.WHITE);

    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((ECartHomeActivity) getActivity()).getmDrawerLayout().openDrawer(GravityCompat.START);
        }
    });

    ((ECartHomeActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    similarProductsPager = (ClickableViewPager) rootView.findViewById(R.id.similar_products_pager);

    topSellingPager = (ClickableViewPager) rootView.findViewById(R.id.top_selleing_pager);

    itemSellPrice = ((TextView) rootView.findViewById(R.id.category_discount));

    quanitity = ((TextView) rootView.findViewById(R.id.iteam_amount));

    itemName = ((TextView) rootView.findViewById(R.id.product_name));

    itemdescription = ((TextView) rootView.findViewById(R.id.product_description));

    itemImage = (ImageView) rootView.findViewById(R.id.product_image);

    fillProductData();

    rootView.findViewById(R.id.add_item).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (isFromCart) {

                //Update Quantity on shopping List
                GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber)
                        .setQuantity(String.valueOf(

                                Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                        .get(productListNumber).getQuantity()) + 1));

                //Update Ui
                quanitity.setText(GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber)
                        .getQuantity());

                Utils.vibrate(getActivity());

                //Update checkout amount on screen
                ((ECartHomeActivity) getActivity()).updateCheckOutAmount(
                        BigDecimal.valueOf(Long.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                .get(productListNumber).getSellMRP())),
                        true);

            } else {

                // current object
                Product tempObj = GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                        .get(productListNumber);

                // if current object is lready in shopping list
                if (GlobaDataHolder.getGlobaDataHolder().getShoppingList().contains(tempObj)) {

                    // get position of current item in shopping list
                    int indexOfTempInShopingList = GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                            .indexOf(tempObj);

                    // increase quantity of current item in shopping
                    // list
                    if (Integer.parseInt(tempObj.getQuantity()) == 0) {

                        ((ECartHomeActivity) getContext()).updateItemCount(true);

                    }

                    // update quanity in shopping list
                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(indexOfTempInShopingList)
                            .setQuantity(String.valueOf(Integer.valueOf(tempObj.getQuantity()) + 1));

                    // update checkout amount
                    ((ECartHomeActivity) getContext())
                            .updateCheckOutAmount(
                                    BigDecimal.valueOf(
                                            Long.valueOf(GlobaDataHolder.getGlobaDataHolder().getProductMap()
                                                    .get(subcategoryKey).get(productListNumber).getSellMRP())),
                                    true);

                    // update current item quanitity
                    quanitity.setText(tempObj.getQuantity());

                } else {

                    ((ECartHomeActivity) getContext()).updateItemCount(true);

                    tempObj.setQuantity(String.valueOf(1));

                    quanitity.setText(tempObj.getQuantity());

                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().add(tempObj);

                    ((ECartHomeActivity) getContext())
                            .updateCheckOutAmount(
                                    BigDecimal.valueOf(
                                            Long.valueOf(GlobaDataHolder.getGlobaDataHolder().getProductMap()
                                                    .get(subcategoryKey).get(productListNumber).getSellMRP())),
                                    true);

                }

                Utils.vibrate(getContext());

            }
        }

    });

    rootView.findViewById(R.id.remove_item).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (isFromCart)

            {

                if (Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                        .get(productListNumber).getQuantity()) > 2) {

                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(productListNumber)
                            .setQuantity(String.valueOf(

                                    Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                            .get(productListNumber).getQuantity()) - 1));

                    quanitity.setText(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                            .get(productListNumber).getQuantity());

                    ((ECartHomeActivity) getActivity()).updateCheckOutAmount(
                            BigDecimal.valueOf(Long.valueOf(GlobaDataHolder.getGlobaDataHolder()
                                    .getShoppingList().get(productListNumber).getSellMRP())),
                            false);

                    Utils.vibrate(getActivity());
                }

                else if (Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                        .get(productListNumber).getQuantity()) == 1) {
                    ((ECartHomeActivity) getActivity()).updateItemCount(false);

                    ((ECartHomeActivity) getActivity()).updateCheckOutAmount(
                            BigDecimal.valueOf(Long.valueOf(GlobaDataHolder.getGlobaDataHolder()
                                    .getShoppingList().get(productListNumber).getSellMRP())),
                            false);

                    GlobaDataHolder.getGlobaDataHolder().getShoppingList().remove(productListNumber);

                    if (Integer.valueOf(((ECartHomeActivity) getActivity()).getItemCount()) == 0) {

                        MyCartFragment.updateMyCartFragment(false);

                    }

                    Utils.vibrate(getActivity());

                }

            }

            else {

                Product tempObj = GlobaDataHolder.getGlobaDataHolder().getProductMap().get(subcategoryKey)
                        .get(productListNumber);

                if (GlobaDataHolder.getGlobaDataHolder().getShoppingList().contains(tempObj)) {

                    int indexOfTempInShopingList = GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                            .indexOf(tempObj);

                    if (Integer.valueOf(tempObj.getQuantity()) != 0) {

                        GlobaDataHolder.getGlobaDataHolder().getShoppingList().get(indexOfTempInShopingList)
                                .setQuantity(String.valueOf(Integer.valueOf(tempObj.getQuantity()) - 1));

                        ((ECartHomeActivity) getContext()).updateCheckOutAmount(
                                BigDecimal.valueOf(
                                        Long.valueOf(GlobaDataHolder.getGlobaDataHolder().getProductMap()
                                                .get(subcategoryKey).get(productListNumber).getSellMRP())),
                                false);

                        quanitity.setText(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                .get(indexOfTempInShopingList).getQuantity());

                        Utils.vibrate(getContext());

                        if (Integer.valueOf(GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                .get(indexOfTempInShopingList).getQuantity()) == 0) {

                            GlobaDataHolder.getGlobaDataHolder().getShoppingList()
                                    .remove(indexOfTempInShopingList);

                            ((ECartHomeActivity) getContext()).updateItemCount(false);

                        }

                    }

                } else {

                }

            }

        }

    });

    rootView.setFocusableInTouchMode(true);
    rootView.requestFocus();
    rootView.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {

                if (isFromCart) {

                    Utils.switchContent(R.id.frag_container, Utils.SHOPPING_LIST_TAG,
                            ((ECartHomeActivity) (getActivity())), AnimationType.SLIDE_UP);
                } else {

                    Utils.switchContent(R.id.frag_container, Utils.PRODUCT_OVERVIEW_FRAGMENT_TAG,
                            ((ECartHomeActivity) (getActivity())), AnimationType.SLIDE_RIGHT);
                }

            }
            return true;
        }
    });

    if (isFromCart) {

        similarProductsPager.setVisibility(View.GONE);

        topSellingPager.setVisibility(View.GONE);

    } else {
        showRecomondation();
    }

    return rootView;
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "onCreate()");

    m_app = (TodoApplication) getApplication();
    m_app.setActionBarStyle(getWindow());
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.BROADCAST_UPDATE_UI);
    intentFilter.addAction(Constants.BROADCAST_SYNC_START);
    intentFilter.addAction(Constants.BROADCAST_SYNC_DONE);

    localBroadcastManager = m_app.getLocalBroadCastManager();

    m_broadcastReceiver = new BroadcastReceiver() {
        @Override/*from  w w  w .  j  a v a2  s.  co m*/
        public void onReceive(Context context, @NotNull Intent intent) {
            if (intent.getAction().equals(Constants.BROADCAST_SYNC_START)) {
                setProgressBarIndeterminateVisibility(true);
            } else if (intent.getAction().equals(Constants.BROADCAST_SYNC_DONE)) {
                setProgressBarIndeterminateVisibility(false);
            }
        }
    };
    localBroadcastManager.registerReceiver(m_broadcastReceiver, intentFilter);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    final Intent intent = getIntent();
    ActiveFilter mFilter = new ActiveFilter();
    mFilter.initFromIntent(intent);
    final String action = intent.getAction();
    // create shortcut and exit
    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        Log.d(TAG, "Setting up shortcut icon");
        setupShortcut();
        finish();
        return;
    } else if (Intent.ACTION_SEND.equals(action)) {
        Log.d(TAG, "Share");
        if (intent.hasExtra(Intent.EXTRA_TEXT)) {
            share_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT).toString();
        } else {
            share_text = "";
        }
        if (!m_app.hasShareTaskShowsEdit()) {
            if (!share_text.equals("")) {
                addBackgroundTask(share_text);
            }
            finish();
            return;
        }
    } else if ("com.google.android.gm.action.AUTO_SEND".equals(action)) {
        // Called as note to self from google search/now
        noteToSelf(intent);
        finish();
        return;
    } else if (Constants.INTENT_BACKGROUND_TASK.equals(action)) {
        Log.v(TAG, "Adding background task");
        if (intent.hasExtra(Constants.EXTRA_BACKGROUND_TASK)) {
            addBackgroundTask(intent.getStringExtra(Constants.EXTRA_BACKGROUND_TASK));
        } else {
            Log.w(TAG, "Task was not in extras");
        }
        finish();
        return;
    }

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    setContentView(R.layout.add_task);

    // text
    textInputField = (EditText) findViewById(R.id.taskText);
    m_app.setEditTextHint(textInputField, R.string.tasktexthint);

    if (share_text != null) {
        textInputField.setText(share_text);
    }

    Task iniTask = null;
    setTitle(R.string.addtask);

    m_backup = m_app.getTaskCache(this).getTasksToUpdate();
    if (m_backup != null && m_backup.size() > 0) {
        ArrayList<String> prefill = new ArrayList<String>();
        for (Task t : m_backup) {
            prefill.add(t.inFileFormat());
        }
        String sPrefill = Util.join(prefill, "\n");
        textInputField.setText(sPrefill);
        setTitle(R.string.updatetask);
    } else {
        if (textInputField.getText().length() == 0) {
            iniTask = new Task(1, "");
            iniTask.initWithFilter(mFilter);
        }

        if (iniTask != null && iniTask.getTags().size() == 1) {
            List<String> ps = iniTask.getTags();
            String project = ps.get(0);
            if (!project.equals("-")) {
                textInputField.append(" +" + project);
            }
        }

        if (iniTask != null && iniTask.getLists().size() == 1) {
            List<String> cs = iniTask.getLists();
            String context = cs.get(0);
            if (!context.equals("-")) {
                textInputField.append(" @" + context);
            }
        }
    }
    // Listen to enter events, use IME_ACTION_NEXT for soft keyboards
    // like Swype where ENTER keyCode is not generated.

    int inputFlags = InputType.TYPE_CLASS_TEXT;

    if (m_app.hasCapitalizeTasks()) {
        inputFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
    }
    textInputField.setRawInputType(inputFlags);
    textInputField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    textInputField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, @Nullable KeyEvent keyEvent) {

            boolean hardwareEnterUp = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_UP
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER;
            boolean hardwareEnterDown = keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN
                    && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER;
            boolean imeActionNext = (actionId == EditorInfo.IME_ACTION_NEXT);

            if (imeActionNext || hardwareEnterUp) {
                // Move cursor to end of line
                int position = textInputField.getSelectionStart();
                String remainingText = textInputField.getText().toString().substring(position);
                int endOfLineDistance = remainingText.indexOf('\n');
                int endOfLine;
                if (endOfLineDistance == -1) {
                    endOfLine = textInputField.length();
                } else {
                    endOfLine = position + endOfLineDistance;
                }
                textInputField.setSelection(endOfLine);
                replaceTextAtSelection("\n", false);

                if (hasCloneTags()) {
                    String precedingText = textInputField.getText().toString().substring(0, endOfLine);
                    int lineStart = precedingText.lastIndexOf('\n');
                    String line;
                    if (lineStart != -1) {
                        line = precedingText.substring(lineStart, endOfLine);
                    } else {
                        line = precedingText;
                    }
                    Task t = new Task(0, line);
                    LinkedHashSet<String> tags = new LinkedHashSet<String>();
                    for (String ctx : t.getLists()) {
                        tags.add("@" + ctx);
                    }
                    for (String prj : t.getTags()) {
                        tags.add("+" + prj);
                    }
                    replaceTextAtSelection(Util.join(tags, " "), true);
                }
                endOfLine++;
                textInputField.setSelection(endOfLine);
            }
            return (imeActionNext || hardwareEnterDown || hardwareEnterUp);
        }
    });

    setCloneTags(m_app.isAddTagsCloneTags());
    setWordWrap(m_app.isWordWrap());

    findViewById(R.id.cb_wrap).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setWordWrap(hasWordWrap());
        }
    });

    int textIndex = 0;
    textInputField.setSelection(textIndex);

    // Set button callbacks
    findViewById(R.id.btnContext).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showContextMenu();
        }
    });
    findViewById(R.id.btnProject).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showTagMenu();
        }
    });
    findViewById(R.id.btnPrio).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPrioMenu();
        }
    });

    findViewById(R.id.btnDue).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDate(Task.DUE_DATE);
        }
    });
    findViewById(R.id.btnThreshold).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDate(Task.THRESHOLD_DATE);
        }
    });

    if (m_backup != null && m_backup.size() > 0) {
        textInputField.setSelection(textInputField.getText().length());
    }
}

From source file:org.jitsi.android.gui.call.VideoCallActivity.java

/**
 * {@inheritDoc}//ww w  .  j a v a 2  s.c om
 */
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    /**
     * The call to:
     * setVolumeControlStream(AudioManager.STREAM_VOICE_CALL)
     * doesn't work when notification was being played during this Activity
     * creation, so the buttons must be captured and the voice call level
     * will be manipulated programmatically.
     */
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_UP) {
            volControl.onKeyVolUp();
        }
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            volControl.onKeyVolDown();
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:android.support.v7.app.ToolbarActionBar.java

@Override
public boolean onMenuKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP) {
        openOptionsMenu();/*from  w ww.  j ava2s.  c  om*/
    }
    return true;
}

From source file:org.woltage.irssiconnectbot.ConsoleActivity.java

@Override
@TargetApi(11)//  www. j  a v  a  2 s  .  c o  m
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    if (!InstallMosh.isInstallStarted()) {
        new InstallMosh(this);
    }

    configureStrictMode();
    hardKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY;

    hardKeyboard = hardKeyboard && !Build.MODEL.contains("Transformer");

    this.setContentView(R.layout.act_console);
    BugSenseHandler.setup(this, "d27a12dc");

    clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // hide action bar if requested by user
    try {
        ActionBar actionBar = getActionBar();
        if (!prefs.getBoolean(PreferenceConstants.ACTIONBAR, true)) {
            actionBar.hide();
        }
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
    } catch (NoSuchMethodError error) {
        Log.w(TAG, "Android sdk version pre 11. Not touching ActionBar.");
    }

    // hide status bar if requested by user
    if (prefs.getBoolean(PreferenceConstants.FULLSCREEN, false)) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    // TODO find proper way to disable volume key beep if it exists.
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // handle requested console from incoming intent
    requested = getIntent().getData();

    inflater = LayoutInflater.from(this);

    flip = (ViewFlipper) findViewById(R.id.console_flip);
    empty = (TextView) findViewById(android.R.id.empty);

    stringPromptGroup = (RelativeLayout) findViewById(R.id.console_password_group);
    stringPromptInstructions = (TextView) findViewById(R.id.console_password_instructions);
    stringPrompt = (EditText) findViewById(R.id.console_password);
    stringPrompt.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP)
                return false;
            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;

            // pass collected password down to current terminal
            String value = stringPrompt.getText().toString();

            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return false;
            helper.setResponse(value);

            // finally clear password for next user
            stringPrompt.setText("");
            updatePromptVisible();

            return true;
        }
    });

    booleanPromptGroup = (RelativeLayout) findViewById(R.id.console_boolean_group);
    booleanPrompt = (TextView) findViewById(R.id.console_prompt);

    booleanYes = (Button) findViewById(R.id.console_prompt_yes);
    booleanYes.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.TRUE);
            updatePromptVisible();
        }
    });

    booleanNo = (Button) findViewById(R.id.console_prompt_no);
    booleanNo.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            PromptHelper helper = getCurrentPromptHelper();
            if (helper == null)
                return;
            helper.setResponse(Boolean.FALSE);
            updatePromptVisible();
        }
    });

    // preload animations for terminal switching
    slide_left_in = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
    slide_left_out = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
    slide_right_in = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
    slide_right_out = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);

    fade_out_delayed = AnimationUtils.loadAnimation(this, R.anim.fade_out_delayed);
    fade_stay_hidden = AnimationUtils.loadAnimation(this, R.anim.fade_stay_hidden);

    // Preload animation for keyboard button
    keyboard_fade_in = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_in);
    keyboard_fade_out = AnimationUtils.loadAnimation(this, R.anim.keyboard_fade_out);

    inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    final RelativeLayout keyboardGroup = (RelativeLayout) findViewById(R.id.keyboard_group);

    if (Build.MODEL.contains("Transformer")
            && getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY
            && prefs.getBoolean(PreferenceConstants.ACTIONBAR, true)) {
        keyboardGroup.setEnabled(false);
        keyboardGroup.setVisibility(View.INVISIBLE);
    }

    mKeyboardButton = (ImageView) findViewById(R.id.button_keyboard);
    mKeyboardButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED);
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView symButton = (ImageView) findViewById(R.id.button_sym);
    symButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.showCharPickerDialog(terminal);
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    mInputButton = (ImageView) findViewById(R.id.button_input);
    mInputButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;

            final TerminalView terminal = (TerminalView) flip;
            Thread promptThread = new Thread(new Runnable() {
                public void run() {
                    String inj = getCurrentPromptHelper().requestStringPrompt(null, "");
                    terminal.bridge.injectString(inj);
                }
            });
            promptThread.setName("Prompt");
            promptThread.setDaemon(true);
            promptThread.start();

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView ctrlButton = (ImageView) findViewById(R.id.button_ctrl);
    ctrlButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.metaPress(TerminalKeyListener.META_CTRL_ON);
            terminal.bridge.tryKeyVibrate();

            keyboardGroup.setVisibility(View.GONE);
        }
    });

    final ImageView escButton = (ImageView) findViewById(R.id.button_esc);
    escButton.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            View flip = findCurrentView(R.id.console_flip);
            if (flip == null)
                return;
            TerminalView terminal = (TerminalView) flip;

            TerminalKeyListener handler = terminal.bridge.getKeyHandler();
            handler.sendEscape();
            terminal.bridge.tryKeyVibrate();
            keyboardGroup.setVisibility(View.GONE);
        }
    });

    // detect fling gestures to switch between terminals
    final GestureDetector detect = new GestureDetector(new ICBSimpleOnGestureListener(this));

    flip.setLongClickable(true);
    flip.setOnTouchListener(new ICBOnTouchListener(this, keyboardGroup, detect));

}

From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java

@Override
public void onNewIntent(Intent intent) {
    if (ACTION_CONNECT_INPUT.equals(intent.getAction())
            && (intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) == 0) {
        // We were the front most app and we got a new intent.
        // If screen saver is going, stop it.
        try {/*w w  w .j a  v  a2 s  .c o  m*/
            if (mDreamManager != null && mDreamManager.isDreaming()) {
                mDreamManager.awaken();
            }
        } catch (RemoteException e) {
            // Do nothing.
        }

        KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_PAIRING) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                onHwKeyEvent(false);
            } else if (event.getAction() == KeyEvent.ACTION_DOWN) {
                onHwKeyEvent(true);
            }
        }
    } else {
        setIntent(intent);
    }
}

From source file:org.ulteo.ovd.AndRdpActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    AudioManager audioManager;/*from   www  .jav a  2 s  . c  o  m*/

    if (Config.DEBUG)
        Log.i(Config.TAG, "AndRdpActivity.dispatchKeyEvent " + event);

    // Disable keypress if it is from a mouse or touchpad.
    if (event.getDeviceId() >= 0) {
        InputDevice dev = InputDevice.getDevice(event.getDeviceId());
        if (dev.getSources() == InputDevice.SOURCE_MOUSE || dev.getSources() == InputDevice.SOURCE_TOUCHPAD)
            return true;
    }

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
            OnThreeFingers(null);
            return true;
        case KeyEvent.KEYCODE_BACK:
            Log.i(Config.TAG, "Back key pressed");
            askLogoutDialog();
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI);
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI);
            return true;
        }
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MENU:
        case KeyEvent.KEYCODE_BACK:
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            return true;
        }
    }

    if (isLoggedIn() && rdp.dispatchKeyEvent(event))
        return true;

    return super.dispatchKeyEvent(event);
}

From source file:com.darly.im.ui.LauncherActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    LogUtil.d(LogUtil.getLogUtilsTag(LauncherActivity.class), " onKeyDown");

    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) {
        // dismiss PlusSubMenuHelper
        if (mOverflowHelper != null && mOverflowHelper.isOverflowShowing()) {
            mOverflowHelper.dismiss();/* w ww  .jav  a2s  . co m*/
            return true;
        }
    }

    // ?menu??
    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_DOWN) {
        doTaskToBackEvent();
    }

    try {

        return super.dispatchKeyEvent(event);
    } catch (Exception e) {
        LogUtil.e(LogUtil.getLogUtilsTag(LauncherActivity.class),
                "dispatch key event catch exception " + e.getMessage());
    }

    return false;
}

From source file:com.google.android.apps.flexbox.FlexItemEditFragment.java

private void setNextFocusesOnEnterDown(final TextView... textViews) {
    // This can be done by setting android:nextFocus* as in 
    // https://developer.android.com/training/keyboard-input/navigation.html
    // But it requires API level 11 as a minimum sdk version. To support the lower level devices,
    // doing it programatically.
    for (int i = 0; i < textViews.length; i++) {
        final int index = i;
        textViews[index].setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override/* w ww . j  av a  2 s  .  c om*/
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE
                        || (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                                && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    if (index + 1 < textViews.length) {
                        textViews[index + 1].requestFocus();
                    } else if (index == textViews.length - 1) {
                        InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
                    }
                }
                return true;
            }
        });

        // Suppress the key focus change by KeyEvent.ACTION_UP of the enter key
        textViews[index].setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                return keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP;
            }
        });
    }

}