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:org.dmfs.oauth2.android.fragment.InteractiveGrantFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mWebView.canGoBack()) {
                // user went back a step
                mWebView.goBack();//  w w w .j  a  v a  2  s .co m
            } else {
                // the user cancelled the authorization flow
                sendState(new ErrorOAuth2GrantState(
                        new AuthorizationCancelledError("Authorization cancelled by user.")));
            }
            return true;
        }
    }
    if (event.getAction() == KeyEvent.ACTION_UP) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            // also capture the up event
            return true;
        }
    }
    return false;
}

From source file:com.actionbarsherlock.internal.view.menu.MenuPopupHelper.java

public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) {
        dismiss();/*from   w w  w.java2s .c  o m*/
        return true;
    }
    return false;
}

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

/**
 * {@inheritDoc}/*from w w  w  . j  av a2  s .  co m*/
 */
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:hku.fyp14017.blencode.ui.BackPackActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    //Dismiss ActionMode without effecting checked items

    if (currentFragment != null && currentFragment.getActionModeActive()
            && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        ListAdapter adapter = null;//w w w .  j a  va 2s  .  co m
        if (currentFragment instanceof BackPackScriptFragment) {
            adapter = ((BackPackScriptFragment) currentFragment).getAdapter();
        } else {
            adapter = currentFragment.getListAdapter();
        }
        ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.simas.vc.file_chooser.FileChooser.java

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isLongPress()) {
        dismiss();//from w  w w  .  java  2s.  com
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        navigateUp();
        return true;
    } else {
        return false;
    }
}

From source file:com.coincollection.ReorderCollections.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // If the screen rotated and our view got destroyed/recreated,
    // grab the list of collections from the old view (that we stored
    // in the bundle.)
    if (savedInstanceState != null) {
        mItems = savedInstanceState.getParcelableArrayList("mItems");
        mUnsavedChanges = savedInstanceState.getBoolean("mUnsavedChanges");
    }// w ww . jav  a 2 s .co  m

    RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.reorder_collections_recycler_view);

    mRecyclerView.setBackgroundColor(Color.BLACK);

    // Indicate that the contents do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // Use a linear layout manager
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);

    // Set up the adapter that provides the collection entries
    ReorderAdapter mAdapter = new ReorderAdapter(mItems, this);
    mRecyclerView.setAdapter(mAdapter);

    // Register the ItemTouchHelper Callback so that we can allow reordering
    // collections when the user drags the coin images or long presses and then
    // drags.
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);

    // Register a callback so we can know when the list has been reordered
    mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
            super.onItemRangeMoved(fromPosition, toPosition, itemCount);

            Log.d("onItemRangeMoved", String.valueOf(fromPosition) + " " + String.valueOf(toPosition) + " "
                    + String.valueOf(itemCount));

            ReorderCollections fragment = (ReorderCollections) getFragmentManager()
                    .findFragmentByTag("ReorderFragment");

            fragment.setUnsavedChanges(true);
            fragment.showUnsavedTextView();
        }
    });

    if (mUnsavedChanges) {
        showUnsavedTextView();
    }

    //http://stackoverflow.com/questions/7992216/android-fragment-handle-back-button-press
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.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 (mUnsavedChanges) {
                    showUnsavedChangesMessage();
                } else {
                    closeFragment();
                }
                return true;
            }
            return false;
        }
    });
}

