Skip to content

Commit

Permalink
Build05
Browse files Browse the repository at this point in the history
  - Fixed weird button shape in some devices
  • Loading branch information
Hamza417 committed Apr 3, 2021
1 parent 1237f95 commit 8af0801
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 42 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "app.simple.flaner"
minSdkVersion 21
targetSdkVersion 30
versionCode 4
versionName "Build04"
versionCode 5
versionName "Build05"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import androidx.recyclerview.widget.RecyclerView
import app.simple.flaner.R
import app.simple.flaner.decoration.corners.DynamicCornerLinearLayout
import app.simple.flaner.preferences.AppearancePreferences
import app.simple.flaner.utils.ViewUtils.makeGoAway
import app.simple.flaner.utils.ViewUtils.makeVisible
import org.jetbrains.annotations.NotNull

class AccentColorAdapter : RecyclerView.Adapter<AccentColorAdapter.Holder>() {
Expand Down Expand Up @@ -49,10 +51,10 @@ class AccentColorAdapter : RecyclerView.Adapter<AccentColorAdapter.Holder>() {
palettesAdapterCallbacks.onColorPressed(list[position])
}

holder.tick.visibility = if (list[position] == AppearancePreferences.getAccentColor()) {
View.VISIBLE
if (list[position] == AppearancePreferences.getAccentColor()) {
holder.tick.makeVisible()
} else {
View.INVISIBLE
holder.tick.makeGoAway()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.ViewOutlineProvider;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import app.simple.flaner.preferences.SharedPreferences.getSharedPreferences
object AppearancePreferences {

private const val appCornerRadius = "corner_radius"
private const val dimWindows = "is_dimming_windows_on"
private const val shadows = "are_shadows_on"

const val accentColor = "app_accent_color"
const val appFont = "type_face"
const val appTheme = "app_theme"

// ---------------------------------------------------------------------------------------------------------- //
Expand All @@ -37,26 +34,6 @@ object AppearancePreferences {

// ---------------------------------------------------------------------------------------------------------- //

fun setDimWindows(boolean: Boolean) {
getSharedPreferences().edit().putBoolean(dimWindows, boolean).apply()
}

fun isDimmingOn(): Boolean {
return getSharedPreferences().getBoolean(dimWindows, true)
}

// ---------------------------------------------------------------------------------------------------------- //

fun setShadows(boolean: Boolean) {
getSharedPreferences().edit().putBoolean(shadows, boolean).apply()
}

fun areShadowsOn(): Boolean {
return getSharedPreferences().getBoolean(shadows, true)
}

// ---------------------------------------------------------------------------------------------------------- //

fun setAppTheme(@NonNull theme: Int) {
getSharedPreferences().edit().putInt(appTheme, theme).apply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel

open class SwitchFrameLayout @JvmOverloads constructor(
open class SwitchBackground @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr) {
init {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/app/simple/flaner/switch/SwitchForeground.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package app.simple.flaner.switch

import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet
import android.widget.FrameLayout
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel

class SwitchForeground @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

init {
backgroundTintList = ColorStateList.valueOf(Color.WHITE)

val shapeAppearanceModel = ShapeAppearanceModel()
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED, 500F)
.build()

background = MaterialShapeDrawable(shapeAppearanceModel)
}
}
7 changes: 3 additions & 4 deletions app/src/main/java/app/simple/flaner/switch/SwitchView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ import app.simple.flaner.decoration.ripple.Utils
import app.simple.flaner.utils.ColorUtils.resolveAttrColor
import app.simple.flaner.utils.ViewUtils
import app.simple.inure.decorations.switch.SwitchCallbacks
import com.google.android.material.card.MaterialCardView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@SuppressLint("ClickableViewAccessibility")
class SwitchView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : SwitchFrameLayout(context, attrs, defStyleAttr) {
class SwitchView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : SwitchBackground(context, attrs, defStyleAttr) {

private var vibration: Vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
private val soundPool = SoundPool.Builder().setMaxStreams(1).build()
private val soundId = soundPool.load(context, R.raw.boop, 1)

private var thumb: MaterialCardView
private var track: SwitchFrameLayout
private var thumb: SwitchForeground
private var track: SwitchBackground
private var switchCallbacks: SwitchCallbacks? = null

private var isChecked: Boolean = false
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/app/simple/flaner/utils/ViewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object ViewUtils {
* shadow
*/
fun addShadow(contentView: View) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P && AppearancePreferences.areShadowsOn()) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
contentView.outlineAmbientShadowColor =
contentView.context.resolveAttrColor(R.attr.colorAppAccent)
contentView.outlineSpotShadowColor =
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/res/layout/switch_view.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<app.simple.flaner.switch.SwitchFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<app.simple.flaner.switch.SwitchBackground xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/switch_track"
android:layout_width="@dimen/switch_width"
android:layout_height="wrap_content"
Expand All @@ -11,19 +10,17 @@
android:elevation="10dp"
android:padding="@dimen/switch_padding">

<com.google.android.material.card.MaterialCardView
<app.simple.flaner.switch.SwitchForeground
android:id="@+id/switch_thumb"
android:layout_width="@dimen/switch_thumb_dimensions"
android:layout_height="@dimen/switch_thumb_dimensions"
android:layout_gravity="center_vertical"
app:cardCornerRadius="500dp"
android:backgroundTint="@android:color/white"
android:clipToPadding="false"
app:cardElevation="20dp"
app:cardForegroundColor="@color/thumbColor"
android:background="@drawable/switch_thumb"
android:elevation="20dp"
tools:ignore="ContentDescription" />

</app.simple.flaner.switch.SwitchFrameLayout>
</app.simple.flaner.switch.SwitchBackground>



0 comments on commit 8af0801

Please sign in to comment.