Example usage for android.graphics BitmapFactory decodeFile

List of usage examples for android.graphics BitmapFactory decodeFile

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeFile.

Prototype

public static Bitmap decodeFile(String pathName) 

Source Link

Document

Decode a file path into a bitmap.

Usage

From source file:com.waveface.installer.util.ImageDownloader.java

/**
 * @param url The URL of the image that will be retrieved from the cache.
 * @return The cached bitmap or null if it was not found.
 *//*from  ww w.  ja  v a  2s.  c  o m*/
private Bitmap getBitmapFromCache(String url) {
    // First try the hard reference cache
    synchronized (sHardBitmapCache) {
        final Bitmap bitmap = sHardBitmapCache.get(url);
        if (bitmap != null) {
            // Bitmap found in hard cache
            // Move element to first position, so that it is removed last
            sHardBitmapCache.remove(url);
            sHardBitmapCache.put(url, bitmap);
            return bitmap;
        }
    }

    File cacheDir = mContext.getCacheDir();
    File file = new File(cacheDir, Base64.encodeToString(url.getBytes(), Base64.DEFAULT));
    if (file.exists()) {
        Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
        if (bm != null) {
            return bm;
        }
    }

    // Then try the soft reference cache
    SoftReference<Bitmap> bitmapReference = sSoftBitmapCache.get(url);
    if (bitmapReference != null) {
        final Bitmap bitmap = bitmapReference.get();
        if (bitmap != null) {
            // Bitmap found in soft cache
            return bitmap;
        } else {
            // Soft reference has been Garbage Collected
            sSoftBitmapCache.remove(url);
        }
    }

    return null;
}

From source file:foam.jellyfish.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*w ww .j  av a  2s  .  co m*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx,
                    android.R.layout.simple_spinner_item, spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("nomadic")) {
            final int wid = arr.getInt(1);
            NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            parent.addView(v);
        }

        /*
                    if (type.equals("canvas")) {
        StarwispCanvas v = new StarwispCanvas(ctx);
        final int wid = arr.getInt(1);
        v.setId(wid);
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
        v.SetDrawList(arr.getJSONArray(3));
        parent.addView(v);
                    }
                
                    if (type.equals("camera-preview")) {
        PictureTaker pt = new PictureTaker();
        CameraPreview v = new CameraPreview(ctx,pt);
        final int wid = arr.getInt(1);
        v.setId(wid);
                
                
        //              LinearLayout.LayoutParams lp =
        //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);
                
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
                
        //                v.setLayoutParams(lp);
        parent.addView(v);
                    }
        */
        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:com.akop.bach.ImageCache.java

public Bitmap getBitmap(String imageUrl, boolean bypassCache, int resizeH, int resizeV) {
    File file = getCacheFile(imageUrl, null);

    // See if it's in the local cache 
    // (but only if not being forced to refresh)
    if (!bypassCache && file.canRead()) {
        if (App.getConfig().logToConsole())
            App.logv("Cache hit: " + file.getAbsolutePath());

        file.lastModified();//  w w w . j a v  a2s .  c  o m

        try {
            return BitmapFactory.decodeFile(file.getAbsolutePath());
        } catch (OutOfMemoryError e) {
            return null;
        }
    }

    // Fetch the image
    byte[] blob;
    int length;

    try {
        HttpClient client = new IgnorantHttpClient();
        HttpResponse resp = client.execute(new HttpGet(imageUrl));
        HttpEntity entity = resp.getEntity();

        if (entity == null)
            return null;

        InputStream stream = entity.getContent();
        if (stream == null)
            return null;

        try {
            if ((length = (int) entity.getContentLength()) <= 0)
                return null;

            blob = new byte[length];

            // Read the stream until nothing more to read
            for (int r = 0; r < length; r += stream.read(blob, r, length - r))
                ;
        } finally {
            stream.close();
            entity.consumeContent();
        }
    } catch (IOException e) {
        if (App.getConfig().logToConsole())
            e.printStackTrace();

        return null;
    }

    // if (file.canWrite())
    {
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(file);

            if (resizeH > -1 || resizeV > -1) {
                Bitmap bmp = BitmapFactory.decodeByteArray(blob, 0, length);
                float aspectRatio = (float) bmp.getWidth() / (float) bmp.getHeight();

                int newWidth = (resizeH < 0) ? (int) ((float) resizeV * aspectRatio) : resizeH;
                int newHeight = (resizeV < 0) ? (int) ((float) resizeH / aspectRatio) : resizeV;

                Bitmap resized = Bitmap.createScaledBitmap(bmp, newWidth, newHeight, true);
                resized.compress(Bitmap.CompressFormat.PNG, 100, fos);

                return resized;
            } else {
                fos.write(blob);
            }

            if (App.getConfig().logToConsole())
                App.logv("Wrote to cache: " + file.getAbsolutePath());
        } catch (IOException e) {
            if (App.getConfig().logToConsole())
                e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }
        }
    }

    Bitmap bmp = null;

    try {
        bmp = BitmapFactory.decodeByteArray(blob, 0, length);
    } catch (Exception e) {
        if (App.getConfig().logToConsole())
            e.printStackTrace();
    }

    return bmp;
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.util.ImageDownloader.java

