List of usage examples for android.widget ImageView setTag
public void setTag(final Object tag)
From source file:cn.com.wo.bitmap.ImageWorker.java
public void loadImage(String url, ImageView imageView, int radian, boolean isBackground) { if (url == null || url.trim().length() == 0 || !url.startsWith("http")) return;// w w w . j a v a 2s. co m BitmapDrawable value = null; if (ImageFetcher.isDebug) Log.i(ImageFetcher.TAG, "loadImage " + url + "; isBg=" + isBackground); if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(url)); } if (value != null) { // Bitmap found in memory cache // imageView.setImageDrawable(value); if (isBackground) { imageView.setBackgroundDrawable(null); imageView.setBackgroundDrawable(value); } else imageView.setImageDrawable(value); } else if (cancelPotentialWork(url, imageView, isBackground)) { imageView.setTag(0); final BitmapWorkerTask task = new BitmapWorkerTask(imageView, radian, isBackground); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap[0], task); // imageView.setImageDrawable(asyncDrawable); if (isBackground) { imageView.setBackgroundDrawable(null); imageView.setBackgroundDrawable(asyncDrawable); } else imageView.setImageDrawable(asyncDrawable); // NOTE: This uses a custom version of AsyncTask that has been pulled from the // framework and slightly modified. Refer to the docs at the top of the class // for more info on what was changed. task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, url); } }
From source file:com.geeker.door.imgcache.ImageDownloader.java
/** * Same as download but the image is always downloaded and the cache is not * used. Kept private at the moment as its interest is not clear. *///from www .ja v a 2 s .c o m private void forceDownload(String url, ImageView imageView, String cookie, int defaultPicType) { try { // State sanity: url is guaranteed to never be null in if (url == null && imageView != null) { // imageView.setImageBitmap(getDefaultBitmap(mContext)); return; } if (cancelPotentialDownload(url, imageView)) { // mBitmapDownloaderTaskCache.remove(url); BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, mContext, defaultPicType); // imageView.setImageDrawable(downloadedDrawable); imageView.setTag(downloadedDrawable); task.execute(url, cookie); // ? // mBitmapDownloaderTaskCache.put(url, task); } } catch (RejectedExecutionException localRejectedExecutionException) { Logger.w(TAG, "localRejectedExecutionException"); } }
From source file:org.xbmc.kore.ui.AlbumDetailsFragment.java
/** * Display the songs/* w ww . ja va 2s . c o m*/ * * @param cursor Cursor with the data */ private void displaySongsList(Cursor cursor) { if (cursor.moveToFirst()) { songInfoList = new ArrayList<FileDownloadHelper.SongInfo>(cursor.getCount()); do { View songView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_song, songListView, false); TextView songTitle = (TextView) songView.findViewById(R.id.song_title); TextView trackNumber = (TextView) songView.findViewById(R.id.track_number); TextView duration = (TextView) songView.findViewById(R.id.duration); ImageView contextMenu = (ImageView) songView.findViewById(R.id.list_context_menu); // Add this song to the list FileDownloadHelper.SongInfo songInfo = new FileDownloadHelper.SongInfo(albumDisplayArtist, albumTitle, cursor.getInt(AlbumSongsListQuery.SONGID), cursor.getInt(AlbumSongsListQuery.TRACK), cursor.getString(AlbumSongsListQuery.TITLE), cursor.getString(AlbumSongsListQuery.FILE)); songInfoList.add(songInfo); songTitle.setText(songInfo.title); trackNumber.setText(String.valueOf(songInfo.track)); duration.setText(UIUtils.formatTime(cursor.getInt(AlbumSongsListQuery.DURATION))); contextMenu.setTag(songInfo); contextMenu.setOnClickListener(songItemMenuClickListener); songView.setTag(songInfo); songView.setOnClickListener(songClickListener); songListView.addView(songView); } while (cursor.moveToNext()); if (!songInfoList.isEmpty()) { // Check if download dir exists FileDownloadHelper.SongInfo songInfo = new FileDownloadHelper.SongInfo(albumDisplayArtist, albumTitle, 0, 0, null, null); if (songInfo.downloadDirectoryExists()) { Resources.Theme theme = getActivity().getTheme(); TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.colorAccent }); downloadButton.setColorFilter(styledAttributes.getColor(0, getActivity().getResources().getColor(R.color.accent_default))); styledAttributes.recycle(); } else { downloadButton.clearColorFilter(); } } } }
From source file:fr.jcf.pret.activities.PretEmpruntActivity.java
/** * Permet de sauvegarder des photos prises avec l'appareil photo * /*from www . j a v a 2 s . c o m*/ * @param data * @param context * @param fileUri * @param contentResolver * @param imageView */ private void sauvegardeImage(Intent data, Context context, Uri fileUri, ContentResolver contentResolver, ImageView imageView) { Bitmap bitmap = null; if (data != null) { // L'image a t retourne (ne fonctionne pas sur certains priphriques!!!) Bundle extras = data.getExtras(); bitmap = (Bitmap) extras.get("data"); imageView.setImageBitmap(bitmap); } else { // On prpare l'image pour enregistrer son nom et son chemin en base Uri imageSelection = null; // On rcupre le nom du fichier String nomImage = fileUri.toString().substring(fileUri.toString().lastIndexOf("/") + 1, fileUri.toString().length()); // Ici on enlve la partie "file://" afin de ne rcuprer que le chemin du rpertoire String chemin = fileUri.toString().substring(7, fileUri.toString().length()); try { // On enregistre l'image en base pour la rcuprer plus tard imageSelection = Uri .parse(MediaStore.Images.Media.insertImage(contentResolver, chemin, nomImage, "")); bitmap = UtilPret.decodeUri(imageSelection, contentResolver, imageView); // On associe l'image pour affichage imageView.setTag(imageSelection); imageView.setImageBitmap(bitmap); } catch (FileNotFoundException e) { Log.d(UtilPret.LOG_SOURCE, "Le fichier slectionn n'a pas t trouv."); Log.d(UtilPret.LOG_SOURCE, e.getMessage()); } } }
From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java
public void refreshActionBarColumns() { int currentPosition = pager.getCurrentItem(); layoutBackgroundColumnsBar.removeAllViews(); int padding = (int) getResources().getDimension(R.dimen.default_padding); //int sizeButton = (int) getResources().getDimension(R.dimen.actionbar_columns_height); for (int i = 1; i < fragmentAdapter.getFragmentList().size(); i++) { ImageView view = new ImageView(this); view.setPadding(padding, padding, padding, padding); view.setImageBitmap(ColumnsUtils.getButtonWithTitle(this, fragmentAdapter.getFragmentList().get(i), true, currentPosition == i ? Color.GREEN : Color.BLACK)); view.setTag(i); view.setOnClickListener(new View.OnClickListener() { @Override/*from ww w . j a va2 s . c o m*/ public void onClick(View view) { if (layoutMainOptionsColumns.getVisibility() != View.VISIBLE) { showActionBarIndicatorAndMovePager((Integer) view.getTag()); } } }); view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { int pos = (Integer) view.getTag(); int[] loc = new int[2]; view.getLocationOnScreen(loc); showOptionsColumns(loc[0], pos, true); return false; } }); layoutBackgroundColumnsBar.addView(view); } }
From source file:pro.dbro.bart.TheActivity.java
public void displayRouteResponse(routeResponse routeResponse) { // Log.d("displayRouteResponse","Is this real?: "+routeResponse.toString()); // Previously, if the device's locale wasn't in Pacific Standard Time // Responses with all expired routes could present, causing a looping refresh cycle // This is now remedied by coercing response dates into PST boolean expiredResponse = false; if (routeResponse.routes.size() == 0) { Log.d("displayRouteResponse", "no routes to display"); expiredResponse = true;//from w ww . j a va2 s. c o m } if (timer != null) timer.cancel(); // cancel previous timer timerViews = new ArrayList(); // release old ETA text views maxTimer = 0; try { tableLayout.removeAllViews(); //Log.v("DATE",new Date().toString()); long now = new Date().getTime(); if (!expiredResponse) { fareTv.setVisibility(0); fareTv.setText("$" + routeResponse.routes.get(0).fare); for (int x = 0; x < routeResponse.routes.size(); x++) { route thisRoute = routeResponse.routes.get(x); TableRow tr = (TableRow) View.inflate(c, R.layout.tablerow, null); tr.setPadding(0, 20, 0, 0); LinearLayout legLayout = (LinearLayout) View.inflate(c, R.layout.routelinearlayout, null); for (int y = 0; y < thisRoute.legs.size(); y++) { TextView trainTv = (TextView) View.inflate(c, R.layout.tabletext, null); trainTv.setPadding(0, 0, 0, 0); trainTv.setTextSize(20); trainTv.setGravity(3); // set left gravity // If route has multiple legs, generate "Transfer At [station name]" and "To [train name] " rows for each leg after the first if (y > 0) { trainTv.setText("transfer at " + BART.REVERSE_STATION_MAP .get(((leg) thisRoute.legs.get(y - 1)).disembarkStation.toLowerCase())); trainTv.setPadding(0, 0, 0, 0); legLayout.addView(trainTv); trainTv.setTextSize(14); trainTv = (TextView) View.inflate(c, R.layout.tabletext, null); trainTv.setPadding(0, 0, 0, 0); trainTv.setTextSize(20); trainTv.setGravity(3); // set left gravity trainTv.setText("to " + BART.REVERSE_STATION_MAP .get(((leg) thisRoute.legs.get(y)).trainHeadStation.toLowerCase())); } else { // For first route leg, display "Take [train name]" row trainTv.setText("take " + BART.REVERSE_STATION_MAP.get(((leg) thisRoute.legs.get(y)).trainHeadStation)); } legLayout.addView(trainTv); } if (thisRoute.legs.size() == 1) { legLayout.setPadding(0, 10, 0, 0); // Address detination train and ETA not aligning } tr.addView(legLayout); // Prepare ETA TextView TextView arrivalTimeTv = (TextView) View.inflate(c, R.layout.tabletext, null); arrivalTimeTv.setPadding(10, 0, 0, 0); //Log.v("DEPART_DATE",thisRoute.departureDate.toString()); // Don't report a train that may JUST be leaving with a negative ETA long eta; if (thisRoute.departureDate.getTime() - now <= 0) { eta = 0; } else { eta = thisRoute.departureDate.getTime() - now; } if (eta > maxTimer) { maxTimer = eta; } // Set timeTv Tag to departure date for interpretation by ViewCountDownTimer arrivalTimeTv.setTag(thisRoute.departureDate.getTime()); // Print arrival as time, not eta if greater than BART.ETA_THRESHOLD_MS if (thisRoute.departureDate.getTime() - now > BART.ETA_IN_MINUTES_THRESHOLD_MS) { SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); arrivalTimeTv.setText(sdf.format(thisRoute.departureDate)); arrivalTimeTv.setTextSize(20); } // Display ETA as minutes until arrival else { arrivalTimeTv.setTextSize(36); // Display eta less than 1m as "<1" if (eta < 60 * 1000) arrivalTimeTv.setText("<1"); // TODO - remove this? Does countdown tick on start else arrivalTimeTv.setText(String.valueOf(eta / (1000 * 60))); // TODO - remove this? Does countdown tick on start // Add the timerView to the list of views to be passed to the ViewCountDownTimer timerViews.add(arrivalTimeTv); } //new ViewCountDownTimer(arrivalTimeTv, eta, 60*1000).start(); tr.addView(arrivalTimeTv); // Set the Row View (containing train names and times) Tag to the route it represents tr.setTag(thisRoute); tableLayout.addView(tr); tr.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { Log.d("RouteViewTag", ((route) arg0.getTag()).toString()); usherRoute = (route) arg0.getTag(); TextView guidanceTv = (TextView) View.inflate(c, R.layout.tabletext, null); guidanceTv.setText(Html.fromHtml(getString(R.string.service_prompt))); guidanceTv.setTextSize(18); guidanceTv.setPadding(0, 0, 0, 0); new AlertDialog.Builder(c).setTitle("Route Guidance").setIcon(R.drawable.ic_launcher) .setView(guidanceTv).setPositiveButton(R.string.service_start_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(c, UsherService.class); //i.putExtra("departure", ((leg)usherRoute.legs.get(0)).boardStation); //Log.v("SERVICE","Starting"); if (usherServiceIsRunning()) { stopService(i); } startService(i); } }) .setNeutralButton("Cancel", null).show(); return true; // consumed the long click } }); tr.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { int index = tableLayout.indexOfChild(arg0); // index of clicked view. Expanded view will always be +1 route thisRoute = (route) arg0.getTag(); if (!thisRoute.isExpanded) { // if route not expanded thisRoute.isExpanded = true; LinearLayout routeDetail = (LinearLayout) View.inflate(c, R.layout.routedetail, null); TextView arrivalTv = (TextView) View.inflate(c, R.layout.tabletext, null); SimpleDateFormat curFormater = new SimpleDateFormat("h:mm a"); //arrivalTv.setTextColor(0xFFC9C7C8); arrivalTv.setText("arrives " + curFormater.format(thisRoute.arrivalDate)); arrivalTv.setTextSize(20); routeDetail.addView(arrivalTv); ImageView bikeIv = (ImageView) View.inflate(c, R.layout.bikeimage, null); if (!thisRoute.bikes) { bikeIv.setImageResource(R.drawable.no_bicycle); } routeDetail.addView(bikeIv); tableLayout.addView(routeDetail, index + 1); } else { thisRoute.isExpanded = false; tableLayout.removeViewAt(index + 1); } } }); } // end route iteration } // end expiredResponse check // expiredResponse == True // If a late-night routeResponse includes the next morning's routes, they will be // presented with HH:MM ETAs, instead of minutes // Else if a late-night routeResponse includes routes from earlier in the evening // We will display "This route has stopped for tonight" else { String message = "This route has stopped for tonight"; TextView specialScheduleTextView = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTextView.setText(message); specialScheduleTextView.setPadding(0, 0, 0, 0); tableLayout.addView(specialScheduleTextView); } if (routeResponse.specialSchedule != null) { ImageView specialSchedule = (ImageView) View.inflate(c, R.layout.specialschedulelayout, null); specialSchedule.setTag(routeResponse.specialSchedule); specialSchedule.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { TextView specialScheduleTv = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTv.setPadding(0, 0, 0, 0); specialScheduleTv.setText(Html.fromHtml(arg0.getTag().toString())); specialScheduleTv.setTextSize(16); specialScheduleTv.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(c).setTitle("Route Alerts").setIcon(R.drawable.warning) .setView(specialScheduleTv).setPositiveButton("Okay!", null).show(); } }); tableLayout.addView(specialSchedule); } // Don't set timer if response is expired if (!expiredResponse) { timer = new ViewCountDownTimer(timerViews, "route", maxTimer, 30 * 1000); timer.start(); } } catch (Throwable t) { Log.d("displayRouteResponseError", t.getStackTrace().toString()); } }
From source file:com.eutectoid.dosomething.picker.GraphObjectAdapter.java
private void downloadProfilePicture(final String profileId, Uri pictureUri, final ImageView imageView) { if (pictureUri == null) { return;//w w w. j av a2 s . c o m } // If we don't have an imageView, we are pre-fetching this image to store in-memory because we // think the user might scroll to its corresponding list row. If we do have an imageView, we // only want to queue a download if the view's tag isn't already set to the URL (which would mean // it's already got the correct picture). boolean prefetching = imageView == null; if (prefetching || !pictureUri.equals(imageView.getTag())) { if (!prefetching) { // Setting the tag to the profile ID indicates that we're currently downloading the // picture for this profile; we'll set it to the actual picture URL when complete. imageView.setTag(profileId); imageView.setImageResource(getDefaultPicture()); } ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureUri) .setCallerTag(this).setCallback(new ImageRequest.Callback() { @Override public void onCompleted(ImageResponse response) { processImageResponse(response, profileId, imageView); } }); ImageRequest newRequest = builder.build(); pendingRequests.put(profileId, newRequest); ImageDownloader.downloadAsync(newRequest); } }
From source file:com.trk.aboutme.facebook.widget.GraphObjectAdapter.java
private void downloadProfilePicture(final String profileId, URL pictureURL, final ImageView imageView) { if (pictureURL == null) { return;// w w w . ja v a2s .c om } // If we don't have an imageView, we are pre-fetching this image to store in-memory because we // think the user might scroll to its corresponding list row. If we do have an imageView, we // only want to queue a download if the view's tag isn't already set to the URL (which would mean // it's already got the correct picture). boolean prefetching = imageView == null; if (prefetching || !pictureURL.equals(imageView.getTag())) { if (!prefetching) { // Setting the tag to the profile ID indicates that we're currently downloading the // picture for this profile; we'll set it to the actual picture URL when complete. imageView.setTag(profileId); imageView.setImageResource(getDefaultPicture()); } ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureURL) .setCallerTag(this).setCallback(new ImageRequest.Callback() { @Override public void onCompleted(ImageResponse response) { processImageResponse(response, profileId, imageView); } }); ImageRequest newRequest = builder.build(); pendingRequests.put(profileId, newRequest); ImageDownloader.downloadAsync(newRequest); } }
From source file:com.facebook.widget.GraphObjectAdapter.java
private void downloadProfilePicture(final String profileId, URI pictureURI, final ImageView imageView) { if (pictureURI == null) { return;/*from w ww . ja va 2 s . c o m*/ } // If we don't have an imageView, we are pre-fetching this image to store in-memory because we // think the user might scroll to its corresponding list row. If we do have an imageView, we // only want to queue a download if the view's tag isn't already set to the URL (which would mean // it's already got the correct picture). boolean prefetching = imageView == null; if (prefetching || !pictureURI.equals(imageView.getTag())) { if (!prefetching) { // Setting the tag to the profile ID indicates that we're currently downloading the // picture for this profile; we'll set it to the actual picture URL when complete. imageView.setTag(profileId); imageView.setImageResource(getDefaultPicture()); } ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureURI) .setCallerTag(this).setCallback(new ImageRequest.Callback() { @Override public void onCompleted(ImageResponse response) { processImageResponse(response, profileId, imageView); } }); ImageRequest newRequest = builder.build(); pendingRequests.put(profileId, newRequest); ImageDownloader.downloadAsync(newRequest); } }
From source file:org.xbmc.kore.ui.sections.audio.AlbumDetailsFragment.java
/** * Display the songs/*from w w w . ja v a 2 s. co m*/ * * @param cursor Cursor with the data */ private void displaySongsList(Cursor cursor) { if (cursor.moveToFirst()) { songInfoList = new ArrayList<>(cursor.getCount()); do { View songView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_song, songListView, false); TextView songTitle = (TextView) songView.findViewById(R.id.song_title); TextView trackNumber = (TextView) songView.findViewById(R.id.track_number); TextView details = (TextView) songView.findViewById(R.id.details); ImageView contextMenu = (ImageView) songView.findViewById(R.id.list_context_menu); String artist = cursor.getString(AlbumSongsListQuery.ARTIST); // Add this song to the list FileDownloadHelper.SongInfo songInfo = new FileDownloadHelper.SongInfo(artist, albumTitle, cursor.getInt(AlbumSongsListQuery.SONGID), cursor.getInt(AlbumSongsListQuery.TRACK), cursor.getString(AlbumSongsListQuery.TITLE), cursor.getString(AlbumSongsListQuery.FILE)); songInfoList.add(songInfo); songTitle.setText(songInfo.title); trackNumber.setText(String.valueOf(songInfo.track)); String duration = UIUtils.formatTime(cursor.getInt(AlbumSongsListQuery.DURATION)); String detailsText = TextUtils.isEmpty(artist) ? duration : duration + " | " + artist; details.setText(detailsText); contextMenu.setTag(songInfo); contextMenu.setOnClickListener(songItemMenuClickListener); songView.setTag(songInfo); songView.setOnClickListener(songClickListener); songListView.addView(songView); } while (cursor.moveToNext()); if (!songInfoList.isEmpty()) { // Check if download dir exists FileDownloadHelper.SongInfo songInfo = new FileDownloadHelper.SongInfo(albumDisplayArtist, albumTitle, 0, 0, null, null); if (songInfo.downloadDirectoryExists()) { Resources.Theme theme = getActivity().getTheme(); TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.colorAccent }); downloadButton.setColorFilter(styledAttributes.getColor(0, getActivity().getResources().getColor(R.color.accent_default))); styledAttributes.recycle(); } else { downloadButton.clearColorFilter(); } } } }