Example usage for android.widget ImageView setImageDrawable

List of usage examples for android.widget ImageView setImageDrawable

Introduction

In this page you can find the example usage for android.widget ImageView setImageDrawable.

Prototype

public void setImageDrawable(@Nullable Drawable drawable) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java

private void addPeopleSession(Member membre) {
    //On recupere aussi la liste des sessions de l'utilisateur
    List<Talk> conferences = ConferenceFacade.getInstance().getSessionMembre(membre, getActivity());

    //On vide les lments
    sessionLayout.removeAllViews();/*from  w  ww.  j a v a2 s .  co m*/

    //On affiche les liens que si on a recuperer des choses
    if (conferences != null && !conferences.isEmpty()) {
        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {

            for (final Talk conf : conferences) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_talk, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView horaire = (TextView) row.findViewById(R.id.talk_horaire);
                TextView talkImageText = (TextView) row.findViewById(R.id.talkImageText);
                TextView talkSalle = (TextView) row.findViewById(R.id.talk_salle);
                ImageView imageFavorite = (ImageView) row.findViewById(R.id.talk_image_favorite);
                ImageView langImage = (ImageView) row.findViewById(R.id.talk_image_language);

                ((TextView) row.findViewById(R.id.talk_name)).setText(conf.getTitle());
                ((TextView) row.findViewById(R.id.talk_shortdesciptif)).setText(conf.getSummary().trim());

                SimpleDateFormat sdf = new SimpleDateFormat("EEE");
                if (conf.getStart() != null && conf.getEnd() != null) {
                    horaire.setText(String.format(getResources().getString(R.string.periode),
                            sdf.format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getEnd())));
                } else {
                    horaire.setText(getResources().getString(R.string.pasdate));

                }
                if (conf.getLang() != null && "ENGLISH".equals(conf.getLang())) {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.en));
                } else {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.fr));
                }
                Salle salle = Salle.INCONNU;
                if (conf instanceof Talk && Salle.INCONNU != Salle.getSalle(conf.getRoom())) {
                    salle = Salle.getSalle(conf.getRoom());
                }
                talkSalle.setText(String.format(getResources().getString(R.string.Salle), salle.getNom()));
                talkSalle.setBackgroundColor(getResources().getColor(salle.getColor()));

                if (conf instanceof Talk) {
                    if ("Workshop".equals(((Talk) conf).getFormat())) {
                        talkImageText.setText("Atelier");
                    } else {
                        talkImageText.setText("Talk");
                    }
                } else {
                    talkImageText.setText("L.Talk");
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TypeFile typeFile;
                        int page = 6;
                        if (conf instanceof Talk) {
                            if ("Workshop".equals(((Talk) conf).getFormat())) {
                                typeFile = TypeFile.workshops;
                                page = 4;
                            } else {
                                typeFile = TypeFile.talks;
                                page = 3;
                            }
                        } else {
                            typeFile = TypeFile.lightningtalks;
                        }
                        ((HomeActivity) getActivity()).changeCurrentFragment(SessionDetailFragment.newInstance(
                                typeFile.toString(), conf.getIdSession(), page), typeFile.toString());
                    }
                });

                //On regarde si la conf fait partie des favoris
                SharedPreferences settings = getActivity().getSharedPreferences(UIUtils.PREFS_FAVORITES_NAME,
                        0);
                boolean trouve = false;
                for (String key : settings.getAll().keySet()) {
                    if (key.equals(String.valueOf(conf.getIdSession()))) {
                        trouve = true;
                        imageFavorite.setImageDrawable(
                                getActivity().getResources().getDrawable(R.drawable.ic_action_important));
                        break;
                    }
                }
                if (!trouve) {
                    imageFavorite.setImageDrawable(
                            getActivity().getResources().getDrawable(R.drawable.ic_action_not_important));
                }
                tableLayout.addView(row);
            }
        }
        sessionLayout.addView(tableLayout);
    } else {
        titleSessions.getLayoutParams().height = 0;
    }
}

From source file:com.dreamspace.superman.UI.View.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from  w w  w  .  jav  a 2 s  . c  o  m*/
        TextView tabTitleView = null;
        ImageView tabIconView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        } else if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (tabTitleView != null)
            tabTitleView.setText(adapter.getPageTitle(i));
        else if (tabIconView != null)
            tabIconView.setImageDrawable(mIconAdapter.getIcon(i));

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }

    mTabStripPopulated = true;
}

From source file:com.waveface.installer.util.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   ww  w  . j av  a2 s  .  c  o m*/
private void forceDownload(String url, ImageView imageView, int resId) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    BitmapDrawable draw = (BitmapDrawable) mContext.getResources().getDrawable(resId);
    Bitmap bm = draw.getBitmap();
    if (url == null) {
        imageView.setImageBitmap(bm);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            addBitmapToCache(url, bitmap);
            imageView.setImageBitmap(bitmap);
            break;

        case NO_DOWNLOADED_DRAWABLE:
            imageView.setMinimumHeight(156);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

        case CORRECT:
            task = new BitmapDownloaderTask(imageView);

            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task, bm);
            imageView.setImageDrawable(downloadedDrawable);
            task.execute(url);
            break;
        }
    }
}

