Example usage for android.view KeyEvent getAction

List of usage examples for android.view KeyEvent getAction

Introduction

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

Prototype

public final int getAction() 

Source Link

Document

Retrieve the action of this key event.

Usage

From source file:fi.mikuz.boarder.gui.internet.DownloadBoardList.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.internet_download);
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override//from  w ww . j  a  va 2s.  c  om
        public void onPageSelected(int position) {
            setPageTitle(position + 1);
        }
    });

    setNewViewPager();
    mSearch = (EditText) findViewById(R.id.searchInput);
    mCurrentSearch = "";
    ImageView refresh = (ImageView) findViewById(R.id.refresh);

    Button orderByDate = (Button) findViewById(R.id.orderByDate);
    Button orderByRate = (Button) findViewById(R.id.orderByRate);
    mOrderRule = ORDER_RULE_CHANGE_TIME;
    mOrderDirection = ORDER_DIRECTION_DESCENDING;
    mMaxResults = 40;

    Bundle extras = getIntent().getExtras();
    if (extras.getSerializable(InternetMenu.LOGIN_KEY) != null) {
        @SuppressWarnings("unchecked")
        HashMap<String, String> lastSession = (HashMap<String, String>) extras
                .getSerializable(InternetMenu.LOGIN_KEY);

        mLoggedIn = true;
        mUserId = lastSession.get(InternetMenu.USER_ID_KEY);
        mSessionToken = lastSession.get(InternetMenu.SESSION_TOKEN_KEY);
    }

    mSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView exampleView, int actionId, KeyEvent event) {
            String search = mSearch.getText().toString();
            if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN
                    && !search.equals(mCurrentSearch)) {
                mCurrentSearch = search;
                setNewViewPager();
            }
            return true;
        }
    });

    refresh.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            refreshViewPager();
        }
    });

    orderByDate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mOrderRule.equals(ORDER_RULE_CHANGE_TIME)
                    && mOrderDirection.equals(ORDER_DIRECTION_DESCENDING)) {
                mOrderDirection = ORDER_DIRECTION_ASCENDING;
            } else {
                mOrderRule = ORDER_RULE_CHANGE_TIME;
                mOrderDirection = ORDER_DIRECTION_DESCENDING;
            }
            setNewViewPager();
        }
    });

    orderByRate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (mOrderRule.equals(ORDER_RULE_BOARD_RATING)
                    && mOrderDirection.equals(ORDER_DIRECTION_DESCENDING)) {
                mOrderDirection = ORDER_DIRECTION_ASCENDING;
            } else {
                mOrderRule = ORDER_RULE_BOARD_RATING;
                mOrderDirection = ORDER_DIRECTION_DESCENDING;
            }
            setNewViewPager();
        }
    });

}

From source file:com.lchtime.safetyexpress.ui.chat.hx.activity.ContactActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        //exit();
        finish();/* ww w .ja  va2s  . c om*/
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //moveTaskToBack(false);
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.mstar.tv.tvplayer.philips.setting.SettingFirstFragment.java

@Override
public void onStart() {
    super.onStart();
    listView = getListView();/* w  ww . ja  v  a 2s. c  om*/
    if (getFragmentManager().findFragmentById(R.id.first_fragment) != null) {
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }
    listView.setDivider(null);
    listView.setDividerHeight(5);
    listView.setSelector(android.R.color.transparent);
    listView.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (parent.isFocused())
                settingAdapter.setSelectViewPosition(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    listView.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                settingAdapter.setSelectViewPosition(getSelectedItemPosition());
            } else {
                settingAdapter.setSelectViewPosition(-1);
            }
        }
    });
    listView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_PHOTO) {
                if (K_TvCommonManager.getInstance().K_getCurrentTvInputSource() == K_Constants.INPUT_SOURCE_VGA
                        && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {

                    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                        if (listView.getSelectedItemPosition() == 2) {
                            listView.setSelection(5);
                            return true;
                        }
                    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
                        if (listView.getSelectedItemPosition() == 5) {
                            listView.setSelection(2);
                            return true;
                        } else if (listView.getSelectedItemPosition() == 1) {
                            //listView.setSelection(1);
                            return true;
                        }
                    }
                }
            } else if (TvSettingMenuActivity.firstSelectPositon == SettingKarrays.SETTING_TV) {
                if (!(mTvCommonManager.getCurrentTvInputSource() == TvCommonManager.INPUT_SOURCE_HDMI
                        || mTvCommonManager.getCurrentTvInputSource() == TvCommonManager.INPUT_SOURCE_HDMI2
                        || mTvCommonManager.getCurrentTvInputSource() == TvCommonManager.INPUT_SOURCE_HDMI3)) {//EDID??
                    if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        if (listView.getSelectedItemPosition() == 4) {
                            listView.setSelection(6);
                            return true;
                        }
                    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP
                            && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        if (listView.getSelectedItemPosition() == 6) {
                            listView.setSelection(4);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    });
}

From source file:org.droidpres.activity.TransferActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN && mStartTransferFlag)
        return true;
    else/*from  w  w w.  j  av a 2 s.co m*/
        return super.onKeyDown(keyCode, event);
}

From source file:com.phonegap.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url           The url to load.
 * @param jsonObject //from ww w.j a  v a  2s.  co  m
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx);

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);

            LinearLayout main = new LinearLayout(ctx);
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx);
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            ImageButton back = new ImageButton(ctx);
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });
            back.setId(1);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setLayoutParams(backParams);

            ImageButton forward = new ImageButton(ctx);
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });
            forward.setId(2);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setLayoutParams(forwardParams);

            edittext = new EditText(ctx);
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setLayoutParams(editParams);

            ImageButton close = new ImageButton(ctx);
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });
            close.setId(4);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setLayoutParams(closeParams);

            webview = new WebView(ctx);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);
            WebViewClient client = new ChildBrowserClient(ctx, edittext);
            webview.setWebViewClient(client);
            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(back);
            toolbar.addView(forward);
            toolbar.addView(edittext);
            toolbar.addView(close);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:com.example.castsample.CastSampleActivity.java

/**
 * Processes volume up and volume down actions upon receiving them as key events.
 *///w w w  . j av  a2 s. c  o m
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_DOWN) {
            double currentVolume;
            if (mMessageStream != null) {
                currentVolume = mMessageStream.getVolume();
                logVIfEnabled(TAG, "Volume up from " + currentVolume);
                if (currentVolume < 1.0) {
                    logVIfEnabled(TAG, "New volume: " + (currentVolume + VOLUME_INCREMENT));
                    onSetVolume(currentVolume + VOLUME_INCREMENT);
                }
            } else {
                Log.e(TAG, "dispatchKeyEvent - volume up - mMPMS==null");
            }
        }

        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            double currentVolume;
            if (mMessageStream != null) {
                currentVolume = mMessageStream.getVolume();
                logVIfEnabled(TAG, "Volume down from: " + currentVolume);
                if (currentVolume > 0.0) {
                    logVIfEnabled(TAG, "New volume: " + (currentVolume - VOLUME_INCREMENT));
                    onSetVolume(currentVolume - VOLUME_INCREMENT);
                }
            } else {
                Log.e(TAG, "dispatchKeyEvent - volume down - mMPMS==null");
            }
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:com.nttec.everychan.ui.NewTabFragment.java

@SuppressLint("ClickableViewAccessibility")
@Override// w ww . jav a 2 s .  c o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    activity.setTitle(R.string.tabs_newtab);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        CompatibilityImpl.setActionBarDefaultIcon(activity);
    View v = inflater.inflate(R.layout.newtab_fragment, container, false);
    listView = (DragSortListView) v.findViewById(android.R.id.list);
    DragSortController controller = new DragSortController(listView, R.id.newtab_quickaccess_drag_handle,
            DragSortController.ON_DRAG, 0) {
        @Override
        public View onCreateFloatView(int position) {
            return adapter.getView(position, null, listView);
        }

        @Override
        public void onDragFloatView(View floatView, Point floatPoint, Point touchPoint) {
        }

        @Override
        public void onDestroyFloatView(View floatView) {
        }
    };
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
    listView.setDragEnabled(true);
    listView.setFloatViewManager(controller);
    listView.setOnTouchListener(controller);
    listView.setDropListener(new DragSortListView.DropListener() {
        @Override
        public void drop(int from, int to) {
            if (from != to) {
                QuickAccess.Entry moved = list.remove(from);
                list.add(to, moved);
                adapter.setDraggingItem(-1);
                saveQuickAccessToPreferences();
            }
        }
    });
    registerForContextMenu(listView);
    addressBar = v.findViewById(R.id.newtab_address_bar);
    openAddressBar = (Button) v.findViewById(R.id.newtab_open_address_bar);
    openAddressBar.setOnClickListener(this);
    addressField = (EditText) v.findViewById(R.id.newtab_address_field);
    addressField.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                onClick(v);
                return true;
            }
            return false;
        }
    });
    addressGo = (Button) v.findViewById(R.id.newtab_address_go);
    addressGo.setOnClickListener(this);
    openLocal = (Button) v.findViewById(R.id.newtab_open_local);
    openLocal.setOnClickListener(this);
    return v;
}

From source file:com.apps.anker.facepunchdroid.SettingsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }//w  w  w  . j ava 2  s  . co  m

    }
    return super.onKeyDown(keyCode, 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  w w . j ava2 s.  c  o  m*/
    }
    return true;
}

From source file:com.kiva.ohmylinux.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
            return true;
        }//w  w  w .  j  av  a2s.  c o m

        if (drawer.isDrawerOpen(GravityCompat.END)) {
            drawer.closeDrawer(GravityCompat.END);
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}