Example usage for android.net Uri getPath

List of usage examples for android.net Uri getPath

Introduction

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

Prototype

@Nullable
public abstract String getPath();

Source Link

Document

Gets the decoded path.

Usage

From source file:ca.frozen.rpicameraviewer.activities.SourceFragment.java

public Source getAndCheckEditedSource() {
    // get the updated source
    Source editedSource = getSource();

    // check the address
    if (forCamera || editedSource.connectionType == Source.ConnectionType.RawMulticast) {
        // make sure there's an address
        if (editedSource.address.isEmpty()) {
            App.error(getActivity(), R.string.error_no_address);
            return null;
        }/*w w w  .  j  a  va2  s. c  om*/

        try {
            // check the address
            Uri uri = Uri.parse(editedSource.address);

            // check IP addresses
            String address = uri.getPath();
            char c = address.charAt(0);
            if (c >= '0' && c <= '9') {
                if (!checkIpAddress(address)) {
                    App.error(getActivity(), R.string.error_bad_address);
                    return null;
                }
            }

            // use the port if it's there
            int port = uri.getPort();
            if (port != -1) {
                editedSource.address = editedSource.address.replace(":" + port, "");
                if (editedSource.port <= 0) {
                    editedSource.port = port;
                }
            }

            // for HTTP, remove the scheme if it's there
            if (editedSource.connectionType == Source.ConnectionType.RawHttp) {
                String scheme = uri.getScheme();
                if (scheme != null && !scheme.isEmpty()) {
                    editedSource.address = editedSource.address.substring(scheme.length() + 3);
                }
            }
        } catch (Exception ex) {
            App.error(getActivity(), R.string.error_bad_address);
            return null;
        }

        // make sure it's a valid multicast address
        if (editedSource.connectionType == Source.ConnectionType.RawMulticast) {
            int check = checkMulticastAddress(editedSource.address);
            if (check < 0) {
                App.error(getActivity(), R.string.error_bad_multicast_address);
                return null;
            } else if (check == 0) {
                Toast.makeText(getActivity(), R.string.warning_multicast_address, Toast.LENGTH_LONG).show();
            }
        }
    }

    // for settings, make sure there's a port
    if (!forCamera) {
        if (editedSource.port == 0) {
            App.error(getActivity(), R.string.error_no_port);
            return null;
        }
    }

    // make sure the port is within range
    if (editedSource.port != 0 && (editedSource.port < MIN_PORT || editedSource.port > MAX_PORT)) {
        App.error(getActivity(), String.format(getString(R.string.error_bad_port), MIN_PORT, MAX_PORT));
        return null;
    }

    // check the width
    if (editedSource.width < 0) {
        App.error(getActivity(), R.string.error_bad_width);
        return null;
    }

    // check the height
    if (editedSource.height < 0) {
        App.error(getActivity(), R.string.error_bad_height);
        return null;
    }

    // check the FPS
    if (editedSource.fps < 0) {
        App.error(getActivity(), R.string.error_bad_fps);
        return null;
    }

    // check the BPS
    if (editedSource.bps < 0) {
        App.error(getActivity(), R.string.error_bad_bps);
        return null;
    }

    // return the successfully edited source
    return editedSource;
}

From source file:com.gabm.fancyplaces.ui.MainWindow.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main_window);

    curAppContext = (FancyPlacesApplication) getApplicationContext();

    setDefaultTitle();//from  w w  w. j  a v a 2  s. c o m

    // inflate toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.main_window_toolbar);
    setSupportActionBar(toolbar);
    if (Build.VERSION.SDK_INT >= 19) {
        int padding_right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                getResources().getDisplayMetrics());
        toolbar.setPadding(toolbar.getPaddingLeft(), curAppContext.getStatusBarHeight(), padding_right, 0);
    }

    // store data
    fancyPlacesDatabase = new FancyPlacesDatabase(getApplicationContext());
    fancyPlacesDatabase.open();
    fancyPlaces = (ArrayList<FancyPlace>) fancyPlacesDatabase.getAllFancyPlaces();
    fancyPlaceArrayAdapter = new FancyPlacesArrayAdapter(getApplicationContext(),
            R.layout.list_item_fancy_place, fancyPlaces);

    ImageFile.curAppContext = curAppContext;

    // viewpager
    viewpagerAdapter = new MainWindowViewpagerAdapter(getApplicationContext(), getSupportFragmentManager(),
            createTabList());
    pager = (ViewPager) findViewById(R.id.main_window_viewpager);
    pager.setAdapter(viewpagerAdapter);

    // Asiging the Sliding Tab Layout View
    tabs = (SlidingTabLayout) findViewById(R.id.main_window_tabs);
    tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

    // Setting Custom Color for the Scroll bar indicator of the Tab View
    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.tabsScrollColor);
        }
    });

    // Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);

    // set current menu
    curState.curMenu = R.menu.menu_main_window;

    // check if we got called through an intent
    Uri u = getIntent().getData();
    if (u != null)
        loadFromFile(u.getPath());
}