From source file:com.spydiko.rotationmanager.MainActivity.java

@Override
public void onClick(View view) {
    //        Button temp = (Button) view;
    ImageView tmp;
    vibe.vibrate(50);// Vibrate it's time you click something...
    switch (view.getId()) {
    case (R.id.button2):// Clear all button
        for (Model mdl : activities) {
            mdl.setSelectedPortrait(false);
            mdl.setSelectedLandscape(false);
            myapp.savePreferences(mdl.getPackageName(), false, true);
            myapp.savePreferences(mdl.getPackageName(), false, false);
        }/*from   ww w . j a v  a  2s.com*/
        lv.setAdapter(adapter);
        break;
    case (R.id.orientationButton):// Auto-Rotation button
        tmp = (ImageView) findViewById(view.getId());
        //******************
        //-----4state-------
        int state = AppSpecificOrientation.getCheck_button();
        state = (state + 1) % 5;
        switch (state) {
        case 0:
            tmp.setImageDrawable(getResources().getDrawable(R.drawable.auto_rotate_on));
            autoRotate.setTextColor(Color.GREEN);
            autoRotate.setText(getResources().getText(R.string.orientationOn));
            AppSpecificOrientation.setCheck_button(0);
            Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
            break;
        case 1:
            tmp.setImageDrawable(getResources().getDrawable(R.drawable.auto_rotate_off));
            autoRotate.setTextColor(Color.RED);
            autoRotate.setText(getResources().getText(R.string.orientationOff));
            AppSpecificOrientation.setCheck_button(1);
            Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
            break;
        case 2:
            tmp.setImageDrawable(getResources().getDrawable(R.drawable.forced_portrait));
            autoRotate.setTextColor(Color.CYAN);
            autoRotate.setText(getResources().getText(R.string.forced_portrait));
            AppSpecificOrientation.setCheck_button(2);
            break;
        case 3:
            tmp.setImageDrawable(getResources().getDrawable(R.drawable.forced_landscape));
            autoRotate.setTextColor(Color.CYAN);
            autoRotate.setText(getResources().getText(R.string.forced_landscape));
            AppSpecificOrientation.setCheck_button(3);
            break;
        case 4:
            tmp.setImageDrawable(getResources().getDrawable(R.drawable.forced_auto));
            autoRotate.setTextColor(Color.parseColor("#FFFFFF"));
            autoRotate.setText(getResources().getText(R.string.forced_auto));
            AppSpecificOrientation.setCheck_button(4);
            break;
        default:
            break;
        }
        break;
    }
}

From source file:com.example.khaalijeb.newlistview_module.SlidingTabLayout.java

private void populateTabStrip() {
    final MainPagerAdapter adapter = (MainPagerAdapter) mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from w w  w.java2s  .co m
        TextView tabTitleView = null;
        ImageView tabIconView = null;
        /*  if (mTabViewLayoutId != 0 ) {
        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
                false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
                
              tabIconView = (ImageView) tabView.findViewById(mTabViewImageViewId);
                
                
                    }
                
                    if (tabView == null) {
        tabView = createDefaultTabView(getContext());
                    }
                
                    if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        tabTitleView = (TextView) tabView;
                    }*/

        if (tabView == null) {
            tabView = createDefaultImageView(getContext());
        }

        if (tabIconView == null && ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
            tabIconView.setImageDrawable(getResources().getDrawable(adapter.getDrawable(i)));
        }

        if (mViewPager.getCurrentItem() == i) {
            tabIconView.setSelected(true);
        }
        /*       if (mDistributeEvenly) {
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
        lp.width = 0;
        lp.weight = 1;
               }
                
        */

        //  tabTitleView.setText(adapter.getPageTitle(i));

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private View getView(List<AppEntry> list, int position) {
    View convertView = View.inflate(this, R.layout.icon, null);

    final AppEntry entry = list.get(position);
    final SharedPreferences pref = U.getSharedPreferences(this);

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    ImageView imageView2 = (ImageView) convertView.findViewById(R.id.shortcut_icon);
    imageView.setImageDrawable(entry.getIcon(this));
    imageView2.setBackgroundColor(/* ww  w .  j  av  a2  s.  c o  m*/
            pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));

    String taskbarPosition = U.getTaskbarPosition(this);
    if (pref.getBoolean("shortcut_icon", true)) {
        boolean shouldShowShortcutIcon;
        if (taskbarPosition.contains("vertical"))
            shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
        else
            shouldShowShortcutIcon = position < numOfPinnedApps;

        if (shouldShowShortcutIcon)
            imageView2.setVisibility(View.VISIBLE);
    }

    if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
        imageView.setRotationY(180);
        imageView2.setRotationY(180);
    }

    FrameLayout layout = (FrameLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(),
            entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int accentColor = U.getAccentColor(TaskbarService.this);
                accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
                v.setBackgroundColor(accentColor);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}

