Example usage for android.graphics.drawable BitmapDrawable getBitmap

List of usage examples for android.graphics.drawable BitmapDrawable getBitmap

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable getBitmap.

Prototype

public final Bitmap getBitmap() 

Source Link

Document

Returns the bitmap used by this drawable to render.

Usage

From source file:com.android.displayingbitmaps.util.ImageWorker.java

public Bitmap loadFromCache(String data) {
    if (data == null) {
        return null;
    }/*from   w  ww .j a va  2  s.  c o m*/
    BitmapDrawable value = null;
    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
        if (value != null) {
            return value.getBitmap();
        }
    }
    return null;
}

From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AppInjector.inject(this);

    if (savedInstanceState != null) {
        mBitmap = savedInstanceState.getParcelable("selected_image");
    }/*  w w  w .  j av a2  s. c om*/

    String woeid = getIntent().getStringExtra(EXTRA_WOEID);
    if (woeid == null) {
        woeid = mSharedPreferences.getString(WeatherLoadingService.PREFERENCE_LAST_KNOWN_WOEID, null);
    }
    if (woeid == null) {
        woeid = mPreferenceHelper.getDefaultLocationWoeId();
    }

    if (woeid == null) {
        // TODO: we need a default location.
        finish();
        return;
    }

    mDisplayUnit = getIntent().getStringExtra(EXTRA_UNIT);
    mTimezone = getIntent().getStringExtra(EXTRA_TIME_ZONE);

    mWoeid = woeid;

    setContentView(R.layout.activity_weather_details);

    mBackgroundImage = (ImageView) findViewById(R.id.weather_background);
    mCurrentWeatherIcon = (ImageView) findViewById(R.id.current_weather);
    mTemperatureView = (TextView) findViewById(R.id.temperature);
    mLocationView = (TextView) findViewById(R.id.location);
    mConditionView = (TextView) findViewById(R.id.condition);
    mCurrentWeatherContainer = findViewById(R.id.current_weather_container);
    mMinTempView = (TextView) findViewById(R.id.temp_min);
    mMaxTempView = (TextView) findViewById(R.id.temp_max);
    mWindView = (TextView) findViewById(R.id.wind);
    mFeelsLikeView = (TextView) findViewById(R.id.feels_like);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler);
    mForecastHeader = (TextView) findViewById(R.id.forecast_header);

    mMinTempDrawable = mMinTempView.getCompoundDrawablesRelative()[0];
    mMaxTempDrawable = mMaxTempView.getCompoundDrawablesRelative()[0];
    BitmapDrawable windDrawable = (BitmapDrawable) mWindView.getCompoundDrawablesRelative()[0];
    mWindDrawable = new SimpleRotateDrawable(getResources(), windDrawable.getBitmap());
    mWindView.setCompoundDrawablesRelativeWithIntrinsicBounds(mWindDrawable, null, null, null);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new ForecastAdapter(mDisplayUnit);
    mRecyclerView.setAdapter(mAdapter);

    getLoaderManager().initLoader(1, null, new WeatherDataLoaderCallbacks());
}

