List of usage examples for android.widget ImageView setImageDrawable
public void setImageDrawable(@Nullable Drawable drawable)
From source file:com.github.programmerr47.vkgroups.imageloading.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//www. j ava2s. c o m */ private void setImageDrawable(ImageView imageView, BitmapDrawable drawable, LoadBitmapParams loadingParams) { Drawable finalDrawable = postProcessDrawable(drawable, loadingParams); if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(imageView.getResources().getColor(android.R.color.transparent)), finalDrawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(finalDrawable); } }
From source file:com.android.aft.AFCoreTools.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the * provided ImageView. The binding is immediate if the image is found in the * cache and will be done asynchronously otherwise. A null bitmap will be * associated to the ImageView if an error occurs. * * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */// w ww . j av a2s . co m public void download(String url, ImageView imageView, ImageDownloaderListener listener, Animation animation, int reqWidth, int reqHeight) { if (url != null) { resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url, reqWidth, reqHeight); if (bitmap == null) { forceDownload(url, imageView, reqWidth, reqHeight, listener, animation); } else { cancelPotentialDownload(url, imageView); // imageView.setBackgroundDrawable(null); imageView.setImageDrawable(null); // imageView.setScaleType(ScaleType.FIT_XY); imageView.setImageBitmap(bitmap); if (animation != null) { imageView.setAnimation(animation); } if (listener != null) { listener.onImageDownloaded(url, bitmap, imageView); } } } }
From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java
private void setupFloatingSearch() { mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override//from ww w . j a v a 2s . co m public void onHomeClicked() { } }); mSearchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, final String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { mSearchView.clearSuggestions(); } else { //this shows the top left circular progress //you can call it where ever you want, but //it makes sense to do it when loading something in //the background. mSearchView.showProgress(); //simulates a query call to a data source //with a new query. NumberDataHelper.findSuggestions(getApplicationContext(), newQuery, 5, FIND_SUGGESTION_SIMULATED_DELAY, new NumberDataHelper.OnFindSuggestionsListener() { @Override public void onResults(List<NumberSuggestion> results) { //this will swap the data and //render the collapse/expand animations as necessary mSearchView.swapSuggestions(results); //let the users know that the background //process has completed mSearchView.hideProgress(); } }); } Log.d(TAG, "onSearchTextChanged()"); } }); mSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(final SearchSuggestion searchSuggestion) { NumberSuggestion numberSuggestion = (NumberSuggestion) searchSuggestion; NumberDataHelper.findNumbers(getApplicationContext(), numberSuggestion.getWord(), new NumberDataHelper.OnFindNumberListener() { @Override public void onResults(List<NumberWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSuggestionClicked()"); mLastQuery = searchSuggestion.getWord(); } @Override public void onSearchAction(String query) { mLastQuery = query; NumberDataHelper.findNumbers(getApplicationContext(), query, new NumberDataHelper.OnFindNumberListener() { @Override public void onResults(List<NumberWrapper> results) { mSearchResultsAdapter.swapData(results); } }); Log.d(TAG, "onSearchAction()"); } }); mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override public void onFocus() { //show suggestions when search bar gains focus (typically history suggestions) // NumberDataHelper cdh = new NumberDataHelper(); // cdh.setContext(getApplicationContext()); mSearchView.swapSuggestions(NumberDataHelper.getHistory(getApplicationContext(), 5)); Log.d(TAG, "onFocus()"); } @Override public void onFocusCleared() { //set the title of the bar so that when focus is returned a new query begins mSearchView.setSearchBarTitle(mLastQuery); //you can also set setSearchText(...) to make keep the query there when not focused and when focus returns //mSearchView.setSearchText(searchSuggestion.getWord()); Log.d(TAG, "onFocusCleared()"); } }); //handle menu clicks the same way as you would //in a regular activity mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() { @Override public void onActionMenuItemSelected(MenuItem item) { if (item.getItemId() == R.id.action_refresh_list) { /*mIsDarkSearchTheme = true; //demonstrate setting colors for items mSearchView.setBackgroundColor(Color.parseColor("#787878")); mSearchView.setViewTextColor(Color.parseColor("#e9e9e9")); mSearchView.setHintTextColor(Color.parseColor("#e9e9e9")); mSearchView.setActionMenuOverflowColor(Color.parseColor("#e9e9e9")); mSearchView.setMenuItemIconColor(Color.parseColor("#e9e9e9")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9")); mSearchView.setClearBtnColor(Color.parseColor("#e9e9e9")); mSearchView.setDividerColor(Color.parseColor("#BEBEBE")); mSearchView.setLeftActionIconColor(Color.parseColor("#e9e9e9"));*/ populateCardList(); } else if (item.getItemId() == R.id.action_voice_rec) { Intent voiceRecognize = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); voiceRecognize.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voiceRecognize.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ar-EG"); voiceRecognize.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say the letter in ARABIC..."); /*voiceRecognize.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); */ voiceRecognize.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 100); startActivityForResult(voiceRecognize, REQUEST_CODE); } else { //just print action //Toast.makeText(getApplicationContext().getApplicationContext(), item.getTitle(), // Toast.LENGTH_SHORT).show(); } } }); //use this listener to listen to menu clicks when app:floatingSearch_leftAction="showHome" mSearchView.setOnHomeActionClickListener(new FloatingSearchView.OnHomeActionClickListener() { @Override public void onHomeClicked() { startActivity(new Intent(NumberViewActivity.this, MainActivity.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left); Log.d(TAG, "onHomeClicked()"); } }); /* * Here you have access to the left icon and the text of a given suggestion * item after as it is bound to the suggestion list. You can utilize this * callback to change some properties of the left icon and the text. For example, you * can load the left icon images using your favorite image loading library, or change text color. * * * Important: * Keep in mind that the suggestion list is a RecyclerView, so views are reused for different * items in the list. */ mSearchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { NumberSuggestion numberSuggestion = (NumberSuggestion) item; String textColor = mIsDarkSearchTheme ? "#ffffff" : "#000000"; String textLight = mIsDarkSearchTheme ? "#bfbfbf" : "#787878"; if (numberSuggestion.getIsHistory()) { leftIcon.setImageDrawable( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_history_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); } else { leftIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_lightbulb_outline_black_24dp, null)); Util.setIconColor(leftIcon, Color.parseColor(textColor)); leftIcon.setAlpha(.36f); /*leftIcon.setAlpha(0.0f); leftIcon.setImageDrawable(null);*/ } textView.setTextColor(Color.parseColor(textColor)); String text = numberSuggestion.getWord().replaceFirst(mSearchView.getQuery(), "<font color=\"" + textLight + "\">" + mSearchView.getQuery() + "</font>"); textView.setText(Html.fromHtml(text)); } }); //listen for when suggestion list expands/shrinks in order to move down/up the //search results list mSearchView.setOnSuggestionsListHeightChanged(new FloatingSearchView.OnSuggestionsListHeightChanged() { @Override public void onSuggestionsListHeightChanged(float newHeight) { mSearchResultsList.setTranslationY(newHeight); } }); }
From source file:com.facebook.android.friendsmash.ScoreboardFragment.java
private void populateScoreboard() { // Ensure all components are firstly removed from scoreboardContainer scoreboardContainer.removeAllViews(); // Ensure the progress spinner is hidden progressContainer.setVisibility(View.INVISIBLE); // Ensure scoreboardEntriesList is not null and not empty first if (application.getScoreboardEntriesList() == null || application.getScoreboardEntriesList().size() <= 0) { closeAndShowError(getResources().getString(R.string.error_no_scores)); } else {// ww w . j a va 2s.com // Iterate through scoreboardEntriesList, creating new UI elements for each entry int index = 0; Iterator<ScoreboardEntry> scoreboardEntriesIterator = application.getScoreboardEntriesList().iterator(); while (scoreboardEntriesIterator.hasNext()) { // Get the current scoreboard entry final ScoreboardEntry currentScoreboardEntry = scoreboardEntriesIterator.next(); // FrameLayout Container for the currentScoreboardEntry ... // Create and add a new FrameLayout to display the details of this entry FrameLayout frameLayout = new FrameLayout(getActivity()); scoreboardContainer.addView(frameLayout); // Set the attributes for this frameLayout int topPadding = getResources().getDimensionPixelSize(R.dimen.scoreboard_entry_top_margin); frameLayout.setPadding(0, topPadding, 0, 0); // ImageView background image ... { // Create and add an ImageView for the background image to this entry ImageView backgroundImageView = new ImageView(getActivity()); frameLayout.addView(backgroundImageView); // Set the image of the backgroundImageView String uri = "drawable/scores_stub_even"; if (index % 2 != 0) { // Odd entry uri = "drawable/scores_stub_odd"; } int imageResource = getResources().getIdentifier(uri, null, getActivity().getPackageName()); Drawable image = getResources().getDrawable(imageResource); backgroundImageView.setImageDrawable(image); // Other attributes of backgroundImageView to modify FrameLayout.LayoutParams backgroundImageViewLayoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); int backgroundImageViewMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_background_imageview_margin_top); backgroundImageViewLayoutParams.setMargins(0, backgroundImageViewMarginTop, 0, 0); backgroundImageViewLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry backgroundImageViewLayoutParams.gravity = Gravity.RIGHT; } backgroundImageView.setLayoutParams(backgroundImageViewLayoutParams); } // ProfilePictureView of the current user ... { // Create and add a ProfilePictureView for the current user entry's profile picture ProfilePictureView profilePictureView = new ProfilePictureView(getActivity()); frameLayout.addView(profilePictureView); // Set the attributes of the profilePictureView int profilePictureViewWidth = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_width); FrameLayout.LayoutParams profilePictureViewLayoutParams = new FrameLayout.LayoutParams( profilePictureViewWidth, profilePictureViewWidth); int profilePictureViewMarginLeft = 0; int profilePictureViewMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_top); int profilePictureViewMarginRight = 0; int profilePictureViewMarginBottom = 0; if (index % 2 == 0) { profilePictureViewMarginLeft = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_left); } else { profilePictureViewMarginRight = getResources() .getDimensionPixelSize(R.dimen.scoreboard_profile_picture_view_margin_right); } profilePictureViewLayoutParams.setMargins(profilePictureViewMarginLeft, profilePictureViewMarginTop, profilePictureViewMarginRight, profilePictureViewMarginBottom); profilePictureViewLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry profilePictureViewLayoutParams.gravity = Gravity.RIGHT; } profilePictureView.setLayoutParams(profilePictureViewLayoutParams); // Finally set the id of the user to show their profile pic profilePictureView.setProfileId(currentScoreboardEntry.getId()); } // LinearLayout to hold the text in this entry // Create and add a LinearLayout to hold the TextViews LinearLayout textViewsLinearLayout = new LinearLayout(getActivity()); frameLayout.addView(textViewsLinearLayout); // Set the attributes for this textViewsLinearLayout FrameLayout.LayoutParams textViewsLinearLayoutLayoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); int textViewsLinearLayoutMarginLeft = 0; int textViewsLinearLayoutMarginTop = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_top); int textViewsLinearLayoutMarginRight = 0; int textViewsLinearLayoutMarginBottom = 0; if (index % 2 == 0) { textViewsLinearLayoutMarginLeft = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_left); } else { textViewsLinearLayoutMarginRight = getResources() .getDimensionPixelSize(R.dimen.scoreboard_textviews_linearlayout_margin_right); } textViewsLinearLayoutLayoutParams.setMargins(textViewsLinearLayoutMarginLeft, textViewsLinearLayoutMarginTop, textViewsLinearLayoutMarginRight, textViewsLinearLayoutMarginBottom); textViewsLinearLayoutLayoutParams.gravity = Gravity.LEFT; if (index % 2 != 0) { // Odd entry textViewsLinearLayoutLayoutParams.gravity = Gravity.RIGHT; } textViewsLinearLayout.setLayoutParams(textViewsLinearLayoutLayoutParams); textViewsLinearLayout.setOrientation(LinearLayout.VERTICAL); // TextView with the position and name of the current user { // Set the text that should go in this TextView first int position = index + 1; String currentScoreboardEntryTitle = position + ". " + currentScoreboardEntry.getName(); // Create and add a TextView for the current user position and first name TextView titleTextView = new TextView(getActivity()); textViewsLinearLayout.addView(titleTextView); // Set the text and other attributes for this TextView titleTextView.setText(currentScoreboardEntryTitle); titleTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerNameFont); } // TextView with the score of the current user { // Create and add a TextView for the current user score TextView scoreTextView = new TextView(getActivity()); textViewsLinearLayout.addView(scoreTextView); // Set the text and other attributes for this TextView scoreTextView.setText("Score: " + currentScoreboardEntry.getScore()); scoreTextView.setTextAppearance(getActivity(), R.style.ScoreboardPlayerScoreFont); } // Finally make this frameLayout clickable so that a game starts with the user smashing // the user represented by this frameLayout in the scoreContainer frameLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { Bundle bundle = new Bundle(); bundle.putString("user_id", currentScoreboardEntry.getId()); Intent i = new Intent(); i.putExtras(bundle); getActivity().setResult(Activity.RESULT_FIRST_USER, i); getActivity().finish(); return false; } else { return true; } } }); // Increment the index before looping back index++; } } }
From source file:com.example.android.displayingbitmaps.imageloader.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*from w w w.j av a 2 s.co m*/ * * @param imageView * @param drawable */ private void setImageDrawable(final ImageView imageView, final Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { // new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, mLoadingBitmap), drawable }); // Set background to loading bitmap // imageView.setBackgroundDrawable( // new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setBackgroundColor(Color.TRANSPARENT); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); imageView.setBackgroundColor(Color.TRANSPARENT); } }
From source file:com.ccz.viewimages.displayingbitmaps.util.ImageWorker.java
private void setImageDrawable(ImageView imageView, Drawable drawable, Bitmap transbitmap) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(mResources.getColor(android.R.color.transparent)), drawable }); // Set background to loading bitmap if (null != transbitmap) { imageView.setBackgroundDrawable(new BitmapDrawable(mResources, transbitmap)); }/*w ww . j a v a 2 s . c o m*/ imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.alex.develop.cache.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//ww w.j a v a2 s . c o m * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable(new Drawable[] { // Edit by alex // before new ColorDrawable(android.R.color.transparent), // after // new ColorDrawable(Color.parseColor("#00000000")), // end drawable }); // Set background to loading bitmap imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.app.secnodhand.imageutil.ImageWorker.java
public void loadImage(Object data, ImageView imageView, ImageLoadingListener mImageLoadingListener) { if (data == null) { return;// w w w.j a v a2s .c om } if (mImageLoadingListener != null) { this.mImageLoadingListener = mImageLoadingListener; mImageLoadingListener.startLoading(); } Log.d("driverInfo", "data:" + data); BitmapDrawable value = null; if (mImageCache != null) { value = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (value != null) { // Bitmap found in memory cache Log.d("driverInfo", "value:" + value); imageView.setImageDrawable(value); if (mImageLoadingListener != null) { mImageLoadingListener.finishLoading(); } } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); 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, data); } }
From source file:com.airad.zhonghan.ui.components.ImageWorker.java
public void loadImage(Object data, ImageView imageView, ProgressBar progressBar) { if (data == null) { return;/*from w w w . ja v a 2s. c o m*/ } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); if (progressBar != null) { progressBar.setVisibility(View.INVISIBLE); } } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView, progressBar); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); task.execute(data); if (progressBar != null) { progressBar.setVisibility(View.INVISIBLE); } } }
From source file:com.iped.ipcam.bitmapfun.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageWorker#processBitmap(Object)} to define the processing logic). A memory and disk * cache will be used if an {@link ImageCache} has been set using * {@link ImageWorker#setImageCache(ImageCache)}. If the image is found in the memory cache, it * is set immediately, otherwise an {@link AsyncTask} will be created to asynchronously load the * bitmap./*from ww w .j a va2 s . c o m*/ * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */ public void loadImage(Object data, ImageView imageView) { if (data == null) { return; } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache imageView.setImageBitmap(bitmap); if (loadImageListener != null) { loadImageListener.updateResolution(String.valueOf(data), bitmap.getWidth(), bitmap.getHeight()); } } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); 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, data); } }