Example usage for android.view KeyEvent KEYCODE_DPAD_CENTER

List of usage examples for android.view KeyEvent KEYCODE_DPAD_CENTER

Introduction

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

Prototype

int KEYCODE_DPAD_CENTER

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

Click Source Link

Document

Key code constant: Directional Pad Center key.

Usage

From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java

/**
 * Handle the tap event from the touchpad.
 *///from w  w  w  .ja  va  2s  .c  o m
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    // Handle tap events.
    case KeyEvent.KEYCODE_DPAD_CENTER:
        //case KeyEvent.KEYCODE_ENTER:

        AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audio.playSoundEffect(Sounds.TAP);

        _speech.speak("The weather is" + mCurrent + "Fahrenheit and" + mDescription, TextToSpeech.QUEUE_FLUSH,
                null);

        Bitmap bitmap = loadImageFromURL("http://openweathermap.org/img/w/10d.png");
        _weatherIconImageView.setImageBitmap(bitmap);

        return true;
    default:
        return super.onKeyDown(keyCode, event);
    }
}

From source file:com.cybrosys.basic.EventListener.java

@Override
public boolean onKey(View vwView, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/*w  w  w  .  j  av a 2s. c  o  m*/
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true;
    }
    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }
    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        return false;
    }
    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:org.whisperim.android.ui.ChatWindow.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER)
            && (event.getAction() == KeyEvent.ACTION_DOWN)) {
        Log.i("WhisperIM", "KeyCodeIntercepted: " + keyCode);

        if (messageBox_.getText().toString().equalsIgnoreCase("")) {
            return true;
        }//from  w  ww . j a v  a 2  s.c  om

        sendMessage();
        return true;
    }
    return false;
}

From source file:com.mobshep.mobileshepherd.UDataLeakage.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.udl_layout);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w  ww. jav a  2 s  .  co m

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    String destinationDir = "/data/data/" + getPackageName() + "/files/";

    String destinationPath = destinationDir + "Tue Jul 08 172618 EDT 2014";

    File f = new File(destinationPath);

    if (!f.exists()) {
        File directory = new File(destinationDir);
        directory.mkdirs();
        //assets members.db -> /databases/

        try {
            copyKey(getBaseContext().getAssets().open("Tue Jul 08 172618 EDT 2014"),
                    new FileOutputStream(destinationPath));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    ListView noteList = (ListView) findViewById(R.id.noteList);
    final EditText miniNote = (EditText) findViewById(R.id.miniNote);
    final ArrayList<String> noteItems = new ArrayList<String>();
    final ArrayAdapter<String> arrayAdapter;

    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, noteItems);

    noteList.setAdapter(arrayAdapter);

    miniNote.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
                if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || keyCode == KeyEvent.KEYCODE_ENTER) {

                    String Log = miniNote.getText().toString();

                    logDetails(Log);

                    noteItems.add(0, miniNote.getText().toString());
                    arrayAdapter.notifyDataSetChanged();
                    miniNote.setText("");
                    miniNote.setTextColor(Color.WHITE);

                    return true;
                }
            return false;
        }
    }

    );

}

From source file:com.jefftharris.passwdsafe.lib.view.GuiUtils.java

/**
 * Setup the keyboard on a form.  The final field performs the supplied
 * runnable when enter is pressed./* w  w  w  . j  a  v a 2 s  .co  m*/
 */
public static void setupFormKeyboard(TextView firstField, TextView finalField, Context ctx,
        final Runnable enterRunnable) {
    if (firstField != null) {
        GuiUtilsFroyo.showKeyboard(firstField, ctx);
    }

    finalField.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER: {
                    enterRunnable.run();
                    return true;
                }
                }
            }
            return false;
        }
    });
}

From source file:com.luyaozhou.recognizethisforglass.ViewFinder.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_CAMERA: { // camera button (hardware)
        if (keyEnable) {

            camera.stopPreview(); // stop the preview
            camera.release(); // release the camera
            previewOn = false;//from   ww w  .j  av  a2 s.co  m

            keyEnable = false;
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // capture image
                    if (intent.resolveActivity(getPackageManager()) != null) {
                        startActivityForResult(intent, PHOTO_REQUEST_CODE);
                    }
                }
            });

        }
        // Return false to allow the camera button to do its default action
        return false;

    }
    case KeyEvent.KEYCODE_DPAD_CENTER: // touchpad tap
    case KeyEvent.KEYCODE_ENTER: {

        if (keyEnable) {

            camera.stopPreview();
            camera.release();

            previewOn = false; // Don't release the camera in surfaceDestroyed()

            keyEnable = false;
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // capture image
                    if (intent.resolveActivity(getPackageManager()) != null) {
                        startActivityForResult(intent, PHOTO_REQUEST_CODE);
                    }
                }
            });

        }
        return false;
    }
    default: {
        return super.onKeyDown(keyCode, event);
    }
    }
}

