Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onDraw(Canvas canvas) {
- for (int i=0; i < GlobalVars.getInstance().WHITE_COUNT; i++) {
- canvas.drawRect(whites.get(i).rect, i == 23 ? downKeyColor : whiteKeyColor);
- canvas.drawLine(whites.get(i).rect.left, top_pad, whites.get(i).rect.left, height, blackLineColor);
- }
- canvas.drawLine(0, top_pad, width, top_pad, blackLineColor);
- canvas.drawLine(0, height, width, height, blackLineColor);
- for (Key k : blacks) {
- canvas.drawRect(k.rect, blackKeyColor);
- }
- canvas.drawRect(0, 0, keyWidth * GlobalVars.getInstance().START_WITH, height, rectColor);
- canvas.drawRect(keyWidth * (GlobalVars.getInstance().START_WITH + GlobalVars.getInstance().DISPLAY_COUNT), 0, width, height, rectColor);
- canvas.drawRect(0, 0, 10, height, borderColor);
- canvas.drawRect(width - 10, 0, width, height, borderColor);
- canvas.drawRect(0, 0, width, 10, borderColor);
- canvas.drawRect(0, height - 10, width, height, borderColor);
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- int action = MotionEventCompat.getActionMasked(event);
- boolean isDownAction = action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE || action == MotionEvent.ACTION_POINTER_DOWN;
- boolean isUp = action == MotionEvent.ACTION_UP || MotionEvent.ACTION_POINTER_UP == action;
- double x = event.getX(event.getActionIndex()) - keyWidth * (GlobalVars.getInstance().DISPLAY_COUNT / 2);
- if (x < 0)
- x = 0;
- if (x > keyWidth * (GlobalVars.getInstance().WHITE_COUNT - GlobalVars.getInstance().DISPLAY_COUNT))
- x = keyWidth * (GlobalVars.getInstance().WHITE_COUNT - GlobalVars.getInstance().DISPLAY_COUNT);
- x = x / keyWidth;
- KeyboardView k = MainActivity.getInstance().findViewById(R.id.keyboardView);
- RunAnimation thread = new RunAnimation(k, this, GlobalVars.getInstance().START_WITH, (float) Math.floor(x));
- thread.start();
- return true;
- }
- public void Animate(final KeyboardView k, final KeyboardViewSmall ks){
- MainActivity.getInstance().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- k.onSizeChanged(k.width, k.height, k.width, k.height);
- k.invalidate();
- ks.invalidate();
- }
- });
- }
- class RunAnimation extends Thread {
- private KeyboardView k;
- private KeyboardViewSmall ks;
- private float start, end;
- public RunAnimation(KeyboardView k, KeyboardViewSmall ks, float start, float end) {
- this.k = k;
- this.ks = ks;
- this.start = start;
- this.end = end;
- }
- @Override
- public void run() {
- try {
- float s = start;
- while (abs(s - end) > 0.01) {
- if (s > end)
- s -= 0.2;
- else
- s += 0.2;
- GlobalVars.getInstance().START_WITH = s;
- Animate(k, ks);
- sleep(1);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- GlobalVars.getInstance().START_WITH = end;
- MainActivity.getInstance().SaveVariables();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement