public static void showKeyboard(EditText target) { target.requestFocus(); InputMethodManager imm = (InputMethodManager) target.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); // Either show it once imm.showSoftInput(target, InputMethodManager.SHOW_FORCED); // Or toggle it twice with forced and hide with not force imm.toggleSoftInputFromWindow( target.getWindowToken(), InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS); imm.toggleSoftInputFromWindow( target.getWindowToken(), InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS); }
public boolean onKeyLongPress(int keyCode, KeyEvent event) { View v = GeckoApp.mAppContext.getLayerController().getView(); switch (keyCode) { case KeyEvent.KEYCODE_MENU: InputMethodManager imm = getInputMethodManager(); imm.toggleSoftInputFromWindow(v.getWindowToken(), InputMethodManager.SHOW_FORCED, 0); return true; default: break; } return false; }
private void openSearch(Boolean openKeyboard) { if (animateDrawerLogo) { this.materialMenu.animateState(IconState.ARROW); this.drawerLogo.setVisibility(View.GONE); } this.logo.setVisibility(View.GONE); this.search.setVisibility(View.VISIBLE); search.requestFocus(); this.results.setVisibility(View.VISIBLE); animate = true; setAdapter(new SearchAdapter(context, resultList, search)); searchOpen = true; results.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { SearchResult result = resultList.get(arg2); search(result, true); } }); if (initialResults != null) { setInitialResults(); } else { updateResults(); } if (listener != null) listener.onSearchOpened(); if (getSearchText().length() > 0) { micStateChanged(false); mic.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_clear)); } if (openKeyboard) { InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInputFromWindow( getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); } }
public boolean processCommand(String command, String params) { if (command.equals("launchBrowser")) { try { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(params)); startActivity(i); return true; } catch (Exception e) { // No browser? Log.e(TAG, e.toString()); return false; } } else if (command.equals("launchEmail")) { try { Intent send = new Intent(Intent.ACTION_SENDTO); String uriText; uriText = "mailto:[email protected]" + "?subject=Your app is..." + "&body=great! Or?"; uriText = uriText.replace(" ", "%20"); Uri uri = Uri.parse(uriText); send.setData(uri); startActivity(Intent.createChooser(send, "E-mail the app author!")); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException Log.e(TAG, e.toString()); return false; } } else if (command.equals("sharejpeg")) { try { Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/jpeg"); share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + params)); startActivity(Intent.createChooser(share, "Share Picture")); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException Log.e(TAG, e.toString()); return false; } } else if (command.equals("sharetext")) { try { Intent sendIntent = new Intent(); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, params); sendIntent.setAction(Intent.ACTION_SEND); startActivity(sendIntent); return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException Log.e(TAG, e.toString()); return false; } } else if (command.equals("showTwitter")) { try { String twitter_user_name = params; try { startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("twitter://user?screen_name=" + twitter_user_name))); } catch (Exception e) { startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse("https://twitter.com/#!/" + twitter_user_name))); } return true; } catch (Exception e) { // For example, android.content.ActivityNotFoundException Log.e(TAG, e.toString()); return false; } } else if (command.equals("launchMarket")) { // Don't need this, can just use launchBrowser with a market: // http://stackoverflow.com/questions/3442366/android-link-to-market-from-inside-another-app // http://developer.android.com/guide/publishing/publishing.html#marketintent return false; } else if (command.equals("toast")) { Toast toast = Toast.makeText(this, params, Toast.LENGTH_SHORT); toast.show(); Log.i(TAG, params); return true; } else if (command.equals("showKeyboard") && mSurfaceView != null) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // No idea what the point of the ApplicationWindowToken is or if it // matters where we get it from... inputMethodManager.toggleSoftInputFromWindow( mSurfaceView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); return true; } else if (command.equals("hideKeyboard") && mSurfaceView != null) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInputFromWindow( mSurfaceView.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); return true; } else if (command.equals("inputbox")) { String title = "Input"; String defString = ""; String[] param = params.split(":"); if (param[0].length() > 0) title = param[0]; if (param.length > 1) defString = param[1]; Log.i(TAG, "Launching inputbox: " + title + " " + defString); inputBox(title, defString, "OK"); return true; } else if (command.equals("vibrate") && mSurfaceView != null) { int milliseconds = -1; if (params != "") { try { milliseconds = Integer.parseInt(params); } catch (NumberFormatException e) { } } // Special parameters to perform standard haptic feedback // operations // -1 = Standard keyboard press feedback // -2 = Virtual key press // -3 = Long press feedback // Note that these three do not require the VIBRATE Android // permission. switch (milliseconds) { case -1: mSurfaceView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); break; case -2: mSurfaceView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); break; case -3: mSurfaceView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); break; default: if (vibrator != null) { vibrator.vibrate(milliseconds); } break; } return true; } else if (command.equals("finish")) { finish(); } else if (command.equals("rotate")) { updateScreenRotation(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Log.i(TAG, "Must recreate activity on rotation"); } } else if (command.equals("immersive")) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { updateSystemUiVisibility(); } } else if (command.equals("recreate")) { exitEGLRenderLoop(); recreate(); } else if (command.equals("ask_permission") && params.equals("storage")) { askForStoragePermission(); } return false; }
@Override public void onClick(View v) { final int id = v.getId(); switch (id) { case R.id.left_btn: case R.id.left_txt: actFinish(); break; case R.id.right_btn: showGroupManageActivity(); break; case R.id.show_add_photo_btn: { recordAudioBtn.setVisibility(View.GONE); keyboardInputImg.setVisibility(View.GONE); messageEdt.setVisibility(View.VISIBLE); audioInputImg.setVisibility(View.VISIBLE); addEmoBtn.setVisibility(View.VISIBLE); if (keyboardHeight != 0) { this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } if (addOthersPanelView.getVisibility() == View.VISIBLE) { if (!messageEdt.hasFocus()) { messageEdt.requestFocus(); } inputManager.toggleSoftInputFromWindow(messageEdt.getWindowToken(), 1, 0); if (keyboardHeight == 0) { addOthersPanelView.setVisibility(View.GONE); } } else if (addOthersPanelView.getVisibility() == View.GONE) { addOthersPanelView.setVisibility(View.VISIBLE); inputManager.hideSoftInputFromWindow(messageEdt.getWindowToken(), 0); } if (null != emoLayout && emoLayout.getVisibility() == View.VISIBLE) { emoLayout.setVisibility(View.GONE); } scrollToBottomListItem(); } break; case R.id.take_photo_btn: { if (albumList.size() < 1) { Toast.makeText( MessageActivity.this, getResources().getString(R.string.not_found_album), Toast.LENGTH_LONG) .show(); return; } // 选择图片的时候要将session的整个回话 传过来 Intent intent = new Intent(MessageActivity.this, PickPhotoActivity.class); intent.putExtra(IntentConstant.KEY_SESSION_KEY, currentSessionKey); startActivityForResult(intent, SysConstant.ALBUM_BACK_DATA); MessageActivity.this.overridePendingTransition(R.anim.tt_album_enter, R.anim.tt_stay); // addOthersPanelView.setVisibility(View.GONE); messageEdt.clearFocus(); // 切记清除焦点 scrollToBottomListItem(); } break; // case R.id.take_camera_btn: { // Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // takePhotoSavePath = CommonUtil.getImageSavePath(String.valueOf(System // .currentTimeMillis()) // + ".jpg"); // intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new // File(takePhotoSavePath))); // startActivityForResult(intent, SysConstant.CAMERA_WITH_DATA); // //addOthersPanelView.setVisibility(View.GONE); // messageEdt.clearFocus();//切记清除焦点 // scrollToBottomListItem(); // } // break; case R.id.take_camera_btn: { Intent intent = new Intent(MessageActivity.this, CameraActivity.class); intent.putExtra(IntentConstant.KEY_SESSION_KEY, currentSessionKey); startActivity(intent); } break; case R.id.show_emo_btn: { /** yingmu 调整成键盘输出 */ recordAudioBtn.setVisibility(View.GONE); keyboardInputImg.setVisibility(View.GONE); messageEdt.setVisibility(View.VISIBLE); audioInputImg.setVisibility(View.VISIBLE); addEmoBtn.setVisibility(View.VISIBLE); /** end */ if (keyboardHeight != 0) { this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); } if (emoLayout.getVisibility() == View.VISIBLE) { if (!messageEdt.hasFocus()) { messageEdt.requestFocus(); } inputManager.toggleSoftInputFromWindow(messageEdt.getWindowToken(), 1, 0); if (keyboardHeight == 0) { emoLayout.setVisibility(View.GONE); } } else if (emoLayout.getVisibility() == View.GONE) { emoLayout.setVisibility(View.VISIBLE); yayaEmoGridView.setVisibility(View.VISIBLE); emoRadioGroup.check(R.id.tab1); emoGridView.setVisibility(View.GONE); inputManager.hideSoftInputFromWindow(messageEdt.getWindowToken(), 0); } if (addOthersPanelView.getVisibility() == View.VISIBLE) { addOthersPanelView.setVisibility(View.GONE); } } break; case R.id.send_message_btn: { logger.d("message_activity#send btn clicked"); String content = messageEdt.getText().toString(); logger.d("message_activity#chat content:%s", content); if (content.trim().equals("")) { Toast.makeText( MessageActivity.this, getResources().getString(R.string.message_null), Toast.LENGTH_LONG) .show(); return; } TextMessage textMessage = TextMessage.buildForSend(content, loginUser, peerEntity); imService.getMessageManager().sendText(textMessage); messageEdt.setText(""); pushList(textMessage); scrollToBottomListItem(); } break; case R.id.voice_btn: { inputManager.hideSoftInputFromWindow(messageEdt.getWindowToken(), 0); messageEdt.setVisibility(View.GONE); audioInputImg.setVisibility(View.GONE); recordAudioBtn.setVisibility(View.VISIBLE); keyboardInputImg.setVisibility(View.VISIBLE); emoLayout.setVisibility(View.GONE); addOthersPanelView.setVisibility(View.GONE); messageEdt.setText(""); } break; case R.id.show_keyboard_btn: { recordAudioBtn.setVisibility(View.GONE); keyboardInputImg.setVisibility(View.GONE); messageEdt.setVisibility(View.VISIBLE); audioInputImg.setVisibility(View.VISIBLE); addEmoBtn.setVisibility(View.VISIBLE); } break; case R.id.message_text: break; case R.id.tt_new_msg_tip: { scrollToBottomListItem(); textView_new_msg_tip.setVisibility(View.GONE); } break; } }