From source file:hku.fyp14017.blencode.ui.ProjectActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Dismiss ActionMode without effecting sounds
    if (spritesListFragment.getActionModeActive() && event.getKeyCode() == KeyEvent.KEYCODE_BACK
            && event.getAction() == KeyEvent.ACTION_UP) {
        SpriteAdapter adapter = (SpriteAdapter) spritesListFragment.getListAdapter();
        adapter.clearCheckedSprites();/*from   ww  w  .j av a 2  s  .  com*/
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java

public DrawerForm(Context context, Context unstyledContext, Callback callback,
        WatcherService.Client watcherServiceClient) {
    this.context = context;
    this.unstyledContext = unstyledContext;
    this.callback = callback;
    this.watcherServiceClient = watcherServiceClient;
    float density = ResourceUtils.obtainDensity(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT,
            SortableListView.LayoutParams.WRAP_CONTENT));
    LinearLayout editTextContainer = new LinearLayout(context);
    editTextContainer.setGravity(Gravity.CENTER_VERTICAL);
    linearLayout.addView(editTextContainer);
    searchEdit = new SafePasteEditText(context);
    searchEdit.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
            v.clearFocus();//  w  w w .  j  a  v  a2 s .c om
        }
        return false;
    });
    searchEdit.setHint(context.getString(R.string.text_code_number_address));
    searchEdit.setOnEditorActionListener(this);
    searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle);
    searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0));
    searchIcon.setScaleType(ImageView.ScaleType.CENTER);
    searchIcon.setOnClickListener(this);
    editTextContainer.addView(searchEdit,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density));
    if (C.API_LOLLIPOP) {
        editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0);
    } else {
        editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density));
    }
    LinearLayout selectorContainer = new LinearLayout(context);
    selectorContainer.setBackgroundResource(
            ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0));
    selectorContainer.setOrientation(LinearLayout.HORIZONTAL);
    selectorContainer.setGravity(Gravity.CENTER_VERTICAL);
    selectorContainer.setOnClickListener(v -> {
        hideKeyboard();
        setChanSelectMode(!chanSelectMode);
    });
    linearLayout.addView(selectorContainer);
    selectorContainer.setMinimumHeight((int) (40f * density));
    if (C.API_LOLLIPOP) {
        selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0);
        ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density);
    } else {
        selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0);
    }
    chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem);
    chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f);
    if (C.API_LOLLIPOP) {
        chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
    } else {
        chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    }
    selectorContainer.addView(chanNameView,
            new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    chanSelectorIcon = new ImageView(context);
    chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0));
    selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density));
    ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL
            | Gravity.END;
    headerView = linearLayout;
    inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null));
    int color = ResourceUtils.getColor(context, R.attr.drawerIconColor);
    ChanManager manager = ChanManager.getInstance();
    Collection<String> availableChans = manager.getAvailableChanNames();
    for (String chanName : availableChans) {
        ChanConfiguration configuration = ChanConfiguration.get(chanName);
        if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) {
            watcherSupportSet.add(chanName);
        }
        Drawable drawable = manager.getIcon(chanName, color);
        chanIcons.put(chanName, drawable);
        chans.add(
                new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable));
    }
    if (availableChans.size() == 1) {
        selectorContainer.setVisibility(View.GONE);
    }
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.EnterStopCodeFragment.java

/**
 * {@inheritDoc}/*from www . ja  v a2  s. c o  m*/
 */
@Override
public boolean onKey(final View v, final int keyCode, final KeyEvent event) {
    // Grab the enter key.
    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER
            && txt.getText().length() == 8) {
        imm.hideSoftInputFromWindow(txt.getWindowToken(), 0);
        task();
    }

    return false;
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view != null) {

        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null)
            parent.removeView(view);//  www  .j a v  a 2s  .  c om

    }
    try {
        view = inflater.inflate(R.layout.fragment_time_estemet, container, false);
    } catch (InflateException e) {
    }
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);

    gps = new GPSTracker(getActivity());
    MyApplication.arrivedrivermarker = true;
    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Please wait...");
    progressDialog.setCancelable(false);

    mlinerlayoutbottom = (LinearLayout) view.findViewById(R.id.ll_bottom);
    mphone = (ImageView) view.findViewById(R.id.iv_phone);
    mphonenumber = (TextView) view.findViewById(R.id.tv_phonenumber);
    marrivaltime = (TextView) view.findViewById(R.id.tv_textarrival);
    mname = (TextView) view.findViewById(R.id.tv_name);
    mlicence = (TextView) view.findViewById(R.id.tv_licence);
    mtaximodel = (TextView) view.findViewById(R.id.tv_model);
    muserImage = (ImageView) view.findViewById(R.id.imageView_close);
    getLatLong();
    btnSplite = (Button) view.findViewById(R.id.btn_splite_rides);

    btnSplite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(getActivity(), SplitAddFrnd.class);
            startActivity(in);
        }
    });

    mphone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String uri = "tel:" + mphonenumber.getText().toString().trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        }
    });

    System.out.println("userId>>>>>>>>>>>>>>>>>>>>>" + mUserId);

    mname.setText(MyApplication.driverName);
    mlicence.setText(MyApplication.licenseId);
    mtaximodel.setText(MyApplication.vehicle);
    mphonenumber.setText(MyApplication.mobileNO);

    Picasso.with(getActivity()).load(MyApplication.imageUrl).error(R.mipmap.avtar).placeholder(R.mipmap.avtar)
            .into(muserImage);

    System.out.println("driverImageurl" + "chceck=" + MyApplication.imageUrl);

    mphonenumber.setText("Call To" + " " + MyApplication.driverName);

    final SinchClient sinchClient = Sinch.getSinchClientBuilder().context(getActivity()).userId(mUserId)
            .applicationKey("3b013f09-db1f-422e-ac7b-c6498e119612")
            .applicationSecret("LMhelEFYtUqms55VX1C7MQ==").environmentHost("sandbox.sinch.com").build();

    sinchClient.setSupportCalling(true);
    sinchClient.start();
    mphone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (call == null) {
                if (MyApplication.mobileNO != null && !MyApplication.mobileNO.equals("")) {
                    call = sinchClient.getCallClient().callPhoneNumber("+" + MyApplication.mobileNO);
                    System.out.println("mobile_number" + MyApplication.mobileNO);
                    //call = sinchClient.getCallClient().callPhoneNumber("+918510834641");
                    try {
                        call.addCallListener(new SinchCallListener());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    mphonenumber.setText("Hang Up");
                }
            } else {
                call.hangup();
            }
        }
    });

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;
}