Skip to content

Commit

Permalink
Update theme code
Browse files Browse the repository at this point in the history
Dynamic utils 4.3.1.
Add support for stroke, corner and opacity.
Optimize theme constants to fix lint errors.
  • Loading branch information
pranavpandey committed Oct 10, 2021
1 parent c817e22 commit 838961e
Show file tree
Hide file tree
Showing 8 changed files with 790 additions and 369 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildscript {
'minSdk' : 14,
'targetSdk' : 31,
'buildTools': '31.0.0',
'dynamic' : '4.2.0',
'dynamic' : '4.3.1',
'gson' : '2.8.6',
'palette' : '1.0.0',
'zxing' : '3.3.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

package com.pranavpandey.android.dynamic.theme;

import android.graphics.Color;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;

import com.google.gson.Gson;
import com.pranavpandey.android.dynamic.theme.base.AutoTheme;
import com.pranavpandey.android.dynamic.theme.base.BackgroundAware;
import com.pranavpandey.android.dynamic.theme.base.BaseTheme;
Expand All @@ -34,6 +37,7 @@
import com.pranavpandey.android.dynamic.theme.base.TranslucentTheme;
import com.pranavpandey.android.dynamic.theme.base.TypeTheme;
import com.pranavpandey.android.dynamic.theme.util.DynamicThemeUtils;
import com.pranavpandey.android.dynamic.util.DynamicColorUtils;

/**
* An abstract class to implement an app theme.
Expand All @@ -52,6 +56,13 @@ public boolean isDynamicColor() {
|| getAccentColor(false, false) == Theme.AUTO;
}

@Override
public boolean isStroke() {
return DynamicColorUtils.removeAlpha(getBackgroundColor())
== DynamicColorUtils.removeAlpha(getSurfaceColor())
&& Color.alpha(getSurfaceColor()) < Theme.Opacity.STROKE;
}

@Override
public @NonNull String getCodeData() {
return DynamicThemeUtils.getThemeUrl(this);
Expand All @@ -62,6 +73,11 @@ public boolean isDynamicColor() {
return getBackgroundColor();
}

@Override
public @ColorInt int getCodeStrokeColor() {
return getStrokeColor();
}

@Override
public @ColorInt int getCodeDataColor() {
return getTintBackgroundColor();
Expand All @@ -84,9 +100,13 @@ public float getCodeContrastRatio() {

@Override
public @Theme.Code.Style int getCodeStyle() {
return getCornerSizeDp(false) == Theme.Corner.AUTO
|| getCornerSizeDp() < Theme.Corner.MIN_ROUND
return getCornerSizeDp() < Theme.Corner.MIN_ROUND
? Theme.Code.Style.DEFAULT : getCornerSizeDp() < Theme.Corner.MIN_OVAL
? Theme.Code.Style.ROUND : Theme.Code.Style.OVAL;
}

@Override
public @NonNull String toJsonString() {
return new Gson().toJson(this);
}
}

0 comments on commit 838961e

Please sign in to comment.