Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 1 | package com.android.launcher3; |
| 2 | |
Sunny Goyal | ae2129e | 2018-01-24 10:26:35 -0800 | [diff] [blame] | 3 | import android.content.Context; |
Sunny Goyal | 3e9be43 | 2017-01-05 15:22:41 -0800 | [diff] [blame] | 4 | import android.content.pm.LauncherActivityInfo; |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 5 | import android.graphics.drawable.Drawable; |
Hyunyoung Song | 3152827 | 2017-08-28 14:27:00 -0700 | [diff] [blame] | 6 | import android.os.Build; |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 7 | |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 8 | import com.android.launcher3.util.ResourceBasedOverride; |
| 9 | |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 10 | import java.util.Locale; |
| 11 | |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 12 | public class IconProvider implements ResourceBasedOverride { |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 13 | |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 14 | protected String mSystemState; |
| 15 | |
Sunny Goyal | ae2129e | 2018-01-24 10:26:35 -0800 | [diff] [blame] | 16 | public static IconProvider newInstance(Context context) { |
Sunny Goyal | 7f920b8 | 2018-06-27 15:47:49 -0700 | [diff] [blame] | 17 | IconProvider provider = Overrides.getObject( |
Sunny Goyal | ae2129e | 2018-01-24 10:26:35 -0800 | [diff] [blame] | 18 | IconProvider.class, context, R.string.icon_provider_class); |
| 19 | provider.updateSystemStateString(context); |
| 20 | return provider; |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Sunny Goyal | ae2129e | 2018-01-24 10:26:35 -0800 | [diff] [blame] | 23 | public IconProvider() { } |
| 24 | |
| 25 | public void updateSystemStateString(Context context) { |
| 26 | final String locale; |
| 27 | if (Utilities.ATLEAST_NOUGAT) { |
| 28 | locale = context.getResources().getConfiguration().getLocales().toLanguageTags(); |
| 29 | } else { |
| 30 | locale = Locale.getDefault().toString(); |
| 31 | } |
| 32 | |
| 33 | mSystemState = locale + "," + Build.VERSION.SDK_INT; |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | public String getIconSystemState(String packageName) { |
| 37 | return mSystemState; |
| 38 | } |
| 39 | |
Sunny Goyal | 1da1389 | 2017-06-22 11:03:40 -0700 | [diff] [blame] | 40 | /** |
| 41 | * @param flattenDrawable true if the caller does not care about the specification of the |
| 42 | * original icon as long as the flattened version looks the same. |
| 43 | */ |
| 44 | public Drawable getIcon(LauncherActivityInfo info, int iconDpi, boolean flattenDrawable) { |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 45 | return info.getIcon(iconDpi); |
| 46 | } |
| 47 | } |