Example usage for android.net Uri getEncodedPath

List of usage examples for android.net Uri getEncodedPath

Introduction

In this page you can find the example usage for android.net Uri getEncodedPath.

Prototype

@Nullable
public abstract String getEncodedPath();

Source Link

Document

Gets the encoded path.

Usage

From source file:Main.java

@Deprecated
public static HashMap<String, String> parseDataGET(Uri uri) {
    String params = uri.getEncodedPath().substring(1);
    return splitParams(params);
}

From source file:Main.java

public static String parseOwnUri(Uri uri, Context context) {
    if (uri == null)
        return "";

    return uri.getEncodedPath();
}

From source file:org.goodev.droidddle.utils.IOUtil.java

public static String getCacheFilenameForUri(Uri uri) {
    StringBuilder filename = new StringBuilder();
    //        filename.append(uri.getScheme()).append("_")
    //                .append(uri.getHost()).append("_");
    String encodedPath = uri.getEncodedPath();
    if (!TextUtils.isEmpty(encodedPath)) {
        int length = encodedPath.length();
        if (length > 60) {
            encodedPath = encodedPath.substring(length - 60);
        }//from   w ww  . jav  a 2 s.  c o  m
        encodedPath = encodedPath.replace('/', '_');
        //            filename.append(encodedPath).append("_");
    }
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(uri.toString().getBytes("UTF-8"));
        byte[] digest = md.digest();
        for (byte b : digest) {
            if ((0xff & b) < 0x10) {
                filename.append("0").append(Integer.toHexString((0xFF & b)));
            } else {
                filename.append(Integer.toHexString(0xFF & b));
            }
        }
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        filename.append(uri.toString().hashCode());
    }

    return filename.toString();
}

From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java

public static String getCacheFilenameForUri(Uri uri) {
    StringBuilder filename = new StringBuilder();
    filename.append(uri.getScheme()).append("_").append(uri.getHost()).append("_");
    String encodedPath = uri.getEncodedPath();
    if (!TextUtils.isEmpty(encodedPath)) {
        int length = encodedPath.length();
        if (length > 60) {
            encodedPath = encodedPath.substring(length - 60);
        }//from  w  w w .ja va  2s.com
        encodedPath = encodedPath.replace('/', '_');
        filename.append(encodedPath).append("_");
    }
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(uri.toString().getBytes("UTF-8"));
        byte[] digest = md.digest();
        for (byte b : digest) {
            if ((0xff & b) < 0x10) {
                filename.append("0").append(Integer.toHexString((0xFF & b)));
            } else {
                filename.append(Integer.toHexString(0xFF & b));
            }
        }
    } catch (NoSuchAlgorithmException e) {
        filename.append(uri.toString().hashCode());
    } catch (UnsupportedEncodingException e) {
        filename.append(uri.toString().hashCode());
    }

    return filename.toString();
}

From source file:com.remobile.file.ContentFilesystem.java

@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
    if (!"content".equals(inputURL.getScheme())) {
        return null;
    }//from ww  w  . j a  v  a 2  s.c om
    String subPath = inputURL.getEncodedPath();
    if (subPath.length() > 0) {
        subPath = subPath.substring(1);
    }
    Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost")
            .path(name).appendPath(inputURL.getAuthority());
    if (subPath.length() > 0) {
        b.appendEncodedPath(subPath);
    }
    Uri localUri = b.encodedQuery(inputURL.getEncodedQuery()).encodedFragment(inputURL.getEncodedFragment())
            .build();
    return LocalFilesystemURL.parse(localUri);
}

From source file:com.remobile.file.AssetFilesystem.java

@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
    if (!"file".equals(inputURL.getScheme())) {
        return null;
    }//from  ww w  . ja v  a 2 s .com
    File f = new File(inputURL.getPath());
    // Removes and duplicate /s (e.g. file:///a//b/c)
    Uri resolvedUri = Uri.fromFile(f);
    String rootUriNoTrailingSlash = rootUri.getEncodedPath();
    rootUriNoTrailingSlash = rootUriNoTrailingSlash.substring(0, rootUriNoTrailingSlash.length() - 1);
    if (!resolvedUri.getEncodedPath().startsWith(rootUriNoTrailingSlash)) {
        return null;
    }
    String subPath = resolvedUri.getEncodedPath().substring(rootUriNoTrailingSlash.length());
    // Strip leading slash
    if (!subPath.isEmpty()) {
        subPath = subPath.substring(1);
    }
    Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost")
            .path(name);
    if (!subPath.isEmpty()) {
        b.appendEncodedPath(subPath);
    }
    if (isDirectory(subPath) || inputURL.getPath().endsWith("/")) {
        // Add trailing / for directories.
        b.appendEncodedPath("");
    }
    return LocalFilesystemURL.parse(b.build());
}

