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:at.alladin.rmbt.android.map.RMBTMapFilterFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        if (currentOptionList != null && !isRoot) {
            populateList(options.getRootOptions(), true);
            return true;
        }//  ww  w.  ja v  a 2 s.  c o m
    }
    return false;
}

From source file:com.velli.passwordmanager.FragmentLockScreen.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) {
        onClick(mButtonOk);/*from www .  j ava2  s  .  c  o m*/
    }
    return false;
}

From source file:com.gao.im.ui.ECLauncherUI.java

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

    if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK) && event.getAction() == KeyEvent.ACTION_UP) {
        // dismiss PlusSubMenuHelper
        if (mOverflowHelper != null && mOverflowHelper.isOverflowShowing()) {
            mOverflowHelper.dismiss();//from   ww w. j a v  a  2s  .  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(ECLauncherUI.class),
                "dispatch key event catch exception " + e.getMessage());
    }

    return false;
}

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

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

    ratingBar = (RatingBar) view.findViewById(R.id.ratingbar);
    Text_tripcomplete_pickuplocation = (TextView) view.findViewById(R.id.tripcomplete_pickuplocation);
    Text_tripcomplete_dropoff_location = (TextView) view.findViewById(R.id.tripcomplete_dropoff_location);
    mname = (TextView) view.findViewById(R.id.tv_name);
    Text_tripcharged = (TextView) view.findViewById(R.id.tripcharged);
    mlicenceplate = (TextView) view.findViewById(R.id.tv_licenceplate);
    mtaname = (TextView) view.findViewById(R.id.tv_taname);
    mcommentbox = (EditText) view.findViewById(R.id.et_commentbox);
    btntip = (Button) view.findViewById(R.id.btntip);
    btnsubmit = (Button) view.findViewById(R.id.btnsubmit);
    icon = (ImageView) view.findViewById(R.id.tripcompltd_icons);

    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);
    prgDialog = new ProgressDialog(getActivity());
    prgDialog.setMessage("Please wait...");
    prgDialog.setCancelable(false);//from w  ww.  j a  v  a2s .c  o  m
    btntip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (MyApplication.RateyourRide == false) {

                LayoutInflater li = LayoutInflater.from(getContext());
                View promptsView = li.inflate(R.layout.prompts, null);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setView(promptsView);
                tipValue = (EditText) promptsView.findViewById(R.id.edittip_value);
                // set dialog message
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // get user input and set it to result
                                // edit text
                                if (tipValue.getText().toString().trim().length() == 0) {

                                } else {
                                    btntip.setText(String.format("Tip: $ %.2f",
                                            Double.valueOf(tipValue.getText().toString())));

                                }
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

                getToken(mUserId);

            }

        }
    });
    rideDriverComplete = sharedPreference.getDriverRidercompleate(getActivity());
    String rideId = MyApplication.RideId;
    if (rideDriverComplete == null && rideId != null) {

        ValidateRidecomplet(mUserId, rideId);
    }

    if (MyApplication.RateyourRide == true) {
        btnsubmit.setVisibility(View.GONE);
        mcommentbox.setVisibility(View.GONE);
    }

    if (rideDriverComplete != null) {

        if (rideDriverComplete.getPickupaddress() != null && rideDriverComplete.getPickupaddress() != " "
                && rideDriverComplete.getDestinationaddress() != null
                && rideDriverComplete.getDestinationaddress() != " ") {
            Text_tripcomplete_pickuplocation.setText(rideDriverComplete.getPickupaddress());
            Text_tripcomplete_dropoff_location.setText(rideDriverComplete.getDestinationaddress());
        }
        try {

            Picasso.with(getActivity()).load(MyPreferences.getActiveInstance(getActivity()).getImageUrl())
                    .error(R.mipmap.avtar).placeholder(R.mipmap.avtar).into(icon);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mname.setText(rideDriverComplete.driverNameride);
        mlicenceplate.setText(rideDriverComplete.licenseId);
        mtaname.setText(rideDriverComplete.vehicle);
        Text_tripcharged
                .setText("$" + rideDriverComplete.getTotalfare() + "  HAS BEEN CHARGED TO YOUR CREDIT CARD");

        btnsubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String totalStars = "Total Stars:: " + ratingBar.getNumStars();
                String rating = "Rating :: " + ratingBar.getRating();
                String tip = "";
                if (rideDriverComplete != null) {

                    String driverid = rideDriverComplete.getDriverIdride();
                    String rideId = rideDriverComplete.getRideId();
                    if (tipValue != null)
                        tip = tipValue.getText().toString();

                    String comment = mcommentbox.getText().toString();
                    if (driverid != null && rideId != null && totalStars != null && tip != null) {

                        validateRideRating(mUserId, driverid, rideId, totalStars, tip, comment);
                    }

                }
            }
        });
    }

    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;

}

