List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:pt.bappy.domsebastiao.activities.MapSearchActivity.java
@Override public boolean onMarkerClick(final Marker marker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); final long duration = 1500; final Interpolator interpolator = new BounceInterpolator(); handler.post(new Runnable() { @Override//w ww . j av a 2s.co m public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0); marker.setAnchor(0.5f, 1.0f + 2 * t); if (t > 0.0) { // Post again 16ms later. handler.postDelayed(this, 16); } } }); return false; }
From source file:com.hangulo.powercontact.MapViewFragment.java
public void makeClusterItemClickFromOthers(final PowerContactAddress item, float zoomLevel) { if (zoomLevel == -1) { cameraZoomLevel = mMap.getCameraPosition().zoom; // get current zoom level } else//from ww w . j ava 2 s .c om cameraZoomLevel = zoomLevel; mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(item.getPosition(), cameraZoomLevel), 100, new GoogleMap.CancelableCallback() { @Override public void onFinish() { Log.v(LOG_TAG, "onClusterItemClickFromListView():: onFinish"); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // ? . Log.v(LOG_TAG, "start"); Marker myMarker = searchMarkersFromArrayList(item); if (myMarker != null) { // ? ui thread. myMarker.showInfoWindow(); // ? . Log.v(LOG_TAG, "onClusterItemClickFromListView():: ok. showinfowindow()" + cameraZoomLevel); } else { // ... if (cameraZoomLevel < mMap.getMaxZoomLevel()) { makeClusterItemClickFromOthers(item, mMap.getMaxZoomLevel()); // recursive } } Log.v(LOG_TAG, "onClusterItemClickFromListView():: end " + cameraZoomLevel + "/"); } }, 500); } @Override public void onCancel() { } }); }
From source file:com.sentaroh.android.Utilities.LogUtil.CommonLogFileListDialogFragment.java
final private void confirmSettingsLogOption(final boolean enabled) { final Button btn_save = (Button) mDialog.findViewById(R.id.log_file_list_dlg_log_save); final Button btn_send_dev = (Button) mDialog.findViewById(R.id.log_file_list_dlg_log_send); final CheckBox cb_log_enabled = (CheckBox) mDialog.findViewById(R.id.log_file_list_dlg_log_enabled); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override/*from w w w . j av a2 s . c o m*/ public void positiveResponse(Context c, Object[] o) { if (mNotifyUpdateLogOption != null) mNotifyUpdateLogOption.notifyToListener(true, new Object[] { enabled }); btn_save.setEnabled(enabled); btn_send_dev.setEnabled(enabled); Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override public void run() { mLogFileList = CommonLogUtil.createLogFileList(mGp); mLogFileManagementAdapter.replaceDataList(mLogFileList); mLogFileManagementAdapter.notifyDataSetChanged(); } }, 200); } @Override public void negativeResponse(Context c, Object[] o) { mDisableChangeLogEnabled = true; cb_log_enabled.setChecked(!cb_log_enabled.isChecked()); } }); String msg = ""; if (enabled) msg = getString(R.string.msgs_log_file_list_confirm_log_enable); else msg = getString(R.string.msgs_log_file_list_confirm_log_disable); MessageDialogFragment cdf = MessageDialogFragment.newInstance(true, "W", msg, ""); cdf.showDialog(getFragmentManager(), cdf, ntfy); }
From source file:com.filterdevice.ProfileScanningFragment.java
/** * Method to connect to the device selected. The time allotted for having a * connection is 8 seconds. After 8 seconds it will disconnect if not * connected and initiate scan once more * * @param device//from w ww . j a v a2 s . c om */ private void connectDevice(BluetoothDevice device, boolean isFirstConnect) { mDeviceAddress = device.getAddress(); mDeviceName = device.getName(); // Get the connection status of the device if (bluetoothLeService.getConnectionState() == bluetoothLeService.STATE_DISCONNECTED) { Logger.v("BLE DISCONNECTED STATE"); // Disconnected,so connect bluetoothLeService.connect(mDeviceAddress); showConnectAlertMessage(mDeviceName, mDeviceAddress); } else { Logger.v("BLE OTHER STATE-->" + bluetoothLeService.getConnectionState()); // Connecting to some devices,so disconnect and then connect bluetoothLeService.disconnect(); Handler delayHandler = new Handler(); delayHandler.postDelayed(new Runnable() { @Override public void run() { bluetoothLeService.connect(mDeviceAddress); showConnectAlertMessage(mDeviceName, mDeviceAddress); } }, DELAY_PERIOD); } if (isFirstConnect) { startConnectTimer(); mConnectTimerON = true; } }
From source file:com.sentaroh.android.TextFileBrowser.MainActivity.java
@Override public void onDestroy() { super.onDestroy(); if (mGlblParms.debugEnabled) Log.v(APPLICATION_TAG, "onDestroy entered"); // Application process is follow if (mTerminateApplication) { NotificationUtil.clearNotification(mContext, mGlblParms.commonNotification); // deleteTaskData(); if (mGlblParms.settingExitCleanly) { Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override//from ww w . j a va 2s .c om public void run() { android.os.Process.killProcess(android.os.Process.myPid()); } }, 200); } else { mGlblParms.viewedFileList = null; mGlblParms.commonNotification = null; mGlblParms = null; System.gc(); } } else { } }
From source file:com.esri.arcgisruntime.sample.readsymbolsmobilestylefile.MainActivity.java
/** * Animates {@link RecyclerView}s to inform user that there are more options available *///from w w w. ja va 2 s . c o m private void animateRecyclerViews() { Handler handler = new Handler(); final Runnable resetScrollRunnable = () -> { mHatRecyclerView.smoothScrollBy(-100, 0); mEyesRecyclerView.smoothScrollBy(-100, 0); mMouthRecyclerView.smoothScrollBy(-100, 0); }; Runnable startScrollRunnable = () -> { mHatRecyclerView.smoothScrollBy(100, 0); mEyesRecyclerView.smoothScrollBy(100, 0); mMouthRecyclerView.smoothScrollBy(100, 0); handler.postDelayed(resetScrollRunnable, 1000); }; runOnUiThread(() -> handler.postDelayed(startScrollRunnable, 2000)); }
From source file:com.github.irshulx.Components.InputExtensions.java
public TextView insertEditText(int position, String hint, CharSequence text) { String nextHint = isLastText(position) ? null : editorCore.getPlaceHolder(); if (editorCore.getRenderType() == RenderType.Editor) { /**// w w w . ja v a2 s .co m * when user press enter from first line without keyin anything, need to remove the placeholder from that line 0... */ if (position == 1) { View view = editorCore.getParentView().getChildAt(0); EditorType type = editorCore.getControlType(view); if (type == EditorType.INPUT) { TextView textView = (TextView) view; if (TextUtils.isEmpty(textView.getText())) { textView.setHint(null); } } } final CustomEditText view = getNewEditTextInst(nextHint, text); editorCore.getParentView().addView(view, position); editorCore.setActiveView(view); final android.os.Handler handler = new android.os.Handler(); handler.postDelayed(new Runnable() { @Override public void run() { setFocus(view); } }, 0); editorCore.setActiveView(view); return view; } else { final TextView view = getNewTextView(text); view.setTag(editorCore.createTag(EditorType.INPUT)); editorCore.getParentView().addView(view); return view; } }
From source file:com.google.android.apps.santatracker.doodles.tilt.SwimmingFragment.java
@Override public void onEventReceived(int type, final Object data) { if (isDestroyed) { return;/* w ww . j a v a 2 s . co m*/ } switch (type) { case EventBus.SCORE_CHANGED: int distance = integerValue(data); boolean shouldAddStar = false; if (model.currentScoreThreshold < SwimmingModel.SCORE_THRESHOLDS.length && distance >= SwimmingModel.SCORE_THRESHOLDS[model.currentScoreThreshold]) { // Pop in star. shouldAddStar = true; model.currentScoreThreshold++; } updateScoreUi(distance, shouldAddStar); break; case EventBus.SWIMMING_DIVE: getActivity().runOnUiThread(new Runnable() { @Override public void run() { diveView.startCooldown(); } }); break; case EventBus.GAME_STATE_CHANGED: SwimmingState state = (SwimmingState) data; mIsGameOver = false; if (state == SwimmingState.FINISHED) { mIsGameOver = true; calculateBestDistance(); calculateStars(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { pauseView.hidePauseButton(); } }); final Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { @Override public void run() { if (model == null) { return; } int bestDistance = historyManager.getBestDistance(GameType.SWIMMING).intValue(); String collidedObjectType = model.swimmer.getCollidedObjectType(); scoreView.updateBestScore(AndroidUtils.getText(context.getResources(), R.string.swimming_score, bestDistance)); scoreView.setShareDrawable(getShareImageDrawable(collidedObjectType)); diveView.hide(); scoreView.animateToEndState(); } }, END_VIEW_ON_DEATH_DELAY_MS); } // [ANALYTICS] FirebaseAnalytics analytics = FirebaseAnalytics.getInstance(getActivity()); MeasurementManager.recordSwimmingEnd(analytics, model.getStarCount(), model.distanceMeters, model.swimmer.getCollidedObjectType()); break; case EventBus.PLAY_SOUND: int resId = (int) data; if (soundManager != null) { soundManager.play(resId); } break; case EventBus.MUTE_SOUNDS: boolean shouldMute = (boolean) data; if (soundManager != null) { if (shouldMute) { soundManager.mute(); } else { soundManager.unmute(); } } break; case EventBus.GAME_LOADED: long loadTimeMs = (long) data; titleDurationMs = Math.max(0, titleDurationMs - loadTimeMs); Log.d(TAG, "Waiting " + titleDurationMs + "ms and then hiding title."); break; } }
From source file:com.sentaroh.android.TextFileBrowser.MainActivity.java
@Override public void onResume() { super.onResume(); if (mGlblParms.debugEnabled) Log.v(APPLICATION_TAG, "onResume entered, restartStatus=" + mRestartStatus); String fp = ""; if (mRestartStatus == 0) { Intent in = getIntent();/*ww w . j a v a 2 s . c om*/ String cd = getCacheDir() + "/attached/"; if (in.getData() != null) fp = ContentProviderUtil.getFilePath(mContext, cd, in.getData()); if (fp == null || fp.equals("")) { NotificationUtil.initNotification(mContext, mGlblParms.commonNotification); showFileSelectDialog(); // if (getViewedFileListCount()==0) mTerminateApplication=true; // finish(); } else { NotificationUtil.initNotification(mContext, mGlblParms.commonNotification); NotificationUtil.clearNotification(mContext, mGlblParms.commonNotification); if (!isFileAlreadyViewed(fp)) { addFileToViewedFileList(true, fp); showFileByViewedFileList(fp); } else { showFileByViewedFileList(fp); } NotificationUtil.showOngoingNotificationMsg(mContext, mGlblParms.commonNotification, fp); } } else if (mRestartStatus == 1) { } else if (mRestartStatus == 2) { NotificationUtil.initNotification(mContext, mGlblParms.commonNotification); for (int i = 0; i < mGlblParms.viewedFileList.size(); i++) { ViewedFileListItem vfli = mGlblParms.viewedFileList.get(i); vfli.viewerParmsInitRequired = false; vfli.viewerParmsRestoreRequired = true; vfli.encodeName = ""; vfli.file_view_fragment = FileViewerFragment.newInstance(vfli.file_path); vfli.tc_view = new ThreadCtrl(); vfli.ix_reader_view = new IndexedFileReader(mGlblParms.debugEnabled, mGlblParms.settingAlwayDeterminCharCode, this, mCommonDlg, vfli.tc_view, mGlblParms.settingEncodeName, mGlblParms.settingIndexCache, mGlblParms.settingBufferCharIndexSize, mGlblParms.settingBufferHexIndexSize, mGlblParms.settingBufferPoolSize, this); // mViewedFileListAdapter.notifyDataSetChanged(); if (i == mSavedViewedFileListSpinnerPosition) mGlblParms.currentViewedFile = vfli.file_path; } initFileSelectionSpinner(); mCommonDlg.showCommonDialog(false, "W", getString(R.string.msgs_tb_application_restarted), "", null); showFileByViewedFileList(mGlblParms.currentViewedFile); NotificationUtil.showOngoingNotificationMsg(mContext, mGlblParms.commonNotification, mGlblParms.currentViewedFile); mViewedFileListSpinner.setSelection(mSavedViewedFileListSpinnerPosition); } mRestartStatus = 1; setViewedFilleSelectorListener(); Handler hndl = new Handler(); hndl.postDelayed(new Runnable() { @Override public void run() { mEnableFileSelection = true; } }, 500); }
From source file:com.example.hellogooglemaps.MarkerDemoActivity.java
@Override public boolean onMarkerClick(final Marker marker) { if (marker.equals(mPerth)) { // This causes the marker at Perth to bounce into position when it is clicked. final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); final long duration = 1500; final Interpolator interpolator = new BounceInterpolator(); handler.post(new Runnable() { @Override//from ww w .ja v a2 s. c o m public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0); marker.setAnchor(0.5f, 1.0f + 2 * t); if (t > 0.0) { // Post again 16ms later. handler.postDelayed(this, 16); } } }); } else if (marker.equals(mAdelaide)) { // This causes the marker at Adelaide to change color. marker.setIcon(BitmapDescriptorFactory.defaultMarker(new Random().nextFloat() * 360)); } // We return false to indicate that we have not consumed the event and that we wish // for the default behavior to occur (which is for the camera to move such that the // marker is centered and for the marker's info window to open, if it has one). return false; }