From source file:com.rokolabs.app.common.image.ImageFetcher.java

/**
 * The main process method, which will be called by the ImageWorker in the
 * AsyncTask background thread./*from  w  ww .j ava2  s. co  m*/
 * 
 * @param data
 *            The data to load the bitmap, in this case, a regular http URL
 * @return The downloaded and resized bitmap
 */
@Override
protected Bitmap processBitmap(ImageFetchTask data, int index) {
    if (Utils.DEBUG) {
        Log.d(TAG, "processBitmap - " + data.getImageUrl(index));
    }
    File temp = null;
    Bitmap bmp = null;
    boolean diskCache = true;
    try {
        String url = data.getImageUrl(index);
        Logger.d("image url: " + url);
        Uri uri = Uri.parse(url);
        if ("file".equalsIgnoreCase(uri.getScheme())) {
            Logger.d("encoded path: " + uri.getEncodedPath());
            diskCache = false;
            bmp = decodeSampledBitmapFromFile(uri.getEncodedPath(), data.getDesiredWidth(),
                    data.getDesiredHeight());
        } else if ("asset".equalsIgnoreCase(uri.getScheme())) {
            diskCache = false;
            String path = uri.getEncodedPath();
            if (path.startsWith("/"))
                path = path.substring(1);
            Logger.d("asset path: " + path);
            bmp = decodeSampledBitmapFromAsset(mResources.getAssets(), path, data.getDesiredWidth(),
                    data.getDesiredHeight());
        } else if ("content".equalsIgnoreCase(uri.getScheme())) {
            diskCache = false;
            Logger.d("content path: " + url);
            bmp = decodeSampledBitmapFromInputStream(mAppContext.getContentResolver().openInputStream(uri),
                    data.getDesiredWidth(), data.getDesiredHeight());
        } else if ("video".equals(uri.getScheme())) {
            Logger.d("encoded path: " + uri.getEncodedPath());
            bmp = ThumbnailUtils.createVideoThumbnail(uri.getEncodedPath(), Thumbnails.MINI_KIND);
        } else {
            Logger.d(tempDir.getAbsolutePath());
            if (mImageCache != null) {
                bmp = mImageCache.getBitmapFromDiskCache(data.getImageUrl(index), data.getDesiredWidth(),
                        data.getDesiredHeight());
            }
            if (bmp == null) {
                temp = File.createTempFile("img_" + Math.random(), ".jpg", tempDir);
                if (downloadUrlToStream(data.getImageUrl(index), new FileOutputStream(temp))) {
                    Logg.d(temp.getAbsolutePath() + ", size =" + temp.length());
                    bmp = decodeSampledBitmapFromFile(temp.getAbsolutePath(), data.getDesiredWidth(),
                            data.getDesiredHeight());
                    if (bmp != null && mImageCache != null
                            && data.getTaskCachePolicy() == CachePolicy.MEM_AND_DISK) {
                        mImageCache.saveBitmapToDisk(data.getImageUrl(index), temp);
                    } else {
                        if (temp.length() < 2 * 1024)
                            Logg.d("temp file: " + new String(IOUtils.toByteArray(new FileInputStream(temp))));
                        temp.delete();
                    }
                } else {
                    temp.delete();
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "processBitmap - " + e);
    } catch (OutOfMemoryError oom) {
        Logger.printMemory("OOM error " + data.getImageUrl(index));
    } finally {
        if (bmp != null && mImageCache != null && diskCache
                && data.getTaskCachePolicy() == CachePolicy.MEM_AND_DISK)
            mImageCache.saveBitmapToDisk(data.getStoreKey(index), bmp);
    }
    return bmp;
}

From source file:ca.rmen.android.scrumchatter.main.MainActivity.java

/**
 * Import the given database file. This will replace the current database.
 *//* ww  w  .  j a v  a  2 s  .  c o m*/
private void importDB(final Uri uri) {
    ScrumChatterDialog.showDialog(this, getString(R.string.import_confirm_title),
            getString(R.string.import_confirm_message, uri.getEncodedPath()), new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (which == DialogInterface.BUTTON_POSITIVE) {
                        AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
                            private ProgressDialog mProgressDialog;

                            @Override
                            protected void onPreExecute() {
                                mProgressDialog = ProgressDialog.show(MainActivity.this, null,
                                        getString(R.string.progress_dialog_message), true);
                            }

                            @Override
                            protected Boolean doInBackground(Void... params) {
                                try {
                                    Log.v(TAG, "Importing db from " + uri);
                                    DBImport.importDB(MainActivity.this, uri);
                                } catch (Exception e) {
                                    Log.e(TAG, "Error importing db: " + e.getMessage(), e);
                                    return false;
                                }
                                return true;
                            }

                            @Override
                            protected void onPostExecute(Boolean result) {
                                mProgressDialog.cancel();
                                Toast.makeText(MainActivity.this,
                                        result ? R.string.import_result_success : R.string.import_result_failed,
                                        Toast.LENGTH_SHORT).show();
                            }

                        };
                        task.execute();
                    }
                }
            });

}

