예제 #1
0
        /// <summary>
        /// Updates the <see cref="Android.Support.V7.Widget.RecyclerView"/> with the list of
        /// <see cref="Android.App.Usage.UsageStats"/> passed as an argument.
        /// </summary>
        /// <param name="usageStatsList">
        /// A list of <see cref="Android.App.Usage.UsageStats"/> from which
        /// upadte the <see cref="Android.Support.V7.Widget.RecyclerView"/>.
        /// </param>
        protected void UpdateAppsList(List <UsageStats> usageStatsList)
        {
            var customUsageStatsList = new List <CustomUsageStats>();

            for (int i = 0; i < usageStatsList.Count; i++)
            {
                var customUsageStats = new CustomUsageStats();
                customUsageStats.UsageStats = usageStatsList[i];
                try
                {
                    var appIcon = Activity.PackageManager
                                  .GetApplicationIcon(customUsageStats.UsageStats.PackageName);
                    customUsageStats.AppIcon = appIcon;
                    var appName = Activity.PackageManager.GetApplicationLabel(Activity.PackageManager.GetApplicationInfo(customUsageStats.UsageStats.PackageName, PackageInfoFlags.MetaData));
                    customUsageStats.AppName = appName;
                }
                catch (PackageManager.NameNotFoundException)
                {
                    Log.Warn(TAG, string.Format("App Icon is not found for {0}",
                                                customUsageStats.UsageStats.PackageName));
                    customUsageStats.AppIcon = Activity
                                               .GetDrawable(Resource.Drawable.ic_default_app_launcher);
                }

                if (customUsageStats.UsageStats.TotalTimeInForeground > 1000)
                {
                    customUsageStatsList.Add(customUsageStats);
                }
            }
            mUsageListAdapter.SetCustomUsageStatsList(customUsageStatsList);
            mUsageListAdapter.NotifyDataSetChanged();
            mRecyclerView.ScrollToPosition(0);
        }
		/// <summary>
		/// Updates the <see cref="Android.Support.V7.Widget.RecyclerView"/> with the list of 
		/// <see cref="Android.App.Usage.UsageStats"/> passed as an argument.
		/// </summary>
		/// <param name="usageStatsList">
		/// A list of <see cref="Android.App.Usage.UsageStats"/> from which 
		/// upadte the <see cref="Android.Support.V7.Widget.RecyclerView"/>.
		/// </param>
		protected void UpdateAppsList (List<UsageStats> usageStatsList)
		{
			var customUsageStatsList = new List<CustomUsageStats> ();
			for (int i = 0; i < usageStatsList.Count; i++) {
				var customUsageStats = new CustomUsageStats ();
				customUsageStats.UsageStats = usageStatsList [i];
				try {
					var appIcon = Activity.PackageManager
						.GetApplicationIcon (customUsageStats.UsageStats.PackageName);
					customUsageStats.AppIcon = appIcon;
				} catch (PackageManager.NameNotFoundException) {
					Log.Warn (TAG, string.Format ("App Icon is not found for {0}",
						customUsageStats.UsageStats.PackageName));
					customUsageStats.AppIcon = Activity
						.GetDrawable (Resource.Drawable.ic_default_app_launcher);
				}
				customUsageStatsList.Add (customUsageStats);
			}
			mUsageListAdapter.SetCustomUsageStatsList (customUsageStatsList);
			mUsageListAdapter.NotifyDataSetChanged ();
			mRecyclerView.ScrollToPosition (0);
		}