From 17241927171cdd08bdcaba4639c1a7b551e27eff Mon Sep 17 00:00:00 2001 From: Saatwik Date: Wed, 13 Jul 2022 14:08:35 +0530 Subject: [PATCH 01/10] Zoom window(empty) appears when the drawing board is touched --- .../espresso/ZoomWindowIntegrationTest.kt | 110 ++++++++++++++++++ .../test/espresso/util/UiInteractions.java | 69 +++++++++++ .../util/wrappers/ZoomWindowInteraction.java | 78 +++++++++++++ .../org/catrobat/paintroid/MainActivity.kt | 10 +- .../listener/DrawingSurfaceListener.kt | 14 +++ .../catrobat/paintroid/ui/DrawingSurface.kt | 10 +- .../zoomwindow/DefaultZoomWindowController.kt | 69 +++++++++++ .../ui/zoomwindow/ZoomWindowController.kt | 11 ++ .../pocketpaint_zoom_window_shape.xml | 4 + .../res/layout/activity_pocketpaint_main.xml | 7 ++ .../layout/pocketpaint_layout_zoom_window.xml | 18 +++ 11 files changed, 397 insertions(+), 3 deletions(-) create mode 100644 Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt create mode 100644 Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java create mode 100644 Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt create mode 100644 Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt create mode 100644 Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml create mode 100644 Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt new file mode 100644 index 0000000000..1df6b37938 --- /dev/null +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt @@ -0,0 +1,110 @@ +package org.catrobat.paintroid.test.espresso + +import android.content.Intent +import android.os.Build +import android.text.Layout +import android.widget.RelativeLayout +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.CoordinatesProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import org.catrobat.paintroid.MainActivity +import org.catrobat.paintroid.common.TEMP_IMAGE_PATH +import org.catrobat.paintroid.test.espresso.util.UiInteractions.touchCenterMiddle +import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.onDrawingSurfaceView +import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction +import org.catrobat.paintroid.tools.ToolType +import org.junit.Before +import org.junit.Rule +import org.junit.runner.RunWith +import java.io.File +import org.catrobat.paintroid.R +import org.junit.Test +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.* +import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider +import org.catrobat.paintroid.test.espresso.util.UiInteractions.PressAndReleaseActions.* +import org.catrobat.paintroid.test.espresso.util.UiInteractions.touchLongAt +import org.catrobat.paintroid.test.espresso.util.wrappers.ZoomWindowInteraction.onZoomWindow +import org.junit.After + + +@RunWith(AndroidJUnit4::class) +class ZoomWindowIntegrationTest { + + @get:Rule + val launchActivityRule = ActivityTestRule(MainActivity::class.java) + + @Before + fun setUp() { + ToolBarViewInteraction.onToolBarView() + .performSelectTool(ToolType.BRUSH) + } + + @After + fun tearDown() { + tearDownPressAndRelease() + } + + @Test + fun windowAppearsWhenDrawingSurfaceIsTouched() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) + + onView(withId(R.id.pocketpaint_zoom_window)) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + onDrawingSurfaceView() + .perform(releaseAction()) + } + + @Test + fun windowDisappearsWhenDrawingSurfaceIsPressedAndReleased() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) + + onDrawingSurfaceView() + .perform(releaseAction()) + + onView(withId(R.id.pocketpaint_zoom_window)) + .check(matches(withEffectiveVisibility(Visibility.GONE))) + } + + @Test + fun windowAppearsOnRightWhenClickedAtTheTopLeft() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + onZoomWindow() + .checkAlignment(RelativeLayout.ALIGN_PARENT_RIGHT) + } else { + // Layout params rules for ALIGN_PARENT_LEFT and ALIGN_PARENT_RIGHT from + // https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams#getRules() + // for API level less than M + onZoomWindow() + .checkAlignmentBelowM(11) + } + + onDrawingSurfaceView() + .perform(releaseAction()) + } + + @Test + fun windowAppearsOnLeftWhenClickedAnywhere() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + onZoomWindow() + .checkAlignment(RelativeLayout.ALIGN_PARENT_LEFT) + } else { + onZoomWindow() + .checkAlignmentBelowM(9) + } + + onDrawingSurfaceView() + .perform(releaseAction()) + } +} \ No newline at end of file diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java index c1d16eea9b..ece08b740a 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java @@ -53,6 +53,7 @@ import static androidx.test.espresso.action.ViewActions.actionWithAssertions; import static androidx.test.espresso.matcher.ViewMatchers.assertThat; import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; @@ -306,4 +307,72 @@ public Status sendTap(UiController uiController, float[] coordinates, float[] pr MotionEvent.BUTTON_PRIMARY); } } + + public static class PressAndReleaseActions { + + static MotionEvent motionEvent = null; + + public static PressAction pressAction(DrawingSurfaceLocationProvider coordinates) { + return new PressAction(coordinates); + } + + public static ReleaseAction releaseAction() { + return new ReleaseAction(); + } + + public static void tearDownPressAndRelease() { + motionEvent = null; + } + + public static class PressAction implements ViewAction { + + DrawingSurfaceLocationProvider coordinates; + + PressAction(DrawingSurfaceLocationProvider coords) { + this.coordinates = coords; + } + + @Override + public Matcher getConstraints() { + return isDisplayingAtLeast(90); + } + + @Override + public String getDescription() { + return "Press Action"; + } + + @Override + public void perform(UiController uiController, View view) { + if (motionEvent != null) { + throw new AssertionError("Only one view can be held at a time"); + } + float[] coords = coordinates.calculateCoordinates(view); + float[] precision = Press.FINGER.describePrecision(); + + motionEvent = MotionEvents.sendDown(uiController, coords, precision).down; + } + } + + public static class ReleaseAction implements ViewAction { + + @Override + public Matcher getConstraints() { + return isDisplayingAtLeast(90); + } + + @Override + public String getDescription() { + return "Release"; + } + + @Override + public void perform(UiController uiController, View view) { + if (motionEvent == null) { + throw new AssertionError("Only one view can be held at a time"); + } + MotionEvents.sendUp(uiController, motionEvent); + } + } + } } diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java new file mode 100644 index 0000000000..30f95cc2e5 --- /dev/null +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java @@ -0,0 +1,78 @@ +package org.catrobat.paintroid.test.espresso.util.wrappers; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +import static org.catrobat.paintroid.test.espresso.util.MainActivityHelper.getMainActivityFromView; + +import android.util.Log; +import android.view.View; +import android.widget.RelativeLayout; + +import org.catrobat.paintroid.MainActivity; +import org.catrobat.paintroid.R; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; + +import java.util.Arrays; + +public class ZoomWindowInteraction extends CustomViewInteraction { + + private ZoomWindowInteraction() { + super(onView(withId(R.id.pocketpaint_zoom_window))); + } + + public static ZoomWindowInteraction onZoomWindow() { + return new ZoomWindowInteraction(); + } + + public ZoomWindowInteraction checkAlignment(final int verb) { + check(matches(new TypeSafeMatcher() { + @Override + protected boolean matchesSafely(View view) { + MainActivity activity = getMainActivityFromView(view); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) + activity.findViewById(R.id.pocketpaint_zoom_window_inner).getLayoutParams(); + + int rulesFromLayout = layoutParams.getRule(verb); + + Log.d("TAG", String.valueOf(rulesFromLayout)); + for(int i : layoutParams.getRules()) + Log.d("TAG", String.valueOf(i)); + + return rulesFromLayout == -1; + } + + @Override + public void describeTo(Description description) { + String alignedAccordingTo = + (verb == RelativeLayout.ALIGN_PARENT_LEFT) ? "left" : "right"; + description.appendText("The zoom window is aligned to the " + alignedAccordingTo); + } + })); + return this; + } + + public ZoomWindowInteraction checkAlignmentBelowM(final int index) { + check(matches(new TypeSafeMatcher() { + @Override + protected boolean matchesSafely(View view) { + MainActivity activity = getMainActivityFromView(view); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) + activity.findViewById(R.id.pocketpaint_zoom_window_inner).getLayoutParams(); + + int[] rulesFromLayout = layoutParams.getRules(); + + return rulesFromLayout[index] == -1; + } + + @Override + public void describeTo(Description description) { + String alignedAccordingTo = index == 11 ? "right" : "left"; + description.appendText("The zoom window is aligned to " + alignedAccordingTo); + } + })); + return this; + } +} diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt index edbaf27963..56c7b1c79d 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt @@ -93,6 +93,7 @@ import org.catrobat.paintroid.ui.viewholder.BottomNavigationViewHolder import org.catrobat.paintroid.ui.viewholder.DrawerLayoutViewHolder import org.catrobat.paintroid.ui.viewholder.LayerMenuViewHolder import org.catrobat.paintroid.ui.viewholder.TopBarViewHolder +import org.catrobat.paintroid.ui.zoomwindow.DefaultZoomWindowController import java.io.File import java.util.Locale @@ -127,6 +128,9 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { @VisibleForTesting lateinit var toolOptionsViewController: ToolOptionsViewController + @VisibleForTesting + lateinit var zoomWindowController: DefaultZoomWindowController + lateinit var bottomNavigationViewHolder: BottomNavigationViewHolder private lateinit var layerPresenter: LayerPresenter @@ -401,6 +405,9 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { val bottomBarLayout = findViewById(R.id.pocketpaint_main_bottom_bar) val bottomNavigationView = findViewById(R.id.pocketpaint_main_bottom_navigation) toolOptionsViewController = DefaultToolOptionsViewController(this) + + zoomWindowController = DefaultZoomWindowController(this, layerModel) + drawerLayoutViewHolder = DrawerLayoutViewHolder(drawerLayout) val topBarViewHolder = TopBarViewHolder(topBarLayout) val bottomBarViewHolder = BottomBarViewHolder(bottomBarLayout) @@ -481,7 +488,8 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { perspective, toolReference, toolOptionsViewController, - supportFragmentManager + supportFragmentManager, + zoomWindowController ) layerPresenter.setDrawingSurface(drawingSurface) appFragment.perspective = perspective diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index 620007b65b..fb1d13fe7e 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -24,11 +24,14 @@ import android.os.Handler import android.view.MotionEvent import android.view.View import android.view.View.OnTouchListener +import org.catrobat.paintroid.MainActivity import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.Tool.StateChange import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.DrawingSurface +import org.catrobat.paintroid.ui.zoomwindow.DefaultZoomWindowController +import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController import java.util.EnumSet import kotlin.collections.ArrayList import kotlin.collections.MutableList @@ -56,6 +59,7 @@ open class DrawingSurfaceListener( private val drawerEdgeSize: Int = (DRAWER_EDGE_SIZE * displayDensity + CONSTANT_1).toInt() private var autoScroll = true private var timerStartDraw = 0.toLong() + private lateinit var zoomController: ZoomWindowController private var recentTouchEventsData: MutableList = mutableListOf() @@ -103,6 +107,12 @@ open class DrawingSurfaceListener( autoScrollTask.setViewDimensions(view.width, view.height) } + fun setZoomController( + zoomWindowContoller: ZoomWindowController + ) { + zoomController = zoomWindowContoller + } + private fun handleActionMove(currentTool: Tool?, view: View, event: MotionEvent) { val xOld: Float val yOld: Float @@ -149,6 +159,7 @@ open class DrawingSurfaceListener( if (xOld > 0 && xMidPoint != xOld || yOld > 0 && yMidPoint != yOld) { callback.translatePerspective(xMidPoint - xOld, yMidPoint - yOld) } + zoomController.dismissOnPinch() } } @@ -172,6 +183,8 @@ open class DrawingSurfaceListener( setEvenPointAndViewDimensionsForAutoScrollTask(view) autoScrollTask.start() } + ///////////////// + zoomController.show(canvasTouchPoint) } MotionEvent.ACTION_MOVE -> handleActionMove(currentTool, view, event) MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { @@ -207,6 +220,7 @@ open class DrawingSurfaceListener( eventX = 0f eventY = 0f touchMode = TouchMode.DRAW + zoomController.dismiss() } } drawingSurface.refreshDrawingSurface() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index b2d79d404c..b025c02df1 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -53,6 +53,7 @@ import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.options.ToolOptionsViewController +import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { private val canvasRect = Rect() @@ -69,6 +70,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { private lateinit var toolReference: ToolReference private lateinit var toolOptionsViewController: ToolOptionsViewController private lateinit var fragmentManager: FragmentManager + private lateinit var zoomController: ZoomWindowController constructor(context: Context?, attrSet: AttributeSet?) : super(context, attrSet) @@ -109,7 +111,8 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { override fun getToolOptionsViewController(): ToolOptionsViewController = toolOptionsViewController } - drawingSurfaceListener = DrawingSurfaceListener(autoScrollTask, callback, density) + drawingSurfaceListener = + DrawingSurfaceListener(autoScrollTask, callback, density) setOnTouchListener(drawingSurfaceListener) } @@ -122,13 +125,16 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { perspective: Perspective, toolReference: ToolReference, toolOptionsViewController: ToolOptionsViewController, - fragmentManager: FragmentManager + fragmentManager: FragmentManager, + zoomController: ZoomWindowController ) { this.layerModel = layerModel this.perspective = perspective this.toolReference = toolReference this.toolOptionsViewController = toolOptionsViewController this.fragmentManager = fragmentManager + this.zoomController = zoomController + drawingSurfaceListener.setZoomController(zoomWindowContoller = zoomController) } @Synchronized diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt new file mode 100644 index 0000000000..4d14f979b9 --- /dev/null +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -0,0 +1,69 @@ +package org.catrobat.paintroid.ui.zoomwindow + +import android.app.Activity +import android.graphics.PointF +import android.os.Build +import android.util.Log +import android.view.View +import android.view.ViewGroup +import android.widget.RelativeLayout +import org.catrobat.paintroid.R +import org.catrobat.paintroid.contract.LayerContracts + +class DefaultZoomWindowController(val activity: Activity, val layerModel: LayerContracts.Model) : ZoomWindowController { + + private val zoomWindow: RelativeLayout = + activity.findViewById(R.id.pocketpaint_zoom_window) + private val zoomWindowShape: ViewGroup = + activity.findViewById(R.id.pocketpaint_zoom_window_inner) + + override fun show(coordinates: PointF) { + if(isPointOnCanvas(coordinates.x, coordinates.y)){ + if(shouldBeInTheRight(coordinates = coordinates)) { + Log.d("TAG", "YES") + setLayoutAlignment(right = true) + } + else { + setLayoutAlignment(right = false) + } + + zoomWindow.visibility = View.VISIBLE + } + } + + override fun dismiss() { + zoomWindow.visibility = View.GONE + } + + override fun dismissOnPinch() { + zoomWindow.visibility = View.GONE + } + + private fun isPointOnCanvas(pointX: Float, pointY: Float): Boolean = + pointX > 0 && pointX < layerModel.width && pointY > 0 && pointY < layerModel.height + + private fun shouldBeInTheRight(coordinates: PointF) : Boolean { + if(coordinates.x < layerModel.width / 3 && coordinates.y < layerModel.height / 2) + return true + return false + } + + private fun setLayoutAlignment(right: Boolean) { + val params : RelativeLayout.LayoutParams = + zoomWindowShape.layoutParams as RelativeLayout.LayoutParams + if(right) { + params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT) + params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT) + } else { + params.addRule(RelativeLayout.ALIGN_PARENT_LEFT) + params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT) + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Log.d("TAG", params.getRule(RelativeLayout.ALIGN_PARENT_RIGHT).toString()) + } + + Log.d("TAG", params.rules.contentToString()) + Log.d("TAG", params.rules.indexOf(-1).toString()) + zoomWindowShape.layoutParams = params + } +} \ No newline at end of file diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt new file mode 100644 index 0000000000..a6ce34e671 --- /dev/null +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt @@ -0,0 +1,11 @@ +package org.catrobat.paintroid.ui.zoomwindow + +import android.graphics.PointF + +interface ZoomWindowController { + fun show(coordinates: PointF) + + fun dismiss() + + fun dismissOnPinch() +} \ No newline at end of file diff --git a/Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml b/Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml new file mode 100644 index 0000000000..e2b2e6be10 --- /dev/null +++ b/Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml b/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml index 09f7bcb5ec..c571ebcf7b 100644 --- a/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml +++ b/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml @@ -52,6 +52,13 @@ android:layout_above="@id/pocketpaint_main_bottom_bar" android:layout_below="@+id/pocketpaint_layout_top_bar"/> + + + + + + + \ No newline at end of file From 3534eec9050bccf8382e5c5635986c06befc04c0 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Wed, 13 Jul 2022 14:08:35 +0530 Subject: [PATCH 02/10] Paintroid 433: Zoom window appears when the canvas is touched --- .../espresso/ZoomWindowIntegrationTest.kt | 110 ++++++++++++++++++ .../test/espresso/util/UiInteractions.java | 69 +++++++++++ .../util/wrappers/ZoomWindowInteraction.java | 78 +++++++++++++ .../org/catrobat/paintroid/MainActivity.kt | 6 + .../listener/DrawingSurfaceListener.kt | 14 +++ .../catrobat/paintroid/ui/DrawingSurface.kt | 6 +- .../zoomwindow/DefaultZoomWindowController.kt | 69 +++++++++++ .../ui/zoomwindow/ZoomWindowController.kt | 11 ++ .../pocketpaint_zoom_window_shape.xml | 4 + .../res/layout/activity_pocketpaint_main.xml | 7 ++ .../layout/pocketpaint_layout_zoom_window.xml | 18 +++ 11 files changed, 391 insertions(+), 1 deletion(-) create mode 100644 Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt create mode 100644 Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java create mode 100644 Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt create mode 100644 Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt create mode 100644 Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml create mode 100644 Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt new file mode 100644 index 0000000000..1df6b37938 --- /dev/null +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt @@ -0,0 +1,110 @@ +package org.catrobat.paintroid.test.espresso + +import android.content.Intent +import android.os.Build +import android.text.Layout +import android.widget.RelativeLayout +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.CoordinatesProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.rule.ActivityTestRule +import org.catrobat.paintroid.MainActivity +import org.catrobat.paintroid.common.TEMP_IMAGE_PATH +import org.catrobat.paintroid.test.espresso.util.UiInteractions.touchCenterMiddle +import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.onDrawingSurfaceView +import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction +import org.catrobat.paintroid.tools.ToolType +import org.junit.Before +import org.junit.Rule +import org.junit.runner.RunWith +import java.io.File +import org.catrobat.paintroid.R +import org.junit.Test +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.* +import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider +import org.catrobat.paintroid.test.espresso.util.UiInteractions.PressAndReleaseActions.* +import org.catrobat.paintroid.test.espresso.util.UiInteractions.touchLongAt +import org.catrobat.paintroid.test.espresso.util.wrappers.ZoomWindowInteraction.onZoomWindow +import org.junit.After + + +@RunWith(AndroidJUnit4::class) +class ZoomWindowIntegrationTest { + + @get:Rule + val launchActivityRule = ActivityTestRule(MainActivity::class.java) + + @Before + fun setUp() { + ToolBarViewInteraction.onToolBarView() + .performSelectTool(ToolType.BRUSH) + } + + @After + fun tearDown() { + tearDownPressAndRelease() + } + + @Test + fun windowAppearsWhenDrawingSurfaceIsTouched() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) + + onView(withId(R.id.pocketpaint_zoom_window)) + .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + + onDrawingSurfaceView() + .perform(releaseAction()) + } + + @Test + fun windowDisappearsWhenDrawingSurfaceIsPressedAndReleased() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) + + onDrawingSurfaceView() + .perform(releaseAction()) + + onView(withId(R.id.pocketpaint_zoom_window)) + .check(matches(withEffectiveVisibility(Visibility.GONE))) + } + + @Test + fun windowAppearsOnRightWhenClickedAtTheTopLeft() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.HALFWAY_TOP_LEFT)) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + onZoomWindow() + .checkAlignment(RelativeLayout.ALIGN_PARENT_RIGHT) + } else { + // Layout params rules for ALIGN_PARENT_LEFT and ALIGN_PARENT_RIGHT from + // https://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams#getRules() + // for API level less than M + onZoomWindow() + .checkAlignmentBelowM(11) + } + + onDrawingSurfaceView() + .perform(releaseAction()) + } + + @Test + fun windowAppearsOnLeftWhenClickedAnywhere() { + onDrawingSurfaceView() + .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + onZoomWindow() + .checkAlignment(RelativeLayout.ALIGN_PARENT_LEFT) + } else { + onZoomWindow() + .checkAlignmentBelowM(9) + } + + onDrawingSurfaceView() + .perform(releaseAction()) + } +} \ No newline at end of file diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java index c1d16eea9b..ece08b740a 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/UiInteractions.java @@ -53,6 +53,7 @@ import static androidx.test.espresso.action.ViewActions.actionWithAssertions; import static androidx.test.espresso.matcher.ViewMatchers.assertThat; import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; @@ -306,4 +307,72 @@ public Status sendTap(UiController uiController, float[] coordinates, float[] pr MotionEvent.BUTTON_PRIMARY); } } + + public static class PressAndReleaseActions { + + static MotionEvent motionEvent = null; + + public static PressAction pressAction(DrawingSurfaceLocationProvider coordinates) { + return new PressAction(coordinates); + } + + public static ReleaseAction releaseAction() { + return new ReleaseAction(); + } + + public static void tearDownPressAndRelease() { + motionEvent = null; + } + + public static class PressAction implements ViewAction { + + DrawingSurfaceLocationProvider coordinates; + + PressAction(DrawingSurfaceLocationProvider coords) { + this.coordinates = coords; + } + + @Override + public Matcher getConstraints() { + return isDisplayingAtLeast(90); + } + + @Override + public String getDescription() { + return "Press Action"; + } + + @Override + public void perform(UiController uiController, View view) { + if (motionEvent != null) { + throw new AssertionError("Only one view can be held at a time"); + } + float[] coords = coordinates.calculateCoordinates(view); + float[] precision = Press.FINGER.describePrecision(); + + motionEvent = MotionEvents.sendDown(uiController, coords, precision).down; + } + } + + public static class ReleaseAction implements ViewAction { + + @Override + public Matcher getConstraints() { + return isDisplayingAtLeast(90); + } + + @Override + public String getDescription() { + return "Release"; + } + + @Override + public void perform(UiController uiController, View view) { + if (motionEvent == null) { + throw new AssertionError("Only one view can be held at a time"); + } + MotionEvents.sendUp(uiController, motionEvent); + } + } + } } diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java new file mode 100644 index 0000000000..30f95cc2e5 --- /dev/null +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java @@ -0,0 +1,78 @@ +package org.catrobat.paintroid.test.espresso.util.wrappers; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.assertion.ViewAssertions.matches; +import static androidx.test.espresso.matcher.ViewMatchers.withId; + +import static org.catrobat.paintroid.test.espresso.util.MainActivityHelper.getMainActivityFromView; + +import android.util.Log; +import android.view.View; +import android.widget.RelativeLayout; + +import org.catrobat.paintroid.MainActivity; +import org.catrobat.paintroid.R; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; + +import java.util.Arrays; + +public class ZoomWindowInteraction extends CustomViewInteraction { + + private ZoomWindowInteraction() { + super(onView(withId(R.id.pocketpaint_zoom_window))); + } + + public static ZoomWindowInteraction onZoomWindow() { + return new ZoomWindowInteraction(); + } + + public ZoomWindowInteraction checkAlignment(final int verb) { + check(matches(new TypeSafeMatcher() { + @Override + protected boolean matchesSafely(View view) { + MainActivity activity = getMainActivityFromView(view); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) + activity.findViewById(R.id.pocketpaint_zoom_window_inner).getLayoutParams(); + + int rulesFromLayout = layoutParams.getRule(verb); + + Log.d("TAG", String.valueOf(rulesFromLayout)); + for(int i : layoutParams.getRules()) + Log.d("TAG", String.valueOf(i)); + + return rulesFromLayout == -1; + } + + @Override + public void describeTo(Description description) { + String alignedAccordingTo = + (verb == RelativeLayout.ALIGN_PARENT_LEFT) ? "left" : "right"; + description.appendText("The zoom window is aligned to the " + alignedAccordingTo); + } + })); + return this; + } + + public ZoomWindowInteraction checkAlignmentBelowM(final int index) { + check(matches(new TypeSafeMatcher() { + @Override + protected boolean matchesSafely(View view) { + MainActivity activity = getMainActivityFromView(view); + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) + activity.findViewById(R.id.pocketpaint_zoom_window_inner).getLayoutParams(); + + int[] rulesFromLayout = layoutParams.getRules(); + + return rulesFromLayout[index] == -1; + } + + @Override + public void describeTo(Description description) { + String alignedAccordingTo = index == 11 ? "right" : "left"; + description.appendText("The zoom window is aligned to " + alignedAccordingTo); + } + })); + return this; + } +} diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt index 2234036b10..a4ac4d9d78 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt @@ -98,6 +98,7 @@ import org.catrobat.paintroid.ui.viewholder.BottomNavigationViewHolder import org.catrobat.paintroid.ui.viewholder.DrawerLayoutViewHolder import org.catrobat.paintroid.ui.viewholder.LayerMenuViewHolder import org.catrobat.paintroid.ui.viewholder.TopBarViewHolder +import org.catrobat.paintroid.ui.zoomwindow.DefaultZoomWindowController import java.io.File import java.util.Locale @@ -134,6 +135,9 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { var idlingResource: CountingIdlingResource = CountingIdlingResource("MainIdleResource") + @VisibleForTesting + lateinit var zoomWindowController: DefaultZoomWindowController + lateinit var bottomNavigationViewHolder: BottomNavigationViewHolder private lateinit var layerPresenter: LayerPresenter @@ -427,6 +431,7 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { val bottomBarLayout = findViewById(R.id.pocketpaint_main_bottom_bar) val bottomNavigationView = findViewById(R.id.pocketpaint_main_bottom_navigation) toolOptionsViewController = DefaultToolOptionsViewController(this, idlingResource) + zoomWindowController = DefaultZoomWindowController(this, layerModel) drawerLayoutViewHolder = DrawerLayoutViewHolder(drawerLayout) val topBarViewHolder = TopBarViewHolder(topBarLayout) val bottomBarViewHolder = BottomBarViewHolder(bottomBarLayout) @@ -513,6 +518,7 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { idlingResource, supportFragmentManager, toolOptionsViewController + zoomWindowController, ) layerPresenter.setDrawingSurface(drawingSurface) appFragment.perspective = perspective diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index 6beef74067..e25fea7801 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -24,11 +24,14 @@ import android.os.Handler import android.view.MotionEvent import android.view.View import android.view.View.OnTouchListener +import org.catrobat.paintroid.MainActivity import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.Tool.StateChange import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.DrawingSurface +import org.catrobat.paintroid.ui.zoomwindow.DefaultZoomWindowController +import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController import java.util.EnumSet import kotlin.collections.ArrayList import kotlin.collections.MutableList @@ -56,6 +59,7 @@ open class DrawingSurfaceListener( private val drawerEdgeSize: Int = (DRAWER_EDGE_SIZE * displayDensity + CONSTANT_1).toInt() private var autoScroll = true private var timerStartDraw = 0.toLong() + private lateinit var zoomController: ZoomWindowController private var recentTouchEventsData: MutableList = mutableListOf() @@ -103,6 +107,12 @@ open class DrawingSurfaceListener( autoScrollTask.setViewDimensions(view.width, view.height) } + fun setZoomController( + zoomWindowContoller: ZoomWindowController + ) { + zoomController = zoomWindowContoller + } + private fun handleActionMove(currentTool: Tool?, view: View, event: MotionEvent) { val xOld: Float val yOld: Float @@ -149,6 +159,7 @@ open class DrawingSurfaceListener( if (xOld > 0 && xMidPoint != xOld || yOld > 0 && yMidPoint != yOld) { callback.translatePerspective(xMidPoint - xOld, yMidPoint - yOld) } + zoomController.dismissOnPinch() } } @@ -172,6 +183,8 @@ open class DrawingSurfaceListener( setEvenPointAndViewDimensionsForAutoScrollTask(view) autoScrollTask.start() } + ///////////////// + zoomController.show(canvasTouchPoint) } MotionEvent.ACTION_MOVE -> handleActionMove(currentTool, view, event) MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { @@ -207,6 +220,7 @@ open class DrawingSurfaceListener( eventX = 0f eventY = 0f touchMode = TouchMode.DRAW + zoomController.dismiss() } } drawingSurface.refreshDrawingSurface() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index 307e79c826..65d590edb7 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -54,6 +54,7 @@ import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.options.ToolOptionsViewController +import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { private val canvasRect = Rect() @@ -71,6 +72,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { private lateinit var toolOptionsViewController: ToolOptionsViewController private lateinit var fragmentManager: FragmentManager private lateinit var idlingResource: CountingIdlingResource + private lateinit var zoomController: ZoomWindowController constructor(context: Context?, attrSet: AttributeSet?) : super(context, attrSet) @@ -126,6 +128,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { idlingResource: CountingIdlingResource, fragmentManager: FragmentManager, toolOptionsViewController: ToolOptionsViewController + zoomController: ZoomWindowController ) { this.layerModel = layerModel this.perspective = perspective @@ -133,7 +136,8 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { this.toolOptionsViewController = toolOptionsViewController this.idlingResource = idlingResource this.fragmentManager = fragmentManager - this.toolOptionsViewController = toolOptionsViewController + this.zoomController = zoomController + drawingSurfaceListener.setZoomController(zoomWindowContoller = zoomController) } @Synchronized diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt new file mode 100644 index 0000000000..4d14f979b9 --- /dev/null +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -0,0 +1,69 @@ +package org.catrobat.paintroid.ui.zoomwindow + +import android.app.Activity +import android.graphics.PointF +import android.os.Build +import android.util.Log +import android.view.View +import android.view.ViewGroup +import android.widget.RelativeLayout +import org.catrobat.paintroid.R +import org.catrobat.paintroid.contract.LayerContracts + +class DefaultZoomWindowController(val activity: Activity, val layerModel: LayerContracts.Model) : ZoomWindowController { + + private val zoomWindow: RelativeLayout = + activity.findViewById(R.id.pocketpaint_zoom_window) + private val zoomWindowShape: ViewGroup = + activity.findViewById(R.id.pocketpaint_zoom_window_inner) + + override fun show(coordinates: PointF) { + if(isPointOnCanvas(coordinates.x, coordinates.y)){ + if(shouldBeInTheRight(coordinates = coordinates)) { + Log.d("TAG", "YES") + setLayoutAlignment(right = true) + } + else { + setLayoutAlignment(right = false) + } + + zoomWindow.visibility = View.VISIBLE + } + } + + override fun dismiss() { + zoomWindow.visibility = View.GONE + } + + override fun dismissOnPinch() { + zoomWindow.visibility = View.GONE + } + + private fun isPointOnCanvas(pointX: Float, pointY: Float): Boolean = + pointX > 0 && pointX < layerModel.width && pointY > 0 && pointY < layerModel.height + + private fun shouldBeInTheRight(coordinates: PointF) : Boolean { + if(coordinates.x < layerModel.width / 3 && coordinates.y < layerModel.height / 2) + return true + return false + } + + private fun setLayoutAlignment(right: Boolean) { + val params : RelativeLayout.LayoutParams = + zoomWindowShape.layoutParams as RelativeLayout.LayoutParams + if(right) { + params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT) + params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT) + } else { + params.addRule(RelativeLayout.ALIGN_PARENT_LEFT) + params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT) + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Log.d("TAG", params.getRule(RelativeLayout.ALIGN_PARENT_RIGHT).toString()) + } + + Log.d("TAG", params.rules.contentToString()) + Log.d("TAG", params.rules.indexOf(-1).toString()) + zoomWindowShape.layoutParams = params + } +} \ No newline at end of file diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt new file mode 100644 index 0000000000..a6ce34e671 --- /dev/null +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt @@ -0,0 +1,11 @@ +package org.catrobat.paintroid.ui.zoomwindow + +import android.graphics.PointF + +interface ZoomWindowController { + fun show(coordinates: PointF) + + fun dismiss() + + fun dismissOnPinch() +} \ No newline at end of file diff --git a/Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml b/Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml new file mode 100644 index 0000000000..e2b2e6be10 --- /dev/null +++ b/Paintroid/src/main/res/drawable/pocketpaint_zoom_window_shape.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml b/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml index 405154b8f8..34e1c6312b 100644 --- a/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml +++ b/Paintroid/src/main/res/layout/activity_pocketpaint_main.xml @@ -52,6 +52,13 @@ android:layout_above="@id/pocketpaint_main_bottom_bar" android:layout_below="@+id/pocketpaint_layout_top_bar"/> + + + + + + + \ No newline at end of file From 5253635d9edd16a26cd8b22eeee28acccd4266b3 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Fri, 15 Jul 2022 12:16:08 +0530 Subject: [PATCH 03/10] Paintroid 433: Zoom window appears when clicked on the canvas --- Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt | 2 +- .../src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt index a4ac4d9d78..46c27b72e3 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt @@ -517,7 +517,7 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { toolReference, idlingResource, supportFragmentManager, - toolOptionsViewController + toolOptionsViewController, zoomWindowController, ) layerPresenter.setDrawingSurface(drawingSurface) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index 65d590edb7..a9df716474 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -127,7 +127,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { toolReference: ToolReference, idlingResource: CountingIdlingResource, fragmentManager: FragmentManager, - toolOptionsViewController: ToolOptionsViewController + toolOptionsViewController: ToolOptionsViewController, zoomController: ZoomWindowController ) { this.layerModel = layerModel From 37b048185d8ded2eda3bce217cf1ef1d2a305399 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Fri, 15 Jul 2022 12:23:50 +0530 Subject: [PATCH 04/10] Painroid 433: Missing import fixed --- .../src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index 257316fc33..a9df716474 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -54,6 +54,7 @@ import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.options.ToolOptionsViewController +import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { private val canvasRect = Rect() From e1f7d111e3ef32811b9e64e2436f90145e90a184 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Mon, 26 Sep 2022 16:03:48 +0530 Subject: [PATCH 05/10] Paintroid 433: Zoom window with content inside --- Paintroid/build.gradle | 1 + .../util/wrappers/ZoomWindowInteraction.java | 4 - .../org/catrobat/paintroid/MainActivity.kt | 7 +- .../listener/DrawingSurfaceListener.kt | 8 +- .../catrobat/paintroid/ui/DrawingSurface.kt | 34 +++- .../zoomwindow/DefaultZoomWindowController.kt | 181 ++++++++++++++++-- .../ui/zoomwindow/ZoomWindowController.kt | 6 + .../layout/pocketpaint_layout_zoom_window.xml | 14 +- Paintroid/src/main/res/values/dimens.xml | 4 + Paintroid/src/main/res/values/string.xml | 3 + 10 files changed, 227 insertions(+), 35 deletions(-) diff --git a/Paintroid/build.gradle b/Paintroid/build.gradle index 8d997b9160..98a77061ee 100644 --- a/Paintroid/build.gradle +++ b/Paintroid/build.gradle @@ -129,6 +129,7 @@ dependencies { implementation 'androidx.exifinterface:exifinterface:1.3.2' implementation 'com.esotericsoftware:kryo:5.1.1' implementation 'id.zelory:compressor:2.1.1' + androidTestImplementation project(path: ':Paintroid') debugImplementation 'androidx.multidex:multidex:2.0.0' diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java index 30f95cc2e5..40bff07036 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java @@ -37,10 +37,6 @@ protected boolean matchesSafely(View view) { int rulesFromLayout = layoutParams.getRule(verb); - Log.d("TAG", String.valueOf(rulesFromLayout)); - for(int i : layoutParams.getRules()) - Log.d("TAG", String.valueOf(i)); - return rulesFromLayout == -1; } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt index 46c27b72e3..7198fd3599 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt @@ -431,7 +431,6 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { val bottomBarLayout = findViewById(R.id.pocketpaint_main_bottom_bar) val bottomNavigationView = findViewById(R.id.pocketpaint_main_bottom_navigation) toolOptionsViewController = DefaultToolOptionsViewController(this, idlingResource) - zoomWindowController = DefaultZoomWindowController(this, layerModel) drawerLayoutViewHolder = DrawerLayoutViewHolder(drawerLayout) val topBarViewHolder = TopBarViewHolder(topBarLayout) val bottomBarViewHolder = BottomBarViewHolder(bottomBarLayout) @@ -448,6 +447,12 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { listener, CommandSerializationUtilities(this, commandManager) ) + zoomWindowController = DefaultZoomWindowController( + this, + layerModel, + workspace, + toolReference + ) model = MainActivityModel() defaultToolController = DefaultToolController( toolReference, diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index e25fea7801..7415a26524 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -24,13 +24,11 @@ import android.os.Handler import android.view.MotionEvent import android.view.View import android.view.View.OnTouchListener -import org.catrobat.paintroid.MainActivity import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.Tool.StateChange import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.DrawingSurface -import org.catrobat.paintroid.ui.zoomwindow.DefaultZoomWindowController import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController import java.util.EnumSet import kotlin.collections.ArrayList @@ -108,9 +106,9 @@ open class DrawingSurfaceListener( } fun setZoomController( - zoomWindowContoller: ZoomWindowController + zoomWindowController: ZoomWindowController ) { - zoomController = zoomWindowContoller + zoomController = zoomWindowController } private fun handleActionMove(currentTool: Tool?, view: View, event: MotionEvent) { @@ -141,6 +139,7 @@ open class DrawingSurfaceListener( } currentTool.handleMove(canvasTouchPoint) } + zoomController.onMove(canvasTouchPoint) } else { disableAutoScroll() if (touchMode == TouchMode.DRAW) { @@ -183,7 +182,6 @@ open class DrawingSurfaceListener( setEvenPointAndViewDimensionsForAutoScrollTask(view) autoScrollTask.start() } - ///////////////// zoomController.show(canvasTouchPoint) } MotionEvent.ACTION_MOVE -> handleActionMove(currentTool, view, event) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index a9df716474..fbb8e4c6ac 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -53,6 +53,7 @@ import org.catrobat.paintroid.listener.DrawingSurfaceListener.DrawingSurfaceList import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType +import org.catrobat.paintroid.tools.implementation.LineTool import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController @@ -137,7 +138,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { this.idlingResource = idlingResource this.fragmentManager = fragmentManager this.zoomController = zoomController - drawingSurfaceListener.setZoomController(zoomWindowContoller = zoomController) + drawingSurfaceListener.setZoomController(zoomWindowController = zoomController) } @Synchronized @@ -168,7 +169,22 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { } val tool = toolReference.tool - tool?.draw(surfaceViewCanvas) + + // Will create the zoom window only if the tool is a compatible tool + if(checkCurrentTool(tool)){ + val bitmapOfDrawingBoard = layerModel.currentLayer?.bitmap + surfaceViewCanvas.setBitmap(bitmapOfDrawingBoard) + + tool?.draw(surfaceViewCanvas) + + handler.post( + Runnable { + zoomController.getBitmap(bitmapOfDrawingBoard) + } + ) + } else { + tool?.draw(surfaceViewCanvas) + } } } } @@ -200,6 +216,20 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { drawingSurfaceListener.disableAutoScroll() } + private fun checkCurrentTool(tool: Tool?): Boolean { + if( + tool?.toolType?.name.equals(ToolType.HAND.name) || + tool?.toolType?.name.equals(ToolType.FILL.name) || + tool?.toolType?.name.equals(ToolType.STAMP.name) || + tool?.toolType?.name.equals(ToolType.TRANSFORM.name) || + tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) || + tool?.toolType?.name.equals(ToolType.SHAPE.name) || + tool?.toolType?.name.equals(ToolType.TEXT.name) + ) + return false + return true + } + @Synchronized fun setBitmap(bitmap: Bitmap?) { layerModel.currentLayer?.bitmap = bitmap diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt index 4d14f979b9..b0b940364f 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -1,33 +1,92 @@ package org.catrobat.paintroid.ui.zoomwindow -import android.app.Activity -import android.graphics.PointF -import android.os.Build -import android.util.Log +import android.graphics.* import android.view.View import android.view.ViewGroup +import android.widget.ImageView import android.widget.RelativeLayout +import org.catrobat.paintroid.MainActivity import org.catrobat.paintroid.R import org.catrobat.paintroid.contract.LayerContracts +import org.catrobat.paintroid.tools.Tool +import org.catrobat.paintroid.tools.ToolReference +import org.catrobat.paintroid.tools.ToolType +import org.catrobat.paintroid.tools.Workspace +import kotlin.math.roundToInt -class DefaultZoomWindowController(val activity: Activity, val layerModel: LayerContracts.Model) : ZoomWindowController { + +class DefaultZoomWindowController + (val activity: MainActivity, + val layerModel: LayerContracts.Model, + val workspace: Workspace, + val toolReference: ToolReference) : + ZoomWindowController { + + private val canvasRect = Rect() + private val checkeredPattern = Paint() + private val framePaint = Paint() + + // Getting the dimensions of the zoom window + private val windowHeight = + activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_height) + private val windowWidth = + activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_width) + + // CHEQUERED + private val backgroundBitmap = + Bitmap.createBitmap(layerModel.width, layerModel.height, Bitmap.Config.ARGB_8888) + + // GREY BACKGROUND + private val greyBackgroundBitmap = + Bitmap.createBitmap( + layerModel.width + windowWidth, + layerModel.height + windowHeight, + Bitmap.Config.ARGB_8888 + ) + + init { + framePaint.color = Color.BLACK + framePaint.style = Paint.Style.STROKE + framePaint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC) + val checkerboard = + BitmapFactory.decodeResource(activity.resources, R.drawable.pocketpaint_checkeredbg) + val shader = BitmapShader(checkerboard, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT) + checkeredPattern.shader = shader + checkeredPattern.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC) + + val backgroundCanvas: Canvas? = backgroundBitmap?.let { Canvas(it) } + + canvasRect.set(0, 0, layerModel.width, layerModel.height) + + backgroundCanvas?.drawRect(canvasRect, checkeredPattern) + backgroundCanvas?.drawRect(canvasRect, framePaint) + + val greyBackgroundCanvas = Canvas(greyBackgroundBitmap) + greyBackgroundCanvas.drawColor( + activity.resources.getColor(R.color.pocketpaint_main_drawing_surface_background) + ) + } private val zoomWindow: RelativeLayout = activity.findViewById(R.id.pocketpaint_zoom_window) private val zoomWindowShape: ViewGroup = activity.findViewById(R.id.pocketpaint_zoom_window_inner) + private val zoomWindowImage: ImageView = + activity.findViewById(R.id.pocketpaint_zoom_window_image) + private var coordinates: PointF? = null override fun show(coordinates: PointF) { - if(isPointOnCanvas(coordinates.x, coordinates.y)){ - if(shouldBeInTheRight(coordinates = coordinates)) { - Log.d("TAG", "YES") - setLayoutAlignment(right = true) - } - else { - setLayoutAlignment(right = false) + // Check if the tool is a compatible tool + if(checkCurrentTool(toolReference.tool)) { + if (isPointOnCanvas(coordinates.x, coordinates.y)) { + if (shouldBeInTheRight(coordinates = coordinates)) { + setLayoutAlignment(right = true) + } else { + setLayoutAlignment(right = false) + } + zoomWindow.visibility = View.VISIBLE + zoomWindowImage.setImageBitmap(cropBitmap(workspace.bitmapOfAllLayers, coordinates)) } - - zoomWindow.visibility = View.VISIBLE } } @@ -39,6 +98,26 @@ class DefaultZoomWindowController(val activity: Activity, val layerModel: LayerC zoomWindow.visibility = View.GONE } + override fun onMove(coordinates: PointF) { + if(shouldBeInTheRight(coordinates = coordinates)) { + setLayoutAlignment(right = true) + } + else { + setLayoutAlignment(right = false) + } + if(isPointOnCanvas(coordinates.x, coordinates.y)){ + if(zoomWindow.visibility == View.GONE) + zoomWindow.visibility = View.VISIBLE + this.coordinates = coordinates + } else { + dismiss() + } + } + + override fun getBitmap(bitmap: Bitmap?) { + zoomWindowImage.setImageBitmap(coordinates?.let { cropBitmap(bitmap, it) }) + } + private fun isPointOnCanvas(pointX: Float, pointY: Float): Boolean = pointX > 0 && pointX < layerModel.width && pointY > 0 && pointY < layerModel.height @@ -58,12 +137,74 @@ class DefaultZoomWindowController(val activity: Activity, val layerModel: LayerC params.addRule(RelativeLayout.ALIGN_PARENT_LEFT) params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT) } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - Log.d("TAG", params.getRule(RelativeLayout.ALIGN_PARENT_RIGHT).toString()) - } - - Log.d("TAG", params.rules.contentToString()) - Log.d("TAG", params.rules.indexOf(-1).toString()) zoomWindowShape.layoutParams = params } + + private fun cropBitmap(bitmap: Bitmap?, coordinates: PointF) : Bitmap? { + + val bitmapWithBackground: Bitmap? = mergeBackground(bitmap) + + // StartX and StartY coordinates + // StartX and StartY - windowWidth / 2, without the grey background + // But since we are adding the grey background, windowWidth / 2 should be added + // So they get cancelled + val startX: Int = (coordinates.x).roundToInt() + val startY: Int = (coordinates.y).roundToInt() + + val croppedBitmap: Bitmap? = + Bitmap.createBitmap(windowWidth, windowHeight, Bitmap.Config.ARGB_8888) + + val canvas: Canvas? = croppedBitmap?.let { Canvas(it) } + + val paint = Paint() + paint.isAntiAlias = true + + val rect = Rect(0, 0, windowWidth, windowHeight) + val rectF = RectF(rect) + + canvas?.drawOval(rectF, paint) + + paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) + + bitmapWithBackground?.let { + canvas?.drawBitmap(it, + Rect(startX, startY, startX+windowWidth, startY+windowHeight), + rect, + paint + ) } + + return croppedBitmap + } + + private fun mergeBackground(bitmap: Bitmap?): Bitmap? { + + // Adding the extra width and height for the grey background + val bmOverlay = + Bitmap.createBitmap( + layerModel.width + windowWidth, + layerModel.height + windowHeight, + Bitmap.Config.ARGB_8888 + ) + val canvas = Canvas(bmOverlay) + + canvas.drawBitmap(greyBackgroundBitmap, Matrix(), null) + canvas.drawBitmap(backgroundBitmap, windowWidth / 2f, windowHeight / 2f, null) + bitmap?.let { canvas.drawBitmap(it, windowWidth / 2f, windowHeight / 2f, null) } + + return bmOverlay + } + + private fun checkCurrentTool(tool: Tool?): Boolean { + if( + tool?.toolType?.name.equals(ToolType.HAND.name) || + tool?.toolType?.name.equals(ToolType.FILL.name) || + tool?.toolType?.name.equals(ToolType.STAMP.name) || + tool?.toolType?.name.equals(ToolType.TRANSFORM.name) || + tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) || + tool?.toolType?.name.equals(ToolType.SHAPE.name) || + tool?.toolType?.name.equals(ToolType.TEXT.name) + ) + return false + return true + } } \ No newline at end of file diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt index a6ce34e671..85bf226416 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt @@ -1,5 +1,7 @@ package org.catrobat.paintroid.ui.zoomwindow +import android.graphics.Bitmap +import android.graphics.Canvas import android.graphics.PointF interface ZoomWindowController { @@ -8,4 +10,8 @@ interface ZoomWindowController { fun dismiss() fun dismissOnPinch() + + fun onMove(coordinates: PointF) + + fun getBitmap(bitmap: Bitmap?) } \ No newline at end of file diff --git a/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml b/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml index 52bb0e224e..64c52f04b1 100644 --- a/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml +++ b/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml @@ -8,11 +8,19 @@ + android:orientation="horizontal" > + + + + \ No newline at end of file diff --git a/Paintroid/src/main/res/values/dimens.xml b/Paintroid/src/main/res/values/dimens.xml index 5429d16521..b46bf456ab 100644 --- a/Paintroid/src/main/res/values/dimens.xml +++ b/Paintroid/src/main/res/values/dimens.xml @@ -29,4 +29,8 @@ 100dp 50dp 25dp + + + 80dp + 80dp diff --git a/Paintroid/src/main/res/values/string.xml b/Paintroid/src/main/res/values/string.xml index 00894169a6..641d14a5f5 100644 --- a/Paintroid/src/main/res/values/string.xml +++ b/Paintroid/src/main/res/values/string.xml @@ -249,4 +249,7 @@ Image is too big to load The image is too big to load. Tap OK to scale down the image automatically. + Press + Release + From 6e7040f48ecc1862ef0f20fdc325fc048ef11f11 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Wed, 28 Sep 2022 13:06:56 +0530 Subject: [PATCH 06/10] Paintroid 433: Zoom window performance update --- .../catrobat/paintroid/ui/DrawingSurface.kt | 64 +++++++++++++++---- .../zoomwindow/DefaultZoomWindowController.kt | 30 +++++++-- 2 files changed, 76 insertions(+), 18 deletions(-) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index fbb8e4c6ac..9164bb37f4 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -171,19 +171,50 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { val tool = toolReference.tool // Will create the zoom window only if the tool is a compatible tool - if(checkCurrentTool(tool)){ - val bitmapOfDrawingBoard = layerModel.currentLayer?.bitmap - surfaceViewCanvas.setBitmap(bitmapOfDrawingBoard) + when(checkCurrentTool(tool)) { + 0 -> { + // NON-COMPATIBLE TOOLS + tool?.draw(surfaceViewCanvas) + } + 1 -> { + // LINE TOOL + // Does not return the contents of the current layer + // But only the new lines drawn - tool?.draw(surfaceViewCanvas) + val bitmapOfDrawingBoard = Bitmap.createBitmap( + layerModel.width, layerModel.height, Bitmap.Config.ARGB_8888) - handler.post( - Runnable { - zoomController.getBitmap(bitmapOfDrawingBoard) - } - ) - } else { - tool?.draw(surfaceViewCanvas) + tool?.draw(surfaceViewCanvas) + + val canvas = Canvas(bitmapOfDrawingBoard) + tool?.draw(canvas) + + handler.post( + Runnable { + zoomController.getBitmap(bitmapOfDrawingBoard) + } + ) + } + 2 -> { + // CURSOR TOOL + // Does not return the contents of the current layer + // But only the new lines drawn + + tool?.draw(surfaceViewCanvas) + } + 3 -> { + // OTHER COMPATIBLE TOOLS + val bitmapOfDrawingBoard = layerModel.currentLayer?.bitmap + surfaceViewCanvas.setBitmap(bitmapOfDrawingBoard) + + tool?.draw(surfaceViewCanvas) + + handler.post( + Runnable { + zoomController.getBitmap(bitmapOfDrawingBoard) + } + ) + } } } } @@ -216,7 +247,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { drawingSurfaceListener.disableAutoScroll() } - private fun checkCurrentTool(tool: Tool?): Boolean { + private fun checkCurrentTool(tool: Tool?): Int { if( tool?.toolType?.name.equals(ToolType.HAND.name) || tool?.toolType?.name.equals(ToolType.FILL.name) || @@ -226,8 +257,13 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { tool?.toolType?.name.equals(ToolType.SHAPE.name) || tool?.toolType?.name.equals(ToolType.TEXT.name) ) - return false - return true + return 0 + else if(tool?.toolType?.name.equals(ToolType.LINE.name)) + return 1 + else if (tool?.toolType?.name.equals(ToolType.CURSOR.name)) + return 2 + else + return 3 } @Synchronized diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt index b0b940364f..1753eaa67b 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -33,7 +33,7 @@ class DefaultZoomWindowController activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_width) // CHEQUERED - private val backgroundBitmap = + private val chequeredBackgroundBitmap = Bitmap.createBitmap(layerModel.width, layerModel.height, Bitmap.Config.ARGB_8888) // GREY BACKGROUND @@ -44,6 +44,13 @@ class DefaultZoomWindowController Bitmap.Config.ARGB_8888 ) + private val backgroundBitmap = + Bitmap.createBitmap( + layerModel.width + windowWidth, + layerModel.height + windowHeight, + Bitmap.Config.ARGB_8888 + ) + init { framePaint.color = Color.BLACK framePaint.style = Paint.Style.STROKE @@ -54,7 +61,7 @@ class DefaultZoomWindowController checkeredPattern.shader = shader checkeredPattern.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC) - val backgroundCanvas: Canvas? = backgroundBitmap?.let { Canvas(it) } + val backgroundCanvas: Canvas? = chequeredBackgroundBitmap?.let { Canvas(it) } canvasRect.set(0, 0, layerModel.width, layerModel.height) @@ -65,6 +72,13 @@ class DefaultZoomWindowController greyBackgroundCanvas.drawColor( activity.resources.getColor(R.color.pocketpaint_main_drawing_surface_background) ) + + + val canvasBackground = Canvas(backgroundBitmap) + + canvasBackground.drawBitmap(greyBackgroundBitmap, Matrix(), null) + canvasBackground.drawBitmap( + chequeredBackgroundBitmap, windowWidth / 2f, windowHeight / 2f, null) } private val zoomWindow: RelativeLayout = @@ -187,8 +201,16 @@ class DefaultZoomWindowController ) val canvas = Canvas(bmOverlay) - canvas.drawBitmap(greyBackgroundBitmap, Matrix(), null) - canvas.drawBitmap(backgroundBitmap, windowWidth / 2f, windowHeight / 2f, null) + canvas.drawBitmap(backgroundBitmap, Matrix(), null) + + // Add the current layer if the tool is line or cursor tool + if(toolReference.tool?.toolType?.name.equals(ToolType.LINE.name) || + toolReference.tool?.toolType?.name.equals(ToolType.CURSOR.name)) { + layerModel.currentLayer?.bitmap?.let { + canvas.drawBitmap(it, windowWidth / 2f, windowHeight / 2f, null) + } + } + bitmap?.let { canvas.drawBitmap(it, windowWidth / 2f, windowHeight / 2f, null) } return bmOverlay From a53f39317e5a3db94cbe9771a10c21bd2ce1701f Mon Sep 17 00:00:00 2001 From: Saatwik Date: Sat, 1 Oct 2022 19:17:14 +0530 Subject: [PATCH 07/10] Paintroid 433: Cursor tool integration --- .../listener/DrawingSurfaceListener.kt | 14 ++++++++++++-- .../java/org/catrobat/paintroid/tools/Tool.kt | 2 ++ .../tools/implementation/BrushTool.kt | 5 +++++ .../tools/implementation/CursorTool.kt | 10 ++++++++++ .../paintroid/tools/implementation/FillTool.kt | 5 +++++ .../paintroid/tools/implementation/HandTool.kt | 5 +++++ .../tools/implementation/ImportTool.kt | 6 ++++++ .../paintroid/tools/implementation/LineTool.kt | 5 +++++ .../tools/implementation/PipetteTool.kt | 5 +++++ .../tools/implementation/ShapeTool.kt | 6 ++++++ .../tools/implementation/SmudgeTool.kt | 5 +++++ .../tools/implementation/SprayTool.kt | 5 +++++ .../tools/implementation/StampTool.kt | 6 ++++++ .../paintroid/tools/implementation/TextTool.kt | 5 +++++ .../tools/implementation/TransformTool.kt | 5 +++++ .../catrobat/paintroid/ui/DrawingSurface.kt | 18 ++++++------------ 16 files changed, 93 insertions(+), 14 deletions(-) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index 7415a26524..a39a26452e 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -139,7 +139,11 @@ open class DrawingSurfaceListener( } currentTool.handleMove(canvasTouchPoint) } - zoomController.onMove(canvasTouchPoint) + if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) { + zoomController.onMove(canvasTouchPoint) + } else { + zoomController.onMove(currentTool.toolPositionCoordinates(canvasTouchPoint)) + } } else { disableAutoScroll() if (touchMode == TouchMode.DRAW) { @@ -182,7 +186,12 @@ open class DrawingSurfaceListener( setEvenPointAndViewDimensionsForAutoScrollTask(view) autoScrollTask.start() } - zoomController.show(canvasTouchPoint) + if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) { + zoomController.show(canvasTouchPoint) + } else { + currentTool?.toolPositionCoordinates(canvasTouchPoint) + ?.let { zoomController.show(it) } + } } MotionEvent.ACTION_MOVE -> handleActionMove(currentTool, view, event) MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { @@ -219,6 +228,7 @@ open class DrawingSurfaceListener( eventY = 0f touchMode = TouchMode.DRAW zoomController.dismiss() + callback.getCurrentTool()?.handToolMode() } } drawingSurface.refreshDrawingSurface() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/Tool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/Tool.kt index 0ed20d5616..85f1f22aab 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/Tool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/Tool.kt @@ -64,4 +64,6 @@ interface Tool { enum class StateChange { ALL, RESET_INTERNAL_STATE, NEW_IMAGE_LOADED, MOVE_CANCELED } + + fun toolPositionCoordinates(coordinate: PointF): PointF } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt index ca60ebc05a..5b30886a0b 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt @@ -148,6 +148,11 @@ open class BrushTool( } } + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + override fun resetInternalState() { pathToDraw.rewind() pointArray.clear() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt index a2e2dcc683..4a888fe5fc 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/CursorTool.kt @@ -381,4 +381,14 @@ open class CursorTool( pointArray.clear() } + + override fun toolPositionCoordinates(coordinate: PointF): PointF { + var finalCoordinates: PointF = PointF(0f, 0f) + previousEventCoordinate?.let { + val deltaX = coordinate.x - it.x + val deltaY = coordinate.y - it.y + finalCoordinates = calculateNewClampedToolPosition(deltaX, deltaY) + } + return finalCoordinates + } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt index 8cbc72b1e3..feac24c756 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt @@ -87,6 +87,11 @@ class FillTool( return true } + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + public override fun resetInternalState() = Unit override val toolType: ToolType = ToolType.FILL diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt index 52a7dea5b7..e9fac0e313 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt @@ -57,5 +57,10 @@ class HandTool( override fun handleUp(coordinate: PointF?): Boolean = true + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + override fun handToolMode(): Boolean = true } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt index 6c933fba27..5956874bce 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt @@ -20,6 +20,7 @@ package org.catrobat.paintroid.tools.implementation import android.graphics.Bitmap import android.graphics.Canvas +import android.graphics.PointF import android.os.Bundle import androidx.test.espresso.idling.CountingIdlingResource import org.catrobat.paintroid.command.CommandManager @@ -48,6 +49,11 @@ class ImportTool( override val toolType: ToolType get() = ToolType.IMPORTPNG + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + init { rotationEnabled = true } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt index 1fe89d18cb..ef6fdccea3 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt @@ -341,6 +341,11 @@ class LineTool( return true } + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + override fun resetInternalState() { initialEventCoordinate = null currentCoordinate = null diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt index 203ef386ca..c5d7064813 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt @@ -58,6 +58,11 @@ class PipetteTool( override fun handleUp(coordinate: PointF?): Boolean = setColor(coordinate) + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + override fun resetInternalState() { updateSurfaceBitmap() } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt index 30a9717866..dd147e7986 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt @@ -20,6 +20,7 @@ package org.catrobat.paintroid.tools.implementation import android.graphics.Canvas import android.graphics.Paint +import android.graphics.PointF import android.graphics.RectF import android.os.Bundle import androidx.test.espresso.idling.CountingIdlingResource @@ -67,6 +68,11 @@ class ShapeTool( override val toolType: ToolType get() = ToolType.SHAPE + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + init { rotationEnabled = true this.shapeToolOptionsView = shapeToolOptionsView diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt index 2644646a43..dddce1f301 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt @@ -232,6 +232,11 @@ class SmudgeTool( } } + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + override fun draw(canvas: Canvas) { if (pointArray.isNotEmpty()) { val pointPath = pointArray.toMutableList() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt index e0c6c7a535..a29a3605ff 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt @@ -103,6 +103,11 @@ class SprayTool( return true } + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + override fun handleMove(coordinate: PointF?): Boolean { currentCoordinate = coordinate return true diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt index 258fda431c..fa767daced 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt @@ -21,6 +21,7 @@ package org.catrobat.paintroid.tools.implementation import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color +import android.graphics.PointF import android.os.Bundle import androidx.test.espresso.idling.CountingIdlingResource import org.catrobat.paintroid.R @@ -60,6 +61,11 @@ class StampTool( override val toolType: ToolType get() = ToolType.STAMP + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + init { rotationEnabled = true this.stampToolOptionsView = stampToolOptionsView diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt index 5416205fe6..ae0b77b3f8 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt @@ -116,6 +116,11 @@ class TextTool( override val toolType: ToolType get() = ToolType.TEXT + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + init { rotationEnabled = ROTATION_ENABLED resizePointsVisible = RESIZE_POINTS_VISIBLE diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt index 6f618f1229..a34acae5af 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt @@ -112,6 +112,11 @@ class TransformTool( override val toolType: ToolType get() = ToolType.TRANSFORM + override fun toolPositionCoordinates(coordinate: PointF): PointF { + // The tool coordinate is same as the touch coordinate + return coordinate + } + init { rotationEnabled = ROTATION_ENABLED resizePointsVisible = RESIZE_POINTS_VISIBLE diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index 9164bb37f4..9ccfd40696 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -177,7 +177,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { tool?.draw(surfaceViewCanvas) } 1 -> { - // LINE TOOL + // LINE TOOL OR CURSOR TOOL // Does not return the contents of the current layer // But only the new lines drawn @@ -196,13 +196,6 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { ) } 2 -> { - // CURSOR TOOL - // Does not return the contents of the current layer - // But only the new lines drawn - - tool?.draw(surfaceViewCanvas) - } - 3 -> { // OTHER COMPATIBLE TOOLS val bitmapOfDrawingBoard = layerModel.currentLayer?.bitmap surfaceViewCanvas.setBitmap(bitmapOfDrawingBoard) @@ -258,12 +251,13 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { tool?.toolType?.name.equals(ToolType.TEXT.name) ) return 0 - else if(tool?.toolType?.name.equals(ToolType.LINE.name)) + else if( + tool?.toolType?.name.equals(ToolType.LINE.name) || + tool?.toolType?.name.equals(ToolType.CURSOR.name) + ) return 1 - else if (tool?.toolType?.name.equals(ToolType.CURSOR.name)) - return 2 else - return 3 + return 2 } @Synchronized From 23206d66c0696478a12f56159aea9d142b6dbb28 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Tue, 4 Oct 2022 20:33:23 +0530 Subject: [PATCH 08/10] Paintroid 434: Zoom window settings dialog --- .../org/catrobat/paintroid/MainActivity.kt | 8 +- .../org/catrobat/paintroid/UserPreferences.kt | 19 +++++ .../catrobat/paintroid/common/Constants.kt | 3 + .../contract/MainActivityContracts.kt | 6 ++ .../dialog/ZoomWindowSettingsDialog.kt | 82 +++++++++++++++++++ .../listener/DrawingSurfaceListener.kt | 36 +++++--- .../presenter/MainActivityPresenter.kt | 4 + .../catrobat/paintroid/ui/DrawingSurface.kt | 9 +- .../paintroid/ui/MainActivityNavigator.kt | 57 +++---------- .../zoomwindow/DefaultZoomWindowController.kt | 51 ++++++------ ...dialog_pocketpaint_zoomwindow_settings.xml | 49 +++++++++++ .../menu/menu_pocketpaint_more_options.xml | 3 + Paintroid/src/main/res/values/string.xml | 6 ++ 13 files changed, 251 insertions(+), 82 deletions(-) create mode 100644 Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt create mode 100644 Paintroid/src/main/res/layout/dialog_pocketpaint_zoomwindow_settings.xml diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt index 104ba7ad4a..0f70d93bae 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/MainActivity.kt @@ -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 @@ -451,7 +455,8 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { this, layerModel, workspace, - toolReference + toolReference, + UserPreferences(getPreferences(MODE_PRIVATE)) ) model = MainActivityModel() defaultToolController = DefaultToolController( @@ -528,6 +533,7 @@ class MainActivity : AppCompatActivity(), MainView, CommandListener { supportFragmentManager, toolOptionsViewController, zoomWindowController, + UserPreferences(getPreferences(MODE_PRIVATE)) ) layerPresenter.setDrawingSurface(drawingSurface) appFragment.perspective = perspective diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt b/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt index 82e316b109..7e8553f7e4 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt @@ -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 @@ -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 diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/common/Constants.kt b/Paintroid/src/main/java/org/catrobat/paintroid/common/Constants.kt index 208c0bfb21..cb84a56746 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/common/Constants.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/common/Constants.kt @@ -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" @@ -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" diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt b/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt index 0cc5eb66d7..a34d2fc8a5 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt @@ -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 @@ -58,6 +60,8 @@ interface MainActivityContracts { fun showFeedbackDialog() + fun showZoomWindowSettingsDialog(sharedPreferences: UserPreferences) + fun showAdvancedSettingsDialog() fun showOverwriteDialog(permissionCode: Int, isExport: Boolean) @@ -215,6 +219,8 @@ interface MainActivityContracts { fun showAboutClicked() + fun showZoomWindowSettingsClicked(sharedPreferences: UserPreferences) + fun showAdvancedSettingsClicked() fun showRateUsDialog() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt b/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt new file mode 100644 index 0000000000..c6e02369b4 --- /dev/null +++ b/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt @@ -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(R.id.pocketpaint_zoom_window_enabled) + val slider = view.findViewById(R.id.pocketpaint_zoom_window_slider) + val sliderTextView = view.findViewById(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) + } +} \ No newline at end of file diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index a39a26452e..5e374149a5 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -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 @@ -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 @@ -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 = mutableListOf() @@ -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) { @@ -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() @@ -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) @@ -227,7 +241,7 @@ open class DrawingSurfaceListener( eventX = 0f eventY = 0f touchMode = TouchMode.DRAW - zoomController.dismiss() + if(callZoomWindow) zoomController.dismiss() callback.getCurrentTool()?.handToolMode() } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/presenter/MainActivityPresenter.kt b/Paintroid/src/main/java/org/catrobat/paintroid/presenter/MainActivityPresenter.kt index 474e3927d4..1041952418 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/presenter/MainActivityPresenter.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/presenter/MainActivityPresenter.kt @@ -279,6 +279,10 @@ open class MainActivityPresenter( navigator.showAboutDialog() } + override fun showZoomWindowSettingsClicked(sharedPreferences: UserPreferences) { + navigator.showZoomWindowSettingsDialog(sharedPreferences) + } + override fun showAdvancedSettingsClicked() { navigator.showAdvancedSettingsDialog() } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index 9ccfd40696..0630adeaad 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt index 47d291ae09..c722aa0e60 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt @@ -22,6 +22,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent +import android.content.SharedPreferences import android.content.pm.PackageManager import android.content.res.Configuration import android.graphics.Bitmap @@ -34,58 +35,16 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment -import org.catrobat.paintroid.FileIO -import org.catrobat.paintroid.MainActivity -import org.catrobat.paintroid.R -import org.catrobat.paintroid.WelcomeActivity +import org.catrobat.paintroid.* import org.catrobat.paintroid.colorpicker.ColorPickerDialog import org.catrobat.paintroid.colorpicker.OnColorPickedListener import org.catrobat.paintroid.command.CommandFactory import org.catrobat.paintroid.command.implementation.DefaultCommandFactory -import org.catrobat.paintroid.common.ABOUT_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.ADVANCED_SETTINGS_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.CATROBAT_INFORMATION_DIALOG_TAG -import org.catrobat.paintroid.common.CATROID_MEDIA_GALLERY_FRAGMENT_TAG -import org.catrobat.paintroid.common.COLOR_PICKER_DIALOG_TAG -import org.catrobat.paintroid.common.FEEDBACK_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.INDETERMINATE_PROGRESS_DIALOG_TAG -import org.catrobat.paintroid.common.JPG_INFORMATION_DIALOG_TAG -import org.catrobat.paintroid.common.LIKE_US_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.LOAD_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.* import org.catrobat.paintroid.common.MainActivityConstants.ActivityRequestCode -import org.catrobat.paintroid.common.ORA_INFORMATION_DIALOG_TAG -import org.catrobat.paintroid.common.OVERWRITE_INFORMATION_DIALOG_TAG -import org.catrobat.paintroid.common.PAINTROID_PICTURE_PATH -import org.catrobat.paintroid.common.PERMISSION_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.PERMISSION_EXTERNAL_STORAGE_SAVE_COPY -import org.catrobat.paintroid.common.PNG_INFORMATION_DIALOG_TAG -import org.catrobat.paintroid.common.RATE_US_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.SAVE_DIALOG_FRAGMENT_TAG -import org.catrobat.paintroid.common.SAVE_INFORMATION_DIALOG_TAG -import org.catrobat.paintroid.common.SAVE_QUESTION_FRAGMENT_TAG -import org.catrobat.paintroid.common.SCALE_IMAGE_FRAGMENT_TAG import org.catrobat.paintroid.contract.MainActivityContracts -import org.catrobat.paintroid.dialog.AboutDialog -import org.catrobat.paintroid.dialog.AdvancedSettingsDialog -import org.catrobat.paintroid.dialog.CatrobatImageInfoDialog -import org.catrobat.paintroid.dialog.FeedbackDialog -import org.catrobat.paintroid.dialog.ImportImageDialog -import org.catrobat.paintroid.dialog.IndeterminateProgressDialog -import org.catrobat.paintroid.dialog.InfoDialog -import org.catrobat.paintroid.dialog.JpgInfoDialog -import org.catrobat.paintroid.dialog.LikeUsDialog -import org.catrobat.paintroid.dialog.OraInfoDialog -import org.catrobat.paintroid.dialog.OverwriteDialog -import org.catrobat.paintroid.dialog.PermanentDenialPermissionInfoDialog -import org.catrobat.paintroid.dialog.PermissionInfoDialog +import org.catrobat.paintroid.dialog.* import org.catrobat.paintroid.dialog.PermissionInfoDialog.PermissionType -import org.catrobat.paintroid.dialog.PngInfoDialog -import org.catrobat.paintroid.dialog.RateUsDialog -import org.catrobat.paintroid.dialog.SaveBeforeFinishDialog -import org.catrobat.paintroid.dialog.SaveBeforeLoadImageDialog -import org.catrobat.paintroid.dialog.SaveBeforeNewImageDialog -import org.catrobat.paintroid.dialog.SaveInformationDialog -import org.catrobat.paintroid.dialog.ScaleImageOnLoadDialog import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.ui.fragments.CatroidMediaGalleryFragment @@ -299,6 +258,14 @@ class MainActivityNavigator( ) } + override fun showZoomWindowSettingsDialog(sharedPreferences: UserPreferences) { + val zoomWindowSettingsDialog = ZoomWindowSettingsDialog(sharedPreferences) + zoomWindowSettingsDialog.show( + mainActivity.supportFragmentManager, + ZOOM_WINDOW_SETTINGS_DIALOG_FRAGMENT_TAG + ) + } + override fun showAdvancedSettingsDialog() { val advancedSettingsDialog = AdvancedSettingsDialog() advancedSettingsDialog.show( diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt index 1753eaa67b..14f515188b 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -1,12 +1,15 @@ package org.catrobat.paintroid.ui.zoomwindow +import android.content.SharedPreferences import android.graphics.* +import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.RelativeLayout import org.catrobat.paintroid.MainActivity import org.catrobat.paintroid.R +import org.catrobat.paintroid.UserPreferences import org.catrobat.paintroid.contract.LayerContracts import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.ToolReference @@ -19,18 +22,19 @@ class DefaultZoomWindowController (val activity: MainActivity, val layerModel: LayerContracts.Model, val workspace: Workspace, - val toolReference: ToolReference) : + val toolReference: ToolReference, + val sharedPreferences: UserPreferences) : ZoomWindowController { private val canvasRect = Rect() private val checkeredPattern = Paint() private val framePaint = Paint() + private val zoomFactor: Int = 25 + // Getting the dimensions of the zoom window - private val windowHeight = + private val windowSideDimen = activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_height) - private val windowWidth = - activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_width) // CHEQUERED private val chequeredBackgroundBitmap = @@ -39,15 +43,15 @@ class DefaultZoomWindowController // GREY BACKGROUND private val greyBackgroundBitmap = Bitmap.createBitmap( - layerModel.width + windowWidth, - layerModel.height + windowHeight, + layerModel.width + windowSideDimen, + layerModel.height + windowSideDimen, Bitmap.Config.ARGB_8888 ) private val backgroundBitmap = Bitmap.createBitmap( - layerModel.width + windowWidth, - layerModel.height + windowHeight, + layerModel.width + windowSideDimen, + layerModel.height + windowSideDimen, Bitmap.Config.ARGB_8888 ) @@ -78,7 +82,7 @@ class DefaultZoomWindowController canvasBackground.drawBitmap(greyBackgroundBitmap, Matrix(), null) canvasBackground.drawBitmap( - chequeredBackgroundBitmap, windowWidth / 2f, windowHeight / 2f, null) + chequeredBackgroundBitmap, windowSideDimen / 2f, windowSideDimen / 2f, null) } private val zoomWindow: RelativeLayout = @@ -91,7 +95,7 @@ class DefaultZoomWindowController override fun show(coordinates: PointF) { // Check if the tool is a compatible tool - if(checkCurrentTool(toolReference.tool)) { + if(checkCurrentTool(toolReference.tool) && sharedPreferences.preferenceZoomWindowEnabled) { if (isPointOnCanvas(coordinates.x, coordinates.y)) { if (shouldBeInTheRight(coordinates = coordinates)) { setLayoutAlignment(right = true) @@ -158,22 +162,18 @@ class DefaultZoomWindowController val bitmapWithBackground: Bitmap? = mergeBackground(bitmap) - // StartX and StartY coordinates - // StartX and StartY - windowWidth / 2, without the grey background - // But since we are adding the grey background, windowWidth / 2 should be added - // So they get cancelled - val startX: Int = (coordinates.x).roundToInt() - val startY: Int = (coordinates.y).roundToInt() + val startX: Int = (coordinates.x).roundToInt() + windowSideDimen / 2 - getSizeOfZoomWindow() / 2 + val startY: Int = (coordinates.y).roundToInt() + windowSideDimen / 2 - getSizeOfZoomWindow() / 2 val croppedBitmap: Bitmap? = - Bitmap.createBitmap(windowWidth, windowHeight, Bitmap.Config.ARGB_8888) + Bitmap.createBitmap(getSizeOfZoomWindow(), getSizeOfZoomWindow(), Bitmap.Config.ARGB_8888) val canvas: Canvas? = croppedBitmap?.let { Canvas(it) } val paint = Paint() paint.isAntiAlias = true - val rect = Rect(0, 0, windowWidth, windowHeight) + val rect = Rect(0, 0, getSizeOfZoomWindow(), getSizeOfZoomWindow()) val rectF = RectF(rect) canvas?.drawOval(rectF, paint) @@ -182,7 +182,7 @@ class DefaultZoomWindowController bitmapWithBackground?.let { canvas?.drawBitmap(it, - Rect(startX, startY, startX+windowWidth, startY+windowHeight), + Rect(startX, startY, startX+getSizeOfZoomWindow(), startY+getSizeOfZoomWindow()), rect, paint ) } @@ -195,8 +195,8 @@ class DefaultZoomWindowController // Adding the extra width and height for the grey background val bmOverlay = Bitmap.createBitmap( - layerModel.width + windowWidth, - layerModel.height + windowHeight, + layerModel.width + windowSideDimen, + layerModel.height + windowSideDimen, Bitmap.Config.ARGB_8888 ) val canvas = Canvas(bmOverlay) @@ -207,15 +207,20 @@ class DefaultZoomWindowController if(toolReference.tool?.toolType?.name.equals(ToolType.LINE.name) || toolReference.tool?.toolType?.name.equals(ToolType.CURSOR.name)) { layerModel.currentLayer?.bitmap?.let { - canvas.drawBitmap(it, windowWidth / 2f, windowHeight / 2f, null) + canvas.drawBitmap(it, windowSideDimen / 2f, windowSideDimen / 2f, null) } } - bitmap?.let { canvas.drawBitmap(it, windowWidth / 2f, windowHeight / 2f, null) } + bitmap?.let { canvas.drawBitmap(it, windowSideDimen / 2f, windowSideDimen / 2f, null) } return bmOverlay } + private fun getSizeOfZoomWindow(): Int { + val zoomIndex = (sharedPreferences.preferenceZoomWindowZoomPercentage - 100) / 50 + return windowSideDimen - (zoomIndex * zoomFactor) + } + private fun checkCurrentTool(tool: Tool?): Boolean { if( tool?.toolType?.name.equals(ToolType.HAND.name) || diff --git a/Paintroid/src/main/res/layout/dialog_pocketpaint_zoomwindow_settings.xml b/Paintroid/src/main/res/layout/dialog_pocketpaint_zoomwindow_settings.xml new file mode 100644 index 0000000000..d270cb8340 --- /dev/null +++ b/Paintroid/src/main/res/layout/dialog_pocketpaint_zoomwindow_settings.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + diff --git a/Paintroid/src/main/res/menu/menu_pocketpaint_more_options.xml b/Paintroid/src/main/res/menu/menu_pocketpaint_more_options.xml index f7aeafe64b..67934c43cc 100644 --- a/Paintroid/src/main/res/menu/menu_pocketpaint_more_options.xml +++ b/Paintroid/src/main/res/menu/menu_pocketpaint_more_options.xml @@ -46,6 +46,9 @@ + diff --git a/Paintroid/src/main/res/values/string.xml b/Paintroid/src/main/res/values/string.xml index b585803d72..47120771f5 100644 --- a/Paintroid/src/main/res/values/string.xml +++ b/Paintroid/src/main/res/values/string.xml @@ -97,6 +97,7 @@ Export Feedback Advanced settings + Zoom Window Settings Image saved to\n Image saved Copy saved to\n @@ -164,6 +165,11 @@ Antialiasing Smoothing + Enabled + 100 + 300 + 100 + Quality: jpg From 33e4754fc844c09e5c7dc02b6c0c5a9ddf490704 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Wed, 12 Oct 2022 21:20:52 +0530 Subject: [PATCH 09/10] Paintroid 434: Shape and Text tool compatibility --- .../listener/DrawingSurfaceListener.kt | 16 ++++---- .../tools/implementation/ImportTool.kt | 2 +- .../tools/implementation/ShapeTool.kt | 2 +- .../tools/implementation/StampTool.kt | 2 +- .../tools/implementation/TextTool.kt | 2 +- .../catrobat/paintroid/ui/DrawingSurface.kt | 24 +----------- .../zoomwindow/DefaultZoomWindowController.kt | 39 +++++++++++-------- .../ui/zoomwindow/ZoomWindowController.kt | 3 ++ 8 files changed, 39 insertions(+), 51 deletions(-) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index 5e374149a5..3b9ad30a74 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -18,7 +18,6 @@ */ package org.catrobat.paintroid.listener -import android.content.SharedPreferences import android.graphics.Point import android.graphics.PointF import android.os.Handler @@ -147,10 +146,10 @@ open class DrawingSurfaceListener( currentTool.handleMove(canvasTouchPoint) } if(callZoomWindow) { - if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) { - zoomController.onMove(canvasTouchPoint) - } else { + if (zoomController.checkCurrentTool(callback.getCurrentTool()) == 1) { zoomController.onMove(currentTool.toolPositionCoordinates(canvasTouchPoint)) + } else { + zoomController.onMove(canvasTouchPoint) } } } else { @@ -196,11 +195,12 @@ open class DrawingSurfaceListener( autoScrollTask.start() } if(sharedPreferences.preferenceZoomWindowEnabled) { - if (!callback.getCurrentTool()?.toolType?.name.equals(ToolType.CURSOR.name)) { - zoomController.show(canvasTouchPoint) + if (zoomController.checkCurrentTool(callback.getCurrentTool()) == 1) { + currentTool?.let { + zoomController.onMove(it.toolPositionCoordinates(canvasTouchPoint)) + } } else { - currentTool?.toolPositionCoordinates(canvasTouchPoint) - ?.let { zoomController.show(it) } + zoomController.onMove(canvasTouchPoint) } callZoomWindow = true } else { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt index 5956874bce..ce364847cd 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt @@ -51,7 +51,7 @@ class ImportTool( override fun toolPositionCoordinates(coordinate: PointF): PointF { // The tool coordinate is same as the touch coordinate - return coordinate + return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) } init { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt index dd147e7986..49d4844d25 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt @@ -70,7 +70,7 @@ class ShapeTool( override fun toolPositionCoordinates(coordinate: PointF): PointF { // The tool coordinate is same as the touch coordinate - return coordinate + return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) } init { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt index fa767daced..2d2947f52c 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt @@ -63,7 +63,7 @@ class StampTool( override fun toolPositionCoordinates(coordinate: PointF): PointF { // The tool coordinate is same as the touch coordinate - return coordinate + return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) } init { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt index ae0b77b3f8..22d2920cc2 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt @@ -118,7 +118,7 @@ class TextTool( override fun toolPositionCoordinates(coordinate: PointF): PointF { // The tool coordinate is same as the touch coordinate - return coordinate + return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) } init { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index 0630adeaad..a5482ea8a4 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -19,7 +19,6 @@ 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 @@ -55,7 +54,6 @@ import org.catrobat.paintroid.listener.DrawingSurfaceListener.DrawingSurfaceList import org.catrobat.paintroid.tools.Tool import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType -import org.catrobat.paintroid.tools.implementation.LineTool import org.catrobat.paintroid.tools.options.ToolOptionsViewController import org.catrobat.paintroid.ui.zoomwindow.ZoomWindowController @@ -176,7 +174,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { val tool = toolReference.tool // Will create the zoom window only if the tool is a compatible tool - when(checkCurrentTool(tool)) { + when(zoomController.checkCurrentTool(tool)) { 0 -> { // NON-COMPATIBLE TOOLS tool?.draw(surfaceViewCanvas) @@ -245,26 +243,6 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { drawingSurfaceListener.disableAutoScroll() } - private fun checkCurrentTool(tool: Tool?): Int { - if( - tool?.toolType?.name.equals(ToolType.HAND.name) || - tool?.toolType?.name.equals(ToolType.FILL.name) || - tool?.toolType?.name.equals(ToolType.STAMP.name) || - tool?.toolType?.name.equals(ToolType.TRANSFORM.name) || - tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) || - tool?.toolType?.name.equals(ToolType.SHAPE.name) || - tool?.toolType?.name.equals(ToolType.TEXT.name) - ) - return 0 - else if( - tool?.toolType?.name.equals(ToolType.LINE.name) || - tool?.toolType?.name.equals(ToolType.CURSOR.name) - ) - return 1 - else - return 2 - } - @Synchronized fun setBitmap(bitmap: Bitmap?) { layerModel.currentLayer?.bitmap = bitmap diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt index 14f515188b..2163a25d32 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -1,8 +1,6 @@ package org.catrobat.paintroid.ui.zoomwindow -import android.content.SharedPreferences import android.graphics.* -import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.ImageView @@ -94,8 +92,8 @@ class DefaultZoomWindowController private var coordinates: PointF? = null override fun show(coordinates: PointF) { - // Check if the tool is a compatible tool - if(checkCurrentTool(toolReference.tool) && sharedPreferences.preferenceZoomWindowEnabled) { +// Check if the tool is a compatible tool + if(checkCurrentTool(toolReference.tool) != 0 && sharedPreferences.preferenceZoomWindowEnabled) { if (isPointOnCanvas(coordinates.x, coordinates.y)) { if (shouldBeInTheRight(coordinates = coordinates)) { setLayoutAlignment(right = true) @@ -124,9 +122,11 @@ class DefaultZoomWindowController setLayoutAlignment(right = false) } if(isPointOnCanvas(coordinates.x, coordinates.y)){ - if(zoomWindow.visibility == View.GONE) - zoomWindow.visibility = View.VISIBLE - this.coordinates = coordinates + if(checkCurrentTool(toolReference.tool) != 0 && sharedPreferences.preferenceZoomWindowEnabled) { + if (zoomWindow.visibility == View.GONE) + zoomWindow.visibility = View.VISIBLE + this.coordinates = coordinates + } } else { dismiss() } @@ -204,8 +204,7 @@ class DefaultZoomWindowController canvas.drawBitmap(backgroundBitmap, Matrix(), null) // Add the current layer if the tool is line or cursor tool - if(toolReference.tool?.toolType?.name.equals(ToolType.LINE.name) || - toolReference.tool?.toolType?.name.equals(ToolType.CURSOR.name)) { + if(checkCurrentTool(toolReference.tool) == 1) { layerModel.currentLayer?.bitmap?.let { canvas.drawBitmap(it, windowSideDimen / 2f, windowSideDimen / 2f, null) } @@ -221,17 +220,25 @@ class DefaultZoomWindowController return windowSideDimen - (zoomIndex * zoomFactor) } - private fun checkCurrentTool(tool: Tool?): Boolean { + override fun checkCurrentTool(tool: Tool?): Int { if( tool?.toolType?.name.equals(ToolType.HAND.name) || tool?.toolType?.name.equals(ToolType.FILL.name) || - tool?.toolType?.name.equals(ToolType.STAMP.name) || - tool?.toolType?.name.equals(ToolType.TRANSFORM.name) || - tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) || + tool?.toolType?.name.equals(ToolType.TRANSFORM.name) + ) + // NON-COMPATIBLE + return 0 + else if( + tool?.toolType?.name.equals(ToolType.LINE.name) || + tool?.toolType?.name.equals(ToolType.CURSOR.name) || + tool?.toolType?.name.equals(ToolType.TEXT.name) || tool?.toolType?.name.equals(ToolType.SHAPE.name) || - tool?.toolType?.name.equals(ToolType.TEXT.name) + tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) || + tool?.toolType?.name.equals(ToolType.STAMP.name) ) - return false - return true + return 1 + else + // COMPATIBLE + return 2 } } \ No newline at end of file diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt index 85bf226416..6261b9f06a 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt @@ -3,6 +3,7 @@ package org.catrobat.paintroid.ui.zoomwindow import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.PointF +import org.catrobat.paintroid.tools.Tool interface ZoomWindowController { fun show(coordinates: PointF) @@ -14,4 +15,6 @@ interface ZoomWindowController { fun onMove(coordinates: PointF) fun getBitmap(bitmap: Bitmap?) + + fun checkCurrentTool(tool: Tool?) : Int } \ No newline at end of file From 9e41f9036427f9032c7cb635f7d2236efa5cc5a3 Mon Sep 17 00:00:00 2001 From: Saatwik Date: Fri, 14 Oct 2022 19:12:21 +0530 Subject: [PATCH 10/10] Paintroid 434: Static warnings removed --- .../espresso/ZoomWindowIntegrationTest.kt | 22 ++-- .../util/wrappers/ZoomWindowInteraction.java | 5 +- .../org/catrobat/paintroid/UserPreferences.kt | 10 +- .../contract/MainActivityContracts.kt | 1 - .../dialog/ZoomWindowSettingsDialog.kt | 6 +- .../listener/DrawingSurfaceListener.kt | 23 ++-- .../tools/implementation/BrushTool.kt | 5 +- .../tools/implementation/FillTool.kt | 5 +- .../tools/implementation/HandTool.kt | 5 +- .../tools/implementation/ImportTool.kt | 5 +- .../tools/implementation/LineTool.kt | 5 +- .../tools/implementation/PipetteTool.kt | 5 +- .../tools/implementation/ShapeTool.kt | 5 +- .../tools/implementation/SmudgeTool.kt | 5 +- .../tools/implementation/SprayTool.kt | 5 +- .../tools/implementation/StampTool.kt | 5 +- .../tools/implementation/TextTool.kt | 5 +- .../tools/implementation/TransformTool.kt | 5 +- .../catrobat/paintroid/ui/DrawingSurface.kt | 2 +- .../paintroid/ui/MainActivityNavigator.kt | 52 ++++++++- .../zoomwindow/DefaultZoomWindowController.kt | 109 ++++++++++-------- .../ui/zoomwindow/ZoomWindowController.kt | 5 +- .../layout/pocketpaint_layout_zoom_window.xml | 13 +-- Paintroid/src/main/res/values/string.xml | 3 +- 24 files changed, 172 insertions(+), 139 deletions(-) diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt index 1df6b37938..93dfcde9a4 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/ZoomWindowIntegrationTest.kt @@ -1,41 +1,35 @@ package org.catrobat.paintroid.test.espresso -import android.content.Intent import android.os.Build -import android.text.Layout import android.widget.RelativeLayout import androidx.test.espresso.Espresso.onView -import androidx.test.espresso.action.CoordinatesProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import org.catrobat.paintroid.MainActivity -import org.catrobat.paintroid.common.TEMP_IMAGE_PATH -import org.catrobat.paintroid.test.espresso.util.UiInteractions.touchCenterMiddle import org.catrobat.paintroid.test.espresso.util.wrappers.DrawingSurfaceInteraction.onDrawingSurfaceView import org.catrobat.paintroid.test.espresso.util.wrappers.ToolBarViewInteraction import org.catrobat.paintroid.tools.ToolType import org.junit.Before import org.junit.Rule import org.junit.runner.RunWith -import java.io.File import org.catrobat.paintroid.R import org.junit.Test import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.matcher.ViewMatchers -import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import androidx.test.espresso.matcher.ViewMatchers.withId import org.catrobat.paintroid.test.espresso.util.DrawingSurfaceLocationProvider -import org.catrobat.paintroid.test.espresso.util.UiInteractions.PressAndReleaseActions.* -import org.catrobat.paintroid.test.espresso.util.UiInteractions.touchLongAt +import org.catrobat.paintroid.test.espresso.util.UiInteractions.PressAndReleaseActions.tearDownPressAndRelease +import org.catrobat.paintroid.test.espresso.util.UiInteractions.PressAndReleaseActions.pressAction +import org.catrobat.paintroid.test.espresso.util.UiInteractions.PressAndReleaseActions.releaseAction import org.catrobat.paintroid.test.espresso.util.wrappers.ZoomWindowInteraction.onZoomWindow import org.junit.After - @RunWith(AndroidJUnit4::class) class ZoomWindowIntegrationTest { @get:Rule val launchActivityRule = ActivityTestRule(MainActivity::class.java) - @Before fun setUp() { ToolBarViewInteraction.onToolBarView() @@ -53,7 +47,7 @@ class ZoomWindowIntegrationTest { .perform(pressAction(DrawingSurfaceLocationProvider.MIDDLE)) onView(withId(R.id.pocketpaint_zoom_window)) - .check(matches(withEffectiveVisibility(Visibility.VISIBLE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))) onDrawingSurfaceView() .perform(releaseAction()) @@ -68,7 +62,7 @@ class ZoomWindowIntegrationTest { .perform(releaseAction()) onView(withId(R.id.pocketpaint_zoom_window)) - .check(matches(withEffectiveVisibility(Visibility.GONE))) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))) } @Test @@ -107,4 +101,4 @@ class ZoomWindowIntegrationTest { onDrawingSurfaceView() .perform(releaseAction()) } -} \ No newline at end of file +} diff --git a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java index 40bff07036..7552e8c524 100644 --- a/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java +++ b/Paintroid/src/androidTest/java/org/catrobat/paintroid/test/espresso/util/wrappers/ZoomWindowInteraction.java @@ -6,7 +6,6 @@ import static org.catrobat.paintroid.test.espresso.util.MainActivityHelper.getMainActivityFromView; -import android.util.Log; import android.view.View; import android.widget.RelativeLayout; @@ -15,9 +14,7 @@ import org.hamcrest.Description; import org.hamcrest.TypeSafeMatcher; -import java.util.Arrays; - -public class ZoomWindowInteraction extends CustomViewInteraction { +public final class ZoomWindowInteraction extends CustomViewInteraction { private ZoomWindowInteraction() { super(onView(withId(R.id.pocketpaint_zoom_window))); diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt b/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt index 7e8553f7e4..3465535971 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/UserPreferences.kt @@ -25,6 +25,7 @@ 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 get() = preferences.getBoolean(SHOW_LIKE_US_DIALOG_SHARED_PREFERENCES_TAG, false) open var preferenceImageNumber: Int @@ -45,7 +46,10 @@ open class UserPreferences(var preferences: SharedPreferences) { } open var preferenceZoomWindowZoomPercentage: Int - get() = preferences.getInt(ZOOM_WINDOW_ZOOM_PERCENTAGE_SHARED_PREFERENCES_TAG, 100) + get() = preferences.getInt( + ZOOM_WINDOW_ZOOM_PERCENTAGE_SHARED_PREFERENCES_TAG, + initialZoomPercent + ) set(value) { preferences .edit() @@ -59,4 +63,8 @@ open class UserPreferences(var preferences: SharedPreferences) { .putBoolean(SHOW_LIKE_US_DIALOG_SHARED_PREFERENCES_TAG, true) .apply() } + + companion object { + const val initialZoomPercent: Int = 100 + } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt b/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt index a34d2fc8a5..43bb945d2e 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/contract/MainActivityContracts.kt @@ -21,7 +21,6 @@ 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 diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt b/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt index c6e02369b4..32631bbf69 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/dialog/ZoomWindowSettingsDialog.kt @@ -3,9 +3,7 @@ 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 @@ -13,8 +11,6 @@ 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 @@ -79,4 +75,4 @@ class ZoomWindowSettingsDialog( sharedPreferences.preferenceZoomWindowZoomPercentage = initialPercentageValue super.onCancel(dialog) } -} \ No newline at end of file +} diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt index 3b9ad30a74..89ee8d1107 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/listener/DrawingSurfaceListener.kt @@ -114,7 +114,6 @@ open class DrawingSurfaceListener( ) { zoomController = zoomWindowController this.sharedPreferences = sharedPreferences - } private fun handleActionMove(currentTool: Tool?, view: View, event: MotionEvent) { @@ -145,12 +144,8 @@ open class DrawingSurfaceListener( } currentTool.handleMove(canvasTouchPoint) } - if(callZoomWindow) { - if (zoomController.checkCurrentTool(callback.getCurrentTool()) == 1) { - zoomController.onMove(currentTool.toolPositionCoordinates(canvasTouchPoint)) - } else { - zoomController.onMove(canvasTouchPoint) - } + if (callZoomWindow) { + handleZoomOnMove(currentTool) } } else { disableAutoScroll() @@ -174,6 +169,14 @@ open class DrawingSurfaceListener( } } + private fun handleZoomOnMove(currentTool: Tool) { + if (zoomController.checkCurrentTool(callback.getCurrentTool()) == 1) { + zoomController.onMove(currentTool.toolPositionCoordinates(canvasTouchPoint)) + } else { + zoomController.onMove(canvasTouchPoint) + } + } + override fun onTouch(view: View, event: MotionEvent): Boolean { val drawingSurface = view as DrawingSurface val currentTool = callback.getCurrentTool() @@ -194,8 +197,8 @@ open class DrawingSurfaceListener( setEvenPointAndViewDimensionsForAutoScrollTask(view) autoScrollTask.start() } - if(sharedPreferences.preferenceZoomWindowEnabled) { - if (zoomController.checkCurrentTool(callback.getCurrentTool()) == 1) { + if (sharedPreferences.preferenceZoomWindowEnabled) { + if (zoomController.checkCurrentTool(callback.getCurrentTool()) == 1) { currentTool?.let { zoomController.onMove(it.toolPositionCoordinates(canvasTouchPoint)) } @@ -241,7 +244,7 @@ open class DrawingSurfaceListener( eventX = 0f eventY = 0f touchMode = TouchMode.DRAW - if(callZoomWindow) zoomController.dismiss() + if (callZoomWindow) zoomController.dismiss() callback.getCurrentTool()?.handToolMode() } } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt index c9c22d63c2..092e97881d 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/BrushTool.kt @@ -147,10 +147,9 @@ open class BrushTool( } } - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate override fun resetInternalState() { pathToDraw.rewind() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt index feac24c756..e26267dc71 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/FillTool.kt @@ -87,10 +87,9 @@ class FillTool( return true } - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate public override fun resetInternalState() = Unit diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt index e9fac0e313..b65d0fa73f 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/HandTool.kt @@ -57,10 +57,7 @@ class HandTool( override fun handleUp(coordinate: PointF?): Boolean = true - override fun toolPositionCoordinates(coordinate: PointF): PointF { - // The tool coordinate is same as the touch coordinate - return coordinate - } + override fun toolPositionCoordinates(coordinate: PointF): PointF = coordinate override fun handToolMode(): Boolean = true } diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt index ce364847cd..711d2a6c24 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ImportTool.kt @@ -49,10 +49,9 @@ class ImportTool( override val toolType: ToolType get() = ToolType.IMPORTPNG - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) - } + PointF(toolPosition.x - boxWidth / 2, toolPosition.y - boxHeight / 2) init { rotationEnabled = true diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt index eccf3b22f8..ced89757d1 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/LineTool.kt @@ -321,10 +321,9 @@ class LineTool( return true } - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate override fun resetInternalState() { initialEventCoordinate = null diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt index c5d7064813..26db01c8b0 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/PipetteTool.kt @@ -58,10 +58,9 @@ class PipetteTool( override fun handleUp(coordinate: PointF?): Boolean = setColor(coordinate) - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate override fun resetInternalState() { updateSurfaceBitmap() diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt index 49d4844d25..a3e1626814 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/ShapeTool.kt @@ -68,10 +68,9 @@ class ShapeTool( override val toolType: ToolType get() = ToolType.SHAPE - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) - } + PointF(toolPosition.x - boxWidth / 2, toolPosition.y - boxHeight / 2) init { rotationEnabled = true diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt index dddce1f301..03fafba2a0 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SmudgeTool.kt @@ -232,10 +232,9 @@ class SmudgeTool( } } - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate override fun draw(canvas: Canvas) { if (pointArray.isNotEmpty()) { diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt index a29a3605ff..ff5aed6acf 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/SprayTool.kt @@ -103,10 +103,9 @@ class SprayTool( return true } - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate override fun handleMove(coordinate: PointF?): Boolean { currentCoordinate = coordinate diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt index 2d2947f52c..354f608277 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/StampTool.kt @@ -61,10 +61,9 @@ class StampTool( override val toolType: ToolType get() = ToolType.STAMP - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) - } + PointF(toolPosition.x - boxWidth / 2, toolPosition.y - boxHeight / 2) init { rotationEnabled = true diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt index 22d2920cc2..4fe6536858 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TextTool.kt @@ -116,10 +116,9 @@ class TextTool( override val toolType: ToolType get() = ToolType.TEXT - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return PointF(toolPosition.x - (boxWidth / 2), toolPosition.y - (boxHeight / 2)) - } + PointF(toolPosition.x - boxWidth / 2, toolPosition.y - boxHeight / 2) init { rotationEnabled = ROTATION_ENABLED diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt index a34acae5af..cc3f3c5b65 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/tools/implementation/TransformTool.kt @@ -112,10 +112,9 @@ class TransformTool( override val toolType: ToolType get() = ToolType.TRANSFORM - override fun toolPositionCoordinates(coordinate: PointF): PointF { + override fun toolPositionCoordinates(coordinate: PointF): PointF = // The tool coordinate is same as the touch coordinate - return coordinate - } + coordinate init { rotationEnabled = ROTATION_ENABLED diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt index a5482ea8a4..23b06b7868 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/DrawingSurface.kt @@ -174,7 +174,7 @@ open class DrawingSurface : SurfaceView, SurfaceHolder.Callback { val tool = toolReference.tool // Will create the zoom window only if the tool is a compatible tool - when(zoomController.checkCurrentTool(tool)) { + when (zoomController.checkCurrentTool(tool)) { 0 -> { // NON-COMPATIBLE TOOLS tool?.draw(surfaceViewCanvas) diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt index c722aa0e60..3136f1cc98 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/MainActivityNavigator.kt @@ -22,7 +22,6 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.ActivityNotFoundException import android.content.Intent -import android.content.SharedPreferences import android.content.pm.PackageManager import android.content.res.Configuration import android.graphics.Bitmap @@ -35,16 +34,61 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment -import org.catrobat.paintroid.* +import org.catrobat.paintroid.FileIO +import org.catrobat.paintroid.MainActivity +import org.catrobat.paintroid.R +import org.catrobat.paintroid.UserPreferences +import org.catrobat.paintroid.WelcomeActivity import org.catrobat.paintroid.colorpicker.ColorPickerDialog import org.catrobat.paintroid.colorpicker.OnColorPickedListener import org.catrobat.paintroid.command.CommandFactory import org.catrobat.paintroid.command.implementation.DefaultCommandFactory -import org.catrobat.paintroid.common.* +import org.catrobat.paintroid.common.ABOUT_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.ADVANCED_SETTINGS_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.CATROBAT_INFORMATION_DIALOG_TAG +import org.catrobat.paintroid.common.CATROID_MEDIA_GALLERY_FRAGMENT_TAG +import org.catrobat.paintroid.common.COLOR_PICKER_DIALOG_TAG +import org.catrobat.paintroid.common.FEEDBACK_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.INDETERMINATE_PROGRESS_DIALOG_TAG +import org.catrobat.paintroid.common.JPG_INFORMATION_DIALOG_TAG +import org.catrobat.paintroid.common.LIKE_US_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.LOAD_DIALOG_FRAGMENT_TAG import org.catrobat.paintroid.common.MainActivityConstants.ActivityRequestCode +import org.catrobat.paintroid.common.ORA_INFORMATION_DIALOG_TAG +import org.catrobat.paintroid.common.OVERWRITE_INFORMATION_DIALOG_TAG +import org.catrobat.paintroid.common.PAINTROID_PICTURE_PATH +import org.catrobat.paintroid.common.PERMISSION_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.PERMISSION_EXTERNAL_STORAGE_SAVE_COPY +import org.catrobat.paintroid.common.PNG_INFORMATION_DIALOG_TAG +import org.catrobat.paintroid.common.RATE_US_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.SAVE_DIALOG_FRAGMENT_TAG +import org.catrobat.paintroid.common.SAVE_INFORMATION_DIALOG_TAG +import org.catrobat.paintroid.common.SAVE_QUESTION_FRAGMENT_TAG +import org.catrobat.paintroid.common.SCALE_IMAGE_FRAGMENT_TAG +import org.catrobat.paintroid.common.ZOOM_WINDOW_SETTINGS_DIALOG_FRAGMENT_TAG import org.catrobat.paintroid.contract.MainActivityContracts -import org.catrobat.paintroid.dialog.* +import org.catrobat.paintroid.dialog.AboutDialog +import org.catrobat.paintroid.dialog.AdvancedSettingsDialog +import org.catrobat.paintroid.dialog.CatrobatImageInfoDialog +import org.catrobat.paintroid.dialog.FeedbackDialog +import org.catrobat.paintroid.dialog.ImportImageDialog +import org.catrobat.paintroid.dialog.IndeterminateProgressDialog +import org.catrobat.paintroid.dialog.InfoDialog +import org.catrobat.paintroid.dialog.JpgInfoDialog +import org.catrobat.paintroid.dialog.LikeUsDialog +import org.catrobat.paintroid.dialog.OraInfoDialog +import org.catrobat.paintroid.dialog.OverwriteDialog +import org.catrobat.paintroid.dialog.PermanentDenialPermissionInfoDialog +import org.catrobat.paintroid.dialog.PermissionInfoDialog import org.catrobat.paintroid.dialog.PermissionInfoDialog.PermissionType +import org.catrobat.paintroid.dialog.PngInfoDialog +import org.catrobat.paintroid.dialog.RateUsDialog +import org.catrobat.paintroid.dialog.SaveBeforeFinishDialog +import org.catrobat.paintroid.dialog.SaveBeforeLoadImageDialog +import org.catrobat.paintroid.dialog.SaveBeforeNewImageDialog +import org.catrobat.paintroid.dialog.SaveInformationDialog +import org.catrobat.paintroid.dialog.ScaleImageOnLoadDialog +import org.catrobat.paintroid.dialog.ZoomWindowSettingsDialog import org.catrobat.paintroid.tools.ToolReference import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.ui.fragments.CatroidMediaGalleryFragment diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt index 2163a25d32..35a2a118ca 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/DefaultZoomWindowController.kt @@ -1,8 +1,19 @@ package org.catrobat.paintroid.ui.zoomwindow -import android.graphics.* +import android.graphics.Bitmap +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Rect +import android.graphics.PorterDuffXfermode +import android.graphics.PorterDuff +import android.graphics.BitmapFactory +import android.graphics.BitmapShader +import android.graphics.Canvas +import android.graphics.Shader +import android.graphics.Matrix +import android.graphics.PointF +import android.graphics.RectF import android.view.View -import android.view.ViewGroup import android.widget.ImageView import android.widget.RelativeLayout import org.catrobat.paintroid.MainActivity @@ -15,7 +26,6 @@ import org.catrobat.paintroid.tools.ToolType import org.catrobat.paintroid.tools.Workspace import kotlin.math.roundToInt - class DefaultZoomWindowController (val activity: MainActivity, val layerModel: LayerContracts.Model, @@ -28,8 +38,6 @@ class DefaultZoomWindowController private val checkeredPattern = Paint() private val framePaint = Paint() - private val zoomFactor: Int = 25 - // Getting the dimensions of the zoom window private val windowSideDimen = activity.resources.getDimensionPixelSize(R.dimen.pocketpaint_zoom_window_height) @@ -75,7 +83,6 @@ class DefaultZoomWindowController activity.resources.getColor(R.color.pocketpaint_main_drawing_surface_background) ) - val canvasBackground = Canvas(backgroundBitmap) canvasBackground.drawBitmap(greyBackgroundBitmap, Matrix(), null) @@ -85,24 +92,22 @@ class DefaultZoomWindowController private val zoomWindow: RelativeLayout = activity.findViewById(R.id.pocketpaint_zoom_window) - private val zoomWindowShape: ViewGroup = - activity.findViewById(R.id.pocketpaint_zoom_window_inner) private val zoomWindowImage: ImageView = activity.findViewById(R.id.pocketpaint_zoom_window_image) private var coordinates: PointF? = null override fun show(coordinates: PointF) { // Check if the tool is a compatible tool - if(checkCurrentTool(toolReference.tool) != 0 && sharedPreferences.preferenceZoomWindowEnabled) { - if (isPointOnCanvas(coordinates.x, coordinates.y)) { - if (shouldBeInTheRight(coordinates = coordinates)) { - setLayoutAlignment(right = true) - } else { - setLayoutAlignment(right = false) - } - zoomWindow.visibility = View.VISIBLE - zoomWindowImage.setImageBitmap(cropBitmap(workspace.bitmapOfAllLayers, coordinates)) + if (checkCurrentTool(toolReference.tool) != 0 && + sharedPreferences.preferenceZoomWindowEnabled && + isPointOnCanvas(coordinates.x, coordinates.y)) { + if (shouldBeInTheRight(coordinates = coordinates)) { + setLayoutAlignment(right = true) + } else { + setLayoutAlignment(right = false) } + zoomWindow.visibility = View.VISIBLE + zoomWindowImage.setImageBitmap(cropBitmap(workspace.bitmapOfAllLayers, coordinates)) } } @@ -115,16 +120,16 @@ class DefaultZoomWindowController } override fun onMove(coordinates: PointF) { - if(shouldBeInTheRight(coordinates = coordinates)) { + if (shouldBeInTheRight(coordinates = coordinates)) { setLayoutAlignment(right = true) - } - else { + } else { setLayoutAlignment(right = false) } - if(isPointOnCanvas(coordinates.x, coordinates.y)){ - if(checkCurrentTool(toolReference.tool) != 0 && sharedPreferences.preferenceZoomWindowEnabled) { - if (zoomWindow.visibility == View.GONE) + if (isPointOnCanvas(coordinates.x, coordinates.y)) { + if (checkCurrentTool(toolReference.tool) != 0 && sharedPreferences.preferenceZoomWindowEnabled) { + if (zoomWindow.visibility == View.GONE) { zoomWindow.visibility = View.VISIBLE + } this.coordinates = coordinates } } else { @@ -139,31 +144,32 @@ class DefaultZoomWindowController private fun isPointOnCanvas(pointX: Float, pointY: Float): Boolean = pointX > 0 && pointX < layerModel.width && pointY > 0 && pointY < layerModel.height - private fun shouldBeInTheRight(coordinates: PointF) : Boolean { - if(coordinates.x < layerModel.width / 3 && coordinates.y < layerModel.height / 2) + private fun shouldBeInTheRight(coordinates: PointF): Boolean { + if (coordinates.x < layerModel.width / 2 && coordinates.y < layerModel.height / 2) { return true + } return false } private fun setLayoutAlignment(right: Boolean) { - val params : RelativeLayout.LayoutParams = - zoomWindowShape.layoutParams as RelativeLayout.LayoutParams - if(right) { + val params: RelativeLayout.LayoutParams = + zoomWindowImage.layoutParams as RelativeLayout.LayoutParams + if (right) { params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT) params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT) } else { params.addRule(RelativeLayout.ALIGN_PARENT_LEFT) params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT) } - zoomWindowShape.layoutParams = params + zoomWindowImage.layoutParams = params } - private fun cropBitmap(bitmap: Bitmap?, coordinates: PointF) : Bitmap? { + private fun cropBitmap(bitmap: Bitmap?, coordinates: PointF): Bitmap? { val bitmapWithBackground: Bitmap? = mergeBackground(bitmap) - val startX: Int = (coordinates.x).roundToInt() + windowSideDimen / 2 - getSizeOfZoomWindow() / 2 - val startY: Int = (coordinates.y).roundToInt() + windowSideDimen / 2 - getSizeOfZoomWindow() / 2 + val startX: Int = coordinates.x.roundToInt() + windowSideDimen / 2 - getSizeOfZoomWindow() / 2 + val startY: Int = coordinates.y.roundToInt() + windowSideDimen / 2 - getSizeOfZoomWindow() / 2 val croppedBitmap: Bitmap? = Bitmap.createBitmap(getSizeOfZoomWindow(), getSizeOfZoomWindow(), Bitmap.Config.ARGB_8888) @@ -182,7 +188,7 @@ class DefaultZoomWindowController bitmapWithBackground?.let { canvas?.drawBitmap(it, - Rect(startX, startY, startX+getSizeOfZoomWindow(), startY+getSizeOfZoomWindow()), + Rect(startX, startY, startX + getSizeOfZoomWindow(), startY + getSizeOfZoomWindow()), rect, paint ) } @@ -204,7 +210,7 @@ class DefaultZoomWindowController canvas.drawBitmap(backgroundBitmap, Matrix(), null) // Add the current layer if the tool is line or cursor tool - if(checkCurrentTool(toolReference.tool) == 1) { + if (checkCurrentTool(toolReference.tool) == 1) { layerModel.currentLayer?.bitmap?.let { canvas.drawBitmap(it, windowSideDimen / 2f, windowSideDimen / 2f, null) } @@ -216,29 +222,38 @@ class DefaultZoomWindowController } private fun getSizeOfZoomWindow(): Int { - val zoomIndex = (sharedPreferences.preferenceZoomWindowZoomPercentage - 100) / 50 - return windowSideDimen - (zoomIndex * zoomFactor) + val zoomIndex = (sharedPreferences.preferenceZoomWindowZoomPercentage - initialZoomValue) / zoomPercentStepValue + return windowSideDimen - zoomIndex * zoomFactor } - override fun checkCurrentTool(tool: Tool?): Int { - if( + override fun checkCurrentTool(tool: Tool?): Int = + if ( tool?.toolType?.name.equals(ToolType.HAND.name) || tool?.toolType?.name.equals(ToolType.FILL.name) || tool?.toolType?.name.equals(ToolType.TRANSFORM.name) - ) + ) { // NON-COMPATIBLE - return 0 - else if( + 0 + } else if ( tool?.toolType?.name.equals(ToolType.LINE.name) || tool?.toolType?.name.equals(ToolType.CURSOR.name) || - tool?.toolType?.name.equals(ToolType.TEXT.name) || + tool?.toolType?.name.equals(ToolType.TEXT.name) + ) { + 1 + } else if ( tool?.toolType?.name.equals(ToolType.SHAPE.name) || tool?.toolType?.name.equals(ToolType.IMPORTPNG.name) || tool?.toolType?.name.equals(ToolType.STAMP.name) - ) - return 1 - else + ) { + 1 + } else { // COMPATIBLE - return 2 + 2 + } + + companion object { + const val zoomFactor: Int = 25 + const val initialZoomValue: Int = 100 + const val zoomPercentStepValue = 50 } -} \ No newline at end of file +} diff --git a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt index 6261b9f06a..4fa075f685 100644 --- a/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt +++ b/Paintroid/src/main/java/org/catrobat/paintroid/ui/zoomwindow/ZoomWindowController.kt @@ -1,7 +1,6 @@ package org.catrobat.paintroid.ui.zoomwindow import android.graphics.Bitmap -import android.graphics.Canvas import android.graphics.PointF import org.catrobat.paintroid.tools.Tool @@ -16,5 +15,5 @@ interface ZoomWindowController { fun getBitmap(bitmap: Bitmap?) - fun checkCurrentTool(tool: Tool?) : Int -} \ No newline at end of file + fun checkCurrentTool(tool: Tool?): Int +} diff --git a/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml b/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml index 64c52f04b1..7c349c43bf 100644 --- a/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml +++ b/Paintroid/src/main/res/layout/pocketpaint_layout_zoom_window.xml @@ -6,21 +6,14 @@ android:visibility="gone" android:layout_height="match_parent"> - - - - - + android:contentDescription="@string/zoom_window_description" /> \ No newline at end of file diff --git a/Paintroid/src/main/res/values/string.xml b/Paintroid/src/main/res/values/string.xml index 47120771f5..f3ad908896 100644 --- a/Paintroid/src/main/res/values/string.xml +++ b/Paintroid/src/main/res/values/string.xml @@ -245,7 +245,6 @@ Image is too big to load The image is too big to load. Tap OK to scale down the image automatically. - Press - Release + Used to display a zoomed in part of the drawing surface