Exemple #1
0
 /// <summary>Create a new component identifier from a Context and class name.</summary>
 /// <remarks>Create a new component identifier from a Context and class name.</remarks>
 /// <param name="pkg">
 /// A Context for the package implementing the component,
 /// from which the actual package name will be retrieved.
 /// </param>
 /// <param name="cls">
 /// The name of the class inside of <var>pkg</var> that
 /// implements the component.
 /// </param>
 public ComponentName(android.content.Context pkg, string cls)
 {
     if (cls == null)
     {
         throw new System.ArgumentNullException("class name is null");
     }
     mPackage = pkg.getPackageName();
     mClass   = cls;
 }
 /// <summary>Gets a drawable given a value provided by a suggestion provider.</summary>
 /// <remarks>
 /// Gets a drawable given a value provided by a suggestion provider.
 /// This value could be just the string value of a resource id
 /// (e.g., "2130837524"), in which case we will try to retrieve a drawable from
 /// the provider's resources. If the value is not an integer, it is
 /// treated as a Uri and opened with
 /// <see cref="android.content.ContentResolver.openOutputStream(System.Uri, string)">android.content.ContentResolver.openOutputStream(System.Uri, string)
 ///     </see>
 /// .
 /// All resources and URIs are read using the suggestion provider's context.
 /// If the string is not formatted as expected, or no drawable can be found for
 /// the provided value, this method returns null.
 /// </remarks>
 /// <param name="drawableId">
 /// a string like "2130837524",
 /// "android.resource://com.android.alarmclock/2130837524",
 /// or "content://contacts/photos/253".
 /// </param>
 /// <returns>a Drawable, or null if none found</returns>
 private android.graphics.drawable.Drawable getDrawableFromResourceValue(string drawableId
                                                                         )
 {
     if (drawableId == null || drawableId.Length == 0 || "0".Equals(drawableId))
     {
         return(null);
     }
     try
     {
         // First, see if it's just an integer
         int resourceId = System.Convert.ToInt32(drawableId);
         // It's an int, look for it in the cache
         string drawableUri = android.content.ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                              + mProviderContext.getPackageName() + "/" + resourceId;
         // Must use URI as cache key, since ints are app-specific
         android.graphics.drawable.Drawable drawable = checkIconCache(drawableUri);
         if (drawable != null)
         {
             return(drawable);
         }
         // Not cached, find it by resource ID
         drawable = mProviderContext.getResources().getDrawable(resourceId);
         // Stick it in the cache, using the URI as key
         storeInIconCache(drawableUri, drawable);
         return(drawable);
     }
     catch (System.ArgumentException)
     {
         // It's not an integer, use it as a URI
         android.graphics.drawable.Drawable drawable = checkIconCache(drawableId);
         if (drawable != null)
         {
             return(drawable);
         }
         System.Uri uri = Sharpen.Util.ParseUri(drawableId);
         drawable = getDrawable(uri);
         storeInIconCache(drawableId, drawable);
         return(drawable);
     }
     catch (android.content.res.Resources.NotFoundException)
     {
         // It was an integer, but it couldn't be found, bail out
         android.util.Log.w(LOG_TAG, "Icon resource not found: " + drawableId);
         return(null);
     }
 }
Exemple #3
0
 /// <summary>Create a new component identifier from a Context and Class object.</summary>
 /// <remarks>Create a new component identifier from a Context and Class object.</remarks>
 /// <param name="pkg">
 /// A Context for the package implementing the component, from
 /// which the actual package name will be retrieved.
 /// </param>
 /// <param name="cls">
 /// The Class object of the desired component, from which the
 /// actual class name will be retrieved.
 /// </param>
 public ComponentName(android.content.Context pkg, System.Type cls)
 {
     mPackage = pkg.getPackageName();
     mClass   = cls.FullName;
 }
Exemple #4
0
 public override string getPackageName()
 {
     return(mBase.getPackageName());
 }