Revision cab1d9c1
Added by Leszek Koltunski over 3 years ago
| build.gradle | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
// NOTE: Do not place your application dependencies here; they belong |
| 11 | 11 |
// in the individual module build.gradle files |
| 12 |
|
|
| 13 |
classpath 'com.google.gms:google-services:4.3.13' |
|
| 14 |
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1' |
|
| 12 | 15 |
} |
| 13 | 16 |
} |
| 14 | 17 |
|
| distorted-sokoban/build.gradle | ||
|---|---|---|
| 1 | 1 |
apply plugin: 'com.android.application' |
| 2 |
apply plugin: 'com.google.gms.google-services' |
|
| 3 |
apply plugin: 'com.google.firebase.crashlytics' |
|
| 2 | 4 |
|
| 3 | 5 |
android {
|
| 4 | 6 |
compileSdkVersion 31 |
| ... | ... | |
| 6 | 8 |
|
| 7 | 9 |
defaultConfig {
|
| 8 | 10 |
applicationId "org.distorted.sokoban" |
| 9 |
minSdkVersion 7
|
|
| 11 |
minSdkVersion 21
|
|
| 10 | 12 |
targetSdkVersion 31 |
| 11 | 13 |
} |
| 12 | 14 |
|
| ... | ... | |
| 17 | 19 |
} |
| 18 | 20 |
} |
| 19 | 21 |
} |
| 22 |
|
|
| 23 |
dependencies {
|
|
| 24 |
implementation platform('com.google.firebase:firebase-bom:30.2.0')
|
|
| 25 |
implementation 'com.google.firebase:firebase-messaging' |
|
| 26 |
implementation 'com.google.firebase:firebase-analytics' |
|
| 27 |
implementation 'com.google.firebase:firebase-crashlytics' |
|
| 28 |
implementation 'com.google.firebase:firebase-inappmessaging-display' |
|
| 29 |
implementation "androidx.work:work-runtime:2.7.1" |
|
| 30 |
} |
|
| 31 |
|
|
| distorted-sokoban/src/main/AndroidManifest.xml | ||
|---|---|---|
| 10 | 10 |
android:anyDensity="true"/> |
| 11 | 11 |
|
| 12 | 12 |
<uses-permission android:name="android.permission.INTERNET"/> |
| 13 |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
|
| 14 |
|
|
| 13 | 15 |
<uses-feature android:name="android.hardware.touchscreen"/> |
| 14 | 16 |
|
| 15 | 17 |
<application android:icon="@drawable/icon" android:label="@string/app_name"> |
| distorted-sokoban/src/main/java/org/distorted/keyboard/TextFieldArea.java | ||
|---|---|---|
| 1 |
package org.distorted.sokoban; |
|
| 2 |
|
|
| 3 |
import android.graphics.Canvas; |
|
| 4 |
import android.graphics.Paint; |
|
| 5 |
import android.graphics.Paint.Style; |
|
| 6 |
|
|
| 7 |
/////////////////////////////////////////////////////////////////// |
|
| 8 |
|
|
| 9 |
public class TextFieldArea |
|
| 10 |
{
|
|
| 11 |
//private static final String TAG_TEXT = "RRText"; |
|
| 12 |
|
|
| 13 |
private StringBuffer text; |
|
| 14 |
|
|
| 15 |
private int textFieldBkgColor = 0xFFEEEEEE; |
|
| 16 |
private int textFieldBorderColor = 0xFF000000; |
|
| 17 |
private int textFieldFontColor = 0xFF000000; |
|
| 18 |
|
|
| 19 |
private int maxSize = -1; |
|
| 20 |
private int strLen; |
|
| 21 |
private Paint mPaint; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
public TextFieldArea() |
|
| 26 |
{
|
|
| 27 |
text = new StringBuffer(); |
|
| 28 |
strLen = 0; |
|
| 29 |
mPaint = new Paint(); |
|
| 30 |
mPaint.setAntiAlias(true); |
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public void deleteLastChar() |
|
| 36 |
{
|
|
| 37 |
if (strLen > 0) |
|
| 38 |
{
|
|
| 39 |
text.deleteCharAt(strLen-1); |
|
| 40 |
strLen--; |
|
| 41 |
} |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
public void insertNewChar(char aChar) |
|
| 47 |
{
|
|
| 48 |
if ( ((maxSize > 0) && (text.length() < maxSize)) || (maxSize < 0)) |
|
| 49 |
{
|
|
| 50 |
if (aChar != 0) |
|
| 51 |
{
|
|
| 52 |
text.insert(strLen, aChar); |
|
| 53 |
strLen++; |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
public String getText() |
|
| 61 |
{
|
|
| 62 |
return text.toString(); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
public void setText(String newText) |
|
| 68 |
{
|
|
| 69 |
text = null; |
|
| 70 |
text = new StringBuffer(newText); |
|
| 71 |
strLen = newText.length(); |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////// |
|
| 75 |
|
|
| 76 |
public void clearTextField() |
|
| 77 |
{
|
|
| 78 |
text = null; |
|
| 79 |
text = new StringBuffer(); |
|
| 80 |
strLen = 0; |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////// |
|
| 84 |
|
|
| 85 |
public void paint( Canvas canvas, int left, int top, int right, int bottom) |
|
| 86 |
{
|
|
| 87 |
int fontH = (int)((bottom-top)*0.7); |
|
| 88 |
|
|
| 89 |
mPaint.setColor(textFieldBkgColor); |
|
| 90 |
mPaint.setStyle(Style.FILL); |
|
| 91 |
canvas.drawRect(left, top, right, bottom, mPaint); |
|
| 92 |
mPaint.setColor(textFieldBorderColor); |
|
| 93 |
mPaint.setStyle(Style.STROKE); |
|
| 94 |
canvas.drawRect(left, top, right, bottom, mPaint); |
|
| 95 |
mPaint.setColor(textFieldFontColor); |
|
| 96 |
mPaint.setTextSize(fontH); |
|
| 97 |
|
|
| 98 |
String t = text.toString(); |
|
| 99 |
|
|
| 100 |
while( mPaint.measureText(t) > right-left-(bottom-top)/2 ) |
|
| 101 |
{
|
|
| 102 |
mPaint.setTextSize(--fontH); |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
canvas.drawText( t, left+(bottom-top)/4, (bottom+top+fontH)/2-fontH/8, mPaint); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
|
|
| 110 |
public void setTextFieldBkgColor(int textFieldBkgColor) |
|
| 111 |
{
|
|
| 112 |
this.textFieldBkgColor = textFieldBkgColor; |
|
| 113 |
} |
|
| 114 |
|
|
| 115 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 116 |
|
|
| 117 |
public void setTextFieldBorderColor(int textFieldBorderColor) |
|
| 118 |
{
|
|
| 119 |
this.textFieldBorderColor = textFieldBorderColor; |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 123 |
|
|
| 124 |
public void setTextFieldFontColor(int textFieldFontColor) |
|
| 125 |
{
|
|
| 126 |
this.textFieldFontColor = textFieldFontColor; |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
public int getMaxSize() |
|
| 132 |
{
|
|
| 133 |
return maxSize; |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 137 |
|
|
| 138 |
public void setMaxSize(int maxSize) |
|
| 139 |
{
|
|
| 140 |
this.maxSize = maxSize; |
|
| 141 |
} |
|
| 142 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
// end of TextFieldArea |
|
| 144 |
} |
|
| distorted-sokoban/src/main/java/org/distorted/keyboard/TouchKeyboard.java | ||
|---|---|---|
| 1 |
package org.distorted.sokoban; |
|
| 2 |
|
|
| 3 |
import android.content.Context; |
|
| 4 |
import android.content.res.Resources; |
|
| 5 |
import android.graphics.Bitmap; |
|
| 6 |
import android.graphics.BitmapFactory; |
|
| 7 |
import android.graphics.Canvas; |
|
| 8 |
import android.graphics.Paint; |
|
| 9 |
import android.graphics.Paint.Align; |
|
| 10 |
import android.graphics.Paint.Style; |
|
| 11 |
import android.graphics.drawable.NinePatchDrawable; |
|
| 12 |
|
|
| 13 |
import android.view.KeyEvent; |
|
| 14 |
import android.view.MotionEvent; |
|
| 15 |
import android.view.View; |
|
| 16 |
|
|
| 17 |
//import android.util.Log; |
|
| 18 |
|
|
| 19 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
public class TouchKeyboard extends View |
|
| 22 |
{
|
|
| 23 |
//private static final String TAG_KEYBOARD = "RubikKeyboard"; |
|
| 24 |
|
|
| 25 |
private static final int MARGIN = 2; |
|
| 26 |
private static final int WMARGIN = 8; |
|
| 27 |
private static final int BUTTON_NONE = -4; |
|
| 28 |
private static final int BUTTON_OK = -3; |
|
| 29 |
private static final int BUTTON_BKSP = -2; |
|
| 30 |
private static final int BUTTON_CAPS = -1; |
|
| 31 |
|
|
| 32 |
private int currPressed; |
|
| 33 |
|
|
| 34 |
private TextFieldArea textField; |
|
| 35 |
private Paint mPaint; |
|
| 36 |
private NinePatchDrawable keyBlue, keyRed, keyWhite; |
|
| 37 |
private Bitmap ok, bksp, caps; |
|
| 38 |
|
|
| 39 |
private int bmpSize; |
|
| 40 |
|
|
| 41 |
char[][] lowerCaseL = |
|
| 42 |
{ {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'},
|
|
| 43 |
{'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r'},
|
|
| 44 |
{'s', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0'},
|
|
| 45 |
{'1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
|
| 46 |
}; |
|
| 47 |
|
|
| 48 |
char[][] upperCaseL = |
|
| 49 |
{ {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'},
|
|
| 50 |
{'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R'},
|
|
| 51 |
{'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0'},
|
|
| 52 |
{'1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
|
| 53 |
}; |
|
| 54 |
|
|
| 55 |
char[][] lowerCaseP = |
|
| 56 |
{ {'a', 'b', 'c', 'd', 'e', 'f'},
|
|
| 57 |
{'g', 'h', 'i', 'j', 'k', 'l'},
|
|
| 58 |
{'m', 'n', 'o', 'p', 'q', 'r'},
|
|
| 59 |
{'s', 't', 'u', 'v', 'w', 'x'},
|
|
| 60 |
{'y', 'z', '0', '1', '2', '3'},
|
|
| 61 |
{'4', '5', '6', '7', '8', '9'}
|
|
| 62 |
}; |
|
| 63 |
|
|
| 64 |
char[][] upperCaseP = |
|
| 65 |
{ {'A', 'B', 'C', 'D', 'E', 'F'},
|
|
| 66 |
{'G', 'H', 'I', 'J', 'K', 'L'},
|
|
| 67 |
{'M', 'N', 'O', 'P', 'Q', 'R'},
|
|
| 68 |
{'S', 'T', 'U', 'V', 'W', 'X'},
|
|
| 69 |
{'Y', 'Z', '0', '1', '2', '3'},
|
|
| 70 |
{'4', '5', '6', '7', '8', '9'}
|
|
| 71 |
}; |
|
| 72 |
|
|
| 73 |
private int width, height; |
|
| 74 |
|
|
| 75 |
private int textFieldWidth; |
|
| 76 |
private int textFieldHeight; |
|
| 77 |
private int textTopLeftX; |
|
| 78 |
private int textTopLeftY; |
|
| 79 |
private int keyWidth, keyHeight; |
|
| 80 |
private int sKeyWidth, sKeyHeight; |
|
| 81 |
|
|
| 82 |
private VirtualKeyboardListener invoker; |
|
| 83 |
|
|
| 84 |
private int charH; |
|
| 85 |
|
|
| 86 |
private int backgroundColor = 0xffffffff; |
|
| 87 |
private int buttonsColor = 0xff000000; |
|
| 88 |
|
|
| 89 |
private boolean uppercase; |
|
| 90 |
private int minSize=0; |
|
| 91 |
|
|
| 92 |
public interface VirtualKeyboardListener |
|
| 93 |
{
|
|
| 94 |
void okPressed(String string); |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
public TouchKeyboard(Context context, int scrWid, int scrHei) |
|
| 100 |
{
|
|
| 101 |
super(context); |
|
| 102 |
mPaint = new Paint(); |
|
| 103 |
mPaint.setAntiAlias(true); |
|
| 104 |
|
|
| 105 |
currPressed = BUTTON_NONE; |
|
| 106 |
width = scrWid; |
|
| 107 |
height= scrHei; |
|
| 108 |
|
|
| 109 |
Resources res = context.getResources(); |
|
| 110 |
|
|
| 111 |
keyBlue = (NinePatchDrawable)res.getDrawable(R.drawable.keys_blue); |
|
| 112 |
keyRed = (NinePatchDrawable)res.getDrawable(R.drawable.keys_red); |
|
| 113 |
keyWhite= (NinePatchDrawable)res.getDrawable(R.drawable.keys_white); |
|
| 114 |
|
|
| 115 |
ok = BitmapFactory.decodeResource(res, R.drawable.ok ); |
|
| 116 |
bksp= BitmapFactory.decodeResource(res, R.drawable.bksp); |
|
| 117 |
caps= BitmapFactory.decodeResource(res, R.drawable.caps); |
|
| 118 |
|
|
| 119 |
if( width<=height ) |
|
| 120 |
{
|
|
| 121 |
sKeyWidth = width/3; |
|
| 122 |
sKeyHeight= width/5; |
|
| 123 |
keyWidth = width/6; |
|
| 124 |
keyHeight = (height-2*sKeyHeight)/6; |
|
| 125 |
|
|
| 126 |
textFieldHeight = height-sKeyHeight-6*keyHeight; |
|
| 127 |
textFieldWidth = width; |
|
| 128 |
textTopLeftX = 0; |
|
| 129 |
textTopLeftY = sKeyHeight; |
|
| 130 |
} |
|
| 131 |
else |
|
| 132 |
{
|
|
| 133 |
sKeyWidth = sKeyHeight = keyHeight = height/5; |
|
| 134 |
keyWidth = (width+1)/9; |
|
| 135 |
|
|
| 136 |
textFieldHeight= sKeyHeight; |
|
| 137 |
textFieldWidth = width-3*sKeyWidth; |
|
| 138 |
textTopLeftX = sKeyWidth; |
|
| 139 |
textTopLeftY = 0; |
|
| 140 |
} |
|
| 141 |
|
|
| 142 |
bmpSize = ok.getHeight(); |
|
| 143 |
|
|
| 144 |
if( bmpSize> 0.8*sKeyHeight ) |
|
| 145 |
{
|
|
| 146 |
bmpSize = (int)(0.8*sKeyHeight); |
|
| 147 |
ok = Bitmap.createScaledBitmap(ok , bmpSize, bmpSize, true); |
|
| 148 |
bksp = Bitmap.createScaledBitmap(bksp, bmpSize, bmpSize, true); |
|
| 149 |
caps = Bitmap.createScaledBitmap(caps, bmpSize, bmpSize, true); |
|
| 150 |
} |
|
| 151 |
|
|
| 152 |
textField = new TextFieldArea(); |
|
| 153 |
charH= (int)(keyHeight*0.7); |
|
| 154 |
uppercase = true; |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 158 |
|
|
| 159 |
public void resetKeyBoard() |
|
| 160 |
{
|
|
| 161 |
textField.clearTextField(); |
|
| 162 |
invalidate(); |
|
| 163 |
} |
|
| 164 |
|
|
| 165 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 166 |
|
|
| 167 |
protected void onDraw(Canvas c) |
|
| 168 |
{
|
|
| 169 |
mPaint.setColor(backgroundColor); |
|
| 170 |
mPaint.setStyle(Style.FILL); |
|
| 171 |
mPaint.setTextSize(charH); |
|
| 172 |
mPaint.setTextAlign(Align.CENTER); |
|
| 173 |
|
|
| 174 |
c.drawRect(0, 0, width, height, mPaint); |
|
| 175 |
|
|
| 176 |
mPaint.setColor(buttonsColor); |
|
| 177 |
|
|
| 178 |
textField.paint( c, textTopLeftX+1, textTopLeftY+MARGIN/2+1, textTopLeftX+textFieldWidth-1, textTopLeftY+textFieldHeight-MARGIN/2-1); |
|
| 179 |
|
|
| 180 |
if( currPressed==BUTTON_OK ) |
|
| 181 |
{
|
|
| 182 |
keyRed.setBounds( MARGIN/2, MARGIN/2, sKeyWidth-MARGIN/2, sKeyHeight-MARGIN/2); |
|
| 183 |
keyRed.draw(c); |
|
| 184 |
} |
|
| 185 |
else |
|
| 186 |
{
|
|
| 187 |
keyBlue.setBounds( MARGIN/2, MARGIN/2,sKeyWidth-MARGIN/2, sKeyHeight-MARGIN/2); |
|
| 188 |
keyBlue.draw(c); |
|
| 189 |
} |
|
| 190 |
|
|
| 191 |
if( currPressed==BUTTON_BKSP ) |
|
| 192 |
{
|
|
| 193 |
keyRed.setBounds( width-2*sKeyWidth+MARGIN/2, MARGIN/2, width-sKeyWidth-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 194 |
keyRed.draw(c); |
|
| 195 |
} |
|
| 196 |
else |
|
| 197 |
{
|
|
| 198 |
keyBlue.setBounds(width-2*sKeyWidth+MARGIN/2, MARGIN/2, width-sKeyWidth-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 199 |
keyBlue.draw(c); |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
if( currPressed==BUTTON_CAPS ) |
|
| 203 |
{
|
|
| 204 |
keyRed.setBounds( width-sKeyWidth+MARGIN/2, MARGIN/2, width-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 205 |
keyRed.draw(c); |
|
| 206 |
} |
|
| 207 |
else |
|
| 208 |
{
|
|
| 209 |
keyBlue.setBounds(width-sKeyWidth+MARGIN/2, MARGIN/2, width-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 210 |
keyBlue.draw(c); |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
c.drawBitmap(ok , MARGIN/2+sKeyWidth/2-bmpSize/2, MARGIN/2+sKeyHeight/2-bmpSize/2, mPaint); |
|
| 214 |
c.drawBitmap(bksp, width-2*sKeyWidth+MARGIN/2+sKeyWidth/2-bmpSize/2, MARGIN/2+sKeyHeight/2-bmpSize/2, mPaint); |
|
| 215 |
c.drawBitmap(caps, width- sKeyWidth+MARGIN/2+sKeyWidth/2-bmpSize/2, MARGIN/2+sKeyHeight/2-bmpSize/2, mPaint); |
|
| 216 |
|
|
| 217 |
int hei = (width<=height ? textFieldHeight+sKeyHeight : textFieldHeight); |
|
| 218 |
int numCol = (width<=height ? lowerCaseP[0].length : lowerCaseL[0].length); |
|
| 219 |
int numRow = (width<=height ? lowerCaseP.length : lowerCaseL.length); |
|
| 220 |
|
|
| 221 |
for(int j=0; j<numRow; j++) |
|
| 222 |
{
|
|
| 223 |
for(int i=0; i<numCol; i++) |
|
| 224 |
{
|
|
| 225 |
if( currPressed==j*numCol+i ) |
|
| 226 |
{
|
|
| 227 |
keyRed.setBounds( i*width/numCol+ MARGIN/2, hei+ MARGIN/2, |
|
| 228 |
(i+1)*width/numCol- MARGIN/2, hei+ MARGIN/2 +keyHeight ); |
|
| 229 |
keyRed.draw(c); |
|
| 230 |
keyWhite.setBounds(i*width/numCol+WMARGIN/2, hei+WMARGIN/2-keyHeight, |
|
| 231 |
(i+1)*width/numCol-WMARGIN/2, hei-WMARGIN/2 ); |
|
| 232 |
keyWhite.draw(c); |
|
| 233 |
|
|
| 234 |
if( width<=height ) |
|
| 235 |
c.drawText( uppercase? upperCaseP[j]:lowerCaseP[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 236 |
(float)(hei-keyHeight/2+charH*0.4), mPaint); |
|
| 237 |
else |
|
| 238 |
c.drawText( uppercase? upperCaseL[j]:lowerCaseL[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 239 |
(float)(hei-keyHeight/2+charH*0.4), mPaint); |
|
| 240 |
} |
|
| 241 |
else |
|
| 242 |
{
|
|
| 243 |
keyBlue.setBounds( i*width/numCol+ MARGIN/2, hei+ MARGIN/2, |
|
| 244 |
(i+1)*width/numCol- MARGIN/2, hei+ MARGIN/2 +keyHeight ); |
|
| 245 |
keyBlue.draw(c); |
|
| 246 |
} |
|
| 247 |
|
|
| 248 |
if( width<=height ) |
|
| 249 |
c.drawText( uppercase? upperCaseP[j]:lowerCaseP[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 250 |
(float)(hei+keyHeight/2+charH*0.4), mPaint); |
|
| 251 |
else |
|
| 252 |
c.drawText( uppercase? upperCaseL[j]:lowerCaseL[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 253 |
(float)(hei+keyHeight/2+charH*0.4), mPaint); |
|
| 254 |
} |
|
| 255 |
hei+=keyHeight; |
|
| 256 |
} |
|
| 257 |
} |
|
| 258 |
|
|
| 259 |
/////////////////////////////////////////////////////////////////// |
|
| 260 |
|
|
| 261 |
public boolean onTouchEvent(MotionEvent event) |
|
| 262 |
{
|
|
| 263 |
switch(event.getAction()) |
|
| 264 |
{
|
|
| 265 |
case MotionEvent.ACTION_DOWN: buttonPressed( (int)event.getX(), (int)event.getY() ); |
|
| 266 |
break; |
|
| 267 |
case MotionEvent.ACTION_UP : buttonReleased(); |
|
| 268 |
break; |
|
| 269 |
case MotionEvent.ACTION_MOVE: buttonPressed( (int)event.getX(), (int)event.getY() ); |
|
| 270 |
break; |
|
| 271 |
} |
|
| 272 |
|
|
| 273 |
invalidate(); |
|
| 274 |
return true; |
|
| 275 |
} |
|
| 276 |
|
|
| 277 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 278 |
|
|
| 279 |
private void buttonPressed(int x, int y) |
|
| 280 |
{
|
|
| 281 |
if( width<height ) |
|
| 282 |
{
|
|
| 283 |
if( y>=0 && y<sKeyHeight ) |
|
| 284 |
{
|
|
| 285 |
if( x<= sKeyWidth ) currPressed = BUTTON_OK; |
|
| 286 |
else if( x<=2*sKeyWidth ) currPressed = BUTTON_BKSP; |
|
| 287 |
else currPressed = BUTTON_CAPS; |
|
| 288 |
} |
|
| 289 |
else if( y>=sKeyHeight+textFieldHeight && y<=height ) |
|
| 290 |
{
|
|
| 291 |
currPressed = (int)((y-sKeyHeight-textFieldHeight)/keyHeight)*lowerCaseP[0].length + x/keyWidth; |
|
| 292 |
} |
|
| 293 |
} |
|
| 294 |
else |
|
| 295 |
{
|
|
| 296 |
if( y>=0 && y<textFieldHeight ) |
|
| 297 |
{
|
|
| 298 |
if( x<=sKeyWidth ) currPressed = BUTTON_OK; |
|
| 299 |
else if( x>=width-2*sKeyWidth && x<=width-sKeyWidth ) currPressed = BUTTON_BKSP; |
|
| 300 |
else if( x>=width- sKeyWidth && x<=width ) currPressed = BUTTON_CAPS; |
|
| 301 |
else currPressed = BUTTON_NONE; |
|
| 302 |
} |
|
| 303 |
else if( y>=textFieldHeight && y<=height) |
|
| 304 |
{
|
|
| 305 |
currPressed = (int)((y-textFieldHeight)/keyHeight)*lowerCaseL[0].length + x/keyWidth; |
|
| 306 |
} |
|
| 307 |
} |
|
| 308 |
} |
|
| 309 |
|
|
| 310 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 311 |
|
|
| 312 |
private void buttonReleased() |
|
| 313 |
{
|
|
| 314 |
if( currPressed==BUTTON_OK ) okButtonAction(); |
|
| 315 |
else if( currPressed==BUTTON_BKSP ) bkspButtonAction(); |
|
| 316 |
else if( currPressed==BUTTON_CAPS ) capsButtonAction(); |
|
| 317 |
else if( currPressed>=0 ) charAreaAction(currPressed); |
|
| 318 |
|
|
| 319 |
currPressed = BUTTON_NONE; |
|
| 320 |
} |
|
| 321 |
|
|
| 322 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 323 |
|
|
| 324 |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) |
|
| 325 |
{
|
|
| 326 |
if( currPressed!=BUTTON_NONE ) return false; |
|
| 327 |
/* |
|
| 328 |
switch( keyCode ) |
|
| 329 |
{
|
|
| 330 |
case Keypad.KEY_ALT : |
|
| 331 |
case Keypad.KEY_SHIFT_RIGHT: |
|
| 332 |
case Keypad.KEY_SHIFT_LEFT : currPressed= BUTTON_CAPS; invalidate(); break; |
|
| 333 |
case Keypad.KEY_ENTER : currPressed= BUTTON_OK ; invalidate(); break; |
|
| 334 |
case Keypad.KEY_DELETE : |
|
| 335 |
case Keypad.KEY_BACKSPACE : currPressed= BUTTON_BKSP; invalidate(); break; |
|
| 336 |
} |
|
| 337 |
|
|
| 338 |
if( key>='A' && key<='Z' ) { currPressed = key-'A' ; invalidate(); }
|
|
| 339 |
if( key>='a' && key<='z' ) { currPressed = key-'a' ; invalidate(); }
|
|
| 340 |
if( key>='0' && key<='9' ) { currPressed = 'z'-'a'+1+key-'0'; invalidate(); }
|
|
| 341 |
*/ |
|
| 342 |
return true; |
|
| 343 |
} |
|
| 344 |
|
|
| 345 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 346 |
|
|
| 347 |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) |
|
| 348 |
{
|
|
| 349 |
buttonReleased(); |
|
| 350 |
return true; |
|
| 351 |
} |
|
| 352 |
|
|
| 353 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 354 |
|
|
| 355 |
private void capsButtonAction() |
|
| 356 |
{
|
|
| 357 |
uppercase = !uppercase; |
|
| 358 |
} |
|
| 359 |
|
|
| 360 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 361 |
|
|
| 362 |
private void okButtonAction() |
|
| 363 |
{
|
|
| 364 |
if ( invoker != null ) |
|
| 365 |
{
|
|
| 366 |
String text = textField.getText(); |
|
| 367 |
|
|
| 368 |
if( text.length()>= minSize ) |
|
| 369 |
invoker.okPressed(text); |
|
| 370 |
} |
|
| 371 |
} |
|
| 372 |
|
|
| 373 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 374 |
|
|
| 375 |
private void bkspButtonAction() |
|
| 376 |
{
|
|
| 377 |
textField.deleteLastChar(); |
|
| 378 |
} |
|
| 379 |
|
|
| 380 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 381 |
|
|
| 382 |
private void charAreaAction(int pressed) |
|
| 383 |
{
|
|
| 384 |
int numCol = (width<height ? lowerCaseP[0].length:lowerCaseL[0].length); |
|
| 385 |
int j = pressed/numCol; |
|
| 386 |
int i = pressed%numCol; |
|
| 387 |
|
|
| 388 |
if( width<height ) |
|
| 389 |
textField.insertNewChar( uppercase ? upperCaseP[j][i]:lowerCaseP[j][i]); |
|
| 390 |
else |
|
| 391 |
textField.insertNewChar( uppercase ? upperCaseL[j][i]:lowerCaseL[j][i]); |
|
| 392 |
} |
|
| 393 |
|
|
| 394 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 395 |
|
|
| 396 |
public void setText(String text) |
|
| 397 |
{
|
|
| 398 |
textField.setText( (text==null||text.length()==0)?"":text); |
|
| 399 |
invalidate(); |
|
| 400 |
} |
|
| 401 |
|
|
| 402 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 403 |
|
|
| 404 |
public void setTextFieldBkgColor(int color) |
|
| 405 |
{
|
|
| 406 |
textField.setTextFieldBkgColor(color); |
|
| 407 |
} |
|
| 408 |
|
|
| 409 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 410 |
|
|
| 411 |
public void setTextFieldBorderColor(int color) |
|
| 412 |
{
|
|
| 413 |
textField.setTextFieldBorderColor(color); |
|
| 414 |
} |
|
| 415 |
|
|
| 416 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 417 |
|
|
| 418 |
public void setTextFieldFontColor(int color) |
|
| 419 |
{
|
|
| 420 |
textField.setTextFieldFontColor(color); |
|
| 421 |
} |
|
| 422 |
|
|
| 423 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 424 |
|
|
| 425 |
public int getBackgroundColor() |
|
| 426 |
{
|
|
| 427 |
return backgroundColor; |
|
| 428 |
} |
|
| 429 |
|
|
| 430 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 431 |
|
|
| 432 |
public void setBackgroundColor(int backgroundColor) |
|
| 433 |
{
|
|
| 434 |
this.backgroundColor = backgroundColor; |
|
| 435 |
} |
|
| 436 |
|
|
| 437 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 438 |
|
|
| 439 |
public void setMaxSize(int maxSize) |
|
| 440 |
{
|
|
| 441 |
textField.setMaxSize(maxSize); |
|
| 442 |
} |
|
| 443 |
|
|
| 444 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 445 |
|
|
| 446 |
public void setMinSize(int minSize) |
|
| 447 |
{
|
|
| 448 |
this.minSize = minSize; |
|
| 449 |
} |
|
| 450 |
|
|
| 451 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 452 |
|
|
| 453 |
public void setVirtualKeyboardListener(VirtualKeyboardListener invoker) |
|
| 454 |
{
|
|
| 455 |
this.invoker = invoker; |
|
| 456 |
} |
|
| 457 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 458 |
// end of TouchKeyboard |
|
| 459 |
} |
|
| distorted-sokoban/src/main/java/org/distorted/messaging/SokobanInAppMessanging.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.messaging; |
|
| 11 |
|
|
| 12 |
import com.google.firebase.inappmessaging.FirebaseInAppMessagingClickListener; |
|
| 13 |
import com.google.firebase.inappmessaging.model.Action; |
|
| 14 |
import com.google.firebase.inappmessaging.model.CampaignMetadata; |
|
| 15 |
import com.google.firebase.inappmessaging.model.InAppMessage; |
|
| 16 |
|
|
| 17 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 18 |
|
|
| 19 |
public class SokobanInAppMessanging implements FirebaseInAppMessagingClickListener |
|
| 20 |
{
|
|
| 21 |
@Override |
|
| 22 |
public void messageClicked(InAppMessage inAppMessage, Action action) |
|
| 23 |
{
|
|
| 24 |
// Determine which URL the user clicked |
|
| 25 |
String url = action.getActionUrl(); |
|
| 26 |
|
|
| 27 |
android.util.Log.e("D", "In App Messaging: url="+url);
|
|
| 28 |
|
|
| 29 |
// Get general information about the campaign |
|
| 30 |
CampaignMetadata metadata = inAppMessage.getCampaignMetadata(); |
|
| 31 |
|
|
| 32 |
if( metadata!=null ) |
|
| 33 |
{
|
|
| 34 |
String id = metadata.getCampaignId(); |
|
| 35 |
String name = metadata.getCampaignName(); |
|
| 36 |
boolean test = metadata.getIsTestMessage(); |
|
| 37 |
android.util.Log.e("D", "In App Messaging: id="+id+" name="+name+" test="+test);
|
|
| 38 |
} |
|
| 39 |
} |
|
| 40 |
} |
|
| distorted-sokoban/src/main/java/org/distorted/messaging/SokobanMessagingService.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.messaging; |
|
| 11 |
|
|
| 12 |
import android.content.Context; |
|
| 13 |
import android.util.Log; |
|
| 14 |
|
|
| 15 |
import androidx.annotation.NonNull; |
|
| 16 |
|
|
| 17 |
import androidx.work.OneTimeWorkRequest; |
|
| 18 |
import androidx.work.WorkManager; |
|
| 19 |
import androidx.work.Worker; |
|
| 20 |
import androidx.work.WorkerParameters; |
|
| 21 |
|
|
| 22 |
import com.google.firebase.messaging.FirebaseMessagingService; |
|
| 23 |
import com.google.firebase.messaging.RemoteMessage; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
public class SokobanMessagingService extends FirebaseMessagingService |
|
| 28 |
{
|
|
| 29 |
private static final String TAG = "RubikMessagingService"; |
|
| 30 |
|
|
| 31 |
public static class RubikWorker extends Worker |
|
| 32 |
{
|
|
| 33 |
public RubikWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) |
|
| 34 |
{
|
|
| 35 |
super(context, workerParams); |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
@NonNull |
|
| 39 |
@Override |
|
| 40 |
public Result doWork() |
|
| 41 |
{
|
|
| 42 |
return Result.success(); |
|
| 43 |
} |
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
@Override |
|
| 49 |
public void onMessageReceived(RemoteMessage remoteMessage) |
|
| 50 |
{
|
|
| 51 |
Log.e(TAG, "From: " + remoteMessage.getFrom()); |
|
| 52 |
|
|
| 53 |
if (remoteMessage.getData().size() > 0) |
|
| 54 |
{
|
|
| 55 |
Log.e(TAG, "Message data payload: " + remoteMessage.getData()); |
|
| 56 |
|
|
| 57 |
if (/* Check if data needs to be processed by long running job */ true) |
|
| 58 |
{
|
|
| 59 |
scheduleJob(); |
|
| 60 |
} |
|
| 61 |
else |
|
| 62 |
{
|
|
| 63 |
handleNow(); |
|
| 64 |
} |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
if (remoteMessage.getNotification() != null) |
|
| 68 |
{
|
|
| 69 |
Log.e(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); |
|
| 70 |
} |
|
| 71 |
} |
|
| 72 |
|
|
| 73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 74 |
|
|
| 75 |
@Override |
|
| 76 |
public void onNewToken(@NonNull String token) |
|
| 77 |
{
|
|
| 78 |
// TODO: send to my server |
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 82 |
|
|
| 83 |
private void scheduleJob() |
|
| 84 |
{
|
|
| 85 |
OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(RubikWorker.class).build(); |
|
| 86 |
WorkManager.getInstance(this).beginWith(work).enqueue(); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
|
|
| 91 |
private void handleNow() |
|
| 92 |
{
|
|
| 93 |
|
|
| 94 |
} |
|
| 95 |
} |
|
| distorted-sokoban/src/main/java/org/distorted/sokoban/Sokoban.java | ||
|---|---|---|
| 5 | 5 |
import android.os.Bundle; |
| 6 | 6 |
import android.util.Log; |
| 7 | 7 |
|
| 8 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
| 9 |
import com.google.firebase.inappmessaging.FirebaseInAppMessaging; |
|
| 10 |
|
|
| 11 |
import org.distorted.messaging.SokobanInAppMessanging; |
|
| 12 |
|
|
| 8 | 13 |
/////////////////////////////////////////////////////////////////// |
| 9 | 14 |
|
| 10 | 15 |
public class Sokoban extends Activity |
| 11 | 16 |
{
|
| 12 | 17 |
private static final String TAG_SPLASH = "SokobanSplash"; |
| 13 |
public static final boolean DEBUG = false;
|
|
| 14 |
private int sleepTime=2000;
|
|
| 15 |
|
|
| 16 |
private class SplashThread extends Thread
|
|
| 18 |
private int sleepTime=2000;
|
|
| 19 |
private FirebaseAnalytics mFirebaseAnalytics;
|
|
| 20 |
|
|
| 21 |
private class SplashThread extends Thread |
|
| 17 | 22 |
{
|
| 18 |
private boolean bootup=true;
|
|
| 23 |
private boolean bootup=true; |
|
| 19 | 24 |
|
| 20 | 25 |
public void run() |
| 21 | 26 |
{
|
| ... | ... | |
| 52 | 57 |
/////////////////////////////////////////////////////////////////// |
| 53 | 58 |
|
| 54 | 59 |
public void onCreate(Bundle savedInstanceState) |
| 55 |
{
|
|
| 56 |
Log.d( TAG_SPLASH, "onCreate"); |
|
| 57 |
|
|
| 60 |
{
|
|
| 58 | 61 |
super.onCreate(savedInstanceState); |
| 59 |
|
|
| 60 |
if( getResources().getInteger(R.integer.is_korean) == 1 ) |
|
| 61 |
{
|
|
| 62 |
setContentView(R.layout.grb); |
|
| 63 |
sleepTime=3500; |
|
| 64 |
} |
|
| 65 |
else |
|
| 66 |
{
|
|
| 67 |
setContentView(R.layout.splash); |
|
| 68 |
sleepTime=2000; |
|
| 69 |
} |
|
| 70 |
} |
|
| 62 |
|
|
| 63 |
setContentView(R.layout.splash); |
|
| 64 |
sleepTime=2000; |
|
| 65 |
|
|
| 66 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
|
| 67 |
SokobanInAppMessanging listener = new SokobanInAppMessanging(); |
|
| 68 |
|
|
| 69 |
FirebaseInAppMessaging.getInstance().addClickListener(listener); |
|
| 70 |
} |
|
| 71 | 71 |
|
| 72 | 72 |
/////////////////////////////////////////////////////////////////// |
| 73 | 73 |
|
| distorted-sokoban/src/main/java/org/distorted/sokoban/TextFieldArea.java | ||
|---|---|---|
| 1 |
package org.distorted.sokoban; |
|
| 2 |
|
|
| 3 |
import android.graphics.Canvas; |
|
| 4 |
import android.graphics.Paint; |
|
| 5 |
import android.graphics.Paint.Style; |
|
| 6 |
|
|
| 7 |
/////////////////////////////////////////////////////////////////// |
|
| 8 |
|
|
| 9 |
public class TextFieldArea |
|
| 10 |
{
|
|
| 11 |
//private static final String TAG_TEXT = "RRText"; |
|
| 12 |
|
|
| 13 |
private StringBuffer text; |
|
| 14 |
|
|
| 15 |
private int textFieldBkgColor = 0xFFEEEEEE; |
|
| 16 |
private int textFieldBorderColor = 0xFF000000; |
|
| 17 |
private int textFieldFontColor = 0xFF000000; |
|
| 18 |
|
|
| 19 |
private int maxSize = -1; |
|
| 20 |
private int strLen; |
|
| 21 |
private Paint mPaint; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
public TextFieldArea() |
|
| 26 |
{
|
|
| 27 |
text = new StringBuffer(); |
|
| 28 |
strLen = 0; |
|
| 29 |
mPaint = new Paint(); |
|
| 30 |
mPaint.setAntiAlias(true); |
|
| 31 |
} |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public void deleteLastChar() |
|
| 36 |
{
|
|
| 37 |
if (strLen > 0) |
|
| 38 |
{
|
|
| 39 |
text.deleteCharAt(strLen-1); |
|
| 40 |
strLen--; |
|
| 41 |
} |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
public void insertNewChar(char aChar) |
|
| 47 |
{
|
|
| 48 |
if ( ((maxSize > 0) && (text.length() < maxSize)) || (maxSize < 0)) |
|
| 49 |
{
|
|
| 50 |
if (aChar != 0) |
|
| 51 |
{
|
|
| 52 |
text.insert(strLen, aChar); |
|
| 53 |
strLen++; |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
public String getText() |
|
| 61 |
{
|
|
| 62 |
return text.toString(); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
public void setText(String newText) |
|
| 68 |
{
|
|
| 69 |
text = null; |
|
| 70 |
text = new StringBuffer(newText); |
|
| 71 |
strLen = newText.length(); |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////// |
|
| 75 |
|
|
| 76 |
public void clearTextField() |
|
| 77 |
{
|
|
| 78 |
text = null; |
|
| 79 |
text = new StringBuffer(); |
|
| 80 |
strLen = 0; |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////// |
|
| 84 |
|
|
| 85 |
public void paint( Canvas canvas, int left, int top, int right, int bottom) |
|
| 86 |
{
|
|
| 87 |
int fontH = (int)((bottom-top)*0.7); |
|
| 88 |
|
|
| 89 |
mPaint.setColor(textFieldBkgColor); |
|
| 90 |
mPaint.setStyle(Style.FILL); |
|
| 91 |
canvas.drawRect(left, top, right, bottom, mPaint); |
|
| 92 |
mPaint.setColor(textFieldBorderColor); |
|
| 93 |
mPaint.setStyle(Style.STROKE); |
|
| 94 |
canvas.drawRect(left, top, right, bottom, mPaint); |
|
| 95 |
mPaint.setColor(textFieldFontColor); |
|
| 96 |
mPaint.setTextSize(fontH); |
|
| 97 |
|
|
| 98 |
String t = text.toString(); |
|
| 99 |
|
|
| 100 |
while( mPaint.measureText(t) > right-left-(bottom-top)/2 ) |
|
| 101 |
{
|
|
| 102 |
mPaint.setTextSize(--fontH); |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
canvas.drawText( t, left+(bottom-top)/4, (bottom+top+fontH)/2-fontH/8, mPaint); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
|
|
| 110 |
public void setTextFieldBkgColor(int textFieldBkgColor) |
|
| 111 |
{
|
|
| 112 |
this.textFieldBkgColor = textFieldBkgColor; |
|
| 113 |
} |
|
| 114 |
|
|
| 115 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 116 |
|
|
| 117 |
public void setTextFieldBorderColor(int textFieldBorderColor) |
|
| 118 |
{
|
|
| 119 |
this.textFieldBorderColor = textFieldBorderColor; |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 123 |
|
|
| 124 |
public void setTextFieldFontColor(int textFieldFontColor) |
|
| 125 |
{
|
|
| 126 |
this.textFieldFontColor = textFieldFontColor; |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 130 |
|
|
| 131 |
public int getMaxSize() |
|
| 132 |
{
|
|
| 133 |
return maxSize; |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 137 |
|
|
| 138 |
public void setMaxSize(int maxSize) |
|
| 139 |
{
|
|
| 140 |
this.maxSize = maxSize; |
|
| 141 |
} |
|
| 142 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
// end of TextFieldArea |
|
| 144 |
} |
|
| distorted-sokoban/src/main/java/org/distorted/sokoban/TouchKeyboard.java | ||
|---|---|---|
| 1 |
package org.distorted.sokoban; |
|
| 2 |
|
|
| 3 |
import android.content.Context; |
|
| 4 |
import android.content.res.Resources; |
|
| 5 |
import android.graphics.Bitmap; |
|
| 6 |
import android.graphics.BitmapFactory; |
|
| 7 |
import android.graphics.Canvas; |
|
| 8 |
import android.graphics.Paint; |
|
| 9 |
import android.graphics.Paint.Align; |
|
| 10 |
import android.graphics.Paint.Style; |
|
| 11 |
import android.graphics.drawable.NinePatchDrawable; |
|
| 12 |
|
|
| 13 |
import android.view.KeyEvent; |
|
| 14 |
import android.view.MotionEvent; |
|
| 15 |
import android.view.View; |
|
| 16 |
|
|
| 17 |
//import android.util.Log; |
|
| 18 |
|
|
| 19 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
public class TouchKeyboard extends View |
|
| 22 |
{
|
|
| 23 |
//private static final String TAG_KEYBOARD = "RubikKeyboard"; |
|
| 24 |
|
|
| 25 |
private static final int MARGIN = 2; |
|
| 26 |
private static final int WMARGIN = 8; |
|
| 27 |
private static final int BUTTON_NONE = -4; |
|
| 28 |
private static final int BUTTON_OK = -3; |
|
| 29 |
private static final int BUTTON_BKSP = -2; |
|
| 30 |
private static final int BUTTON_CAPS = -1; |
|
| 31 |
|
|
| 32 |
private int currPressed; |
|
| 33 |
|
|
| 34 |
private TextFieldArea textField; |
|
| 35 |
private Paint mPaint; |
|
| 36 |
private NinePatchDrawable keyBlue, keyRed, keyWhite; |
|
| 37 |
private Bitmap ok, bksp, caps; |
|
| 38 |
|
|
| 39 |
private int bmpSize; |
|
| 40 |
|
|
| 41 |
char[][] lowerCaseL = |
|
| 42 |
{ {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'},
|
|
| 43 |
{'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r'},
|
|
| 44 |
{'s', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0'},
|
|
| 45 |
{'1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
|
| 46 |
}; |
|
| 47 |
|
|
| 48 |
char[][] upperCaseL = |
|
| 49 |
{ {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'},
|
|
| 50 |
{'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R'},
|
|
| 51 |
{'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0'},
|
|
| 52 |
{'1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
|
| 53 |
}; |
|
| 54 |
|
|
| 55 |
char[][] lowerCaseP = |
|
| 56 |
{ {'a', 'b', 'c', 'd', 'e', 'f'},
|
|
| 57 |
{'g', 'h', 'i', 'j', 'k', 'l'},
|
|
| 58 |
{'m', 'n', 'o', 'p', 'q', 'r'},
|
|
| 59 |
{'s', 't', 'u', 'v', 'w', 'x'},
|
|
| 60 |
{'y', 'z', '0', '1', '2', '3'},
|
|
| 61 |
{'4', '5', '6', '7', '8', '9'}
|
|
| 62 |
}; |
|
| 63 |
|
|
| 64 |
char[][] upperCaseP = |
|
| 65 |
{ {'A', 'B', 'C', 'D', 'E', 'F'},
|
|
| 66 |
{'G', 'H', 'I', 'J', 'K', 'L'},
|
|
| 67 |
{'M', 'N', 'O', 'P', 'Q', 'R'},
|
|
| 68 |
{'S', 'T', 'U', 'V', 'W', 'X'},
|
|
| 69 |
{'Y', 'Z', '0', '1', '2', '3'},
|
|
| 70 |
{'4', '5', '6', '7', '8', '9'}
|
|
| 71 |
}; |
|
| 72 |
|
|
| 73 |
private int width, height; |
|
| 74 |
|
|
| 75 |
private int textFieldWidth; |
|
| 76 |
private int textFieldHeight; |
|
| 77 |
private int textTopLeftX; |
|
| 78 |
private int textTopLeftY; |
|
| 79 |
private int keyWidth, keyHeight; |
|
| 80 |
private int sKeyWidth, sKeyHeight; |
|
| 81 |
|
|
| 82 |
private VirtualKeyboardListener invoker; |
|
| 83 |
|
|
| 84 |
private int charH; |
|
| 85 |
|
|
| 86 |
private int backgroundColor = 0xffffffff; |
|
| 87 |
private int buttonsColor = 0xff000000; |
|
| 88 |
|
|
| 89 |
private boolean uppercase; |
|
| 90 |
private int minSize=0; |
|
| 91 |
|
|
| 92 |
public interface VirtualKeyboardListener |
|
| 93 |
{
|
|
| 94 |
void okPressed(String string); |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
public TouchKeyboard(Context context, int scrWid, int scrHei) |
|
| 100 |
{
|
|
| 101 |
super(context); |
|
| 102 |
mPaint = new Paint(); |
|
| 103 |
mPaint.setAntiAlias(true); |
|
| 104 |
|
|
| 105 |
currPressed = BUTTON_NONE; |
|
| 106 |
width = scrWid; |
|
| 107 |
height= scrHei; |
|
| 108 |
|
|
| 109 |
Resources res = context.getResources(); |
|
| 110 |
|
|
| 111 |
keyBlue = (NinePatchDrawable)res.getDrawable(R.drawable.keys_blue); |
|
| 112 |
keyRed = (NinePatchDrawable)res.getDrawable(R.drawable.keys_red); |
|
| 113 |
keyWhite= (NinePatchDrawable)res.getDrawable(R.drawable.keys_white); |
|
| 114 |
|
|
| 115 |
ok = BitmapFactory.decodeResource(res, R.drawable.ok ); |
|
| 116 |
bksp= BitmapFactory.decodeResource(res, R.drawable.bksp); |
|
| 117 |
caps= BitmapFactory.decodeResource(res, R.drawable.caps); |
|
| 118 |
|
|
| 119 |
if( width<=height ) |
|
| 120 |
{
|
|
| 121 |
sKeyWidth = width/3; |
|
| 122 |
sKeyHeight= width/5; |
|
| 123 |
keyWidth = width/6; |
|
| 124 |
keyHeight = (height-2*sKeyHeight)/6; |
|
| 125 |
|
|
| 126 |
textFieldHeight = height-sKeyHeight-6*keyHeight; |
|
| 127 |
textFieldWidth = width; |
|
| 128 |
textTopLeftX = 0; |
|
| 129 |
textTopLeftY = sKeyHeight; |
|
| 130 |
} |
|
| 131 |
else |
|
| 132 |
{
|
|
| 133 |
sKeyWidth = sKeyHeight = keyHeight = height/5; |
|
| 134 |
keyWidth = (width+1)/9; |
|
| 135 |
|
|
| 136 |
textFieldHeight= sKeyHeight; |
|
| 137 |
textFieldWidth = width-3*sKeyWidth; |
|
| 138 |
textTopLeftX = sKeyWidth; |
|
| 139 |
textTopLeftY = 0; |
|
| 140 |
} |
|
| 141 |
|
|
| 142 |
bmpSize = ok.getHeight(); |
|
| 143 |
|
|
| 144 |
if( bmpSize> 0.8*sKeyHeight ) |
|
| 145 |
{
|
|
| 146 |
bmpSize = (int)(0.8*sKeyHeight); |
|
| 147 |
ok = Bitmap.createScaledBitmap(ok , bmpSize, bmpSize, true); |
|
| 148 |
bksp = Bitmap.createScaledBitmap(bksp, bmpSize, bmpSize, true); |
|
| 149 |
caps = Bitmap.createScaledBitmap(caps, bmpSize, bmpSize, true); |
|
| 150 |
} |
|
| 151 |
|
|
| 152 |
textField = new TextFieldArea(); |
|
| 153 |
charH= (int)(keyHeight*0.7); |
|
| 154 |
uppercase = true; |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 158 |
|
|
| 159 |
public void resetKeyBoard() |
|
| 160 |
{
|
|
| 161 |
textField.clearTextField(); |
|
| 162 |
invalidate(); |
|
| 163 |
} |
|
| 164 |
|
|
| 165 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 166 |
|
|
| 167 |
protected void onDraw(Canvas c) |
|
| 168 |
{
|
|
| 169 |
mPaint.setColor(backgroundColor); |
|
| 170 |
mPaint.setStyle(Style.FILL); |
|
| 171 |
mPaint.setTextSize(charH); |
|
| 172 |
mPaint.setTextAlign(Align.CENTER); |
|
| 173 |
|
|
| 174 |
c.drawRect(0, 0, width, height, mPaint); |
|
| 175 |
|
|
| 176 |
mPaint.setColor(buttonsColor); |
|
| 177 |
|
|
| 178 |
textField.paint( c, textTopLeftX+1, textTopLeftY+MARGIN/2+1, textTopLeftX+textFieldWidth-1, textTopLeftY+textFieldHeight-MARGIN/2-1); |
|
| 179 |
|
|
| 180 |
if( currPressed==BUTTON_OK ) |
|
| 181 |
{
|
|
| 182 |
keyRed.setBounds( MARGIN/2, MARGIN/2, sKeyWidth-MARGIN/2, sKeyHeight-MARGIN/2); |
|
| 183 |
keyRed.draw(c); |
|
| 184 |
} |
|
| 185 |
else |
|
| 186 |
{
|
|
| 187 |
keyBlue.setBounds( MARGIN/2, MARGIN/2,sKeyWidth-MARGIN/2, sKeyHeight-MARGIN/2); |
|
| 188 |
keyBlue.draw(c); |
|
| 189 |
} |
|
| 190 |
|
|
| 191 |
if( currPressed==BUTTON_BKSP ) |
|
| 192 |
{
|
|
| 193 |
keyRed.setBounds( width-2*sKeyWidth+MARGIN/2, MARGIN/2, width-sKeyWidth-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 194 |
keyRed.draw(c); |
|
| 195 |
} |
|
| 196 |
else |
|
| 197 |
{
|
|
| 198 |
keyBlue.setBounds(width-2*sKeyWidth+MARGIN/2, MARGIN/2, width-sKeyWidth-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 199 |
keyBlue.draw(c); |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
if( currPressed==BUTTON_CAPS ) |
|
| 203 |
{
|
|
| 204 |
keyRed.setBounds( width-sKeyWidth+MARGIN/2, MARGIN/2, width-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 205 |
keyRed.draw(c); |
|
| 206 |
} |
|
| 207 |
else |
|
| 208 |
{
|
|
| 209 |
keyBlue.setBounds(width-sKeyWidth+MARGIN/2, MARGIN/2, width-MARGIN/2,sKeyHeight-MARGIN/2); |
|
| 210 |
keyBlue.draw(c); |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
c.drawBitmap(ok , MARGIN/2+sKeyWidth/2-bmpSize/2, MARGIN/2+sKeyHeight/2-bmpSize/2, mPaint); |
|
| 214 |
c.drawBitmap(bksp, width-2*sKeyWidth+MARGIN/2+sKeyWidth/2-bmpSize/2, MARGIN/2+sKeyHeight/2-bmpSize/2, mPaint); |
|
| 215 |
c.drawBitmap(caps, width- sKeyWidth+MARGIN/2+sKeyWidth/2-bmpSize/2, MARGIN/2+sKeyHeight/2-bmpSize/2, mPaint); |
|
| 216 |
|
|
| 217 |
int hei = (width<=height ? textFieldHeight+sKeyHeight : textFieldHeight); |
|
| 218 |
int numCol = (width<=height ? lowerCaseP[0].length : lowerCaseL[0].length); |
|
| 219 |
int numRow = (width<=height ? lowerCaseP.length : lowerCaseL.length); |
|
| 220 |
|
|
| 221 |
for(int j=0; j<numRow; j++) |
|
| 222 |
{
|
|
| 223 |
for(int i=0; i<numCol; i++) |
|
| 224 |
{
|
|
| 225 |
if( currPressed==j*numCol+i ) |
|
| 226 |
{
|
|
| 227 |
keyRed.setBounds( i*width/numCol+ MARGIN/2, hei+ MARGIN/2, |
|
| 228 |
(i+1)*width/numCol- MARGIN/2, hei+ MARGIN/2 +keyHeight ); |
|
| 229 |
keyRed.draw(c); |
|
| 230 |
keyWhite.setBounds(i*width/numCol+WMARGIN/2, hei+WMARGIN/2-keyHeight, |
|
| 231 |
(i+1)*width/numCol-WMARGIN/2, hei-WMARGIN/2 ); |
|
| 232 |
keyWhite.draw(c); |
|
| 233 |
|
|
| 234 |
if( width<=height ) |
|
| 235 |
c.drawText( uppercase? upperCaseP[j]:lowerCaseP[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 236 |
(float)(hei-keyHeight/2+charH*0.4), mPaint); |
|
| 237 |
else |
|
| 238 |
c.drawText( uppercase? upperCaseL[j]:lowerCaseL[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 239 |
(float)(hei-keyHeight/2+charH*0.4), mPaint); |
|
| 240 |
} |
|
| 241 |
else |
|
| 242 |
{
|
|
| 243 |
keyBlue.setBounds( i*width/numCol+ MARGIN/2, hei+ MARGIN/2, |
|
| 244 |
(i+1)*width/numCol- MARGIN/2, hei+ MARGIN/2 +keyHeight ); |
|
| 245 |
keyBlue.draw(c); |
|
| 246 |
} |
|
| 247 |
|
|
| 248 |
if( width<=height ) |
|
| 249 |
c.drawText( uppercase? upperCaseP[j]:lowerCaseP[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 250 |
(float)(hei+keyHeight/2+charH*0.4), mPaint); |
|
| 251 |
else |
|
| 252 |
c.drawText( uppercase? upperCaseL[j]:lowerCaseL[j], i,1,(float)(i*width/numCol+keyWidth/2), |
|
| 253 |
(float)(hei+keyHeight/2+charH*0.4), mPaint); |
|
| 254 |
} |
|
| 255 |
hei+=keyHeight; |
|
| 256 |
} |
|
| 257 |
} |
|
| 258 |
|
|
| 259 |
/////////////////////////////////////////////////////////////////// |
|
| 260 |
|
|
| 261 |
public boolean onTouchEvent(MotionEvent event) |
|
| 262 |
{
|
|
| 263 |
switch(event.getAction()) |
|
| 264 |
{
|
|
| 265 |
case MotionEvent.ACTION_DOWN: buttonPressed( (int)event.getX(), (int)event.getY() ); |
|
| 266 |
break; |
|
| 267 |
case MotionEvent.ACTION_UP : buttonReleased(); |
|
| 268 |
break; |
|
| 269 |
case MotionEvent.ACTION_MOVE: buttonPressed( (int)event.getX(), (int)event.getY() ); |
|
| 270 |
break; |
|
| 271 |
} |
|
| 272 |
|
|
| 273 |
invalidate(); |
|
| 274 |
return true; |
|
| 275 |
} |
|
| 276 |
|
|
| 277 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 278 |
|
|
| 279 |
private void buttonPressed(int x, int y) |
|
| 280 |
{
|
|
| 281 |
if( width<height ) |
|
| 282 |
{
|
|
| 283 |
if( y>=0 && y<sKeyHeight ) |
|
| 284 |
{
|
|
| 285 |
if( x<= sKeyWidth ) currPressed = BUTTON_OK; |
|
| 286 |
else if( x<=2*sKeyWidth ) currPressed = BUTTON_BKSP; |
|
| 287 |
else currPressed = BUTTON_CAPS; |
|
| 288 |
} |
|
| 289 |
else if( y>=sKeyHeight+textFieldHeight && y<=height ) |
|
| 290 |
{
|
|
| 291 |
currPressed = (int)((y-sKeyHeight-textFieldHeight)/keyHeight)*lowerCaseP[0].length + x/keyWidth; |
|
| 292 |
} |
|
| 293 |
} |
|
| 294 |
else |
|
| 295 |
{
|
|
| 296 |
if( y>=0 && y<textFieldHeight ) |
|
| 297 |
{
|
|
| 298 |
if( x<=sKeyWidth ) currPressed = BUTTON_OK; |
|
| 299 |
else if( x>=width-2*sKeyWidth && x<=width-sKeyWidth ) currPressed = BUTTON_BKSP; |
|
| 300 |
else if( x>=width- sKeyWidth && x<=width ) currPressed = BUTTON_CAPS; |
|
| 301 |
else currPressed = BUTTON_NONE; |
|
| 302 |
} |
|
| 303 |
else if( y>=textFieldHeight && y<=height) |
|
| 304 |
{
|
|
| 305 |
currPressed = (int)((y-textFieldHeight)/keyHeight)*lowerCaseL[0].length + x/keyWidth; |
|
| 306 |
} |
|
| 307 |
} |
|
| 308 |
} |
|
| 309 |
|
|
| 310 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 311 |
|
|
| 312 |
private void buttonReleased() |
|
| 313 |
{
|
|
| 314 |
if( currPressed==BUTTON_OK ) okButtonAction(); |
|
| 315 |
else if( currPressed==BUTTON_BKSP ) bkspButtonAction(); |
|
| 316 |
else if( currPressed==BUTTON_CAPS ) capsButtonAction(); |
|
| 317 |
else if( currPressed>=0 ) charAreaAction(currPressed); |
|
| 318 |
|
|
| 319 |
currPressed = BUTTON_NONE; |
|
| 320 |
} |
|
| 321 |
|
|
| 322 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 323 |
|
|
| 324 |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) |
|
| 325 |
{
|
|
| 326 |
if( currPressed!=BUTTON_NONE ) return false; |
|
| 327 |
/* |
|
| 328 |
switch( keyCode ) |
|
| 329 |
{
|
|
| 330 |
case Keypad.KEY_ALT : |
|
| 331 |
case Keypad.KEY_SHIFT_RIGHT: |
|
| 332 |
case Keypad.KEY_SHIFT_LEFT : currPressed= BUTTON_CAPS; invalidate(); break; |
|
| 333 |
case Keypad.KEY_ENTER : currPressed= BUTTON_OK ; invalidate(); break; |
|
| 334 |
case Keypad.KEY_DELETE : |
|
| 335 |
case Keypad.KEY_BACKSPACE : currPressed= BUTTON_BKSP; invalidate(); break; |
|
| 336 |
} |
|
| 337 |
|
|
| 338 |
if( key>='A' && key<='Z' ) { currPressed = key-'A' ; invalidate(); }
|
|
| 339 |
if( key>='a' && key<='z' ) { currPressed = key-'a' ; invalidate(); }
|
|
| 340 |
if( key>='0' && key<='9' ) { currPressed = 'z'-'a'+1+key-'0'; invalidate(); }
|
|
| 341 |
*/ |
|
| 342 |
return true; |
|
| 343 |
} |
|
| 344 |
|
|
| 345 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 346 |
|
|
| 347 |
@Override public boolean onKeyUp(int keyCode, KeyEvent event) |
|
| 348 |
{
|
|
| 349 |
buttonReleased(); |
|
| 350 |
return true; |
|
| 351 |
} |
|
| 352 |
|
|
| 353 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 354 |
|
|
| 355 |
private void capsButtonAction() |
|
| 356 |
{
|
|
| 357 |
uppercase = !uppercase; |
|
| 358 |
} |
|
| 359 |
|
|
| 360 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 361 |
|
|
| 362 |
private void okButtonAction() |
|
| 363 |
{
|
|
| 364 |
if ( invoker != null ) |
|
| 365 |
{
|
|
| 366 |
String text = textField.getText(); |
|
| 367 |
|
|
| 368 |
if( text.length()>= minSize ) |
|
| 369 |
invoker.okPressed(text); |
|
| 370 |
} |
|
| 371 |
} |
|
| 372 |
|
|
| 373 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 374 |
|
|
| 375 |
private void bkspButtonAction() |
|
| 376 |
{
|
|
| 377 |
textField.deleteLastChar(); |
|
| 378 |
} |
|
| 379 |
|
|
| 380 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 381 |
|
|
| 382 |
private void charAreaAction(int pressed) |
|
| 383 |
{
|
|
| 384 |
int numCol = (width<height ? lowerCaseP[0].length:lowerCaseL[0].length); |
|
| 385 |
int j = pressed/numCol; |
|
| 386 |
int i = pressed%numCol; |
|
| 387 |
|
|
| 388 |
if( width<height ) |
|
| 389 |
textField.insertNewChar( uppercase ? upperCaseP[j][i]:lowerCaseP[j][i]); |
|
| 390 |
else |
|
| 391 |
textField.insertNewChar( uppercase ? upperCaseL[j][i]:lowerCaseL[j][i]); |
|
| 392 |
} |
|
| 393 |
|
|
| 394 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 395 |
|
|
| 396 |
public void setText(String text) |
|
| 397 |
{
|
|
| 398 |
textField.setText( (text==null||text.length()==0)?"":text); |
|
| 399 |
invalidate(); |
|
| 400 |
} |
|
| 401 |
|
|
| 402 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 403 |
|
|
| 404 |
public void setTextFieldBkgColor(int color) |
|
| 405 |
{
|
|
| 406 |
textField.setTextFieldBkgColor(color); |
|
| 407 |
} |
|
| 408 |
|
|
| 409 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 410 |
|
|
| 411 |
public void setTextFieldBorderColor(int color) |
|
| 412 |
{
|
|
| 413 |
textField.setTextFieldBorderColor(color); |
|
| 414 |
} |
|
| 415 |
|
|
| 416 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 417 |
|
|
| 418 |
public void setTextFieldFontColor(int color) |
|
| 419 |
{
|
|
| 420 |
textField.setTextFieldFontColor(color); |
|
| 421 |
} |
|
| 422 |
|
|
| 423 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 424 |
|
|
| 425 |
public int getBackgroundColor() |
|
| 426 |
{
|
|
| 427 |
return backgroundColor; |
|
| 428 |
} |
|
| 429 |
|
|
| 430 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 431 |
|
|
| 432 |
public void setBackgroundColor(int backgroundColor) |
|
| 433 |
{
|
|
| 434 |
this.backgroundColor = backgroundColor; |
|
| 435 |
} |
|
| 436 |
|
|
| 437 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 438 |
|
|
| 439 |
public void setMaxSize(int maxSize) |
|
| 440 |
{
|
|
| 441 |
textField.setMaxSize(maxSize); |
|
| 442 |
} |
|
| 443 |
|
|
| 444 |
//////////////////////////////////////////////////////////////////////////////// |
|
| 445 |
|
|
| 446 |
public void setMinSize(int minSize) |
|
| 447 |
{
|
|
| 448 |
this.minSize = minSize; |
|
| 449 |
} |
|
Also available in: Unified diff
Add Crashlytics, Analytics, In-App Messaging and Cloud Messaging.