Example usage for android.graphics.drawable BitmapDrawable BitmapDrawable

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

Introduction

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

Prototype

@Deprecated
public BitmapDrawable(java.io.InputStream is) 

Source Link

Document

Create a drawable by decoding a bitmap from the given input stream.

Usage

From source file:com.midisheetmusic.ChooseSongActivity.java

@Override
public void onCreate(Bundle state) {
    globalActivity = this;
    super.onCreate(state);

    Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon);
    Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon);
    Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon);

    final TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon))
            .setContent(new Intent(this, AllSongsActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon))
            .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

    tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon))
            .setContent(new Intent(this, FileBrowserActivity.class)));

}

From source file:com.midisheetmusicmemo.ChooseSongActivity.java

@Override
public void onCreate(Bundle state) {
    globalActivity = this;
    TommyConfig.init(this);
    super.onCreate(state);

    Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon);
    Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon);
    Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon);

    final TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon))
            .setContent(new Intent(this, AllSongsActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon))
            .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

    tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon))
            .setContent(new Intent(this, FileBrowserActivity.class)));

}

From source file:com.image.oom.ImageUtil.java

public void load(String url, ImageView imageView) {
    Log.e(this.toString(), "sHardBitmapCache:" + Integer.toString(sHardBitmapCache.size())
            + ",sSoftBitmapCache:" + Integer.toString(sSoftBitmapCache.size()));
    resetPurgeTimer();//from  ww  w .  j av  a 2s  .  c  o  m
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        // imageView.setImageBitmap(bitmap);
        Drawable Avater = new BitmapDrawable(bitmap);
        imageView.setImageDrawable(Avater);
    }
}

From source file:com.ecml.ChooseSongActivity.java

@Override
public void onCreate(Bundle state) {

    globalActivity = this;
    super.onCreate(state);

    // Set the Action Bar Title of the Activity (corresponding to the first Tab)
    setTitle("ECML: Choose Song");

    Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon);
    Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon);
    Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon);

    final TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon))
            .setContent(new Intent(this, AllSongsActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon))
            .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

    tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon))
            .setContent(new Intent(this, FileBrowserActivity.class)));

    tabHost.setOnTabChangedListener(this);
}

From source file:com.coodesoft.notee.MyImageGetter.java

@Override
public Drawable getDrawable(String source) {
    Drawable d = null;/* w ww .  j a v  a  2 s . c  o  m*/

    String strSrcLeft5 = source.substring(0, 5);

    // data
    if (strSrcLeft5.equalsIgnoreCase("data:")) {
        InputStream is = new ByteArrayInputStream(source.getBytes());

        //d = Drawable.createFromStream(is, null);
        //d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());

        //Bitmap dBitmap = BitmapFactory.decodeByteArray(data, 0, length);
        int nPosComma = source.indexOf(',');
        if (nPosComma > 0) {
            byte[] arrBuffer = Base64.decode(source.substring(nPosComma + 1), Base64.DEFAULT);
            //byte[] arrBuffer = Base64Coder.decode(source.substring(nPosComma + 1));
            Bitmap dBitmap = BitmapFactory.decodeByteArray(arrBuffer, 0, arrBuffer.length);
            d = new BitmapDrawable(dBitmap);
            d.setBounds(0, 0, dBitmap.getWidth(), dBitmap.getHeight());
        }

    } else {
        // url

        try {

            InputStream is = (InputStream) new URL(source).getContent();
            Bitmap dBitmap = BitmapFactory.decodeStream(is);
            if (dBitmap == null) {
                d = Resources.getSystem().getDrawable(android.R.drawable.picture_frame);
            } else {
                d = new BitmapDrawable(dBitmap);
                d.setBounds(0, 0, dBitmap.getWidth(), dBitmap.getHeight());
            }

            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());

        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        }

        /*
         URLDrawable urlDrawable = new URLDrawable();
                
         // get the actual source
         ImageGetterAsyncTask asyncTask = 
        new ImageGetterAsyncTask( urlDrawable);
                
         asyncTask.execute(source);
                
         // return reference to URLDrawable where I will change with actual image from
         // the src tag
         return urlDrawable;
         */

    }

    return d;
}

From source file:com.magizdev.babyoneday.profilewizard.AvatarFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(com.magizdev.babyoneday.R.layout.fragment_profilewizard_avatar, container,
            false);//from  w w w .  j av  a 2s .c  om
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    mAvatarBtn = (ImageButton) rootView.findViewById(com.magizdev.babyoneday.R.id.profile_pic);
    Bitmap avatar = (Bitmap) mPage.getData().getParcelable(Profile.AVATAR);
    if (avatar != null) {
        mAvatarBtn.setBackgroundDrawable(new BitmapDrawable(avatar));
    }
    mAvatarBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
            galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
            galleryIntent.setType("image/*");
            startActivityForResult(galleryIntent, IMAGE_REQUEST_CODE);
        }
    });
    return rootView;
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.mode.Billboard.java

@SuppressWarnings("deprecation")
public View billboardView() {
    LinearLayout billboardLayout = new LinearLayout(context);
    LayoutParams layoutParams = null;//from   ww  w . j  ava  2s  .com
    if (bgImg != null) {
        billboardLayout.setBackgroundDrawable(new BitmapDrawable(bgImg));
        layoutParams = new LayoutParams(UZCoreUtil.dipToPix(width), UZCoreUtil.dipToPix(height));
    } else {
        billboardLayout.setBackgroundResource(UZResourcesIDFinder.getResDrawableID("mo_bmap_popupmap"));
        layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, UZCoreUtil.dipToPix(height));
    }
    billboardLayout.setLayoutParams(layoutParams);
    billboardLayout.setOrientation(LinearLayout.HORIZONTAL);
    if (getIconAlign().equals("left")) {
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
        billboardLayout.addView(titleLayout());
    } else {
        billboardLayout.addView(titleLayout());
        if (iconStr != null && !iconStr.isEmpty())
            billboardLayout.addView(icon());
    }
    return billboardLayout;
}

