-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAINTROID-434 An option to enable/disable and adjust Zoom
- Loading branch information
1 parent
8bb6bb2
commit cfae324
Showing
16 changed files
with
268 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.catrobat.paintroid.dialog | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
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 | ||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.