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:com.polyvi.xface.extension.zip.XZipExt.java

/**
 * Uri???//from  ww  w .j  a  va 2s. c  o  m
 *
 * @param fileAbsPath
 * @return true: ??false: 
 */
private boolean isFileUriValid(Uri fileUri) {
    return XFileUtils.isFilePathValid(fileUri.getPath());
}

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

/**
 * ?zip?/*from w  w w .  j av  a2 s. co  m*/
 *
 * @param dstFileUri
 */
private void prepareForZipDir(Uri dstFileUri) {
    File zipFile = new File(dstFileUri.getPath());
    if (zipFile.exists()) {
        zipFile.delete();
    }
    File zipFileParent = zipFile.getParentFile();
    if (!zipFileParent.exists()) {
        zipFileParent.mkdirs();
    }
}

From source file:com.gsma.rcs.provisioning.local.Provisioning.java

/**
 * Read a text file and convert it into a string
 *
 * @param provisioningFile Uri for the file
 * @return the result string//  ww w .  jav a 2 s .  c  om
 * @throws IOException
 */
private String getFileContent(Uri provisioningFile) throws IOException {
    File file = new File(provisioningFile.getPath());
    StringBuilder text = new StringBuilder();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
        return text.toString();

    } finally {
        // noinspection ThrowableResultOfMethodCallIgnored
        CloseableUtils.tryToClose(br);
    }
}

From source file:com.example.parking.ParkingInformationActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null) {
        switch (requestCode) {
        case TAKE_PHOTO: //?
            if (data.getData() != null || data.getExtras() != null) { //
                Uri uri = data.getData();
                if (uri != null) {
                    if (mEnterImage == null) {
                        mEnterImage = BitmapFactory.decodeFile(uri.getPath()); //
                    }//from   ww  w.  j  a  va 2  s  .c  om
                }
                Bundle bundle = data.getExtras();
                if (bundle != null) {
                    if (mEnterImage == null) {
                        mEnterImage = (Bitmap) bundle.get("data");
                    }
                }
            }
            if (mEnterImage != null) {
                mEnterImageIV.setImageBitmap(mEnterImage);
            }
            break;

        }
    }

}

From source file:com.example.user.lstapp.CreatePlaceFragment.java

/**
 * Photo Selection result/*  ww w.  j  a  va  2  s .  c  o  m*/
 */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SELECT_PHOTO && resultCode == Activity.RESULT_OK) {
        HomeActivity activity = (HomeActivity) getActivity();
        Bitmap bitmap = getBitmapFromCameraData(data, activity);
        poster.setImageBitmap(bitmap);

        Uri selectedImageUri = data.getData();

        String filemanagerstring = selectedImageUri.getPath();
        posterPath = getRealPathFromURI(activity, selectedImageUri);
        Log.d("LST", posterPath);
    }
}

From source file:com.activiti.android.app.fragments.account.AccountEditFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getArguments() != null) {
        accountId = getArguments().getLong(ARGUMENT_ACCOUNT_ID);
    }// w w w . j  a v  a  2  s . c  om
    acc = ActivitiAccountManager.getInstance(getActivity()).getByAccountId(accountId);
    Uri serverUri = Uri.parse(acc.getServerUrl());

    if (serverUri.getPath().equals("/activiti-app")) {
        // It's default url
        https = ("https".equals(serverUri.getScheme().toLowerCase()));
        hostname = serverUri.getAuthority();
    } else {
        // It's not default we display full url in hostname
        hostname = acc.getServerUrl();
        hide(R.id.signing_https);
    }

    // TITLE
    TextView tv = (TextView) viewById(R.id.signin_title);
    tv.setText(R.string.settings_userinfo_account_summary);

    // USERNAME
    mEmailView = (MaterialAutoCompleteTextView) viewById(R.id.username);
    Account[] accounts = AccountManager.get(getActivity()).getAccounts();
    List<String> names = new ArrayList<>(accounts.length);
    String accountName;
    for (int i = 0; i < accounts.length; i++) {
        accountName = accounts[i].name;
        if (!TextUtils.isEmpty(accountName) && !names.contains(accountName)) {
            names.add(accounts[i].name);
        }
    }
    ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, names);
    mEmailView.setAdapter(adapter);
    mEmailView.setText(acc.getUsername());

    // PASSWORD
    mPasswordView = (EditText) viewById(R.id.password);
    mPasswordView.setText(acc.getPassword());

    Button mEmailSignInButton = (Button) viewById(R.id.email_sign_in_button);
    mEmailSignInButton.setText(R.string.general_action_confirm);
    mEmailSignInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });

    mProgressView = viewById(R.id.login_progress);
    mFormView = viewById(R.id.login_form);

    // Server part
    httpsView = (CheckBox) viewById(R.id.signing_https);
    httpsView.setChecked(https);
    hostnameView = (MaterialEditText) viewById(R.id.signing_hostname);
    hostnameView.setText(hostname);

    show(R.id.server_form);
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

