From 5a7bbdeae6bde0c3ae202de7bac8a797fc51a68c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 6 May 2014 23:26:18 -0400 Subject: Draw circles gooder --- src/us/minak/IMEGestureOverlayView.java | 12 +++--- src/us/minak/IMEModifier.java | 24 ++++++++++++ src/us/minak/IMEModifierCircle.java | 37 ++++++++++++++++++ src/us/minak/IMEModifiers.java | 69 +++++++++++++++++++++++++++++++++ src/us/minak/IMEView.java | 12 ++---- src/us/minak/MetaCircle.java | 37 ------------------ src/us/minak/MetaExpression.java | 24 ------------ 7 files changed, 139 insertions(+), 76 deletions(-) create mode 100644 src/us/minak/IMEModifier.java create mode 100644 src/us/minak/IMEModifierCircle.java create mode 100644 src/us/minak/IMEModifiers.java delete mode 100644 src/us/minak/MetaCircle.java delete mode 100644 src/us/minak/MetaExpression.java diff --git a/src/us/minak/IMEGestureOverlayView.java b/src/us/minak/IMEGestureOverlayView.java index 7e8867d..e27b70a 100644 --- a/src/us/minak/IMEGestureOverlayView.java +++ b/src/us/minak/IMEGestureOverlayView.java @@ -22,7 +22,6 @@ import android.gesture.GestureOverlayView; import android.gesture.GestureOverlayView.OnGesturePerformedListener; import android.gesture.Prediction; import android.graphics.Canvas; -import android.graphics.Paint; import android.util.AttributeSet; /** @@ -32,8 +31,8 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu private static final double SCORE_TRESHOLD = 3.0; private final GestureLibrary mGestureLibrary; private StringReciever mOnGestureRecognizedListener; - public List circles = new LinkedList(); - private final Paint mPaint = new Paint(); + public List circles = new LinkedList(); + private final IMEModifiers modifiers = new IMEModifiers(); public IMEGestureOverlayView(Context context, AttributeSet attrs) { super(context, attrs); @@ -62,10 +61,9 @@ public class IMEGestureOverlayView extends GestureOverlayView implements OnGestu } } + @Override public void onDraw(Canvas canvas) { - for (MetaCircle circle : circles) { - mPaint.setColor(circle.color); - canvas.drawCircle(circle.x, circle.y, circle.radius, mPaint); - } + float d = Math.min(canvas.getWidth(), canvas.getHeight()); + modifiers.draw(canvas, d/2, d/2, d*.4F); } } diff --git a/src/us/minak/IMEModifier.java b/src/us/minak/IMEModifier.java new file mode 100644 index 0000000..6b5ee67 --- /dev/null +++ b/src/us/minak/IMEModifier.java @@ -0,0 +1,24 @@ +package us.minak; + +public class IMEModifier { + public static enum State { + ON, OFF, LOCK + } + + public State state; + private String value; + + public String getValue() { + //however we want to do return this + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + IMEModifier(String value) { + this.value = value; + this.state = State.OFF; + } +} diff --git a/src/us/minak/IMEModifierCircle.java b/src/us/minak/IMEModifierCircle.java new file mode 100644 index 0000000..246036f --- /dev/null +++ b/src/us/minak/IMEModifierCircle.java @@ -0,0 +1,37 @@ +package us.minak; + +/* + * Not sure if this should be drawable or what. + * + */ +public class IMEModifierCircle { + private IMEModifier metaExpression; + public float x; + public float y; + public float radius; + public int color; + public boolean expanded; + public int expansion; //the level of expansion (if multiple circles are expanded, this decides precidence) + + IMEModifierCircle(float x, float y, float radius, int color, IMEModifier metaExpr) { + this.setMetaExpression(metaExpr); + this.x = x; + this.y = y; + this.radius = radius; + this.color = color; + this.expanded = false; + this.expansion = 0; + } + + public boolean containsPoint(float x, float y) { + return Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2) < Math.pow(this.radius, 2) ? true : false; + } + + public IMEModifier getMetaExpression() { + return metaExpression; + } + + public void setMetaExpression(IMEModifier metaExpr) { + this.metaExpression = metaExpr; + } +} diff --git a/src/us/minak/IMEModifiers.java b/src/us/minak/IMEModifiers.java new file mode 100644 index 0000000..ef49f17 --- /dev/null +++ b/src/us/minak/IMEModifiers.java @@ -0,0 +1,69 @@ +package us.minak; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import java.util.List; +import java.util.ArrayList; + +public class IMEModifiers { + private final String[] modifiers = { "shift", "ctrl", "alt" }; + private final Paint colorPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + private final Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + + private float cx = 0; + private float cy = 0; + private double innerR = 0; + private double outerR = 0; + private double radEach = 0; + + + public IMEModifiers() { + textPaint.setColor(Color.BLACK); + } + + public void draw(Canvas canvas, float cx, float cy, float r) { + this.cx = cx; + this.cy = cy; + innerR = r*(1.0/3.0); + outerR = (float)(r*(2.0/3.0)); + radEach = (Math.PI*2.0)/modifiers.length; + + double rad = 0; + float[] hsv = {0F, 1F, .75F}; + + for (int i = 0; i < modifiers.length; i++) { + rad = radEach * i; + hsv[0] = (float)Math.toDegrees(rad); + colorPaint.setColor(Color.HSVToColor(0x80, hsv)); + + canvas.drawCircle( + (float)(cx+innerR*Math.cos(rad)), + (float)(cy+innerR*Math.sin(rad)), + (float)outerR, + colorPaint); + canvas.drawText( + modifiers[i], + (float)(cx+innerR*Math.cos(rad)), + (float)(cy+innerR*Math.sin(rad)), + textPaint); + } + } + + public List getModifiersAtPoint(float x, float y) { + ArrayList ret = new ArrayList(); + + double mx; + double my; + double rad = 0; + for (int i = 0; i < modifiers.length; i++) { + rad = radEach * i; + mx = cx+innerR*Math.cos(rad); + my = cy+innerR*Math.sin(rad); + + if (Math.sqrt(Math.pow(mx-x,2)+Math.pow(my-y, 2)) > outerR) + ret.add(modifiers[i]); + } + return ret; + } +} diff --git a/src/us/minak/IMEView.java b/src/us/minak/IMEView.java index 318abd0..a992011 100644 --- a/src/us/minak/IMEView.java +++ b/src/us/minak/IMEView.java @@ -16,7 +16,6 @@ import java.util.LinkedList; import java.util.Queue; import android.content.Context; -import android.graphics.Color; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; @@ -56,18 +55,13 @@ public class IMEView extends RelativeLayout { @Override protected void onFinishInflate() { - IMEGestureOverlayView drawingSpaceView = (IMEGestureOverlayView) findViewById(R.id.drawing_space); - drawingSpaceView.setOnGestureRecognizedListener(new StringReciever() { + IMEGestureOverlayView gestureOverlayView = (IMEGestureOverlayView) findViewById(R.id.drawing_space); + gestureOverlayView.setOnGestureRecognizedListener(new StringReciever() { @Override public void putString(String character) { enterCharacter(character); } }); - - //dynamic MetaCircle adding stuff here. replace null with Shift or Ctrl or Meta or Alt or Hyper or whatever. - drawingSpaceView.circles.add(new MetaCircle((float)50.0, (float)50.0, (float)20.0, Color.RED, new MetaExpression(null))); - drawingSpaceView.circles.add(new MetaCircle((float)70.0, (float)70.0, (float)20.0, Color.RED, new MetaExpression(null))); - drawingSpaceView.circles.add(new MetaCircle((float)50.0, (float)30.0, (float)20.0, Color.RED, new MetaExpression(null))); } public void setOnCharacterEnteredListener(StringReciever onCharacterEnteredListener) { @@ -92,6 +86,7 @@ public class IMEView extends RelativeLayout { * The character to enter */ private void enterCharacter(String character) { + /* for (MetaCircle circle : ((IMEGestureOverlayView) findViewById(R.id.drawing_space)).circles) { //go through circles and check if they are applicable if (circle.containsPoint(this.x, this.y) && circle.getMetaExpression().state != MetaExpression.State.OFF) { @@ -99,6 +94,7 @@ public class IMEView extends RelativeLayout { ; } } + */ mOnCharacterEnteredListener.putString(character); } } diff --git a/src/us/minak/MetaCircle.java b/src/us/minak/MetaCircle.java deleted file mode 100644 index 9139dc9..0000000 --- a/src/us/minak/MetaCircle.java +++ /dev/null @@ -1,37 +0,0 @@ -package us.minak; - -/* - * Not sure if this should be drawable or what. - * - */ -public class MetaCircle { - private MetaExpression metaExpression; - public float x; - public float y; - public float radius; - public int color; - public boolean expanded; - public int expansion; //the level of expansion (if multiple circles are expanded, this decides precidence) - - MetaCircle(float x, float y, float radius, int color, MetaExpression metaExpr) { - this.setMetaExpression(metaExpr); - this.x = x; - this.y = y; - this.radius = radius; - this.color = color; - this.expanded = false; - this.expansion = 0; - } - - public boolean containsPoint(float x, float y) { - return Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2) < Math.pow(this.radius, 2) ? true : false; - } - - public MetaExpression getMetaExpression() { - return metaExpression; - } - - public void setMetaExpression(MetaExpression metaExpr) { - this.metaExpression = metaExpr; - } -} diff --git a/src/us/minak/MetaExpression.java b/src/us/minak/MetaExpression.java deleted file mode 100644 index f9c6cbe..0000000 --- a/src/us/minak/MetaExpression.java +++ /dev/null @@ -1,24 +0,0 @@ -package us.minak; - -public class MetaExpression { - public static enum State { - ON, OFF, LOCK - } - - public State state; - private String value; - - public String getValue() { - //however we want to do return this - return this.value; - } - - public void setValue(String value) { - this.value = value; - } - - MetaExpression(String value) { - this.value = value; - this.state = State.OFF; - } -} -- cgit v1.2.3-54-g00ecf