From source file:jp.ksksue.app.terminal.AndroidUSBSerialMonitorLite.java

/** Called when the activity is first created. */
@Override//from   w  w w . j ava2s  .  c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* FIXME : How to check that there is a title bar menu or not.
            // Should not set a Window.FEATURE_NO_TITLE on Honeycomb because a user cannot see menu button.
            if(isICSorHigher) {
    if(!getWindow().hasFeature(Window.FEATURE_ACTION_BAR)) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
            }
    */
    setContentView(R.layout.main);

    mSvText = (ScrollView) findViewById(R.id.svText);
    mTvSerial = (TextView) findViewById(R.id.tvSerial);
    btWrite = (Button) findViewById(R.id.btWrite);
    btWrite.setEnabled(false);
    etWrite = (EditText) findViewById(R.id.etWrite);
    etWrite.setEnabled(false);
    etWrite.setHint("CR : \\r, LF : \\n, bin : \\u0000");

    if (SHOW_DEBUG) {
        Log.d(TAG, "New FTDriver");
    }

    // get service
    mSerial = new Physicaloid(this);

    if (SHOW_DEBUG) {
        Log.d(TAG, "New instance : " + mSerial);
    }
    // listen for new devices
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (SHOW_DEBUG) {
        Log.d(TAG, "FTDriver beginning");
    }

    openUsbSerial();

    etWrite.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) {
                writeDataToSerial();
                return true;
            }
            return false;
        }
    });
    // ---------------------------------------------------------------------------------------
    // Write Button
    // ---------------------------------------------------------------------------------------
    if (!USE_WRITE_BUTTON_FOR_DEBUG) {
        btWrite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                writeDataToSerial();
            }
        });
    } else {
        // Write test button for debug
        btWrite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String strWrite = "";
                for (int i = 0; i < 3000; ++i) {
                    strWrite = strWrite + " " + Integer.toString(i);
                }
                if (SHOW_DEBUG) {
                    Log.d(TAG, "FTDriver Write(" + strWrite.length() + ") : " + strWrite);
                }
                mSerial.write(strWrite.getBytes(), strWrite.length());
            }
        });
    } // end of if(SHOW_WRITE_TEST_BUTTON)

    btnLoad = (Button) findViewById(R.id.btnLoad);
    btnLoad.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SimpleFileDialog simpleFileDialog = new SimpleFileDialog(AndroidUSBSerialMonitorLite.this,
                    "FileOpen", new SimpleFileDialog.SimpleFileDialogListener() {
                        @Override
                        public void onChosenDir(String chosenDir) {
                            File file = null;
                            FileInputStream fileInputStream = null;
                            byte[] data;

                            try {
                                file = new File(chosenDir);
                                if (file.isDirectory()) {
                                    throw new IOException("not file");
                                }

                                fileInputStream = new FileInputStream(file);
                                data = new byte[(int) file.length()];
                                fileInputStream.read(data);

                                String dataText = new String(data, "UTF-8");
                                parseJSON(dataText);

                            } catch (IOException e) {
                                Toast.makeText(AndroidUSBSerialMonitorLite.this, e.getMessage(),
                                        Toast.LENGTH_SHORT).show();
                            } finally {
                                if (fileInputStream != null) {
                                    try {
                                        fileInputStream.close();
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                    });
            simpleFileDialog.chooseFile_or_Dir();
        }
    });

    btnPlay = (Button) findViewById(R.id.btnPlay);
    btnPlay.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startIrBeaconPulse();
        }
    });

    btnStop = (Button) findViewById(R.id.btnStop);
    btnStop.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            stopIrBeaconPulse();
        }
    });

    btnPlay.setEnabled(false);
    btnStop.setEnabled(false);
}

From source file:com.android.tv.TvApplication.java

/**
 * Handles the global key KEYCODE_TV_INPUT.
 *///from ww w . ja  va2  s  .  c o m