From source file:com.polyvi.xface.extension.zip.XZipExt.java

/**
 * ?assets/*w  w  w  . j av  a2 s.c o m*/
 *
 * @param srcFileUri
 * @param zos
 * @param entry
 * @throws IOException
 * @throws FileNotFoundException
 */
private void compressNormalFile(Uri srcFileUri, ZipOutputStream zos, String entry)
        throws IOException, FileNotFoundException {
    File srcFile = new File(srcFileUri.getPath());
    if (null == srcFile || !srcFile.exists()) {
        XLog.e(CLASS_NAME, "Method compressNormalFile:Source file path does not exist!");
        throw new FileNotFoundException();
    }
    String[] dirList = srcFile.list();
    if ((null == dirList || 1 > dirList.length) && srcFile.isFile()) {
        // ??
        zipFile(srcFileUri, zos, srcFile.getName());
    } else {
        // ?
        String srcRootPath = srcFileUri.toString();
        String srcFilePath = null;
        for (String pathName : dirList) {
            srcFilePath = srcRootPath + File.separator + pathName;
            srcFileUri = Uri.parse(srcFilePath);
            File f = new File(srcFileUri.getPath());
            if (f.isDirectory()) {
                compressNormalFile(srcFileUri, zos, entry + f.getName() + File.separator);
                continue;
            }
            zipFile(srcFileUri, zos, entry + f.getName());
        }
    }
}

From source file:com.github.dfa.diaspora_android.ui.ContextMenuWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    HitTestResult result = getHitTestResult();

    MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            HitTestResult result = getHitTestResult();
            String url = result.getExtra();
            switch (item.getItemId()) {
            //Save image to external memory
            case ID_SAVE_IMAGE: {
                boolean writeToStoragePermitted = true;
                if (android.os.Build.VERSION.SDK_INT >= 23) {
                    int hasWRITE_EXTERNAL_STORAGE = parentActivity
                            .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                        writeToStoragePermitted = false;
                        if (!parentActivity.shouldShowRequestPermissionRationale(
                                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                            new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                    .setPositiveButton(context.getText(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (android.os.Build.VERSION.SDK_INT >= 23)
                                                        parentActivity.requestPermissions(new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                }
                                            })
                                    .setNegativeButton(context.getText(android.R.string.no), null).show();
                        }//www  .  jav  a2s  .c o m
                        parentActivity.requestPermissions(
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                    }
                }
                if (writeToStoragePermitted) {
                    if (url != null) {
                        Uri source = Uri.parse(url);
                        DownloadManager.Request request = new DownloadManager.Request(source);
                        File destinationFile = new File(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        request.setDestinationUri(Uri.fromFile(destinationFile));
                        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
                        Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location)
                                + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    }
                }
            }
                break;

            case ID_SHARE_IMAGE:
                if (url != null) {
                    boolean writeToStoragePermitted = true;
                    if (android.os.Build.VERSION.SDK_INT >= 23) {
                        int hasWRITE_EXTERNAL_STORAGE = parentActivity
                                .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                            writeToStoragePermitted = false;
                            if (!parentActivity.shouldShowRequestPermissionRationale(
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                        .setPositiveButton(context.getText(android.R.string.yes),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        if (android.os.Build.VERSION.SDK_INT >= 23)
                                                            parentActivity.requestPermissions(new String[] {
                                                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                    MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                    }
                                                })
                                        .setNegativeButton(context.getText(android.R.string.no), null).show();
                            } else {
                                parentActivity.requestPermissions(
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                            }
                        }
                    }
                    if (writeToStoragePermitted) {
                        final Uri local = Uri.parse(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        new ImageDownloadTask(null, local.getPath()) {
                            @Override
                            protected void onPostExecute(Bitmap result) {
                                Uri myUri = Uri.fromFile(new File(local.getPath()));
                                Intent sharingIntent = new Intent();
                                sharingIntent.setAction(Intent.ACTION_SEND);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
                                sharingIntent.setType("image/png");
                                sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                context.startActivity(Intent.createChooser(sharingIntent,
                                        getResources().getString(R.string.action_share_dotdotdot)));
                            }
                        }.execute(url);
                    }
                } else {
                    Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
                }

                break;

            case ID_IMAGE_EXTERNAL_BROWSER:
                if (url != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    context.startActivity(intent);
                }
                break;

            //Copy url to clipboard
            case ID_COPY_LINK:
                if (url != null) {
                    ClipboardManager clipboard = (ClipboardManager) context
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
                    Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            //Try to share link to other apps
            case ID_SHARE_LINK:
                if (url != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, url);
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent,
                            getResources().getText(R.string.context_menu_share_link)));
                }
                break;
            }
            return true;
        }
    };

    //Build context menu
    if (result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        // Menu options for an image.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0,
                context.getString(R.string.context_menu_open_external_browser))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image))
                .setOnMenuItemClickListener(handler);
    } else if (result.getType() == HitTestResult.ANCHOR_TYPE
            || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        // Menu options for a hyperlink.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link))
                .setOnMenuItemClickListener(handler);
    }
}

