Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7b97b87 authored by Amit Kumar's avatar Amit Kumar
Browse files

Fix icon reset issue and add support for work profile

parent 9b74e296
Loading
Loading
Loading
Loading
+45 −50
Original line number Original line Diff line number Diff line
@@ -11,12 +11,10 @@
        android:protectionLevel="dangerous" />
        android:protectionLevel="dangerous" />
    <permission
    <permission
        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"
        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:description="@string/permdesc_uninstall_shortcut"
        android:protectionLevel="dangerous"
        android:label="@string/permlab_uninstall_shortcut"
        android:label="@string/permlab_uninstall_shortcut"
        android:description="@string/permdesc_uninstall_shortcut"/>
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"

        android:protectionLevel="dangerous" /> <!-- General -->
    <!-- General -->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.INTERNET" />
@@ -34,7 +32,7 @@
    <uses-permission android:name="lineageos.permission.READ_WEATHER" />
    <uses-permission android:name="lineageos.permission.READ_WEATHER" />


    <application
    <application
        android:name="BlissLauncher"
        android:name=".BlissLauncher"
        android:icon="@mipmap/ic_launcher"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:supportsRtl="true"
@@ -51,6 +49,7 @@
            android:windowSoftInputMode="adjustPan">
            android:windowSoftInputMode="adjustPan">
            <intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            </intent-filter>
@@ -66,8 +65,7 @@


        <activity
        <activity
            android:name=".features.weather.WeatherPreferences"
            android:name=".features.weather.WeatherPreferences"
            android:theme="@style/AppTheme">
            android:theme="@style/AppTheme"></activity>
        </activity>
        <activity
        <activity
            android:name=".features.weather.PermissionRequestActivity"
            android:name=".features.weather.PermissionRequestActivity"
            android:excludeFromRecents="true"
            android:excludeFromRecents="true"
@@ -79,9 +77,7 @@
        <service android:name=".features.weather.DeviceStatusService" />
        <service android:name=".features.weather.DeviceStatusService" />
        <service android:name=".features.weather.WeatherSourceListenerService" />
        <service android:name=".features.weather.WeatherSourceListenerService" />


        <receiver android:name="core.broadcast.PackageAddedRemovedHandler"/>
        <receiver android:name="core.broadcast.PackageAddedRemovedHandler" /> <!-- Intent received used to install shortcuts from other applications -->

        <!-- Intent received used to install shortcuts from other applications -->
        <receiver
        <receiver
            android:name=".features.shortcuts.InstallShortcutReceiver"
            android:name=".features.shortcuts.InstallShortcutReceiver"
            android:enabled="true"
            android:enabled="true"
@@ -89,9 +85,7 @@
            <intent-filter>
            <intent-filter>
                <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
                <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
            </intent-filter>
            </intent-filter>
        </receiver>
        </receiver> <!-- Intent received used to uninstall shortcuts from other applications -->

        <!-- Intent received used to uninstall shortcuts from other applications -->
        <receiver
        <receiver
            android:name=".features.shortcuts.UninstallShortcutReceiver"
            android:name=".features.shortcuts.UninstallShortcutReceiver"
            android:enabled="true"
            android:enabled="true"
@@ -111,19 +105,20 @@
                <action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" />
                <action android:name="android.content.pm.action.CONFIRM_PIN_SHORTCUT" />
            </intent-filter>
            </intent-filter>
        </activity>
        </activity>

        <activity
        <activity android:name=".features.widgets.WidgetsActivity"
            android:name=".features.widgets.WidgetsActivity"
            android:autoRemoveFromRecents="true"
            android:autoRemoveFromRecents="true"
            android:excludeFromRecents="true"
            android:excludeFromRecents="true"
                  android:theme="@style/AppTheme"
            android:label="Widgets"
                  android:label="Widgets"/>
            android:theme="@style/AppTheme" />
        <activity android:name=".features.widgets.WidgetPicker"
        <activity
            android:name=".features.widgets.WidgetPicker"
            android:autoRemoveFromRecents="true"
            android:autoRemoveFromRecents="true"
            android:excludeFromRecents="true"
            android:excludeFromRecents="true"
                  android:theme="@style/WidgetPickerDialog"
            android:exported="true"
            android:finishOnCloseSystemDialogs="true"
            android:finishOnCloseSystemDialogs="true"
            android:label="Choose widget"
            android:label="Choose widget"
        android:exported="true"/>
            android:theme="@style/WidgetPickerDialog" />
    </application>
    </application>


</manifest>
</manifest>
 No newline at end of file
