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.example.mediasync3.DownloadPhoto.java

@Override
protected void onPostExecute(Boolean result) {
    mDialog.dismiss();/*  w  w  w . j a v a2  s .c  o  m*/

    if (pos == -2) {
        Spinner listSpin = (Spinner) rootView.findViewById(R.id.spinner1);
        listSpin.setAdapter(adapterList);
        listSpin.setEnabled(true);
    } else {

        ImageView iv = (ImageView) rootView.findViewById(R.id.image_view);

        fnames = mActivity.getPhotoNames();
        Drawable drawable = Drawable.createFromPath(LOCAL_PHOTO_DIR + "/" + fnames[pos]);
        iv.setImageDrawable(drawable);

        /*
        ListView lv = (ListView)rootView.findViewById(R.id.listView1);
        ArrayList<String> dir=new ArrayList<String>();
                
        //File sdCardRoot = Environment.getExternalStorageDirectory();
        final File PhotoDir = new File(LOCAL_PHOTO_DIR);
        for (File f : PhotoDir.listFiles()) {
           if (f.isFile())
        dir.add(f.getName());
        // Do your stuff
        }
        String[] localnames = dir.toArray(new String[dir.size()]);
                
        ArrayAdapter<String> ad = new ArrayAdapter<String>(mFrag.getActivity(), android.R.layout.simple_list_item_1,localnames);
        lv.setAdapter(ad);  
        */

        //TextView tv = (TextView) rootView.findViewById(R.id.textView1);
        //tv.setText(fnames[pos]);

    }

    if (result) {
        // Set the image now that we have it
        //    mView.setImageDrawable(mDrawable);
    } else {
        // Couldn't download it, so show an error
        //    showToast(mErrorMsg);
    }
}

From source file:com.findme.adapter.ImageListAdapter.java

@Override
public View getView(int position, View view, ViewGroup viewGroup) {

    // We only create the view if its needed
    if (view == null) {
        view = inflator.inflate(R.layout.image_list_child, null);
        // Set the click listener for the checkbox
        // view.findViewById(R.id.isSelectedCheckBox).setOnClickListener(this);
    } else//from ww  w .  ja  v  a  2s. co m
        return view;
    final JSONObject personInfo = (JSONObject) getItem(position);
    String imgUrl = null;
    try {
        imgUrl = prefix + personInfo.getJSONArray("images").getString(0);
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    Log.d("image", imgUrl);
    count++;
    Log.d("Result", String.valueOf(count));
    final ImageButton img = (ImageButton) view.findViewById(R.id.appImageView1);
    URL url;
    Bitmap bmp = null;
    (new DownloadImageTask(img)).execute(imgUrl);

    img.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            AlertDialog.Builder builder = new AlertDialog.Builder(mainAct);
            View view = LayoutInflater.from(mainAct).inflate(R.layout.popup_layout, null);

            ImageView image = (ImageView) view.findViewById(R.id.resultDialogImg);

            /**
             * Not sure about the license of PhotoViewAttacher
             * TODO : look into the license of this and decide whether to use it or not.
             */

            image.setImageDrawable(img.getDrawable());
            PhotoViewAttacher mAttacher = new PhotoViewAttacher(image);
            mAttacher.update();
            //builder.setIcon(mainAct.getResources().getDrawable(mainAct.getResources().getIdentifier(app.getImage(), "drawable", mainAct.getPackageName())));
            builder.setView(view);
            builder.setPositiveButton(R.string.match_found, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    try {
                        (new AsyncHttpPostTask(prefix)).execute(personInfo.getString("personname"));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });

            builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked OK. Start a new game.
                    dialog.dismiss();
                }
            });

            builder.create().show();
        }
    });
    return view;
}

From source file:br.com.ettore.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.
 *//* w w  w  .j a v a 2 s.c o  m*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        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);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:com.test.weatherapp.adapters.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 w  w  w  . j  a va2s.  c  o m
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        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);
            imageView.setImageDrawable(downloadedDrawable);
            //                    imageView.setMinimumHeight(156);
            task.execute(url);
            break;
        }
    }
}

From source file:com.quipmate.loadingBitmaps.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.
 *//* www  .  j  av a  2 s.  c o  m*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        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(minHeight);
            BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
            task.execute(url);
            break;

        case CORRECT:
            task = new BitmapDownloaderTask(imageView);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(minHeight);
            task.execute(url);
            break;
        }
    }
}

From source file:org.everyuse.android.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.
 *//* ww w  . ja v a  2s  . c om*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        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);
                imageView.setImageDrawable(downloadedDrawable);
                imageView.setMinimumHeight(156);
                task.execute(url);
                break;
        }
    }
}

From source file:cn.huaxingtan.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  w ww .  j  a  v a  2s.co m*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        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.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
            break;

        case CORRECT:
            task = new BitmapDownloaderTask(imageView);
            DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
            imageView.setImageDrawable(downloadedDrawable);
            imageView.setMinimumHeight(156);
            task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
            break;
        }
    }
}

From source file:com.android.projectz.teamrocket.thebusapp.adapters.CustomListSettingOther.java

/**
 * adattatore custom per la visualizzazione della lista
 * 1. titolo/*from ww w  . j  a va  2s  .co  m*/
 * 2. sottotitolo
 * 3. immagine
 *
 * @param position
 * @param view
 * @param parent
 * @return
 */
@Override
public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View rowView = inflater.inflate(R.layout.list_setting, null, true);

    TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
    TextView txtSubtitle = (TextView) rowView.findViewById(R.id.subtxt);
    ImageView imageView = (ImageView) rowView.findViewById(R.id.img);

    Drawable colorImg = null;
    if (SharedPreferencesUtils.getSelectedTheme(context).equals("AppTheme")) {
        colorImg = changeColorOfIcons(imageId[position], R.color.iconLight);
    } else {
        colorImg = changeColorOfIcons(imageId[position], R.color.iconDark);
    }

    txtTitle.setText(text[position]);
    txtSubtitle.setText(subtext[position]);
    imageView.setImageDrawable(colorImg);

    return rowView;
}

From source file:com.example.web.image.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  w  w  w .j  av a2 s . c o m*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        return;
    }

    if (cancelPotentialDownload(url, imageView)) {
        switch (mode) {
        case NO_ASYNC_TASK:
            Bitmap bitmap = downloadBitmap(url);
            imageCache.addBitmapToCache(url, bitmap);
            if (this.progressBar != null) {
                this.progressBar.setVisibility(View.GONE);
            }
            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);
            imageView.setImageDrawable(downloadedDrawable);
            //                    imageView.setMinimumHeight(156);
            //                    imageView.setMinimumWidth(156);
            task.execute(url);
            break;
        }
    }
}

From source file:adapters.images.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.
 *//*  ww  w .  j a v  a 2  s.  c om*/
private void forceDownload(String url, ImageView imageView) {
    // State sanity: url is guaranteed to never be null in DownloadedDrawable and cache keys.
    if (url == null) {
        imageView.setImageDrawable(null);
        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; /*
                                           task.execute(url);
                                           break;
                                                   
                                           case CORRECT: */
        new BitmapDownloaderTask(imageView);
        task = new BitmapDownloaderTask(imageView);
        DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
        imageView.setImageDrawable(downloadedDrawable);
        imageView.setMinimumHeight(156);
        task.execute(url);
        //break;
        //}
    }
}