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.openlocationcode.android.map.MyMapView.java

@Override
public void moveMapToLocation(final OpenLocationCode code) {
    if (mMap != null) {
        CodeArea area = code.decode();//www  .ja  va  2 s . c  om

        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(area.getCenterLatitude(), area.getCenterLongitude()), INITIAL_MAP_ZOOM));

        drawCodeArea(code);
    } else {
        // In case the map isn't ready yet
        Handler h = new Handler();
        Runnable r = new Runnable() {
            @Override
            public void run() {
                moveMapToLocation(code);
            }
        };
        if (mRetryShowingCurrentLocationOnMap) {
            h.postDelayed(r, 2000);
            mRetryShowingCurrentLocationOnMap = false;
        }
    }
}

From source file:org.cocos2dx.lib.Cocos2dxEditBoxDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    getWindow().setBackgroundDrawable(new ColorDrawable(0x80000000));

    LinearLayout layout = new LinearLayout(mParentActivity);
    layout.setOrientation(LinearLayout.VERTICAL);

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);

    mTextViewTitle = new TextView(mParentActivity);
    LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textviewParams.leftMargin = textviewParams.rightMargin = convertDipsToPixels(10);
    mTextViewTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    layout.addView(mTextViewTitle, textviewParams);

    mInputEditText = new EditText(mParentActivity);
    LinearLayout.LayoutParams editTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    editTextParams.leftMargin = editTextParams.rightMargin = convertDipsToPixels(10);

    layout.addView(mInputEditText, editTextParams);

    setContentView(layout, layoutParams);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    mInputMode = mMsg.inputMode;/*from ww  w.  j ava 2s. com*/
    mInputFlag = mMsg.inputFlag;
    mReturnType = mMsg.returnType;
    mMaxLength = mMsg.maxLength;

    mTextViewTitle.setText(mMsg.title);
    mInputEditText.setText(mMsg.content);

    int oldImeOptions = mInputEditText.getImeOptions();
    mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    oldImeOptions = mInputEditText.getImeOptions();

    switch (mInputMode) {
    case kEditBoxInputModeAny:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
        break;
    case kEditBoxInputModeEmailAddr:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
        break;
    case kEditBoxInputModeNumeric:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
    case kEditBoxInputModePhoneNumber:
        mInputModeContraints = InputType.TYPE_CLASS_PHONE;
        break;
    case kEditBoxInputModeUrl:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI;
        break;
    case kEditBoxInputModeDecimal:
        mInputModeContraints = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
                | InputType.TYPE_NUMBER_FLAG_SIGNED;
        break;
    case kEditBoxInputModeSingleLine:
        mInputModeContraints = InputType.TYPE_CLASS_TEXT;
        break;
    default:

        break;
    }

    if (mIsMultiline) {
        mInputModeContraints |= InputType.TYPE_TEXT_FLAG_MULTI_LINE;
    }

    mInputEditText.setInputType(mInputModeContraints | mInputFlagConstraints);

    switch (mInputFlag) {
    case kEditBoxInputFlagPassword:
        mInputFlagConstraints = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
        break;
    case kEditBoxInputFlagSensitive:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        break;
    case kEditBoxInputFlagInitialCapsWord:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_WORDS;
        break;
    case kEditBoxInputFlagInitialCapsSentence:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
        break;
    case kEditBoxInputFlagInitialCapsAllCharacters:
        mInputFlagConstraints = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
        break;
    default:
        break;
    }
    mInputEditText.setInputType(mInputFlagConstraints | mInputModeContraints);

    switch (mReturnType) {
    case kKeyboardReturnTypeDefault:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    case kKeyboardReturnTypeDone:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_DONE);
        break;
    case kKeyboardReturnTypeSend:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEND);
        break;
    case kKeyboardReturnTypeSearch:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_SEARCH);
        break;
    case kKeyboardReturnTypeGo:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_GO);
        break;
    default:
        mInputEditText.setImeOptions(oldImeOptions | EditorInfo.IME_ACTION_NONE);
        break;
    }

    if (mMaxLength > 0) {
        mInputEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mMaxLength) });
    }

    Handler initHandler = new Handler();
    initHandler.postDelayed(new Runnable() {
        public void run() {
            mInputEditText.requestFocus();
            mInputEditText.setSelection(mInputEditText.length());
            openKeyboard();
        }
    }, 200);

    mInputEditText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // if user didn't set keyboard type,
            // this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'
            if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null
                    && event.getAction() == KeyEvent.ACTION_DOWN)) {
                //Log.d("EditBox", "actionId: "+actionId +",event: "+event);
                mParentActivity.setEditBoxResult(mInputEditText.getText().toString());
                closeKeyboard();
                dismiss();
                return true;
            }
            return false;
        }
    });
}

