From 4f12ee7fcfe2b875fa02b43099642828c53934b3 Mon Sep 17 00:00:00 2001 From: Beppi Menozzi Date: Mon, 10 Jul 2017 00:32:20 +0200 Subject: [PATCH] "Auto" --- .idea/vcs.xml | 6 ++ knoblibrary/build.gradle | 4 +- .../main/java/it/beppi/knoblibrary/Knob.java | 84 +++++++++++++++++-- knoblibrary/src/main/res/values/attrs.xml | 8 ++ .../src/main/res/layout/activity_sample.xml | 5 +- 5 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/knoblibrary/build.gradle b/knoblibrary/build.gradle index 1990739..91c997f 100644 --- a/knoblibrary/build.gradle +++ b/knoblibrary/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 11 targetSdkVersion 25 - versionCode 11 - versionName "1.7.0" + versionCode 12 + versionName "1.8.0" } buildTypes { release { diff --git a/knoblibrary/src/main/java/it/beppi/knoblibrary/Knob.java b/knoblibrary/src/main/java/it/beppi/knoblibrary/Knob.java index e654959..877012e 100644 --- a/knoblibrary/src/main/java/it/beppi/knoblibrary/Knob.java +++ b/knoblibrary/src/main/java/it/beppi/knoblibrary/Knob.java @@ -9,8 +9,11 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.RequiresApi; +import android.support.v7.widget.PopupMenu; import android.util.AttributeSet; import android.util.TypedValue; +import android.view.Menu; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewParent; @@ -36,6 +39,13 @@ public class Knob extends View { public static final int SWIPEDIRECTION_HORIZONTALVERTICAL = 3; public static final int SWIPEDIRECTION_CIRCULAR = 4; + public static final int ONCLICK_NONE = 0; + public static final int ONCLICK_NEXT = 1; + public static final int ONCLICK_PREV = 2; + public static final int ONCLICK_RESET = 3; + public static final int ONCLICK_MENU = 4; + + // constructors public Knob(Context context) { super(context); @@ -318,6 +328,7 @@ BalloonPopup.BalloonAnimation getBalloonAnimation() { private int balloonValuesAnimation = 0; private CharSequence[] balloonValuesArray = null; private boolean balloonValuesSlightlyTransparent = true; + private int clickBehaviour = 1; // next // initialize @@ -416,6 +427,8 @@ void loadAttributes(AttributeSet attrs) { balloonValuesArray = typedArray.getTextArray(R.styleable.Knob_kBalloonValuesArray); balloonValuesSlightlyTransparent = typedArray.getBoolean(R.styleable.Knob_kBalloonValuesSlightlyTransparent, balloonValuesSlightlyTransparent); + clickBehaviour = clickAttrToInt(typedArray.getString(R.styleable.Knob_kClickBehaviour)); + enabled = typedArray.getBoolean(R.styleable.Knob_kEnabled, enabled); typedArray.recycle(); @@ -429,6 +442,15 @@ int swipeAttrToInt(String s) { else if (s.equals("4")) return 4; // default - circular else return 4; } + int clickAttrToInt(String s) { + if (s == null) return 1; + if (s.equals("0")) return 0; + else if (s.equals("1")) return 1; // default - next + else if (s.equals("2")) return 2; // prev + else if (s.equals("3")) return 3; // reset + else if (s.equals("4")) return 4; // menu + else return 1; + } int balloonAnimationAttrToInt(String s) { if (s == null) return 0; if (s.equals("0")) return 0; // pop @@ -444,13 +466,22 @@ private void disallowParentToHandleTouchEvents() { } } - void initListeners() { + void clickMe(View view) { + switch (clickBehaviour) { + case 0: break; + case 1: toggle(animation); break; + case 2: inverseToggle(animation); break; + case 3: revertToDefault(animation); break; + case 4: createPopupMenu(view); break; + } + } + void initListeners() { this.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (!enabled) return; - toggle(animation); + clickMe(view); } }); @@ -482,7 +513,7 @@ else if (swipeY - y > swipeSensibilityPixels) { } } else if (action == MotionEvent.ACTION_UP) { - if (!swipeing) toggle(animation); // click + if (!swipeing) clickMe(view); // click return true; } return false; @@ -509,7 +540,7 @@ else if (swipeX - x > swipeSensibilityPixels) { } } else if (action == MotionEvent.ACTION_UP) { - if (!swipeing) toggle(animation); // click + if (!swipeing) clickMe(view); // click return true; } return false; @@ -540,7 +571,7 @@ else if (swipeX - x > swipeSensibilityPixels || y - swipeY > swipeSensibilityPix } } else if (action == MotionEvent.ACTION_UP) { - if (!swipeing) toggle(animation); // click + if (!swipeing) clickMe(view); // click return true; } return false; @@ -559,7 +590,7 @@ else if (action == MotionEvent.ACTION_MOVE) { return true; } else if (action == MotionEvent.ACTION_UP) { - if (!swipeing) toggle(animation); // click + if (!swipeing) clickMe(view); // click return true; } return false; @@ -569,6 +600,7 @@ else if (action == MotionEvent.ACTION_UP) { return false; } }); + spring.addListener(new SimpleSpringListener(){ @Override public void onSpringUpdate(Spring spring) { @@ -577,6 +609,28 @@ public void onSpringUpdate(Spring spring) { }}); } + void createPopupMenu(View view) { + PopupMenu mPopupMenu = new PopupMenu(getContext(), view); + if (balloonValuesArray == null) + for (int w=0; w + + + + + + + + diff --git a/knobsample/src/main/res/layout/activity_sample.xml b/knobsample/src/main/res/layout/activity_sample.xml index 6c7b5af..bf984c6 100644 --- a/knobsample/src/main/res/layout/activity_sample.xml +++ b/knobsample/src/main/res/layout/activity_sample.xml @@ -35,7 +35,8 @@ + android:layout_height="96dp" + />