List of usage examples for android.net Uri hashCode
public int hashCode()
From source file:com.swater.meimeng.activity.oomimg.ImageCache.java
/** * Returns an opaque cache key representing the given uri, width and height. * * @param uri/*from ww w .ja v a 2 s . c o m*/ * an image uri * @param width * the desired image max width * @param height * the desired image max height * @return a cache key unique to the given parameters */ public String getKey(Uri uri, int width, int height) { // collisions are possible, but unlikely. final int hashId = uri.hashCode() + width + height * 10000; String key = mKeyCache.get(hashId); if (key == null) { key = uri.buildUpon().appendQueryParameter("width", String.valueOf(width)) .appendQueryParameter("height", String.valueOf(height)).build().toString(); mKeyCache.put(hashId, key); } return key; }
From source file:android.support.content.Query.java
@VisibleForTesting Query(@NonNull Uri uri, @Nullable String[] projection, @NonNull Bundle args, @Nullable CancellationSignal cancellationSignal, @NonNull ContentPager.ContentCallback callback) { checkArgument(uri != null);//w ww.j a v a2 s .c o m checkArgument(args != null); checkArgument(callback != null); this.mUri = uri; this.mProjection = projection; this.mQueryArgs = args; this.mCancellationSignal = cancellationSignal; this.mCallback = callback; this.mOffset = args.getInt(ContentPager.QUERY_ARG_OFFSET, -1); this.mLimit = args.getInt(ContentPager.QUERY_ARG_LIMIT, -1); // NOTE: We omit mProjection and other details from ID. If a client wishes // to request a page with a different mProjection or sorting, they should // wait for first request to finish. Same goes for mCallback. this.mId = uri.hashCode() << 16 | (mOffset | (mLimit << 8)); checkArgument(mOffset >= 0); // mOffset must be set, mLimit is optional. }
From source file:com.layer.atlas.messenger.MessengerPushReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (debug)//from www . ja v a 2s . co m Log.w(TAG, "onReceive() action: " + intent.getAction() + ", extras: " + MessengerApp.toString(intent.getExtras(), "\n", "\n")); if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { if (debug) Log.w(TAG, "onReceive() Waking Up! due to action: " + intent.getAction()); return; } NotificationManager notificationService = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String text = intent.getStringExtra("layer-push-message"); Uri conversationId = (Uri) intent.getExtras().get("layer-conversation-id"); String title = getTitle(context, conversationId); if (title == null) title = context.getResources().getString(R.string.app_name); Notification.Builder bld = new Notification.Builder(context); bld.setContentTitle(title).setContentText(text).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setLights(Color.rgb(0, 255, 0), 100, 1900) .setDefaults(NotificationCompat.DEFAULT_SOUND | NotificationCompat.DEFAULT_VIBRATE); Intent chatIntent = new Intent(context, AtlasMessagesScreen.class); chatIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); chatIntent.putExtra(keys.CONVERSATION_URI, conversationId.toString()); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, chatIntent, PendingIntent.FLAG_ONE_SHOT); bld.setContentIntent(resultPendingIntent); final Notification notification = bld.getNotification(); try { // Group notifications by Conversation notificationService.notify(conversationId.hashCode(), notification); } catch (SecurityException ignored) { // 4.1.2 device required VIBRATE permission when in Vibrate mode. // Fixed in 4.2.1 https://android.googlesource.com/platform/frameworks/base/+/cc2e849 } }
From source file:com.cs180.ucrtinder.youwho.Messenger.MessengerPushReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (debug)// ww w. j a v a 2 s . c om Log.w(TAG, "onReceive() action: " + intent.getAction() + ", extras: " + YouWhoApplication.toString(intent.getExtras(), "\n", "\n")); if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { if (debug) Log.w(TAG, "onReceive() Waking Up! due to action: " + intent.getAction()); return; } NotificationManager notificationService = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String text = intent.getStringExtra("layer-push-message"); Uri conversationId = (Uri) intent.getExtras().get("layer-conversation-id"); String title = getTitle(context, conversationId); if (title == null) title = context.getResources().getString(R.string.app_name); Notification.Builder bld = new Notification.Builder(context); bld.setContentTitle(title).setContentText(text).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setLights(Color.rgb(0, 255, 0), 100, 1900) .setDefaults(NotificationCompat.DEFAULT_SOUND | NotificationCompat.DEFAULT_VIBRATE); Intent chatIntent = new Intent(context, AtlasMessagesScreen.class); chatIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); chatIntent.putExtra(keys.CONVERSATION_URI, conversationId.toString()); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, chatIntent, PendingIntent.FLAG_ONE_SHOT); bld.setContentIntent(resultPendingIntent); final Notification notification = bld.getNotification(); try { // Group notifications by Conversation notificationService.notify(conversationId.hashCode(), notification); } catch (SecurityException ignored) { // 4.1.2 device required VIBRATE permission when in Vibrate mode. // Fixed in 4.2.1 https://android.googlesource.com/platform/frameworks/base/+/cc2e849 } }
From source file:edu.mit.mobile.android.locast.sync.AbsMediaSync.java
/** * Synchronize the media of the given castMedia. It will download or upload as needed. * * Blocks until the sync is complete.//ww w . j a va 2 s.c om * * @param castMediaDir * a {@link CastMedia} item uri * @throws SyncException */ public void syncItemMedia(Uri castMediaDir) throws SyncException { final SyncableProvider provider = getSyncableProvider(castMediaDir); if (provider == null) { Log.e(TAG, "could not sync item media: could not get local binder for syncable provider"); return; } if (DEBUG) { Log.d(TAG, "syncing " + castMediaDir); } final CastMedia castMedia = (CastMedia) provider.getWrappedContentItem(castMediaDir, mCr.query(castMediaDir, getCastMediaProjection(), null, null, null)); final NotificationProgressListener downloadListener = new NotificationProgressListener(this, NotificationProgressListener.TYPE_DOWNLOAD, R.id.locast_core__sync_download); try { final int totalItems = castMedia.getCount(); downloadListener.setTotalItems(totalItems); // cache the column numbers final int mediaUrlCol = castMedia.getColumnIndex(CastMedia.COL_MEDIA_URL); final int localUriCol = castMedia.getColumnIndex(CastMedia.COL_LOCAL_URL); final int idCol = castMedia.getColumnIndex(CastMedia._ID); final int mediaDirtyCol = castMedia.getColumnIndex(CastMedia.COL_MEDIA_DIRTY); while (castMedia.moveToNext()) { final boolean keepOffline = castMedia .getInt(castMedia.getColumnIndex(CastMedia.COL_KEEP_OFFLINE)) != 0; final String mimeType = castMedia.getString(castMedia.getColumnIndex(CastMedia.COL_MIME_TYPE)); final boolean isImage = (mimeType != null) && mimeType.startsWith("image/"); // we don't need to sync this if ("text/html".equals(mimeType)) { return; } final Uri locMedia = castMedia.isNull(localUriCol) ? null : Uri.parse(castMedia.getString(localUriCol)); final String pubMedia = castMedia.getString(mediaUrlCol); final boolean hasLocMedia = locMedia != null && new File(locMedia.getPath()).exists(); final boolean hasPubMedia = pubMedia != null && pubMedia.length() > 0; final String localThumb = castMedia.getString(castMedia.getColumnIndex(CastMedia.COL_THUMB_LOCAL)); final Uri castMediaItem = ContentUris.withAppendedId(castMediaDir, castMedia.getLong(idCol)); final boolean isLocalDirty = castMedia.isNull(mediaDirtyCol) || castMedia.getInt(mediaDirtyCol) != 0; if (hasLocMedia && isLocalDirty) { if (DEBUG) { Log.d(TAG, castMediaItem + " has local media and it's dirty"); } final String uploadPath = castMedia .getString(castMedia.getColumnIndex(CastMedia.COL_PUBLIC_URL)); if (uploadPath == null) { Log.w(TAG, "attempted to sync " + castMediaItem + " which has a null uploadPath"); return; } final Uri titledItem = getTitledItemForCastMedia(castMediaItem); final NotificationProgressListener uploadListener = new NotificationProgressListener(this, NotificationProgressListener.TYPE_UPLOAD, titledItem.hashCode()); try { uploadMedia(uploadPath, castMediaItem, titledItem, mimeType, locMedia, uploadListener); uploadListener.onTransfersSuccessful(); } finally { uploadListener.onAllTransfersComplete(); } } else if (!hasLocMedia && hasPubMedia) { if (DEBUG) { Log.d(TAG, castMediaItem + " doesn't have local media, but has public media url"); } // only have a public copy, so download it and store locally. final Uri pubMediaUri = Uri.parse(pubMedia); final File destfile = getFilePath(pubMediaUri); // the following conditions indicate that the cast media should be downloaded. if (keepOffline || getKeepOffline(castMediaItem, castMedia)) { final boolean anythingChanged = downloadMediaFile(pubMedia, destfile, castMediaItem, downloadListener); // the below is inverted from what seems logical, because // downloadMediaFile() // will actually update the castmedia if it downloads anything. We'll only // be // getting here if we don't have any local record of the file, so we should // make // the association by ourselves. if (!anythingChanged) { File thumb = null; if (isImage && localThumb == null) { thumb = destfile; } updateLocalFile(castMediaDir, destfile, thumb); // disabled to avoid spamming the user with downloaded // items. // checkForMediaEntry(castMediaUri, pubMediaUri, mimeType); } } } else { // ensure we tell the listener that we finished downloadListener.onTransferComplete(castMediaItem); } } downloadListener.onTransfersSuccessful(); } finally { downloadListener.onAllTransfersComplete(); castMedia.close(); } }
From source file:org.mozilla.gecko.FilePickerResultHandler.java
@Override public void onActivityResult(int resultCode, Intent intent) { if (resultCode != Activity.RESULT_OK) { sendResult(""); return;/*w ww .j ava 2 s .c o m*/ } // Camera results won't return an Intent. Use the file name we passed to the original intent. // In Android M, camera results return an empty Intent rather than null. if (intent == null || (intent.getAction() == null && intent.getData() == null)) { if (mImageName != null) { File file = new File(Environment.getExternalStorageDirectory(), mImageName); sendResult(file.getAbsolutePath()); } else { sendResult(""); } return; } Uri uri = intent.getData(); if (uri == null) { sendResult(""); return; } // Some file pickers may return a file uri if ("file".equals(uri.getScheme())) { String path = uri.getPath(); sendResult(path == null ? "" : path); return; } final FragmentActivity fa = (FragmentActivity) GeckoAppShell.getGeckoInterface().getActivity(); final LoaderManager lm = fa.getSupportLoaderManager(); // Finally, Video pickers and some file pickers may return a content provider. Cursor cursor = null; try { // Try a query to make sure the expected columns exist final ContentResolver cr = fa.getContentResolver(); cursor = cr.query(uri, new String[] { MediaStore.Video.Media.DATA }, null, null, null); int index = cursor.getColumnIndex(MediaStore.Video.Media.DATA); if (index >= 0) { lm.initLoader(intent.hashCode(), null, new VideoLoaderCallbacks(uri)); return; } } catch (Exception ex) { // We'll try a different loader below } finally { if (cursor != null) { cursor.close(); } } lm.initLoader(uri.hashCode(), null, new FileLoaderCallbacks(uri, cacheDir, tabId)); }