From source file:com.rickstart.moviefriend.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 added using
 * {@link ImageWorker#addImageCache(android.support.v4.app.FragmentManager, ImageCache.ImageCacheParams)}. 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.
 *
 * @param data The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *///from   ww w. ja v a  2s  .  c  om
public void loadImage(Object data, ImageView imageView) {
    if (data == null) {
        return;
    }

    BitmapDrawable value = null;

    if (mImageCache != null) {

        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
    }

    if (value != null) {
        // Bitmap found in memory cache
        Bitmap bitmap = value.getBitmap().createScaledBitmap(value.getBitmap(), columnWidth,
                columnWidth + (columnWidth / 3), false);
        value = new BitmapDrawable(mResources, bitmap);
        imageView.setImageDrawable(value);
    } else if (cancelPotentialWork(data, imageView)) {
        //BEGIN_INCLUDE(execute_background_task)
        final BitmapWorkerTask task = new BitmapWorkerTask(data, 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);
        //END_INCLUDE(execute_background_task)
    }
}

From source file:com.android.displayingbitmaps.util.ImageWorker.java

public Bitmap loadImage(String data) {
    if (data == null) {
        return null;
    }/*  w ww.  jav a2s . co  m*/
    BitmapDrawable value = null;
    if (mImageCache != null) {
        value = mImageCache.getBitmapFromMemCache(String.valueOf(data));
        if (value != null) {
            return value.getBitmap();
        }
    }
    Bitmap bitmap = processBitmap(data);
    if (bitmap != null) {
        if (Utils.hasHoneycomb()) {
            // Running on Honeycomb or newer, so wrap in a standard
            // BitmapDrawable
            value = new BitmapDrawable(mResources, bitmap);
        } else {
            // Running on Gingerbread or older, so wrap in a
            // RecyclingBitmapDrawable
            // which will recycle automagically
            value = new RecyclingBitmapDrawable(mResources, bitmap);
        }

        if (mImageCache != null) {
            mImageCache.addBitmapToCache(data, value);
        }
    }

    return bitmap;
}

From source file:github.madmarty.madsonic.util.ImageLoader.java

private void createLargeUnknownImage(Context context) {

    BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(R.drawable.unknown_album);
    Bitmap bitmap = Bitmap.createScaledBitmap(drawable.getBitmap(), imageSizeLarge, imageSizeLarge, true);
    bitmap = createReflection(bitmap);//www . jav a  2 s. com
    largeUnknownImage = Util.createDrawableFromBitmap(context, bitmap);
}

From source file:org.chromium.chrome.browser.media.ui.MediaNotificationManager.java

private Bitmap drawableToBitmap(Drawable drawable) {
    if (!(drawable instanceof BitmapDrawable))
        return null;

    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    return bitmapDrawable.getBitmap();
}

From source file:com.SecUpwN.AIMSICD.fragments.MapFragment.java

/**
 * Description:     Initialises the Map and sets initial options such as:
 * Zoom levels and controls//from ww w .  j a  va 2s .co m
 * Compass
 * ScaleBar
 * Cluster Pin colors
 * Location update settings
 */
private void setUpMapIfNeeded() {

    // Check if we were successful in obtaining the map.
    mMap.setBuiltInZoomControls(true);
    mMap.setMultiTouchControls(true);
    mMap.setMinZoomLevel(3);
    mMap.setMaxZoomLevel(19); // Latest OSM can go to 21!
    mMap.getTileProvider().createTileCache();
    mCompassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()),
            mMap);

    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(getActivity());
    mScaleBarOverlay.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels / 2, 10);
    mScaleBarOverlay.setCentred(true);

    // Sets cluster pin color
    mCellTowerGridMarkerClusterer = new CellTowerGridMarkerClusterer(getActivity());
    BitmapDrawable mapPinDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_map_pin_orange);
    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());

    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(getActivity().getBaseContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(100); // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000); // [ms] // Set the minimum time interval for location updates
    mMyLocationOverlay = new MyLocationNewOverlay(getActivity().getBaseContext(), gpsMyLocationProvider, mMap);
    mMyLocationOverlay.setDrawAccuracyEnabled(true);

    mMap.getOverlays().add(mCellTowerGridMarkerClusterer);
    mMap.getOverlays().add(mMyLocationOverlay);
    mMap.getOverlays().add(mCompassOverlay);
    mMap.getOverlays().add(mScaleBarOverlay);
}

From source file:de.ub0r.android.websms.connector.o2.ConnectorO2.java

/**
 * Load captcha and wait for user input to solve it.
 * /*from  ww  w.j a va 2s. c o  m*/
 * @param context
 *            {@link Context}
 * @param flow
 *            _flowExecutionKey
 * @return true if captcha was solved
 * @throws IOException
 *             IOException
 */
