List of usage examples for android.app Activity runOnUiThread
public final void runOnUiThread(Runnable action)
From source file:com.alexlionne.apps.avatars.Utils.DirectoryChooserFragment.java
/** * Sets up a FileObserver to watch the current directory. *///from ww w. j a v a 2s .c o m 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:com.teddoll.movies.InfoActivityFragment.java
private void loadMovie() { if (movie == null) return;// w w w .j av a2s. com String url = "http://image.tmdb.org/t/p/w500/" + movie.posterPath; Picasso.with(getActivity()).load(url).into(poster); title.setText(movie.title); overview.setText(movie.overview); rate.setText(getString(R.string.rating_format, movie.voteAverage)); if (movie.releaseDate != null) { SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); SimpleDateFormat outFormat = new SimpleDateFormat("MMMM, yyyy", Locale.getDefault()); String dateOut; try { Date date = inFormat.parse(movie.releaseDate); dateOut = outFormat.format(date); } catch (ParseException e) { e.printStackTrace(); dateOut = movie.releaseDate; } dateText.setText(dateOut); } if (movie.genreIds != null && movie.genreIds.length > 0) { int[] gIds = movie.genreIds; StringBuilder genreOut = new StringBuilder(); Map<Integer, String> genreMap = MovieProvider .getInstance(HttpClientProvider.getInstance(getActivity()).getHttpClient()).getGenres(); for (int i = 0; i < gIds.length - 1; i++) { String genreString = getGenre(genreMap, gIds[i]); if (!genreString.isEmpty()) { genreOut.append(genreString).append(", "); } } if (gIds.length > 0) { genreOut.append(getGenre(genreMap, gIds[gIds.length - 1])); } genre.setText(genreOut.toString()); } boolean favorited = faves.hasFavorite(movie); if (favorited) { add.setVisibility(View.GONE); remove.setVisibility(View.VISIBLE); } else { remove.setVisibility(View.GONE); add.setVisibility(View.VISIBLE); } add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { faves.addFavorite(movie); add.setVisibility(View.GONE); remove.setVisibility(View.VISIBLE); } }); remove.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { faves.removeFavorite(movie); remove.setVisibility(View.GONE); add.setVisibility(View.VISIBLE); } }); trailerContainer.setVisibility(View.GONE); reviewContainer.setVisibility(View.GONE); MovieSync.getVideos(HttpClientProvider.getInstance(getActivity()).getHttpClient(), movie, new MovieSync.OnGetVideosListener() { @Override public void onVideos(final List<Video> videos) { if (videos == null || videos.size() == 0) return; final Activity context = getActivity(); final View view = getView(); if (view == null || context == null) return; context.runOnUiThread(new Runnable() { @Override public void run() { trailerContainer.setVisibility(View.VISIBLE); videoList.removeAllViews(); LayoutInflater inflater = LayoutInflater.from(context); int height = getResources().getDimensionPixelSize(R.dimen.trailer_item_height); int lineHeight = getResources().getDimensionPixelSize(R.dimen.linear_line_break); for (int i = 0; i < videos.size() - 1; i++) { addVideoView(videos.get(i), videoList, inflater, height); addSeparator(videoList, lineHeight); } if (videos.size() > 0) { addVideoView(videos.get(videos.size() - 1), videoList, inflater, height); } } }); } }); MovieSync.getReviews(HttpClientProvider.getInstance(getActivity()).getHttpClient(), movie, new MovieSync.OnGetReviewsListener() { @Override public void onReviews(final List<Review> reviews) { if (reviews == null || reviews.size() == 0) return; final Activity context = getActivity(); final View view = getView(); if (view == null || context == null) return; context.runOnUiThread(new Runnable() { @Override public void run() { reviewContainer.setVisibility(View.VISIBLE); reviewList.removeAllViews(); LayoutInflater inflater = LayoutInflater.from(context); int height = getResources().getDimensionPixelSize(R.dimen.trailer_item_height); int lineHeight = getResources().getDimensionPixelSize(R.dimen.linear_line_break); for (int i = 0; i < reviews.size() - 1; i++) { addReviewView(reviews.get(i), reviewList, inflater, height); addSeparator(reviewList, lineHeight); } if (reviews.size() > 0) { addReviewView(reviews.get(reviews.size() - 1), reviewList, inflater, height); } } }); } }); }
From source file:com.microsoft.windowsazure.mobileservices.authentication.LoginManager.java
/** * Creates the UI for the interactive authentication process * * @param startUrl The initial URL for the authentication process * @param endUrl The final URL for the authentication process * @param context The context used to create the authentication dialog * @param callback Callback to invoke when the authentication process finishes *//*from w w w. j av a 2 s.c om*/ private void showLoginUI(final String startUrl, final String endUrl, final Context context, final LoginUIOperationCallback callback) { Activity activity = (Activity) context; activity.runOnUiThread(new Runnable() { public void run() { showLoginUIInternal(startUrl, endUrl, context, callback); } }); }
From source file:org.transdroid.core.gui.navigation.NavigationHelper.java
private boolean checkPermission(final Activity activity, final String permission, final int requestCode) { if (hasPermission(permission)) // Permission already granted return true; if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { // Never asked again: show a dialog with an explanation activity.runOnUiThread(new Runnable() { public void run() { new MaterialDialog.Builder(context).content(R.string.permission_readtorrent) .positiveText(android.R.string.ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ActivityCompat.requestPermissions(activity, new String[] { permission }, requestCode); }//from w ww. ja va2 s . c o m }).show(); } }); return false; } // Permission not granted (and we asked for it already before) ActivityCompat.requestPermissions(activity, new String[] { permission }, REQUEST_TORRENT_READ_PERMISSION); return false; }
From source file:im.vector.receiver.VectorUniversalLinkReceiver.java
/** * Start the universal link management when the login process is done. * If there is no active activity, launch the home activity * * @param aContext the context.// w w w. j a v a 2 s.co m */ private void manageRoomOnActivity(final Context aContext) { final Activity currentActivity = VectorApp.getCurrentActivity(); if (null != currentActivity) { currentActivity.runOnUiThread(new Runnable() { @Override public void run() { manageRoom(aContext); } }); } else { // clear the activity stack to home activity Intent intent = new Intent(aContext, VectorHomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(VectorHomeActivity.EXTRA_WAITING_VIEW_STATUS, VectorHomeActivity.WAITING_VIEW_START); aContext.startActivity(intent); try { final Timer wakeup = new Timer(); wakeup.schedule(new TimerTask() { @Override public void run() { wakeup.cancel(); manageRoomOnActivity(aContext); } }, 200); } catch (Throwable throwable) { Log.e(LOG_TAG, "## manageRoomOnActivity timer creation failed " + throwable.getMessage()); manageRoomOnActivity(aContext); } } }
From source file:at.ac.tuwien.detlef.fragments.PlayerFragment.java
@Override public void onEpisodeDeleted(final Episode episode) { Activity activity = getActivity(); if (activity == null) { return;//w w w. j a va 2s. co m } activity.runOnUiThread(new Runnable() { @Override public void run() { if (activeEpisode == episode) { stopPlaying(); activeEpisode = null; setEpisodeInfoControls(activeEpisode); } } }); }
From source file:im.neon.util.VectorUtils.java
/** * Display the licenses text./*from ww w .java 2 s . c om*/ */ public static void displayThirdPartyLicenses() { final Activity activity = VectorApp.getCurrentActivity(); if (null != activity) { if (null != mMainAboutDialog) { if (mMainAboutDialog.isShowing() && (null != mMainAboutDialog.getOwnerActivity())) { try { mMainAboutDialog.dismiss(); } catch (Exception e) { Log.e(LOG_TAG, "## displayThirdPartyLicenses() : " + e.getMessage()); } } mMainAboutDialog = null; } activity.runOnUiThread(new Runnable() { @Override public void run() { WebView view = (WebView) LayoutInflater.from(activity).inflate(R.layout.dialog_licenses, null); view.loadUrl("file:///android_asset/open_source_licenses.html"); View titleView = LayoutInflater.from(activity).inflate(R.layout.dialog_licenses_header, null); view.setScrollbarFadingEnabled(false); mMainAboutDialog = new AlertDialog.Builder(activity).setCustomTitle(titleView).setView(view) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mMainAboutDialog = null; } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mMainAboutDialog = null; } }).create(); mMainAboutDialog.show(); } }); } }
From source file:org.videolan.vlc.gui.audio.AudioAlbumsSongsFragment.java
private void updateList() { if (mMediaList == null || getActivity() == null) return;//from ww w . j a va2 s. co m final Activity activity = getActivity(); mAlbumsAdapter.clear(); mSongsAdapter.clear(); new Thread(new Runnable() { @Override public void run() { Collections.sort(mMediaList, MediaComparators.byAlbum); activity.runOnUiThread(new Runnable() { @Override public void run() { for (int i = 0; i < mMediaList.size(); ++i) { MediaWrapper media = mMediaList.get(i); mAlbumsAdapter.addSeparator(Util.getMediaReferenceArtist(activity, media), media); mAlbumsAdapter.add(Util.getMediaAlbum(activity, media), null, media); mSongsAdapter.addSeparator(Util.getMediaAlbum(activity, media), media); } mSongsAdapter.sortByAlbum(); mAlbumsAdapter.notifyDataSetChanged(); mSongsAdapter.notifyDataSetChanged(); mSwipeRefreshLayout.setRefreshing(false); } }); } }).start(); }
From source file:com.vuze.android.remote.SessionInfo.java
public static void showUrlFailedDialog(final Activity activity, final String errMsg, final String url, final String sample) { if (activity == null) { Log.e(null, "No activity for error message " + errMsg); return;/* w w w. jav a 2 s.c o m*/ } activity.runOnUiThread(new Runnable() { public void run() { if (activity.isFinishing()) { return; } String s = activity.getResources().getString(R.string.torrent_url_add_failed, url, sample); Spanned msg = Html.fromHtml(s); Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true) .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).setNeutralButton(R.string.torrent_url_add_failed_openurl, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); activity.startActivity(intent); } }); builder.show(); } }); }
From source file:com.google.cloud.android.language.ApiFragment.java
private void deliverResponse(GenericJson response) { final Activity activity = getActivity(); if (response instanceof AnalyzeEntitiesResponse) { final List<Entity> entities = ((AnalyzeEntitiesResponse) response).getEntities(); final int size = entities.size(); final EntityInfo[] array = new EntityInfo[size]; for (int i = 0; i < size; i++) { array[i] = new EntityInfo(entities.get(i)); //System.out.println(array[i]); }// ww w . j av a2 s.c om activity.runOnUiThread(new Runnable() { @Override public void run() { if (mCallback != null) { mCallback.onEntitiesReady(array); } } }); } else if (response instanceof AnalyzeSentimentResponse) { final SentimentInfo sentiment = new SentimentInfo( ((AnalyzeSentimentResponse) response).getDocumentSentiment()); activity.runOnUiThread(new Runnable() { @Override public void run() { if (mCallback != null) { mCallback.onSentimentReady(sentiment); } } }); } else if (response instanceof AnnotateTextResponse) { final List<Token> tokens = ((AnnotateTextResponse) response).getTokens(); final int size = tokens.size(); final TokenInfo[] array = new TokenInfo[size]; for (int i = 0; i < size; i++) { array[i] = new TokenInfo(tokens.get(i)); } activity.runOnUiThread(new Runnable() { @Override public void run() { if (mCallback != null) { mCallback.onSyntaxReady(array); } } }); } }