List of usage examples for android.net Uri getLastPathSegment
@Nullable public abstract String getLastPathSegment();
From source file:mobisocial.socialkit.musubi.Musubi.java
public DbIdentity userForLocalId(Uri feedUri, long localId) { DbIdentity cachedUser = sUserCache.get(localId); if (cachedUser != null) { return cachedUser; }/*from www . j av a 2 s . c om*/ String feedName; if (feedUri != null) { feedName = feedUri.getLastPathSegment(); } else { feedName = "friend"; } Uri uri = uriForItem(DbThing.IDENTITY, localId); String[] projection = { DbIdentity.COL_ID_HASH, DbIdentity.COL_NAME }; String selection = DbIdentity.COL_IDENTITY_ID + " = ?"; String[] selectionArgs = new String[] { Long.toString(localId) }; String sortOrder = null; Cursor c = mContext.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); if (c == null) { Log.w(Musubi.TAG, "Null cursor for user query " + localId); return null; } try { if (!c.moveToFirst()) { Log.w(Musubi.TAG, "No user found for " + localId + " in " + feedName, new Throwable()); return null; } DbIdentity user = DbIdentity.fromStandardCursor(mContext, c); sUserCache.put(localId, user); return user; } finally { c.close(); } }
From source file:com.deliciousdroid.activity.FragmentBaseActivity.java
@Override @TargetApi(14)/*from w ww . j av a 2s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; mAccountManager = AccountManager.get(this); settings = PreferenceManager.getDefaultSharedPreferences(this); loadSettings(); init(); if (android.os.Build.VERSION.SDK_INT >= 14) { getActionBar().setHomeButtonEnabled(true); } Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction()) && !intent.hasExtra("MainSearchResults")) { if (intent.hasExtra(SearchManager.QUERY)) { Intent i = new Intent(this, MainSearchResults.class); i.putExtras(intent.getExtras()); startActivity(i); finish(); } else { onSearchRequested(); } } else if (Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) { Uri data = intent.getData(); String path = null; String tagname = null; if (data != null) { path = data.getPath(); tagname = data.getQueryParameter("tagname"); } if (data.getScheme() == null || !data.getScheme().equals("content")) { Intent i = new Intent(Intent.ACTION_VIEW, data); startActivity(i); finish(); } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment()) && intent.hasExtra(SearchManager.USER_QUERY)) { Intent viewBookmark = new Intent(this, ViewBookmark.class); viewBookmark.setAction(Intent.ACTION_VIEW); viewBookmark.setData(data); viewBookmark.removeExtra(SearchManager.USER_QUERY); Log.d("View Bookmark Uri", data.toString()); startActivity(viewBookmark); finish(); } else if (tagname != null) { Intent viewTags = new Intent(this, BrowseBookmarks.class); viewTags.setData(data); Log.d("View Tags Uri", data.toString()); startActivity(viewTags); finish(); } } }
From source file:com.nextgis.woody.activity.EditActivity.java
private void save() throws NGException { // Add constant values values.put(Constants.FIELD_DATETIME, Calendar.getInstance().getTimeInMillis()); AccountUtil.AccountData accountData; try {//from www . ja v a 2s .c o m accountData = AccountUtil.getAccountData(this, Constants.ACCOUNT_NAME); values.put(Constants.FIELD_REPORTER, accountData.login); } catch (IllegalStateException e) { throw new NGException(getString(com.nextgis.maplib.R.string.error_auth)); } // Create or change feature IGISApplication app = (IGISApplication) getApplication(); if (null == app) { throw new IllegalArgumentException("Not a IGISApplication"); } Uri uri = Uri.parse("content://" + app.getAuthority() + "/" + Constants.KEY_MAIN); if (mFeatureId == NOT_FOUND) { // we need to get proper mFeatureId for new features first Uri result = getContentResolver().insert(uri, values); if (result == null) { Toast.makeText(this, getText(com.nextgis.maplibui.R.string.error_db_insert), Toast.LENGTH_SHORT) .show(); return; } else { mFeatureId = Long.parseLong(result.getLastPathSegment()); } } else { Uri updateUri = ContentUris.withAppendedId(uri, mFeatureId); boolean valuesUpdated = getContentResolver().update(updateUri, values, null, null) == 1; if (!valuesUpdated) { Toast.makeText(this, getText(com.nextgis.maplibui.R.string.error_db_update), Toast.LENGTH_SHORT) .show(); return; } } // add photos putAttaches(); finish(); }
From source file:com.app.uafeed.fragment.EntryFragment.java
public void setData(Uri uri) { mCurrentPagerPos = -1;/*from w ww.j ava2s .c o m*/ mBaseUri = FeedData.EntryColumns.PARENT_URI(uri.getPath()); try { mInitialEntryId = Long.parseLong(uri.getLastPathSegment()); } catch (Exception unused) { mInitialEntryId = -1; } if (mBaseUri != null) { Bundle b = getActivity().getIntent().getExtras(); String whereClause = FeedData.shouldShowReadEntries(mBaseUri) || (b != null && b.getBoolean(Constants.INTENT_FROM_WIDGET, false)) ? null : EntryColumns.WHERE_UNREAD; // Load the entriesIds list. Should be in a loader... but I was too lazy to do so Cursor entriesCursor = MainApplication.getContext().getContentResolver().query(mBaseUri, EntryColumns.PROJECTION_ID, whereClause, null, EntryColumns.DATE + Constants.DB_DESC); if (entriesCursor != null && entriesCursor.getCount() > 0) { mEntriesIds = new long[entriesCursor.getCount()]; int i = 0; while (entriesCursor.moveToNext()) { mEntriesIds[i] = entriesCursor.getLong(0); if (mEntriesIds[i] == mInitialEntryId) { mCurrentPagerPos = i; // To immediately display the good entry } i++; } entriesCursor.close(); } } else { mEntriesIds = null; } mEntryPagerAdapter.notifyDataSetChanged(); if (mCurrentPagerPos != -1) { mEntryPager.setCurrentItem(mCurrentPagerPos); } }
From source file:com.polyvi.xface.extension.zip.XZipExt.java
/** * assets//from w w w .j a v a2 s .c o m * * @param srcFileUri * @param zos * @param entry * @throws IOException */ private void compressAssetsFile(Uri srcFileUri, ZipOutputStream zos, String entry) throws IOException, FileNotFoundException { srcFileUri = handleUri(srcFileUri); String srcPath = srcFileUri.getPath().substring(XConstant.ANDROID_ASSET.length()); if (XAssetsFileUtils.isFile(mContext, srcPath)) { zipFile(srcFileUri, zos, entry + srcFileUri.getLastPathSegment()); } else { String childrens[] = mContext.getAssets().list(srcPath); if (null == childrens || 0 == childrens.length) { XLog.e(CLASS_NAME, "Method compressAssetsFile: Source file path does not exist!"); throw new FileNotFoundException(); } Uri srcRootUri = srcFileUri; for (int index = 0; index < childrens.length; index++) { srcFileUri = Uri.parse(srcRootUri.toString() + File.separator + childrens[index]); if (XAssetsFileUtils.isFile(mContext, srcPath + File.separator + childrens[index])) { zipFile(srcFileUri, zos, entry + childrens[index]); } else { compressAssetsFile(srcFileUri, zos, entry + childrens[index] + File.separator); } } } }
From source file:com.renard.ocr.OCRActivity.java
private void saveDocument(final Pix pix, final String hocrString, final String utf8String, final boolean checkSd) { // if (checkSd && !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { // waitForSdCard(pix, hocrString, utf8String); // } else { Util.startBackgroundJob(OCRActivity.this, "", getText(R.string.saving_document).toString(), new Runnable() { @Override//from w w w. ja v a 2 s . c om public void run() { File imageFile = null; Uri documentUri = null; try { if (checkSd) { imageFile = saveImage(pix); } documentUri = saveDocumentToDB(imageFile, hocrString, utf8String); Util.createThumbnail(OCRActivity.this, imageFile, Integer.valueOf(documentUri.getLastPathSegment())); } catch (RemoteException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getText(R.string.error_create_file), Toast.LENGTH_LONG).show(); } }); } catch (IOException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), getText(R.string.error_create_file), Toast.LENGTH_LONG).show(); } }); } finally { if (pix != null) { pix.recycle(); } if (documentUri != null) { Intent i = new Intent(OCRActivity.this, DocumentActivity.class); i.putExtra(DocumentActivity.EXTRA_ASK_FOR_TITLE, true); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setData(documentUri); startActivity(i); finish(); } } } }, new Handler()); // } }
From source file:com.kyakujin.android.autoeco.ui.MainActivity.java
private int createManualData() { ContentValues cv = new ContentValues(); cv.put(ManualTbl.NAME, Conf.NONE);//from ww w . jav a 2 s . co m Uri uri = getContentResolver().insert(ManualTbl.CONTENT_URI, cv); if (uri == null) return 0; mManualId = Integer.valueOf(uri.getLastPathSegment()); return mManualId; }
From source file:edu.stanford.mobisocial.dungbeetle.MessagingManagerThread.java
private List<Long> getFeedSubscribers(Uri feedUri) { if (feedUri == null) { throw new NullPointerException("Feed cannot be null"); }//w ww .j ava 2s. c o m String feedName = feedUri.getLastPathSegment(); switch (Feed.typeOf(feedUri)) { case FRIEND: String personId = Feed.friendIdForFeed(feedUri); if (personId == null) { return new ArrayList<Long>(0); } String table = Contact.TABLE; String[] columns = new String[] { Contact._ID }; String selection = Contact.PERSON_ID + " = ?"; String[] selectionArgs = new String[] { personId }; String groupBy = null; String having = null; String orderBy = null; Cursor c = mHelper.getReadableDatabase().query(table, columns, selection, selectionArgs, groupBy, having, orderBy); if (c == null || !c.moveToFirst()) { Log.w(TAG, "Could not find user for id " + personId); return new ArrayList<Long>(0); } return Collections.singletonList(c.getLong(0)); case APP: // Currently, we send app messages to all users, which are registered // as subscribers to the "friend" feed. The subscribers model needs to // be reworked, and further the "app" feed needs further thinking. // Messages should be lossy, and encryption should not require keys // for each recipient. feedName = "friend"; // No break: case GROUP: Cursor subs = mHelper.querySubscribers(feedName); List<Long> recipientIds = new ArrayList<Long>(subs.getCount()); subs.moveToFirst(); while (!subs.isAfterLast()) { long id = subs.getLong(subs.getColumnIndexOrThrow(Subscriber.CONTACT_ID)); recipientIds.add(id); subs.moveToNext(); } subs.close(); return recipientIds; default: Log.w(TAG, "unmatched feed type for " + feedUri); return new ArrayList<Long>(); } }
From source file:com.kyakujin.android.autoeco.ui.MainActivity.java
private int createBatteryData() { ContentValues cv = new ContentValues(); cv.put(BatteryTbl.ENABLED, 1);/*from w ww.j av a 2 s. co m*/ cv.put(BatteryTbl.THRESHOLD, 30); Uri uri = getContentResolver().insert(BatteryTbl.CONTENT_URI, cv); if (uri == null) return 0; mBatteryId = Integer.valueOf(uri.getLastPathSegment()); return mBatteryId; }
From source file:org.cgnet.swara.fragment.EntryFragment.java
@Override public void onClickEnclosure() { getActivity().runOnUiThread(new Runnable() { //TODO/*w w w. j a v a2 s.co m*/ @Override public void run() { final String enclosure = mEntryPagerAdapter.getCursor(mCurrentPagerPos).getString(mEnclosurePos); final int position1 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR); final int position2 = enclosure.indexOf(Constants.ENCLOSURE_SEPARATOR, position1 + 3); final Uri uri = Uri.parse(enclosure.substring(0, position1)); final String filename = uri.getLastPathSegment(); t.send(new HitBuilders.EventBuilder().setCategory("Button to download audio file was clicked on") .setAction(filename).build()); new AlertDialog.Builder(getActivity()).setTitle(R.string.open_enclosure) // .setMessage(getString(R.string.file) + ": " + filename) .setNegativeButton(R.string.cancel_phone, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // showEnclosure(uri, enclosure, position1, position2); t.send(new HitBuilders.EventBuilder() .setCategory("Button to download audio file was clicked on") .setAction(filename).setValue(0).build()); } }).setPositiveButton(R.string.download_and_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { t.send(new HitBuilders.EventBuilder() .setCategory("Button to download audio file was clicked on") .setAction(filename).setValue(1).build()); DownloadManager.Request r = new DownloadManager.Request(uri); r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename); r.allowScanningByMediaScanner(); r.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); r.setVisibleInDownloadsUi(true); String name = new File(uri.toString()).getName(); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); path += "/CGNet_Swara"; File dir = new File(path); if (!dir.exists() || !dir.isDirectory()) { dir.mkdirs(); } r.setDestinationInExternalPublicDir("CGNet_Swara", name); DownloadManager dm = (DownloadManager) MainApplication.getContext() .getSystemService(Context.DOWNLOAD_SERVICE); dm.enqueue(r); Cursor c = mEntryPagerAdapter.getCursor(mCurrentPagerPos); refreshUI(c); // TODO } catch (Exception e) { Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_LONG).show(); } } }).show(); } }); }