Skip to content

Commit

Permalink
Merge pull request #412 from lucasnlm/update-17-1-0
Browse files Browse the repository at this point in the history
Improve wear control / Fix crash
  • Loading branch information
lucasnlm committed Mar 2, 2023
2 parents c059cf1 + 2be12cb commit 3ce87a8
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 31 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1701061
versionName '17.1.6'
versionCode 1701071
versionName '17.1.7'
minSdkVersion 21
targetSdkVersion 33
multiDexEnabled true
Expand Down Expand Up @@ -88,6 +88,7 @@ android {
dimension 'version'
// There's a typo on F-Droid release :(
applicationId 'dev.lucanlm.antimine'
versionNameSuffix " F"
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions gdx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,4 @@ task copyAndroidNatives {
}
}

preBuild.dependsOn
try {
copyAndroidNatives
} catch (Exception ignored) {
// Ignore
}
preBuild.dependsOn copyAndroidNatives
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GameApplicationListener(
navigationBarHeight = dimensionRepository.navigationBarHeight().toFloat(),
appBarWithStatusHeight = dimensionRepository.actionBarSizeWithStatus().toFloat(),
appBarHeight = if (context.isPortrait()) { dimensionRepository.actionBarSize().toFloat() } else { 0f },
joinAreas = themeRepository.getSkin().joinAreas,
joinAreas = themeRepository.getSkin().hasPadding,
)

