Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch sync #456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
<activity android:name="info.touchimage.demo.RecyclerExampleActivity" />
<activity android:name="info.touchimage.demo.AnimateZoomActivity" />
<activity android:name="info.touchimage.demo.ShapedExampleActivity" />
<activity android:name="info.touchimage.demo.TouchSyncActivity" />
</application>
</manifest>
1 change: 1 addition & 0 deletions app/src/main/java/info/touchimage/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ class MainActivity : AppCompatActivity() {
binding.animateButton.setOnClickListener { startActivity(Intent(this@MainActivity, AnimateZoomActivity::class.java)) }
binding.glideButton.setOnClickListener { startActivity(Intent(this@MainActivity, GlideExampleActivity::class.java)) }
binding.shapedImageButton.setOnClickListener { startActivity(Intent(this@MainActivity, ShapedExampleActivity::class.java)) }
binding.touchSync.setOnClickListener { startActivity(Intent(this@MainActivity, TouchSyncActivity::class.java)) }
}
}
54 changes: 54 additions & 0 deletions app/src/main/java/info/touchimage/demo/TouchSyncActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package info.touchimage.demo

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.ortiz.touchview.OnTouchImageViewListener
import info.touchimage.demo.databinding.ActivityTouchSyncBinding

class TouchSyncActivity : AppCompatActivity() {

private lateinit var binding: ActivityTouchSyncBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityTouchSyncBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)

binding.touchImageOverlay.setOnTouchImageViewListener(object : OnTouchImageViewListener {
override fun onMove() {
binding.touchImage1.setZoom(binding.touchImageOverlay)
binding.touchImage2.setZoom(binding.touchImageOverlay)
}
})

// Works
val img = getBitmap(this, R.drawable.ic_baseline_aspect_ratio_24)
Copy link
Collaborator Author

@hannesa2 hannesa2 Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doplerfish @phillies
I tried out the 'Works' section of the code, and in my point of view, this doesn't work either. Or I simply don't understand the issue.
ic_baseline_aspect_ratio_24 is not in sync in move during zoom.

TouchSyncWorks.mp4

Btw, I do what I can and I keep this repository alive by merging pull requests, but I don't fix any issue of other guys. You can help me too !


/** HERE IS THE PROBLEM **/
// Does not work (after zooming in, dinosaur head is unreachable)
// val img = getBitmap(this, R.drawable.corgosaurus)
binding.touchImage2.setImageBitmap(img)

// Also does not work (after zooming in, dinosaur head is unreachable)
// binding.touchImage2.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.corgosaurus))
}

