Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

In this page you can find the example usage for android.os Handler postDelayed.

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:com.liferay.alerts.activity.SignInActivity.java

protected void showKeyboard() {
    final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    Runnable runnable = new Runnable() {

        @Override//w  ww  .jav a2s. co m
        public void run() {
            manager.showSoftInput(_server, InputMethodManager.SHOW_IMPLICIT);
        }

    };

    int delay = getResources().getInteger(R.integer.compose_show_keyboard_delay);

    Handler handler = new Handler();
    handler.postDelayed(runnable, delay);
}

From source file:nu.yona.app.customview.CustomProgressDialog.java

/**
 * Show.// w  w  w.  j a  v a  2  s  .c o  m
 *
 * @param duration the duration
 */
public void show(int duration) {
    try {
        super.show();
        hideOkBtn();
        Handler handler;
        handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (CustomProgressDialog.this.isShowing()) {
                    CustomProgressDialog.this.cancel();
                    CustomProgressDialog.this.dismiss();
                }
            }
        }, duration);
    } catch (Exception e) {
        AppUtils.reportException(CustomProgressDialog.class.getSimpleName(), e, Thread.currentThread());
    }
}

From source file:org.schabi.terminightor.NightKillerActivity.java

@Override
protected void onResume() {
    Intent intent = new Intent(this, this.getClass());
    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    pendingIntent = PendingIntent.getActivity(this, SpecialPendingIds.NIGHT_KILLER_READ_NFC_TAG_ID, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    IntentFilter[] intentFilters = new IntentFilter[] {};
    nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilters, null);

    Handler handler = new Handler();
    handler.postDelayed(animRunnable, 500);
    hasStopped = false;//from   w w  w .j a v a  2 s  .co m

    super.onResume();
}

From source file:org.apache.cordova.screenorientation.ScreenOrientation.java

/**
 * Executes the request and returns whether the action was valid.
 *
 * @param action                 The action to execute.
 * @param args                 JSONArray of arguments for the plugin.
 * @param callbackContext        The callback context used when calling back into JavaScript.
 * @return                         True if the action was valid, false otherwise.
 *///from  w  w w. j av a 2  s.c  o  m
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    final String orientation = args.optString(0);
    final Activity activity = this.cordova.getActivity();
    final View view = this.webView;

    if (action.equals("setOrientation")) {
        LOG.w("ScreenOrientation", "Change orientation");
        final int androidOrientation = getOrientation(orientation);
        if (lastOrientation == -1) {
            lastOrientation = androidOrientation;
        }

        if (lastOrientation != androidOrientation) {
            activity.runOnUiThread(new Runnable() {
                public void run() {
                    LOG.v("ScreenOrientation", "Set orientation");
                    view.setVisibility(View.INVISIBLE);
                    activity.setRequestedOrientation(androidOrientation);

                    final Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            view.setVisibility(View.VISIBLE);
                        }
                    }, 1300);
                }
            });
            lastOrientation = androidOrientation;
        }

        callbackContext.success();
        return true;
    } else {
        return false;
    }
}

From source file:com.pixelpixel.pyp.SplashActivity.java