private var actionSettings = with(preferencesRepository) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.color.MaterialColors
import dev.lucasnlm.antimine.core.dpToPx
import dev.lucasnlm.antimine.preferences.IPreferencesRepository
import dev.lucasnlm.antimine.themes.R
import dev.lucasnlm.antimine.themes.databinding.ViewSkinBinding
Expand Down Expand Up @@ -47,6 +48,7 @@ class SkinAdapter(
override fun onBindViewHolder(holder: SkinViewHolder, position: Int) {
val skin = appSkins[position]
val tintColor = themeRepository.getTheme().palette.covered.toAndroidColor()
val context = holder.itemView.context

holder.itemView.apply {
val selected = (skin.id == themeViewModel.singleState().currentAppSkin.id)
Expand Down Expand Up @@ -75,13 +77,19 @@ class SkinAdapter(

holder.binding.skinImage.apply {
val floatAlpha = 0.45f
val paddingValue = context.dpToPx(8)
alpha = if (selected) 1.0f else floatAlpha
setImageResource(skin.imageRes)
if (skin.canTint) {
setColorFilter(tintColor, PorterDuff.Mode.MULTIPLY)
} else {
setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY)
}
if (!skin.hasPadding) {
setPadding(0, 0, 0, 0)
} else {
setPadding(paddingValue, paddingValue, paddingValue, paddingValue)
}
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions themes/src/main/res/layout/view_skin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@

<ImageView
android:id="@+id/skinImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@null"
android:padding="8dp"
android:scaleType="fitCenter" />

</com.google.android.material.card.MaterialCardView>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/main/java/dev/lucasnlm/antimine/ui/model/AppSkin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class AppSkin(
@DrawableRes val imageRes: Int,
val canTint: Boolean,
val isPaid: Boolean,
val joinAreas: Boolean,
val hasPadding: Boolean,
val background: Int = 0,
val showPadding: Boolean = true,
)
20 changes: 10 additions & 10 deletions ui/src/main/java/dev/lucasnlm/antimine/ui/repository/Skins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Skins {
file = "standard.png",
canTint = true,
isPaid = false,
joinAreas = true,
hasPadding = true,
imageRes = R.drawable.skin_standard,
)

Expand All @@ -18,7 +18,7 @@ object Skins {
file = "square.png",
canTint = true,
isPaid = true,
joinAreas = true,
hasPadding = true,
imageRes = R.drawable.skin_square,
)

Expand All @@ -27,7 +27,7 @@ object Skins {
file = "square-2.png",
canTint = true,
isPaid = true,
joinAreas = true,
hasPadding = true,
imageRes = R.drawable.skin_square_2,
)

Expand All @@ -36,7 +36,7 @@ object Skins {
file = "square-3.png",
canTint = true,
isPaid = true,
joinAreas = true,
hasPadding = false,
imageRes = R.drawable.skin_square_3,
showPadding = false,
)
Expand All @@ -46,7 +46,7 @@ object Skins {
file = "classic.png",
canTint = true,
isPaid = true,
joinAreas = false,
hasPadding = true,
imageRes = R.drawable.skin_classic,
background = 4,
)
Expand All @@ -56,7 +56,7 @@ object Skins {
file = "classic.png",
canTint = false,
isPaid = true,
joinAreas = false,
hasPadding = true,
imageRes = R.drawable.skin_classic,
background = 4,
)
Expand All @@ -66,7 +66,7 @@ object Skins {
file = "glass.png",
canTint = true,
isPaid = true,
joinAreas = false,
hasPadding = true,
imageRes = R.drawable.skin_glass_2,
)

Expand All @@ -75,7 +75,7 @@ object Skins {
file = "stone.png",
canTint = false,
isPaid = true,
joinAreas = false,
hasPadding = true,
imageRes = R.drawable.skin_stone,
background = 4,
)
Expand All @@ -85,7 +85,7 @@ object Skins {
file = "stone-2.png",
canTint = true,
isPaid = true,
joinAreas = false,
hasPadding = true,
imageRes = R.drawable.skin_stone_2,
background = 4,
)
Expand All @@ -95,7 +95,7 @@ object Skins {
file = "standard.png",
canTint = true,
isPaid = true,
joinAreas = false,
hasPadding = false,
imageRes = R.drawable.skin_standard_no_connection,
showPadding = false,
)
Expand Down
51 changes: 45 additions & 6 deletions wear/src/main/java/dev/lucasnlm/antimine/wear/game/GameActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.lucasnlm.antimine.wear.game

import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.text.format.DateUtils
import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import androidx.activity.addCallback
Expand Down Expand Up @@ -44,15 +46,49 @@ class GameActivity : ThemedActivity(), AndroidFragmentApplication.Callbacks {
binding = ActivityGameBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.levelContainer.apply {
canScrollHorizontally(1)
dismissMinDragWidthRatio = 0.95f
}

loadGameFragment()
bindViewModel()
}

@Suppress("UnnecessaryVariable")
private fun View.tryHandleMotionEvent(event: MotionEvent?): Boolean {
val shouldHandle = if (event == null) {
false
} else {
val location = IntArray(2)
getLocationOnScreen(location)
val viewX = location[0]
val viewY = location[1]

val left = viewX
val right = viewX + width
val top = viewY
val bottom = viewY + height

val rect = Rect(left, top, right, bottom)
rect.contains(event.x.toInt(), event.y.toInt())
}

return shouldHandle && dispatchTouchEvent(event)
}

override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
val handledByView = listOf(
binding.close,
binding.selectFlag,
binding.selectOpen,
binding.newGame,
).firstOrNull {
it.tryHandleMotionEvent(event)
} != null

return handledByView || binding.levelContainer.dispatchTouchEvent(event)
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
return true
}

override fun onResume() {
super.onResume()
refreshSwitchButtons()
Expand Down Expand Up @@ -85,8 +121,11 @@ class GameActivity : ThemedActivity(), AndroidFragmentApplication.Callbacks {

private fun loadGameFragment() {
supportFragmentManager.commit(allowStateLoss = true) {
replace(binding.levelContainer.id, GameRenderFragment())
val fragment = GameRenderFragment()
replace(binding.levelContainer.id, fragment)
handleIntent(intent)

binding.levelContainer.setChildFragment(fragment)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.lucasnlm.antimine.wear.game.view

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import androidx.fragment.app.Fragment
import java.lang.ref.WeakReference

class CustomDismissibleFrameLayout : FrameLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

private var childFragment: WeakReference<Fragment>? = null

fun setChildFragment(fragment: Fragment) {
childFragment = WeakReference(fragment)
}

override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
val child = childFragment?.get()
return child?.view?.onTouchEvent(event) ?: true
}
}
4 changes: 2 additions & 2 deletions wear/src/main/res/layout/activity_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.wear.widget.SwipeDismissFrameLayout
<dev.lucasnlm.antimine.wear.game.view.CustomDismissibleFrameLayout
android:id="@+id/levelContainer"
android:layout_width="0dp"
android:layout_height="0dp"
Expand All @@ -15,7 +15,7 @@
app:layout_constraintTop_toTopOf="parent">

<requestFocus />
</androidx.wear.widget.SwipeDismissFrameLayout>
</dev.lucasnlm.antimine.wear.game.view.CustomDismissibleFrameLayout>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/tapToBegin"
Expand Down

0 comments on commit 3ce87a8

Please sign in to comment.