From source file:com.github.dfa.diaspora_android.web.ContextMenuWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    HitTestResult result = getHitTestResult();

    MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            HitTestResult result = getHitTestResult();
            String url = result.getExtra();
            switch (item.getItemId()) {
            //Save image to external memory
            case ID_SAVE_IMAGE: {
                boolean writeToStoragePermitted = true;
                if (android.os.Build.VERSION.SDK_INT >= 23) {
                    int hasWRITE_EXTERNAL_STORAGE = parentActivity
                            .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                        writeToStoragePermitted = false;
                        if (!parentActivity.shouldShowRequestPermissionRationale(
                                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                            new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                    .setPositiveButton(context.getText(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (android.os.Build.VERSION.SDK_INT >= 23)
                                                        parentActivity.requestPermissions(new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                }
                                            })
                                    .setNegativeButton(context.getText(android.R.string.no), null).show();
                        }//from w  w  w  . j  av  a2 s .  c o m
                        parentActivity.requestPermissions(
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                    }
                }
                if (writeToStoragePermitted) {
                    if (url != null) {
                        Uri source = Uri.parse(url);
                        DownloadManager.Request request = new DownloadManager.Request(source);
                        File destinationFile = new File(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        request.setDestinationUri(Uri.fromFile(destinationFile));
                        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);

                        Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location)
                                + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    }
                }
            }
                break;

            case ID_SHARE_IMAGE:
                if (url != null) {
                    boolean writeToStoragePermitted = true;
                    if (android.os.Build.VERSION.SDK_INT >= 23) {
                        int hasWRITE_EXTERNAL_STORAGE = parentActivity
                                .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                            writeToStoragePermitted = false;
                            if (!parentActivity.shouldShowRequestPermissionRationale(
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                        .setPositiveButton(context.getText(android.R.string.yes),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        if (android.os.Build.VERSION.SDK_INT >= 23)
                                                            parentActivity.requestPermissions(new String[] {
                                                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                    MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                    }
                                                })
                                        .setNegativeButton(context.getText(android.R.string.no), null).show();
                            } else {
                                parentActivity.requestPermissions(
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                            }
                        }
                    }
                    if (writeToStoragePermitted) {
                        final Uri local = Uri.parse(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        new ImageDownloadTask(null, local.getPath()) {
                            @Override
                            protected void onPostExecute(Bitmap result) {
                                Uri myUri = Uri.fromFile(new File(local.getPath()));
                                Intent sharingIntent = new Intent();
                                sharingIntent.setAction(Intent.ACTION_SEND);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
                                sharingIntent.setType("image/png");
                                sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                context.startActivity(Intent.createChooser(sharingIntent,
                                        getResources().getString(R.string.action_share_dotdotdot)));
                            }
                        }.execute(url);
                    }
                } else {
                    Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
                }

                break;

            case ID_IMAGE_EXTERNAL_BROWSER:
                if (url != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    context.startActivity(intent);
                }
                break;

            //Copy url to clipboard
            case ID_COPY_LINK:
                if (url != null) {
                    ClipboardManager clipboard = (ClipboardManager) context
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
                    Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            //Try to share link to other apps
            case ID_SHARE_LINK:
                if (url != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, url);
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent,
                            getResources().getText(R.string.context_menu_share_link)));
                }
                break;
            }
            return true;
        }
    };

    //Build context menu
    if (result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        // Menu options for an image.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0,
                context.getString(R.string.context_menu_open_external_browser))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image))
                .setOnMenuItemClickListener(handler);
    } else if (result.getType() == HitTestResult.ANCHOR_TYPE
            || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        // Menu options for a hyperlink.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link))
                .setOnMenuItemClickListener(handler);
    }
}

