List of usage examples for android.os Handler postDelayed
public final boolean postDelayed(Runnable r, long delayMillis)
From source file:com.bluros.music.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;/*from ww w .j av a 2 s . co m*/ switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; 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; } 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.zzisoo.toylibrary.fragment.ToyListViewFragment.java
@Override public void onResume() { super.onResume(); mToyListView.setAdapter(mAdapter);//from w w w .j a va 2 s . c o m if (mAdapter != null) { final int lastClickedPostion = mAdapter.getClickedPostion(); final int lastClickedPrePostion = lastClickedPostion - 1 < 0 ? 0 : lastClickedPostion - 1; Log.e(TAG, "mClickedPostion:" + lastClickedPostion); mToyListView.scrollToPosition(lastClickedPrePostion); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { mToyListView.smoothScrollToPosition(lastClickedPostion); } }, 100); } }
From source file:com.github.pedrovgs.sample.activity.PlacesSampleActivity.java
/** * Return the view to the DraggablePanelState: minimized, maximized, closed to the right or * closed/*from w w w. j av a2s .c om*/ * to the left. * * @param draggableState to apply. */ private void updateDraggablePanelStateDelayed(DraggableState draggableState) { Handler handler = new Handler(); switch (draggableState) { case MAXIMIZED: handler.postDelayed(new Runnable() { @Override public void run() { draggablePanel.maximize(); } }, DELAY_MILLIS); break; case MINIMIZED: handler.postDelayed(new Runnable() { @Override public void run() { draggablePanel.minimize(); } }, DELAY_MILLIS); break; case CLOSED_AT_LEFT: handler.postDelayed(new Runnable() { @Override public void run() { draggablePanel.setVisibility(View.GONE); draggablePanel.closeToLeft(); } }, DELAY_MILLIS); break; case CLOSED_AT_RIGHT: handler.postDelayed(new Runnable() { @Override public void run() { draggablePanel.setVisibility(View.GONE); draggablePanel.closeToRight(); } }, DELAY_MILLIS); break; default: draggablePanel.setVisibility(View.GONE); break; } }
From source file:uk.ac.horizon.artcodes.camera.CameraView.java
@Override public void focus(final Runnable callback) { synchronized (cameraFocusLock) { Log.i("FOCUS", "cameraIsFocused = false;"); cameraIsFocused = false;/*w w w .ja v a 2 s .c om*/ } if (camera != null) { Log.i("FOCUS", "Attempting to focus camera."); camera.autoFocus(null); } // set a timeout rather than use the auto focus callback // (because the auto focus callback never gets called on some devices) Handler h = new Handler(Looper.getMainLooper()); h.postDelayed(new Runnable() { @Override public void run() { Log.i("FOCUS", "Firing auto focus timeout."); synchronized (cameraFocusLock) { Log.i("FOCUS", "cameraIsFocused = true;"); cameraIsFocused = true; Log.i("FOCUS", "notifyAll()"); cameraFocusLock.notifyAll(); } callback.run(); } }, 1000); }
From source file:com.dwdesign.tweetings.fragment.MentionsFragment.java
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { isReadTrackingSuspended = true;/* w w w .j a va2 s. c om*/ final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { isReadTrackingSuspended = false; } }, 500); long last_viewed_id = -1; { final int position = mListView.getFirstVisiblePosition(); if (position > 0) { last_viewed_id = mAdapter.findItemIdByPosition(position); } } super.onLoadFinished(loader, data); final boolean remember_position = mPreferences.getBoolean(PREFERENCE_KEY_REMEMBER_POSITION, true); if (gapStatusId > 0) { if (mPreferences.getBoolean(PREFERENCE_KEY_GAP_POSITION, true)) { scrollToStatusId(gapStatusId); } gapStatusId = -1; return; } if (mShouldRestorePosition && remember_position) { final long status_id = mPreferences.getLong(PREFERENCE_KEY_SAVED_MENTIONS_LIST_ID, -1); final int position = mAdapter.findItemPositionByStatusId(status_id); if (position > -1 && position < mListView.getCount()) { mListView.setSelection(position); } mShouldRestorePosition = false; return; } if (mMinIdToRefresh > 0 && remember_position) { final int position = mAdapter .findItemPositionByStatusId(last_viewed_id > 0 ? last_viewed_id : mMinIdToRefresh); if (position >= 0 && position < mListView.getCount()) { mListView.setSelection(position); } mMinIdToRefresh = -1; return; } final int position = mAdapter .findItemPositionByStatusId(last_viewed_id > 0 ? last_viewed_id : mMinIdToRefresh); if (position > 0) { mListView.setSelection(position); } }
From source file:com.megster.cordova.ble.central.BLECentralPlugin.java
private void findLowEnergyDevices(CallbackContext callbackContext, UUID[] serviceUUIDs, int scanSeconds) { // TODO skip if currently scanning // clear non-connected cached peripherals for (Iterator<Map.Entry<String, Peripheral>> iterator = peripherals.entrySet().iterator(); iterator .hasNext();) {/*from ww w .j a v a 2 s . c o m*/ Map.Entry<String, Peripheral> entry = iterator.next(); if (!entry.getValue().isConnected()) { iterator.remove(); } } discoverCallback = callbackContext; if (serviceUUIDs.length > 0) { bluetoothAdapter.startLeScan(serviceUUIDs, this); } else { bluetoothAdapter.startLeScan(this); } if (scanSeconds > 0) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { LOG.d(TAG, "Stopping Scan"); BLECentralPlugin.this.bluetoothAdapter.stopLeScan(BLECentralPlugin.this); } }, scanSeconds * 1000); } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); }
From source file:com.devalladolid.musictoday.subfragments.QuickControlsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false); this.rootView = rootView; mPlayPause = (PlayPauseButton) rootView.findViewById(R.id.play_pause); mPlayPauseExpanded = (PlayPauseButton) rootView.findViewById(R.id.playpause); playPauseWrapper = rootView.findViewById(R.id.play_pause_wrapper); playPauseWrapperExpanded = rootView.findViewById(R.id.playpausewrapper); playPauseWrapper.setOnClickListener(mPlayPauseListener); playPauseWrapperExpanded.setOnClickListener(mPlayPauseExpandedListener); mProgress = (ProgressBar) rootView.findViewById(R.id.song_progress_normal); mSeekBar = (SeekBar) rootView.findViewById(R.id.song_progress); mTitle = (TextView) rootView.findViewById(R.id.title); mArtist = (TextView) rootView.findViewById(R.id.artist); mTitleExpanded = (TextView) rootView.findViewById(R.id.song_title); mArtistExpanded = (TextView) rootView.findViewById(R.id.song_artist); mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art_nowplayingcard); mBlurredArt = (ImageView) rootView.findViewById(R.id.blurredAlbumart); next = (MaterialIconView) rootView.findViewById(R.id.next); previous = (MaterialIconView) rootView.findViewById(R.id.previous); topContainer = rootView.findViewById(R.id.topContainer); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mProgress.getLayoutParams(); mProgress.measure(0, 0);//w w w . ja v a 2 s. c om layoutParams.setMargins(0, -(mProgress.getMeasuredHeight() / 2), 0, 0); mProgress.setLayoutParams(layoutParams); mPlayPause.setColor(Config.accentColor(getActivity(), Helpers.getATEKey(getActivity()))); mPlayPauseExpanded.setColor(Color.WHITE); mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (b) { MusicPlayer.seek((long) i); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { MusicPlayer.next(); } }, 200); } }); previous.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { MusicPlayer.previous(getActivity(), false); } }, 200); } }); ((BaseActivity) getActivity()).setMusicStateListenerListener(this); if (PreferencesUtility.getInstance(getActivity()).isGesturesEnabled()) { new SlideTrackSwitcher() { @Override public void onClick() { NavigationUtils.navigateToNowplaying(getActivity(), false); } }.attach(rootView.findViewById(R.id.root_view)); } return rootView; }
From source file:com.dwdesign.tweetings.fragment.HomeTimelineFragment.java
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { isReadTrackingSuspended = true;//from w ww . ja v a2 s. co m final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { isReadTrackingSuspended = false; } }, 500); final CursorStatusesAdapter adapter = getListAdapter(); long last_viewed_id = -1; { final int position = mListView.getFirstVisiblePosition(); if (position > 0) { last_viewed_id = adapter.findItemIdByPosition(position); } } super.onLoadFinished(loader, data); final boolean remember_position = mPreferences.getBoolean(PREFERENCE_KEY_REMEMBER_POSITION, true); if (gapStatusId > 0) { if (mPreferences.getBoolean(PREFERENCE_KEY_GAP_POSITION, true)) { scrollToStatusId(gapStatusId); } gapStatusId = -1; return; } if (mShouldRestorePosition && remember_position) { final long status_id = mPreferences.getLong(PREFERENCE_KEY_SAVED_HOME_TIMELINE_ID, -1); final int position = adapter.findItemPositionByStatusId(status_id); if (position > -1 && position < mListView.getCount()) { mListView.setSelection(position); } mShouldRestorePosition = false; return; } if (mMinIdToRefresh > 0 && remember_position) { final int position = adapter .findItemPositionByStatusId(last_viewed_id > 0 ? last_viewed_id : mMinIdToRefresh); if (position >= 0 && position < mListView.getCount()) { mListView.setSelection(position); } mMinIdToRefresh = -1; return; } final int position = adapter .findItemPositionByStatusId(last_viewed_id > 0 ? last_viewed_id : mMinIdToRefresh); if (position > 0) { mListView.setSelection(position); } }
From source file:com.money.manager.ex.reports.CategoriesReportFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { super.onLoadFinished(loader, data); switch (loader.getId()) { case ID_LOADER: //parse cursor for calculate total if (data == null) return; CurrencyService currencyService = new CurrencyService(getActivity().getApplicationContext()); Money totalAmount = MoneyFactory.fromString("0"); while (data.moveToNext()) { String totalRow = data.getString(data.getColumnIndex("TOTAL")); if (!TextUtils.isEmpty(totalRow)) { totalAmount = totalAmount.add(MoneyFactory.fromString(totalRow)); } else { new UIHelper(getActivity()).showToast("reading total"); }//from w w w.j av a 2s . com } TextView txtColumn2 = (TextView) mListViewFooter.findViewById(R.id.textViewColumn2); txtColumn2.setText(currencyService.getBaseCurrencyFormatted(totalAmount)); // solved bug chart if (data.getCount() > 0) { getListView().removeFooterView(mListViewFooter); getListView().addFooterView(mListViewFooter); } if (((CategoriesReportActivity) getActivity()).mIsDualPanel) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { showChart(); } }, 1000); } } }
From source file:com.ota.updates.receivers.AppReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Bundle extras = intent.getExtras();//ww w .jav a 2 s. co m long mRomDownloadID = Preferences.getDownloadID(context); if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { long id = extras.getLong(DownloadManager.EXTRA_DOWNLOAD_ID); boolean isAddonDownload = false; int keyForAddonDownload = 0; Set<Integer> set = OtaUpdates.getAddonDownloadKeySet(); Iterator<Integer> iterator = set.iterator(); while (iterator.hasNext() && isAddonDownload != true) { int nextValue = iterator.next(); if (id == OtaUpdates.getAddonDownload(nextValue)) { isAddonDownload = true; keyForAddonDownload = nextValue; if (DEBUGGING) { Log.d(TAG, "Checking ID " + nextValue); } } } if (isAddonDownload) { DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = downloadManager.query(query); // it shouldn't be empty, but just in case if (!cursor.moveToFirst()) { if (DEBUGGING) Log.e(TAG, "Addon Download Empty row"); return; } int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) { if (DEBUGGING) Log.w(TAG, "Download Failed"); Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload); OtaUpdates.removeAddonDownload(keyForAddonDownload); AddonActivity.AddonsArrayAdapter.updateProgress(keyForAddonDownload, 0, true); AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, false); return; } else { if (DEBUGGING) Log.v(TAG, "Download Succeeded"); Log.d(TAG, "Removing Addon download with id " + keyForAddonDownload); OtaUpdates.removeAddonDownload(keyForAddonDownload); AddonActivity.AddonsArrayAdapter.updateButtons(keyForAddonDownload, true); return; } } else { if (DEBUGGING) Log.v(TAG, "Receiving " + mRomDownloadID); if (id != mRomDownloadID) { if (DEBUGGING) Log.v(TAG, "Ignoring unrelated non-ROM download " + id); return; } DownloadManager downloadManager = (DownloadManager) context .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Query query = new DownloadManager.Query(); query.setFilterById(id); Cursor cursor = downloadManager.query(query); // it shouldn't be empty, but just in case if (!cursor.moveToFirst()) { if (DEBUGGING) Log.e(TAG, "Rom download Empty row"); return; } int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL != cursor.getInt(statusIndex)) { if (DEBUGGING) Log.w(TAG, "Download Failed"); Preferences.setDownloadFinished(context, false); if (Utils.isLollipop()) { AvailableActivity.setupMenuToolbar(context); // Reset options menu } else { AvailableActivity.invalidateMenu(); } return; } else { if (DEBUGGING) Log.v(TAG, "Download Succeeded"); Preferences.setDownloadFinished(context, true); AvailableActivity.setupProgress(context); if (Utils.isLollipop()) { AvailableActivity.setupMenuToolbar(context); // Reset options menu } else { AvailableActivity.invalidateMenu(); } return; } } } if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = extras.getLongArray(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); for (long id : ids) { if (id != mRomDownloadID) { if (DEBUGGING) Log.v(TAG, "mDownloadID is " + mRomDownloadID + " and ID is " + id); return; } else { Intent i = new Intent(context, AvailableActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } } if (action.equals(MANIFEST_CHECK_BACKGROUND)) { if (DEBUGGING) Log.d(TAG, "Receiving background check confirmation"); boolean updateAvailable = RomUpdate.getUpdateAvailability(context); String filename = RomUpdate.getFilename(context); if (updateAvailable) { Utils.setupNotification(context, filename); Utils.scheduleNotification(context, !Preferences.getBackgroundService(context)); } } if (action.equals(START_UPDATE_CHECK)) { if (DEBUGGING) Log.d(TAG, "Update check started"); new LoadUpdateManifest(context, false).execute(); } if (action.equals(Intent.ACTION_BOOT_COMPLETED)) { if (DEBUGGING) { Log.d(TAG, "Boot received"); } boolean backgroundCheck = Preferences.getBackgroundService(context); if (backgroundCheck) { if (DEBUGGING) Log.d(TAG, "Starting background check alarm"); Utils.scheduleNotification(context, !Preferences.getBackgroundService(context)); } } if (action.equals(IGNORE_RELEASE)) { if (DEBUGGING) { Log.d(TAG, "Ignore release"); } Preferences.setIgnoredRelease(context, Integer.toString(RomUpdate.getVersionNumber(context))); final NotificationManager mNotifyManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle(context.getString(R.string.main_release_ignored)) .setSmallIcon(R.drawable.ic_notif) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build()); Handler h = new Handler(); long delayInMilliseconds = 1500; h.postDelayed(new Runnable() { public void run() { mNotifyManager.cancel(NOTIFICATION_ID); } }, delayInMilliseconds); } }