From source file:br.com.bioscada.apps.biotracks.fragments.StatsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    handler = new Handler();

    Spinner activityTypeIcon = (Spinner) getView().findViewById(R.id.stats_activity_type_icon);
    activityTypeIcon.setAdapter(TrackIconUtils.getIconSpinnerAdapter(getActivity(), ""));
    activityTypeIcon.setOnTouchListener(new View.OnTouchListener() {
        @Override/*w ww  . ja va 2  s .c om*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                ((TrackDetailActivity) getActivity()).chooseActivityType(category);
            }
            return true;
        }
    });
    activityTypeIcon.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
                ((TrackDetailActivity) getActivity()).chooseActivityType(category);
            }
            return true;
        }
    });
}

From source file:net.xpece.android.support.preference.SeekBarPreference.java

/**
 * Listener reacting to the user pressing DPAD left/right keys if {@code
 * adjustable} attribute is set to true; it transfers the key presses to the SeekBar
 * to be handled accordingly./*from   w ww. j  a  v  a2s. c o m*/
 */
private View.OnKeyListener buildSeekBarKeyListener(final SeekBar seekBar) {
    return new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() != KeyEvent.ACTION_DOWN) {
                return false;
            }

            if (!mAdjustable
                    && (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
                // Right or left keys are pressed when in non-adjustable mode; Skip the keys.
                return false;
            }

            // We don't want to propagate the click keys down to the seekbar view since it will
            // create the ripple effect for the thumb.
            if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
                return false;
            }

            if (seekBar == null) {
                Log.e(TAG, "SeekBar view is null and hence cannot be adjusted.");
                return false;
            }
            return seekBar.onKeyDown(keyCode, event);
        }
    };
}

From source file:org.ednovo.goorusearchwidget.HomeScreenActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_screen);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE);
    headerSearch = (RelativeLayout) findViewById(R.id.layoutHeader);
    imgViewGooruSearch = (ImageView) findViewById(R.id.ivGooruLogo);
    imgViewSections = (ImageView) findViewById(R.id.imgViewSections);
    imgViewSettings = (ImageView) findViewById(R.id.imgViewSettings);
    imageViewClose = (ImageView) findViewById(R.id.imageViewClose);
    imageViewSearch = (ImageView) findViewById(R.id.imageViewSearch);
    editTexthome = (EditText) findViewById(R.id.textViewSearch);
    switchResColl = (Switch) findViewById(R.id.switchResColl);

    dialog = new ProgressDialog(this);
    imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
    new Loginform().execute();
    switchResColl.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override//from  w w  w.  j a  v a2  s  .co m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                Log.i("Hello", "True");
                searchCriteria = true;
            } else {
                Log.i("Hello", "False");
                searchCriteria = false;
            }
        }
    });

    editTexthome.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    searchKeyword = editTexthome.getText().toString().trim();
                    if (searchKeyword.isEmpty() || searchKeyword.length() == 0) {

                    } else {
                        if (!searchCriteria) {
                            Log.i("Resources", searchKeyword);
                            Intent intentResResults = new Intent(getBaseContext(),
                                    SearchResults_resource.class);

                            Bundle extras = new Bundle();
                            extras.putString("keyWord", searchKeyword);
                            intentResResults.putExtras(extras);
                            startActivity(intentResResults);
                            finish();
                        }
                    }
                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });

    imageViewClose.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            finish();
        }
    });

    imgViewGooruSearch.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Intent intentResResults = new Intent(getBaseContext(), SearchDialogpopup.class);

            startActivity(intentResResults);

        }
    });

}

From source file:com.orangelabs.rcs.ri.messaging.chat.ChatView.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /* Set layout */
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.chat_view);/*www  . j  av a  2s. co  m*/

    initialize();

    HistoryUriBuilder uriBuilder = new HistoryUriBuilder(HistoryLog.CONTENT_URI);
    uriBuilder.appendProvider(ChatLog.Message.HISTORYLOG_MEMBER_ID);
    uriBuilder.appendProvider(FileTransferLog.HISTORYLOG_MEMBER_ID);
    mUriHistoryProvider = uriBuilder.build();

    /* Set message composer callbacks */
    mComposeText = (EditText) findViewById(R.id.userText);
    mComposeText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (KeyEvent.ACTION_DOWN != event.getAction()) {
                return false;

            }
            switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_ENTER:
                sendText();
                return true;
            }
            return false;
        }
    });

    mComposeText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Check if the text is not null.
            // we do not wish to consider putting the edit text back to null
            // (like when sending message), is having activity
            if (!TextUtils.isEmpty(s)) {
                // Warn the composing manager that we have some activity
                if (mComposingManager != null) {
                    mComposingManager.hasActivity();
                }
            }
        }

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

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    /* Set send button listener */
    Button sendBtn = (Button) findViewById(R.id.send_button);
    sendBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            sendText();
        }
    });

    /* Initialize the adapter. */
    mAdapter = new ChatCursorAdapter(this, isSingleChat());

    // Associate the list adapter with the ListView.
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(mAdapter);
    registerForContextMenu(listView);

    if (!isServiceConnected(RcsServiceName.CHAT, RcsServiceName.CONTACT, RcsServiceName.CAPABILITY,
            RcsServiceName.FILE_TRANSFER)) {
        showMessageThenExit(R.string.label_service_not_available);
        return;
    }
    startMonitorServices(RcsServiceName.CHAT, RcsServiceName.CONTACT, RcsServiceName.CAPABILITY,
            RcsServiceName.FILE_TRANSFER);
    mChatService = getChatApi();
    mFileTransferService = getFileTransferApi();
    processIntent(getIntent());
}