List of usage examples for android.content ComponentName flattenToShortString
public @NonNull String flattenToShortString()
From source file:com.google.android.apps.muzei.api.MuzeiArtSource.java
private void saveSubscriptions() { Set<String> serializedSubscriptions = new HashSet<String>(); for (ComponentName subscriber : mSubscriptions.keySet()) { serializedSubscriptions.add(subscriber.flattenToShortString() + "|" + mSubscriptions.get(subscriber)); }//ww w. j a va 2s .c o m mSharedPrefs.edit().putStringSet(PREF_SUBSCRIPTIONS, serializedSubscriptions).commit(); }
From source file:android.support.v7.widget.SuggestionsAdapter.java
/** * Gets the activity or application icon for an activity. * Uses the local icon cache for fast repeated lookups. * * @param component Name of an activity. * @return A drawable, or {@code null} if neither the activity nor the application * has an icon set./* w w w . ja va2 s . co m*/ */ private Drawable getActivityIconWithCache(ComponentName component) { // First check the icon cache String componentIconKey = component.flattenToShortString(); // Using containsKey() since we also store null values. if (mOutsideDrawablesCache.containsKey(componentIconKey)) { Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey); return cached == null ? null : cached.newDrawable(mProviderContext.getResources()); } // Then try the activity or application icon Drawable drawable = getActivityIcon(component); // Stick it in the cache so we don't do this lookup again. Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState(); mOutsideDrawablesCache.put(componentIconKey, toCache); return drawable; }
From source file:com.iStudy.Study.ActionBarSherlock.Widget.SuggestionsAdapter.java
/** * Gets the activity or application icon for an activity. * Uses the local icon cache for fast repeated lookups. * * @param component Name of an activity. * @return A drawable, or {@code null} if neither the activity nor the application * has an icon set./*from w ww. j a v a 2 s. c om*/ */ @SuppressWarnings("unused") private Drawable getActivityIconWithCache(ComponentName component) { // First check the icon cache String componentIconKey = component.flattenToShortString(); // Using containsKey() since we also store null values. if (mOutsideDrawablesCache.containsKey(componentIconKey)) { Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey); return cached == null ? null : cached.newDrawable(mProviderContext.getResources()); } // Then try the activity or application icon Drawable drawable = getActivityIcon(component); // Stick it in the cache so we don't do this lookup again. Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState(); mOutsideDrawablesCache.put(componentIconKey, toCache); return drawable; }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
private String componentNameToString(ComponentName component) { return component == null ? null : component.flattenToShortString(); }
From source file:com.google.android.apps.muzei.SourceManager.java
public void selectSource(ComponentName source) { if (source == null) { LOGE(TAG, "selectSource: Empty source"); return;/*from w w w . j a v a 2 s.c o m*/ } synchronized (this) { if (source.equals(mSelectedSource)) { return; } LOGD(TAG, "Source " + source + " selected."); if (mSelectedSource != null) { // unsubscribe from existing source mApplicationContext.startService(new Intent(ACTION_SUBSCRIBE).setComponent(mSelectedSource) .putExtra(EXTRA_SUBSCRIBER_COMPONENT, mSubscriberComponentName) .putExtra(EXTRA_TOKEN, (String) null)); } // generate a new token and subscribe to new source mSelectedSource = source; mSelectedSourceToken = UUID.randomUUID().toString(); mSharedPrefs.edit().putString(PREF_SELECTED_SOURCE, source.flattenToShortString()) .putString(PREF_SELECTED_SOURCE_TOKEN, mSelectedSourceToken).apply(); subscribeToSelectedSource(); } EventBus.getDefault().post(new SelectedSourceChangedEvent()); EventBus.getDefault().post(new SelectedSourceStateChangedEvent()); }
From source file:com.androidzeitgeist.dashwatch.muzei.SourceManager.java
public void selectSource(ComponentName source) { if (source == null) { Log.e(TAG, "selectSource: Empty source"); return;/*from w w w . j ava 2 s . co m*/ } synchronized (this) { if (source.equals(mSelectedSource)) { return; } Log.d(TAG, "Source " + source + " selected."); if (mSelectedSource != null) { // unsubscribe from existing source mApplicationContext.startService(new Intent(ACTION_SUBSCRIBE).setComponent(mSelectedSource) .putExtra(EXTRA_SUBSCRIBER_COMPONENT, mSubscriberComponentName) .putExtra(EXTRA_TOKEN, (String) null)); } // generate a new token and subscribe to new source mSelectedSource = source; mSelectedSourceToken = UUID.randomUUID().toString(); mSharedPrefs.edit().putString(PREF_SELECTED_SOURCE, source.flattenToShortString()) .putString(PREF_SELECTED_SOURCE_TOKEN, mSelectedSourceToken).apply(); subscribeToSelectedSource(); } // EventBus.getDefault().post(new SelectedSourceChangedEvent()); // EventBus.getDefault().post(new SelectedSourceStateChangedEvent()); }
From source file:org.deviceconnect.message.intent.util.IntentAuthProcessor.java
/** * ????. Device Connect Manager??????????? * Device Connect Manager??Intent??<br/> * ?????Intent????????UI?????<strong>????</strong><br/> * ??? AndroidManifest.xml??//from ww w. ja v a 2 s .co m * {@link org.deviceconnect.message.intent.impl.io.IntentResponseReceiver} * ????? * * @param context * @param componentName Device Connect Manager???? * @param packageName Authorization Create Client API?package? * @param appName Authorization Create Access Token * API?applicationName? * @param scopes Authorization Create Access Token API?scope? * @param callback ?????? */ public static void authorize(final Context context, final ComponentName componentName, final String packageName, final String appName, final String[] scopes, final AuthorizationHandler callback) { if (callback == null) { throw new IllegalArgumentException("Callback is null."); } else if (scopes == null || scopes.length == 0) { throw new IllegalArgumentException("No scopes."); } else if (componentName == null) { throw new IllegalArgumentException("componentName is null."); } else if (packageName == null) { throw new IllegalArgumentException("Package name is null."); } else if (appName == null) { throw new IllegalArgumentException("App name is null."); } if (Thread.currentThread().equals(context.getMainLooper().getThread())) { throw new IllegalStateException("DON'T CALL this method in UI thread."); } URIBuilder builder = new URIBuilder(); // ??ComponentName????????????????????? builder.setHost("localhost"); builder.setPort(0); builder.setScheme("http"); builder.setProfile(AuthorizationProfileConstants.PROFILE_NAME); builder.setAttribute(AuthorizationProfileConstants.ATTRIBUTE_CREATE_CLIENT); builder.addParameter(AuthorizationProfileConstants.PARAM_PACKAGE, packageName); HttpUriRequest request = null; try { request = new HttpGet(builder.build()); } catch (URISyntaxException e1) { throw new IllegalArgumentException("Invalid Param. Check parameters."); } // DefaultIntentClient?????Host????????????????? request.setHeader(HttpHeaders.HOST, componentName.flattenToShortString()); ErrorCode error = null; HttpParams params = new BasicHttpParams(); IntentConnectionParams.setContext(params, context); IntentConnectionParams.setComponent(params, componentName); DefaultIntentClient client = new DefaultIntentClient(params); do { try { JSONObject json = execute(client, request); error = checkResponse(json); if (error != null) { break; } String clientId = json.getString(AuthorizationProfileConstants.PARAM_CLIENT_ID); String clientSecret = json.getString(AuthorizationProfileConstants.PARAM_CLIENT_SECRET); String signature = AuthSignature.generateSignature(clientId, AuthorizationProfileConstants.GrantType.AUTHORIZATION_CODE.getValue(), null, scopes, clientSecret); // ??? builder.setAttribute(AuthorizationProfileConstants.ATTRIBUTE_REQUEST_ACCESS_TOKEN); builder.addParameter(AuthorizationProfileConstants.PARAM_CLIENT_ID, clientId); builder.addParameter(AuthorizationProfileConstants.PARAM_SCOPE, combineStr(scopes)); builder.addParameter(AuthorizationProfileConstants.PARAM_GRANT_TYPE, AuthorizationProfileConstants.GrantType.AUTHORIZATION_CODE.getValue()); builder.addParameter(AuthorizationProfileConstants.PARAM_SIGNATURE, signature); builder.addParameter(AuthorizationProfileConstants.PARAM_APPLICATION_NAME, appName); try { request = new HttpGet(builder.build()); } catch (URISyntaxException e1) { error = ErrorCode.UNKNOWN; break; } // client?????????? client.getConnectionManager().shutdown(); client = new DefaultIntentClient(params); json = execute(client, request); error = checkResponse(json); if (error != null) { break; } String accessToken = json.getString(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN); callback.onAuthorized(clientId, clientSecret, accessToken); } catch (Exception e) { error = ErrorCode.UNKNOWN; e.printStackTrace(); break; } } while (false); client.getConnectionManager().shutdown(); if (error != null) { callback.onAuthFailed(error); } }
From source file:android.support.v7.widget.SuggestionsAdapter.java
/** * Gets the activity or application icon for an activity. * * @param component Name of an activity. * @return A drawable, or {@code null} if neither the acitivy or the application * have an icon set.//from w w w. j a v a 2 s . c om */ private Drawable getActivityIcon(ComponentName component) { PackageManager pm = mContext.getPackageManager(); final ActivityInfo activityInfo; try { activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA); } catch (NameNotFoundException ex) { Log.w(LOG_TAG, ex.toString()); return null; } int iconId = activityInfo.getIconResource(); if (iconId == 0) return null; String pkg = component.getPackageName(); Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo); if (drawable == null) { Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString()); return null; } return drawable; }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) { Context context = getContext(); if (context == null) { return null; }/*from ww w . j a v a 2 s.c om*/ if (values == null) { throw new IllegalArgumentException("Invalid ContentValues: must not be null"); } if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME) || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name: " + values); } // Check to make sure the component name is valid ComponentName componentName = ComponentName .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); } // Make sure they are using the short string format values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString()); // Ensure the app inserting the artwork is either Muzei or the same app as the source String callingPackageName = getCallingPackage(); if (!context.getPackageName().equals(callingPackageName) && !TextUtils.equals(callingPackageName, componentName.getPackageName())) { throw new IllegalArgumentException("Calling package name (" + callingPackageName + ") must match the source's package name (" + componentName.getPackageName() + ")"); } if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) { String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); Intent viewIntent; try { if (!TextUtils.isEmpty(viewIntentString)) { // Make sure it is a valid Intent URI viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME); // Make sure we can construct a PendingIntent for the Intent PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT); } } catch (URISyntaxException e) { Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } catch (RuntimeException e) { // This is actually meant to catch a FileUriExposedException, but you can't // have catch statements for exceptions that don't exist at your minSdkVersion Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } } // Ensure the related source has been added to the database. // This should be true in 99.9% of cases, but the insert will fail if this isn't true Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { componentName.flattenToShortString() }, null); if (sourceQuery == null || sourceQuery.getCount() == 0) { ContentValues initialValues = new ContentValues(); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues); } if (sourceQuery != null) { sourceQuery.close(); } values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis()); final SQLiteDatabase db = databaseHelper.getWritableDatabase(); long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, values); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the artwork ID pattern and the new row ID appended to it. final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId); File artwork = getCacheFileForArtworkUri(artworkUri); if (artwork != null && artwork.exists()) { // The image already exists so we'll notifyChange() to say the new artwork is ready // Otherwise, this will be called when the file is written with openFile() // using this Uri and the actual artwork is written successfully notifyChange(artworkUri); } return artworkUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java
/** * Create and return an Intent that can launch the voice search activity for web search. *///from www . ja va 2 s . co m private Intent createVoiceWebSearchIntent(Intent baseIntent, SearchableInfo searchable) { Intent voiceIntent = new Intent(baseIntent); ComponentName searchActivity = searchable.getSearchActivity(); voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity == null ? null : searchActivity.flattenToShortString()); return voiceIntent; }