public void handleTvInputKey() {
    TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    List<TvInputInfo> tvInputs = tvInputManager.getTvInputList();
    int inputCount = 0;
    boolean hasTunerInput = false;
    for (TvInputInfo input : tvInputs) {
        if (input.isPassthroughInput()) {
            if (!input.isHidden(this)) {
                ++inputCount;
            }
        } else if (!hasTunerInput) {
            hasTunerInput = true;
            ++inputCount;
        }
    }
    if (inputCount < 2) {
        return;
    }
    Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity()
            : mSelectInputActivity;
    if (activityToHandle != null) {
        // If startActivity is called, MainActivity.onPause is unnecessarily called. To
        // prevent it, MainActivity.dispatchKeyEvent is directly called.
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT));
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT));
    } else if (mMainActivityWrapper.isStarted()) {
        Bundle extras = new Bundle();
        extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT);
        startMainActivity(extras);
    } else {
        startActivity(new Intent(this, SelectInputActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }
}

From source file:com.volosyukivan.WiFiInputMethod.java

void sendKey(int code, boolean down, boolean resetModifiers) {
    long time = System.currentTimeMillis();
    if (time - lastWake > 5000) {
        wakeLock.acquire();//from ww w  .  j  a v  a  2s.  co  m
        wakeLock.release();
        lastWake = time;
    }
    InputConnection conn = getCurrentInputConnection();
    if (conn == null) {
        //      Debug.d("connection closed");
        return;
    }
    if (code < 0) {
        if (down == false)
            return;
        switch (code) {
        case KEY_HOME:
            keyHome(conn);
            break;
        case KEY_END:
            keyEnd(conn);
            break;
        case KEY_DEL:
            keyDel(conn);
            break;
        }
        return;
    }

    if (code == KeyEvent.KEYCODE_DPAD_LEFT && pressedKeys.contains(KEY_CONTROL)) {
        if (down == false)
            return;
        wordLeft(conn);
        return;
    } else if (code == KeyEvent.KEYCODE_DPAD_RIGHT && pressedKeys.contains(KEY_CONTROL)) {
        if (down == false)
            return;
        wordRight(conn);
        return;
    } else if (code == KeyEvent.KEYCODE_DPAD_CENTER) {
        if (pressedKeys.contains(KEY_CONTROL)) {
            if (!down)
                return;
            copy(conn);
            return;
        }
        if (pressedKeys.contains(KeyEvent.KEYCODE_SHIFT_LEFT)) {
            if (!down)
                return;
            paste(conn);
            return;
        }
    }

    //    if (pressedKeys.contains(KEY_CONTROL)) {
    //      if (down == false) return;
    //      switch (code) {
    //      case KeyEvent.KEYCODE_A: selectAll(conn); break;
    //      case KeyEvent.KEYCODE_X: cut(conn); break;
    //      case KeyEvent.KEYCODE_C: copy(conn); break;
    //      case KeyEvent.KEYCODE_V: paste(conn); break;
    //      }
    //      return;
    //    }

    conn.sendKeyEvent(new KeyEvent(down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, code));
    if (resetModifiers) {
        conn.clearMetaKeyStates(KeyEvent.META_ALT_ON | KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON);
    }
}

From source file:butter.droid.tv.fragments.TVPlaybackOverlayFragment.java

@Override
public boolean handleInputEvent(@NonNull InputEvent event) {
    if (event instanceof KeyEvent) {
        KeyEvent keyEvent = (KeyEvent) event;
        if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_DPAD_CENTER)
            return false;
        if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
            if (mFastForwardAction != null && mSelectedActionId == mFastForwardAction.getId()) {
                if (keyEvent.getRepeatCount() == 0) {
                    mCurrentMode = MODE_FAST_FORWARD;
                    invokeFastForwardAction();
                }//from  w  ww .jav  a2s  .c  om
            } else if (mRewindAction != null && mSelectedActionId == mRewindAction.getId()) {
                if (keyEvent.getRepeatCount() == 0) {
                    mCurrentMode = MODE_REWIND;
                    invokeRewindAction();
                }
            }
        } else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
            mCurrentMode = MODE_NOTHING;
        }
    }
    return false;
}

From source file:com.xee.auth.SignInButton.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER
            || event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        if (mListener != null) {
            mListener.onClick(this);
        }/*from   w w  w.  jav a  2  s.  com*/
        if (mConnectionCallback != null) {
            signIn();
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

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