Skip to content

Commit

Permalink
Library: Clean up themes and attributes
Browse files Browse the repository at this point in the history
Introduce 'Theme.Neumorph' like 'Theme.AppCompat'.
  • Loading branch information
fornewid committed Apr 26, 2020
1 parent 3be468f commit b2914c8
Show file tree
Hide file tree
Showing 17 changed files with 259 additions and 32 deletions.
8 changes: 4 additions & 4 deletions neumorphism/src/main/java/soup/neumorphism/NeumorphButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import android.graphics.Color
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import android.widget.Button
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatButton

class NeumorphButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.defaultNeumorphButton
) : Button(context, attrs, defStyleAttr, defStyleRes) {
defStyleAttr: Int = R.attr.neumorphButtonStyle,
defStyleRes: Int = R.style.Widget_Neumorph_Button
) : AppCompatButton(context, attrs, defStyleAttr) {

private val shapeDrawable: NeumorphShapeDrawable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.annotation.ColorInt
class NeumorphCardView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.defaultNeumorphCardView
defStyleAttr: Int = R.attr.neumorphCardViewStyle,
defStyleRes: Int = R.style.Widget_Neumorph_CardView
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {

private val shapeDrawable: NeumorphShapeDrawable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.util.AttributeSet
import android.widget.EditText
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatEditText
import soup.neumorphism.internal.blur.BlurProvider
import soup.neumorphism.internal.util.withClip
import soup.neumorphism.internal.util.withTranslation

class NeumorphEditText @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.defaultNeumorphEditText
) : EditText(context, attrs, defStyleAttr, defStyleRes) {
defStyleAttr: Int = R.attr.neumorphEditTextStyle,
defStyleRes: Int = R.style.Widget_Neumorph_EditText
) : AppCompatEditText(context, attrs, defStyleAttr) {

private val shapeDrawable: NeumorphShapeDrawable
private val underlineDrawable: NeumorphShapeDrawable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.appcompat.widget.AppCompatImageButton
class NeumorphFloatingActionButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.defaultNeumorphFloatingActionButton
defStyleAttr: Int = R.attr.neumorphFloatingActionButtonStyle,
defStyleRes: Int = R.style.Widget_Neumorph_FAB
) : AppCompatImageButton(context, attrs, defStyleAttr) {

private val shapeDrawable: NeumorphShapeDrawable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import android.graphics.Color
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import android.widget.ImageView
import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatImageView

class NeumorphImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.defaultNeumorphImageView
) : ImageView(context, attrs, defStyleAttr, defStyleRes) {
defStyleAttr: Int = R.attr.neumorphImageViewStyle,
defStyleRes: Int = R.style.Widget_Neumorph_ImageView
) : AppCompatImageView(context, attrs, defStyleAttr) {

private val shapeDrawable: NeumorphShapeDrawable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import kotlin.math.max
class NeumorphTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = R.style.defaultNeumorphTextView
defStyleAttr: Int = R.attr.neumorphTextViewStyle,
defStyleRes: Int = R.style.Widget_Neumorph_TextView
) : AppCompatTextView(context, attrs, defStyleAttr) {

private val shadowElevation: Float
Expand Down
12 changes: 12 additions & 0 deletions neumorphism/src/main/res/values-night/themes_daynight.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Neumorph.DayNight" parent="Theme.Neumorph" />

<style name="Theme.Neumorph.DayNight.DarkActionBar" parent="Theme.Neumorph" />

<style name="Theme.Neumorph.DayNight.NoActionBar" parent="Theme.Neumorph.NoActionBar" />

<style name="Theme.Neumorph.DayNight.DialogWhenLarge" parent="Theme.Neumorph.DialogWhenLarge" />

</resources>
10 changes: 10 additions & 0 deletions neumorphism/src/main/res/values-night/themes_daynight_bridge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Neumorph.DayNight.Bridge" parent="Theme.Neumorph.Bridge" />

<style name="Theme.Neumorph.DayNight.DarkActionBar.Bridge" parent="Theme.Neumorph.Bridge" />

<style name="Theme.Neumorph.DayNight.NoActionBar.Bridge" parent="Theme.Neumorph.NoActionBar.Bridge" />

</resources>
6 changes: 6 additions & 0 deletions neumorphism/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<attr name="neumorph_shadowColorDark" format="color" />
<attr name="neumorph_shapeAppearance" format="reference" />

<attr name="neumorphButtonStyle" format="reference" />
<declare-styleable name="NeumorphButton">
<attr name="neumorph_shapeType" />
<attr name="neumorph_shadowElevation" />
Expand All @@ -19,6 +20,7 @@
<attr name="neumorph_shapeAppearance" />
</declare-styleable>

<attr name="neumorphCardViewStyle" format="reference" />
<declare-styleable name="NeumorphCardView">
<attr name="neumorph_shapeType" />
<attr name="neumorph_shadowElevation" />
Expand All @@ -27,6 +29,7 @@
<attr name="neumorph_shapeAppearance" />
</declare-styleable>

<attr name="neumorphEditTextStyle" format="reference" />
<declare-styleable name="NeumorphEditText">
<attr name="neumorph_shapeType" />
<attr name="neumorph_shadowElevation" />
Expand All @@ -35,6 +38,7 @@
<attr name="neumorph_shapeAppearance" />
</declare-styleable>

<attr name="neumorphFloatingActionButtonStyle" format="reference" />
<declare-styleable name="NeumorphFloatingActionButton">
<attr name="neumorph_shapeType" />
<attr name="neumorph_shadowElevation" />
Expand All @@ -43,6 +47,7 @@
<attr name="neumorph_shapeAppearance" />
</declare-styleable>

<attr name="neumorphImageViewStyle" format="reference" />
<declare-styleable name="NeumorphImageView">
<attr name="neumorph_shapeType" />
<attr name="neumorph_shadowElevation" />
Expand All @@ -51,6 +56,7 @@
<attr name="neumorph_shapeAppearance" />
</declare-styleable>

<attr name="neumorphTextViewStyle" format="reference" />
<declare-styleable name="NeumorphTextView">
<attr name="neumorph_shadowElevation" />
<attr name="neumorph_shadowColorLight" />
Expand Down
50 changes: 36 additions & 14 deletions neumorphism/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="defaultNeumorphButton">
<style name="Widget" />

<style name="Widget.Neumorph" />

<style name="Widget.Neumorph.Button" parent="android:Widget">
<item name="android:textAppearance">?android:attr/textAppearanceButton</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
Expand All @@ -12,59 +16,77 @@
<item name="neumorph_shadowColorLight">@color/default_shadow_light</item>
<item name="neumorph_shadowColorDark">@color/default_shadow_dark</item>
<item name="neumorph_shapeType">flat</item>
<item name="neumorph_shapeAppearance">@style/NeumorphShape.Rounded</item>
<item name="neumorph_shapeAppearance">@style/ShapeAppearance.Neumorph.Button</item>
</style>

<style name="defaultNeumorphCardView">
<style name="Widget.Neumorph.CardView" parent="android:Widget">
<item name="neumorph_shadowElevation">6dp</item>
<item name="neumorph_shadowColorLight">@color/default_shadow_light</item>
<item name="neumorph_shadowColorDark">@color/default_shadow_dark</item>
<item name="neumorph_shapeType">flat</item>
<item name="neumorph_shapeAppearance">@style/NeumorphShape.Rounded</item>
<item name="neumorph_shapeAppearance">@style/ShapeAppearance.Neumorph.CardView</item>
</style>

<style name="defaultNeumorphFloatingActionButton">
<style name="Widget.Neumorph.FAB" parent="android:Widget">
<item name="neumorph_shadowElevation">6dp</item>
<item name="neumorph_shadowColorLight">@color/default_shadow_light</item>
<item name="neumorph_shadowColorDark">@color/default_shadow_dark</item>
<item name="neumorph_shapeType">flat</item>
<item name="neumorph_shapeAppearance">@style/NeumorphShape.Oval</item>
<item name="neumorph_shapeAppearance">@style/ShapeAppearance.Neumorph.FAB</item>
</style>

<style name="defaultNeumorphEditText" parent="Widget.AppCompat.EditText">
<style name="Widget.Neumorph.EditText" parent="Widget.AppCompat.EditText">
<item name="neumorph_shadowElevation">6dp</item>
<item name="neumorph_shadowColorLight">@color/default_shadow_light</item>
<item name="neumorph_shadowColorDark">@color/default_shadow_dark</item>
<item name="neumorph_shapeType">flat</item>
<item name="neumorph_shapeAppearance">@style/NeumorphShape.Rounded</item>
<item name="neumorph_shapeAppearance">@style/ShapeAppearance.Neumorph.EditText</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
<item name="android:background">@drawable/default_edit_text_background</item>
</style>

<style name="defaultNeumorphImageView">
<style name="Widget.Neumorph.ImageView" parent="android:Widget">
<item name="neumorph_shadowElevation">6dp</item>
<item name="neumorph_shadowColorLight">@color/default_shadow_light</item>
<item name="neumorph_shadowColorDark">@color/default_shadow_dark</item>
<item name="neumorph_shapeType">flat</item>
<item name="neumorph_shapeAppearance">@style/NeumorphShape.Rounded</item>
<item name="neumorph_shapeAppearance">@style/ShapeAppearance.Neumorph.ImageView</item>
</style>

<style name="defaultNeumorphTextView">
<style name="Widget.Neumorph.TextView" parent="android:Widget">
<item name="neumorph_shadowElevation">2dp</item>
<item name="neumorph_shadowColorLight">@color/default_shadow_light</item>
<item name="neumorph_shadowColorDark">@color/default_shadow_dark</item>
</style>

<style name="NeumorphShape" />
<style name="ShapeAppearance" />

<style name="ShapeAppearance.Neumorph" />

<style name="ShapeAppearance.Neumorph.Button" parent="">
<item name="neumorph_cornerFamily">rounded</item>
<item name="neumorph_cornerSize">24dp</item>
</style>

<style name="NeumorphShape.Rounded">
<style name="ShapeAppearance.Neumorph.CardView" parent="">
<item name="neumorph_cornerFamily">rounded</item>
<item name="neumorph_cornerSize">24dp</item>
</style>

<style name="NeumorphShape.Oval">
<style name="ShapeAppearance.Neumorph.FAB" parent="">
<item name="neumorph_cornerFamily">oval</item>
<item name="neumorph_cornerSize">0dp</item>
</style>

<style name="ShapeAppearance.Neumorph.EditText" parent="">
<item name="neumorph_cornerFamily">rounded</item>
<item name="neumorph_cornerSize">24dp</item>
</style>

<style name="ShapeAppearance.Neumorph.ImageView" parent="">
<item name="neumorph_cornerFamily">rounded</item>
<item name="neumorph_cornerSize">24dp</item>
</style>

</resources>
26 changes: 26 additions & 0 deletions neumorphism/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Neumorph" parent="Base.Theme.Neumorph" />

<style name="Theme.Neumorph.Light" parent="Base.Theme.Neumorph.Light" />

<style name="Theme.Neumorph.Light.DarkActionBar" parent="Base.Theme.Neumorph.Light.DarkActionBar" />

<style name="Theme.Neumorph.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="Theme.Neumorph.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="Theme.Neumorph.DialogWhenLarge" parent="Base.Theme.Neumorph.DialogWhenLarge" />

<style name="Theme.Neumorph.Light.DialogWhenLarge" parent="Base.Theme.Neumorph.Light.DialogWhenLarge" />

<style name="Theme.Neumorph.CompactMenu" parent="Base.Theme.Neumorph.CompactMenu" />

</resources>
36 changes: 36 additions & 0 deletions neumorphism/src/main/res/values/themes_base.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Base.V21.Theme.Neumorph" parent="Base.V21.Theme.Neumorph.Bridge">
<item name="android:alertDialogTheme">@style/ThemeOverlay.AppCompat.Dialog.Alert</item>
<item name="neumorphButtonStyle">@style/Widget.Neumorph.Button</item>
<item name="neumorphCardViewStyle">@style/Widget.Neumorph.CardView</item>
<item name="neumorphEditTextStyle">@style/Widget.Neumorph.EditText</item>
<item name="neumorphFloatingActionButtonStyle">@style/Widget.Neumorph.FAB</item>
<item name="neumorphImageViewStyle">@style/Widget.Neumorph.ImageView</item>
<item name="neumorphTextViewStyle">@style/Widget.Neumorph.TextView</item>
</style>

<style name="Base.V21.Theme.Neumorph.Light" parent="Base.V21.Theme.Neumorph.Light.Bridge">
<item name="android:alertDialogTheme">@style/ThemeOverlay.AppCompat.Dialog.Alert</item>
<item name="neumorphButtonStyle">@style/Widget.Neumorph.Button</item>
<item name="neumorphCardViewStyle">@style/Widget.Neumorph.CardView</item>
<item name="neumorphEditTextStyle">@style/Widget.Neumorph.EditText</item>
<item name="neumorphFloatingActionButtonStyle">@style/Widget.Neumorph.FAB</item>
<item name="neumorphImageViewStyle">@style/Widget.Neumorph.ImageView</item>
<item name="neumorphTextViewStyle">@style/Widget.Neumorph.TextView</item>
</style>

<style name="Base.Theme.Neumorph" parent="Base.V21.Theme.Neumorph" />

<style name="Base.Theme.Neumorph.Light" parent="Base.V21.Theme.Neumorph.Light" />

<style name="Base.Theme.Neumorph.Light.DarkActionBar" parent="Base.Theme.Neumorph.Light" />

<style name="Base.Theme.Neumorph.CompactMenu" parent="" />

<style name="Base.Theme.Neumorph.DialogWhenLarge" parent="Theme.Neumorph" />

<style name="Base.Theme.Neumorph.Light.DialogWhenLarge" parent="Theme.Neumorph.Light" />

</resources>
41 changes: 41 additions & 0 deletions neumorphism/src/main/res/values/themes_base_bridge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Platform.Neumorph" parent="Theme.AppCompat" />

<style name="Platform.Neumorph.Light" parent="Theme.AppCompat.Light" />

<style name="Base.V21.Theme.Neumorph.Bridge" parent="Platform.Neumorph">
<item name="neumorphButtonStyle">@style/Widget.Neumorph.Button</item>
<item name="neumorphCardViewStyle">@style/Widget.Neumorph.CardView</item>
<item name="neumorphEditTextStyle">@style/Widget.Neumorph.EditText</item>
<item name="neumorphFloatingActionButtonStyle">@style/Widget.Neumorph.FAB</item>
<item name="neumorphImageViewStyle">@style/Widget.Neumorph.ImageView</item>
<item name="neumorphTextViewStyle">@style/Widget.Neumorph.TextView</item>
</style>

<style name="Base.V21.Theme.Neumorph.Light.Bridge" parent="Platform.Neumorph.Light">
<item name="neumorphButtonStyle">@style/Widget.Neumorph.Button</item>
<item name="neumorphCardViewStyle">@style/Widget.Neumorph.CardView</item>
<item name="neumorphEditTextStyle">@style/Widget.Neumorph.EditText</item>
<item name="neumorphFloatingActionButtonStyle">@style/Widget.Neumorph.FAB</item>
<item name="neumorphImageViewStyle">@style/Widget.Neumorph.ImageView</item>
<item name="neumorphTextViewStyle">@style/Widget.Neumorph.TextView</item>
</style>

<style name="Base.V21.Theme.Neumorph.Light.DarkActionBar.Bridge" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="neumorphButtonStyle">@style/Widget.Neumorph.Button</item>
<item name="neumorphCardViewStyle">@style/Widget.Neumorph.CardView</item>
<item name="neumorphEditTextStyle">@style/Widget.Neumorph.EditText</item>
<item name="neumorphFloatingActionButtonStyle">@style/Widget.Neumorph.FAB</item>
<item name="neumorphImageViewStyle">@style/Widget.Neumorph.ImageView</item>
<item name="neumorphTextViewStyle">@style/Widget.Neumorph.TextView</item>
</style>

<style name="Base.Theme.Neumorph.Bridge" parent="Base.V21.Theme.Neumorph.Bridge" />

<style name="Base.Theme.Neumorph.Light.Bridge" parent="Base.V21.Theme.Neumorph.Light.Bridge" />

<style name="Base.Theme.Neumorph.Light.DarkActionBar.Bridge" parent="Base.V21.Theme.Neumorph.Light.DarkActionBar.Bridge" />

</resources>
20 changes: 20 additions & 0 deletions neumorphism/src/main/res/values/themes_bridge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Neumorph.Bridge" parent="Base.Theme.Neumorph.Bridge" />

<style name="Theme.Neumorph.Light.Bridge" parent="Base.Theme.Neumorph.Light.Bridge" />

<style name="Theme.Neumorph.NoActionBar.Bridge" parent="Theme.Neumorph.Bridge">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="Theme.Neumorph.Light.NoActionBar.Bridge" parent="Theme.Neumorph.Light.Bridge">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="Theme.Neumorph.Light.DarkActionBar.Bridge" parent="Base.Theme.Neumorph.Light.DarkActionBar.Bridge" />

</resources>
Loading

0 comments on commit b2914c8

Please sign in to comment.