private boolean solveCaptcha(final Context context, final String flow) throws IOException {
    HttpResponse response = Utils.getHttpClient(URL_CAPTCHA, null, null, TARGET_AGENT, URL_LOGIN, ENCODING,
            O2_SSL_FINGERPRINTS);
    int resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(context, R.string.error_http, "" + resp);
    }
    BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent());
    final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST);
    intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap());
    captcha = null;
    this.getSpec(context).setToIntent(intent);
    context.sendBroadcast(intent);
    try {
        synchronized (CAPTCHA_SYNC) {
            CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT);
        }
    } catch (InterruptedException e) {
        Log.e(TAG, null, e);
        return false;
    }
    if (captchaSolve == null) {
        return false;
    }
    // got user response, try to solve captcha
    Log.d(TAG, "got solved captcha: " + captchaSolve);
    final ArrayList<BasicNameValuePair> postData = // .
            new ArrayList<BasicNameValuePair>(3);
    postData.add(new BasicNameValuePair("_flowExecutionKey", flow));
    postData.add(new BasicNameValuePair("_eventId", "submit"));
    postData.add(new BasicNameValuePair("riddleValue", captchaSolve));
    response = Utils.getHttpClient(URL_SOLVECAPTCHA, null, postData, TARGET_AGENT, URL_LOGIN, ENCODING,
            O2_SSL_FINGERPRINTS);
    Log.d(TAG, postData.toString());
    resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(context, R.string.error_http, "" + resp);
    }
    final String mHtmlText = Utils.stream2str(response.getEntity().getContent());
    if (mHtmlText.indexOf(CHECK_WRONGCAPTCHA) > 0) {
        throw new WebSMSException(context, R.string.error_wrongcaptcha);
    }
    return true;
}

From source file:com.secupwn.aimsicd.ui.activities.MapViewerOsmDroid.java

/**
 * Description:     Initialises the Map and sets initial options such as:
 * Zoom levels and controls/*from w ww  . java2s .co m*/
 * Compass
 * ScaleBar
 * Cluster Pin colors
 * Location update settings
 */
private void setUpMapIfNeeded() {

    // Check if we were successful in obtaining the map.
    mMap.setBuiltInZoomControls(true);
    mMap.setMultiTouchControls(true);
    mMap.setMinZoomLevel(3);
    mMap.setMaxZoomLevel(19); // Latest OSM can go to 21!
    mMap.getTileProvider().createTileCache();
    mCompassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), mMap);

    ScaleBarOverlay mScaleBarOverlay = new ScaleBarOverlay(this);
    mScaleBarOverlay.setScaleBarOffset(getResources().getDisplayMetrics().widthPixels / 2, 10);
    mScaleBarOverlay.setCentred(true);

    // Sets cluster pin color
    mCellTowerGridMarkerClusterer = new CellTowerGridMarkerClusterer(MapViewerOsmDroid.this);
    BitmapDrawable mapPinDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_map_pin_orange);
    mCellTowerGridMarkerClusterer.setIcon(mapPinDrawable == null ? null : mapPinDrawable.getBitmap());

    GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(
            MapViewerOsmDroid.this.getBaseContext());
    gpsMyLocationProvider.setLocationUpdateMinDistance(100); // [m]  // Set the minimum distance for location updates
    gpsMyLocationProvider.setLocationUpdateMinTime(10000); // [ms] // Set the minimum time interval for location updates
    mMyLocationOverlay = new MyLocationNewOverlay(MapViewerOsmDroid.this.getBaseContext(),
            gpsMyLocationProvider, mMap);
    mMyLocationOverlay.setDrawAccuracyEnabled(true);

    mMap.getOverlays().add(mCellTowerGridMarkerClusterer);
    mMap.getOverlays().add(mMyLocationOverlay);
    mMap.getOverlays().add(mCompassOverlay);
    mMap.getOverlays().add(mScaleBarOverlay);
}

From source file:com.app.secnodhand.imageutil.ImageWorker.java

public void loadImageForView(Object data, ZoomableImageView view, ImageLoadingListener mImageLoadingListener) {
    if (data == null) {
        return;/* w  w  w .  ja va  2s. c  o m*/
    }

    if (mImageLoadingListener != null) {
        this.mImageLoadingListener = mImageLoadingListener;
        mImageLoadingListener.startLoading();
    }

    BitmapDrawable value = null;

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

    if (value != null) {
        // Bitmap found in memory cache
        view.setImageBitmap(value.getBitmap());
    } else {
        final BitmapWorkerTask task = new BitmapWorkerTask(view);
        final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task);
        view.setImageDrawable(asyncDrawable);
        task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data);
    }
}