List of usage examples for android.view.inputmethod InputMethodManager toggleSoftInput
public void toggleSoftInput(int showFlags, int hideFlags)
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
void continueConnecting() { // TODO: Implement left-icon //requestWindowFeature(Window.FEATURE_LEFT_ICON); //setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon); setContentView(R.layout.canvas);// ww w .j a v a2 s . c o m canvas = (RemoteCanvas) findViewById(R.id.vnc_canvas); zoomer = (ZoomControls) findViewById(R.id.zoomer); // Initialize and define actions for on-screen keys. initializeOnScreenKeys(); canvas.initializeCanvas(connection, database, new Runnable() { public void run() { try { setModes(); } catch (NullPointerException e) { } } }); canvas.setOnKeyListener(this); canvas.setFocusableInTouchMode(true); canvas.setDrawingCacheEnabled(false); // This code detects when the soft keyboard is up and sets an appropriate visibleHeight in vncCanvas. // When the keyboard is gone, it resets visibleHeight and pans zero distance to prevent us from being // below the desktop image (if we scrolled all the way down when the keyboard was up). // TODO: Move this into a separate thread, and post the visibility changes to the handler. // to avoid occupying the UI thread with this. final View rootView = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0); rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); rootView.getWindowVisibleDisplayFrame(r); // To avoid setting the visible height to a wrong value after an screen unlock event // (when r.bottom holds the width of the screen rather than the height due to a rotation) // we make sure r.top is zero (i.e. there is no notification bar and we are in full-screen mode) // It's a bit of a hack. if (r.top == 0) { if (canvas.bitmapData != null) { canvas.setVisibleHeight(r.bottom); canvas.pan(0, 0); } } // Enable/show the zoomer if the keyboard is gone, and disable/hide otherwise. // We detect the keyboard if more than 19% of the screen is covered. int offset = 0; int rootViewHeight = rootView.getHeight(); if (r.bottom > rootViewHeight * 0.81) { offset = rootViewHeight - r.bottom; // Soft Kbd gone, shift the meta keys and arrows down. if (layoutKeys != null) { layoutKeys.offsetTopAndBottom(offset); keyStow.offsetTopAndBottom(offset); if (prevBottomOffset != offset) { setExtraKeysVisibility(View.GONE, false); canvas.invalidate(); zoomer.enable(); } } } else { offset = r.bottom - rootViewHeight; // Soft Kbd up, shift the meta keys and arrows up. if (layoutKeys != null) { layoutKeys.offsetTopAndBottom(offset); keyStow.offsetTopAndBottom(offset); if (prevBottomOffset != offset) { setExtraKeysVisibility(View.VISIBLE, true); canvas.invalidate(); zoomer.hide(); zoomer.disable(); } } } setKeyStowDrawableAndVisibility(); prevBottomOffset = offset; } }); zoomer.hide(); zoomer.setOnZoomKeyboardClickListener(new View.OnClickListener() { @Override public void onClick(View v) { InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } }); zoomer.setOnShowMenuClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RemoteCanvasActivity.this.openOptionsMenu(); } }); panner = new Panner(this, canvas.handler); inputHandler = getInputHandlerById(R.id.itemInputTouchPanZoomMouse); }
From source file:com.bjerva.tsplex.fragments.PagerFragment.java
@Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { final Locale swedishLocale = new Locale("sv", "SE"); InputMethodManager imm; switch (item.getItemId()) { case MainActivity.ID_SEARCH_BUTTON: search = (EditText) item.getActionView(); final SignListFragment signListFragment = (SignListFragment) mAdapter.getItem(0); search.requestFocus();/*from w ww . j a v a 2 s.c o m*/ search.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence cs, int start, int before, int count) { signListFragment.getmAdapter().getFilter().filter(cs); try { String word = ((SimpleGson) signListFragment.getListView().getItemAtPosition(0)).getWord(); signListFragment.getTextHeader().setText(word.substring(0, 1).toUpperCase(swedishLocale)); } catch (IndexOutOfBoundsException e) { Log.w("IndexErr", "IndexErr after change text"); } signListFragment.setOldSearch(cs.toString()); } }); search.setText(""); imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); break; case MainActivity.ID_COLLAPSE_BUTTON: ((SignCategoryFragment) mAdapter.getItem(1)).collapseaAll(); break; case MainActivity.ID_EDIT_BUTTON: FavouritesFragment favFrag = (FavouritesFragment) mAdapter.getItem(2); mMenu.clear(); if (!favFrag.checkBoxesVisible()) { mMenu.add(0, MainActivity.ID_EDIT_BUTTON, 1, R.string.edit_favs).setIcon(R.drawable.recyclebin) .setShowAsAction( MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); ; } else { favFrag.deleteChecked(); mMenu.add(0, MainActivity.ID_EDIT_BUTTON, 1, R.string.edit_favs).setIcon(R.drawable.edit_query) .setShowAsAction( MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); ; } ma.onPrepareOptionsMenu(mMenu); favFrag.toggleCheckBoxes(); break; } return true; }
From source file:net.momodalo.app.vimtouch.VimTouch.java
private void doToggleSoftKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // force leave fullscreen first WindowManager.LayoutParams attrs = getWindow().getAttributes(); if ((attrs.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) { attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); mFullscreen = false;/*from w ww. j a v a2 s . com*/ mOptionMenu.findItem(R.id.menu_fullscreen).setChecked(mFullscreen); } imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }
From source file:com.anton.gavel.GavelMain.java
public void createDialog(int id) { if (progressDialog != null) { progressDialog.dismiss();/* w w w . ja va 2s .c o m*/ } // handles creation of any dialogs by other actions switch (id) { case DIALOG_PI: //call custom dialog for collecting Personal Info PersonalInfoDialogFragment personalInfoDialog = new PersonalInfoDialogFragment(); personalInfoDialog.setPersonalInfo(mPersonalInfo); personalInfoDialog.show(getSupportFragmentManager(), "PersonalInfoDialogFragment"); break; case DIALOG_ABOUT: //construct a simple dialog to show text //get about text TextView aboutView = new TextView(this); aboutView.setText(R.string.about_text); aboutView.setMovementMethod(LinkMovementMethod.getInstance());//enable links aboutView.setPadding(50, 30, 50, 30); //build dialog AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("About")//title .setView(aboutView)//insert textview from above .setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setIcon(R.drawable.ic_launcher).create() //build .show(); //display break; case DIALOG_SUBMISSION_ERR: AlertDialog.Builder submissionErrorDialog = new AlertDialog.Builder(this); submissionErrorDialog.setTitle("Submission Error")//title .setMessage("There was a problem submitting your complaint on the City's website.")//insert textview from above .setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setIcon(R.drawable.ic_launcher).show(); //display break; case DIALOG_OTHER_COMPLAINT: final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_CLASS_TEXT); // capitalize letters + seperate words AlertDialog.Builder getComplaintDialog = new AlertDialog.Builder(this); getComplaintDialog.setTitle("Other...").setView(input) .setMessage("Give a categorical title for your complaint:") .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); // add the item to list and make it selected complaintsAdapter.insert(value, 0); complaintSpinner.setSelection(0); complaintsAdapter.notifyDataSetChanged(); addToSubmitValues(value); imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard dialog.cancel(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard dialog.cancel(); } }).create(); input.requestFocus(); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);// show keyboard getComplaintDialog.show();//show dialog break; case DIALOG_NO_GEOCODING: AlertDialog.Builder noGeoCoding = new AlertDialog.Builder(this); noGeoCoding.setTitle("Not Available")//title .setMessage( "Your version of Android does not support location-based address lookup. This feature is only supported on Gingerbread and above.")//insert textview from above .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setIcon(R.drawable.ic_launcher).show(); //display break; case DIALOG_INCOMPLETE_PERSONAL_INFORMATION: AlertDialog.Builder incompleteInfo = new AlertDialog.Builder(this); incompleteInfo.setTitle("Incomplete")//title .setMessage( "Your personal information is incomplete. Select 'Edit Personal Information' from the menu and fill in all required fields")//insert textview from above .setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setIcon(R.drawable.ic_launcher).show(); //display break; case DIALOG_NO_COMPLAINT: AlertDialog.Builder noComplaint = new AlertDialog.Builder(this); noComplaint.setTitle("No Comlaint Specified")//title .setMessage("You must specify a complaint (e.g. barking dog).")//insert textview from above .setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setIcon(R.drawable.ic_launcher).show(); //display break; case DIALOG_NO_LOCATION: AlertDialog.Builder incompleteComplaint = new AlertDialog.Builder(this); incompleteComplaint.setTitle("No Location Specified")//title .setMessage("You must specify a location (approximate street address) of the complaint.")//insert textview from above .setPositiveButton("Done", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setIcon(R.drawable.ic_launcher).show(); //display } }
From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java
private void initChatListView() { listView = (ListView) findViewById(R.id.listViewChat); btnChatShowToggle = (Button) findViewById(R.id.btnChatShowToggle); Button btnChatClose = (Button) findViewById(R.id.btnChatClose); Button btnSend = (Button) findViewById(R.id.btnSend); chat_layout = findViewById(R.id.chat_layout); if (adapter == null) { adapter = new ChatListAdapter(this, dataList); }/* www. ja va 2 s . c o m*/ listView.setAdapter(adapter); btnChatShowToggle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (TextUtils.isEmpty((CharSequence) btnChatShowToggle.getTag())) { chat_layout.setVisibility(View.VISIBLE); canvas.getKeyboard().setIsChating(true); btnChatShowToggle.setTag("toggle on"); btnChatShowToggle.setVisibility(View.GONE); } else { canvas.getKeyboard().setIsChating(false); chat_layout.setVisibility(View.GONE); btnChatShowToggle.setTag(""); } } }); btnChatClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { btnChatShowToggle.setVisibility(View.VISIBLE); canvas.getKeyboard().setIsChating(false); chat_layout.setVisibility(View.GONE); btnChatShowToggle.setTag(""); } }); btnSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO runsoft.com.runsupport.mqtt.MSGRECVD final EditText edit = new EditText(RemoteCanvasActivity.this); edit.setBackgroundColor(Color.WHITE); edit.setTextColor(getResources().getColor(R.color.button_text_color)); new AlertDialog.Builder(RemoteCanvasActivity.this).setTitle(" ").setView(edit) .setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String msg = edit.getText().toString().trim(); if (TextUtils.isEmpty(msg)) { Toast.makeText(mThis, " ", Toast.LENGTH_LONG).show(); return; } try { Intent broadcastIntent = new Intent(); broadcastIntent.setAction("runsoft.com.runsupport.mqtt.MSGRECVD"); broadcastIntent.putExtra("runsoft.com.runsupport.mqtt.MSGRECVD_MSGBODY", String.format(Locale.getDefault(), "{\"mode\":\"%s\",\"msg\":\"%s\"}", "map_find_send_msg", msg)); sendBroadcast(broadcastIntent); } catch (Exception e1) { e1.printStackTrace(); } ChatData chatData = new ChatData(); chatData.msg = " : " + msg; chatData.date = getRegdateRelative(); dataList.add(0, chatData); adapter.notifyDataSetChanged(); InputMethodManager inputMgr = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } }).create().show(); } }); }
From source file:jackpal.androidterm.Term.java
private void doToggleSoftKeyboard() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); }
From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java
/** * Initializes the on-screen keys for meta keys and arrow keys. *//* ww w. ja v a2 s . co m*/ private void initializeOnScreenKeys() { layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys); keyStow = (ImageButton) findViewById(R.id.keyStow); setKeyStowDrawableAndVisibility(); keyStow.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (layoutKeys.getVisibility() == View.VISIBLE) { extraKeysHidden = true; setExtraKeysVisibility(View.GONE, false); } else { extraKeysHidden = false; setExtraKeysVisibility(View.VISIBLE, true); } layoutKeys.offsetTopAndBottom(prevBottomOffset); setKeyStowDrawableAndVisibility(); } }); // Define action of tab key and meta keys. keyTab = (ImageButton) findViewById(R.id.keyTab); keyTab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_TAB; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyTab.setImageResource(R.drawable.tabon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyTab.setImageResource(R.drawable.taboff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyEsc = (ImageButton) findViewById(R.id.keyEsc); keyEsc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = 111; /* KEYCODE_ESCAPE */ if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyEsc.setImageResource(R.drawable.escon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyEsc.setImageResource(R.drawable.escoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyCtrl = (ImageButton) findViewById(R.id.keyCtrl); keyCtrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = false; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); } }); keyCtrl.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = true; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); return true; } }); keySuper = (ImageButton) findViewById(R.id.keySuper); keySuper.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = false; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); } }); keySuper.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = true; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); return true; } }); keypad = (HangulKeypad) findViewById(R.id.hangul_keypad); keypad.setVncKeyboard(canvas); keypad.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { btnChatShowToggle.setVisibility(View.VISIBLE); keypad.setVisibility(View.GONE); keypad.setTag(""); keyKor.setVisibility(View.VISIBLE); if (v.getId() == R.id.key_show_eng) { InputMethodManager inputMgr = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } } }); //TODO keyKor = (Button) findViewById(R.id.keyKor); keyKor.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String toggle = (String) keypad.getTag(); if (TextUtils.isEmpty(toggle)) { InputMethodManager inputMgr = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMgr.hideSoftInputFromWindow(btnChatShowToggle.getWindowToken(), 0); new Handler().postDelayed(new Runnable() { @Override public void run() { canvas.getKeyboard().processLocalKeyEvent(144, new KeyEvent(144, 0)); keyKor.setVisibility(View.GONE); keypad.setVisibility(View.VISIBLE); keypad.setTag("1"); } }, 500); } else { keyKor.setVisibility(View.VISIBLE); btnChatShowToggle.setVisibility(View.VISIBLE); keypad.setVisibility(View.GONE); keypad.setTag(""); } } }); keyAlt = (ImageButton) findViewById(R.id.keyAlt); keyAlt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = false; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); } }); keyAlt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = true; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); return true; } }); keyShift = (ImageButton) findViewById(R.id.keyShift); keyShift.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = false; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); } }); keyShift.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = true; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); return true; } }); // vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft); // Define action of arrow keys. keyUp = (ImageButton) findViewById(R.id.keyUpArrow); keyUp.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_UP; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyUp.setImageResource(R.drawable.upon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyUp.setImageResource(R.drawable.upoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyDown = (ImageButton) findViewById(R.id.keyDownArrow); keyDown.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_DOWN; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyDown.setImageResource(R.drawable.downon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyDown.setImageResource(R.drawable.downoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow); keyLeft.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_LEFT; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyLeft.setImageResource(R.drawable.lefton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyLeft.setImageResource(R.drawable.leftoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyRight = (ImageButton) findViewById(R.id.keyRightArrow); keyRight.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_RIGHT; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyRight.setImageResource(R.drawable.righton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyRight.setImageResource(R.drawable.rightoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); }
From source file:androidVNC.VncCanvasActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); database = new VncDatabase(this); connection = new ConnectionBean(); Intent i = getIntent();//from w w w . j a v a 2s . co m Uri data = i.getData(); if ((data != null) && (data.getScheme().equals("vnc"))) { String host = data.getHost(); // This should not happen according to Uri contract, but bug introduced in Froyo (2.2) // has made this parsing of host necessary int index = host.indexOf(':'); int port; if (index != -1) { try { port = Integer.parseInt(host.substring(index + 1)); } catch (NumberFormatException nfe) { port = 0; } host = host.substring(0, index); } else { port = data.getPort(); } if (host.equals(VncConstants.CONNECTION)) { if (connection.Gen_read(database.getReadableDatabase(), port)) { MostRecentBean bean = androidVNC.getMostRecent(database.getReadableDatabase()); if (bean != null) { bean.setConnectionId(connection.get_Id()); bean.Gen_update(database.getWritableDatabase()); } } } else { connection.setAddress(host); connection.setNickname(connection.getAddress()); connection.setPort(port); List<String> path = data.getPathSegments(); if (path.size() >= 1) { connection.setColorModel(path.get(0)); } if (path.size() >= 2) { connection.setPassword(path.get(1)); } connection.save(database.getWritableDatabase()); } } else { Bundle extras = i.getExtras(); if (extras != null) { connection.Gen_populate((ContentValues) extras.getParcelable(VncConstants.CONNECTION)); } if (connection.getPort() == 0) connection.setPort(5900); // Parse a HOST:PORT entry String host = connection.getAddress(); if (host.indexOf(':') > -1) { String p = host.substring(host.indexOf(':') + 1); try { connection.setPort(Integer.parseInt(p)); } catch (Exception e) { } connection.setAddress(host.substring(0, host.indexOf(':'))); } } try { setContentView(fi.aalto.openoranges.project1.mcc.R.layout.canvas); vncCanvas = (VncCanvas) findViewById(fi.aalto.openoranges.project1.mcc.R.id.vnc_canvas); zoomer = (ZoomControls) findViewById(R.id.zoomer); } catch (Exception e) { e.printStackTrace(); } vncCanvas.initializeVncCanvas(connection, new Runnable() { public void run() { setModes(); } }); vncCanvas.setOnGenericMotionListener(this); zoomer.hide(); zoomer.setOnZoomInClickListener(new View.OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { showZoomer(true); vncCanvas.scaling.zoomIn(VncCanvasActivity.this); } }); zoomer.setOnZoomOutClickListener(new View.OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { showZoomer(true); vncCanvas.scaling.zoomOut(VncCanvasActivity.this); } }); zoomer.setOnZoomKeyboardClickListener(new View.OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } }); panner = new Panner(this, vncCanvas.handler); inputHandler = getInputHandlerById(fi.aalto.openoranges.project1.mcc.R.id.itemInputFitToScreen); mToken = getIntent().getStringExtra("token"); mId = getIntent().getStringExtra("id"); mName = getIntent().getStringExtra("name"); //listener for the back-button registerClickCallback(); //Notification in status bar NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(VncCanvasActivity.this) .setSmallIcon(R.drawable.icon_white).setContentTitle(mName + " running") .setContentText("Click to open the application screen"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(VncCanvasActivity.this, VncCanvasActivity.class); resultIntent.setAction(Long.toString(System.currentTimeMillis())); mBuilder.setContentIntent(PendingIntent.getActivity(VncCanvasActivity.this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mNotifyID allows you to update the notification later on. mNotificationManager.notify(mNotifyId, mBuilder.build()); startService(); }
From source file:net.olejon.mdapp.TasksActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Input manager final InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); // Layout/*from ww w .ja va2s . com*/ setContentView(R.layout.activity_tasks); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.tasks_toolbar); toolbar.setTitle(getString(R.string.tasks_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Floating action button FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.tasks_fab); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new MaterialDialog.Builder(mContext).title(getString(R.string.tasks_dialog_title)) .customView(R.layout.activity_tasks_dialog, true) .positiveText(getString(R.string.tasks_dialog_positive_button)) .negativeText(getString(R.string.tasks_dialog_negative_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { EditText taskEditText = (EditText) dialog.findViewById(R.id.tasks_dialog_task); String task = taskEditText.getText().toString().trim(); if (task.equals("")) { mTools.showToast("Du m fylle ut navn p oppgaven", 1); } else { ContentValues contentValues = new ContentValues(); contentValues.put(TasksSQLiteHelper.COLUMN_TASK, task); contentValues.put(TasksSQLiteHelper.COLUMN_CREATED_TIME, ""); contentValues.put(TasksSQLiteHelper.COLUMN_REMINDER_TIME, ""); contentValues.put(TasksSQLiteHelper.COLUMN_COMPLETED, "no"); mSqLiteDatabase.insert(TasksSQLiteHelper.TABLE, null, contentValues); dialog.dismiss(); getTasks(); } } @Override public void onNegative(MaterialDialog dialog) { dialog.dismiss(); } }).showListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue) .negativeColorRes(R.color.black).autoDismiss(false).show(); } }); Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.fab); floatingActionButton.startAnimation(animation); floatingActionButton.setVisibility(View.VISIBLE); // List mListView = (ListView) findViewById(R.id.tasks_list); // Get tasks getTasks(); // Tip dialog if (!mTools.getSharedPreferencesBoolean("TASKS_HIDE_TIP_DIALOG")) { new MaterialDialog.Builder(mContext).title(getString(R.string.tasks_tip_dialog_title)) .content(getString(R.string.tasks_tip_dialog_message)) .positiveText(getString(R.string.tasks_tip_dialog_positive_button)) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { mTools.setSharedPreferencesBoolean("TASKS_HIDE_TIP_DIALOG", true); } }).contentColorRes(R.color.black).positiveColorRes(R.color.dark_blue).show(); } }