Android Open Source - NavigationDrawer Planet Bitmap






From Project

Back to project page NavigationDrawer.

License

The source code is released under:

Apache License

If you think the Android project NavigationDrawer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.android.navigationdrawer;
//from   ww  w  .ja  v a 2  s. c  om
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class PlanetBitmap {

  private static Map<String, Bitmap> cache = new HashMap<String, Bitmap>();
  private Activity activity;

  public PlanetBitmap(Activity activity) {
    this.activity = activity;
  }

  public Bitmap getBitmap(String planet) {
    Bitmap bitmap = cache.get(planet);
    if (bitmap != null) return bitmap;

    int imageId = activity.getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()),
        "drawable", activity.getPackageName());

    try {
      Thread.sleep(500);
    } catch (InterruptedException ignored) {
    }

    bitmap = BitmapFactory.decodeResource(activity.getResources(), imageId);
    cache.put(planet, bitmap);
    return bitmap;
  }
}




Java Source Code List

com.example.android.common.logger.LogFragment.java
com.example.android.common.logger.LogNode.java
com.example.android.common.logger.LogView.java
com.example.android.common.logger.LogWrapper.java
com.example.android.common.logger.Log.java
com.example.android.common.logger.MessageOnlyLogFilter.java
com.example.android.navigationdrawer.MainActivity.java
com.example.android.navigationdrawer.NavigationDrawerActivity.java
com.example.android.navigationdrawer.PlanetAdapter.java
com.example.android.navigationdrawer.PlanetBitmap.java