/** Called when the activity is first created. */
@Override//  w  w w  .  j ava  2 s  .c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    //Initializing the application cache
    final int memClass = ((ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    final int cacheSize = 1024 * 1024 * memClass / 4;
    mMemoryCache = new LruCache<String, Object>(cacheSize);

    /*
     * Setting up the animation for the logo
     * */
    final ImageView splash_logo = (ImageView) findViewById(R.id.SplashLogo);
    Animation sa1 = AnimationUtils.loadAnimation(this, R.anim.splash_anim);
    sa1.setAnimationListener(new AnimationListener() {

        public void onAnimationEnd(Animation arg0) {
            /*
             * After the end of the "growing" animation, we call the "shrinking" animation.
             * */
            Animation sa2 = AnimationUtils.loadAnimation(SplashActivity.this, R.anim.splash_anim2);
            sa2.setAnimationListener(new AnimationListener() {

                public void onAnimationEnd(Animation animation) {
                    /*
                     * After the end of the "shrinking" animation, we proceed to the
                     * next screen, the start screen.
                     * */
                    Handler mHandler = new Handler();
                    mHandler.postDelayed(new Runnable() {
                        public void run() {
                            startActivity(new Intent(SplashActivity.this, StartActivity.class));
                            SplashActivity.this.finish();
                        }
                    }, 5000);
                }

                public void onAnimationRepeat(Animation animation) {
                }

                public void onAnimationStart(Animation animation) {
                }

            });
            splash_logo.startAnimation(sa2);
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationStart(Animation animation) {
        }

    });

    splash_logo.startAnimation(sa1);
}

From source file:com.liferay.alerts.activity.ComposeActivity.java

protected void showKeyboard() {
    final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    Runnable runnable = new Runnable() {

        @Override/*from   w ww .jav a 2  s  . c o m*/
        public void run() {
            manager.showSoftInput(_edit, InputMethodManager.SHOW_IMPLICIT);
        }

    };

    int delay = getResources().getInteger(R.integer.compose_show_keyboard_delay);

    Handler handler = new Handler();
    handler.postDelayed(runnable, delay);

    _edit.setKeyboardHideListener(new KeyboardHideListener() {

        @Override
        public void onHide() {
            finish();
        }

    });
}

From source file:com.sentaroh.android.SMBSync2.ShortcutAutoSync.java

final public void onResume() {
    super.onResume();
    util.addDebugMsg(1, "I", "onResume entered restartStaus=" + restartStatus);

    if (restartStatus == 0) {
        if (SyncService.isDuplicateRequest(mGp, SMBSYNC_SYNC_REQUEST_SHORTCUT)) {
            util.addLogMsg("W",
                    String.format(
                            context.getString(
                                    R.string.msgs_svc_received_start_request_ignored_duplicate_request),
                            SMBSYNC_SYNC_REQUEST_SHORTCUT));
            Toast.makeText(context,/*  w ww  .ja va 2 s  .  co m*/
                    String.format(
                            context.getString(
                                    R.string.msgs_svc_received_start_request_ignored_duplicate_request),
                            SMBSYNC_SYNC_REQUEST_SHORTCUT),
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(context, context.getString(R.string.msgs_svc_received_start_request_from_shortcut),
                    Toast.LENGTH_LONG).show();
            Intent in = new Intent(context, SyncService.class);
            in.setAction(SMBSYNC_AUTO_SYNC_INTENT);
            context.startService(in);
        }
    }
    Handler hndl = new Handler();
    hndl.postDelayed(new Runnable() {
        @Override
        public void run() {
            finish();
        }
    }, 2000);
}

From source file:com.hector.invoice.common.BaseFragmentActivity.java

/**
 * //from w w w.j  a  v a2 s .co  m
 * show progress dialog
 * 
 * @author: HaiTC3
 * @param content
 * @param cancleable
 * @return: void
 * @throws:
 */
public void showProgressDialog(String content, boolean cancleable, boolean isTimeout, int numTimeout) {
    if (progressDlg != null && progressDlg.isShowing()) {
        closeProgressDialog();
    }
    progressDlg = ProgressDialog.show(this, "", content, true, true);
    progressDlg.setCancelable(cancleable);
    progressDlg.setCanceledOnTouchOutside(false);
    progressDlg.setOnCancelListener(this);

    if (isTimeout) {
        Handler handler = null;
        handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                progressDlg.cancel();
                progressDlg.dismiss();
            }
        }, numTimeout);
    }
}

From source file:com.cranberrygame.phonegap.plugin.NavigationBar.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void _setUp(boolean autoHideNavigationBar) {
    if (autoHideNavigationBar) {
        Activity activity = cordova.getActivity();
        //http://stackoverflow.com/questions/21164836/immersive-mode-navigation-becomes-sticky-after-volume-press-or-minimise-restore
        //http://www.youtube.com/watch?v=Xw9TIS_JsPM      
        //https://developer.android.com/training/system-ui/status.html
        activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                //| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

        final CordovaInterface cordova_final = cordova;
        //http://stackoverflow.com/questions/11762306/listen-for-first-touchevent-when-using-system-ui-flag-hide-navigation
        //http://stackoverflow.com/questions/15103339/android-full-screen-modeics-first-touch-shows-the-navigation-bar
        //http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html   
        webView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override/*from   w ww  .j av  a 2 s.c o  m*/
            public void onSystemUiVisibilityChange(int vis) {
                if (vis == 0) {
                    //http://stackoverflow.com/questions/3072173/how-to-call-a-method-after-a-delay-in-android
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Activity activity = cordova_final.getActivity();
                            activity.getWindow().getDecorView()
                                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//
                                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            //| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            //| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
                        }
                    }, 3000);//after ms                
                }
            }
        });
    }
}

From source file:ca.hoogit.garagepi.Main.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == Consts.RESULT_SETTINGS && resultCode == RESULT_OK) {
        User user = UserManager.getInstance().user();
        if (!user.canAuthenticate()) {
            showCredentialsDialog(R.string.dialog_missing_cred, R.string.dialog_missing_cred_content);
        } else if (data.getBooleanExtra(Consts.KEY_THEME_CHANGED, false)) {
            Handler handler = new Handler();
            handler.postDelayed(this::recreate, 0);
        }//from  w  ww  .java 2  s .c o  m
    }
}