List of usage examples for android.os Handler post
public final boolean post(Runnable r)
From source file:im.neon.contacts.ContactsManager.java
/** * Retrieve the contacts PIDs/*www. j a v a 2 s . c o m*/ */ public void retrievePids() { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { if (mIsRetrievingPids) { Log.d(LOG_TAG, "## retrievePids() : already in progress"); } else if (mArePidsRetrieved) { Log.d(LOG_TAG, "## retrievePids() : already done"); } else { Log.d(LOG_TAG, "## retrievePids() : Start search"); mIsRetrievingPids = true; PIDsRetriever.getInstance().retrieveMatrixIds(VectorApp.getInstance(), mContactsList, false); } } }); }
From source file:com.dmsl.anyplace.tasks.FetchFloorPlanTask.java
private void runPreExecuteOnUI() { // Get a handler that can be used to post to the main thread Handler mainHandler = new Handler(ctx.getMainLooper()); Runnable myRunnable = new Runnable() { @Override/*ww w.j av a2s . c o m*/ public void run() { try { mListener.onPrepareLongExecute(); } finally { synchronized (syncListener) { run = true; syncListener.notifyAll(); } } } }; mainHandler.post(myRunnable); }
From source file:com.norman0406.slimgress.FragmentInventory.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_inventory, container, false); final ExpandableListView list = (ExpandableListView) rootView.findViewById(R.id.listView); final ProgressBar progress = (ProgressBar) rootView.findViewById(R.id.progressBar1); list.setVisibility(View.INVISIBLE); progress.setVisibility(View.VISIBLE); // create group names mGroupNames = new ArrayList<String>(); mGroups = new ArrayList<Object>(); mGroupMedia = new ArrayList<String>(); mGroupMods = new ArrayList<String>(); mGroupPortalKeys = new ArrayList<String>(); mGroupPowerCubes = new ArrayList<String>(); mGroupResonators = new ArrayList<String>(); mGroupWeapons = new ArrayList<String>(); final FragmentInventory thisObject = this; final Handler handler = new Handler(); mGame.intGetInventory(new Handler(new Handler.Callback() { @Override//from w ww . j a v a 2 s.c o m public boolean handleMessage(Message msg) { fillInventory(new Runnable() { @Override public void run() { handler.post(new Runnable() { @Override public void run() { InventoryList inventoryList = new InventoryList(mGroupNames, mGroups); inventoryList.setInflater(inflater, thisObject.getActivity()); list.setAdapter(inventoryList); list.setOnChildClickListener(thisObject); list.setVisibility(View.VISIBLE); progress.setVisibility(View.INVISIBLE); } }); } }); return true; } })); return rootView; }
From source file:org.dharmaseed.android.PlayTalkActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play_talk); // Turn on action bar up/home button ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); }/*from w ww. j a v a 2s. co m*/ // Get the ID of the talk to display Intent i = getIntent(); talkID = (int) i.getLongExtra(NavigationActivity.TALK_DETAIL_EXTRA, 0); dbManager = DBManager.getInstance(this); // only hit the DB again if we know the talk is different than the one // we have saved. // for example, if the user selects a talk, exits, and re-opens it, no need // to hit the DB again, since we already have that talk saved if (talk == null || talk.getId() != talkID) { Cursor cursor = getCursor(); if (cursor.moveToFirst()) { // convert DB result to an object talk = new Talk(cursor); talk.setId(talkID); } else { Log.e(LOG_TAG, "Could not look up talk, id=" + talkID); cursor.close(); return; } cursor.close(); } // else we already have the talk, just re-draw the page // Set the talk title TextView titleView = (TextView) findViewById(R.id.play_talk_talk_title); titleView.setText(talk.getTitle()); // Set the teacher name TextView teacherView = (TextView) findViewById(R.id.play_talk_teacher); teacherView.setText(talk.getTeacherName()); // Set the center name TextView centerView = (TextView) findViewById(R.id.play_talk_center); centerView.setText(talk.getCenterName()); // Set the talk description TextView descriptionView = (TextView) findViewById(R.id.play_talk_talk_description); descriptionView.setText(talk.getDescription()); // Set teacher photo String photoFilename = talk.getPhotoFileName(); ImageView photoView = (ImageView) findViewById(R.id.play_talk_teacher_photo); Log.i(LOG_TAG, "photoFilename: " + photoFilename); try { FileInputStream photo = openFileInput(photoFilename); photoView.setImageBitmap(BitmapFactory.decodeStream(photo)); } catch (FileNotFoundException e) { Drawable icon = ContextCompat.getDrawable(this, R.drawable.dharmaseed_icon); photoView.setImageDrawable(icon); } // set the image of the download button based on whether the talk is // downloaded or not toggleDownloadImage(); // Set date TextView dateView = (TextView) findViewById(R.id.play_talk_date); String recDate = talk.getDate(); SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { dateView.setText(DateFormat.getDateInstance().format(parser.parse(recDate))); } catch (ParseException e) { dateView.setText(""); Log.w(LOG_TAG, "Could not parse talk date for talk ID " + talkID); } // Get/create a persistent fragment to manage the MediaPlayer instance FragmentManager fm = getSupportFragmentManager(); talkPlayerFragment = (TalkPlayerFragment) fm.findFragmentByTag("talkPlayerFragment"); if (talkPlayerFragment == null) { // add the fragment talkPlayerFragment = new TalkPlayerFragment(); fm.beginTransaction().add(talkPlayerFragment, "talkPlayerFragment").commit(); } else if (talkPlayerFragment.getMediaPlayer().isPlaying()) { setPPButton("ic_media_pause"); } // Set the talk duration final TextView durationView = (TextView) findViewById(R.id.play_talk_talk_duration); double duration = talk.getDurationInMinutes(); String durationStr = DateUtils.formatElapsedTime((long) (duration * 60)); durationView.setText(durationStr); // Start a handler to periodically update the seek bar and talk time final SeekBar seekBar = (SeekBar) findViewById(R.id.play_talk_seek_bar); seekBar.setMax((int) (duration * 60 * 1000)); userDraggingSeekBar = false; userSeekBarPosition = 0; seekBar.setOnSeekBarChangeListener(this); final Handler handler = new Handler(); final MediaPlayer mediaPlayer = talkPlayerFragment.getMediaPlayer(); handler.post(new Runnable() { @Override public void run() { handler.postDelayed(this, 1000); if (talkPlayerFragment.getMediaPrepared() && !userDraggingSeekBar) { try { int pos = mediaPlayer.getCurrentPosition(); int mpDuration = mediaPlayer.getDuration(); seekBar.setMax(mpDuration); seekBar.setProgress(pos); String posStr = DateUtils.formatElapsedTime(pos / 1000); String mpDurStr = DateUtils.formatElapsedTime(mpDuration / 1000); durationView.setText(posStr + "/" + mpDurStr); } catch (IllegalStateException e) { } } } }); }
From source file:com.campusclipper.android.MyLocationActivity.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 www . j av a2s .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); } } }); } else if (marker.equals(mAdelaide)) { // This causes the marker at Adelaide to change color and alpha. marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360)); marker.setAlpha(mRandom.nextFloat()); } // 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; }
From source file:de.stadtrallye.rallyesoft.model.map.MapManager.java
private void notifyMapConfigChange() { Handler handler; synchronized (mapListeners) { configLock.readLock().lock();/*from w ww. jav a 2 s .co m*/ try { for (final IMapListener l : mapListeners) { handler = l.getCallbackHandler(); if (handler == null) { l.onMapConfigChange(MapManager.this.mapConfig); } else { handler.post(new Runnable() { @Override public void run() { configLock.readLock().lock(); try { l.onMapConfigChange(MapManager.this.mapConfig); } finally { configLock.readLock().unlock(); } } }); } } } finally { configLock.readLock().unlock(); } } }
From source file:ai.eve.volley.Request.java
/** * Notifies the request queue that this request has finished (successfully * or with error).//from w ww .j a v a2 s .c o m * * <p> * Also dumps all events from this request's event log; for debugging. * </p> */ public void finish(final String tag) { if (mRequestQueue != null) { mRequestQueue.finish(this); } if (MarkerLog.ENABLED) { final long threadId = Thread.currentThread().getId(); if (Looper.myLooper() != Looper.getMainLooper()) { // If we finish marking off of the main thread, we need to // actually do it on the main thread to ensure correct ordering. Handler mainThread = new Handler(Looper.getMainLooper()); mainThread.post(new Runnable() { @Override public void run() { mEventLog.add(tag, threadId); mEventLog.finish(this.toString()); } }); return; } mEventLog.add(tag, threadId); mEventLog.finish(this.toString()); } else { long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime; if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) { NetroidLog.d("%d ms: %s", requestTime, this.toString()); } } }
From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java
public void callBackgroundService(final double latitude, final double longitude) { final Handler handler = new Handler(); Timer timer = new Timer(); TimerTask doAsynchronousTask = new TimerTask() { @Override/*from ww w . j av a2s .c o m*/ public void run() { handler.post(new Runnable() { public void run() { try { if (latitude != 0.0d && longitude != 0.0d) { Intent intent = new Intent(getActivity(), BackgroundService.class); intent.putExtra("userid", mUserId); intent.putExtra("lat", String.valueOf(latitude)); intent.putExtra("long", String.valueOf(longitude)); getActivity().startService(intent); } } catch (Exception e) { // TODO Auto-generated catch block } } }); } }; timer.schedule(doAsynchronousTask, 0, 5000); }
From source file:com.dmsl.anyplace.tasks.DownloadRadioMapTaskBuid.java
private void runPreExecuteOnUI() { // Get a handler that can be used to post to the main thread Handler mainHandler = new Handler(ctx.getMainLooper()); Runnable myRunnable = new Runnable() { @Override/* w ww . j av a2 s. co m*/ public void run() { try { if (mListener != null) mListener.onPrepareLongExecute(); } finally { synchronized (syncListener) { run = true; syncListener.notifyAll(); } } } }; mainHandler.post(myRunnable); }
From source file:org.hfoss.posit.android.sync.Communicator.java
/** * Sends the result of a getProjects request from server back to the caller * main UI thread through its handler.//w w w. j a va 2s . com * * @param projects * the list of projects gotten from server * @param result * The boolean holding authentication result * @param authToken * The auth token returned from the server for this account. * @param handler * The main UI thread's handler instance. * @param context * The caller Activity's context. */ private static void sendProjectsResult(final ArrayList<HashMap<String, Object>> projects, final Boolean result, final Handler handler, final Context context) { if (handler == null || context == null) { return; } handler.post(new Runnable() { public void run() { ((ListProjectsActivity) context).onShowProjectsResult(projects, result); } }); }