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:hku.fyp14017.blencode.ui.fragment.FormulaEditorVariableListFragment.java

@Override
public void onListItemClick(int position) {
    Log.d("catroid", "onListItemClick");
    if (!inContextMode) {
        FormulaEditorFragment formulaEditor = (FormulaEditorFragment) getSherlockActivity()
                .getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
        if (formulaEditor != null) {
            formulaEditor.addUserVariableToActiveFormula(adapter.getItem(position).getName());
            formulaEditor.updateButtonViewOnKeyboard();
        }/*  ww w.  j a v a  2 s.  com*/
        KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
        onKey(null, keyEvent.getKeyCode(), keyEvent);
    }

}

From source file:org.alfresco.mobile.android.application.fragments.help.HelpDialogFragment.java

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

    webView = (WebView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty);
    emptyTextView = (TextView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final FragmentActivity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override//from  ww  w . ja va 2s .co m
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            displayProgress(true);
            if (refreshIcon != null) {
                refreshIcon.setVisible(false);
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (getActivity() == null) {
                return;
            }
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }
            displayProgress(false);
            if (refreshIcon != null) {
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:com.smoothsync.smoothsetup.microfragments.appspecificpassword.AppSpecificWebviewFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            if (mWebView.canGoBack()) {
                // user went back a step
                mWebView.goBack();/* w ww .j  a v  a 2 s . c  om*/
            } else {
                // the user cancelled the authorization flow
                new FragmentEnvironment<>(this).host().execute(getActivity(), new BackTransition());
            }
        }
        return true;
    }
    return false;
}

From source file:com.luo.luofist.base.BaseAppCompatActivity.java

/**
 * Loadding/*from   ww  w. jav  a2  s.c o  m*/
 */
public void showLoadingDialog() {
    try {
        mLoadingDialog = LoadingDialog.createDialog(this);
        mLoadingDialog.setTitle(null);
        mLoadingDialog.setCancelable(false);
        mLoadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                    hideLoadingDialog();
                }
                return true;
            }
        });
        if (!isFinishing()) {
            mLoadingDialog.show();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:singh.amandeep.musicplayer.MediaButtonIntentReceiver.java

/**
 * {@inheritDoc}//www. j  av  a 2s.  co m
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, MusicService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.scooter1556.sms.androidtv.fragment.VideoPlayerFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override/*from   w  ww . java 2s  .c  o  m*/
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
                    if (player != null) {
                        if (player.isPlaying()) {
                            player.pause();
                        } else {
                            player.start();
                        }
                    }
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.syncedsynapse.kore2.ui.RemoteActivity.java

/**
 * Override hardware volume keys and send to Kodi
 *///from w w w. java 2s . c  o m
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Check whether we should intercept this
    boolean useVolumeKeys = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
            Settings.KEY_PREF_USE_HARDWARE_VOLUME_KEYS, Settings.DEFAULT_PREF_USE_HARDWARE_VOLUME_KEYS);
    if (useVolumeKeys) {
        int action = event.getAction();
        int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                new Application.SetVolume(GlobalType.IncrementDecrement.INCREMENT)
                        .execute(hostManager.getConnection(), null, null);
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                new Application.SetVolume(GlobalType.IncrementDecrement.DECREMENT)
                        .execute(hostManager.getConnection(), null, null);
            }
            return true;
        }
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.mozilla.simplepush.simplepushdemoapp.MainActivity.java

/** Initialize the app from the saved state
 *
 * @param savedInstanceState The previously stored instance
 *///from  w w w .  j  a  va2 s.  com
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Properties config;
    try {
        config = loadProperties();
        SENDER_ID = config.getProperty("sender_id");
        if (SENDER_ID == null) {
            Log.e(TAG, "sender_id not definied in configuration file. Aborting");
            return;
        }
    } catch (IOException x) {
        Log.e(TAG, "Could not load properties");
        return;
    }
    setContentView(R.layout.activity_main);

    // Set the convenience globals.
    mDisplay = (TextView) findViewById(R.id.display);
    hostUrl = (EditText) findViewById(R.id.host_edit);
    pingData = (EditText) findViewById(R.id.message);
    sendButton = (Button) findViewById(R.id.send);
    connectButton = (Button) findViewById(R.id.connect);

    context = getApplicationContext();
    // Check that GCM is available on this device.
    if (checkPlayServices()) {
        gcm = GoogleCloudMessaging.getInstance(this);
        regid = getRegistrationId(context);
    } else {
        Log.i(TAG, "No valid Google Play Services APK found");
    }

    // detect the "enter/submit" key for the editor views.
    hostUrl.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            // yes, be very careful about this, else you can send multiple actions.
            if (actionId == EditorInfo.IME_ACTION_SEND || (actionId == EditorInfo.IME_ACTION_UNSPECIFIED
                    && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                registerInBackground();
                handled = true;
            }
            return handled;
        }
    });

    pingData.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND || (actionId == EditorInfo.IME_ACTION_UNSPECIFIED
                    && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                SendNotification(getMessage());
                handled = true;
            }
            return handled;
        }
    });
}

From source file:com.scooter1556.sms.androidtv.fragment.AudioPlayerFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override//from w  ww .  ja  va 2 s.c o  m
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
                    if (audioPlayerService != null) {
                        if (audioPlayerService.isPlaying()) {
                            audioPlayerService.pause();
                        } else {
                            audioPlayerService.start();
                        }
                    }
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:org.alfresco.mobile.android.application.fragments.site.search.SearchSitesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }/*w  w  w  .java  2s .  c o m*/
    setRootView(inflater.inflate(R.layout.fr_site_search, container, false));
    init(getRootView(), emptyListMessageId);

    searchText = (MaterialAutoCompleteTextView) viewById(R.id.search_query);
    searchAdapter = new HistorySearchInlineCursorAdapter(this, null, R.layout.row_two_lines_search);
    getLoaderManager().initLoader(0, null, this);
    searchText.setAdapter(searchAdapter);
    searchText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TwoLinesViewHolder vh = (TwoLinesViewHolder) view.getTag();
            HistorySearch tmphistorySearchItem = HistorySearchManager.retrieveHistorySearch(getActivity(),
                    (Long) vh.choose.getTag());
            searchText.setText(tmphistorySearchItem.getQuery());
            historySearchItem = tmphistorySearchItem;
            search();
        }
    });

    bAdd = (ImageButton) viewById(R.id.search_action);
    bAdd.setEnabled(false);
    activateSend();

    bAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            search();
        }
    });

    searchText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            historySearchItem = null;
            activateSend();
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    searchText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                    && ((actionId == EditorInfo.IME_ACTION_SEARCH)
                            || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                search();
                return true;
            }
            return false;
        }
    });

    return getRootView();
}