List of usage examples for android.view KeyEvent KEYCODE_ENTER
int KEYCODE_ENTER
To view the source code for android.view KeyEvent KEYCODE_ENTER.
Click Source Link
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; }/*from w ww. ja v a 2 s .c om*/ return false; }
From source file:com.phonegap.childBrowser.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject // w w w .j a v a 2s. 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.xee.auth.SignInButton.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER || event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { if (mListener != null) { mListener.onClick(this); }// w w w. j a v a 2 s .c om if (mConnectionCallback != null) { signIn(); } } 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.//from ww w. j a v a 2 s .c o 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 ""; }
From source file:com.phonegap.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject /* w w w . j a va 2 s . c om*/ */ 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(), android.R.style.Theme_Translucent_NoTitleBar); 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.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 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(ctx.getContext()); 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.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); 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.taobao.wuzhong.plugins.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject/*from w w w . java2 s . c om*/ */ 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(), android.R.style.Theme_Translucent_NoTitleBar); 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.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 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(ctx.getContext()); 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.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); 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.fatelon.flyingphotobooth.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final LaunchActivity activity = (LaunchActivity) getActivity(); SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(activity.getApplicationContext()); /*/* w w w.j ava 2 s . c om*/ * Reset frames. */ String numPhotosPref = preferences.getString(getString(R.string.pref__number_of_photos_key), getString(R.string.pref__number_of_photos_default)); mFramesTotal = Integer.parseInt(numPhotosPref); mFrameIndex = 0; mFramesData = new byte[mFramesTotal][]; /* * Initialize and set key event handlers. */ mBackPressedHandler = new LaunchActivity.BackPressedHandler() { @Override public boolean onBackPressed() { // If capture sequence is running, exit capture sequence on back pressed event. if (mIsCaptureSequenceRunning) { activity.replaceFragment(CaptureFragment.newInstance(mUseFrontFacing), false, true); } return mIsCaptureSequenceRunning; } }; activity.setBackPressedHandler(mBackPressedHandler); mKeyEventHandler = new LaunchActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ mPreferencesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent preferencesIntent = new Intent(activity, MyPreferenceActivity.class); startActivity(preferencesIntent); } }); // Show switch button only if more than one camera is available. if (mNumCameras > 1) { mSwitchButton.setVisibility(View.VISIBLE); mSwitchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Switch camera. boolean useFrontFacing = false; CameraInfo cameraInfo = new CameraInfo(); if (mCameraId != INVALID_CAMERA_ID) { Camera.getCameraInfo(mCameraId, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { useFrontFacing = true; } // Relaunch fragment with new camera. activity.replaceFragment(CaptureFragment.newInstance(useFrontFacing), false, true); } } }); } // Get trigger mode preference. String triggerPref = preferences.getString(getString(R.string.pref__trigger_key), getString(R.string.pref__trigger_default)); if (triggerPref.equals(getString(R.string.pref__trigger_countdown))) { mTriggerMode = TRIGGER_MODE_COUNTDOWN; } else if (triggerPref.equals(getString(R.string.pref__trigger_burst))) { mTriggerMode = TRIGGER_MODE_BURST; } else { mTriggerMode = TRIGGER_MODE_MANUAL; } // Configure title and start button text. mTitle.setText(String.format(getString(R.string.capture__title_frame), mFrameIndex + 1, mFramesTotal)); if (mTriggerMode == TRIGGER_MODE_MANUAL) { // Update title. mStartButton.setText(getString(R.string.capture__start_manual_button_text)); } else { mStartButton.setText(getString(R.string.capture__start_countdown_button_text)); } // Configure start button behaviour. mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onStartButtonPressedImpl(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { onStartButtonPressedImpl(); return true; } }); }
From source file:io.syng.activity.BaseActivity.java
private void initSearch() { mSearchTextView.addTextChangedListener(new TextWatcher() { @Override//from w ww.j a v a 2 s . c o m public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { String searchValue = editable.toString(); updateDAppList(searchValue); } }); mSearchTextView.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { GeneralUtil.hideKeyBoard(mSearchTextView, BaseActivity.this); return true; } return false; } }); }
From source file:com.arthurtimberly.fragments.CaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final LaunchActivity activity = (LaunchActivity) getActivity(); SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(activity.getApplicationContext()); /*/*from w ww.j a v a2 s . co m*/ * Reset frames. */ // force to use 4 photos /* String numPhotosPref = preferences.getString(getString(R.string.pref__number_of_photos_key), getString(R.string.pref__number_of_photos_default)); */ mFramesTotal = 4;//Integer.parseInt(numPhotosPref); mFrameIndex = 0; mFramesData = new byte[mFramesTotal][]; /* * Initialize and set key event handlers. */ mBackPressedHandler = new LaunchActivity.BackPressedHandler() { @Override public boolean onBackPressed() { // If capture sequence is running, exit capture sequence on back pressed event. if (mIsCaptureSequenceRunning) { activity.replaceFragment(CaptureFragment.newInstance(mUseFrontFacing), false, true); } return mIsCaptureSequenceRunning; } }; activity.setBackPressedHandler(mBackPressedHandler); mKeyEventHandler = new LaunchActivity.KeyEventHandler() { @Override public boolean onKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mStartButton.dispatchKeyEvent(event); return true; } return false; } }; activity.setKeyEventHandler(mKeyEventHandler); /* * Functionalize views. */ mPreferencesButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent preferencesIntent = new Intent(activity, MyPreferenceActivity.class); startActivity(preferencesIntent); } }); // Show switch button only if more than one camera is available. if (mNumCameras > 1) { mSwitchButton.setVisibility(View.VISIBLE); mSwitchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Switch camera. boolean useFrontFacing = false; CameraInfo cameraInfo = new CameraInfo(); if (mCameraId != INVALID_CAMERA_ID) { Camera.getCameraInfo(mCameraId, cameraInfo); if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) { useFrontFacing = true; } // Relaunch fragment with new camera. activity.replaceFragment(CaptureFragment.newInstance(useFrontFacing), false, true); } } }); } // Get trigger mode preference. /* String triggerPref = preferences.getString(getString(R.string.pref__trigger_key), getString(R.string.pref__trigger_default)); if (triggerPref.equals(getString(R.string.pref__trigger_countdown))) { mTriggerMode = TRIGGER_MODE_COUNTDOWN; } else if (triggerPref.equals(getString(R.string.pref__trigger_burst))) { mTriggerMode = TRIGGER_MODE_BURST; } else { mTriggerMode = TRIGGER_MODE_MANUAL; } */ // force to use countdown mode mTriggerMode = TRIGGER_MODE_COUNTDOWN; // Configure title and start button text. mTitle.setText(String.format(getString(R.string.capture__title_frame), mFrameIndex + 1, mFramesTotal)); if (mTriggerMode == TRIGGER_MODE_MANUAL) { // Update title. mStartButton.setText(getString(R.string.capture__start_manual_button_text)); } else { mStartButton.setText(getString(R.string.capture__start_countdown_button_text)); } // Configure start button behaviour. mStartButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onStartButtonPressedImpl(); } }); mStartButton.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { onStartButtonPressedImpl(); return true; } }); }
From source file:org.connectbot.ConsoleFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.frg_console, container, false); this.inflater = inflater; flip = (ViewFlipper) v.findViewById(R.id.console_flip); empty = (TextView) v.findViewById(android.R.id.empty); stringPromptGroup = (RelativeLayout) v.findViewById(R.id.console_password_group); stringPromptInstructions = (TextView) v.findViewById(R.id.console_password_instructions); stringPrompt = (EditText) v.findViewById(R.id.console_password); stringPrompt.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) return false; if (keyCode != KeyEvent.KEYCODE_ENTER) return false; // pass collected password down to current terminal String value = stringPrompt.getText().toString(); PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return false; helper.setResponse(value);// w w w. j av a2s . co m // finally clear password for next user stringPrompt.setText(""); updatePromptVisible(); return true; } }); booleanPromptGroup = (RelativeLayout) v.findViewById(R.id.console_boolean_group); booleanPrompt = (TextView) v.findViewById(R.id.console_prompt); booleanYes = (Button) v.findViewById(R.id.console_prompt_yes); booleanYes.setOnClickListener(new OnClickListener() { public void onClick(View v) { PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return; helper.setResponse(Boolean.TRUE); updatePromptVisible(); } }); booleanNo = (Button) v.findViewById(R.id.console_prompt_no); booleanNo.setOnClickListener(new OnClickListener() { public void onClick(View v) { PromptHelper helper = getCurrentPromptHelper(); if (helper == null) return; helper.setResponse(Boolean.FALSE); updatePromptVisible(); } }); // preload animations for terminal switching slide_left_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_in); slide_left_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_left_out); slide_right_in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_in); slide_right_out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_out); fade_out_delayed = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out_delayed); fade_stay_hidden = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_stay_hidden); // Preload animation for keyboard button keyboard_fade_in = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_in); keyboard_fade_out = AnimationUtils.loadAnimation(getActivity(), R.anim.keyboard_fade_out); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); final RelativeLayout keyboardGroup = (RelativeLayout) v.findViewById(R.id.keyboard_group); mKeyboardButton = (ImageView) v.findViewById(R.id.button_keyboard); mKeyboardButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return; inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED); keyboardGroup.setVisibility(View.GONE); } }); final ImageView ctrlButton = (ImageView) v.findViewById(R.id.button_ctrl); ctrlButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.metaPress(TerminalKeyListener.META_CTRL_ON); keyboardGroup.setVisibility(View.GONE); } }); final ImageView escButton = (ImageView) v.findViewById(R.id.button_esc); escButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.sendEscape(); keyboardGroup.setVisibility(View.GONE); } }); // detect fling gestures to switch between terminals final GestureDetector detect = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { private float totalY = 0; @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { final float distx = e2.getRawX() - e1.getRawX(); final float disty = e2.getRawY() - e1.getRawY(); final int goalwidth = flip.getWidth() / 2; // need to slide across half of display to trigger console change // make sure user kept a steady hand horizontally if (Math.abs(disty) < (flip.getHeight() / 4)) { if (distx > goalwidth) { shiftCurrentTerminal(SHIFT_RIGHT); return true; } if (distx < -goalwidth) { shiftCurrentTerminal(SHIFT_LEFT); return true; } } return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // if copying, then ignore if (copySource != null && copySource.isSelectingForCopy()) return false; if (e1 == null || e2 == null) return false; // if releasing then reset total scroll if (e2.getAction() == MotionEvent.ACTION_UP) { totalY = 0; } // activate consider if within x tolerance if (Math.abs(e1.getX() - e2.getX()) < ViewConfiguration.getTouchSlop() * 4) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; // estimate how many rows we have scrolled through // accumulate distance that doesn't trigger immediate scroll totalY += distanceY; final int moved = (int) (totalY / terminal.bridge.charHeight); // consume as scrollback only if towards right half of screen if (e2.getX() > flip.getWidth() / 2) { if (moved != 0) { int base = terminal.bridge.buffer.getWindowBase(); terminal.bridge.buffer.setWindowBase(base + moved); totalY = 0; return true; } } else { // otherwise consume as pgup/pgdown for every 5 lines if (moved > 5) { ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_DOWN, ' ', 0); terminal.bridge.tryKeyVibrate(); totalY = 0; return true; } else if (moved < -5) { ((vt320) terminal.bridge.buffer).keyPressed(vt320.KEY_PAGE_UP, ' ', 0); terminal.bridge.tryKeyVibrate(); totalY = 0; return true; } } } return false; } }); flip.setLongClickable(true); flip.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // when copying, highlight the area if (copySource != null && copySource.isSelectingForCopy()) { int row = (int) Math.floor(event.getY() / copySource.charHeight); int col = (int) Math.floor(event.getX() / copySource.charWidth); SelectionArea area = copySource.getSelectionArea(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // recording starting area if (area.isSelectingOrigin()) { area.setRow(row); area.setColumn(col); lastTouchRow = row; lastTouchCol = col; copySource.redraw(); } return true; case MotionEvent.ACTION_MOVE: /* ignore when user hasn't moved since last time so * we can fine-tune with directional pad */ if (row == lastTouchRow && col == lastTouchCol) return true; // if the user moves, start the selection for other corner area.finishSelectingOrigin(); // update selected area area.setRow(row); area.setColumn(col); lastTouchRow = row; lastTouchCol = col; copySource.redraw(); return true; case MotionEvent.ACTION_UP: /* If they didn't move their finger, maybe they meant to * select the rest of the text with the directional pad. */ if (area.getLeft() == area.getRight() && area.getTop() == area.getBottom()) { return true; } // copy selected area to clipboard String copiedText = area.copyFrom(copySource.buffer); clipboard.setText(copiedText); Toast.makeText(getActivity(), getString(R.string.console_copy_done, copiedText.length()), Toast.LENGTH_LONG).show(); // fall through to clear state case MotionEvent.ACTION_CANCEL: // make sure we clear any highlighted area area.reset(); copySource.setSelectingForCopy(false); copySource.redraw(); return true; } } Configuration config = getResources().getConfiguration(); if (event.getAction() == MotionEvent.ACTION_DOWN) { lastX = event.getX(); lastY = event.getY(); } else if (event.getAction() == MotionEvent.ACTION_UP && keyboardGroup.getVisibility() == View.GONE && event.getEventTime() - event.getDownTime() < CLICK_TIME && Math.abs(event.getX() - lastX) < MAX_CLICK_DISTANCE && Math.abs(event.getY() - lastY) < MAX_CLICK_DISTANCE) { keyboardGroup.startAnimation(keyboard_fade_in); keyboardGroup.setVisibility(View.VISIBLE); mUIHandler.postDelayed(new Runnable() { public void run() { if (keyboardGroup.getVisibility() == View.GONE) return; keyboardGroup.startAnimation(keyboard_fade_out); keyboardGroup.setVisibility(View.GONE); } }, KEYBOARD_DISPLAY_TIME); } // pass any touch events back to detector return detect.onTouchEvent(event); } }); return v; }