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

Commit 3624a987 authored by Amit Kumar's avatar Amit Kumar
Browse files

Add widget support

parent c0e7f95f
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
package org.indin.blisslaunchero;
package org.indin.blisslaunchero;


import android.app.Application;
import android.app.Application;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
@@ -9,9 +8,10 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.IBinder;


import org.indin.blisslaunchero.features.launcher.AppProvider;
import org.indin.blisslaunchero.core.DeviceProfile;
import org.indin.blisslaunchero.core.DeviceProfile;
import org.indin.blisslaunchero.core.IconsHandler;
import org.indin.blisslaunchero.core.IconsHandler;
import org.indin.blisslaunchero.core.customviews.WidgetHost;
import org.indin.blisslaunchero.features.launcher.AppProvider;


import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;


@@ -21,7 +21,7 @@ public class BlissLauncher extends Application {


    private AppProvider mAppProvider;
    private AppProvider mAppProvider;


    private AppWidgetHost sAppWidgetHost;
    private WidgetHost sAppWidgetHost;
    private AppWidgetManager sAppWidgetManager;
    private AppWidgetManager sAppWidgetManager;


    private static final String TAG = "BlissLauncher";
    private static final String TAG = "BlissLauncher";
@@ -35,7 +35,7 @@ public class BlissLauncher extends Application {
                .build());
                .build());


        sAppWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
        sAppWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
        sAppWidgetHost = new AppWidgetHost(getApplicationContext(),
        sAppWidgetHost = new WidgetHost(getApplicationContext(),
                R.id.APPWIDGET_HOST_ID);
                R.id.APPWIDGET_HOST_ID);
        sAppWidgetHost.startListening();
        sAppWidgetHost.startListening();
    }
    }
@@ -91,7 +91,7 @@ public class BlissLauncher extends Application {
        return mAppProvider;
        return mAppProvider;
    }
    }


    public AppWidgetHost getAppWidgetHost() { return sAppWidgetHost; }
    public WidgetHost getAppWidgetHost() { return sAppWidgetHost; }


    public AppWidgetManager getAppWidgetManager() { return sAppWidgetManager; }
    public AppWidgetManager getAppWidgetManager() { return sAppWidgetManager; }


