Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

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

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

From source file:com.notepadlite.MainActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/* w ww . j  av a  2  s.  c o m*/
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
        if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) {
            NoteListFragment fragment = (NoteListFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteListFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        } else if (getSupportFragmentManager()
                .findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment) {
            NoteViewFragment fragment = (NoteViewFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteViewFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        } else if (getSupportFragmentManager()
                .findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) {
            NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteEditFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        } else if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof WelcomeFragment) {
            WelcomeFragment fragment = (WelcomeFragment) getSupportFragmentManager()
                    .findFragmentByTag("NoteListFragment");
            fragment.dispatchKeyShortcutEvent(event.getKeyCode());
        }

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

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  ava 2  s.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:dev.memento.MementoBrowser.java

/** Called when the activity is first created. */
@Override/*from  w  w w.  j  av a2s  . co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);

    mUserAgent = getApplicationContext().getText(R.string.user_agent).toString();

    // Set the date and time format
    SimpleDateTime.mDateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
    SimpleDateTime.mTimeFormat = android.text.format.DateFormat.getTimeFormat(getApplicationContext());

    mDateChosenButton = (Button) findViewById(R.id.dateChosen);
    mDateDisplayedView = (TextView) findViewById(R.id.dateDisplayed);

    // Launch the DatePicker dialog box
    mDateChosenButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DIALOG_DATE);
        }
    });

    // Set the current date
    mToday = new SimpleDateTime();

    // Handle change in orientation gracefully
    if (savedInstanceState == null) {
        mCurrentUrl = getApplicationContext().getText(R.string.homepage).toString();
        mOriginalUrl = mCurrentUrl;

        setChosenDate(mToday);
        setDisplayedDate(mToday);

        mMementos = new MementoList();
    } else {
        mCurrentUrl = savedInstanceState.getString("mCurrentUrl");
        mDateChosen = (SimpleDateTime) savedInstanceState.getSerializable("mDateChosen");
        mDateDisplayed = (SimpleDateTime) savedInstanceState.getSerializable("mDateDisplayed");

        setChosenDate(mDateChosen);
        setDisplayedDate(mDateDisplayed);
    }

    mTimegateUris = getResources().getStringArray(R.array.listTimegates);

    // Add some favicons of web archives used by proxy server
    mFavicons = new HashMap<String, Bitmap>();
    mFavicons.put("ia", BitmapFactory.decodeResource(getResources(), R.drawable.ia_favicon));
    mFavicons.put("webcite", BitmapFactory.decodeResource(getResources(), R.drawable.webcite_favicon));
    mFavicons.put("national-archives",
            BitmapFactory.decodeResource(getResources(), R.drawable.national_archives_favicon));

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mProgressBar.setVisibility(View.GONE);

    mLocation = (TextView) findViewById(R.id.locationEditText);
    mLocation.setSelectAllOnFocus(true);

    mLocation.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // Replace title with URL when focus is lost
            if (hasFocus)
                mLocation.setText(mCurrentUrl);
            else if (mPageTitle.length() > 0)
                mLocation.setText(mPageTitle);
        }
    });

    mLocation.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            //Log.d(LOG_TAG, "keyCode = " + keyCode + "   event = " + event.getAction());

            // Go to URL if user presses Go button
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {

                mOriginalUrl = fixUrl(mLocation.getText().toString());

                // Access live version if date is today or in the future
                if (mToday.compareTo(mDateChosen) <= 0) {
                    Log.d(LOG_TAG, "Browsing to " + mOriginalUrl);
                    mWebview.loadUrl(mOriginalUrl);

                    // Clear since we are visiting a different page in the present
                    mMementos.clear();
                } else
                    makeMementoRequests();

                // Hide the virtual keyboard
                ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(mLocation.getWindowToken(), 0);
                return true;
            }

            return false;
        }

    });

    // TEST        
    /*
    Context context = getBaseContext();
    Drawable image = getImage(context, "http://web.archive.org/favicon.ico");
    if (image == null) {
       System.out.println("image is null !!");
    }
    else {
       //image.setBounds(5, 5, 5, 5);
     //ImageView imgView = new ImageView(context);
     //ImageView imgView = (ImageView)findViewById(R.id.imagetest);
     //imgView.setImageDrawable(image);
       mLocation.setCompoundDrawablesWithIntrinsicBounds(image, null, null, null);
    }
    */

    mNextButton = (Button) findViewById(R.id.next);
    mNextButton.setEnabled(false);
    mNextButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Advance to next Memento

            // This could happen if the index has not been set yet
            if (mMementos.getCurrentIndex() < 0) {
                int index = mMementos.getIndex(mDateDisplayed);
                if (index < 0) {
                    Log.d(LOG_TAG, "Could not find next Memento after date " + mDateDisplayed);
                    return;
                } else
                    mMementos.setCurrentIndex(index);
            }

            // Locate the next Memento in the list
            Memento nextMemento = mMementos.getNext();

            if (nextMemento == null) {
                Log.d(LOG_TAG, "Still could not find next Memento!");
                Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex());
            } else {
                SimpleDateTime date = nextMemento.getDateTime();
                setChosenDate(nextMemento.getDateTime());
                showToast("Time travelling to next Memento on " + mDateChosen.dateFormatted());

                mDateDisplayed = date;

                String redirectUrl = nextMemento.getUrl();
                Log.d(LOG_TAG, "Sending browser to " + redirectUrl);
                mWebview.loadUrl(redirectUrl);

                // Just in case it wasn't already enabled
                mPreviousButton.setEnabled(true);

                // If this is the last memento, disable button
                if (mMementos.isLast(date))
                    mNextButton.setEnabled(false);
            }
        }
    });
    mPreviousButton = (Button) findViewById(R.id.previous);
    mPreviousButton.setEnabled(false);
    mPreviousButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Advance to previous Memento

            // This could happen if the index has not been set yet
            if (mMementos.getCurrentIndex() < 0) {
                int index = mMementos.getIndex(mDateDisplayed);
                if (index < 0) {
                    Log.d(LOG_TAG, "Could not find previous Memento before date " + mDateDisplayed);
                    return;
                } else
                    mMementos.setCurrentIndex(index);
            }

            // Locate the prev Memento in the list
            Memento prevMemento = mMementos.getPrevious();

            if (prevMemento == null) {
                Log.d(LOG_TAG, "Still could not find previous Memento!");
                Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex());
            } else {
                SimpleDateTime date = prevMemento.getDateTime();
                setChosenDate(date);
                showToast("Time travelling to previous Memento on " + mDateChosen.dateFormatted());

                mDateDisplayed = date;

                String redirectUrl = prevMemento.getUrl();
                Log.d(LOG_TAG, "Sending browser to " + redirectUrl);
                mWebview.loadUrl(redirectUrl);

                // Just in case it wasn't already enabled
                mNextButton.setEnabled(true);

                // If this is the first memento, disable button
                if (mMementos.isFirst(date))
                    mPreviousButton.setEnabled(false);
            }
        }
    });

    mWebview = (WebView) findViewById(R.id.webview);
    mWebview.setWebViewClient(new MementoWebViewClient());
    mWebview.setWebChromeClient(new MementoWebChromClient());
    mWebview.getSettings().setJavaScriptEnabled(true);
    mWebview.loadUrl(mCurrentUrl);

    mWebview.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            // Set focus here so focus is removed from the location text field
            // which will change the URL into the page's title.
            // There really should be a better way to do this, but it's a general
            // problem that other developers have ran into as well:
            // http://groups.google.com/group/android-developers/browse_thread/thread/9d1681a01f05e782?pli=1

            if (mLocation.hasFocus()) {
                mWebview.requestFocus();
                return true;
            }

            // Hide the virtual keyboard
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(mLocation.getWindowToken(), 0);

            return false;
        }
    });

    //testMementos();
}