From source file:com.abcs.sociax.gimgutil.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.
 * //www  .j av  a2  s.com
 * @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, String type) {

    if (SociaxUIUtils.getNetworkType(mContext) == ConnectivityManager.TYPE_MOBILE) {

        System.out.println("is download image setting " + SettingsActivity.isDownloadPic(mContext));

        if (!SettingsActivity.isDownloadPic(mContext)) {
            System.out.println("is download image setting " + SettingsActivity.isDownloadPic(mContext));
            return;
        }
    }

    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);
    } 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.haipeng.libraryforandroid.cacheormemory.imageload.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.
 * /*w  ww  .ja  v  a  2s  . c  o  m*/
 * @param data
 *            The URL of the image to download.
 * @param imageView
 *            The ImageView to bind the downloaded image to.
 * @param loadImgViaMobile 
 *             ?true
 */
public void loadImage(Object data, ImageView imageView, boolean loadImgViaMobile) {

    if (data == null || TextUtils.isEmpty(data.toString().trim())) {
        if (mLoadingBitmap != null && imageView != null)
            imageView.setImageBitmap(mLoadingBitmap);
        return;
    }

    Bitmap bitmap = null;

    if (mImageCache != null) {
        bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (bitmap != null) {
        // Bitmap found in memory cache
        notifyLoadComplete(String.valueOf(data), bitmap, imageView);
        imageView.setImageBitmap(bitmap);
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView, loadImgViaMobile);
        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.android.tv.settings.dialog.SettingsLayoutFragment.java

private void initializeContentView(View content) {
    TextView titleView = (TextView) content.findViewById(R.id.title);
    TextView breadcrumbView = (TextView) content.findViewById(R.id.breadcrumb);
    TextView descriptionView = (TextView) content.findViewById(R.id.description);
    titleView.setText(mTitle);/*from  w w  w  .  ja v  a  2 s .  c  o m*/
    breadcrumbView.setText(mBreadcrumb);
    descriptionView.setText(mDescription);
    final ImageView iconImageView = (ImageView) content.findViewById(R.id.icon);
    iconImageView.setBackgroundColor(mIconBackgroundColor);

    // Force text fields to be focusable when accessibility is enabled.
    if (AccessibilityHelper.forceFocusableViews(getActivity())) {
        titleView.setFocusable(true);
        titleView.setFocusableInTouchMode(true);
        descriptionView.setFocusable(true);
        descriptionView.setFocusableInTouchMode(true);
        breadcrumbView.setFocusable(true);
        breadcrumbView.setFocusableInTouchMode(true);
    }

    if (mIcon != null) {
        iconImageView.setImageDrawable(mIcon);
        updateViewSize(iconImageView);
    } else if (mIconBitmap != null) {
        iconImageView.setImageBitmap(mIconBitmap);
        updateViewSize(iconImageView);
    } else if (mIconUri != null) {
        iconImageView.setVisibility(View.INVISIBLE);
        /*
                
        BitmapDownloader bitmapDownloader = BitmapDownloader.getInstance(
            content.getContext());
        mBitmapCallBack = new BitmapCallback() {
        @Override
        public void onBitmapRetrieved(Bitmap bitmap) {
            if (bitmap != null) {
                mIconBitmap = bitmap;
                iconImageView.setVisibility(View.VISIBLE);
                iconImageView.setImageBitmap(bitmap);
                updateViewSize(iconImageView);
            }
        }
        };
                
        bitmapDownloader.getBitmap(new BitmapWorkerOptions.Builder(
            content.getContext()).resource(mIconUri)
            .width(iconImageView.getLayoutParams().width).build(),
            mBitmapCallBack);
        */
    } else {
        iconImageView.setVisibility(View.GONE);
    }

    content.setTag(R.id.title, titleView);
    content.setTag(R.id.breadcrumb, breadcrumbView);
    content.setTag(R.id.description, descriptionView);
    content.setTag(R.id.icon, iconImageView);
}

From source file:com.android.volley.cache.plus.SimpleImageLoader.java

public ImageContainer set(String requestUrl, ImageView imageView, Drawable placeHolder, int maxWidth,
        int maxHeight, Bitmap bitmap) {

    // Find any old image load request pending on this ImageView (in case this view was
    // recycled)//from ww w.j  av  a 2  s  .  c  om
    ImageContainer imageContainer = imageView.getTag() != null && imageView.getTag() instanceof ImageContainer
            ? (ImageContainer) imageView.getTag()
            : null;

    // Find image url from prior request
    //String recycledImageUrl = imageContainer != null ? imageContainer.getRequestUrl() : null;

    if (imageContainer != null) {
        // Cancel previous image request
        imageContainer.cancelRequest();
        imageView.setTag(null);
    }
    if (requestUrl != null) {
        // Queue new request to fetch image
        imageContainer = set(requestUrl, getImageListener(getResources(), imageView, placeHolder, mFadeInImage),
                maxWidth, maxHeight, bitmap);
        // Store request in ImageView tag
        imageView.setTag(imageContainer);
    } else {
        if (!(imageView instanceof PhotoView)) {
            imageView.setImageDrawable(placeHolder);
        }
        imageView.setTag(null);
    }

    return imageContainer;
}