mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Implement CheckmarkPopup
This commit is contained in:
@@ -36,6 +36,7 @@ class EntryButtonViewTest : BaseViewTest() {
|
||||
lateinit var view: CheckmarkButtonView
|
||||
|
||||
var toggled = false
|
||||
var edited = false
|
||||
|
||||
@Before
|
||||
override fun setUp() {
|
||||
@@ -44,6 +45,7 @@ class EntryButtonViewTest : BaseViewTest() {
|
||||
value = Entry.NO
|
||||
color = PaletteUtils.getAndroidTestColor(5)
|
||||
onToggle = { _, _, _ -> toggled = true }
|
||||
onEdit = { _ -> edited = true }
|
||||
}
|
||||
measureView(view, dpToPixels(48), dpToPixels(48))
|
||||
}
|
||||
@@ -70,20 +72,28 @@ class EntryButtonViewTest : BaseViewTest() {
|
||||
fun testClick_withShortToggleDisabled() {
|
||||
prefs.isShortToggleEnabled = false
|
||||
view.performClick()
|
||||
assertFalse(toggled)
|
||||
assertTrue(!toggled and edited)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClick_withShortToggleEnabled() {
|
||||
prefs.isShortToggleEnabled = true
|
||||
view.performClick()
|
||||
assertTrue(toggled)
|
||||
assertTrue(toggled and !edited)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongClick() {
|
||||
fun testLongClick_withShortToggleDisabled() {
|
||||
prefs.isShortToggleEnabled = false
|
||||
view.performLongClick()
|
||||
assertTrue(toggled)
|
||||
assertTrue(toggled and !edited)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongClick_withShortToggleEnabled() {
|
||||
prefs.isShortToggleEnabled = true
|
||||
view.performLongClick()
|
||||
assertTrue(!toggled and edited)
|
||||
}
|
||||
|
||||
private fun assertRendersCheckedExplicitly() {
|
||||
|
||||
@@ -76,7 +76,7 @@ class NumberPanelViewTest : BaseViewTest() {
|
||||
@Test
|
||||
fun testEdit() {
|
||||
val timestamps = mutableListOf<Timestamp>()
|
||||
view.onEdit = { timestamps.plusAssign(it) }
|
||||
view.onEdit = { _, t -> timestamps.plusAssign(t) }
|
||||
view.buttons[0].performLongClick()
|
||||
view.buttons[2].performLongClick()
|
||||
view.buttons[3].performLongClick()
|
||||
@@ -87,7 +87,7 @@ class NumberPanelViewTest : BaseViewTest() {
|
||||
fun testEdit_withOffset() {
|
||||
val timestamps = mutableListOf<Timestamp>()
|
||||
view.dataOffset = 3
|
||||
view.onEdit = { timestamps += it }
|
||||
view.onEdit = { _, t -> timestamps += t }
|
||||
view.buttons[0].performLongClick()
|
||||
view.buttons[2].performLongClick()
|
||||
view.buttons[3].performLongClick()
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.common.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.widget.PopupWindow
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.databinding.CheckmarkPopupBinding
|
||||
import org.isoron.uhabits.utils.InterfaceUtils.getFontAwesome
|
||||
import org.isoron.uhabits.utils.dimBehind
|
||||
import org.isoron.uhabits.utils.dp
|
||||
import org.isoron.uhabits.utils.sres
|
||||
|
||||
const val POPUP_WIDTH = 4 * 48f + 16f
|
||||
const val POPUP_HEIGHT = 48f * 2.5f + 8f
|
||||
|
||||
class CheckmarkPopup(
|
||||
private val context: Context,
|
||||
private val color: Int,
|
||||
private var notes: String,
|
||||
private var value: Int,
|
||||
private val prefs: Preferences,
|
||||
private val anchor: View,
|
||||
) {
|
||||
var onToggle: (Int, String) -> Unit = { _, _ -> }
|
||||
|
||||
private val view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context)).apply {
|
||||
// Required for round corners
|
||||
container.clipToOutline = true
|
||||
}
|
||||
|
||||
init {
|
||||
initColors()
|
||||
initTypefaces()
|
||||
hideDisabledButtons()
|
||||
populate()
|
||||
}
|
||||
|
||||
private fun initColors() {
|
||||
arrayOf(view.yesBtn, view.skipBtn).forEach {
|
||||
it.setTextColor(color)
|
||||
}
|
||||
arrayOf(view.noBtn, view.unknownBtn).forEach {
|
||||
it.setTextColor(view.root.sres.getColor(R.attr.contrast60))
|
||||
}
|
||||
}
|
||||
|
||||
private fun initTypefaces() {
|
||||
arrayOf(view.yesBtn, view.noBtn, view.skipBtn, view.unknownBtn).forEach {
|
||||
it.typeface = getFontAwesome(context)
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideDisabledButtons() {
|
||||
if (!prefs.isSkipEnabled) view.skipBtn.visibility = GONE
|
||||
if (!prefs.areQuestionMarksEnabled) view.unknownBtn.visibility = GONE
|
||||
}
|
||||
|
||||
private fun populate() {
|
||||
val selectedBtn = when (value) {
|
||||
YES_MANUAL -> view.yesBtn
|
||||
YES_AUTO -> view.noBtn
|
||||
NO -> view.noBtn
|
||||
UNKNOWN -> if (prefs.areQuestionMarksEnabled) view.unknownBtn else view.noBtn
|
||||
SKIP -> if (prefs.isSkipEnabled) view.skipBtn else view.noBtn
|
||||
else -> null
|
||||
}
|
||||
selectedBtn?.background = ColorDrawable(view.root.sres.getColor(R.attr.contrast40))
|
||||
view.notes.setText(notes)
|
||||
}
|
||||
|
||||
fun show(location: ScreenLocation) {
|
||||
val popup = PopupWindow()
|
||||
popup.contentView = view.root
|
||||
popup.width = view.root.dp(POPUP_WIDTH).toInt()
|
||||
popup.height = view.root.dp(POPUP_HEIGHT).toInt()
|
||||
popup.isFocusable = true
|
||||
popup.elevation = view.root.dp(24f)
|
||||
fun onClick(v: Int) {
|
||||
this.value = v
|
||||
popup.dismiss()
|
||||
}
|
||||
view.yesBtn.setOnClickListener { onClick(YES_MANUAL) }
|
||||
view.noBtn.setOnClickListener { onClick(NO) }
|
||||
view.skipBtn.setOnClickListener { onClick(SKIP) }
|
||||
view.unknownBtn.setOnClickListener { onClick(UNKNOWN) }
|
||||
popup.setOnDismissListener {
|
||||
onToggle(value, view.notes.text.toString())
|
||||
}
|
||||
popup.showAtLocation(
|
||||
anchor,
|
||||
Gravity.NO_GRAVITY,
|
||||
view.root.dp(location.x.toFloat()).toInt(),
|
||||
view.root.dp(location.y.toFloat()).toInt(),
|
||||
)
|
||||
popup.dimBehind()
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
private lateinit var commandRunner: CommandRunner
|
||||
private lateinit var habit: Habit
|
||||
private lateinit var preferences: Preferences
|
||||
private lateinit var dataView: AndroidDataView
|
||||
lateinit var dataView: AndroidDataView
|
||||
|
||||
private var chart: HistoryChart? = null
|
||||
private var onDateClickedListener: OnDateClickedListener? = null
|
||||
|
||||
@@ -24,12 +24,16 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import dagger.Lazy
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.platform.gui.toInt
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.dialogs.CheckmarkDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.CheckmarkPopup
|
||||
import org.isoron.uhabits.activities.common.dialogs.ColorPickerDialogFactory
|
||||
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
||||
import org.isoron.uhabits.activities.common.dialogs.POPUP_WIDTH
|
||||
import org.isoron.uhabits.activities.habits.edit.HabitTypeDialog
|
||||
import org.isoron.uhabits.activities.habits.list.views.HabitCardListAdapter
|
||||
import org.isoron.uhabits.core.commands.ArchiveHabitsCommand
|
||||
@@ -43,6 +47,7 @@ import org.isoron.uhabits.core.commands.UnarchiveHabitsCommand
|
||||
import org.isoron.uhabits.core.models.Frequency
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.PaletteColor
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.tasks.TaskRunner
|
||||
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
||||
import org.isoron.uhabits.core.ui.callbacks.OnColorPickedCallback
|
||||
@@ -63,6 +68,7 @@ import org.isoron.uhabits.tasks.ExportDBTaskFactory
|
||||
import org.isoron.uhabits.tasks.ImportDataTask
|
||||
import org.isoron.uhabits.tasks.ImportDataTaskFactory
|
||||
import org.isoron.uhabits.utils.copyTo
|
||||
import org.isoron.uhabits.utils.currentTheme
|
||||
import org.isoron.uhabits.utils.restartWithFade
|
||||
import org.isoron.uhabits.utils.showMessage
|
||||
import org.isoron.uhabits.utils.showSendEmailScreen
|
||||
@@ -93,7 +99,9 @@ class ListHabitsScreen
|
||||
private val colorPickerFactory: ColorPickerDialogFactory,
|
||||
private val numberPickerFactory: NumberPickerFactory,
|
||||
private val checkMarkDialog: CheckmarkDialog,
|
||||
private val behavior: Lazy<ListHabitsBehavior>
|
||||
private val behavior: Lazy<ListHabitsBehavior>,
|
||||
private val preferences: Preferences,
|
||||
private val rootView: Lazy<ListHabitsRootView>,
|
||||
) : CommandRunner.Listener,
|
||||
ListHabitsBehavior.Screen,
|
||||
ListHabitsMenuBehavior.Screen,
|
||||
@@ -237,6 +245,32 @@ class ListHabitsScreen
|
||||
numberPickerFactory.create(value, unit, notes, dateString, frequency, callback).show()
|
||||
}
|
||||
|
||||
override fun showCheckmarkPopup(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
color: PaletteColor,
|
||||
location: ScreenLocation,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
) {
|
||||
val view = rootView.get()
|
||||
CheckmarkPopup(
|
||||
context = context,
|
||||
prefs = preferences,
|
||||
anchor = view,
|
||||
color = view.currentTheme().color(color).toInt(),
|
||||
notes = notes,
|
||||
value = selectedValue,
|
||||
).apply {
|
||||
onToggle = { value, notes -> callback.onNotesSaved(value, notes) }
|
||||
show(
|
||||
ScreenLocation(
|
||||
x = location.x - POPUP_WIDTH / 2,
|
||||
y = location.y
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showCheckmarkDialog(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.text.TextPaint
|
||||
import android.view.HapticFeedbackConstants
|
||||
import android.view.View
|
||||
import android.view.View.MeasureSpec.EXACTLY
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.models.Entry
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||
@@ -38,6 +39,7 @@ import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.drawNotesIndicator
|
||||
import org.isoron.uhabits.utils.getCenter
|
||||
import org.isoron.uhabits.utils.getFontAwesome
|
||||
import org.isoron.uhabits.utils.sp
|
||||
import org.isoron.uhabits.utils.sres
|
||||
@@ -81,7 +83,8 @@ class CheckmarkButtonView(
|
||||
|
||||
var onToggle: (Int, String, Long) -> Unit = { _, _, _ -> }
|
||||
|
||||
var onEdit: () -> Unit = {}
|
||||
var onEdit: (ScreenLocation) -> Unit = { _ -> }
|
||||
|
||||
private var drawer = Drawer()
|
||||
|
||||
init {
|
||||
@@ -102,11 +105,11 @@ class CheckmarkButtonView(
|
||||
|
||||
override fun onClick(v: View) {
|
||||
if (preferences.isShortToggleEnabled) performToggle(TOGGLE_DELAY_MILLIS)
|
||||
else onEdit()
|
||||
else onEdit(getCenter())
|
||||
}
|
||||
|
||||
override fun onLongClick(v: View): Boolean {
|
||||
if (preferences.isShortToggleEnabled) onEdit()
|
||||
if (preferences.isShortToggleEnabled) onEdit(getCenter())
|
||||
else performToggle(TOGGLE_DELAY_MILLIS)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package org.isoron.uhabits.activities.habits.list.views
|
||||
|
||||
import android.content.Context
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||
import org.isoron.uhabits.core.models.Timestamp
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
@@ -66,7 +67,7 @@ class CheckmarkPanelView(
|
||||
setupButtons()
|
||||
}
|
||||
|
||||
var onEdit: (Timestamp) -> Unit = {}
|
||||
var onEdit: (ScreenLocation, Timestamp) -> Unit = { _, _ -> }
|
||||
set(value) {
|
||||
field = value
|
||||
setupButtons()
|
||||
@@ -90,7 +91,7 @@ class CheckmarkPanelView(
|
||||
}
|
||||
button.color = color
|
||||
button.onToggle = { value, notes, delay -> onToggle(timestamp, value, notes, delay) }
|
||||
button.onEdit = { onEdit(timestamp) }
|
||||
button.onEdit = { location -> onEdit(location, timestamp) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,17 +167,17 @@ class HabitCardView(
|
||||
{ runPendingToggles(taskId) }.delay(delay)
|
||||
}
|
||||
}
|
||||
onEdit = { timestamp ->
|
||||
onEdit = { location, timestamp ->
|
||||
triggerRipple(timestamp)
|
||||
habit?.let { behavior.onEdit(it, timestamp) }
|
||||
habit?.let { behavior.onEdit(location, it, timestamp) }
|
||||
}
|
||||
}
|
||||
|
||||
numberPanel = numberPanelFactory.create().apply {
|
||||
visibility = GONE
|
||||
onEdit = { timestamp ->
|
||||
onEdit = { location, timestamp ->
|
||||
triggerRipple(timestamp)
|
||||
habit?.let { behavior.onEdit(it, timestamp) }
|
||||
habit?.let { behavior.onEdit(location, it, timestamp) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,13 @@
|
||||
package org.isoron.uhabits.activities.habits.list.views
|
||||
|
||||
import android.content.Context
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.uhabits.core.models.NumericalHabitType
|
||||
import org.isoron.uhabits.core.models.Timestamp
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.getCenter
|
||||
import javax.inject.Inject
|
||||
|
||||
class NumberPanelViewFactory
|
||||
@@ -78,7 +80,7 @@ class NumberPanelView(
|
||||
setupButtons()
|
||||
}
|
||||
|
||||
var onEdit: (Timestamp) -> Unit = {}
|
||||
var onEdit: (ScreenLocation, Timestamp) -> Unit = { _, _ -> }
|
||||
set(value) {
|
||||
field = value
|
||||
setupButtons()
|
||||
@@ -104,7 +106,7 @@ class NumberPanelView(
|
||||
button.targetType = targetType
|
||||
button.threshold = threshold
|
||||
button.units = units
|
||||
button.onEdit = { onEdit(timestamp) }
|
||||
button.onEdit = { onEdit(getCenter(), timestamp) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.platform.gui.toInt
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.AndroidDirFinder
|
||||
import org.isoron.uhabits.HabitsApplication
|
||||
@@ -34,9 +36,11 @@ import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.AndroidThemeSwitcher
|
||||
import org.isoron.uhabits.activities.HabitsDirFinder
|
||||
import org.isoron.uhabits.activities.common.dialogs.CheckmarkDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.CheckmarkPopup
|
||||
import org.isoron.uhabits.activities.common.dialogs.ConfirmDeleteDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.HistoryEditorDialog
|
||||
import org.isoron.uhabits.activities.common.dialogs.NumberPickerFactory
|
||||
import org.isoron.uhabits.activities.common.dialogs.POPUP_WIDTH
|
||||
import org.isoron.uhabits.core.commands.Command
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.models.Frequency
|
||||
@@ -49,6 +53,8 @@ import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuPresenter
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter
|
||||
import org.isoron.uhabits.core.ui.views.OnDateClickedListener
|
||||
import org.isoron.uhabits.intents.IntentFactory
|
||||
import org.isoron.uhabits.utils.currentTheme
|
||||
import org.isoron.uhabits.utils.getTopLeftCorner
|
||||
import org.isoron.uhabits.utils.showMessage
|
||||
import org.isoron.uhabits.utils.showSendFileScreen
|
||||
import org.isoron.uhabits.widgets.WidgetUpdater
|
||||
@@ -173,7 +179,14 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
frequency: Frequency,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback
|
||||
) {
|
||||
NumberPickerFactory(this@ShowHabitActivity).create(value, unit, notes, dateString, frequency, callback).show()
|
||||
NumberPickerFactory(this@ShowHabitActivity).create(
|
||||
value,
|
||||
unit,
|
||||
notes,
|
||||
dateString,
|
||||
frequency,
|
||||
callback
|
||||
).show()
|
||||
}
|
||||
|
||||
override fun showCheckmarkDialog(
|
||||
@@ -194,6 +207,37 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
).show()
|
||||
}
|
||||
|
||||
override fun showCheckmarkPopup(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
preferences: Preferences,
|
||||
color: PaletteColor,
|
||||
location: ScreenLocation,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback
|
||||
) {
|
||||
val dialog =
|
||||
supportFragmentManager.findFragmentByTag("historyEditor") as HistoryEditorDialog?
|
||||
?: return
|
||||
val view = dialog.dataView
|
||||
val corner = view.getTopLeftCorner()
|
||||
CheckmarkPopup(
|
||||
context = this@ShowHabitActivity,
|
||||
prefs = preferences,
|
||||
notes = notes,
|
||||
color = view.currentTheme().color(color).toInt(),
|
||||
anchor = view,
|
||||
value = selectedValue,
|
||||
).apply {
|
||||
onToggle = { v, n -> callback.onNotesSaved(v, n) }
|
||||
show(
|
||||
ScreenLocation(
|
||||
x = corner.x + location.x - POPUP_WIDTH / 2,
|
||||
y = corner.y + location.y,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showEditHabitScreen(habit: Habit) {
|
||||
startActivity(IntentFactory().startEditActivity(this@ShowHabitActivity, habit))
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
@@ -32,6 +33,8 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
import android.view.WindowManager
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM
|
||||
import android.widget.RelativeLayout.ALIGN_PARENT_TOP
|
||||
@@ -42,6 +45,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.content.FileProvider
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.platform.gui.toInt
|
||||
import org.isoron.uhabits.HabitsApplication
|
||||
import org.isoron.uhabits.R
|
||||
@@ -213,3 +217,42 @@ fun View.drawNotesIndicator(canvas: Canvas, color: Int, size: Float, notes: Stri
|
||||
|
||||
val View.sres: StyledResources
|
||||
get() = StyledResources(context)
|
||||
|
||||
fun PopupWindow.dimBehind() {
|
||||
// https://stackoverflow.com/questions/35874001/dim-the-background-using-popupwindow-in-android
|
||||
val container = contentView.rootView
|
||||
val context = contentView.context
|
||||
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val p = container.layoutParams as WindowManager.LayoutParams
|
||||
p.flags = p.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
|
||||
p.dimAmount = 0.5f
|
||||
wm.updateViewLayout(container, p)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute screen coordinates for the center of this view (in density-independent
|
||||
* pixels).
|
||||
*/
|
||||
fun View.getCenter(): ScreenLocation {
|
||||
val density = resources.displayMetrics.density
|
||||
val loc = IntArray(2)
|
||||
this.getLocationInWindow(loc)
|
||||
return ScreenLocation(
|
||||
x = ((loc[0] + width / 2) / density).toDouble(),
|
||||
y = ((loc[1] + height / 2) / density).toDouble(),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute screen coordinates for the top left corner of this view (in
|
||||
* density-independent pixels).
|
||||
*/
|
||||
fun View.getTopLeftCorner(): ScreenLocation {
|
||||
val density = resources.displayMetrics.density
|
||||
val loc = IntArray(2)
|
||||
this.getLocationInWindow(loc)
|
||||
return ScreenLocation(
|
||||
x = (loc[0] / density).toDouble(),
|
||||
y = (loc[1] / density).toDouble(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="?attr/contrast0" />
|
||||
<stroke
|
||||
android:width="2dp"
|
||||
android:color="?contrast40" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<size android:width="1dip"/>
|
||||
<size android:height="1dip"/>
|
||||
<solid android:color="?contrast40"/>
|
||||
</shape>
|
||||
72
uhabits-android/src/main/res/layout/checkmark_popup.xml
Normal file
72
uhabits-android/src/main/res/layout/checkmark_popup.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2016-2021 Álinson Santos Xavier <git@axavier.org>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:divider="@drawable/checkmark_dialog_divider"
|
||||
app:showDividers="middle"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/checkmark_dialog_bg">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatEditText
|
||||
android:id="@+id/notes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
android:textSize="@dimen/smallTextSize"
|
||||
android:padding="4dp"
|
||||
android:background="@color/transparent"
|
||||
android:hint="@string/notes"
|
||||
android:text="" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:orientation="horizontal"
|
||||
app:divider="@drawable/checkmark_dialog_divider"
|
||||
app:showDividers="middle">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/yesBtn"
|
||||
style="@style/CheckmarkPopupBtn"
|
||||
android:text="@string/fa_check" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/skipBtn"
|
||||
style="@style/CheckmarkPopupBtn"
|
||||
android:text="@string/fa_skipped" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/noBtn"
|
||||
style="@style/CheckmarkPopupBtn"
|
||||
android:text="@string/fa_times" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/unknownBtn"
|
||||
style="@style/CheckmarkPopupBtn"
|
||||
android:text="@string/fa_question" />
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
@@ -399,4 +399,15 @@
|
||||
<item name="selectable">true</item>
|
||||
</style>
|
||||
|
||||
<style name="CheckmarkPopupBtn">
|
||||
<item name="android:layout_width">0dp</item>
|
||||
<item name="android:layout_weight">1</item>
|
||||
<item name="android:layout_height">match_parent</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:clickable">true</item>
|
||||
<item name="android:focusable">true</item>
|
||||
<item name="android:background">@drawable/ripple_transparent</item>
|
||||
<item name="android:textSize">@dimen/smallerTextSize</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user