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:Main.java

/**
 * Checks whether the given event is an ACTION_DOWN event.
 * @param event Event to be checked./*  ww  w  . j  av a  2  s . c  o  m*/
 * @return Whether the event is an ACTION_DOWN event.
 */
public static boolean isActionDown(KeyEvent event) {
    return event.getAction() == KeyEvent.ACTION_DOWN;
}

From source file:Main.java

/**
 * Get an unaccepted key code./*from  w  w  w. j  ava  2s.co m*/
 *
 * @param acceptedChars accepted chars array.
 * @return return key code if we find unaccepted one, or return -1.
 */
public static int getUnacceptedKeyCode(char[] acceptedChars) {
    for (int keyCode = KeyEvent.KEYCODE_A; keyCode <= KeyEvent.KEYCODE_Z; keyCode++) {
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        if ('\0' == event.getMatch(acceptedChars)) {
            return keyCode;
        }
    }
    return -1;
}

From source file:com.judepereira.android.co.uncyclopedia.UncyclopediaActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  ww  w  . j a  v  a2 s .  c  om
    searchText = (EditText) findViewById(R.id.search_edittext);
    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView tv, int i, KeyEvent ke) {
            if ((ke != null) && ke.getAction() == KeyEvent.ACTION_DOWN) {
                search(null);
            }
            if (ke == null) {
                search(null);
            }
            return true;
        }
    });
    wikiView = (WebView) findViewById(R.id.webview);
    client = new UncyclopediaWebViewClient(this, wikiView);
    wikiView.setWebViewClient(client);
    if (savedInstanceState == null) {
        history = new Stack<ArticleHistory>();
        client.setHistory(history);
        client.setUniqueId(Math.random());
        client.setFeatured(true);
        wikiView.loadUrl(c.RANDOM_FEATURED_URL);
    }
}

From source file:com.analysedesgeeks.android.MainActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    //we need to check if we can go back in the twitter fragment. Otherwise, just pass the event down 

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar.getSelectedNavigationIndex() == TWITTER_FRAGMENT_INDEX) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                final WebFragment webFragment = (WebFragment) mTabsAdapter.getItem(TWITTER_FRAGMENT_INDEX);
                if (webFragment.goBack()) {
                    return true;
                }/*from  w  w  w .  j  a va 2s  .c  o  m*/
            }

        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.deviceconnect.android.deviceplugin.theta.activity.ThetaFeatureActivity.java

@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            finish();//from  w  w  w  .ja v  a  2  s.c o m
            break;
        default:
            break;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.digium.respoke.GroupChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group_chat);

    Button buttonSend = (Button) findViewById(R.id.buttonSend);

    EditText chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                sendChatMessage();/*  w w w . j  av  a 2 s  .  co  m*/
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String groupID = null;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        groupID = savedInstanceState.getString(GROUP_ID_KEY);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            groupID = extras.getString(GROUP_ID_KEY);
        } else {
            // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data.
            SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0);
            groupID = prefs.getString(GROUP_ID_KEY, "");
        }
    }

    this.setTitle(groupID);

    for (RespokeGroup eachGroup : ContactManager.sharedInstance().groups) {
        if (eachGroup.getGroupID().equals(groupID)) {
            group = eachGroup;
            break;
        }
    }

    conversation = ContactManager.sharedInstance().groupConversations.get(groupID);

    listAdapter = new ListDataAdapter();

    ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout
    lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView
}

From source file:com.king.base.util.SystemUtils.java

/**
 * /*  w  ww  . ja  v  a  2 s.co m*/
 *
 * @param et
 */
public static void deleteClick(EditText et) {
    final KeyEvent keyEventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
    et.onKeyDown(KeyEvent.KEYCODE_DEL, keyEventDown);
}

From source file:org.videolan.vlc.RemoteControlClientReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (event != null && action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) {

        if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK
                && event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
                && event.getAction() != KeyEvent.ACTION_DOWN) {
            super.onReceive(context, intent);
            return;
        }//from w  ww  . j  a  v a 2s  .c  o  m

        Intent i = null;
        switch (event.getKeyCode()) {
        /*
         * one click => play/pause
         * long click => previous
         * double click => next
         */
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            long time = SystemClock.uptimeMillis();
            switch (event.getAction()) {
            case KeyEvent.ACTION_DOWN:
                if (event.getRepeatCount() <= 0)
                    mHeadsetDownTime = time;
                break;
            case KeyEvent.ACTION_UP:
                if (AndroidDevices.hasTsp()) { //no backward/forward on TV
                    if (time - mHeadsetDownTime >= 1000) { // long click
                        i = new Intent(PlaybackService.ACTION_REMOTE_BACKWARD, null,
                                VLCApplication.getAppContext(), PlaybackService.class);
                        break;
                    } else if (time - mHeadsetUpTime <= 500) { // double click
                        i = new Intent(PlaybackService.ACTION_REMOTE_FORWARD, null,
                                VLCApplication.getAppContext(), PlaybackService.class);
                        break;
                    }
                }
                // one click
                i = new Intent(PlaybackService.ACTION_REMOTE_PLAYPAUSE, null, VLCApplication.getAppContext(),
                        PlaybackService.class);
                mHeadsetUpTime = time;
                break;
            }
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            context.startService(new Intent(PlaybackService.ACTION_REMOTE_PLAY, null,
                    VLCApplication.getAppContext(), PlaybackService.class));
            return;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            i = new Intent(PlaybackService.ACTION_REMOTE_PAUSE, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        case KeyEvent.KEYCODE_MEDIA_STOP:
            i = new Intent(PlaybackService.ACTION_REMOTE_STOP, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            i = new Intent(PlaybackService.ACTION_REMOTE_FORWARD, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            i = new Intent(PlaybackService.ACTION_REMOTE_BACKWARD, null, VLCApplication.getAppContext(),
                    PlaybackService.class);
            break;
        }

        if (isOrderedBroadcast())
            abortBroadcast();
        if (i != null) {
            context.startService(i);
            return;
        }
    } else if (action.equals(PlaybackService.ACTION_REMOTE_PLAYPAUSE)) {
        intent = new Intent(context, PlaybackService.class);
        intent.setAction(PlaybackService.ACTION_REMOTE_PLAYPAUSE);
        context.startService(intent);
        return;
    }
    super.onReceive(context, intent);
}

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean handleCommonKeyDownEvents(Activity a, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }//from  w  ww.j  av a2s . c om
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_NEXT:
    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
        ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content);
        ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0));

        if (list.size() > 0) {
            ViewPager viewPager = (ViewPager) list.get(0);
            viewPager.arrowScroll(View.FOCUS_RIGHT);
        }
        break;
    }

    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
    case KeyEvent.KEYCODE_MEDIA_REWIND: {
        ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content);
        ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0));

        if (list.size() > 0) {
            ViewPager viewPager = (ViewPager) list.get(0);
            viewPager.arrowScroll(View.FOCUS_LEFT);
        }
        break;
    }

    case KeyEvent.KEYCODE_DPAD_LEFT: {
        if (a instanceof DrawerActivity) {
            DrawerActivity da = (DrawerActivity) a;
            DrawerLayout drawerLayout = da.getDrawerLayout();
            View viewFocus = a.getCurrentFocus();
            boolean canOpenDrawer = viewFocus != null && "leftmost".equals(viewFocus.getTag());
            if (canOpenDrawer) {
                drawerLayout.openDrawer(Gravity.LEFT);
                drawerLayout.requestFocus();
                return true;
            }
        }
        break;
    }

    }

    return false;
}