+61 −45
Original line number Original line Diff line number Diff line
@@ -3,6 +3,7 @@ package foundation.e.blisslauncher.core;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
@@ -15,6 +16,7 @@ import android.graphics.Canvas;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.UserManager;
import android.util.Log;
import android.util.Log;


import org.w3c.dom.Document;
import org.w3c.dom.Document;
@@ -34,6 +36,7 @@ import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.customviews.AdaptiveIconDrawableCompat;
import foundation.e.blisslauncher.core.customviews.AdaptiveIconDrawableCompat;
import foundation.e.blisslauncher.core.utils.GraphicsUtil;
import foundation.e.blisslauncher.core.utils.GraphicsUtil;
import foundation.e.blisslauncher.core.utils.UserHandle;
import foundation.e.blisslauncher.core.utils.UserHandle;
import foundation.e.blisslauncher.features.launcher.LauncherActivity;


/**
/**
 * Inspired from http://stackoverflow.com/questions/31490630/how-to-load-icon-from-icon-pack
 * Inspired from http://stackoverflow.com/questions/31490630/how-to-load-icon-from-icon-pack
@@ -97,7 +100,6 @@ public class IconsHandler {
        }
        }


        packagesDrawables.clear();
        packagesDrawables.clear();
        cacheClear();


        // system icons, nothing to do
        // system icons, nothing to do
        if (iconsPackPackageName.equalsIgnoreCase("default")) {
        if (iconsPackPackageName.equalsIgnoreCase("default")) {
@@ -133,17 +135,8 @@ public class IconsHandler {
    }
    }




    private Drawable getDefaultAppDrawable(ComponentName componentName, UserHandle userHandle) {
    private Drawable getDefaultAppDrawable(LauncherActivityInfo activityInfo, UserHandle userHandle) {
        try {
        return activityInfo.getIcon(0);
            LauncherApps launcher = (LauncherApps) ctx.getSystemService(
                    Context.LAUNCHER_APPS_SERVICE);
            LauncherActivityInfo info = launcher.getActivityList(componentName.getPackageName(),
                    userHandle.getRealHandle()).get(0);
            return info.getBadgedIcon(0);
        } catch (IndexOutOfBoundsException e) {
            Log.e(TAG, "Unable to found component " + componentName.toString() + e);
            return null;
        }
    }
    }


    public boolean isClock(String componentName) {
    public boolean isClock(String componentName) {
@@ -160,18 +153,20 @@ public class IconsHandler {
    /**
    /**
     * Get or generate icon for an app
     * Get or generate icon for an app
     */
     */
    public Drawable getDrawableIconForPackage(ComponentName componentName, UserHandle userHandle) {
    public Drawable getDrawableIconForPackage(LauncherActivityInfo activityInfo, UserHandle userHandle) {
       /* // system icons, nothing to do
       /* // system icons, nothing to do
        if (iconsPackPackageName.equalsIgnoreCase("default")) {
        if (iconsPackPackageName.equalsIgnoreCase("default")) {
            return this.getDefaultAppDrawable(componentName, userHandle);
            return this.getDefaultAppDrawable(componentName, userHandle);
        }*/
        }*/
        String drawable = packagesDrawables.get(componentName.toString());

        ComponentName componentName = activityInfo.getComponentName();
        String drawable = packagesDrawables.get(activityInfo.getComponentName().toString());
        if (drawable != null) { //there is a custom icon
        if (drawable != null) { //there is a custom icon
            int id = iconPackres.getIdentifier(drawable, "drawable", iconsPackPackageName);
            int id = iconPackres.getIdentifier(drawable, "drawable", iconsPackPackageName);
            if (id > 0) {
            if (id > 0) {
                //noinspection deprecation: Resources.getDrawable(int, Theme) requires SDK 21+
                //noinspection deprecation: Resources.getDrawable(int, Theme) requires SDK 21+
                try {
                try {
                    return iconPackres.getDrawable(id);
                    return getBadgedIcon(iconPackres.getDrawable(id), activityInfo.getUser());
                } catch (Resources.NotFoundException e) {
                } catch (Resources.NotFoundException e) {
                    // Unable to load icon, keep going.
                    // Unable to load icon, keep going.
                    e.printStackTrace();
                    e.printStackTrace();
@@ -179,13 +174,15 @@ public class IconsHandler {
            }
            }
        }
        }


        String key = userHandle.addUserSuffixToString(componentName.flattenToString(), '/');

        // Search first in cache
        // Search first in cache
        Drawable systemIcon = cacheGetDrawable(componentName.toString());
        Drawable systemIcon = cacheGetDrawable(key);
        if (systemIcon != null) {
        if (systemIcon != null) {
            return systemIcon;
            return systemIcon;
        }
        }


        systemIcon = this.getDefaultAppDrawable(componentName, userHandle);
        systemIcon = this.getDefaultAppDrawable(activityInfo, userHandle);
        if (Utilities.ATLEAST_OREO && systemIcon instanceof AdaptiveIconDrawable) {
        if (Utilities.ATLEAST_OREO && systemIcon instanceof AdaptiveIconDrawable) {
            systemIcon = new AdaptiveIconDrawableCompat(
            systemIcon = new AdaptiveIconDrawableCompat(
                    ((AdaptiveIconDrawable) systemIcon).getBackground(),
                    ((AdaptiveIconDrawable) systemIcon).getBackground(),
@@ -201,8 +198,43 @@ public class IconsHandler {
            }
            }
        }
        }


        cacheStoreDrawable(componentName.toString(), systemIcon);
        Drawable badgedIcon = getBadgedIcon(systemIcon, activityInfo.getUser());
        return systemIcon;
        cacheStoreDrawable(key, badgedIcon);
        return badgedIcon;
    }


    public void resetIconDrawableForPackage(ComponentName componentName, UserHandle userHandle) {
        if (!packagesDrawables.containsKey(componentName.toString())) {
            LauncherApps launcherApps = (LauncherApps) ctx.getSystemService(Context.LAUNCHER_APPS_SERVICE);
            for (LauncherActivityInfo launcherActivityInfo : launcherApps.getActivityList(componentName.getPackageName(), userHandle.getRealHandle())) {
                if (launcherActivityInfo.getComponentName().flattenToString().equals(componentName.flattenToString())) {
                    Drawable icon = this.getDefaultAppDrawable(launcherActivityInfo, userHandle);
                    if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
                        icon = new AdaptiveIconDrawableCompat(
                                ((AdaptiveIconDrawable) icon).getBackground(),
                                ((AdaptiveIconDrawable) icon).getForeground());
                    } else {
                        Drawable adaptiveIcon = new AdaptiveIconProvider().load(ctx,
                                componentName.getPackageName());
                        if (adaptiveIcon != null) {
                            icon = adaptiveIcon;
                        } else {
                            icon = graphicsUtil.convertToRoundedCorner(ctx,
                                    graphicsUtil.addBackground(icon, false));
                        }
                    }

                    Drawable badgedIcon = getBadgedIcon(icon, launcherActivityInfo.getUser());
                    cacheStoreDrawable(userHandle.addUserSuffixToString(componentName.flattenToString(), '/'), badgedIcon);
                }
            }

        }
    }

    private Drawable getBadgedIcon(Drawable icon, android.os.UserHandle userHandle) {
        return ctx.getApplicationContext().getPackageManager().getUserBadgedIcon(icon, userHandle);
    }
    }


    private boolean isDrawableInCache(String key) {
    private boolean isDrawableInCache(String key) {
@@ -211,7 +243,6 @@ public class IconsHandler {
    }
    }


    private void cacheStoreDrawable(String key, Drawable drawable) {
    private void cacheStoreDrawable(String key, Drawable drawable) {
        Log.i(TAG, "cacheStoreDrawable: " + key);
        Bitmap bitmap = getBitmapFromDrawable(drawable);
        Bitmap bitmap = getBitmapFromDrawable(drawable);
        File drawableFile = cacheGetFileName(key);
        File drawableFile = cacheGetFileName(key);
        FileOutputStream fos;
        FileOutputStream fos;
@@ -259,7 +290,7 @@ public class IconsHandler {
     * {cacheDir}/icons/{icons_pack_package_name}_{key_hash}.png
     * {cacheDir}/icons/{icons_pack_package_name}_{key_hash}.png
     */
     */
    private File cacheGetFileName(String key) {
    private File cacheGetFileName(String key) {
        return new File(getIconsCacheDir() + iconsPackPackageName + "_" + key.hashCode() + ".png");
        return new File(getIconsCacheDir() + File.separator + iconsPackPackageName + "_" + key.hashCode() + ".png");
    }
    }




@@ -267,7 +298,9 @@ public class IconsHandler {
     * returns icons cache directory.
     * returns icons cache directory.
     */
     */
    private File getIconsCacheDir() {
    private File getIconsCacheDir() {
        return new File(this.ctx.getCacheDir().getPath() + "/icons/");
        File file = new File(this.ctx.getCacheDir().getPath() + "/icons/");
        file.mkdir();
        return file;
    }
    }


    /**
    /**
@@ -287,28 +320,6 @@ public class IconsHandler {
        }
        }
    }
    }


    public void resetIconDrawableForPackage(ComponentName componentName, UserHandle user) {
        if (!packagesDrawables.containsKey(componentName.toString())) {
            Drawable icon = this.getDefaultAppDrawable(componentName, user);
            if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
                icon = new AdaptiveIconDrawableCompat(
                        ((AdaptiveIconDrawable) icon).getBackground(),
                        ((AdaptiveIconDrawable) icon).getForeground());
            } else {
                Drawable adaptiveIcon = new AdaptiveIconProvider().load(ctx,
                        componentName.getPackageName());
                if (adaptiveIcon != null) {
                    icon = adaptiveIcon;
                } else {
                    icon = graphicsUtil.convertToRoundedCorner(ctx,
                            graphicsUtil.addBackground(icon, false));
                }
            }

            cacheStoreDrawable(componentName.toString(), icon);
        }
    }

    public Drawable convertIcon(Drawable icon) {
    public Drawable convertIcon(Drawable icon) {
        return graphicsUtil.convertToRoundedCorner(ctx,
        return graphicsUtil.convertToRoundedCorner(ctx,
                graphicsUtil.addBackground(icon, false));
                graphicsUtil.addBackground(icon, false));
@@ -358,4 +369,9 @@ public class IconsHandler {


        return (d != null) ? d : getFullResDefaultActivityIcon();
        return (d != null) ? d : getFullResDefaultActivityIcon();
    }
    }

    public void clearAll() {
        packagesDrawables.clear();
        cacheClear();
    }
}
}
+59 −0
Original line number Original line Diff line number Diff line
package foundation.e.blisslauncher.core.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.UserHandle;
import android.util.Log;

import foundation.e.blisslauncher.core.events.Event;
import foundation.e.blisslauncher.core.events.EventRelay;
import foundation.e.blisslauncher.core.events.ForceReloadEvent;

public class ManagedProfileBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("PROFILE", "onReceive: "+intent.getAction());
        final String action = intent.getAction();
        if (Intent.ACTION_MANAGED_PROFILE_ADDED.equals(action)
                || Intent.ACTION_MANAGED_PROFILE_REMOVED.equals(action)) {
            EventRelay.getInstance().push(new ForceReloadEvent());
        } else if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
                Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
                Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
            UserHandle user = intent.getParcelableExtra(Intent.EXTRA_USER);
            if (user != null) {
                /*if (Intent.ACTION_MANAGED_PROFILE_AVAILABLE.equals(action) ||
                        Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action)) {
                    //enqueueModelUpdateTask(new PackageUpdatedTask(PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE, user));
                }

                // ACTION_MANAGED_PROFILE_UNAVAILABLE sends the profile back to locked mode, so
                // we need to run the state change task again.
                if (Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE.equals(action) ||
                        Intent.ACTION_MANAGED_PROFILE_UNLOCKED.equals(action)) {
                    //enqueueModelUpdateTask(new UserLockStateChangedTask(user));
                }*/

                // TODO: Need to handle it more gracefully. Currently it just recreate the launcher.
                EventRelay.getInstance().push(new ForceReloadEvent());
            }
        }
    }

    public static ManagedProfileBroadcastReceiver register(Context context) {
        IntentFilter timeIntentFilter = new IntentFilter(Intent.ACTION_MANAGED_PROFILE_ADDED);
        timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
        timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
        timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
        timeIntentFilter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
        ManagedProfileBroadcastReceiver receiver = new ManagedProfileBroadcastReceiver();
        context.registerReceiver(receiver, timeIntentFilter);
        return receiver;
    }

    public static void unregister(Context context, ManagedProfileBroadcastReceiver receiver) {
        context.unregisterReceiver(receiver);
    }
}
+17 −19
Original line number Original line Diff line number Diff line
@@ -3,6 +3,8 @@ package foundation.e.blisslauncher.core.broadcast;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.Process;
import android.util.Log;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.EventBus;


@@ -10,6 +12,7 @@ import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.events.AppAddEvent;
import foundation.e.blisslauncher.core.events.AppAddEvent;
import foundation.e.blisslauncher.core.events.AppChangeEvent;
import foundation.e.blisslauncher.core.events.AppChangeEvent;
import foundation.e.blisslauncher.core.events.AppRemoveEvent;
import foundation.e.blisslauncher.core.events.AppRemoveEvent;
import foundation.e.blisslauncher.core.events.EventRelay;
import foundation.e.blisslauncher.core.utils.UserHandle;
import foundation.e.blisslauncher.core.utils.UserHandle;
import foundation.e.blisslauncher.features.launcher.AppProvider;
import foundation.e.blisslauncher.features.launcher.AppProvider;


@@ -19,6 +22,11 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {


    public static void handleEvent(Context ctx, String action, String packageName, UserHandle user,
    public static void handleEvent(Context ctx, String action, String packageName, UserHandle user,
                                   boolean replacing) {
                                   boolean replacing) {

        if (!Process.myUserHandle().equals(user.getRealHandle())) {
            return;
        }
        Log.d(TAG, "handleEvent() called with: ctx = [" + ctx + "], action = [" + action + "], packageName = [" + packageName + "], user = [" + user + "], replacing = [" + replacing + "]");
        // Insert into history new packages (not updated ones)
        // Insert into history new packages (not updated ones)
        if ("android.intent.action.PACKAGE_ADDED".equals(action) && !replacing) {
        if ("android.intent.action.PACKAGE_ADDED".equals(action) && !replacing) {
            Intent launchIntent = ctx.getPackageManager().getLaunchIntentForPackage(packageName);
            Intent launchIntent = ctx.getPackageManager().getLaunchIntentForPackage(packageName);
@@ -26,11 +34,10 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
                return;
                return;
            }
            }


            BlissLauncher.getApplication(ctx).resetIconsHandler();
            BlissLauncher.getApplication(ctx).getIconsHandler().clearAll();


            AppAddEvent appAddEvent = new AppAddEvent();
            AppAddEvent event = new AppAddEvent(packageName, user);
            appAddEvent.packageName = packageName;
            EventRelay.getInstance().push(event);
            EventBus.getDefault().post(appAddEvent);
        }
        }


        if ("android.intent.action.PACKAGE_CHANGED".equalsIgnoreCase(action)) {
        if ("android.intent.action.PACKAGE_CHANGED".equalsIgnoreCase(action)) {
@@ -40,23 +47,14 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
                        launchIntent.getComponent(), user);
                        launchIntent.getComponent(), user);
            }
            }


            BlissLauncher.getApplication(ctx).resetIconsHandler();
            BlissLauncher.getApplication(ctx).getIconsHandler().clearAll();

            AppChangeEvent appChangeEvent = new AppChangeEvent();
            appChangeEvent.packageName = packageName;
            EventBus.getDefault().post(appChangeEvent);


            AppChangeEvent event = new AppChangeEvent(packageName, user);
            EventRelay.getInstance().push(event);
        }
        }
        if ("android.intent.action.PACKAGE_REMOVED".equals(action) && !replacing) {
        if ("android.intent.action.PACKAGE_REMOVED".equals(action) && !replacing) {
            AppRemoveEvent appRemoveEvent = new AppRemoveEvent();
            AppRemoveEvent event = new AppRemoveEvent(packageName, user);
            appRemoveEvent.packageName = packageName;
            EventRelay.getInstance().push(event);
            EventBus.getDefault().post(appRemoveEvent);
        }

        // Reload application list
        final AppProvider provider = BlissLauncher.getApplication(ctx).getAppProvider();
        if (provider != null) {
            provider.reload();
        }
        }
    }
    }


+33 −0
Original line number Original line Diff line number Diff line
package foundation.e.blisslauncher.core.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import foundation.e.blisslauncher.core.events.EventRelay;
import foundation.e.blisslauncher.core.events.TimeChangedEvent;

public class TimeChangeBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction() != null && (intent.getAction().equalsIgnoreCase(Intent.ACTION_TIME_CHANGED)
                || intent.getAction().equalsIgnoreCase(Intent.ACTION_DATE_CHANGED)
                || intent.getAction().equalsIgnoreCase(Intent.ACTION_TIMEZONE_CHANGED)))
            EventRelay.getInstance().push(new TimeChangedEvent());
    }

    public static TimeChangeBroadcastReceiver register(Context context) {
        IntentFilter timeIntentFilter = new IntentFilter(Intent.ACTION_TIME_CHANGED);
        timeIntentFilter.addAction(Intent.ACTION_DATE_CHANGED);
        timeIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        TimeChangeBroadcastReceiver receiver = new TimeChangeBroadcastReceiver();
        context.registerReceiver(receiver, timeIntentFilter);
        return receiver;
    }

    public static void unregister(Context context, TimeChangeBroadcastReceiver receiver) {
        context.unregisterReceiver(receiver);
    }
}
Loading