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 | |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 8 | import java.util.Locale; |
| 9 | |
| 10 | public class IconProvider { |
| 11 | |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 12 | protected String mSystemState; |
| 13 | |
Sunny Goyal | ae2129e | 2018-01-24 10:26:35 -0800 | [diff] [blame^] | 14 | public static IconProvider newInstance(Context context) { |
| 15 | IconProvider provider = Utilities.getOverrideObject( |
| 16 | IconProvider.class, context, R.string.icon_provider_class); |
| 17 | provider.updateSystemStateString(context); |
| 18 | return provider; |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 19 | } |
| 20 | |
Sunny Goyal | ae2129e | 2018-01-24 10:26:35 -0800 | [diff] [blame^] | 21 | public IconProvider() { } |
| 22 | |
| 23 | public void updateSystemStateString(Context context) { |
| 24 | final String locale; |
| 25 | if (Utilities.ATLEAST_NOUGAT) { |
| 26 | locale = context.getResources().getConfiguration().getLocales().toLanguageTags(); |
| 27 | } else { |
| 28 | locale = Locale.getDefault().toString(); |
| 29 | } |
| 30 | |
| 31 | mSystemState = locale + "," + Build.VERSION.SDK_INT; |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | public String getIconSystemState(String packageName) { |
| 35 | return mSystemState; |
| 36 | } |
| 37 | |
Sunny Goyal | 1da1389 | 2017-06-22 11:03:40 -0700 | [diff] [blame] | 38 | /** |
| 39 | * @param flattenDrawable true if the caller does not care about the specification of the |
| 40 | * original icon as long as the flattened version looks the same. |
| 41 | */ |
| 42 | public Drawable getIcon(LauncherActivityInfo info, int iconDpi, boolean flattenDrawable) { |
Annie Chin | 17f8595 | 2016-03-24 17:12:30 -0700 | [diff] [blame] | 43 | return info.getIcon(iconDpi); |
| 44 | } |
| 45 | } |