List of usage examples for android.app Activity runOnUiThread
public final void runOnUiThread(Runnable action)
From source file:com.mediatek.contacts.activities.ActivitiesUtils.java
/** For CR ALPS01541210 */ public static boolean checkContactsProcessIsBusy(final Activity activity) { // Since busy return directly no receiver is registered boolean isProcessBusy = ContactsApplicationEx.isContactsApplicationBusy(); Log.d(TAG, "[checkContactsProcessIsBusy]isProcessBusy = " + isProcessBusy); if (isProcessBusy) { activity.runOnUiThread(new Runnable() { @Override// ww w . j av a 2 s.co m public void run() { MtkToast.toast(activity.getApplicationContext(), R.string.phone_book_busy); } }); activity.finish(); return true; } return false; }
From source file:com.oo58.game.texaspoker.AppActivity.java
public static void callCustomService(final String number) { final Activity ctx = mAct; ctx.runOnUiThread(new Runnable() { @Override//from w w w.jav a 2 s.c o m public void run() { // TODO Auto-generated method stub try { Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number)); ctx.startActivity(intent); } catch (Exception ex) { ex.printStackTrace(); } } }); }
From source file:jahirfiquitiva.iconshowcase.fragments.WallpapersFragment.java
private static void setupLayout(final boolean fromTask, final Activity context, final ImageView noConnection) { if (WallpapersList.getWallpapersList() != null && WallpapersList.getWallpapersList().size() > 0) { context.runOnUiThread(new Runnable() { @Override/*from ww w . ja va 2 s . c om*/ public void run() { mAdapter = new WallpapersAdapter(context, new WallpapersAdapter.ClickListener() { @Override public void onClick(WallpapersAdapter.WallsHolder view, int position, boolean longClick) { if ((longClick && !ShowcaseActivity.wallsPicker) || ShowcaseActivity.wallsPicker) { final MaterialDialog dialog = new MaterialDialog.Builder(context) .content(R.string.downloading_wallpaper).progress(true, 0).cancelable(false) .show(); WallpaperItem wallItem = WallpapersList.getWallpapersList().get(position); Glide.with(context).load(wallItem.getWallURL()).asBitmap() .into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { if (resource != null) { new ApplyWallpaper(context, dialog, resource, ShowcaseActivity.wallsPicker, layout).execute(); } } }); } else { final Intent intent = new Intent(context, ViewerActivity.class); intent.putExtra("item", WallpapersList.getWallpapersList().get(position)); intent.putExtra("transitionName", ViewCompat.getTransitionName(view.wall)); Bitmap bitmap; if (view.wall.getDrawable() != null) { bitmap = Utils.drawableToBitmap(view.wall.getDrawable()); try { String filename = "temp.png"; FileOutputStream stream = context.openFileOutput(filename, Context.MODE_PRIVATE); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); stream.close(); intent.putExtra("image", filename); } catch (Exception e) { Utils.showLog(context, "Error getting drawable " + e.getLocalizedMessage()); } ActivityOptionsCompat options = ActivityOptionsCompat .makeSceneTransitionAnimation(context, view.wall, ViewCompat.getTransitionName(view.wall)); context.startActivity(intent, options.toBundle()); } else { context.startActivity(intent); } } } }); mAdapter.setData(WallpapersList.getWallpapersList()); mRecyclerView.setAdapter(mAdapter); fastScroller = (RecyclerFastScroller) layout.findViewById(R.id.rvFastScroller); fastScroller.attachRecyclerView(mRecyclerView); if (fastScroller.getVisibility() != View.VISIBLE) { fastScroller.setVisibility(View.VISIBLE); } if (Utils.hasNetwork(context)) { hideProgressBar(); noConnection.setVisibility(View.GONE); mRecyclerView.setVisibility(View.VISIBLE); fastScroller.setVisibility(View.VISIBLE); mSwipeRefreshLayout.setEnabled(false); mSwipeRefreshLayout.setRefreshing(false); } else { hideStuff(noConnection); } } }); } else { context.runOnUiThread(new Runnable() { @Override public void run() { if (layout != null) { noConnection.setVisibility(View.GONE); showProgressBar(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { context.runOnUiThread(new Runnable() { @Override public void run() { hideStuff(noConnection); } }); } }, 7500); } } }); } }
From source file:tv.ouya.sdk.OuyaUnityPlugin.java
public static void setSafeArea(final float percentage) { try {//from ww w . j a v a2s .co m //Log.i(TAG, "setSafeArea: "+percentage); Activity activity = IOuyaActivity.GetActivity(); if (null != activity) { Runnable runnable = new Runnable() { public void run() { updateSafeArea(percentage); } }; activity.runOnUiThread(runnable); } } catch (Exception e) { Log.e(TAG, "setSafeArea: exception=" + e.toString()); } }
From source file:net.vleu.par.android.rpc.Transceiver.java
/** * Ensures that application has a fresh permission from the user to use his * account/* ww w .j ava 2 s .c om*/ * * @param activity * The Activity context to use for launching a new sub-Activity * to prompt the user for a password if necessary; used only to * call startActivity(); must not be null. * @param onUserResponse * If not null, will be called in the main thread after the user * answered */ public static void askUserForSinglePermissionIfNecessary(final Activity activity, final Runnable onUserResponse, final Account account) { final AccountManager am = AccountManager.get(activity); final AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() { @Override public void run(final AccountManagerFuture<Bundle> bundle) { if (onUserResponse != null) activity.runOnUiThread(onUserResponse); } }; am.getAuthToken(account, APPENGINE_TOKEN_TYPE, null, activity, callback, null); }
From source file:dentex.youtube.downloader.utils.Utils.java
public static void secureShowDialog(final Activity act, final AlertDialog.Builder adb) { act.runOnUiThread(new Runnable() { @Override//ww w . j a va2 s .c o m public void run() { if (!act.isFinishing()) { adb.show(); } } }); }
From source file:com.mediatek.contacts.activities.ActivitiesUtils.java
public static boolean isDeleteingContact(final Activity activity) { if (MultiChoiceService.isProcessing(MultiChoiceService.TYPE_DELETE) || MultiChoiceService.isProcessing(MultiChoiceService.TYPE_COPY) || VCardService.isProcessing(VCardService.TYPE_IMPORT) || MultiGroupPickerFragment.isMoveContactsInProcessing()// M:ALPS00567939 || ContactSaveService.isGroupTransactionProcessing()) { // / M: Fixed ALPS00542175 Log.d(TAG, "delete or copy is processing "); activity.runOnUiThread(new Runnable() { @Override/*from www .ja va 2s . c om*/ public void run() { Toast.makeText(activity.getApplicationContext(), R.string.phone_book_busy, Toast.LENGTH_SHORT) .show(); } }); activity.finish(); return true; } return false; }
From source file:com.onesignal.GenerateNotification.java
private static int showNotificationAsAlert(final JSONObject gcmJson, final Activity activity) { final int aNotificationId = new Random().nextInt(); activity.runOnUiThread(new Runnable() { @Override//from ww w.j a va 2 s .c o m public void run() { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(getTitle(gcmJson)); try { builder.setMessage(gcmJson.getString("alert")); } catch (Throwable t) { } List<String> buttonsLabels = new ArrayList<String>(); List<String> buttonIds = new ArrayList<String>(); addAlertButtons(gcmJson, buttonsLabels, buttonIds); final List<String> finalButtonIds = buttonIds; Intent buttonIntent = getNewBaseIntent(aNotificationId); buttonIntent.putExtra("action_button", true); buttonIntent.putExtra("from_alert", true); buttonIntent.putExtra("onesignal_data", gcmJson.toString()); try { if (gcmJson.has("grp")) buttonIntent.putExtra("grp", gcmJson.getString("grp")); } catch (JSONException e) { } final Intent finalButtonIntent = buttonIntent; DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int index = which + 3; if (finalButtonIds.size() > 1) { try { JSONObject customJson = new JSONObject(gcmJson.getString("custom")); JSONObject additionalDataJSON = customJson.getJSONObject("a"); additionalDataJSON.put("actionSelected", finalButtonIds.get(index)); JSONObject newJsonData = new JSONObject(gcmJson.toString()); newJsonData.put("custom", customJson.toString()); finalButtonIntent.putExtra("onesignal_data", newJsonData.toString()); NotificationOpenedProcessor.processIntent(activity, finalButtonIntent); } catch (Throwable t) { } } else // No action buttons, close button simply pressed. NotificationOpenedProcessor.processIntent(activity, finalButtonIntent); } }; // Back button pressed builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { NotificationOpenedProcessor.processIntent(activity, finalButtonIntent); } }); for (int i = 0; i < buttonsLabels.size(); i++) { if (i == 0) builder.setNeutralButton(buttonsLabels.get(i), buttonListener); else if (i == 1) builder.setNegativeButton(buttonsLabels.get(i), buttonListener); else if (i == 2) builder.setPositiveButton(buttonsLabels.get(i), buttonListener); } AlertDialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } }); return aNotificationId; }
From source file:ru.dublgis.androidlocation.GmsLocationProvider.java
static public boolean isAvailable(final Activity activity, final boolean allowDialog) { try {// w w w .ja v a 2s . co m final GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); final int errorCode = apiAvailability.isGooglePlayServicesAvailable(activity); switch (errorCode) { case ConnectionResult.SERVICE_MISSING: case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: case ConnectionResult.SERVICE_DISABLED: if (allowDialog) { activity.runOnUiThread(new Runnable() { @Override public void run() { Dialog dialog = apiAvailability.getErrorDialog(activity, errorCode, 1); if (null != dialog) { dialog.show(); } } }); } } return ConnectionResult.SUCCESS == errorCode; } catch (Exception e) { Log.e(TAG, "isAvailable(): ", e); } return false; }
From source file:tv.ouya.sdk.OuyaUnityPlugin.java
public static void clearFocus() { try {/*from w w w .java2 s . c o m*/ //Log.i(TAG, "clearFocus"); final Activity activity = IOuyaActivity.GetActivity(); if (null != activity) { Runnable runnable = new Runnable() { public void run() { View view = activity.getCurrentFocus(); if (null != view) { view.setFocusable(false); view.clearFocus(); } } }; activity.runOnUiThread(runnable); } } catch (Exception e) { Log.e(TAG, "clearFocus: exception=" + e.toString()); } }