/**
 * Create a path where we will place our private file on external
 * /*from www .j a v  a 2 s  .  co m*/
 * @param mContext
 * @param uri
 * @return
 */
public static File createExternalStoragePrivateFile(Context mContext, Uri uri, String extension) {

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show();
        return null;
    }
    File file = createNewAttachmentFile(mContext, extension);

    InputStream is;
    OutputStream os;
    try {
        is = mContext.getContentResolver().openInputStream(uri);
        os = new FileOutputStream(file);
        copyFile(is, os);
    } catch (IOException e) {
        try {
            //            InputStream is = new FileInputStream(uri.getPath());
            is = new FileInputStream(FileHelper.getPath(mContext, uri));
            os = new FileOutputStream(file);
            copyFile(is, os);
            // It's a path!!
        } catch (NullPointerException e1) {
            try {
                is = new FileInputStream(uri.getPath());
                os = new FileOutputStream(file);
                copyFile(is, os);
            } catch (FileNotFoundException e2) {
                Log.e(Constants.TAG, "Error writing " + file, e2);
                file = null;
            }
        } catch (FileNotFoundException e2) {
            Log.e(Constants.TAG, "Error writing " + file, e2);
            file = null;
        }
    }
    return file;
}

From source file:com.morphoss.acal.service.UpdateTimezones.java