From source file:org.odk.collect.android.activities.GeoShapeGoogleMapActivity.java

private void zoomtoBounds() {
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            for (Marker marker : markerArray) {
                builder.include(marker.getPosition());
            }// w  w w  .  j  ava  2  s . c  o m
            LatLngBounds bounds = builder.build();
            int padding = 200; // offset from edges of the map in pixels
            CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
            mMap.animateCamera(cu);
        }
    }, 100);

}

From source file:com.perchtech.humraz.blind.libraryact.java

/**
 * Initializes the UI and creates the detector pipeline.
 */// w  w  w  . j av  a  2s.  c om
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    mContext = getApplicationContext();
    setContentView(R.layout.ocr_capture);

    mPreview = (CameraSourcePreview) findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay);

    // Set good defaults for capturing text.
    boolean autoFocus = true;
    boolean useFlash = false;

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(this, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener());

    Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show();

    // Set up the Text To Speech engine.
    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(final int status) {
            if (status == TextToSpeech.SUCCESS) {
                Log.d("OnInitListener", "Text to speech engine started successfully.");
                tts.setLanguage(Locale.US);
            } else {
                Log.d("OnInitListener", "Error starting the text to speech engine.");
            }
        }
    };
    tts = new TextToSpeech(this.getApplicationContext(), listener);
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            speakOut("library mode");
        }
    }, 500);

}

From source file:com.naman14.timber.activities.MainActivity.java

private void updatePosition(final MenuItem menuItem) {
    runnable = null;/*w ww  .  j av  a2  s  . c  o m*/

    switch (menuItem.getItemId()) {
    case R.id.nav_library:
        runnable = navigateLibrary;

        break;
    case R.id.nav_playlists:
        runnable = navigatePlaylist;

        break;
    case R.id.nav_folders:
        runnable = navigateFolder;

        break;
    case R.id.nav_nowplaying:
        NavigationUtils.navigateToNowplaying(MainActivity.this, false);
        break;
    case R.id.nav_queue:
        runnable = navigateQueue;

        break;
    case R.id.nav_settings:
        NavigationUtils.navigateToSettings(MainActivity.this);
        break;
    case R.id.nav_help:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri data = Uri.parse("mailto:namandwivedi14@gmail.com");
        intent.setData(data);
        startActivity(intent);
        break;
    case R.id.nav_about:
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Helpers.showAbout(MainActivity.this);
            }
        }, 350);

        break;
    case R.id.nav_donate:
        startActivity(new Intent(MainActivity.this, DonateActivity.class));
        break;
    }

    if (runnable != null) {
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                runnable.run();
            }
        }, 350);
    }
}

From source file:com.technologx.blaze.player.activities.MainActivity.java

private void updatePosition(final MenuItem menuItem) {
    runnable = null;/*from  w  w  w.  j a v  a2s.  c  o  m*/

    switch (menuItem.getItemId()) {
    case R.id.nav_library:
        runnable = navigateLibrary;

        break;
    case R.id.nav_playlists:
        runnable = navigatePlaylist;

        break;
    case R.id.nav_folders:
        runnable = navigateFolder;

        break;
    case R.id.nav_nowplaying:
        NavigationUtils.navigateToNowplaying(MainActivity.this, false);
        break;
    case R.id.nav_queue:
        runnable = navigateQueue;

        break;
    case R.id.nav_settings:
        NavigationUtils.navigateToSettings(MainActivity.this);
        break;
    case R.id.nav_help:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri data = Uri.parse("mailto:support@technologx.com");
        intent.setData(data);
        startActivity(intent);
        break;
    case R.id.nav_about:
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Helpers.showAbout(MainActivity.this);
            }
        }, 350);

        break;
    case R.id.nav_donate:
        startActivity(new Intent(MainActivity.this, DonateActivity.class));
        break;
    }

    if (runnable != null) {
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                runnable.run();
            }
        }, 350);
    }
}