From source file:com.mobility.android.ui.vehicle.AddVehicleActivity.java

private File getFileFromUri(Uri contentURI) {
    String result;/*from w w  w.java  2 s . c om*/
    Cursor cursor = getContentResolver().query(contentURI, null, null, null, null);

    if (cursor == null) {
        result = contentURI.getPath();
    } else {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }

    return new File(result);
}

From source file:com.geekandroid.sdk.sample.crop.ResultActivity.java

private void copyFileToDownloads(Uri croppedFileUri) throws Exception {
    String downloadsDirectoryPath = Environment
            .getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
    String filename = String.format("%d_%s", Calendar.getInstance().getTimeInMillis(),
            croppedFileUri.getLastPathSegment());

    File saveFile = new File(downloadsDirectoryPath, filename);

    FileInputStream inStream = new FileInputStream(new File(croppedFileUri.getPath()));
    FileOutputStream outStream = new FileOutputStream(saveFile);
    FileChannel inChannel = inStream.getChannel();
    FileChannel outChannel = outStream.getChannel();
    inChannel.transferTo(0, inChannel.size(), outChannel);
    inStream.close();//w  w  w .j  av a 2 s . c om
    outStream.close();

    showNotification(saveFile);
}

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

@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
    if (!"file".equals(inputURL.getScheme())) {
        return null;
    }//from  w ww  .  jav a  2s .  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 (f.isDirectory() || inputURL.getPath().endsWith("/")) {
        // Add trailing / for directories.
        b.appendEncodedPath("");
    }
    return LocalFilesystemURL.parse(b.build());
}

From source file:com.ls.sip.CameraFragment.java

private void recordVideo() {
    if (isVideoRecording) {
        try {//from w  w  w.ja va  2 s  .c om
            ctlr.stopVideoRecording();
        } catch (Exception e) {
            Log.e(getClass().getSimpleName(), "Exception stopping recording of video", e);
            // TODO: um, do something here
        }
    } else {
        try {
            VideoTransaction.Builder b = new VideoTransaction.Builder();
            Uri output = getArguments().getParcelable(ARG_OUTPUT);
            if (output == null) {
                // TODO: um, do something here
                return;
            }

            b.to(new File(output.getPath())).quality(getArguments().getInt(ARG_VIDEO_QUALITY, 1))
                    .sizeLimit(getArguments().getInt(ARG_SIZE_LIMIT, 0))
                    .durationLimit(getArguments().getInt(ARG_DURATION_LIMIT, 0));

            ctlr.recordVideo(b.build());
            isVideoRecording = true;
            btnTakePicture.setImageResource(R.drawable.cwac_cam2_ic_stop);
        } catch (Exception e) {
            Log.e(getClass().getSimpleName(), "Exception recording video", e);
            // TODO: um, do something here
        }
    }
}

From source file:com.kanedias.vanilla.lyrics.LyricsShowActivity.java

/**
 * Try to load lyrics tag from companion *.lrc file nearby
 *
 * @return true if lyrics was loaded from file, false otherwise
 *///www. ja  va 2s.  c  o m
private boolean loadFromFile() {
    // used didn't write any *.lrc file, skip loading
    // better, should we ask user for it in a dialog?
    if (!PluginUtils.havePermissions(this, WRITE_EXTERNAL_STORAGE)) {
        return false;
    }

    Uri fileUri = getIntent().getParcelableExtra(EXTRA_PARAM_URI);
    if (fileUri == null || fileUri.getPath() == null) {
        // wrong intent passed?
        return false;
    }

    File media = new File(fileUri.getPath());
    String lyricsFileName = lyricsForFile(media);
    File lyricsFile = new File(media.getParentFile(), lyricsFileName);
    if (!lyricsFile.exists()) {
        return false;
    }

    try {
        String lyricsText = new String(PluginUtils.readFully(new FileInputStream(lyricsFile)), "UTF-8");
        showFetchedLyrics(lyricsText);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Failed to read lyrics text from file!", e);
        return false;
    }
    return true;
}