From ee91a75d6f9b7daacd6f4fea66a9ea6a86519b69 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 14 Aug 2016 12:23:05 +0200 Subject: [PATCH] Extract DragButton into a separate module --- app/build.gradle | 16 +++++++------ app/src/main/res/values/colors.xml | 2 ++ app/src/main/res/values/dimens.xml | 3 --- app/src/main/res/values/drag_dimens.xml | 4 ---- app/src/main/res/values/styles.xml | 2 +- build.gradle | 5 ++++ dragbutton/.gitignore | 1 + dragbutton/build.gradle | 24 +++++++++++++++++++ dragbutton/proguard-rules.pro | 17 +++++++++++++ dragbutton/src/main/AndroidManifest.xml | 5 ++++ .../views/dragbutton/DirectionDragButton.java | 4 +--- .../dragbutton/DirectionDragImageButton.java | 6 ++--- .../dragbutton/DirectionDragListener.java | 6 +---- .../views/dragbutton/DirectionDragView.java | 4 +--- .../views/dragbutton/DirectionTextView.java | 18 +++++++------- .../android/views/dragbutton/Drag.java | 0 .../android/views/dragbutton/DragButton.java | 0 .../views/dragbutton/DragDirection.java | 2 -- .../android/views/dragbutton/DragEvent.java | 0 .../views/dragbutton/DragGestureDetector.java | 3 --- .../views/dragbutton/DragImageButton.java | 0 .../views/dragbutton/DragListener.java | 0 .../android/views/dragbutton/DragView.java | 0 .../src/main/res/values/attrs.xml | 0 dragbutton/src/main/res/values/colors.xml | 5 ++++ dragbutton/src/main/res/values/dimens.xml | 7 ++++++ settings.gradle | 2 +- 27 files changed, 91 insertions(+), 45 deletions(-) delete mode 100644 app/src/main/res/values/drag_dimens.xml create mode 100644 dragbutton/.gitignore create mode 100644 dragbutton/build.gradle create mode 100644 dragbutton/proguard-rules.pro create mode 100644 dragbutton/src/main/AndroidManifest.xml rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java (98%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java (95%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java (90%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java (82%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java (95%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/Drag.java (100%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragButton.java (100%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java (96%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragEvent.java (100%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java (97%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragImageButton.java (100%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragListener.java (100%) rename {app => dragbutton}/src/main/java/org/solovyev/android/views/dragbutton/DragView.java (100%) rename app/src/main/res/values/drag_attrs.xml => dragbutton/src/main/res/values/attrs.xml (100%) create mode 100644 dragbutton/src/main/res/values/colors.xml create mode 100644 dragbutton/src/main/res/values/dimens.xml diff --git a/app/build.gradle b/app/build.gradle index f8bb028b..28b359f3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,11 +26,12 @@ apply plugin: 'signing' apply plugin: 'com.neenbedankt.android-apt' android { - compileSdkVersion 23 - buildToolsVersion '23.0.3' + compileSdkVersion versions.sdk.compile + buildToolsVersion versions.sdk.buildTools defaultConfig { - minSdkVersion 9 - targetSdkVersion 23 + applicationId "org.solovyev.android.calculator" + minSdkVersion versions.sdk.min + targetSdkVersion versions.sdk.target versionCode 153 versionName '2.2.3' testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -61,9 +62,9 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:support-v4:23.4.0' - compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.android.support:design:23.4.0' + compile "com.android.support:support-v4:${versions.supportLib}" + compile "com.android.support:appcompat-v7:${versions.supportLib}" + compile "com.android.support:design:${versions.supportLib}" compile('ch.acra:acra:4.7.0') { exclude group: 'org.json' } @@ -71,6 +72,7 @@ dependencies { compile ':square-otto:1.3.9-SNAPSHOT' apt ':square-otto-compiler:1.3.9-SNAPSHOT' apt 'com.squareup:javapoet:1.5.1' + compile project(':dragbutton') compile(project(':jscl')) { exclude(module: 'xercesImpl') } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2efa67f2..9b198302 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -65,4 +65,6 @@ #880e4f #ffff8d + @color/cpp_text_inverse + @color/cpp_button_text \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index cc12aa25..be4b574e 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -7,9 +7,6 @@ 6dp 300dp 1px - 2dp - 9dp - 0.35 1dp 4dp diff --git a/app/src/main/res/values/drag_dimens.xml b/app/src/main/res/values/drag_dimens.xml deleted file mode 100644 index 51079469..00000000 --- a/app/src/main/res/values/drag_dimens.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - 15dp - \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index fe2c01d8..ca27ffb0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -35,7 +35,7 @@ @color/cpp_button_text centerInside @color/cpp_button_text - @dimen/cpp_direction_text_scale + @dimen/drag_direction_text_scale @dimen/cpp_keyboard_button_direction_text_padding_updown @dimen/cpp_keyboard_button_direction_text_padding_updown @dimen/cpp_keyboard_button_direction_text_padding_updown diff --git a/build.gradle b/build.gradle index 28c3c35c..5b53b408 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,11 @@ buildscript { classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' } + + ext { + versions = [supportLib: "23.4.0", + sdk : [compile: 23, buildTools: "23.0.3", min: 9, target: 23]] + } } allprojects { diff --git a/dragbutton/.gitignore b/dragbutton/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/dragbutton/.gitignore @@ -0,0 +1 @@ +/build diff --git a/dragbutton/build.gradle b/dragbutton/build.gradle new file mode 100644 index 00000000..6ca31d29 --- /dev/null +++ b/dragbutton/build.gradle @@ -0,0 +1,24 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion versions.sdk.compile + buildToolsVersion versions.sdk.buildTools + defaultConfig { + minSdkVersion versions.sdk.min + targetSdkVersion versions.sdk.target + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile "com.android.support:appcompat-v7:${versions.supportLib}" + compile "com.android.support:support-annotations:${versions.supportLib}" +} diff --git a/dragbutton/proguard-rules.pro b/dragbutton/proguard-rules.pro new file mode 100644 index 00000000..1ecf581f --- /dev/null +++ b/dragbutton/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /opt/android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/dragbutton/src/main/AndroidManifest.xml b/dragbutton/src/main/AndroidManifest.xml new file mode 100644 index 00000000..66654b3d --- /dev/null +++ b/dragbutton/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java similarity index 98% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java index 0d3c69ad..a4341270 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java @@ -8,8 +8,6 @@ import android.support.annotation.Nullable; import android.text.TextPaint; import android.util.AttributeSet; -import javax.annotation.Nonnull; - import static android.graphics.Color.BLACK; import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static android.util.TypedValue.applyDimension; @@ -72,7 +70,7 @@ public class DirectionDragButton extends DragButton implements DirectionDragView } @Override - @Nonnull + @NonNull public DirectionTextView.Text getText(@NonNull DragDirection direction) { return textView.getText(direction); } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java similarity index 95% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java index 9b882723..e18cb5d3 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java @@ -9,8 +9,6 @@ import android.text.TextPaint; import android.util.AttributeSet; import android.widget.TextView; -import javax.annotation.Nonnull; - public class DirectionDragImageButton extends DragImageButton implements DirectionDragView { private final DirectionTextView textView = new DirectionTextView(); private final TextPaint baseTextPaint = new TextPaint(); @@ -47,12 +45,12 @@ public class DirectionDragImageButton extends DragImageButton implements Directi textView.draw(canvas); } - @Nonnull + @NonNull public DirectionTextView.Text getText(@NonNull DragDirection direction) { return textView.getText(direction); } - public void setTypeface(@Nonnull Typeface newTypeface) { + public void setTypeface(@NonNull Typeface newTypeface) { final Typeface oldTypeface = baseTextPaint.getTypeface(); if (oldTypeface == newTypeface) { return; diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java similarity index 90% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java index 4336b123..e6526cec 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragListener.java @@ -7,12 +7,8 @@ import android.support.annotation.Nullable; import android.util.Log; import android.view.View; -import org.solovyev.android.calculator.R; - import static java.lang.Math.toDegrees; -import static org.solovyev.android.views.dragbutton.Drag.distance; -import static org.solovyev.android.views.dragbutton.Drag.getAngle; -import static org.solovyev.android.views.dragbutton.Drag.sum; +import static org.solovyev.android.views.dragbutton.Drag.*; public abstract class DirectionDragListener implements DragListener { diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java similarity index 82% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java index 9ab28fe3..9b90edbf 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragView.java @@ -2,9 +2,7 @@ package org.solovyev.android.views.dragbutton; import android.support.annotation.NonNull; -import javax.annotation.Nonnull; - public interface DirectionDragView extends DragView { - @Nonnull + @NonNull DirectionTextView.Text getText(@NonNull DragDirection direction); } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java similarity index 95% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java index 3af01572..389f85c3 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java @@ -16,9 +16,6 @@ import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.TextView; -import com.google.common.base.Strings; -import org.solovyev.android.Check; -import org.solovyev.android.calculator.R; import java.util.EnumMap; import java.util.Map; @@ -50,11 +47,10 @@ public class DirectionTextView { } public void init(@NonNull View view, @Nullable AttributeSet attrs, @NonNull TextPaint baseTextPaint) { - Check.isTrue(texts.isEmpty()); final Context context = view.getContext(); final int defColor = baseTextPaint.getColor(); - final int defPadding = context.getResources().getDimensionPixelSize(R.dimen.cpp_direction_text_default_padding); - final float minTextSize = context.getResources().getDimensionPixelSize(R.dimen.cpp_direction_text_min_size); + final int defPadding = context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_default_padding); + final float minTextSize = context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_min_size); if (attrs == null) { @@ -126,7 +122,7 @@ public class DirectionTextView { public void init(@NonNull TextPaint base, @Nullable TypedArray array, float defScale, int defColor, float defAlpha, int defPadding) { if (array != null) { if (array.hasValue(direction.textAttr)) { - value = Strings.nullToEmpty(array.getString(direction.textAttr)); + value = nullToEmpty(array.getString(direction.textAttr)); } padding = array.getDimensionPixelSize(direction.paddingAttr, defPadding); scale = array.getFloat(direction.scaleAttr, defScale); @@ -141,8 +137,13 @@ public class DirectionTextView { initPaint(base); } + @NonNull + private String nullToEmpty(@Nullable String s) { + return s == null ? "" : s; + } + private int makeContrastColor(int color) { - final int colorRes = isLightColor(color) ? R.color.cpp_button_text : R.color.cpp_text_inverse; + final int colorRes = isLightColor(color) ? R.color.drag_button_text : R.color.drag_text_inverse; return ContextCompat.getColor(view.getContext(), colorRes); } @@ -218,7 +219,6 @@ public class DirectionTextView { } private void invalidate(boolean remeasure) { - Check.isNotNull(view); view.invalidate(); if (remeasure) { offset.set(0, 0); diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/Drag.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/Drag.java similarity index 100% rename from app/src/main/java/org/solovyev/android/views/dragbutton/Drag.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/Drag.java diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragButton.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragButton.java similarity index 100% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragButton.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragButton.java diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java similarity index 96% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java index 599b98fc..e3a7e969 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragDirection.java @@ -2,8 +2,6 @@ package org.solovyev.android.views.dragbutton; import android.support.annotation.StyleableRes; -import org.solovyev.android.calculator.R; - public enum DragDirection { up(180f - 45f, 180f - 0f, R.styleable.DirectionText_directionTextUp, R.styleable.DirectionText_directionTextScaleUp, R.styleable.DirectionText_directionTextPaddingUp), diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragEvent.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragEvent.java similarity index 100% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragEvent.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragEvent.java diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java similarity index 97% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java index 43d9b891..109faa86 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragGestureDetector.java @@ -6,8 +6,6 @@ import android.support.annotation.Nullable; import android.view.MotionEvent; import android.view.View; -import org.solovyev.android.Check; - import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; @@ -67,7 +65,6 @@ public class DragGestureDetector { } private void startTracking(@NonNull MotionEvent event) { - Check.isNull(start); start = new PointF(event.getX(), event.getY()); } diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragImageButton.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragImageButton.java similarity index 100% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragImageButton.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragImageButton.java diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragListener.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragListener.java similarity index 100% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragListener.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragListener.java diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DragView.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragView.java similarity index 100% rename from app/src/main/java/org/solovyev/android/views/dragbutton/DragView.java rename to dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DragView.java diff --git a/app/src/main/res/values/drag_attrs.xml b/dragbutton/src/main/res/values/attrs.xml similarity index 100% rename from app/src/main/res/values/drag_attrs.xml rename to dragbutton/src/main/res/values/attrs.xml diff --git a/dragbutton/src/main/res/values/colors.xml b/dragbutton/src/main/res/values/colors.xml new file mode 100644 index 00000000..fbc10410 --- /dev/null +++ b/dragbutton/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #424242 + #ffffffff + \ No newline at end of file diff --git a/dragbutton/src/main/res/values/dimens.xml b/dragbutton/src/main/res/values/dimens.xml new file mode 100644 index 00000000..68a92491 --- /dev/null +++ b/dragbutton/src/main/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + 15dp + 2dp + 9dp + 0.35 + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 8e7e28da..f8aaa77f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':jscl', ':translations' +include ':app', ':jscl', ':translations', ':dragbutton'