List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:com.ryan.ryanreader.common.General.java
public static void showResultDialog(final Activity context, final RRError error) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context); alertBuilder.setNeutralButton(R.string.dialog_close, null); alertBuilder.setNegativeButton(R.string.button_moredetail, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ErrorPropertiesDialog.newInstance(error).show(context); }//from ww w. j a va2s .c o m }); alertBuilder.setTitle(error.title); alertBuilder.setMessage(error.message); alertBuilder.create().show(); } }); }
From source file:com.mb.android.playbackmediator.cast.BaseCastManager.java
/************************************************************************/ protected BaseCastManager(Context context, String applicationId) { CCL_VERSION = "1.9"; LOGD(TAG, "BaseCastManager is instantiated"); mContext = context;/*w ww . j a v a2 s . co m*/ mHandler = new Handler(Looper.getMainLooper()); mUiVisibilityHandler = new Handler(new UpdateUiVisibilityHandlerCallback()); mApplicationId = applicationId; Utils.saveStringToPreference(mContext, PREFS_KEY_APPLICATION_ID, applicationId); LOGD(TAG, "Application ID is: " + mApplicationId); mMediaRouter = MediaRouter.getInstance(context); mMediaRouter.addProvider(new MediaBrowserRouteProvider(MainApplication.getInstance())); mMediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId)) .addControlCategory(MediaBrowserRouteProvider.CATEGORY_MEDIA_BROWSER_ROUTE).build(); mMediaRouterCallback = new CastMediaRouterCallback(this, context); mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY); }
From source file:com.android.emailcommon.provider.EmailContent.java
private static void warnIfUiThread() { if (Looper.getMainLooper().getThread() == Thread.currentThread()) { LogUtils.w(Logging.LOG_TAG, new Throwable(), "Method called on the UI thread"); }//from w ww. j a v a 2 s . c o m }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedComment.java
public void refreshView(final Context context) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { rebuildHeader(context);// w w w.j a v a 2 s. co m if (boundView != null) { boundView.updateAppearance(); boundView.requestLayout(); boundView.invalidate(); } } }); }
From source file:com.markupartist.sthlmtraveling.PlaceSearchActivity.java
public void createSearchHandler() { mHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() { @Override/*from w w w. j a v a2s . c o m*/ public boolean handleMessage(Message msg) { switch (msg.what) { case MESSAGE_TEXT_CHANGED: if (mSearchResultAdapter.getFilter() != null) { mSearchResultAdapter.getFilter().filter((String) msg.obj); } return true; } return false; } }); }
From source file:org.quantumbadger.redreader.activities.PostSubmitActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) return;/*w w w. j a va2 s. c o m*/ final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getString(R.string.comment_reply_submitting_title)); progressDialog.setMessage(getString(R.string.comment_reply_submitting_message)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(final DialogInterface dialogInterface) { General.quickToast(PostSubmitActivity.this, getString(R.string.comment_reply_oncancel)); progressDialog.dismiss(); } }); progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(final DialogInterface dialogInterface, final int keyCode, final KeyEvent keyEvent) { if (keyCode == KeyEvent.KEYCODE_BACK) { General.quickToast(PostSubmitActivity.this, getString(R.string.comment_reply_oncancel)); progressDialog.dismiss(); } return true; } }); final CacheManager cm = CacheManager.getInstance(this); final APIResponseHandler.ActionResponseHandler handler = new APIResponseHandler.ActionResponseHandler( this) { @Override protected void onSuccess() { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (progressDialog.isShowing()) progressDialog.dismiss(); General.quickToast(PostSubmitActivity.this, getString(R.string.post_submit_done)); finish(); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(PostSubmitActivity.this, t); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, null); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { General.showResultDialog(PostSubmitActivity.this, error); if (progressDialog.isShowing()) progressDialog.dismiss(); } }); } @Override protected void onFailure(final APIFailureType type) { final RRError error = General.getGeneralErrorForFailure(context, type); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { General.showResultDialog(PostSubmitActivity.this, error); if (progressDialog.isShowing()) progressDialog.dismiss(); } }); } }; final boolean is_self = !typeSpinner.getSelectedItem().equals("Link"); final RedditAccount selectedAccount = RedditAccountManager.getInstance(this) .getAccount((String) usernameSpinner.getSelectedItem()); String subreddit = subredditEdit.getText().toString(); final String title = titleEdit.getText().toString(); final String text = textEdit.getText().toString(); final String captchaId = data.getStringExtra("captchaId"); final String captchaText = data.getStringExtra("captchaText"); while (subreddit.startsWith("/")) subreddit = subreddit.substring(1); while (subreddit.startsWith("r/")) subreddit = subreddit.substring(2); while (subreddit.endsWith("/")) subreddit = subreddit.substring(0, subreddit.length() - 1); RedditAPI.submit(cm, handler, selectedAccount, is_self, subreddit, title, text, captchaId, captchaText, this); progressDialog.show(); }
From source file:com.digium.respokesdk.RespokeDirectConnection.java
public void onMessage(org.webrtc.DataChannel.Buffer buffer) { if (buffer.binary) { // TODO//from w ww.j av a 2s . c o m } else { Charset charset = Charset.forName("UTF-8"); CharsetDecoder decoder = charset.newDecoder(); try { String message = decoder.decode(buffer.data).toString(); try { JSONObject jsonMessage = new JSONObject(message); final String messageText = jsonMessage.getString("message"); if (null != messageText) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (null != listenerReference) { Listener listener = listenerReference.get(); if (null != listener) { listener.onMessage(messageText, RespokeDirectConnection.this); } } } }); } } catch (JSONException e) { // If it is not valid json, ignore the message } } catch (CharacterCodingException e) { // If the message can not be decoded, ignore it } } }
From source file:com.google.sample.castcompanionlibrary.cast.BaseCastManager.java
protected BaseCastManager(Context context, String applicationId) { mContext = context.getApplicationContext(); CCL_VERSION = mContext.getString(R.string.ccl_version); LOGD(TAG, "BaseCastManager is instantiated"); mHandler = new Handler(Looper.getMainLooper()); mUiVisibilityHandler = new Handler(new UpdateUiVisibilityHandlerCallback()); mApplicationId = applicationId;//from w w w . ja v a 2 s. com Utils.saveStringToPreference(mContext, PREFS_KEY_APPLICATION_ID, applicationId); LOGD(TAG, "Application ID is: " + mApplicationId); mMediaRouter = MediaRouter.getInstance(mContext); mMediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory(CastMediaControlIntent.categoryForCast(mApplicationId)).build(); mMediaRouterCallback = new CastMediaRouterCallback(this, mContext); mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY); }
From source file:com.ryan.ryanreader.activities.PostSubmitActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) return;/*from w ww .j av a2 s . c om*/ final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getString(R.string.comment_reply_submitting_title)); progressDialog.setMessage(getString(R.string.comment_reply_submitting_message)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(final DialogInterface dialogInterface) { General.quickToast(PostSubmitActivity.this, getString(R.string.comment_reply_oncancel)); progressDialog.dismiss(); } }); progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(final DialogInterface dialogInterface, final int keyCode, final KeyEvent keyEvent) { if (keyCode == KeyEvent.KEYCODE_BACK) { General.quickToast(PostSubmitActivity.this, getString(R.string.comment_reply_oncancel)); progressDialog.dismiss(); } return true; } }); final CacheManager cm = CacheManager.getInstance(this); final APIResponseHandler.ActionResponseHandler handler = new APIResponseHandler.ActionResponseHandler( this) { @Override protected void onSuccess() { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (progressDialog.isShowing()) progressDialog.dismiss(); General.quickToast(PostSubmitActivity.this, getString(R.string.post_submit_done)); finish(); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(PostSubmitActivity.this, t); } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { General.showResultDialog(PostSubmitActivity.this, error); if (progressDialog.isShowing()) progressDialog.dismiss(); } }); } @Override protected void onFailure(final APIFailureType type) { final RRError error = General.getGeneralErrorForFailure(context, type); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { General.showResultDialog(PostSubmitActivity.this, error); if (progressDialog.isShowing()) progressDialog.dismiss(); } }); } }; final boolean is_self = !typeSpinner.getSelectedItem().equals("Link"); final RedditAccount selectedAccount = RedditAccountManager.getInstance(this) .getAccount((String) usernameSpinner.getSelectedItem()); final String subreddit = subredditEdit.getText().toString(); final String title = titleEdit.getText().toString(); final String text = textEdit.getText().toString(); final String captchaId = data.getStringExtra("captchaId"); final String captchaText = data.getStringExtra("captchaText"); RedditAPI.submit(cm, handler, selectedAccount, is_self, subreddit, title, text, captchaId, captchaText, this); progressDialog.show(); }
From source file:com.itude.mobile.mobbl.core.controller.MBDialogManager.java
public void enqueueDialog(String dialog) { _activeDialog = null;//from w w w.j a va2s . c om _toActivate = dialog; new Handler(Looper.getMainLooper()).post(new MBThread() { @Override public void runMethod() throws MBInterruptedException { checkEnqueued(); } }); }