+15 −1
Original line number Original line Diff line number Diff line
@@ -87,6 +87,10 @@ public class DeviceProfile {
    public int cellHeightPx;
    public int cellHeightPx;
    public int workspaceCellPaddingXPx;
    public int workspaceCellPaddingXPx;


    //Widget
    public int maxWidgetWidth;
    public int maxWidgetHeight;

    // Folder
    // Folder
    public int folderBackgroundOffset;
    public int folderBackgroundOffset;
    public int folderIconSizePx;
    public int folderIconSizePx;
@@ -148,7 +152,6 @@ public class DeviceProfile {
        availableWidthPx = smallestSize.x;
        availableWidthPx = smallestSize.x;
        availableHeightPx = largestSize.y;
        availableHeightPx = largestSize.y;



        Point realSize = new Point();
        Point realSize = new Point();
        display.getRealSize(realSize);
        display.getRealSize(realSize);


@@ -267,6 +270,9 @@ public class DeviceProfile {
        folderIconSizePx = iconSizePx;
        folderIconSizePx = iconSizePx;


        fillResIconDpi = getLauncherIconDensity(iconSizePx);
        fillResIconDpi = getLauncherIconDensity(iconSizePx);

        maxWidgetWidth = availableWidthPx - (2 * Utilities.pxFromDp(8, dm));
        maxWidgetHeight = getWorkspaceHeight();
    }
    }




@@ -298,6 +304,14 @@ public class DeviceProfile {
        return pageIndicatorSizePx + pageIndicatorBottomPaddingPx + pageIndicatorTopPaddingPx;
        return pageIndicatorSizePx + pageIndicatorBottomPaddingPx + pageIndicatorTopPaddingPx;
    }
    }


    public int getMaxWidgetWidth(){
        return maxWidgetWidth;
    }

    public int getMaxWidgetHeight() {
        return maxWidgetHeight;
    }

    public int getCellHeight(int containerType) {
    public int getCellHeight(int containerType) {
        switch (containerType) {
        switch (containerType) {
            case TYPE_WORKSPACE:
            case TYPE_WORKSPACE:
+31 −26
Original line number Original line Diff line number Diff line
@@ -184,22 +184,23 @@ public class IconsHandler {
            return systemIcon;
            return systemIcon;
        }
        }


        systemIcon = new AdaptiveIconProvider().load(ctx, componentName.getPackageName());
        if(systemIcon != null){
            cacheStoreDrawable(componentName.toString(), systemIcon);
            return systemIcon;
        }

        systemIcon = this.getDefaultAppDrawable(componentName, userHandle);
        systemIcon = this.getDefaultAppDrawable(componentName, userHandle);
        if (Utilities.ATLEAST_OREO
        if (Utilities.ATLEAST_OREO && systemIcon instanceof AdaptiveIconDrawable) {
                && systemIcon instanceof AdaptiveIconDrawable) {
            systemIcon = new AdaptiveIconDrawableCompat(
            systemIcon = new AdaptiveIconDrawableCompat(
                    ((AdaptiveIconDrawable) systemIcon).getBackground(),
                    ((AdaptiveIconDrawable) systemIcon).getBackground(),
                    ((AdaptiveIconDrawable) systemIcon).getForeground());
                    ((AdaptiveIconDrawable) systemIcon).getForeground());
        } else {
            Drawable adaptiveIcon = new AdaptiveIconProvider().load(ctx,
                    componentName.getPackageName());
            if (adaptiveIcon != null) {
                systemIcon = adaptiveIcon;
            } else {
            } else {
                systemIcon = graphicsUtil.convertToRoundedCorner(ctx,
                systemIcon = graphicsUtil.convertToRoundedCorner(ctx,
                        graphicsUtil.addBackground(systemIcon, false));
                        graphicsUtil.addBackground(systemIcon, false));

            }
        }
        }

        cacheStoreDrawable(componentName.toString(), systemIcon);
        cacheStoreDrawable(componentName.toString(), systemIcon);
        return systemIcon;
        return systemIcon;
    }
    }
@@ -210,6 +211,7 @@ 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;
@@ -224,7 +226,8 @@ public class IconsHandler {
    }
    }


    private Bitmap getBitmapFromDrawable(Drawable drawable) {
    private Bitmap getBitmapFromDrawable(Drawable drawable) {
        final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        final Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bmp);
        final Canvas canvas = new Canvas(bmp);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        drawable.draw(canvas);
@@ -286,22 +289,22 @@ public class IconsHandler {


    public void resetIconDrawableForPackage(ComponentName componentName, UserHandle user) {
    public void resetIconDrawableForPackage(ComponentName componentName, UserHandle user) {
        if (!packagesDrawables.containsKey(componentName.toString())) {
        if (!packagesDrawables.containsKey(componentName.toString())) {
            Drawable icon = new AdaptiveIconProvider().load(ctx, componentName.getPackageName());
            Drawable icon = this.getDefaultAppDrawable(componentName, user);
            if(icon != null){
            if (Utilities.ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
                cacheStoreDrawable(componentName.toString(), icon);
                return;
            }

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

            cacheStoreDrawable(componentName.toString(), icon);
            cacheStoreDrawable(componentName.toString(), icon);
        }
        }
    }
    }
@@ -315,7 +318,8 @@ public class IconsHandler {
     * Returns a drawable suitable for the all apps view. If the package or the resource do not
     * Returns a drawable suitable for the all apps view. If the package or the resource do not
     * exist, it returns null.
     * exist, it returns null.
     */
     */
    public static Drawable createIconDrawable(Intent.ShortcutIconResource iconRes, Context context) {
    public static Drawable createIconDrawable(Intent.ShortcutIconResource iconRes,
            Context context) {
        PackageManager packageManager = context.getPackageManager();
        PackageManager packageManager = context.getPackageManager();
        // the resource
        // the resource
        try {
        try {
@@ -323,7 +327,8 @@ public class IconsHandler {
            if (resources != null) {
            if (resources != null) {
                final int id = resources.getIdentifier(iconRes.resourceName, null, null);
                final int id = resources.getIdentifier(iconRes.resourceName, null, null);
                return resources.getDrawableForDensity(
                return resources.getDrawableForDensity(
                        id, BlissLauncher.getApplication(context).getDeviceProfile().fillResIconDpi);
                        id,
                        BlissLauncher.getApplication(context).getDeviceProfile().fillResIconDpi);
            }
            }
        } catch (Exception e) {
        } catch (Exception e) {
            // Icon not found.
            // Icon not found.
+6 −11
Original line number Original line Diff line number Diff line
package org.indin.blisslaunchero.core.customviews;
package org.indin.blisslaunchero.core.customviews;


import java.util.Calendar;

import org.indin.blisslaunchero.BlissLauncher;
import org.indin.blisslaunchero.R;

import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Canvas;
@@ -14,6 +9,11 @@ import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.view.View;
import android.view.View;


import org.indin.blisslaunchero.BlissLauncher;
import org.indin.blisslaunchero.R;

import java.util.Calendar;

/**
/**
 * Created by falcon on 8/3/18.
 * Created by falcon on 8/3/18.
 */
 */
@@ -133,12 +133,7 @@ public class CustomAnalogClock extends View {
        mCalendar = calendar;
        mCalendar = calendar;
        invalidate();
        invalidate();
        if (autoUpdate) {
        if (autoUpdate) {
            new Handler().postDelayed(new Runnable() {
            new Handler().postDelayed(() -> setTime(Calendar.getInstance()), 1000);
                @Override
                public void run() {
                    setTime(Calendar.getInstance());
                }
            }, 1000);
        }
        }
    }
    }


+20 −11
Original line number Original line Diff line number Diff line
package org.indin.blisslaunchero.core.customviews;
package org.indin.blisslaunchero.core.customviews;


import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.indin.blisslaunchero.R;

import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
@@ -23,6 +17,12 @@ import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewParent;
import android.widget.Scroller;
import android.widget.Scroller;


import org.indin.blisslaunchero.R;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class HorizontalPager extends ViewGroup {
public class HorizontalPager extends ViewGroup {
    private static final String TAG = "HorizontalPager";
    private static final String TAG = "HorizontalPager";
    private static final int INVALID_SCREEN = -1;
    private static final int INVALID_SCREEN = -1;
@@ -52,6 +52,7 @@ public class HorizontalPager extends ViewGroup {
    private int mTouchState = TOUCH_STATE_REST;
    private int mTouchState = TOUCH_STATE_REST;


    private boolean mAllowLongPress;
    private boolean mAllowLongPress;
    private DockGridLayout mDock;


    private Set<OnScrollListener> mListeners = new HashSet<>();
    private Set<OnScrollListener> mListeners = new HashSet<>();
    private boolean mIsUiCreated;
    private boolean mIsUiCreated;
@@ -81,6 +82,10 @@ public class HorizontalPager extends ViewGroup {
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    }
    }


    public void setDock(DockGridLayout dock) {
        mDock = dock;
    }

    int getCurrentPage() {
    int getCurrentPage() {
        return currentPage;
        return currentPage;
    }
    }
@@ -341,7 +346,7 @@ public class HorizontalPager extends ViewGroup {
        final int action = ev.getAction();
        final int action = ev.getAction();
        final float x = ev.getX();
        final float x = ev.getX();
        final float y = ev.getY();
        final float y = ev.getY();

        Log.i(TAG, "motion x: " + x);
        if (mIsUiCreated) {
        if (mIsUiCreated) {
            switch (action) {
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_DOWN:
@@ -371,6 +376,10 @@ public class HorizontalPager extends ViewGroup {
                        }
                        }


                        scrollBy(deltaX, 0);
                        scrollBy(deltaX, 0);
                        /*if ((currentPage == 0 && deltaX > 0) || (currentPage == 1 && deltaX < 0)) {
                            Log.i(TAG, "onTouchEvent: "+getChildAt(currentPage).getLeft());
                            mDock.setTranslationX(getChildAt(currentPage).getLeft());
                        }*/
                    }
                    }
                    break;
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_UP:
Loading