Example usage for android.content ContextWrapper getDir

List of usage examples for android.content ContextWrapper getDir

Introduction

In this page you can find the example usage for android.content ContextWrapper getDir.

Prototype

@Override
    public File getDir(String name, int mode) 

Source Link

Usage

From source file:com.policestrategies.calm_stop.citizen.ProfileDisplayActivity.java

private void loadProfileImage() {

    ContextWrapper cw = new ContextWrapper(getApplicationContext());
    File directory = cw.getDir("ProfilePic", Context.MODE_PRIVATE);

    String path = directory.getAbsolutePath();
    File f = new File(path, "profilepic.JPG");

    if (convertUriToBitmap(Uri.fromFile(f)) != null) {
        mProfileImageView.setImageBitmap(convertUriToBitmap(Uri.fromFile(f)));
        mProfileImage.setImageBitmap(convertUriToBitmap(Uri.fromFile(f)));
    } else/*  ww  w . j a  v a2s . c o m*/
        Toast.makeText(this, "whyyyyy", Toast.LENGTH_SHORT).show();
}

From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java

private String saveToInternalSorage(Bitmap bitmapImage) {
    ContextWrapper cw = new ContextWrapper(DriverLicenseActivity.this);
    // path to /data/data/yourapp/app_data/imageDir
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    // Create imageDir
    File mypath = new File(directory, "tmpimage.jpg");

    FileOutputStream fos = null;//from ww  w .  j  a v a 2s.c  o  m
    try {
        fos = new FileOutputStream(mypath);
        // Use the compress method on the BitMap object to write image to the OutputStream
        bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mypath.getPath();
}

From source file:com.parse.f8.view.SignInActivity.java

private String saveToInternalSorage(Bitmap bitmapImage) {
    ContextWrapper cw = new ContextWrapper(ctx);
    // path to /data/data/yourapp/app_data/imageDir
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    // Create imageDir
    File mypath = new File(directory, "profile.jpg");

    FileOutputStream fos = null;/* w  w  w .ja  v a2 s .  c o m*/
    try {

        fos = new FileOutputStream(mypath);

        // Use the compress method on the BitMap object to write image to the OutputStream
        bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return directory.getAbsolutePath();
}

From source file:layout.FragmentBoardItemList.java

private void getThumbnail(final BoardItem bi) {
    bi.downloadingThumb = true;// ww w .j a  va 2s  .c om
    ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    boolean usingWifi = (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);

    ContextWrapper cw = new ContextWrapper(getActivity().getApplicationContext());
    File directory = cw.getDir("thumbs", Context.MODE_PRIVATE);
    if (!directory.exists()) {
        directory.mkdir();
    }
    final File mypath;
    if (bi.youtubeLink) {
        mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.youtubeID);
    } else {
        mypath = new File(directory, currentBoard.getBoardDir() + "_" + bi.getThumb());
    }

    if (mypath.exists()) {
        try {
            Bitmap b = BitmapFactory.decodeStream(new FileInputStream(mypath));
            bi.setThumbBitmap(Bitmap.createScaledBitmap(b, 128, 128, false));
            listViewAdapter.notifyDataSetChanged();
            Log.i("getThumb", bi.getThumb() + " from cache");
            return;
        } catch (Exception e) {
            e.printStackTrace();
            displayError(e.getMessage());
        }
    }
    if (settings.getBoolean("setting_downloadOnlyWithWifi", false) == true && !usingWifi) {
        Log.i("getThumb", "Not using wifi");
        return;
    }
    String imgURL = "http://bienvenidoainternet.org/" + bi.getParentBoard().getBoardDir() + "/thumb/"
            + bi.getThumb();
    if (bi.getThumb().startsWith("http")) {
        imgURL = bi.getThumb();
    }
    Ion.with(getContext()).load(imgURL).setLogging("getThumbnail", Log.INFO).asBitmap()
            .setCallback(new FutureCallback<Bitmap>() {
                @Override
                public void onCompleted(Exception e, Bitmap result) {
                    if (e != null) {
                        displayError(e.getMessage());
                        e.printStackTrace();
                    } else {
                        bi.setThumbBitmap(Bitmap.createScaledBitmap(result, 128, 128, false));
                        listViewAdapter.notifyDataSetChanged();
                        FileOutputStream out;
                        try {
                            out = new FileOutputStream(mypath);
                            result.compress(Bitmap.CompressFormat.PNG, 100, out);
                            if (out != null) {
                                out.close();
                            }
                            Log.v("getThumb", bi.getThumb() + " saved.");
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                }
            });
}