List of usage examples for android.app Activity getCurrentFocus
@Nullable
public View getCurrentFocus()
From source file:io.selendroid.server.model.AndroidNativeElement.java
public boolean isDisplayed() { View view = getView();//from ww w . j a v a 2 s. c om boolean hasWindowFocus = view.hasWindowFocus(); int width = view.getWidth(); int height = view.getHeight(); int visibility = view.getVisibility(); boolean isVisible = (View.VISIBLE == visibility); // Check visibility of the view and its parents as well. // This is more reliable when transitions between activities are in progress. boolean isShown = view.isShown(); boolean isDisplayed = hasWindowFocus && isVisible && isShown && (width > 0) && (height > 0); if (!isDisplayed) { Activity activity = instrumentation.getCurrentActivity(); View focusedView = activity.getCurrentFocus(); String displayCheckFailureMessage = String.format( "Display check failed\n" + "for view: %s\n" + "isVisible: %b\nvisibility: %d\nisShown: %b\nhasWindowFocus: %b\n" + "width: %d\nheight: %d\ncurrent activity: %s\nfocused view: %s", view, isVisible, visibility, isShown, hasWindowFocus, width, height, activity, focusedView); SelendroidLogger.debug(displayCheckFailureMessage); if (!isShown) { logIsShownCheckFailure(view); } // Check the view belongs to the same view hierarchy as the view with current window focus. // If true, this usually means a system alert dialog is rendered on top of the view // (typically this is an app crash dialog). if (!hasWindowFocus) { if (activity != null && focusedView != null) { if (view.getRootView() == focusedView.getRootView()) { SelendroidLogger.debug("hasWindowFocus() check failed. " + "This usually means the view is covered by a system dialog."); } } } } return isDisplayed; }
From source file:com.hx.hxchat.activity.ContactlistFragment.java
void hideSoftKeyboard(Activity activity) { if (activity.getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (activity.getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }/*from w w w.ja va 2s . c o m*/ }
From source file:com.vuze.android.remote.AndroidUtilsUI.java
public static boolean handleCommonKeyDownEvents(Activity a, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; }// w w w .j a va 2 s . c o m switch (keyCode) { case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content); ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0)); if (list.size() > 0) { ViewPager viewPager = (ViewPager) list.get(0); viewPager.arrowScroll(View.FOCUS_RIGHT); } break; } case KeyEvent.KEYCODE_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_REWIND: { ViewGroup vg = (ViewGroup) a.findViewById(android.R.id.content); ArrayList list = AndroidUtilsUI.findByClass(vg, ViewPager.class, new ArrayList<View>(0)); if (list.size() > 0) { ViewPager viewPager = (ViewPager) list.get(0); viewPager.arrowScroll(View.FOCUS_LEFT); } break; } case KeyEvent.KEYCODE_DPAD_LEFT: { if (a instanceof DrawerActivity) { DrawerActivity da = (DrawerActivity) a; DrawerLayout drawerLayout = da.getDrawerLayout(); View viewFocus = a.getCurrentFocus(); boolean canOpenDrawer = viewFocus != null && "leftmost".equals(viewFocus.getTag()); if (canOpenDrawer) { drawerLayout.openDrawer(Gravity.LEFT); drawerLayout.requestFocus(); return true; } } break; } } return false; }
From source file:com.b44t.ui.Components.PasscodeView.java
public void onShow() { Activity parentActivity = (Activity) getContext(); if (UserConfig.passcodeType == 1) { if (passwordEditText != null) { passwordEditText.requestFocus(); AndroidUtilities.showKeyboard(passwordEditText); }//from w w w . j a v a2 s. c o m } else { if (parentActivity != null) { View currentFocus = parentActivity.getCurrentFocus(); if (currentFocus != null) { currentFocus.clearFocus(); AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus()); } } } checkFingerprint(); if (getVisibility() == View.VISIBLE) { return; } setAlpha(1.0f); setTranslationY(0); backgroundDrawable = ApplicationLoader.getCachedWallpaper(); if (backgroundDrawable != null) { backgroundFrameLayout.setBackgroundColor(0xb6000000); } else { backgroundFrameLayout.setBackgroundColor(Theme.ACTION_BAR_COLOR); } passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode)); if (UserConfig.passcodeType == 0) { numbersFrameLayout.setVisibility(VISIBLE); passwordEditText.setFocusable(false); passwordEditText.setFocusableInTouchMode(false); checkImage.setVisibility(GONE); } else if (UserConfig.passcodeType == 1) { passwordEditText.setFilters(new InputFilter[0]); numbersFrameLayout.setVisibility(GONE); passwordEditText.setFocusable(true); passwordEditText.setFocusableInTouchMode(true); checkImage.setVisibility(VISIBLE); } setVisibility(VISIBLE); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setText(""); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }
From source file:org.dmfs.android.microfragments.HostFragment.java
private void executeTransition(@NonNull Activity activity, @NonNull FragmentTransition fragmentTransition) { if (!fragmentTransition.timestamp().isAfter(mLastTransactionTimestamp)) { // ignore outdated transition return;/* w w w. ja v a 2s.com*/ } mLastTransactionTimestamp = fragmentTransition.timestamp(); MicroFragment microFragment = new FragmentEnvironment<>( mFragmentManager.findFragmentById(R.id.microfragments_host)).microFragment(); MicroFragmentHost host = new BasicMicroFragmentHost(mOperationDoveCote.cage()); fragmentTransition.prepare(activity, mFragmentManager, host, microFragment); FragmentTransaction fragmentTransaction = fragmentTransition.updateTransaction(activity, mFragmentManager.beginTransaction(), mFragmentManager, host, microFragment); if (!fragmentTransaction.isEmpty()) { fragmentTransaction.commit(); } mFragmentManager.executePendingTransactions(); fragmentTransition.cleanup(activity, mFragmentManager, host, microFragment); // post an update, in case the backstack has not been changed by the transition we still have to notify the listener postUpdate(new FragmentEnvironment<>(currentFragment()).microFragment()); // close keyboard if necessary if (activity.getCurrentFocus() == null) { // no view is focused, close the keyboard InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(activity.findViewById(android.R.id.content).getWindowToken(), 0); } }
From source file:ir.besteveryeverapp.ui.Components.PasscodeView.java
public void onShow() { Activity parentActivity = (Activity) getContext(); if (UserConfig.passcodeType == 1) { if (passwordEditText != null) { passwordEditText.requestFocus(); AndroidUtilities.showKeyboard(passwordEditText); }//from w w w .j a v a 2s . c o m } else { if (parentActivity != null) { View currentFocus = parentActivity.getCurrentFocus(); if (currentFocus != null) { currentFocus.clearFocus(); AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus()); } } } checkFingerprint(); if (getVisibility() == View.VISIBLE) { return; } setAlpha(1.0f); setTranslationY(0); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); if (selectedBackground == 1000001) { backgroundFrameLayout.setBackgroundColor(0xff517c9e); } else { backgroundDrawable = ApplicationLoader.getCachedWallpaper(); if (backgroundDrawable != null) { backgroundFrameLayout.setBackgroundColor(0xbf000000); } else { backgroundFrameLayout.setBackgroundColor(0xff517c9e); } } passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode)); if (UserConfig.passcodeType == 0) { //InputFilter[] filterArray = new InputFilter[1]; //filterArray[0] = new InputFilter.LengthFilter(4); //passwordEditText.setFilters(filterArray); //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE); //passwordEditText.setFocusable(false); //passwordEditText.setFocusableInTouchMode(false); numbersFrameLayout.setVisibility(VISIBLE); passwordEditText.setVisibility(GONE); passwordEditText2.setVisibility(VISIBLE); checkImage.setVisibility(GONE); } else if (UserConfig.passcodeType == 1) { passwordEditText.setFilters(new InputFilter[0]); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); numbersFrameLayout.setVisibility(GONE); passwordEditText.setFocusable(true); passwordEditText.setFocusableInTouchMode(true); passwordEditText.setVisibility(VISIBLE); passwordEditText2.setVisibility(GONE); checkImage.setVisibility(VISIBLE); } setVisibility(VISIBLE); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setText(""); passwordEditText2.eraseAllCharacters(false); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }
From source file:com.goftagram.telegram.ui.Components.PasscodeView.java
public void onShow() { Activity parentActivity = (Activity) getContext(); if (UserConfig.passcodeType == 1) { if (passwordEditText != null) { passwordEditText.requestFocus(); AndroidUtilities.showKeyboard(passwordEditText); }/*ww w . ja va2 s . c o m*/ } else { if (parentActivity != null) { View currentFocus = parentActivity.getCurrentFocus(); if (currentFocus != null) { currentFocus.clearFocus(); AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus()); } } } checkFingerprint(); if (getVisibility() == View.VISIBLE) { return; } if (Build.VERSION.SDK_INT >= 14) { ViewProxy.setAlpha(this, 1.0f); ViewProxy.setTranslationY(this, 0); this.clearAnimation(); } SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); if (selectedBackground == 1000001) { backgroundFrameLayout.setBackgroundColor(0xff517c9e); } else { backgroundDrawable = ApplicationLoader.getCachedWallpaper(); if (backgroundDrawable != null) { backgroundFrameLayout.setBackgroundColor(0xbf000000); } else { backgroundFrameLayout.setBackgroundColor(0xff517c9e); } } passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode)); if (UserConfig.passcodeType == 0) { //InputFilter[] filterArray = new InputFilter[1]; //filterArray[0] = new InputFilter.LengthFilter(4); //passwordEditText.setFilters(filterArray); //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE); //passwordEditText.setFocusable(false); //passwordEditText.setFocusableInTouchMode(false); numbersFrameLayout.setVisibility(VISIBLE); passwordEditText.setVisibility(GONE); passwordEditText2.setVisibility(VISIBLE); checkImage.setVisibility(GONE); } else if (UserConfig.passcodeType == 1) { passwordEditText.setFilters(new InputFilter[0]); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); numbersFrameLayout.setVisibility(GONE); passwordEditText.setFocusable(true); passwordEditText.setFocusableInTouchMode(true); passwordEditText.setVisibility(VISIBLE); passwordEditText2.setVisibility(GONE); checkImage.setVisibility(VISIBLE); } setVisibility(VISIBLE); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setText(""); passwordEditText2.eraseAllCharacters(false); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }
From source file:org.telegram.ui.Components.PasscodeView.java
public void onShow() { Activity parentActivity = (Activity) getContext(); if (UserConfig.passcodeType == 1) { if (passwordEditText != null) { passwordEditText.requestFocus(); AndroidUtilities.showKeyboard(passwordEditText); }/* w ww. j a v a2 s .c o m*/ } else { if (parentActivity != null) { View currentFocus = parentActivity.getCurrentFocus(); if (currentFocus != null) { currentFocus.clearFocus(); AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus()); } } } checkFingerprint(); if (getVisibility() == View.VISIBLE) { return; } if (Build.VERSION.SDK_INT >= 14) { ViewProxy.setAlpha(this, 1.0f); ViewProxy.setTranslationY(this, 0); this.clearAnimation(); } SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); if (selectedBackground == 1000001) { backgroundFrameLayout.setBackgroundColor(0xffff8542); } else { backgroundDrawable = ApplicationLoader.getCachedWallpaper(); if (backgroundDrawable != null) { backgroundFrameLayout.setBackgroundColor(0xbf000000); } else { backgroundFrameLayout.setBackgroundColor(0xffff8542); } } passcodeTextView.setText(LocaleController.getString("EnterYourPasscode", R.string.EnterYourPasscode)); if (UserConfig.passcodeType == 0) { //InputFilter[] filterArray = new InputFilter[1]; //filterArray[0] = new InputFilter.LengthFilter(4); //passwordEditText.setFilters(filterArray); //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE); //passwordEditText.setFocusable(false); //passwordEditText.setFocusableInTouchMode(false); numbersFrameLayout.setVisibility(VISIBLE); passwordEditText.setVisibility(GONE); passwordEditText2.setVisibility(VISIBLE); checkImage.setVisibility(GONE); } else if (UserConfig.passcodeType == 1) { passwordEditText.setFilters(new InputFilter[0]); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); numbersFrameLayout.setVisibility(GONE); passwordEditText.setFocusable(true); passwordEditText.setFocusableInTouchMode(true); passwordEditText.setVisibility(VISIBLE); passwordEditText2.setVisibility(GONE); checkImage.setVisibility(VISIBLE); } setVisibility(VISIBLE); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setText(""); passwordEditText2.eraseAllCharacters(false); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }
From source file:kr.wdream.ui.Components.PasscodeView.java
public void onShow() { Log.d("PassCodeView", "onShow"); Activity parentActivity = (Activity) getContext(); if (UserConfig.passcodeType == 1) { Log.d("PassCodeView", "passcodeType = 1"); if (passwordEditText != null) { Log.d("PassCodeView", "EditText not null"); passwordEditText.requestFocus(); AndroidUtilities.showKeyboard(passwordEditText); }//from w ww .j ava2 s. c o m } else { Log.d("PassCodeView", "passcodeType not 1"); if (parentActivity != null) { Log.d("PassCodeView", "parentActivity not null"); View currentFocus = parentActivity.getCurrentFocus(); if (currentFocus != null) { Log.d("PassCodeView", "current focus not null"); currentFocus.clearFocus(); AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus()); } } } checkFingerprint(); if (getVisibility() == View.VISIBLE) { return; } setAlpha(1.0f); setTranslationY(0); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); if (selectedBackground == 1000001) { backgroundFrameLayout.setBackgroundColor(0xff517c9e); } else { backgroundDrawable = ApplicationLoader.getCachedWallpaper(); if (backgroundDrawable != null) { backgroundFrameLayout.setBackgroundColor(0xbf000000); } else { backgroundFrameLayout.setBackgroundColor(0xff517c9e); } } passcodeTextView.setText( LocaleController.getString("EnterYourPasscode", kr.wdream.storyshop.R.string.EnterYourPasscode)); if (UserConfig.passcodeType == 0) { //InputFilter[] filterArray = new InputFilter[1]; //filterArray[0] = new InputFilter.LengthFilter(4); //passwordEditText.setFilters(filterArray); //passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE); //passwordEditText.setFocusable(false); //passwordEditText.setFocusableInTouchMode(false); numbersFrameLayout.setVisibility(VISIBLE); passwordEditText.setVisibility(GONE); passwordEditText2.setVisibility(VISIBLE); checkImage.setVisibility(GONE); } else if (UserConfig.passcodeType == 1) { passwordEditText.setFilters(new InputFilter[0]); passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); numbersFrameLayout.setVisibility(GONE); passwordEditText.setFocusable(true); passwordEditText.setFocusableInTouchMode(true); passwordEditText.setVisibility(VISIBLE); passwordEditText2.setVisibility(GONE); checkImage.setVisibility(VISIBLE); } setVisibility(VISIBLE); passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setText(""); passwordEditText2.eraseAllCharacters(false); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }
From source file:de.anderdonau.spacetrader.Main.java
public static void hide_keyboard(Activity activity) { // https://stackoverflow.com/a/17789187 InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(INPUT_METHOD_SERVICE); //Find the currently focused view, so we can grab the correct window token from it. View view = activity.getCurrentFocus(); //If no view currently has focus, create a new one, just so we can grab a window token from it if (view == null) { view = new View(activity); }/*from w w w . jav a2 s . c om*/ inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); }