List of usage examples for android.os Handler Handler
public Handler()
From source file:Main.java
public static void fadeOut(final View view, int millis) { view.animate().alpha(0f).setDuration(millis).setListener(null); new Handler().postDelayed(new Runnable() { public void run() { view.setVisibility(View.GONE); }// w w w .j ava 2s.co m }, millis); }
From source file:Main.java
public static void scrollToBottom(final ScrollView sv) { Handler handler = new Handler(); handler.post(new Runnable() { @Override//w ww . ja v a2 s.co m public void run() { sv.fullScroll(ScrollView.FOCUS_DOWN); } }); }
From source file:Main.java
public static Timer setTimeOut(final Runnable runnable, int delayMillis) { final Handler handler = new Handler(); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override/*from w ww . j ava 2s . c o m*/ public void run() { handler.post(runnable); timer.cancel(); } }, delayMillis); return timer; }
From source file:Main.java
public static void setKeyboardFocus(final EditText mEditText) { (new Handler()).postDelayed(new Runnable() { public void run() { mEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0)); mEditText.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0)); }/*from www. j a v a 2 s.c o m*/ }, 100); }
From source file:Main.java
public static Timer setInterval(final Runnable runnable, int delayMillis, int period) { final Handler handler = new Handler(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override//w w w . ja v a 2 s . co m public void run() { handler.post(runnable); } }, delayMillis, period); return timer; }
From source file:Main.java
public static void locateCursur(final EditText text) { if (text == null) { return;/*from www.j a v a 2 s . c om*/ } new Handler().postDelayed(new Runnable() { @Override public void run() { Editable b = text.getText(); text.setSelection(b.length()); } }, 100); }
From source file:Main.java
public static void lockForOneSec(final View view) { if (!view.isClickable()) return;//from w w w . ja v a2 s .c o m view.setClickable(false); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (view == null) return; view.setClickable(true); } }, 1000); }
From source file:Main.java
public static void hideSoftKeyBoard(final Window window) { new Handler().postDelayed(new Runnable() { @Override/*from w w w . j a v a2 s . co m*/ public void run() { if (window.getCurrentFocus() != null) { InputMethodManager inputManager = (InputMethodManager) window.getContext() .getSystemService(Activity.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(window.getCurrentFocus().getWindowToken(), 0); } } }, 200); }
From source file:Main.java
public static void setHint(@StringRes final int res, EditText editText) { editText.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus) { new Handler().postDelayed(() -> editText.setHint(res), 200); } else {//from ww w .j a va2 s . c o m editText.setHint(null); } }); }
From source file:Main.java
public static void hideSoftKeyBoard(Context context, final View... views) { try {// w w w.j av a 2 s. co m final InputMethodManager imm = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); new Handler().postDelayed(new Runnable() { @Override public void run() { try { if (views != null) { for (View view : views) { if (view != null) { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } } } catch (Exception e) { } } }, 200); } catch (Exception e) { } }