From source file:com.devalladolid.musictoday.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    sMainActivity = this;
    action = getIntent().getAction();/*from   ww w .  j  a  va2 s  . c  o m*/

    isDarkTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    navigationMap.put(Constants.NAVIGATE_LIBRARY, navigateLibrary);
    navigationMap.put(Constants.NAVIGATE_PLAYLIST, navigatePlaylist);
    navigationMap.put(Constants.NAVIGATE_QUEUE, navigateQueue);
    navigationMap.put(Constants.NAVIGATE_NOWPLAYING, navigateNowplaying);
    navigationMap.put(Constants.NAVIGATE_ALBUM, navigateAlbum);
    navigationMap.put(Constants.NAVIGATE_ARTIST, navigateArtist);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    panelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    View header = navigationView.inflateHeaderView(R.layout.nav_header);

    albumart = (ImageView) header.findViewById(R.id.album_art);
    songtitle = (TextView) header.findViewById(R.id.song_title);
    songartist = (TextView) header.findViewById(R.id.song_artist);

    setPanelSlideListeners(panelLayout);

    navDrawerRunnable.postDelayed(new Runnable() {
        @Override
        public void run() {
            setupDrawerContent(navigationView);
            setupNavigationIcons(navigationView);
        }
    }, 700);

    if (TimberUtils.isMarshmallow()) {
        checkPermissionAndThenLoad();
    } else {
        loadEverything();
    }

    addBackstackListener();

    if (Intent.ACTION_VIEW.equals(action)) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                MusicPlayer.clearQueue();
                MusicPlayer.openFile(getIntent().getData().getPath());
                MusicPlayer.playOrPause();
                navigateNowplaying.run();
            }
        }, 350);
    }

}

From source file:com.devalladolid.musictoday.activities.MainActivity.java

private void updatePosition(final MenuItem menuItem) {
    runnable = null;//from  www.  j  a  va  2s  .c  o  m

    switch (menuItem.getItemId()) {
    case R.id.nav_library:
        runnable = navigateLibrary;

        break;
    case R.id.nav_playlists:
        runnable = navigatePlaylist;

        break;
    case R.id.nav_folders:
        runnable = navigateFolder;

        break;
    case R.id.nav_nowplaying:
        NavigationUtils.navigateToNowplaying(MainActivity.this, false);
        break;
    case R.id.nav_queue:
        runnable = navigateQueue;

        break;
    case R.id.nav_settings:
        NavigationUtils.navigateToSettings(MainActivity.this);
        break;
    case R.id.nav_help:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri data = Uri.parse("mailto:devalladolidoficial@gmail.com");
        intent.setData(data);
        startActivity(intent);
        break;
    case R.id.nav_about:
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Helpers.showAbout(MainActivity.this);
            }
        }, 350);

        break;
    case R.id.nav_donate:
        startActivity(new Intent(MainActivity.this, DonateActivity.class));
        break;
    }

    if (runnable != null) {
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                runnable.run();
            }
        }, 350);
    }
}

From source file:gl.iglou.scenegraph.MatModeInterface.java

public void ScreenShot(View v) {
    Log.v(TAG, "Souriez!!!");
    //mView.Shoot();
    //GL2JNILib.TakeSnapshot();
    //while(!GL2JNILib.IsSnapshotReady()) { Log.v(TAG,"Waiting for snapshot!!"); }

    GLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    GL2JNILib.SnapshotMode(true);/*w  w w.j a v  a  2s.  c  o  m*/
    GL2JNILib.TakeSnapshot();
    GLView.requestRender();

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            GLView.getBitmapJNI();
            photo.setImageBitmap(GLView.mBitmap);
            snapshotContainer.setVisibility(View.VISIBLE);

        }
    }, 100);
}

From source file:com.techmighty.baseplayer.activities.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    sMainActivity = this;
    action = getIntent().getAction();// w w w.  ja  v  a  2  s .  c  om

    isDarkTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen_1));

    AdRequest adRequest = new AdRequest.Builder().build();

    // Load ads into Interstitial Ads
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }
    });

    navigationMap.put(Constants.NAVIGATE_LIBRARY, navigateLibrary);
    navigationMap.put(Constants.NAVIGATE_PLAYLIST, navigatePlaylist);
    navigationMap.put(Constants.NAVIGATE_QUEUE, navigateQueue);
    navigationMap.put(Constants.NAVIGATE_NOWPLAYING, navigateNowplaying);
    navigationMap.put(Constants.NAVIGATE_ALBUM, navigateAlbum);
    navigationMap.put(Constants.NAVIGATE_ARTIST, navigateArtist);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    panelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    View header = navigationView.inflateHeaderView(R.layout.nav_header);

    albumart = (ImageView) header.findViewById(R.id.album_art);
    songtitle = (TextView) header.findViewById(R.id.song_title);
    songartist = (TextView) header.findViewById(R.id.song_artist);

    setPanelSlideListeners(panelLayout);

    navDrawerRunnable.postDelayed(new Runnable() {
        @Override
        public void run() {
            setupDrawerContent(navigationView);
            setupNavigationIcons(navigationView);
        }
    }, 700);

    if (BasePlayerUtils.isMarshmallow()) {
        checkPermissionAndThenLoad();
    } else {
        loadEverything();
    }

    addBackstackListener();

    if (Intent.ACTION_VIEW.equals(action)) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                MusicPlayer.clearQueue();
                MusicPlayer.openFile(getIntent().getData().getPath());
                MusicPlayer.playOrPause();
                navigateNowplaying.run();
            }
        }, 350);
    }
}