private void refreshTimezoneData() {
    try {/*from  www .  j  a v  a 2 s. c  o  m*/
        HashMap<String, Long> currentZones = new HashMap<String, Long>();
        HashMap<String, Long> updatedZones = new HashMap<String, Long>();
        HashMap<String, Long> insertedZones = new HashMap<String, Long>();
        Cursor allZones = cr.query(Timezones.CONTENT_URI,
                new String[] { Timezones.TZID, Timezones.LAST_MODIFIED }, null, null, null);
        Long maxModified = 0L;
        for (allZones.moveToFirst(); !allZones.isAfterLast(); allZones.moveToNext()) {
            if (Constants.LOG_VERBOSE)
                Log.println(Constants.LOGV, TAG, "Found existing zone of '" + allZones.getString(0)
                        + "' modified: " + AcalDateTime.fromMillis(allZones.getLong(1) * 1000L).toString());
            currentZones.put(allZones.getString(0), allZones.getLong(1));
            if (allZones.getLong(1) > maxModified)
                maxModified = allZones.getLong(1);
        }
        AcalDateTime mostRecentChange = AcalDateTime.getUTCInstance().setEpoch(maxModified);
        Log.println(Constants.LOGI, TAG, "Found " + allZones.getCount()
                + " existing timezones, most recent change on " + mostRecentChange.toString());
        if (allZones.getCount() > 350 && mostRecentChange.after(AcalDateTime.getUTCInstance().addDays(-30))) {
            Log.println(Constants.LOGI, TAG, "Skipping update - our database is pretty recent");
            return;
        }

        requestor.interpretUriString(tzUrl("list", null));
        JSONObject root = requestor.doJsonRequest("GET", null, null, null);
        if (requestor.wasRedirected()) {
            Uri tzUri = Uri.parse(requestor.fullUrl());
            String redirectedUrl = tzUri.getScheme() + "://" + tzUri.getAuthority() + tzUri.getPath();
            if (Constants.debugTimeZone && Constants.LOG_DEBUG)
                Log.println(Constants.LOGD, TAG, "Redirected to Timezone Server at " + redirectedUrl);
            tzServerBaseUrl = redirectedUrl;
            AcalApplication.setPreferenceString(PrefNames.tzServerBaseUrl, redirectedUrl);
        }
        if (requestor.getStatusCode() >= 399) {
            Log.println(Constants.LOGI, TAG, "Bad response " + requestor.getStatusCode()
                    + " from Timezone Server at " + tzUrl("list", null));
        }
        if (root == null) {
            Log.println(Constants.LOGI, TAG, "No JSON from GET " + tzUrl("list", null));
            return;
        }

        String tzid;
        String tzData = "";
        long lastModified;
        StringBuilder localNames;
        StringBuilder aliases;
        ContentValues zoneValues = new ContentValues();

        String tzDateStamp = root.getString("dtstamp");
        JSONArray tzArray = root.getJSONArray("timezones");
        for (int i = 0; i < tzArray.length(); i++) {
            JSONObject zoneNode = tzArray.getJSONObject(i);
            tzid = zoneNode.getString("tzid");
            if (updatedZones.containsKey(tzid) || insertedZones.containsKey(tzid))
                continue;

            if (Constants.debugTimeZone && Constants.LOG_DEBUG)
                Log.println(Constants.LOGD, TAG, "Working on " + tzid);

            lastModified = AcalDateTime.fromString(zoneNode.getString("last-modified")).getEpoch();
            if (currentZones.containsKey(tzid) && currentZones.get(tzid) <= lastModified) {
                currentZones.remove(tzid);
                continue;
            }

            tzData = getTimeZone(tzid);
            if (tzData == null)
                continue;

            localNames = new StringBuilder();
            try {
                JSONArray nameNodes = zoneNode.getJSONArray("local_names");
                for (int j = 0; j < nameNodes.length(); j++) {
                    if (localNames.length() > 0)
                        localNames.append("\n");
                    localNames.append(nameNodes.getJSONObject(j).getString("lang")).append('~')
                            .append(nameNodes.getJSONObject(j).getString("lname"));
                }
            } catch (JSONException je) {
            }

            aliases = new StringBuilder();
            try {
                JSONArray aliasNodes = zoneNode.getJSONArray("aliases");
                for (int j = 0; j < aliasNodes.length(); j++) {
                    if (aliases.length() > 0)
                        aliases.append("\n");
                    aliases.append(aliasNodes.getString(j));
                }
            } catch (JSONException je) {
            }

            zoneValues.put(Timezones.TZID, tzid);
            zoneValues.put(Timezones.ZONE_DATA, tzData);
            zoneValues.put(Timezones.LAST_MODIFIED, lastModified);
            zoneValues.put(Timezones.TZ_NAMES, localNames.toString());
            zoneValues.put(Timezones.TZID_ALIASES, aliases.toString());

            Uri tzUri = Uri.withAppendedPath(Timezones.CONTENT_URI,
                    "tzid/" + StaticHelpers.urlescape(tzid, false));

            if (currentZones.containsKey(tzid)) {
                if (cr.update(tzUri, zoneValues, null, null) != 1) {
                    Log.e(TAG, "Failed update for TZID '" + tzid + "'");
                }
                updatedZones.put(tzid, currentZones.get(tzid));
                currentZones.remove(tzid);
            } else {
                if (cr.insert(tzUri, zoneValues) == null)
                    Log.e(TAG, "Failed insert for TZID '" + tzid + "'");
                insertedZones.put(tzid, currentZones.get(tzid));
            }

            if (context.workWaiting()) {
                Log.println(Constants.LOGI, TAG, "Something is waiting - deferring timezone sync until later.");
                deferMe = true;
                break;
            }
            // Let other stuff have a chance
            Thread.sleep(350);
        }
        int removed = 0;

        if (currentZones.size() > 0) {
            StringBuilder s = new StringBuilder();
            for (String tz : currentZones.keySet()) {
                if (s.length() > 0)
                    s.append(',');
                s.append("'").append(tz).append("'");
            }
            removed = cr.delete(Timezones.CONTENT_URI, Timezones.TZID + " IN (" + s + ")", null);
        }

        Log.println(Constants.LOGI, TAG, "Updated data for " + updatedZones.size() + " zones, added data for "
                + insertedZones.size() + " new zones, removed data for " + removed);
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}

From source file:com.polyvi.xface.extension.security.XSecurityExt.java

/**
 * ???/*from ww w  .  j  a v a  2  s .  c o  m*/
 *
 * @param filePath
 *            ???
 * @return ?
 * @throws IOException
 */
private InputStream readFile(String filePath) throws IllegalArgumentException, IOException {
    Uri fileUri = resolveUri(filePath);
    if (!XFileUtils.isFilePathValid(fileUri.getPath())) {
        throw new IllegalArgumentException();
    }
    InputStream inputStream = mResourceApi.openForRead(fileUri).inputStream;
    if (null == inputStream) {
        throw new FileNotFoundException();
    }
    return inputStream;
}

From source file:com.applozic.mobicommons.file.FileUtils.java

/**
 * @param uri/*  ww w  . j a  v a 2  s.c o  m*/
 * @param context
 * @return
 */
public static String getFileName(Context context, Uri uri) {

    String fileName = null;
    if (uri.getScheme().equals("content")) {
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        if (cursor != null) {
            try {
                if (cursor.moveToFirst()) {
                    fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                cursor.close();
            }
        }
    }
    if (TextUtils.isEmpty(fileName)) {
        fileName = uri.getPath();
        int cut = fileName.lastIndexOf('/');
        if (cut != -1) {
            fileName = fileName.substring(cut + 1);
        }
    }
    return fileName;
}