/**
 * @param url/*  w ww.  j av  a  2  s  .  c om*/
 *            The URL of the image that will be retrieved from the cache.
 * @return The cached bitmap or null if it was not found.
 */
private Bitmap getBitmapFromCache(String url) {
    if (url != null) {
        // First try the hard reference cache
        synchronized (sHardBitmapCache) {
            final Bitmap bitmap = sHardBitmapCache.get(url);
            if (bitmap != null) {
                // Bitmap found in hard cache
                // Move element to first position, so that it is removed
                // last
                sHardBitmapCache.remove(url);
                sHardBitmapCache.put(url, bitmap);
                return bitmap;
            }
        }

        // Then try the soft reference cache
        SoftReference<Bitmap> bitmapReference = sSoftBitmapCache.get(url);
        if (bitmapReference != null) {
            final Bitmap bitmap = bitmapReference.get();
            if (bitmap != null) {
                // Bitmap found in soft cache
                return bitmap;
            } else {
                // Soft reference has been Garbage Collected
                sSoftBitmapCache.remove(url);
            }
        }

        File cacheFile = null;
        try {
            MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
            mDigest.update(url.getBytes());
            final String cacheKey = bytesToHexString(mDigest.digest());
            if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                cacheFile = new File(Environment.getExternalStorageDirectory() + File.separator + "Android"
                        + File.separator + "data" + File.separator + mContext.getPackageName() + File.separator
                        + "cache" + File.separator + "bitmap_" + cacheKey + ".tmp");
            }
        } catch (NoSuchAlgorithmException e) {
            // Oh well, SHA-1 not available (weird), don't cache bitmaps.
        }

        if (cacheFile != null && cacheFile.exists()) {
            Bitmap cachedBitmap = BitmapFactory.decodeFile(cacheFile.toString());
            if (cachedBitmap != null) {
                addBitmapToCache(url, cachedBitmap);
                return cachedBitmap;
            }
        }
    }

    return null;
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageAdapter.java

private void outgoingImage(String numb) {
    Log.setLogLevel(6);//  ww  w  . j  a  v  a 2 s . c  o  m
    Log.d("outgoingImage", "call");
    iv_recievedfile = (ImageView) v.findViewById(R.id.iv_recievedfile);

    if (isimagemsginit(subject)) {
        pb_uploading.setVisibility(ProgressBar.VISIBLE);
    } else {
        pb_uploading.setVisibility(ProgressBar.GONE);
    }

    if (isvideoMsg(subject)) {
        text_view.setVisibility(TextView.GONE);
        iv_recievedfile.setVisibility(ImageView.VISIBLE);
        Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_video_icon);
        iv_recievedfile.setImageBitmap(b);
    } else if (isaudioMsg(subject)) {
        text_view.setVisibility(TextView.GONE);
        iv_recievedfile.setVisibility(ImageView.VISIBLE);
        Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_audio_icon);
        iv_recievedfile.setImageBitmap(b);
    } else if (islocationMsg(subject)) {
        text_view.setVisibility(TextView.GONE);
        iv_recievedfile.setVisibility(ImageView.VISIBLE);
        Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_map_icon);
        iv_recievedfile.setImageBitmap(b);
    } else if (iscontactMsg(subject)) {
        tv_msg_info.setText("1");
        text_view.setVisibility(TextView.GONE);
        iv_recievedfile.setVisibility(ImageView.VISIBLE);
        Bitmap b = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_contact_icon);
        iv_recievedfile.setImageBitmap(b);
    } else if (isimageMsg(subject)) {
        text_view.setVisibility(TextView.GONE);
        iv_recievedfile.setVisibility(ImageView.VISIBLE);
        Log.d("subject outgoingImage", subject);

        if (subject.contains("@@")) {
            String[] fileuriarr = subject.split("@@");
            String fileuri = fileuriarr[1];
            String[] namm = fileuri.split("-");
            String path = Environment.getExternalStorageDirectory() + "/R4W/SharingImage/" + stripNumber(numb)
                    + "/send/" + namm[2];
            Log.d("fileuri1", fileuri);
            Log.d("path1", path);
            File user_imageFile = new File(path);
            if (user_imageFile.exists()) {
                Bitmap b = BitmapFactory.decodeFile(path);

                int[] size = messageActivity.getBitmapSize(b);
                b = Bitmap.createScaledBitmap(b, size[0], size[1], false);
                Log.d("imageFile.exists", "true");
                Log.d("bitmap", b.getWidth() + " @");
                iv_recievedfile.setImageBitmap(b);
                /*
                 iv_recievedfile.setImageURI(Uri.parse(imageFile.getAbsolutePath()));
                 Log.d("imageFile.getAbsolutePath()", imageFile.getAbsolutePath());
                 */
            }
        }

    } else {
        text_view.setVisibility(TextView.VISIBLE);
        iv_recievedfile.setVisibility(ImageView.GONE);
        pb_uploading.setVisibility(ProgressBar.GONE);
    }
}

