Extract DragButton into a separate module

This commit is contained in:
serso 2016-08-14 12:23:05 +02:00
parent 28ac55a0ca
commit ee91a75d6f
27 changed files with 91 additions and 45 deletions

View File

@ -26,11 +26,12 @@ apply plugin: 'signing'
apply plugin: 'com.neenbedankt.android-apt' apply plugin: 'com.neenbedankt.android-apt'
android { android {
compileSdkVersion 23 compileSdkVersion versions.sdk.compile
buildToolsVersion '23.0.3' buildToolsVersion versions.sdk.buildTools
defaultConfig { defaultConfig {
minSdkVersion 9 applicationId "org.solovyev.android.calculator"
targetSdkVersion 23 minSdkVersion versions.sdk.min
targetSdkVersion versions.sdk.target
versionCode 153 versionCode 153
versionName '2.2.3' versionName '2.2.3'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@ -61,9 +62,9 @@ android {
dependencies { dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs') compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.4.0' compile "com.android.support:support-v4:${versions.supportLib}"
compile 'com.android.support:appcompat-v7:23.4.0' compile "com.android.support:appcompat-v7:${versions.supportLib}"
compile 'com.android.support:design:23.4.0' compile "com.android.support:design:${versions.supportLib}"
compile('ch.acra:acra:4.7.0') { compile('ch.acra:acra:4.7.0') {
exclude group: 'org.json' exclude group: 'org.json'
} }
@ -71,6 +72,7 @@ dependencies {
compile ':square-otto:1.3.9-SNAPSHOT' compile ':square-otto:1.3.9-SNAPSHOT'
apt ':square-otto-compiler:1.3.9-SNAPSHOT' apt ':square-otto-compiler:1.3.9-SNAPSHOT'
apt 'com.squareup:javapoet:1.5.1' apt 'com.squareup:javapoet:1.5.1'
compile project(':dragbutton')
compile(project(':jscl')) { compile(project(':jscl')) {
exclude(module: 'xercesImpl') exclude(module: 'xercesImpl')
} }

View File

@ -65,4 +65,6 @@
<color name="pink_900">#880e4f</color> <color name="pink_900">#880e4f</color>
<color name="yellow_100">#ffff8d</color> <color name="yellow_100">#ffff8d</color>
<color name="drag_text_inverse">@color/cpp_text_inverse</color>
<color name="drag_button_text">@color/cpp_button_text</color>
</resources> </resources>

View File

@ -7,9 +7,6 @@
<dimen name="cpp_widget_margin">6dp</dimen> <dimen name="cpp_widget_margin">6dp</dimen>
<dimen name="min_expanded_height_lock_screen">300dp</dimen> <dimen name="min_expanded_height_lock_screen">300dp</dimen>
<dimen name="cpp_button_padding">1px</dimen> <dimen name="cpp_button_padding">1px</dimen>
<dimen name="cpp_direction_text_default_padding">2dp</dimen>
<dimen name="cpp_direction_text_min_size">9dp</dimen>
<item name="cpp_direction_text_scale" format="float" type="dimen">0.35</item>
<dimen name="cpp_button_corner">1dp</dimen> <dimen name="cpp_button_corner">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding_updown">4dp</dimen> <dimen name="cpp_keyboard_button_direction_text_padding_updown">4dp</dimen>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="drag_min_distance">15dp</dimen>
</resources>

View File

@ -35,7 +35,7 @@
<item name="android:textColor">@color/cpp_button_text</item> <item name="android:textColor">@color/cpp_button_text</item>
<item name="android:scaleType">centerInside</item> <item name="android:scaleType">centerInside</item>
<item name="directionTextColor">@color/cpp_button_text</item> <item name="directionTextColor">@color/cpp_button_text</item>
<item name="directionTextScale">@dimen/cpp_direction_text_scale</item> <item name="directionTextScale">@dimen/drag_direction_text_scale</item>
<item name="directionTextPaddingUp">@dimen/cpp_keyboard_button_direction_text_padding_updown</item> <item name="directionTextPaddingUp">@dimen/cpp_keyboard_button_direction_text_padding_updown</item>
<item name="directionTextPaddingDown">@dimen/cpp_keyboard_button_direction_text_padding_updown</item> <item name="directionTextPaddingDown">@dimen/cpp_keyboard_button_direction_text_padding_updown</item>
<item name="directionTextPaddingRight">@dimen/cpp_keyboard_button_direction_text_padding_updown</item> <item name="directionTextPaddingRight">@dimen/cpp_keyboard_button_direction_text_padding_updown</item>

View File

@ -6,6 +6,11 @@ buildscript {
classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 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 { allprojects {

1
dragbutton/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

24
dragbutton/build.gradle Normal file
View File

@ -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}"
}

17
dragbutton/proguard-rules.pro vendored Normal file
View File

@ -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 *;
#}

View File

@ -0,0 +1,5 @@
<manifest package="org.solovyev.android.views.dragbutton">
<application />
</manifest>

View File

@ -8,8 +8,6 @@ import android.support.annotation.Nullable;
import android.text.TextPaint; import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import javax.annotation.Nonnull;
import static android.graphics.Color.BLACK; import static android.graphics.Color.BLACK;
import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static android.util.TypedValue.applyDimension; import static android.util.TypedValue.applyDimension;
@ -72,7 +70,7 @@ public class DirectionDragButton extends DragButton implements DirectionDragView
} }
@Override @Override
@Nonnull @NonNull
public DirectionTextView.Text getText(@NonNull DragDirection direction) { public DirectionTextView.Text getText(@NonNull DragDirection direction) {
return textView.getText(direction); return textView.getText(direction);
} }

View File

@ -9,8 +9,6 @@ import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.TextView; import android.widget.TextView;
import javax.annotation.Nonnull;
public class DirectionDragImageButton extends DragImageButton implements DirectionDragView { public class DirectionDragImageButton extends DragImageButton implements DirectionDragView {
private final DirectionTextView textView = new DirectionTextView(); private final DirectionTextView textView = new DirectionTextView();
private final TextPaint baseTextPaint = new TextPaint(); private final TextPaint baseTextPaint = new TextPaint();
@ -47,12 +45,12 @@ public class DirectionDragImageButton extends DragImageButton implements Directi
textView.draw(canvas); textView.draw(canvas);
} }
@Nonnull @NonNull
public DirectionTextView.Text getText(@NonNull DragDirection direction) { public DirectionTextView.Text getText(@NonNull DragDirection direction) {
return textView.getText(direction); return textView.getText(direction);
} }
public void setTypeface(@Nonnull Typeface newTypeface) { public void setTypeface(@NonNull Typeface newTypeface) {
final Typeface oldTypeface = baseTextPaint.getTypeface(); final Typeface oldTypeface = baseTextPaint.getTypeface();
if (oldTypeface == newTypeface) { if (oldTypeface == newTypeface) {
return; return;

View File

@ -7,12 +7,8 @@ import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import org.solovyev.android.calculator.R;
import static java.lang.Math.toDegrees; import static java.lang.Math.toDegrees;
import static org.solovyev.android.views.dragbutton.Drag.distance; import static org.solovyev.android.views.dragbutton.Drag.*;
import static org.solovyev.android.views.dragbutton.Drag.getAngle;
import static org.solovyev.android.views.dragbutton.Drag.sum;
public abstract class DirectionDragListener implements DragListener { public abstract class DirectionDragListener implements DragListener {

View File

@ -2,9 +2,7 @@ package org.solovyev.android.views.dragbutton;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import javax.annotation.Nonnull;
public interface DirectionDragView extends DragView { public interface DirectionDragView extends DragView {
@Nonnull @NonNull
DirectionTextView.Text getText(@NonNull DragDirection direction); DirectionTextView.Text getText(@NonNull DragDirection direction);
} }

View File

@ -16,9 +16,6 @@ import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.TextView; 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.EnumMap;
import java.util.Map; import java.util.Map;
@ -50,11 +47,10 @@ public class DirectionTextView {
} }
public void init(@NonNull View view, @Nullable AttributeSet attrs, @NonNull TextPaint baseTextPaint) { public void init(@NonNull View view, @Nullable AttributeSet attrs, @NonNull TextPaint baseTextPaint) {
Check.isTrue(texts.isEmpty());
final Context context = view.getContext(); final Context context = view.getContext();
final int defColor = baseTextPaint.getColor(); final int defColor = baseTextPaint.getColor();
final int defPadding = context.getResources().getDimensionPixelSize(R.dimen.cpp_direction_text_default_padding); final int defPadding = context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_default_padding);
final float minTextSize = context.getResources().getDimensionPixelSize(R.dimen.cpp_direction_text_min_size); final float minTextSize = context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_min_size);
if (attrs == null) { 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) { public void init(@NonNull TextPaint base, @Nullable TypedArray array, float defScale, int defColor, float defAlpha, int defPadding) {
if (array != null) { if (array != null) {
if (array.hasValue(direction.textAttr)) { if (array.hasValue(direction.textAttr)) {
value = Strings.nullToEmpty(array.getString(direction.textAttr)); value = nullToEmpty(array.getString(direction.textAttr));
} }
padding = array.getDimensionPixelSize(direction.paddingAttr, defPadding); padding = array.getDimensionPixelSize(direction.paddingAttr, defPadding);
scale = array.getFloat(direction.scaleAttr, defScale); scale = array.getFloat(direction.scaleAttr, defScale);
@ -141,8 +137,13 @@ public class DirectionTextView {
initPaint(base); initPaint(base);
} }
@NonNull
private String nullToEmpty(@Nullable String s) {
return s == null ? "" : s;
}
private int makeContrastColor(int color) { 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); return ContextCompat.getColor(view.getContext(), colorRes);
} }
@ -218,7 +219,6 @@ public class DirectionTextView {
} }
private void invalidate(boolean remeasure) { private void invalidate(boolean remeasure) {
Check.isNotNull(view);
view.invalidate(); view.invalidate();
if (remeasure) { if (remeasure) {
offset.set(0, 0); offset.set(0, 0);

View File

@ -2,8 +2,6 @@ package org.solovyev.android.views.dragbutton;
import android.support.annotation.StyleableRes; import android.support.annotation.StyleableRes;
import org.solovyev.android.calculator.R;
public enum DragDirection { public enum DragDirection {
up(180f - 45f, 180f - 0f, R.styleable.DirectionText_directionTextUp, R.styleable.DirectionText_directionTextScaleUp, R.styleable.DirectionText_directionTextPaddingUp), up(180f - 45f, 180f - 0f, R.styleable.DirectionText_directionTextUp, R.styleable.DirectionText_directionTextScaleUp, R.styleable.DirectionText_directionTextPaddingUp),

View File

@ -6,8 +6,6 @@ import android.support.annotation.Nullable;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; 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_GLOBAL_SETTING;
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING; import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING;
import static android.view.HapticFeedbackConstants.KEYBOARD_TAP; import static android.view.HapticFeedbackConstants.KEYBOARD_TAP;
@ -67,7 +65,6 @@ public class DragGestureDetector {
} }
private void startTracking(@NonNull MotionEvent event) { private void startTracking(@NonNull MotionEvent event) {
Check.isNull(start);
start = new PointF(event.getX(), event.getY()); start = new PointF(event.getX(), event.getY());
} }

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="drag_text_inverse">#424242</color>
<color name="drag_button_text">#ffffffff</color>
</resources>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="drag_min_distance">15dp</dimen>
<dimen name="drag_direction_text_default_padding">2dp</dimen>
<dimen name="drag_direction_text_min_size">9dp</dimen>
<item name="drag_direction_text_scale" format="float" type="dimen">0.35</item>
</resources>

View File

@ -1 +1 @@
include ':app', ':jscl', ':translations' include ':app', ':jscl', ':translations', ':dragbutton'