From 5605c8da542a701d817af9209f3fa5ea010a757d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Nicol=C3=A1s=20Pina?= Date: Mon, 31 Aug 2020 16:33:55 +0200 Subject: [PATCH] V4.0 with better gesture detectors. --- .idea/jarRepositories.xml | 5 + .idea/misc.xml | 2 +- README.md | 13 +- sample/build.gradle | 5 + .../textimageview/sample/MainActivity.kt | 23 +- sample/src/main/res/layout/activity_main.xml | 28 +- sample/src/main/res/values/strings.xml | 1 - textimageview/build.gradle | 41 +- .../RotationGestureDetector.java | 78 --- .../antonionicolaspina/textimageview/Text.kt | 10 + .../textimageview/TextImageView.java | 494 ------------------ .../textimageview/TextImageView.kt | 217 ++++++++ .../textimageview/TextProperties.kt | 33 ++ textimageview/src/main/res/values/attrs.xml | 25 +- 14 files changed, 322 insertions(+), 653 deletions(-) delete mode 100644 textimageview/src/main/java/com/antonionicolaspina/textimageview/RotationGestureDetector.java create mode 100644 textimageview/src/main/java/com/antonionicolaspina/textimageview/Text.kt delete mode 100644 textimageview/src/main/java/com/antonionicolaspina/textimageview/TextImageView.java create mode 100644 textimageview/src/main/java/com/antonionicolaspina/textimageview/TextImageView.kt create mode 100644 textimageview/src/main/java/com/antonionicolaspina/textimageview/TextProperties.kt diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index ba1cefd..5aefbc8 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -41,5 +41,10 @@ - + diff --git a/README.md b/README.md index e70fe03..9ec1856 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,18 @@ An ImageView subclass that draws one or more spannable, rotable, scalable texts Provided that this is an ImageView subclass, you can use Picasso, Glide, or any Image loader that you like to load the image into TextImageView. -## New in 3.0 -You can enable text scale and rotation via multitouch gestures just by declaring it in your layout. -Now you can stack multiple texts one on top of the other and control them. +## New in 4.0 +Rewritten in kotlin+androidx ## Requirements -Android 2.2, API 8 +Android 4.0, API 14 ## Usage ### Gradle dependency ```groovy dependencies { - compile 'com.antonionicolaspina:textimageview:3.1.2' + implementation 'com.antonionicolaspina:textimageview:4.0' } ``` @@ -35,15 +34,13 @@ dependencies { android:textSize="30sp" android:textColor="#ff0000" app:tiv_panEnabled="true" - app:tiv_clampTextMode="textInside" - app:tiv_interline="10sp" app:tiv_scaleEnabled="true" app:tiv_rotationEnabled="true" android:src="@drawable/sample"/> ``` ## License - Copyright 2016 Antonio Nicolás Pina + Copyright 2020 YaikoStudio Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/sample/build.gradle b/sample/build.gradle index ca000fb..ba45a6e 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,10 +1,15 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 buildToolsVersion "29.0.2" + androidExtensions { + experimental = true + } + defaultConfig { applicationId "com.antonionicolaspina.textimageview.sample" minSdkVersion 14 diff --git a/sample/src/main/java/com/antonionicolaspina/textimageview/sample/MainActivity.kt b/sample/src/main/java/com/antonionicolaspina/textimageview/sample/MainActivity.kt index 57dc265..2219267 100644 --- a/sample/src/main/java/com/antonionicolaspina/textimageview/sample/MainActivity.kt +++ b/sample/src/main/java/com/antonionicolaspina/textimageview/sample/MainActivity.kt @@ -1,22 +1,29 @@ package com.antonionicolaspina.textimageview.sample +import android.graphics.Color import android.graphics.Typeface import android.os.Bundle -import android.view.View -import android.widget.TextView import androidx.appcompat.app.AppCompatActivity +import com.antonionicolaspina.textimageview.Text import com.antonionicolaspina.textimageview.TextImageView +import kotlinx.android.synthetic.main.activity_main.* +import java.util.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - val textImageView = findViewById(R.id.text_image) as TextImageView - textImageView.setTypeface(Typeface.DEFAULT_BOLD) - val textView = findViewById(R.id.text) as TextView - textImageView.setOnTextMovedListener { position -> - textView.text = - String.format("Position: [%.2f%%, %.2f%%]", position.x * 100f, position.y * 100f) + + text_image.listener = object : TextImageView.Listener { + override fun textsChanged(texts: List) { + position_textview.text = texts.joinToString("\n") + } + } + + add_more_button.setOnClickListener { + text_image.addText("Text ${Date()}") + text_image.setTypeface(Typeface.DEFAULT_BOLD) + text_image.setTextColor(Color.RED) } } } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index f6454b8..238bc39 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -7,26 +7,28 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> - + android:layout_weight="1"> + +