From source file:com.lastorder.pushnotifications.data.ImageDownloader.java

/**
 * @param url The URL of the image that will be retrieved from the cache.
 * @return The cached bitmap or null if it was not found.
 *///from w w  w . j  a  v  a 2s  . c  o m
private Bitmap getBitmapFromCache(String url) {
    // First try the hard reference cache
    try {
        synchronized (sHardBitmapCache) {

            final Bitmap bitmap = sHardBitmapCache.get(url);
            if (bitmap != null) {
                // Bitmap found in hard cache
                // Move element to first position, so that it is removed last
                sHardBitmapCache.remove(url);
                sHardBitmapCache.put(url, bitmap);
                return bitmap;
            }
        }

        // Then try the soft reference cache
        SoftReference<Bitmap> bitmapReference = sSoftBitmapCache.get(url);
        if (bitmapReference != null) {
            final Bitmap bitmap = bitmapReference.get();
            if (bitmap != null) {
                // Bitmap found in soft cache
                return bitmap;
            } else {
                // Soft reference has been Garbage Collected
                sSoftBitmapCache.remove(url);
            }
        }

        final String pathName = cacheDir + "/" + url.hashCode() + "-t.jpg";
        final Bitmap bitmap = BitmapFactory.decodeFile(pathName);

        if (bitmap != null) {
            return bitmap;
        }

        return null;
    } catch (OutOfMemoryError e) {
        return null;
    }
}

From source file:by.lykashenko.interfaces.ImageDownloader.java

/**
 * @param url The URL of the image that will be retrieved from the cache.
 * @return The cached bitmap or null if it was not found.
 *///from  w w  w  .  j  a v  a  2 s  .  c  o m
private Bitmap getBitmapFromCache(String url) {

    if (state == 1) {
        // First try the hard reference cache
        synchronized (sHardBitmapCache) {
            final Bitmap bitmap = sHardBitmapCache.get(url);
            if (bitmap != null) {
                // Bitmap found in hard cache
                // Move element to first position, so that it is removed last
                sHardBitmapCache.remove(url);
                sHardBitmapCache.put(url, bitmap);
                return bitmap;
            }
        }

        // Then try the soft reference cache
        SoftReference<Bitmap> bitmapReference = sSoftBitmapCache.get(url);
        if (bitmapReference != null) {
            final Bitmap bitmap = bitmapReference.get();
            if (bitmap != null) {
                // Bitmap found in soft cache
                return bitmap;
            } else {
                // Soft reference has been Garbage Collected
                sSoftBitmapCache.remove(url);
            }
        }
    } else {
        String[] separated = url.split("/");

        String file = new StringBuilder(path).append("/").append(separated[7]).toString();

        Bitmap bitmap = BitmapFactory.decodeFile(file);
        return bitmap;
    }

    return null;
}

From source file:rpassmore.app.fillthathole.ViewHazardActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case PICK_PHOTO_ACTIVITY: {
        if (resultCode == RESULT_OK) {
            Bitmap bitmap;//w w w .  ja v  a 2  s.c om
            try {
                bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData()));
                storeNewPhoto(bitmap, data.getData().toString());
            } catch (FileNotFoundException ex) {
                Log.e(getPackageName(), "Error loading image file", ex);
            }
        }
        break;
    }
    case PICTURE_ACTIVITY: {
        if (resultCode == RESULT_OK) {

            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(capturedImageURI, projection, null, null, null);
            int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            String capturedImageFilePath = cursor.getString(column_index_data);

            Bitmap bitmap = BitmapFactory.decodeFile(capturedImageFilePath);

            storeNewPhoto(bitmap, capturedImageFilePath);
        }
        break;
    }
    case LOCATION_MAP_ACTIVITY: {
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            if (extras != null) {
                hazard.setLattitude(extras.getLong(LocationActivity.LOCATION_LAT) / 1.0E6);
                hazard.setLongitude(extras.getLong(LocationActivity.LOCATION_LONG) / 1.0E6);
                if (extras.getString("Address") != null) {
                    hazard.setAddress(extras.getString(LocationActivity.LOCATION_ADDRESS));
                }
            }
        }
        break;
    }
    }
}

From source file:com.skytree.epubtest.BookViewActivity.java

public Bitmap getBitmap(String filename) {
    Bitmap bitmap;
    bitmap = BitmapFactory.decodeFile(SkySetting.getStorageDirectory() + "/images/" + filename);
    return bitmap;
}