Пример #1
0
		/// <summary>Gets the activity or application icon for an activity.</summary>
		/// <remarks>Gets the activity or application icon for an activity.</remarks>
		/// <param name="component">Name of an activity.</param>
		/// <returns>
		/// A drawable, or
		/// <code>null</code>
		/// if neither the acitivy or the application
		/// have an icon set.
		/// </returns>
		private android.graphics.drawable.Drawable getActivityIcon(android.content.ComponentName
			 component)
		{
			android.content.pm.PackageManager pm = mContext.getPackageManager();
			android.content.pm.ActivityInfo activityInfo;
			try
			{
				activityInfo = pm.getActivityInfo(component, android.content.pm.PackageManager.GET_META_DATA
					);
			}
			catch (android.content.pm.PackageManager.NameNotFoundException ex)
			{
				android.util.Log.w(LOG_TAG, ex.ToString());
				return null;
			}
			int iconId = activityInfo.getIconResource();
			if (iconId == 0)
			{
				return null;
			}
			string pkg = component.getPackageName();
			android.graphics.drawable.Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo
				.applicationInfo);
			if (drawable == null)
			{
				android.util.Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component
					.flattenToShortString());
				return null;
			}
			return drawable;
		}
Пример #2
0
		/// <summary>Gets the activity or application icon for an activity.</summary>
		/// <remarks>
		/// Gets the activity or application icon for an activity.
		/// Uses the local icon cache for fast repeated lookups.
		/// </remarks>
		/// <param name="component">Name of an activity.</param>
		/// <returns>
		/// A drawable, or
		/// <code>null</code>
		/// if neither the activity nor the application
		/// has an icon set.
		/// </returns>
		private android.graphics.drawable.Drawable getActivityIconWithCache(android.content.ComponentName
			 component)
		{
			// First check the icon cache
			string componentIconKey = component.flattenToShortString();
			// Using containsKey() since we also store null values.
			if (mOutsideDrawablesCache.containsKey(componentIconKey))
			{
				android.graphics.drawable.Drawable.ConstantState cached = mOutsideDrawablesCache.
					get(componentIconKey);
				return cached == null ? null : cached.newDrawable(mProviderContext.getResources()
					);
			}
			// Then try the activity or application icon
			android.graphics.drawable.Drawable drawable = getActivityIcon(component);
			// Stick it in the cache so we don't do this lookup again.
			android.graphics.drawable.Drawable.ConstantState toCache = drawable == null ? null
				 : drawable.getConstantState();
			mOutsideDrawablesCache.put(componentIconKey, toCache);
			return drawable;
		}