From source file:com.example.kushagar.knockknock.FragmentMain.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    //TextView mTxtTitle = (TextView) rootView.findViewById(R.id.txtTitle);
    //mTxtTitle.setText(getArguments().getString(TEXT_FRAGMENT));
    mCardContainer = (CardContainer) rootView.findViewById(R.id.layoutview);

    SimpleCardStackAdapter adapter = new SimpleCardStackAdapter(getActivity());

    Resources r = getResources();

    //add the cards here by posting a get request.
    byte[] encodeByte = Base64.decode("Description goes here", Base64.DEFAULT);
    Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
    Drawable d = new BitmapDrawable(bitmap);

    adapter.add(new CardModel("Title1", "Description goes here", d));

    CardModel cardModel = new CardModel("Title1", "Description goes here", r.getDrawable(R.drawable.picture1));
    cardModel.setOnClickListener(new CardModel.OnClickListener() {
        @Override/*from  w  w w .ja va 2  s.c  om*/
        public void OnClickListener() {
            Log.i("Swipeable Cards", "I am pressing the card");
        }
    });

    cardModel.setOnCardDimissedListener(new CardModel.OnCardDimissedListener() {
        @Override
        public void onLike() {
            Log.i("Swipeable Cards", "I like the card");
        }

        @Override
        public void onDislike() {
            Log.i("Swipeable Cards", "I dislike the card");
        }
    });

    adapter.add(cardModel);

    mCardContainer.setAdapter(adapter);

    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    return rootView;
}

From source file:com.azcltd.android.test.kolesov.DrawableManager.java

private Drawable getAsBitmap(String urlString) {
    try {/*  www. j  ava  2 s  . c o  m*/
        InputStream is1 = (InputStream) new URL(urlString).getContent();
        Bitmap d = BitmapFactory.decodeStream(is1);
        is1.close();
        Drawable drawable = new BitmapDrawable(d);
        if (d != null)
            drawableMap.put(urlString, drawable);
        return drawable;
    } catch (Exception e1) {
        int i = 1;
    }
    return null;
}

From source file:com.othermedia.asyncimage.AsyncImageDownloader.java

@Override
public void run() {
    if (parentImageCache == null)
        return;/*  w  ww  .j a va  2 s. c  o m*/

    // The downloader runs until the queue is empty or the cache is disconnected
    while (parentImageCache != null && parentImageCache.downloadQueue.size() > 0) {

        AsyncImageTask currentTask = parentImageCache.downloadQueue.remove(0); // Pop first task in (FIFO)

        try {

            // -- Check and retrieve file cache
            String hashedPath = null;
            try {
                if (parentImageCache.isFileCacheEnabled()) {
                    hashedPath = parentImageCache.hashString(currentTask.getImageURL()) + ".png";
                    if (parentImageCache.hasInFileCache(hashedPath)) {
                        parentImageCache.fileCacheRetrieve(hashedPath, currentTask.getImageURL());
                    }
                }
            } catch (Exception e) {
                Log.e(DebugTag, "Exception on retrieving from file cache: " + e + ": " + e.getMessage());
            }

            // - Check cache, if the image got retrieved by an earlier request or from file cache
            if (parentImageCache.hasCached(currentTask.getImageURL())) {
                parentImageCache.updateTargetFromHandler(currentTask.getTargetImageView(),
                        currentTask.getImageURL());
            } else {
                // ...Else download image:

                int tries = 3; // Allowed download Tries

                while (tries > 0) {
                    tries--; // In case of a short network drop or other random connection error.

                    try {

                        // -- Create HTTP Request
                        URL requestUrl = new URL(currentTask.getImageURL());
                        HttpGet httpRequest = new HttpGet(requestUrl.toURI());
                        HttpClient httpClient = new DefaultHttpClient();
                        HttpResponse httpResponse = (HttpResponse) httpClient.execute(httpRequest);

                        // -- Process Bitmap Download
                        BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(httpResponse.getEntity());
                        InputStream inputStream = bufferedEntity.getContent();
                        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                        BitmapDrawable drawable = new BitmapDrawable(bitmap);
                        parentImageCache.cacheImage(currentTask.getImageURL(), drawable); // - cache downloaded bitmap, then update ImageView:
                        parentImageCache.updateTargetFromHandler(currentTask.getTargetImageView(),
                                currentTask.getImageURL());

                        tries = 0; // Release tries.
                        inputStream.close();

                        // -- Cache Drawable as file, if enabled
                        if (parentImageCache.isFileCacheEnabled()) {
                            try {
                                if (hashedPath != null) {
                                    File outputFile = new File(parentImageCache.getCacheDir(), hashedPath);
                                    FileOutputStream outputStream = new FileOutputStream(outputFile);
                                    bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
                                }
                            } catch (Exception e) {
                                Log.e(DebugTag,
                                        "Exception on file caching process: " + e + ": " + e.getMessage());
                            }
                        } // -- End file caching.

                    } catch (Exception e) {
                        Log.e(DebugTag, "Exception on download process: " + e + ": " + e.getMessage());
                        try {
                            Thread.sleep(250);
                        } catch (InterruptedException ei) {
                        }
                    }
                }
            }

        } catch (Exception e) {
            Log.e(DebugTag, "Exception on current AsyncImageTask: " + e + ": " + e.getMessage());
        }

    }

    parentImageCache.downloaderFinished(); // Release thread reference from cache

}