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

Commit 196d8566 authored by Amit Kumar's avatar Amit Kumar
Browse files

Add animated clock icon

parent 5b6c0a8d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
      </value>
    </option>
  </component>
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/build/classes" />
  </component>
  <component name="ProjectType">
+12 −4
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ public class AppItem {
    private String componentName;
    private boolean iconFromIconPack;
    private boolean isSystemApp;
    private boolean isClock;

    // Folder specific
    private boolean belongsToFolder;
@@ -23,7 +24,8 @@ public class AppItem {


    public AppItem(CharSequence label, String packageName, Drawable icon,
                   Intent intent, String componentName, boolean iconFromIconPack, boolean isSystemApp) {
            Intent intent, String componentName, boolean iconFromIconPack, boolean isSystemApp,
            boolean isClock) {
        this.label = label;
        this.packageName = packageName;
        this.icon = icon;
@@ -31,6 +33,7 @@ public class AppItem {
        this.componentName = componentName;
        this.iconFromIconPack = iconFromIconPack;
        this.isSystemApp = isSystemApp;
        this.isClock = isClock;
    }

    public CharSequence getLabel() {
@@ -57,6 +60,10 @@ public class AppItem {
        return isSystemApp;
    }

    public boolean isClock() {
        return isClock;
    }

    public void setSystemApp(boolean isSystemApp) {
        this.isSystemApp = isSystemApp;
    }
@@ -106,8 +113,9 @@ public class AppItem {
    }

    public List<AppItem> getSubApps() {
        if(subApps == null)
        if (subApps == null) {
            subApps = new ArrayList<>();
        }
        return subApps;
    }

+29 −21
Original line number Diff line number Diff line
@@ -36,11 +36,16 @@ public class AppUtil {

                boolean iconFromIconPack = true;
                Drawable appIcon = null;
                boolean isClock = false;
                // Load icon from icon pack if present
                if (IconPackUtil.iconPackPresent) {
                    if (!IconPackUtil.isClock(componentName)) {
                        appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
                    } else {
                        isClock = true;
                    }
                if (appIcon == null) {
                }
                if (appIcon == null && !isClock) {
                    appIcon = appInfo.loadIcon(packageManager);
                    iconFromIconPack = false;
                    appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
@@ -60,7 +65,8 @@ public class AppUtil {
                        intent,
                        componentName,
                        iconFromIconPack,
                        isSystemApp
                        isSystemApp,
                        isClock
                );
                launchableApps.add(launchableApp);
            }
@@ -125,25 +131,23 @@ public class AppUtil {
            ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName, 0);
            Intent intent = packageManager.getLaunchIntentForPackage(packageName);

            if (intent == null) {
                return null;
            }

            if (intent != null) {
                String componentName = intent.getComponent().toString();
            Drawable appIcon;

                boolean iconFromIconPack = true;
                Drawable appIcon = null;
                boolean isClock = false;
                // Load icon from icon pack if present
                if (IconPackUtil.iconPackPresent) {
                    isClock = IconPackUtil.isClock(componentName);
                    appIcon = IconPackUtil.getIconFromIconPack(context, componentName);
                }
                if (appIcon == null) {
                    appIcon = appInfo.loadIcon(packageManager);
                    iconFromIconPack = false;
                    appIcon = GraphicsUtil.scaleImage(context, appIcon, 1f);
                    appIcon = GraphicsUtil.maskImage(context, appIcon);
                }
            } else {
                appIcon = appInfo.loadIcon(packageManager);
                iconFromIconPack = false;
            }

                return new AppItem(appInfo.loadLabel(packageManager),
                        packageName,
@@ -151,7 +155,11 @@ public class AppUtil {
                        intent,
                        componentName,
                        iconFromIconPack,
                    (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
                        (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0,
                        isClock);
            } else {
                return null;
            }
        } catch (PackageManager.NameNotFoundException e) {
            return null;
        }
+9 −0
Original line number Diff line number Diff line
package org.indin.blisslaunchero;

/**
 * Created by falcon on 8/3/18.
 */

public class Constants {
    public static final int DEFAULT_CLOCK_ID = 971;
}
+229 −0
Original line number Diff line number Diff line
package org.indin.blisslaunchero;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import java.util.ArrayList;
import java.util.Calendar;

/**
 * Created by falcon on 8/3/18.
 */

public class CustomAnalogClock extends View {

    public static boolean is24;
    public static boolean hourOnTop;
    private final ArrayList<DialOverlay> mDialOverlay = new ArrayList<DialOverlay>();
    private Calendar mCalendar;
    private Drawable mFace;
    private int mDialWidth;
    private float sizeScale = 1f;
    private int radius;
    private int mDialHeight;
    private int mBottom;
    private int mTop;
    private int mLeft;
    private int mRight;
    private boolean mSizeChanged;
    private HandsOverlay mHandsOverlay;
    private boolean autoUpdate;
    private static final String TAG = "CustomAnalogClock";

    public CustomAnalogClock(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        handleAttrs(context, attrs);
    }

    public CustomAnalogClock(Context context, AttributeSet attrs) {
        super(context, attrs);
        handleAttrs(context, attrs);
    }

    public CustomAnalogClock(Context context) {
        super(context);
        init(context);
    }

    private void handleAttrs(Context context, AttributeSet attrs) {
        init(context);
    }

    public void init(Context context) {
        init(context, R.drawable.clock, R.drawable.hours,
                R.drawable.minutes, R.drawable.seconds, 0, false, false);
    }

    /**
     * Will set the scale of the view, for example 0.5f will draw the clock with half of its radius
     *
     * @param scale the scale to render the view in
     */
    public void setScale(float scale) {
        if (scale <= 0) {
            throw new IllegalArgumentException("Scale must be bigger than 0");
        }
        this.sizeScale = scale;
        mHandsOverlay.withScale(sizeScale);
        invalidate();
    }

    public void setFace(int drawableRes) {
        final Resources r = getResources();
        setFace(r.getDrawable(drawableRes));
    }

    public void init(Context context, @DrawableRes int watchFace, @DrawableRes int hourHand,
            @DrawableRes int minuteHand, @DrawableRes int secHand, int alpha, boolean is24,
            boolean hourOnTop) {
        CustomAnalogClock.is24 = is24;

        CustomAnalogClock.hourOnTop = hourOnTop;
        setFace(watchFace);
        Drawable Hhand = ContextCompat.getDrawable(context, hourHand);
        assert Hhand != null;
        if (alpha > 0) {
            Hhand.setAlpha(alpha);
        }

        Drawable Mhand = ContextCompat.getDrawable(context, minuteHand);

        Drawable SHand = ContextCompat.getDrawable(context, secHand);

        mCalendar = Calendar.getInstance();

        mHandsOverlay = new HandsOverlay(Hhand, Mhand, SHand).withScale(sizeScale);
        mHandsOverlay.setShowSeconds(true);
    }

    public void setFace(Drawable face) {
        mFace = face;
        mSizeChanged = true;
        mDialHeight = mFace.getIntrinsicHeight();
        mDialWidth = mFace.getIntrinsicWidth();
        radius = Math.max(mDialHeight, mDialWidth);
        invalidate();
    }

    /**
     * Sets the currently displayed time in {@link System#currentTimeMillis()}
     * time.
     *
     * @param time the time to display on the clock
     */
    public void setTime(long time) {
        mCalendar.setTimeInMillis(time);
        invalidate();
    }

    /**
     * Sets the currently displayed time.
     *
     * @param calendar The time to display on the clock
     */
    public void setTime(Calendar calendar) {
        mCalendar = calendar;
        invalidate();
        if (autoUpdate) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    setTime(Calendar.getInstance());
                }
            }, 1000);
        }
    }

    public void setAutoUpdate(boolean autoUpdate) {
        this.autoUpdate = autoUpdate;
        setTime(Calendar.getInstance());
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mSizeChanged = true;
    }

    // some parts from AnalogClock.java
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        final boolean sizeChanged = mSizeChanged;
        mSizeChanged = false;

        final int availW = mRight - mLeft;
        final int availH = mBottom - mTop;

        final int cX = availW / 2;
        final int cY = availH / 2;

        final int w = (int) (mDialWidth * sizeScale);
        final int h = (int) (mDialHeight * sizeScale);

        Log.i(TAG, "w="+w+", h="+h+", aw="+availW+", ah="+availH);
        boolean scaled = false;

        if (availW < w || availH < h) {
            scaled = true;
            final float scale = Math.min((float) availW / (float) w,
                    (float) availH / (float) h);
            canvas.save();
            canvas.scale(scale, scale, cX, cY);
        }

        if (sizeChanged) {
            mFace.setBounds(cX - (w / 2), cY - (h / 2), cX + (w / 2), cY
                    + (h / 2));
        }

        mFace.draw(canvas);

        for (final DialOverlay overlay : mDialOverlay) {
            overlay.onDraw(canvas, cX, cY, w, h, mCalendar, sizeChanged);
        }

        mHandsOverlay.onDraw(canvas, cX, cY, w, h, mCalendar, sizeChanged);

        if (scaled) {
            canvas.restore();
        }
    }

    // from AnalogClock.java
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int size = DesktopActivity.appIconWidth;
        setMeasuredDimension(size, size);
    }

    @Override
    protected int getSuggestedMinimumHeight() {
        return (int) (mDialHeight * sizeScale);
    }

    @Override
    protected int getSuggestedMinimumWidth() {
        return (int) (mDialWidth * sizeScale);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right,
            int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        mRight = right;
        mLeft = left;
        mTop = top;
        mBottom = bottom;
    }
}
Loading