Loading app/src/apiNougat/java/org/indin/blisslaunchero/features/launcher/LauncherActivity.java +27 −16 Original line number Original line Diff line number Diff line Loading @@ -102,6 +102,7 @@ import org.indin.blisslaunchero.framework.events.AppRemoveEvent; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.ListUtil; import org.json.JSONArray; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONObject; Loading @@ -117,14 +118,14 @@ import java.util.Set; import java.util.UUID; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit; import cyanogenmod.weather.WeatherInfo; import cyanogenmod.weather.util.WeatherUtils; import io.reactivex.Observable; import io.reactivex.Observable; import io.reactivex.ObservableSource; import io.reactivex.ObservableSource; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers; import cyanogenmod.weather.WeatherInfo; import cyanogenmod.weather.util.WeatherUtils; import me.relex.circleindicator.CircleIndicator; import me.relex.circleindicator.CircleIndicator; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; Loading Loading @@ -179,6 +180,8 @@ public class LauncherActivity extends AppCompatActivity implements private View mWeatherSetupTextView; private View mWeatherSetupTextView; private boolean allAppsDisplayed; private boolean allAppsDisplayed; private List<UsageStats> mUsageStats; private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Loading Loading @@ -621,7 +624,6 @@ public class LauncherActivity extends AppCompatActivity implements } } } } } } addNewApp(packageName); } } } } Loading Loading @@ -805,14 +807,19 @@ public class LauncherActivity extends AppCompatActivity implements private void refreshSuggestedApps() { private void refreshSuggestedApps() { AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { // Check if usage stats have been changed or not to avoid unnecessary flickering if (mUsageStats == null || mUsageStats.size() != usageStats.size() || !ListUtil.areEqualLists(mUsageStats, usageStats)) { mUsageStats = usageStats; if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { suggestedAppsGridLayout.removeAllViews(); suggestedAppsGridLayout.removeAllViews(); } } int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < mUsageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, mUsageStats.get(i).getPackageName()); if (appItem != null) { if (appItem != null) { BlissFrameLayout view = prepareSuggestedApp(appItem); BlissFrameLayout view = prepareSuggestedApp(appItem); addAppToGrid(suggestedAppsGridLayout, view); addAppToGrid(suggestedAppsGridLayout, view); Loading @@ -821,6 +828,7 @@ public class LauncherActivity extends AppCompatActivity implements } } } } } } } /** /** * Populates the pages and the mDock for the first time. * Populates the pages and the mDock for the first time. Loading Loading @@ -1030,6 +1038,7 @@ public class LauncherActivity extends AppCompatActivity implements AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { mUsageStats = usageStats; int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); Loading Loading @@ -1103,7 +1112,8 @@ public class LauncherActivity extends AppCompatActivity implements mWeatherPanel = findViewById(R.id.weather_panel); mWeatherPanel = findViewById(R.id.weather_panel); updateWeatherPanel(); updateWeatherPanel(); if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable(this)) { if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable( this)) { startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, DeviceStatusService.class)); startService(new Intent(this, DeviceStatusService.class)); } } Loading @@ -1118,7 +1128,8 @@ public class LauncherActivity extends AppCompatActivity implements WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); } else { } else { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { showLocationEnableDialog(); showLocationEnableDialog(); Preferences.setEnableLocation(this); Preferences.setEnableLocation(this); } else { } else { Loading app/src/apiOreo/java/org/indin/blisslaunchero/features/launcher/LauncherActivity.java +25 −13 Original line number Original line Diff line number Diff line Loading @@ -102,6 +102,7 @@ import org.indin.blisslaunchero.framework.events.AppRemoveEvent; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.ListUtil; import org.json.JSONArray; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONObject; Loading Loading @@ -179,6 +180,8 @@ public class LauncherActivity extends AppCompatActivity implements private View mWeatherSetupTextView; private View mWeatherSetupTextView; private boolean allAppsDisplayed; private boolean allAppsDisplayed; private List<UsageStats> mUsageStats; private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Loading Loading @@ -804,14 +807,19 @@ public class LauncherActivity extends AppCompatActivity implements private void refreshSuggestedApps() { private void refreshSuggestedApps() { AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { // Check if usage stats have been changed or not to avoid unnecessary flickering if (mUsageStats == null || mUsageStats.size() != usageStats.size() || !ListUtil.areEqualLists(mUsageStats, usageStats)) { mUsageStats = usageStats; if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { suggestedAppsGridLayout.removeAllViews(); suggestedAppsGridLayout.removeAllViews(); } } int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < mUsageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, mUsageStats.get(i).getPackageName()); if (appItem != null) { if (appItem != null) { BlissFrameLayout view = prepareSuggestedApp(appItem); BlissFrameLayout view = prepareSuggestedApp(appItem); addAppToGrid(suggestedAppsGridLayout, view); addAppToGrid(suggestedAppsGridLayout, view); Loading @@ -820,6 +828,7 @@ public class LauncherActivity extends AppCompatActivity implements } } } } } } } /** /** * Populates the pages and the mDock for the first time. * Populates the pages and the mDock for the first time. Loading Loading @@ -1029,6 +1038,7 @@ public class LauncherActivity extends AppCompatActivity implements AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { mUsageStats = usageStats; int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); Loading Loading @@ -1102,7 +1112,8 @@ public class LauncherActivity extends AppCompatActivity implements mWeatherPanel = findViewById(R.id.weather_panel); mWeatherPanel = findViewById(R.id.weather_panel); updateWeatherPanel(); updateWeatherPanel(); if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable(this)) { if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable( this)) { startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, DeviceStatusService.class)); startService(new Intent(this, DeviceStatusService.class)); } } Loading @@ -1117,7 +1128,8 @@ public class LauncherActivity extends AppCompatActivity implements WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); } else { } else { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { showLocationEnableDialog(); showLocationEnableDialog(); Preferences.setEnableLocation(this); Preferences.setEnableLocation(this); } else { } else { Loading app/src/main/java/org/indin/blisslaunchero/features/usagestats/AppUsageStats.java +10 −13 Original line number Original line Diff line number Diff line Loading @@ -2,16 +2,6 @@ package org.indin.blisslaunchero.features.usagestats; import static android.app.usage.UsageStatsManager.INTERVAL_BEST; import static android.app.usage.UsageStatsManager.INTERVAL_BEST; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.indin.blisslaunchero.R; import android.app.usage.UsageStats; import android.app.usage.UsageStats; import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManager; import android.content.Context; import android.content.Context; Loading @@ -20,6 +10,16 @@ import android.provider.Settings; import android.util.Log; import android.util.Log; import android.widget.Toast; import android.widget.Toast; import org.indin.blisslaunchero.R; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; public class AppUsageStats { public class AppUsageStats { private final Context mContext; private final Context mContext; Loading Loading @@ -58,7 +58,6 @@ public class AppUsageStats { mContext.getString(R.string.explanation_access_to_appusage_is_not_enabled), mContext.getString(R.string.explanation_access_to_appusage_is_not_enabled), Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show(); mContext.startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); mContext.startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); Log.i(TAG, "getUsageStats: here"); } else { } else { Set<Map.Entry<String, UsageStats>> set = aggregatedStats.entrySet(); Set<Map.Entry<String, UsageStats>> set = aggregatedStats.entrySet(); List<Map.Entry<String, UsageStats>> list = new ArrayList<>(set); List<Map.Entry<String, UsageStats>> list = new ArrayList<>(set); Loading @@ -69,8 +68,6 @@ public class AppUsageStats { usageStats.add(stringUsageStatsEntry.getValue()); usageStats.add(stringUsageStatsEntry.getValue()); } } } } Log.i(TAG, "getUsageStats: here2"); return usageStats; return usageStats; } } } } app/src/main/java/org/indin/blisslaunchero/framework/utils/ListUtil.java +33 −0 Original line number Original line Diff line number Diff line Loading @@ -15,9 +15,13 @@ */ */ package org.indin.blisslaunchero.framework.utils; package org.indin.blisslaunchero.framework.utils; import android.app.usage.UsageStats; import java.util.ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.List; import java.util.Set; /** /** * Created by Amit Kumar * Created by Amit Kumar Loading @@ -29,4 +33,33 @@ public class ListUtil { public static <T> List<T> asSafeList(T... tArr) { public static <T> List<T> asSafeList(T... tArr) { return (tArr == null || tArr.length == 0) ? new ArrayList() : Arrays.asList(tArr); return (tArr == null || tArr.length == 0) ? new ArrayList() : Arrays.asList(tArr); } } /** * To compare if two lists of {@link android.app.usage.UsageStats} contain same packages or not. * * @return true if both the lists contain the same packages otherwise false. */ public static boolean areEqualLists(List<UsageStats> first, List<UsageStats> second) { if (first == null) { if (second == null) { return true; } else { return false; } } if (second == null) { return false; } Set<String> packages = new HashSet<>(); for (UsageStats usageStats : first) { packages.add(usageStats.getPackageName()); } for (UsageStats usageStats : second) { packages.remove(usageStats.getPackageName()); } return packages.size() == 0; } } } Loading
app/src/apiNougat/java/org/indin/blisslaunchero/features/launcher/LauncherActivity.java +27 −16 Original line number Original line Diff line number Diff line Loading @@ -102,6 +102,7 @@ import org.indin.blisslaunchero.framework.events.AppRemoveEvent; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.ListUtil; import org.json.JSONArray; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONObject; Loading @@ -117,14 +118,14 @@ import java.util.Set; import java.util.UUID; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit; import cyanogenmod.weather.WeatherInfo; import cyanogenmod.weather.util.WeatherUtils; import io.reactivex.Observable; import io.reactivex.Observable; import io.reactivex.ObservableSource; import io.reactivex.ObservableSource; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.observers.DisposableObserver; import io.reactivex.observers.DisposableObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers; import cyanogenmod.weather.WeatherInfo; import cyanogenmod.weather.util.WeatherUtils; import me.relex.circleindicator.CircleIndicator; import me.relex.circleindicator.CircleIndicator; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; Loading Loading @@ -179,6 +180,8 @@ public class LauncherActivity extends AppCompatActivity implements private View mWeatherSetupTextView; private View mWeatherSetupTextView; private boolean allAppsDisplayed; private boolean allAppsDisplayed; private List<UsageStats> mUsageStats; private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Loading Loading @@ -621,7 +624,6 @@ public class LauncherActivity extends AppCompatActivity implements } } } } } } addNewApp(packageName); } } } } Loading Loading @@ -805,14 +807,19 @@ public class LauncherActivity extends AppCompatActivity implements private void refreshSuggestedApps() { private void refreshSuggestedApps() { AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { // Check if usage stats have been changed or not to avoid unnecessary flickering if (mUsageStats == null || mUsageStats.size() != usageStats.size() || !ListUtil.areEqualLists(mUsageStats, usageStats)) { mUsageStats = usageStats; if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { suggestedAppsGridLayout.removeAllViews(); suggestedAppsGridLayout.removeAllViews(); } } int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < mUsageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, mUsageStats.get(i).getPackageName()); if (appItem != null) { if (appItem != null) { BlissFrameLayout view = prepareSuggestedApp(appItem); BlissFrameLayout view = prepareSuggestedApp(appItem); addAppToGrid(suggestedAppsGridLayout, view); addAppToGrid(suggestedAppsGridLayout, view); Loading @@ -821,6 +828,7 @@ public class LauncherActivity extends AppCompatActivity implements } } } } } } } /** /** * Populates the pages and the mDock for the first time. * Populates the pages and the mDock for the first time. Loading Loading @@ -1030,6 +1038,7 @@ public class LauncherActivity extends AppCompatActivity implements AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { mUsageStats = usageStats; int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); Loading Loading @@ -1103,7 +1112,8 @@ public class LauncherActivity extends AppCompatActivity implements mWeatherPanel = findViewById(R.id.weather_panel); mWeatherPanel = findViewById(R.id.weather_panel); updateWeatherPanel(); updateWeatherPanel(); if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable(this)) { if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable( this)) { startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, DeviceStatusService.class)); startService(new Intent(this, DeviceStatusService.class)); } } Loading @@ -1118,7 +1128,8 @@ public class LauncherActivity extends AppCompatActivity implements WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); } else { } else { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { showLocationEnableDialog(); showLocationEnableDialog(); Preferences.setEnableLocation(this); Preferences.setEnableLocation(this); } else { } else { Loading
app/src/apiOreo/java/org/indin/blisslaunchero/features/launcher/LauncherActivity.java +25 −13 Original line number Original line Diff line number Diff line Loading @@ -102,6 +102,7 @@ import org.indin.blisslaunchero.framework.events.AppRemoveEvent; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.network.RetrofitService; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.AppUtils; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.GraphicsUtil; import org.indin.blisslaunchero.framework.utils.ListUtil; import org.json.JSONArray; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONObject; Loading Loading @@ -179,6 +180,8 @@ public class LauncherActivity extends AppCompatActivity implements private View mWeatherSetupTextView; private View mWeatherSetupTextView; private boolean allAppsDisplayed; private boolean allAppsDisplayed; private List<UsageStats> mUsageStats; private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() { @Override @Override public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) { Loading Loading @@ -804,14 +807,19 @@ public class LauncherActivity extends AppCompatActivity implements private void refreshSuggestedApps() { private void refreshSuggestedApps() { AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { // Check if usage stats have been changed or not to avoid unnecessary flickering if (mUsageStats == null || mUsageStats.size() != usageStats.size() || !ListUtil.areEqualLists(mUsageStats, usageStats)) { mUsageStats = usageStats; if (suggestedAppsGridLayout != null && suggestedAppsGridLayout.getChildCount() > 0) { suggestedAppsGridLayout.removeAllViews(); suggestedAppsGridLayout.removeAllViews(); } } int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < mUsageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, mUsageStats.get(i).getPackageName()); if (appItem != null) { if (appItem != null) { BlissFrameLayout view = prepareSuggestedApp(appItem); BlissFrameLayout view = prepareSuggestedApp(appItem); addAppToGrid(suggestedAppsGridLayout, view); addAppToGrid(suggestedAppsGridLayout, view); Loading @@ -820,6 +828,7 @@ public class LauncherActivity extends AppCompatActivity implements } } } } } } } /** /** * Populates the pages and the mDock for the first time. * Populates the pages and the mDock for the first time. Loading Loading @@ -1029,6 +1038,7 @@ public class LauncherActivity extends AppCompatActivity implements AppUsageStats appUsageStats = new AppUsageStats(this); AppUsageStats appUsageStats = new AppUsageStats(this); List<UsageStats> usageStats = appUsageStats.getUsageStats(); List<UsageStats> usageStats = appUsageStats.getUsageStats(); if (usageStats.size() > 0) { if (usageStats.size() > 0) { mUsageStats = usageStats; int i = 0; int i = 0; while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { while (suggestedAppsGridLayout.getChildCount() < 4 && i < usageStats.size()) { AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); AppItem appItem = AppUtils.createAppItem(this, usageStats.get(i).getPackageName()); Loading Loading @@ -1102,7 +1112,8 @@ public class LauncherActivity extends AppCompatActivity implements mWeatherPanel = findViewById(R.id.weather_panel); mWeatherPanel = findViewById(R.id.weather_panel); updateWeatherPanel(); updateWeatherPanel(); if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable(this)) { if (org.indin.blisslaunchero.features.weather.WeatherUtils.isWeatherServiceAvailable( this)) { startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, WeatherSourceListenerService.class)); startService(new Intent(this, DeviceStatusService.class)); startService(new Intent(this, DeviceStatusService.class)); } } Loading @@ -1117,7 +1128,8 @@ public class LauncherActivity extends AppCompatActivity implements WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE); } else { } else { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && Preferences.getEnableLocation(this)) { showLocationEnableDialog(); showLocationEnableDialog(); Preferences.setEnableLocation(this); Preferences.setEnableLocation(this); } else { } else { Loading
app/src/main/java/org/indin/blisslaunchero/features/usagestats/AppUsageStats.java +10 −13 Original line number Original line Diff line number Diff line Loading @@ -2,16 +2,6 @@ package org.indin.blisslaunchero.features.usagestats; import static android.app.usage.UsageStatsManager.INTERVAL_BEST; import static android.app.usage.UsageStatsManager.INTERVAL_BEST; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.indin.blisslaunchero.R; import android.app.usage.UsageStats; import android.app.usage.UsageStats; import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManager; import android.content.Context; import android.content.Context; Loading @@ -20,6 +10,16 @@ import android.provider.Settings; import android.util.Log; import android.util.Log; import android.widget.Toast; import android.widget.Toast; import org.indin.blisslaunchero.R; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; public class AppUsageStats { public class AppUsageStats { private final Context mContext; private final Context mContext; Loading Loading @@ -58,7 +58,6 @@ public class AppUsageStats { mContext.getString(R.string.explanation_access_to_appusage_is_not_enabled), mContext.getString(R.string.explanation_access_to_appusage_is_not_enabled), Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show(); mContext.startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); mContext.startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); Log.i(TAG, "getUsageStats: here"); } else { } else { Set<Map.Entry<String, UsageStats>> set = aggregatedStats.entrySet(); Set<Map.Entry<String, UsageStats>> set = aggregatedStats.entrySet(); List<Map.Entry<String, UsageStats>> list = new ArrayList<>(set); List<Map.Entry<String, UsageStats>> list = new ArrayList<>(set); Loading @@ -69,8 +68,6 @@ public class AppUsageStats { usageStats.add(stringUsageStatsEntry.getValue()); usageStats.add(stringUsageStatsEntry.getValue()); } } } } Log.i(TAG, "getUsageStats: here2"); return usageStats; return usageStats; } } } }
app/src/main/java/org/indin/blisslaunchero/framework/utils/ListUtil.java +33 −0 Original line number Original line Diff line number Diff line Loading @@ -15,9 +15,13 @@ */ */ package org.indin.blisslaunchero.framework.utils; package org.indin.blisslaunchero.framework.utils; import android.app.usage.UsageStats; import java.util.ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.List; import java.util.Set; /** /** * Created by Amit Kumar * Created by Amit Kumar Loading @@ -29,4 +33,33 @@ public class ListUtil { public static <T> List<T> asSafeList(T... tArr) { public static <T> List<T> asSafeList(T... tArr) { return (tArr == null || tArr.length == 0) ? new ArrayList() : Arrays.asList(tArr); return (tArr == null || tArr.length == 0) ? new ArrayList() : Arrays.asList(tArr); } } /** * To compare if two lists of {@link android.app.usage.UsageStats} contain same packages or not. * * @return true if both the lists contain the same packages otherwise false. */ public static boolean areEqualLists(List<UsageStats> first, List<UsageStats> second) { if (first == null) { if (second == null) { return true; } else { return false; } } if (second == null) { return false; } Set<String> packages = new HashSet<>(); for (UsageStats usageStats : first) { packages.add(usageStats.getPackageName()); } for (UsageStats usageStats : second) { packages.remove(usageStats.getPackageName()); } return packages.size() == 0; } } }