mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Improve support for older android versions. Fixes #1443
This commit is contained in:
parent
ff8feb1fc0
commit
8c95d8ec6a
14 changed files with 90 additions and 49 deletions
37
Habitica/res/layout-v22/progress_bar.xml
Normal file
37
Habitica/res/layout-v22/progress_bar.xml
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="1">
|
||||
<View
|
||||
android:id="@+id/pendingBar"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<View
|
||||
android:id="@+id/pendingEmptyBarSpace"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="1">
|
||||
<View
|
||||
android:id="@+id/bar"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"/>
|
||||
<View
|
||||
android:id="@+id/emptyBarSpace"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent" />
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
|
|
@ -10,10 +11,11 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="1">
|
||||
<View
|
||||
<ImageView
|
||||
android:id="@+id/pendingBar"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/layout_rounded_bg" />
|
||||
|
||||
<View
|
||||
android:id="@+id/pendingEmptyBarSpace"
|
||||
|
|
@ -25,11 +27,12 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="1">
|
||||
<View
|
||||
<ImageView
|
||||
android:id="@+id/bar"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent" />
|
||||
<View
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/layout_rounded_bg"/>
|
||||
<ImageView
|
||||
android:id="@+id/emptyBarSpace"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent" />
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@
|
|||
@string/font_family_condensed
|
||||
</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:letterSpacing" tools:targetApi="lollipop">0.035</item>
|
||||
<item name="android:letterSpacing">0.035</item>
|
||||
<item name="android:lineSpacingExtra">2.0dp</item>
|
||||
<item name="android:layout_marginLeft">16dp</item>
|
||||
<item name="android:layout_marginEnd">16dp</item>
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@ import android.content.Context
|
|||
import android.graphics.PorterDuff
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
|
||||
|
||||
public fun Drawable.setTintWith(context: Context, colorResource: Int, tintMode: PorterDuff.Mode) {
|
||||
this.setTintMode(tintMode)
|
||||
this.setTint(ContextCompat.getColor(context, colorResource))
|
||||
public fun Drawable.setTintWith(context: Context, colorResource: Int, tintMode: PorterDuff.Mode = PorterDuff.Mode.MULTIPLY) {
|
||||
DrawableCompat.setTintMode(this, tintMode)
|
||||
DrawableCompat.setTint(this, ContextCompat.getColor(context, colorResource))
|
||||
|
||||
}
|
||||
|
||||
public fun Drawable.setTintWith(color: Int, tintMode: PorterDuff.Mode) {
|
||||
this.setTintMode(tintMode)
|
||||
this.setTint(color)
|
||||
public fun Drawable.setTintWith(color: Int, tintMode: PorterDuff.Mode = PorterDuff.Mode.MULTIPLY) {
|
||||
DrawableCompat.setTint(this, color)
|
||||
DrawableCompat.setTintMode(this, tintMode)
|
||||
}
|
||||
|
|
@ -3,11 +3,14 @@ package com.habitrpg.android.habitica.extensions
|
|||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
||||
fun Window.updateStatusBarColor(color: Int, isLight: Boolean) {
|
||||
statusBarColor = color
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
statusBarColor = color
|
||||
@Suppress("DEPRECATION")
|
||||
decorView.systemUiVisibility = if (isLight) View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR else View.SYSTEM_UI_FLAG_VISIBLE
|
||||
} else {
|
||||
statusBarColor = context.getThemeColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,16 +32,11 @@ class SoundFile(val theme: String, private val fileName: String) : MediaPlayer.O
|
|||
|
||||
try {
|
||||
m.setDataSource(file?.path)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
val attributes = AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
|
||||
.build()
|
||||
m.setAudioAttributes(attributes)
|
||||
} else {
|
||||
@Suppress("Deprecation")
|
||||
m.setAudioStreamType(AudioManager.STREAM_NOTIFICATION)
|
||||
}
|
||||
val attributes = AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
|
||||
.build()
|
||||
m.setAudioAttributes(attributes)
|
||||
m.prepare()
|
||||
|
||||
playerPrepared = true
|
||||
|
|
|
|||
|
|
@ -129,9 +129,7 @@ class NotificationPublisher : BroadcastReceiver() {
|
|||
notificationIntent, 0)
|
||||
builder.setContentIntent(intent)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
builder.color = ContextCompat.getColor(thisContext, R.color.brand_300)
|
||||
}
|
||||
builder.color = ContextCompat.getColor(thisContext, R.color.brand_300)
|
||||
|
||||
notification = builder.build()
|
||||
notification.defaults = notification.defaults or Notification.DEFAULT_LIGHTS
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ class MaxHeightLinearLayout : LinearLayout {
|
|||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
|
||||
if (!isInEditMode) {
|
||||
init(context, attrs)
|
||||
|
|
|
|||
|
|
@ -49,11 +49,8 @@ class IntroActivity : BaseActivity(), View.OnClickListener, ViewPager.OnPageChan
|
|||
compositeSubscription.add(contentRepository.retrieveContent(this).subscribe({ }, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
|
||||
val window = window
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.statusBarColor = ContextCompat.getColor(this, R.color.black_20_alpha)
|
||||
}
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
window.statusBarColor = ContextCompat.getColor(this, R.color.black_20_alpha)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
}
|
||||
|
||||
override fun injectActivity(component: UserComponent?) {
|
||||
|
|
|
|||
|
|
@ -156,11 +156,8 @@ class LoginActivity : BaseActivity(), Consumer<UserAuthResponse> {
|
|||
binding.backgroundContainer.post { binding.backgroundContainer.scrollTo(0, binding.backgroundContainer.bottom) }
|
||||
binding.backgroundContainer.isScrollable = false
|
||||
|
||||
val window = window
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.statusBarColor = ContextCompat.getColor(this, R.color.black_20_alpha)
|
||||
}
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
window.statusBarColor = ContextCompat.getColor(this, R.color.black_20_alpha)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
|
||||
|
||||
binding.newGameButton.setOnClickListener { newGameButtonClicked() }
|
||||
binding.showLoginButton.setOnClickListener { showLoginButtonClicked() }
|
||||
|
|
|
|||
|
|
@ -46,13 +46,16 @@ object ToolbarColorHelper {
|
|||
fun colorizeToolbar(toolbar: Toolbar, activity: Activity?, overrideModernHeader: Boolean? = null) {
|
||||
if (activity == null) return
|
||||
val modernHeaderStyle = overrideModernHeader ?: PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("modern_header_style", true)
|
||||
val toolbarIconsColor = if (modernHeaderStyle && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val toolbarIconsColor = if (modernHeaderStyle) {
|
||||
toolbar.setBackgroundColor(activity.getThemeColor(R.attr.headerBackgroundColor))
|
||||
activity.getThemeColor(R.attr.headerTextColor)
|
||||
} else {
|
||||
toolbar.setBackgroundColor(activity.getThemeColor(R.attr.colorPrimary))
|
||||
activity.getThemeColor(R.attr.toolbarContentColor)
|
||||
}
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
activity.window.statusBarColor = activity.getThemeColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
val colorFilter = PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY)
|
||||
for (i in 0 until toolbar.childCount) {
|
||||
val v = toolbar.getChildAt(i)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.widget.FrameLayout
|
|||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.setTintWith
|
||||
import com.habitrpg.android.habitica.models.responses.TaskDirection
|
||||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
|
||||
|
|
@ -30,8 +31,7 @@ class HabitViewHolder(itemView: View, scoreTaskFunc: ((Task, TaskDirection) -> U
|
|||
this.task = data
|
||||
if (data.up == true) {
|
||||
val plusIcon = ContextCompat.getDrawable(context, R.drawable.habit_plus)
|
||||
plusIcon?.setTint(ContextCompat.getColor(context, R.color.white))
|
||||
plusIcon?.setTintMode(PorterDuff.Mode.MULTIPLY)
|
||||
plusIcon?.setTintWith(context, R.color.white)
|
||||
this.btnPlusIconView.setImageDrawable(plusIcon)
|
||||
val drawable = ContextCompat.getDrawable(context, R.drawable.habit_circle)
|
||||
this.btnPlusWrapper.setBackgroundResource(data.lightTaskColor)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
package com.habitrpg.android.habitica.ui.views
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.widget.ImageViewCompat
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.ProgressBarBinding
|
||||
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||
|
|
@ -18,7 +24,13 @@ class HabiticaProgressBar(context: Context, attrs: AttributeSet?) : FrameLayout(
|
|||
var barForegroundColor: Int = 0
|
||||
set(value) {
|
||||
field = value
|
||||
DataBindingUtils.setRoundedBackground(binding.bar, value)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
DataBindingUtils.setRoundedBackground(binding.bar, value)
|
||||
} else {
|
||||
val bar: ImageView = findViewById(R.id.bar)
|
||||
ImageViewCompat.setImageTintList(bar, ColorStateList.valueOf(field))
|
||||
ImageViewCompat.setImageTintMode(bar, PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
}
|
||||
|
||||
var barPendingColor: Int = 0
|
||||
|
|
@ -105,9 +117,8 @@ class HabiticaProgressBar(context: Context, attrs: AttributeSet?) : FrameLayout(
|
|||
layout?.weight = weight.toFloat()
|
||||
view.layoutParams = layout
|
||||
} else if (layout?.weight?.toDouble() != weight) {
|
||||
val anim = DataBindingUtils.LayoutWeightAnimation(view, weight.toFloat())
|
||||
anim.duration = 300
|
||||
view.startAnimation(anim)
|
||||
layout?.weight = weight.toFloat()
|
||||
view.layoutParams = layout
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -52,11 +52,7 @@ class StatsSliderView(context: Context, attrs: AttributeSet?) : LinearLayout(con
|
|||
binding.statTypeTitle.text = attributes.getString(R.styleable.StatsSliderView_statsTitle)
|
||||
val statColor = attributes.getColor(R.styleable.StatsSliderView_statsColor, 0)
|
||||
binding.statTypeTitle.setTextColor(attributes.getColor(R.styleable.StatsSliderView_statsTextColor, 0))
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
binding.statsSeekBar.progressTintList = ColorStateList.valueOf(statColor)
|
||||
} else {
|
||||
binding.statsSeekBar.progressDrawable.setTintWith(statColor, PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
binding.statsSeekBar.progressTintList = ColorStateList.valueOf(statColor)
|
||||
val thumbDrawable = ContextCompat.getDrawable(context, R.drawable.seekbar_thumb)
|
||||
thumbDrawable?.setTintWith(statColor, PorterDuff.Mode.MULTIPLY)
|
||||
binding.statsSeekBar.thumb = thumbDrawable
|
||||
|
|
|
|||
Loading…
Reference in a new issue