use of android.view.KeyEvent in project FluxyAndroidTodo by armueller.
the class TodoListArrayAdapter method setHolderListeners.
private void setHolderListeners(final ViewHolder holder, final TodoItem item) {
holder.todoDescription.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
DialogFragment editOrDeleteDialog = new EditOrDeleteDialogFragment();
Bundle args = new Bundle();
args.putLong("todoItemId", item.getId());
editOrDeleteDialog.setArguments(args);
editOrDeleteDialog.show(activity.getFragmentManager(), String.valueOf(item.getId()));
return true;
}
});
holder.todoEditDescription.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
actionCreator.createEditTodoAction(item.getId(), v.getText().toString());
handled = true;
}
return handled;
}
});
holder.todoCheckBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
actionCreator.createToggleTodoCompleteAction(item.getId());
}
});
}
use of android.view.KeyEvent in project coursera-android by aporter.
the class SamplerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
final ImageButton button = (ImageButton) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Show Toast message
Toast.makeText(SamplerActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "Done" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Show Toast message
Toast.makeText(SamplerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Show Toast message indicating the CheckBox's Checked state
if (((CheckBox) v).isChecked()) {
Toast.makeText(SamplerActivity.this, "CheckBox checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SamplerActivity.this, "CheckBox not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
radio_red.setOnClickListener(radio_listener);
radio_blue.setOnClickListener(radio_listener);
final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
togglebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (togglebutton.isChecked()) {
Toast.makeText(SamplerActivity.this, "ToggleButton checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SamplerActivity.this, "ToggleButton not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast.makeText(SamplerActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
}
});
}
use of android.view.KeyEvent in project FBReaderJ by geometer.
the class FileChooserActivity method doCreateNewDir.
// doSwitchViewType()
/**
* Confirms user to create new directory.
*/
private void doCreateNewDir() {
if (mFileProvider instanceof LocalFileProvider && !Utils.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Dlg.toast(this, R.string.afc_msg_app_doesnot_have_permission_to_create_files, Dlg._LengthShort);
return;
}
if ((getLocation() instanceof File)) {
if (!((File) getLocation()).canWrite()) {
Dlg.toast(this, R.string.afc_msg_app_cant_create_folder, Dlg._LengthShort);
return;
}
}
final AlertDialog _dlg = Dlg.newDlg(this);
View view = getLayoutInflater().inflate(R.layout.afc_simple_text_input_view, null);
final EditText _textFile = (EditText) view.findViewById(R.id.afc_simple_text_input_view_text1);
_textFile.setHint(mTextResources.get("folderNameHint"));
_textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Ui.hideSoftKeyboard(FileChooserActivity.this, _textFile.getWindowToken());
_dlg.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
return true;
}
return false;
}
});
_dlg.setView(view);
_dlg.setTitle(mTextResources.get("newFolder"));
_dlg.setIcon(android.R.drawable.ic_menu_add);
_dlg.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String name = _textFile.getText().toString().trim();
if (!FileUtils.isFilenameValid(name)) {
Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_filename_is_invalid, name), Dlg._LengthShort);
return;
}
final IFileProvider fileProvider = mFileProvider;
final IFile location = getLocation();
if (fileProvider == null || location == null) {
return;
}
IFile dir = fileProvider.fromPath(String.format("%s/%s", location.getAbsolutePath(), name));
if (dir.mkdir()) {
Dlg.toast(FileChooserActivity.this, getString(R.string.afc_msg_done), Dlg._LengthShort);
setLocation(getLocation(), null);
} else
Dlg.toast(FileChooserActivity.this, getString(R.string.afc_pmsg_cannot_create_folder, name), Dlg._LengthShort);
}
});
_dlg.show();
final Button _btnOk = _dlg.getButton(DialogInterface.BUTTON_POSITIVE);
_btnOk.setEnabled(false);
_textFile.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
_btnOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
}
});
}
use of android.view.KeyEvent in project android-maps-utils by googlemaps.
the class HeatmapsPlacesDemoActivity method startDemo.
@Override
protected void startDemo() {
EditText editText = (EditText) findViewById(R.id.input_text);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
submit();
handled = true;
}
return handled;
}
});
mCheckboxLayout = (LinearLayout) findViewById(R.id.checkboxes);
setUpMap();
}
use of android.view.KeyEvent in project ListenerMusicPlayer by hefuyicoder.
the class MediaButtonIntentReceiver method onReceive.
@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) {
if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
mClickCounter = 0;
}
mClickCounter++;
if (DEBUG)
Log.v(TAG, "Got headset click, count = " + 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();
}
}
}
Aggregations