Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:at.zone.madeleine.slideshow.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.
 *//*from  w ww  .j  ava 2  s.c o m*/
public void download(String url, ImageView imageView, NetworkTaskCallback delegate) {

    netwrkErrorDelegate = delegate;

    Bitmap bitmap = getBitmapFromDisc(url);

    if (bitmap == null) {
        doDownload(url, imageView);
        if (mProgressBar != null) {
            mProgressBar.setVisibility(View.VISIBLE);
        }
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        if (mProgressBar != null) {
            mProgressBar.setVisibility(View.INVISIBLE);
        }
    }
}

From source file:org.nasa.openspace.gc.geolocation.LocationActivity.java

/**
 * This sample demonstrates how to incorporate location based services in your app and
 * process location updates.  The app also shows how to convert lat/long coordinates to
 * human-readable addresses.//from w w w.  j  a v a2  s. c  om
 */
//@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.geolocation);

    // Restore apps state (if exists) after rotation.
    if (savedInstanceState != null) {
        mUseFine = savedInstanceState.getBoolean(KEY_FINE);
        mUseBoth = savedInstanceState.getBoolean(KEY_BOTH);
    } else {
        mUseFine = false;
        mUseBoth = false;
    }
    TextView tv1 = (TextView) findViewById(R.id.textView1);
    TextView tv2 = (TextView) findViewById(R.id.textView2);
    TextView tv3 = (TextView) findViewById(R.id.fileLocation);
    ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
    btnUpload = (Button) findViewById(R.id.btnUpload);
    tv1.setText("Name : " + Session.name);
    tv2.setText("Caption :" + Session.caption);
    iv1.setImageBitmap(Session.image);
    tv3.setVisibility(View.GONE);
    //tv3.setText(Session.fileLocation2);
    mLatLng = (TextView) findViewById(R.id.latlng);
    mAddress = (TextView) findViewById(R.id.address);
    // Receive location updates from the fine location provider (gps) only.
    mFineProviderButton = (Button) findViewById(R.id.provider_fine);
    // Receive location updates from both the fine (gps) and coarse (network) location
    // providers.
    mBothProviderButton = (Button) findViewById(R.id.provider_both);

    // The isPresent() helper method is only available on Gingerbread or above.
    mGeocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent();

    // Handler for updating text fields on the UI like the lat/long and address.
    mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case UPDATE_ADDRESS:
                mAddress.setText((String) msg.obj);
                break;
            case UPDATE_LATLNG:
                mLatLng.setText((String) msg.obj);
                String[] res = ((String) msg.obj).split(",");
                lat = res[0];
                longt = res[1];
                break;
            }
        }
    };
    // Get a reference to the LocationManager object.
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mBothProviderButton.performClick();
    btnUpload.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                executeMultipartPost();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}

From source file:com.manning.androidhacks.hack040.util.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   w w  w . j  ava 2  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) {
    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 = makeTask(imageView, data);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mActivity.getResources(), mLoadingBitmap, task);
        imageView.setImageDrawable(asyncDrawable);
        NetworkThreadPool.submitTask(task);
    }
}

From source file:com.letsdoitworld.wastemapper.utils.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.
 *//*from  w w  w .j a  va  2  s  .co  m*/
public void downloadWithoutAnimation(String url, ImageView imageView) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.limitfan.gojuuon.utils.ScreenSlidePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(com.limitfan.gojuuon.R.layout.detail_slide_page,
            container, false);//from w w w .j  a  v  a2s  .  c  o  m

    ImageView stroke = (ImageView) (rootView.findViewById(com.limitfan.gojuuon.R.id.stroke));
    String romaji = Common.roma[getPageNumber()];

    try {
        String img = "";
        if (ActKana.isHira)
            img = "kanagraph/hiragana_" + romaji + ".jpg";
        else
            img = "kanagraph/katakana_" + romaji + ".jpg";
        InputStream is = getContext().getAssets().open(img, AssetManager.ACCESS_STREAMING);

        Bitmap bm = BitmapFactory.decodeStream(is);
        stroke.setImageBitmap(bm);
    } catch (Exception e) {

    }

    ViewGroup listView = (ViewGroup) rootView.findViewById(com.limitfan.gojuuon.R.id.list);
    ViewGroup demo_speak = (ViewGroup) inflater.inflate(com.limitfan.gojuuon.R.layout.demo_list_item, null);
    ((TextView) demo_speak.findViewById(com.limitfan.gojuuon.R.id.text))
            .setText(com.limitfan.gojuuon.R.string.demo);
    ((ImageView) demo_speak.findViewById(com.limitfan.gojuuon.R.id.icon))
            .setImageResource(com.limitfan.gojuuon.R.drawable.speak_off);

    listView.addView(demo_speak);

    TextView sample = (TextView) (rootView.findViewById(com.limitfan.gojuuon.R.id.sample));
    setSample(sample);
    demo_speak.setOnClickListener(new SpeakListener());

    //stroke.setImageResource();

    // Set the title view to show the page number.
    //EditText main = ((EditText) rootView.findViewById(R.id.Description));
    // main.setText(getString(R.string.title_template_step, mPageNumber + 1));
    //main.setEnabled(false);
    // main.setBackgroundColor(Color.TRANSPARENT);
    // main.setText(getFromAssets("details/"+(mPageNumber+1)+".txt"));

    return rootView;
}

From source file:com.letsdoitworld.wastemapper.utils.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.
 *//*ww  w .  j  a  v a 2  s.  co m*/
public void download(String url, ImageView imageView) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        if (mContext != null) {
            imageView.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.fadeout));
        }

    }
}

From source file:cn.mimail.sdk.net.image.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  w  w  w .j ava2  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) {
    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.baseproject.image.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  w  w w  . j  av a 2  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) {
    Bitmap bitmap = null;

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

    if (bitmap != null) {
        // Bitmap found in memory cache
        if (null != imageView) {
            imageView.setImageBitmap(bitmap);
        }
    } else if (cancelPotentialWork(data, imageView)) {
        final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mContext.getResources(), mLoadingBitmap, task);
        if (null != imageView) {
            imageView.setImageDrawable(asyncDrawable);
        }
        task.execute(data);
    }
}

From source file:com.scigames.slidegame.Registration2RFIDActivity.java

public void onActivityResult(int requestCode, Intent data) {
    //public void onActivityResult(int requestCode, int resultCode, Intent data) {     
    super.onActivityResult(requestCode, 1, data);
    Log.d(TAG, "...super.onActivityResult");
    switch (requestCode) {

    case (0): {//from w w w. j  a va2 s  .  co  m
        Log.d(TAG, "...case(0)");
        //if (resultCode == Activity.RESULT_OK) { 
        //  Log.d(TAG,"...RESULT_OK");

        ImageView previewThumbnail = new ImageView(this);
        Log.d(TAG, "...newImageView");

        Bitmap b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"), 0,
                getIntent().getByteArrayExtra("byteArray").length);
        Log.d(TAG, "...BitmapFactory.decodeByteArray");

        previewThumbnail.setImageBitmap(b);
        Log.d(TAG, "...setImageBitmap");

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
        Log.d(TAG, "...new layoutparams");

        previewThumbnail.setLayoutParams(layoutParams);
        Log.d(TAG, "...setLayoutParams");
        //}
        break;
    }
    }
}

From source file:com.hakkum.eby.garageImageFetcher.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 v  a2s . co  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(Utility.getBitmapWithReflection(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);
    }
}