private fun getBitmap(context: Context, drawableRes: Int): Bitmap? {
val drawable = ContextCompat.getDrawable(context, drawableRes) ?: return null
val canvas = Canvas()
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth,
drawable.intrinsicHeight,
Bitmap.Config.ARGB_8888
)
canvas.setBitmap(bitmap)
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
drawable.draw(canvas)
return bitmap
}
}
Binary file added app/src/main/res/drawable/corgosaurus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_aspect_ratio_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19,12h-2v3h-3v2h5v-5zM7,9h3L10,7L5,7v5h2L7,9zM21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19.01L3,19.01L3,4.99h18v14.02z"/>
</vector>
19 changes: 19 additions & 0 deletions app/src/main/res/drawable/ic_baseline_lunch_dining_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M22,10c0.32,-3.28 -4.28,-6 -9.99,-6C6.3,4 1.7,6.72 2.02,10H22z"
android:fillType="evenOdd"/>
<path
android:fillColor="@android:color/white"
android:pathData="M5.35,13.5c0.55,0 0.78,0.14 1.15,0.36c0.45,0.27 1.07,0.64 2.18,0.64s1.73,-0.37 2.18,-0.64c0.37,-0.23 0.59,-0.36 1.15,-0.36c0.55,0 0.78,0.14 1.15,0.36c0.45,0.27 1.07,0.64 2.18,0.64c1.11,0 1.73,-0.37 2.18,-0.64c0.37,-0.23 0.59,-0.36 1.15,-0.36c0.55,0 0.78,0.14 1.15,0.36c0.45,0.27 1.07,0.63 2.17,0.64v-1.98c0,0 -0.79,-0.16 -1.16,-0.38c-0.45,-0.27 -1.07,-0.64 -2.18,-0.64c-1.11,0 -1.73,0.37 -2.18,0.64c-0.37,0.23 -0.6,0.36 -1.15,0.36s-0.78,-0.14 -1.15,-0.36c-0.45,-0.27 -1.07,-0.64 -2.18,-0.64s-1.73,0.37 -2.18,0.64c-0.37,0.23 -0.59,0.36 -1.15,0.36c-0.55,0 -0.78,-0.14 -1.15,-0.36c-0.45,-0.27 -1.07,-0.64 -2.18,-0.64c-1.11,0 -1.73,0.37 -2.18,0.64C2.78,12.37 2.56,12.5 2,12.5v2c1.11,0 1.73,-0.37 2.21,-0.64C4.58,13.63 4.8,13.5 5.35,13.5z"
android:fillType="evenOdd"/>
<path
android:fillColor="@android:color/white"
android:pathData="M2,16v2c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2v-2H2z"
android:fillType="evenOdd"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_masks_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.5,6c-1.31,0 -2.37,1.01 -2.48,2.3C15.14,7.8 14.18,6.5 12,6.5c-2.19,0 -3.14,1.3 -5.02,1.8C6.87,7.02 5.81,6 4.5,6C3.12,6 2,7.12 2,8.5V9c0,6 3.6,7.81 6.52,7.98C9.53,17.62 10.72,18 12,18s2.47,-0.38 3.48,-1.02C18.4,16.81 22,15 22,9V8.5C22,7.12 20.88,6 19.5,6zM3.5,9V8.5c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v3c0,1.28 0.38,2.47 1.01,3.48C4.99,14.27 3.5,12.65 3.5,9zM20.5,9c0,3.65 -1.49,5.27 -3.01,5.98c0.64,-1.01 1.01,-2.2 1.01,-3.48v-3c0,-0.55 0.45,-1 1,-1s1,0.45 1,1V9zM10.69,10.48c-0.44,0.26 -0.96,0.56 -1.69,0.76V10.2c0.48,-0.17 0.84,-0.38 1.18,-0.58C10.72,9.3 11.23,9 12,9s1.27,0.3 1.8,0.62c0.34,0.2 0.71,0.42 1.2,0.59v1.04c-0.75,-0.21 -1.26,-0.51 -1.71,-0.78C12.83,10.2 12.49,10 12,10C11.51,10 11.16,10.2 10.69,10.48z"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_mode_standby_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C6.49,2 2,6.49 2,12s4.49,10 10,10s10,-4.49 10,-10S17.51,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20zM15,12c0,1.66 -1.34,3 -3,3s-3,-1.34 -3,-3s1.34,-3 3,-3S15,10.34 15,12z"/>
</vector>
170 changes: 170 additions & 0 deletions app/src/main/res/drawable/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
Binary file added app/src/main/res/drawable/img_user_avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
Expand Down Expand Up @@ -74,5 +75,12 @@
android:layout_height="wrap_content"
android:text="@string/rounded_corners_example" />

<Button
android:id="@+id/touchSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="touch sync"
tools:ignore="HardcodedText" />

</LinearLayout>
</ScrollView>
32 changes: 32 additions & 0 deletions app/src/main/res/layout/activity_touch_sync.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recording_core_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:clickable="true"
android:focusable="true">

<com.ortiz.touchview.TouchImageView
android:id="@+id/touch_image_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/img_user_avatar" />

<com.ortiz.touchview.TouchImageView
android:id="@+id/touch_image_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />

<com.ortiz.touchview.TouchImageView
android:id="@+id/touch_image_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
android:src="@drawable/ic_baseline_mode_standby_24"
android:tint="@color/purple_200" />

</RelativeLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
<color name="colorAccent">#FF4081</color>
<color name="brown_light">#cc7b35</color>
<color name="brown">#945824</color>

<color name="purple_200">#FFBB86FC</color>
</resources>