From source file:fr.mixit.android.ui.MembersActivity.java

@Override
public void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode) {
    final Uri uri = intent.getData();
    if (uri != null && uri.getAuthority().equals(MixItContract.Members.CONTENT_URI.getAuthority())) {
        final boolean addToBackStack = intent.getBooleanExtra(IntentUtils.EXTRA_FROM_ADD_TO_BACKSTACK, false);
        final FragmentManager fm = getSupportFragmentManager();
        // MEMBER
        if (uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_MEMBERS)
                || uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_SPEAKERS)) {
            if (UIUtils.isTablet(this)) {
                if (addToBackStack) {
                    final MemberDetailsFragment frag = MemberDetailsFragment.newInstance(intent);
                    final FragmentTransaction ft = fm.beginTransaction();
                    ft.replace(R.id.content_member_details, frag);
                    ft.addToBackStack(null);
                    if (mTopFragCommitId == -1) {
                        mTopFragCommitId = ft.commit();
                    } else {
                        ft.commit();/*from   w w  w.ja  v  a  2  s .  co  m*/
                    }
                    return;
                } else {
                    if (mTopFragCommitId != -1) {
                        fm.popBackStack(mTopFragCommitId, FragmentManager.POP_BACK_STACK_INCLUSIVE);
                        mTopFragCommitId = -1;
                    }
                    if (mMemberDetailsFrag != null) {
                        final int memberId = Integer.parseInt(MixItContract.Members.getMemberId(uri));
                        mMemberDetailsFrag.setMemberId(memberId);
                        return;
                    } else {
                        Log.e(TAG, "no fragment member details found but device is tablet");
                    }
                }
            } else {
                super.startActivityFromFragment(fragment, intent, requestCode);
                return;
            }
        } else
        // SESSIONS
        if (uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_SESSIONS)
                || uri.getEncodedPath().startsWith(SLASH + MixItContract.PATH_LIGHTNINGS)) {
            if (UIUtils.isTablet(this)) {
                final SessionDetailsFragment frag = SessionDetailsFragment.newInstance(intent);
                final FragmentTransaction ft = fm.beginTransaction();
                ft.replace(R.id.content_member_details, frag);
                ft.addToBackStack(null);
                if (mTopFragCommitId == -1) {
                    mTopFragCommitId = ft.commit();
                } else {
                    ft.commit();
                }
                return;
            } else {
                super.startActivityFromFragment(fragment, intent, requestCode);
                return;
            }
        }
    }
    super.startActivityFromFragment(fragment, intent, requestCode);
}

From source file:com.remobile.file.LocalFilesystem.java

@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
    if (!"file".equals(inputURL.getScheme())) {
        return null;
    }/*from   w  ww  . j  a  va  2s.  co  m*/
    File f = new File(inputURL.getPath());
    // Removes and duplicate /s (e.g. file:///a//b/c)
    Uri resolvedUri = Uri.fromFile(f);
    String rootUriNoTrailingSlash = rootUri.getEncodedPath();
    rootUriNoTrailingSlash = rootUriNoTrailingSlash.substring(0, rootUriNoTrailingSlash.length() - 1);
    if (!resolvedUri.getEncodedPath().startsWith(rootUriNoTrailingSlash)) {
        return null;
    }
    String subPath = resolvedUri.getEncodedPath().substring(rootUriNoTrailingSlash.length());
    // Strip leading slash
    if (!subPath.isEmpty()) {
        subPath = subPath.substring(1);
    }
    Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost")
            .path(name);
    if (!subPath.isEmpty()) {
        b.appendEncodedPath(subPath);
    }
    if (f.isDirectory() || inputURL.getPath().endsWith("/")) {
        // Add trailing / for directories.
        b.appendEncodedPath("");
    }
    return LocalFilesystemURL.parse(b.build());
}