From source file:de.qspool.clementineremote.ui.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int currentVolume = App.mClementine.getVolume();
        // Control the volume of clementine if enabled in the options
        if (mSharedPref.getBoolean(App.SP_KEY_USE_VOLUMEKEYS, true)) {
            int volumeInc = Integer
                    .parseInt(mSharedPref.getString(App.SP_VOLUME_INC, Clementine.DefaultVolumeInc));
            switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                Message msgDown = Message.obtain();
                msgDown.obj = ClementineMessageFactory
                        .buildVolumeMessage(App.mClementine.getVolume() - volumeInc);
                App.mClementineConnection.mHandler.sendMessage(msgDown);
                if (currentVolume >= volumeInc) {
                    currentVolume -= volumeInc;
                } else {
                    currentVolume = 0;/*from w ww . j ava2 s.  com*/
                }
                makeToast(getString(R.string.playler_volume) + " " + currentVolume + "%", Toast.LENGTH_SHORT);
                return true;
            case KeyEvent.KEYCODE_VOLUME_UP:
                Message msgUp = Message.obtain();
                msgUp.obj = ClementineMessageFactory
                        .buildVolumeMessage(App.mClementine.getVolume() + volumeInc);
                App.mClementineConnection.mHandler.sendMessage(msgUp);
                if ((currentVolume + volumeInc) >= 100) {
                    currentVolume = 100;
                } else {
                    currentVolume += volumeInc;
                }
                makeToast(getString(R.string.playler_volume) + " " + currentVolume + "%", Toast.LENGTH_SHORT);
                return true;
            default:
                break;
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.google.cloud.solutions.flexenv.PlayActivity.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
        firebase.child(CHS + "/" + currentChannel).push()
                .setValue(new Message(messageText.getText().toString(), acct.getDisplayName()));
        return true;
    }/*  w w w  .j av  a2  s. com*/
    return false;
}

