List of usage examples for android.app Activity runOnUiThread
public final void runOnUiThread(Runnable action)
From source file:com.vuze.android.remote.AndroidUtils.java
public static void showConnectionError(final Activity activity, final String errMsg, final boolean allowContinue) { if (AndroidUtils.DEBUG) { Log.d(TAG, "showConnectionError.string " + AndroidUtils.getCompressedStackTrace()); }//ww w . j a v a 2 s. co m if (activity == null) { Log.e(null, "No activity for error message " + errMsg); return; } activity.runOnUiThread(new Runnable() { public void run() { if (activity.isFinishing()) { if (DEBUG) { System.out.println("can't display -- finishing"); } return; } Builder builder = new AlertDialog.Builder(activity).setTitle(R.string.error_connecting) .setMessage(errMsg).setCancelable(true) .setNegativeButton(R.string.action_logout, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (activity.isTaskRoot()) { RemoteUtils.openRemoteList(activity); } activity.finish(); } }); if (allowContinue) { builder.setPositiveButton(R.string.button_continue, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); } AndroidUtils.openSingleAlertDialog(activity, builder); } }); }
From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java
/** * Shows a {@link Toast} on the UI thread for the classification results. * * @param text The message to show/*from w ww .j a v a 2 s. c o m*/ */ private void showToast(final String text) { final Activity activity = getActivity(); if (activity != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { textView.setText(text); } }); } }
From source file:org.catrobat.catroid.ui.MainMenuActivity.java
@Override protected void onResume() { super.onResume(); if (!Utils.checkForExternalStorageAvailableAndDisplayErrorIfNot(this)) { return;//from w ww. j a v a 2 s.c om } AppEventsLogger.activateApp(this); SettingsActivity.setLegoMindstormsNXTSensorChooserEnabled(this, false); SettingsActivity.setDroneChooserEnabled(this, false); findViewById(R.id.progress_circle).setVisibility(View.VISIBLE); final Activity activity = this; Runnable r = new Runnable() { @Override public void run() { UtilFile.createStandardProjectIfRootDirectoryIsEmpty(activity); activity.runOnUiThread(new Runnable() { @Override public void run() { finishOnCreateAfterRunnable(); } }); } }; (new Thread(r)).start(); }
From source file:com.andrada.sitracker.ui.fragment.DirectoryChooserFragment.java
/** * Sets up a FileObserver to watch the current directory. *///from w w w .j av a 2 s. c o m @NotNull private FileObserver createFileObserver(String path) { return new FileObserver(path, FileObserver.CREATE | FileObserver.DELETE | FileObserver.MOVED_FROM | FileObserver.MOVED_TO) { @Override public void onEvent(int event, String path) { debug("FileObserver received event %d", event); final Activity activity = getActivity(); if (activity != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { refreshDirectory(); } }); } } }; }
From source file:org.kontalk.ui.GroupInfoFragment.java
@Override public void onContactInvalidated(String userId) { Activity context = getActivity(); if (context != null) { context.runOnUiThread(new Runnable() { @Override/*from ww w. j a v a 2 s . com*/ public void run() { // just reload reload(); } }); } }
From source file:com.razerzone.store.sdk.engine.gamemaker.Plugin.java
public static double requestProducts(final String identifiers) { if (null == sStoreFacade) { Log.e(TAG, "StoreFacade is null!"); return sNoop; }/*w w w . jav a 2 s. c o m*/ final Activity activity = Plugin.getRelay().getCurrentActivity(); if (null == activity) { Log.d(TAG, "Activity is null"); return sNoop; } Runnable runnable = new Runnable() { public void run() { List<String> products = new ArrayList<String>(); String[] ids = identifiers.split(","); for (String identifier : ids) { products.add(identifier); } String[] purchasables = new String[products.size()]; purchasables = products.toArray(purchasables); sStoreFacade.requestProductList(activity, purchasables, sRequestProductsListener); } }; activity.runOnUiThread(runnable); return sNoop; }
From source file:org.messic.android.controllers.PlaylistController.java
public void getPlaylistMusic(final PlaylistAdapter adapter, final Activity activity, final PlaylistFragment pf, boolean refresh, final SwipeRefreshLayout srl) { if (rlist == null || refresh) { final String baseURL = Configuration.getBaseUrl() + "/services/playlists?songsInfo=true&messic_token=" + Configuration.getLastToken(); RestJSONClient.get(baseURL, MDMPlaylist[].class, new RestJSONClient.RestListener<MDMPlaylist[]>() { public void response(MDMPlaylist[] response) { rlist = response;//from www.jav a 2s. c o m refreshData(adapter, activity, pf, srl); } public void fail(final Exception e) { Log.e("Playlist", e.getMessage(), e); activity.runOnUiThread(new Runnable() { public void run() { Toast.makeText(activity, "Error:" + e.getMessage(), Toast.LENGTH_LONG).show(); } }); } }); } else { if (rlist != null) { refreshData(adapter, activity, pf, srl); } } }
From source file:com.razerzone.store.sdk.engine.gamemaker.Plugin.java
public static double requestPurchase(final String identifier, final String productType) { if (null == sStoreFacade) { Log.e(TAG, "StoreFacade is null!"); return sNoop; }/*from w w w. jav a 2 s .co m*/ final Activity activity = Plugin.getRelay().getCurrentActivity(); if (null == activity) { Log.d(TAG, "Activity is null"); return sNoop; } if (null == sRequestPurchaseListener) { Log.e(TAG, "requestPurchase: sRequestPurchaseListener is null"); return sNoop; } Runnable runnable = new Runnable() { public void run() { Product product = new Product(identifier, "", 0, 0, "", 0, 0, "", "", Product.Type.valueOf(productType)); Purchasable purchasable = product.createPurchasable(); sStoreFacade.requestPurchase(activity, purchasable, sRequestPurchaseListener); } }; activity.runOnUiThread(runnable); return sNoop; }
From source file:com.hemou.android.account.AccountUtils.java
/** * Get account used for authentication/*from w w w . j a v a 2 s.co m*/ * * @param manager * @param act * @return account * @throws IOException * @throws AccountsException */ public static Account getAccount(final AccountManager manager, final Activity act) throws IOException, AccountsException { final String SUB_TAG = "acnt_get"; final boolean loggable = Log.isLoggable(SUB_TAG, DEBUG); if (loggable) Log.d(SUB_TAG, "Getting account"); if (act == null) throw new IllegalArgumentException("Activity cannot be null"); if (act.isFinishing()) { Log.v(SUB_TAG, act.getClass().getName() + "--->?finish()OperationCanceledException..."); throw new OperationCanceledException(); } Account[] accounts; try { if (!hasAuthenticator(manager)) { Log.e(SUB_TAG, "Current user is not under the authenticated environment...."); throw new AuthenticatorConflictException(); } while ((accounts = getAccounts(manager)).length == 0) { Bundle result = manager.addAccount(ACCOUNT_TYPE, AUTHTOKEN_TYPE, null, null, act, null, null) .getResult(); } } catch (OperationCanceledException e) { Log.d(SUB_TAG, "Excepting retrieving account", e); act.finish(); throw e; } catch (AccountsException e) { Log.d(SUB_TAG, "Excepting retrieving account", e); throw e; } catch (AuthenticatorConflictException e) { act.runOnUiThread(new Runnable() { public void run() { showConflictMessage(act); } }); throw e; } catch (IOException e) { Log.d(SUB_TAG, "Excepting retrieving account", e); throw e; } // if (loggable) Log.d(SUB_TAG, "Returning account " + accounts[0].name); return accounts[0]; }
From source file:com.sourceallies.android.zonebeacon.activity.MainActivity.java
/** * Get the callback that used for querying the gateway for which loads are on and off * * @param currentGateway the currently selected gateway * @param zones list of zones on the gateway * @param buttons list of buttons on the gateway * @return callback that will reset the RecyclerView to have a list of load statuses *//* w w w . ja v a 2 s . c om*/ @VisibleForTesting protected QueryLoadsCallback getQueryCallback(final Activity activity, final Gateway currentGateway, final List<Zone> zones, final List<Button> buttons) { return new QueryLoadsCallback() { @Override public void onResponse(final Map<Integer, Map<Integer, Executor.LoadStatus>> loadStatusMap) { activity.runOnUiThread(setLoadStatusRunnable(currentGateway, zones, buttons, loadStatusMap)); } }; }