Skip to content

Commit

Permalink
Paintroid 434: Zoom window settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
saat-sy committed Oct 4, 2022
1 parent 5b7f550 commit 23206d6
Show file tree
Hide file tree
Showing 13 changed files with 251 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
R.id.pocketpaint_options_about -> presenterMain.showAboutClicked()
R.id.pocketpaint_share_image_button -> presenterMain.shareImageClicked()
R.id.pocketpaint_options_feedback -> presenterMain.sendFeedback()
R.id.pocketpaint_zoom_window_settings ->
presenterMain.showZoomWindowSettingsClicked(
UserPreferences(getPreferences(MODE_PRIVATE))
)
R.id.pocketpaint_advanced_settings -> presenterMain.showAdvancedSettingsClicked()
android.R.id.home -> presenterMain.backToPocketCodeClicked()
else -> return false
Expand Down Expand Up @@ -451,7 +455,8 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
this,
layerModel,
workspace,
toolReference
toolReference,
UserPreferences(getPreferences(MODE_PRIVATE))
)
model = MainActivityModel()
defaultToolController = DefaultToolController(
Expand Down Expand Up @@ -528,6 +533,7 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener {
supportFragmentManager,
toolOptionsViewController,
zoomWindowController,
UserPreferences(getPreferences(MODE_PRIVATE))
)
layerPresenter.setDrawingSurface(drawingSurface)
appFragment.perspective = perspective
Expand Down
19 changes: 19 additions & 0 deletions Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package org.catrobat.paintroid
import android.content.SharedPreferences
import org.catrobat.paintroid.common.IMAGE_NUMBER_SHARED_PREFERENCES_TAG
import org.catrobat.paintroid.common.SHOW_LIKE_US_DIALOG_SHARED_PREFERENCES_TAG
import org.catrobat.paintroid.common.ZOOM_WINDOW_ENABLED_SHARED_PREFERENCES_TAG
import org.catrobat.paintroid.common.ZOOM_WINDOW_ZOOM_PERCENTAGE_SHARED_PREFERENCES_TAG

open class UserPreferences(var preferences: SharedPreferences) {
open val preferenceLikeUsDialogValue: Boolean
Expand All @@ -33,6 +35,23 @@ open class UserPreferences(var preferences: SharedPreferences) {
.putInt(IMAGE_NUMBER_SHARED_PREFERENCES_TAG, value)
.apply()
}
open var preferenceZoomWindowEnabled: Boolean
get() = preferences.getBoolean(ZOOM_WINDOW_ENABLED_SHARED_PREFERENCES_TAG, true)
set(value) {
preferences
.edit()
.putBoolean(ZOOM_WINDOW_ENABLED_SHARED_PREFERENCES_TAG, value)
.apply()
}

open var preferenceZoomWindowZoomPercentage: Int
get() = preferences.getInt(ZOOM_WINDOW_ZOOM_PERCENTAGE_SHARED_PREFERENCES_TAG, 100)
set(value) {
preferences
.edit()
.putInt(ZOOM_WINDOW_ZOOM_PERCENTAGE_SHARED_PREFERENCES_TAG, value)
.apply()
}

open fun setPreferenceLikeUsDialogValue() {
preferences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const val ABOUT_DIALOG_FRAGMENT_TAG = "aboutdialogfragment"
const val LIKE_US_DIALOG_FRAGMENT_TAG = "likeusdialogfragment"
const val RATE_US_DIALOG_FRAGMENT_TAG = "rateusdialogfragment"
const val FEEDBACK_DIALOG_FRAGMENT_TAG = "feedbackdialogfragment"
const val ZOOM_WINDOW_SETTINGS_DIALOG_FRAGMENT_TAG = "zoomwindowsettingsdialogfragment"
const val ADVANCED_SETTINGS_DIALOG_FRAGMENT_TAG = "advancedsettingsdialogfragment"
const val SAVE_DIALOG_FRAGMENT_TAG = "savedialogerror"
const val LOAD_DIALOG_FRAGMENT_TAG = "loadbitmapdialogerror"
Expand All @@ -43,6 +44,8 @@ const val CATROBAT_INFORMATION_DIALOG_TAG = "catrobatinformationdialogfragment"
const val CATROID_MEDIA_GALLERY_FRAGMENT_TAG = "catroidmediagalleryfragment"
const val PERMISSION_DIALOG_FRAGMENT_TAG = "permissiondialogfragment"
const val SHOW_LIKE_US_DIALOG_SHARED_PREFERENCES_TAG = "showlikeusdialog"
const val ZOOM_WINDOW_ENABLED_SHARED_PREFERENCES_TAG = "zoomwindowenabled"
const val ZOOM_WINDOW_ZOOM_PERCENTAGE_SHARED_PREFERENCES_TAG = "zoomwindowzoompercentage"
const val IMAGE_NUMBER_SHARED_PREFERENCES_TAG = "imagenumbertag"
const val SCALE_IMAGE_FRAGMENT_TAG = "showscaleimagedialog"
const val INDETERMINATE_PROGRESS_DIALOG_TAG = "indeterminateprogressdialogfragment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ package org.catrobat.paintroid.contract
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Bitmap
import android.net.Uri
import android.util.DisplayMetrics
import android.view.Menu
import androidx.annotation.ColorInt
import androidx.annotation.StringRes
import org.catrobat.paintroid.UserPreferences
import org.catrobat.paintroid.colorpicker.ColorHistory
import org.catrobat.paintroid.common.MainActivityConstants.ActivityRequestCode
import org.catrobat.paintroid.dialog.PermissionInfoDialog.PermissionType
Expand Down Expand Up @@ -58,6 +60,8 @@ interface MainActivityContracts {

fun showFeedbackDialog()

fun showZoomWindowSettingsDialog(sharedPreferences: UserPreferences)

fun showAdvancedSettingsDialog()

fun showOverwriteDialog(permissionCode: Int, isExport: Boolean)
Expand Down Expand Up @@ -215,6 +219,8 @@ interface MainActivityContracts {

fun showAboutClicked()

fun showZoomWindowSettingsClicked(sharedPreferences: UserPreferences)

fun showAdvancedSettingsClicked()

fun showRateUsDialog()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.catrobat.paintroid.dialog

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.DialogInterface
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat
import com.google.android.material.slider.Slider
import org.catrobat.paintroid.R
import org.catrobat.paintroid.UserPreferences
import org.catrobat.paintroid.tools.helper.AdvancedSettingsAlgorithms
import org.catrobat.paintroid.tools.implementation.DefaultToolPaint

class ZoomWindowSettingsDialog(
private val sharedPreferences: UserPreferences
) : MainActivityDialogFragment() {

private val initialEnabledValue = sharedPreferences.preferenceZoomWindowEnabled
private val initialPercentageValue = sharedPreferences.preferenceZoomWindowZoomPercentage

private var enabled = sharedPreferences.preferenceZoomWindowEnabled
private var percentage = sharedPreferences.preferenceZoomWindowZoomPercentage

@SuppressLint("SetTextI18n")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val enabledSwitch = view.findViewById<SwitchCompat>(R.id.pocketpaint_zoom_window_enabled)
val slider = view.findViewById<Slider>(R.id.pocketpaint_zoom_window_slider)
val sliderTextView = view.findViewById<TextView>(R.id.pocketpaint_zoom_window_slider_progress)

enabledSwitch.isChecked = initialEnabledValue
sliderTextView.text = "$initialPercentageValue%"
slider.value = initialPercentageValue.toFloat()

enabledSwitch.setOnCheckedChangeListener { _, isChecked ->
enabled = isChecked
}

slider.addOnChangeListener { _, value, _ ->
var percentageValue = value.toInt().toString()
sliderTextView.text = "$percentageValue%"

percentage = value.toInt()
}

slider.setLabelFormatter { value: Float ->
value.toInt().toString() + '%'
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val inflater = requireActivity().layoutInflater
val layout = inflater.inflate(R.layout.dialog_pocketpaint_zoomwindow_settings, null)
onViewCreated(layout, savedInstanceState)

return AlertDialog.Builder(requireContext(), R.style.PocketPaintAlertDialog)
.setTitle(R.string.menu_zoom_settings)
.setView(layout)
.setPositiveButton(R.string.pocketpaint_ok) { _, _ ->
sharedPreferences.preferenceZoomWindowEnabled = enabled
sharedPreferences.preferenceZoomWindowZoomPercentage = percentage
dismiss()
}
.setNegativeButton(R.string.cancel_button_text) { _, _ ->
sharedPreferences.preferenceZoomWindowEnabled = initialEnabledValue
sharedPreferences.preferenceZoomWindowZoomPercentage = initialPercentageValue
dismiss()
}
.create()
}

override fun onCancel(dialog: DialogInterface) {
sharedPreferences.preferenceZoomWindowEnabled = initialEnabledValue
sharedPreferences.preferenceZoomWindowZoomPercentage = initialPercentageValue
super.onCancel(dialog)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
*/
package org.catrobat.paintroid.listener

import android.content.SharedPreferences
import android.graphics.Point
import android.graphics.PointF
import android.os.Handler
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import org.catrobat.paintroid.UserPreferences
import org.catrobat.paintroid.tools.Tool
import org.catrobat.paintroid.tools.Tool.StateChange
import org.catrobat.paintroid.tools.ToolType
Expand All @@ -44,7 +46,7 @@ private const val JITTER_DISTANCE_THRESHOLD = 50f
open class DrawingSurfaceListener(
private val autoScrollTask: AutoScrollTask,
private val callback: DrawingSurfaceListenerCallback,
private val displayDensity: Float
private val displayDensity: Float,
) : OnTouchListener {
private var touchMode: TouchMode
private var pointerDistance = 0f
Expand All @@ -58,6 +60,8 @@ open class DrawingSurfaceListener(
private var autoScroll = true
private var timerStartDraw = 0.toLong()
private lateinit var zoomController: ZoomWindowController
private var callZoomWindow: Boolean = true
private lateinit var sharedPreferences: UserPreferences

private var recentTouchEventsData: MutableList<TouchEventData> = mutableListOf()

Expand Down Expand Up @@ -106,9 +110,12 @@ open class DrawingSurfaceListener(
}

fun setZoomController(
zoomWindowController: ZoomWindowController
zoomWindowController: ZoomWindowController,
sharedPreferences: UserPreferences
) {
zoomController = zoomWindowController
this.sharedPreferences = sharedPreferences

}

private fun handleActionMove(currentTool: Tool?, view: View, event: MotionEvent) {
Expand Down Expand Up @@ -139,10 +146,12 @@ open class DrawingSurfaceListener(
}
currentTool.handleMove(canvasTouchPoint)
}
if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) {
zoomController.onMove(canvasTouchPoint)
} else {
zoomController.onMove(currentTool.toolPositionCoordinates(canvasTouchPoint))
if(callZoomWindow) {
if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) {
zoomController.onMove(canvasTouchPoint)
} else {
zoomController.onMove(currentTool.toolPositionCoordinates(canvasTouchPoint))
}
}
} else {
disableAutoScroll()
Expand Down Expand Up @@ -186,11 +195,16 @@ open class DrawingSurfaceListener(
setEvenPointAndViewDimensionsForAutoScrollTask(view)
autoScrollTask.start()
}
if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) {
zoomController.show(canvasTouchPoint)
if(sharedPreferences.preferenceZoomWindowEnabled) {
if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) {
zoomController.show(canvasTouchPoint)
} else {
currentTool?.toolPositionCoordinates(canvasTouchPoint)
?.let { zoomController.show(it) }
}
callZoomWindow = true
} else {
currentTool?.toolPositionCoordinates(canvasTouchPoint)
?.let { zoomController.show(it) }
callZoomWindow = false
}
}
MotionEvent.ACTION_MOVE -> handleActionMove(currentTool, view, event)
Expand Down Expand Up @@ -227,7 +241,7 @@ open class DrawingSurfaceListener(
eventX = 0f
eventY = 0f
touchMode = TouchMode.DRAW
zoomController.dismiss()
if(callZoomWindow) zoomController.dismiss()
callback.getCurrentTool()?.handToolMode()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ open class MainActivityPresenter(
navigator.showAboutDialog()
}

override fun showZoomWindowSettingsClicked(sharedPreferences: UserPreferences) {
navigator.showZoomWindowSettingsDialog(sharedPreferences)
}

override fun showAdvancedSettingsClicked() {
navigator.showAdvancedSettingsDialog()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.catrobat.paintroid.ui

import android.content.Context
import android.content.SharedPreferences
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.BitmapShader
Expand All @@ -43,6 +44,7 @@ import androidx.core.content.ContextCompat
import androidx.test.espresso.idling.CountingIdlingResource
import androidx.fragment.app.FragmentManager
import org.catrobat.paintroid.R
import org.catrobat.paintroid.UserPreferences
import org.catrobat.paintroid.colorpicker.ColorPickerDialog
import org.catrobat.paintroid.common.COLOR_PICKER_DIALOG_TAG
import org.catrobat.paintroid.contract.LayerContracts
Expand Down Expand Up @@ -74,6 +76,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
private lateinit var fragmentManager: FragmentManager
private lateinit var idlingResource: CountingIdlingResource
private lateinit var zoomController: ZoomWindowController
private lateinit var sharedPreferences: UserPreferences

constructor(context: Context?, attrSet: AttributeSet?) : super(context, attrSet)

Expand Down Expand Up @@ -129,7 +132,8 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
idlingResource: CountingIdlingResource,
fragmentManager: FragmentManager,
toolOptionsViewController: ToolOptionsViewController,
zoomController: ZoomWindowController
zoomController: ZoomWindowController,
sharedPreferences: UserPreferences
) {
this.layerModel = layerModel
this.perspective = perspective
Expand All @@ -138,7 +142,8 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback {
this.idlingResource = idlingResource
this.fragmentManager = fragmentManager
this.zoomController = zoomController
drawingSurfaceListener.setZoomController(zoomWindowController = zoomController)
drawingSurfaceListener.setZoomController(zoomController, sharedPreferences)
this.sharedPreferences = sharedPreferences
}

@Synchronized
Expand Down
Loading

0 comments on commit 23206d6

Please sign in to comment.