From source file:de.azapps.mirakel.main_activity.tasks_fragment.TasksFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    this.main = (MainActivity) getActivity();
    this.listId = this.main.getCurrentList().getId();
    this.view = inflater.inflate(R.layout.layout_tasks_fragment, container, false);
    this.adapter = null;
    this.created = true;
    this.listView = (ListView) this.view.findViewById(R.id.tasks_list);
    this.listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
    // Events//w  w w .  j  av  a2 s  .co  m
    this.newTask = (EditText) this.view.findViewById(R.id.tasks_new);
    if (MirakelCommonPreferences.isTablet()) {
        this.newTask.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
    }
    this.newTask.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND
                    || actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN) {
                newTask(v.getText().toString());
                v.setText(null);
            }
            return false;
        }
    });
    this.newTask.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(final Editable s) {
            final ImageButton send = (ImageButton) TasksFragment.this.view.findViewById(R.id.btnEnter);
            if (s.length() > 0) {
                send.setVisibility(View.VISIBLE);
            } else {
                send.setVisibility(View.GONE);
            }
        }

        @Override
        public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
            // Nothing
        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            // Nothing
        }
    });
    update(true);
    final ImageButton btnEnter = (ImageButton) this.view.findViewById(R.id.btnEnter);
    btnEnter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            newTask(TasksFragment.this.newTask.getText().toString());
            TasksFragment.this.newTask.setText(null);
        }
    });
    updateButtons();
    return this.view;
}

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 w  w  w . j  a  v  a2s  .  c o  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.anjalimacwan.MainActivity.java

@Override
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
    super.dispatchKeyShortcutEvent(event);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {
            if (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) {
                NoteListFragment fragment = (NoteListFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteListFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            } else if (getSupportFragmentManager()
                    .findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment) {
                NoteViewFragment fragment = (NoteViewFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteViewFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            } else if (getSupportFragmentManager()
                    .findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) {
                NoteEditFragment fragment = (NoteEditFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteEditFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            } else if (getSupportFragmentManager()
                    .findFragmentById(R.id.noteViewEdit) instanceof WelcomeFragment) {
                WelcomeFragment fragment = (WelcomeFragment) getSupportFragmentManager()
                        .findFragmentByTag("NoteListFragment");
                fragment.dispatchKeyShortcutEvent(event.getKeyCode());
            }/*from www  .j a  v  a 2  s .  c om*/

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

From source file:org.protocoder.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) {

        int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_R:
            MLog.d(TAG, "run app");
            break;

        default://from  www . j a v a2s  .  c o  m
            break;
        }
    }

    return super.dispatchKeyEvent(event);
}

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

/**
 * Display a new browser with the specified URL.
 *
 * @param url       The url to load.//  www.j  a  v a 2  s.  co m
 * @param jsonObject 
 */
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.getContext());

            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.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

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

            ImageButton back = new ImageButton(ctx.getContext());
            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.getContext());
            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.getContext());
            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((Context) 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.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGIC")) {
                        String msg = cmsg.message().substring(5); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d("ChildBrowser", "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });
            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new ChildBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    Log.d("ChildBrowser", "\n\nInjecting javascript\n\n");
                    view.loadUrl(
                            "javascript:console.log('MAGIC'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            //        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 "";
}