1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*
********************************************************************************
* Copyright (c) 2012 Samsung Electronics, Inc.
* All rights reserved.
*
* This software is a confidential and proprietary information of Samsung
* Electronics, Inc. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with the terms
* of the license agreement you entered into with Samsung Electronics.
********************************************************************************
*/
package us.minak;
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;
import android.widget.Button;
import android.widget.RelativeLayout;
/**
* Represents the container for the drawing space and the two side panels.
*/
public class IMEView extends RelativeLayout {
private StringReciever mOnCharacterEnteredListener;
private final Queue<Character> mSymbolsQueue = new LinkedList<Character>();
private float x;
private float y;
private boolean ongoingGesture = false;
public boolean setTouchLocation(float x, float y) {
if (!ongoingGesture) {
this.x = x;
this.y = y;
return true;
}
return false;
}
public void setState(boolean state) {
ongoingGesture = state;
}
public boolean getState() {
return ongoingGesture;
}
public IMEView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
IMEGestureOverlayView drawingSpaceView = (IMEGestureOverlayView) findViewById(R.id.drawing_space);
drawingSpaceView.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) {
mOnCharacterEnteredListener = onCharacterEnteredListener;
}
public Queue<Character> getSymbolsQueue() {
return mSymbolsQueue;
}
private final OnTouchListener mOnTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return setTouchLocation(event.getX(), event.getY());
}
};
/**
* Passes the given character to the input service.
*
* @param character
* 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.ON) {
//TODO: apply the Meta-key here
;
}
}
mOnCharacterEnteredListener.putString(character);
}
}
|