Skip to content

Commit

Permalink
new look and brush width. new Snake
Browse files Browse the repository at this point in the history
  • Loading branch information
quickwritereader committed Dec 13, 2020
1 parent 74c05e9 commit 939060d
Show file tree
Hide file tree
Showing 19 changed files with 582 additions and 334 deletions.
10 changes: 5 additions & 5 deletions KidPhone/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileSdkVersion 29
buildToolsVersion '29.0.3'

defaultConfig {
applicationId "kidtoys.az.kidphone"
minSdkVersion 14
targetSdkVersion 28
versionCode 9
versionName "1.2.1"
targetSdkVersion 29
versionCode 10
versionName "1.3"
}
buildTypes {
release {
Expand Down
14 changes: 12 additions & 2 deletions KidPhone/app/src/main/java/kidtoys/az/kidphone/BaseAnimation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kidtoys.az.kidphone;

import android.util.Log;

/**
* Created by abdurrauf on 7/10/16.
*/
Expand Down Expand Up @@ -59,6 +61,7 @@ public void stop(boolean force){

private static class AnimThread extends Thread implements RenderCallback
{
private static final String TAG = "AnimThread";
private int duration=-1;
private final FunnyDisplayBase display;
private FunnySurface surface;
Expand Down Expand Up @@ -107,6 +110,7 @@ public void run() {
long startTime=System.currentTimeMillis();
boolean forced=false;
if(restoreOld){
//Log.d(TAG,"draw previous");
this.prevSurface=null;
this.prevSurface=display.getSurfaceSnapshot();
}
Expand All @@ -133,19 +137,25 @@ public void run() {
}
if(!forced & !immediate){
if(restoreOld){
//Log.d(TAG,"restore old");
display.copyToSurface(prevSurface);
display.postRender();
}else{
draw();
//Log.d(TAG,"clear 0");
display.clear();
display.postRender();
}

}
//else{
//Log.d(TAG,"force end");
//}

}

private void draw() {
//Log.d(TAG,"draw");
if(isAnimRun()) display.copyToSurface(surface );
else display.clear();
display.postRender();
}

Expand Down
16 changes: 14 additions & 2 deletions KidPhone/app/src/main/java/kidtoys/az/kidphone/BaseMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public BaseMode(Phone phone) throws Exception {
if(phone==null) {
throw new Exception("Phone should not be null");
}

phone.activateDelay(UiHandler.TIME_DELAY);
this.phone=phone;

}
Expand All @@ -35,12 +37,22 @@ public BaseMode(Phone phone) throws Exception {
/**
* It will be called when Mode key pressed
*/
public abstract void onRefresh();
public void onRefresh(){
if(phone!=null) {
phone.activateDelay(UiHandler.TIME_DELAY);
}
}

/**
* Event for saving states of Mode
*/
public abstract void onSave();
public void onSave(){
if(phone!=null) {
phone.deActivateDelay();
phone.stopSpeaker();
phone.getAudio().StopMp3();
}
}


/**
Expand Down
70 changes: 57 additions & 13 deletions KidPhone/app/src/main/java/kidtoys/az/kidphone/CallAnimation.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@
package kidtoys.az.kidphone;

import android.renderscript.Matrix3f;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static kidtoys.az.kidphone.FunnySurfaceUtils.scaleX;
import static kidtoys.az.kidphone.FunnySurfaceUtils.scaleY;
import static kidtoys.az.kidphone.FunnySurfaceUtils.standardFigHeight;
import static kidtoys.az.kidphone.FunnySurfaceUtils.standardFigWidth;

/**
* Created by ramil on 24.07.2016.
*/
public class CallAnimation extends BaseAnimation {


private long timeCall=0;
private int scene=0;
private long timeCall = 0;
private final static List<FunnySurfaceUtils.Primitive> callFigures = Arrays.<FunnySurfaceUtils.Primitive>asList(
new FunnySurfaceUtils.PointObj(10, 10),
new FunnySurfaceUtils.Ellipse(6, 8, 14, 12),
new FunnySurfaceUtils.Ellipse(4, 6, 16, 14),
new FunnySurfaceUtils.Ellipse(2, 4, 18, 16),
new FunnySurfaceUtils.Ellipse(0, 2, 20, 18),
new FunnySurfaceUtils.Ellipse(-2, 0, 22, 20)
);

private final static List<FunnySurfaceUtils.Primitive> front = Arrays.<FunnySurfaceUtils.Primitive>asList(
new FunnySurfaceUtils.Line(0, 0, 8, 8),
new FunnySurfaceUtils.Line(12, 12, 20, 20),
new FunnySurfaceUtils.Line(0, 20, 8, 12),
new FunnySurfaceUtils.Line(12, 8, 20, 0)
);
private int callRing = 0;
private int inc = 1;

public CallAnimation(FunnyDisplayBase display) {
super(display);
callRing= 0;
inc = 1;
}

@Override
protected boolean onDraw(FunnySurface surface) {
boolean drawn=false;
int countX=surface.getWidth()/2 ;
int countY=surface.getHeight()/2;
if(timeCall+50<System.currentTimeMillis()) {
boolean drawn = false;
int centerX = surface.getWidth() / 2;
int centerY = surface.getHeight() / 2;
Matrix3f matrix3f = new Matrix3f();
matrix3f.translate(centerX, centerY);
matrix3f.scale(scaleX, scaleY);
matrix3f.translate(-10, -10);
if (timeCall + 100 < System.currentTimeMillis()) {
surface.clear();
drawn=true;
timeCall=System.currentTimeMillis();
FunnySurface rectA=FunnySurface.createSurface( scene*2 , scene*2 , FunnySurface.DotColor.Orange, FunnySurface.DotType.Star);
surface.putSurface(rectA, countX-scene-1, countY-scene-1);
scene++;
if (scene-4 >=countX) scene = 0;
drawn = true;
timeCall = System.currentTimeMillis();
for (int i = 0; i < callRing; i++) {
FunnySurfaceUtils.Primitive prim = callFigures.get(i);
prim.setpH(2);
prim.setpW(2);
prim.draw(surface, null, FunnySurface.DotColor.Blue, FunnySurface.DotType.Circle, matrix3f);
}
for(FunnySurfaceUtils.Primitive prim:front){
prim.setpH(9);
prim.setpW(9);
prim.draw(surface,null,FunnySurface.DotColor.Black, FunnySurface.DotType.None, matrix3f);
}
if (callRing + inc > callFigures.size()) inc = -1;
if (callRing + inc < 0) inc = 1;
callRing += inc;

}
return drawn;
return drawn;
}

@Override
Expand Down
76 changes: 37 additions & 39 deletions KidPhone/app/src/main/java/kidtoys/az/kidphone/CallMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public class CallMode extends BaseMode implements SoundCallBack {
private int dial_audio_id;
private boolean enableCallbacks;

public enum LAST_TYPE {NONE,SUCCESS_CALL,ANSWER,ABORT,DIAL}
public LAST_TYPE last_type=LAST_TYPE.NONE;
public enum LAST_TYPE {NONE, SUCCESS_CALL, ANSWER, ABORT, DIAL}

public LAST_TYPE last_type = LAST_TYPE.NONE;

public int[] getCallSoundArray(int index) {
switch (index) {
Expand All @@ -51,7 +52,7 @@ public int[] getCallSoundArray(int index) {

public CallMode(Phone phone) throws Exception {
super(phone);
FunnyDisplayBase display=phone.getDisplay();
FunnyDisplayBase display = phone.getDisplay();
surface = new FunnySurface(display.getSurfaceWidth(), display.getSurfaceHeight());
callAnimation = new CallAnimation(display);
callNoAnimation = new CallNoButtonAnim(display);
Expand All @@ -61,33 +62,32 @@ public CallMode(Phone phone) throws Exception {
private boolean handleKeys = true;



@Override
public void onClick(FunnyButton funnyButton) {
if (funnyButton.getId() == R.id.buttonNo) {
if (isNoActive) {
isNoActive = false;
isNoPressed = true;
handleKeys=false;
handleKeys = false;
phone.stopSpeaker(true);
last_type=LAST_TYPE.ABORT;
last_type = LAST_TYPE.ABORT;
callNoAnimation.start();
audio.PlayMp3(R.raw.busy_signal,this);
audio.PlayMp3(R.raw.busy_signal, this);
return;
} else {
readyToCall();
}
}else if(funnyButton.getId()==R.id.buttonYes){
} else if (funnyButton.getId() == R.id.buttonYes) {
call();
}
if (funnyButton.getKeyMode() == FunnyButton.KeyMode.Numbers) {
String number = funnyButton.getNumbersText();
if (number.length() > 0 && handleKeys) {
phone.stopSpeaker();
isNoActive = false;
char num=number.charAt(0);
last_type=LAST_TYPE.DIAL;
audio.playKeypadTones(num,this);
char num = number.charAt(0);
last_type = LAST_TYPE.DIAL;
audio.playKeypadTones(num, this);

adjust_draw(num);
}
Expand All @@ -97,16 +97,15 @@ public void onClick(FunnyButton funnyButton) {

private void adjust_draw(char number) {
dialedNumber = dialedNumber + number;
int w=(FunnySurfaceUtils.standardCharWidth +1)*FunnySurfaceUtils.scaleX;
int w = (FunnySurfaceUtils.standardCharWidth + 1) * FunnySurfaceUtils.scaleX;

if(dialedNumber.length()>3){
dialedNumber=dialedNumber.substring(dialedNumber.length()-3);
if (dialedNumber.length() > 3) {
dialedNumber = dialedNumber.substring(dialedNumber.length() - 3);
//shift left previous ones
surface.putSurface(surface, -w , 0);
surface.clear( 2 * w ,0,surface.getWidth(),surface.getHeight());
surface.putSurface(surface, -w, 0);
surface.clear(2 * w, 0, surface.getWidth(), surface.getHeight());

}
else if (dialedNumber.length() == 1) {
} else if (dialedNumber.length() == 1) {
surface.clear();
}
if (dialedNumber == null || dialedNumber.length() < 1) return;
Expand All @@ -115,30 +114,31 @@ else if (dialedNumber.length() == 1) {
//exclude white and black

int colorRandom = (int) (Math.random() * (FunnySurface.getMaxColorSupport() - 2)) + 1;
int i=dialedNumber.length()-1;
FunnySurfaceUtils.drawChar(surface, i * w+w/2 , surface.getHeight()/2, number,
int i = dialedNumber.length() - 1;
FunnySurfaceUtils.drawChar(surface, i * w + w / 2, surface.getHeight() / 2, number,
FunnySurface.supportedColors[colorRandom],
FunnySurface.supportedTypes[figureRandom], true);
int length = dialedNumber.length() * w;
FunnySurface displaySurface=phone.getDisplay().getSurface();
FunnySurface displaySurface = phone.getDisplay().getSurface();
try {
displaySurface.lock();
displaySurface.clear();

displaySurface.putSurface(surface, (int)(Math.ceil((surface.getWidth()-length)/2.f)), 0);
}finally {
displaySurface.putSurface(surface, (int) (Math.ceil((surface.getWidth() - length) / 2.f)), 0);
} finally {
displaySurface.unlock();
}
phone.getDisplay().render();
}

@Override
public void onRefresh() {
enableCallbacks=true;
readyToCall();
super.onRefresh();
enableCallbacks = true;
readyToCall();
}

public void readyToCall(){
public void readyToCall() {
audio = phone.getAudio();
isNoActive = false;
handleKeys = true;
Expand All @@ -159,16 +159,13 @@ public void readyToCall(){
@Override
public void onSave() {
//change delay to standard
enableCallbacks=false;
phone.deActivateDelay();
phone.activateDelay();
phone.stopSpeaker();
super.onSave();
enableCallbacks = false;
callAnimation.stop(true);
callNoAnimation.stop(true);
audio.StopMp3();
}

public void call(){
public void call() {
if (dialedNumber.length() >= 3) {
int index;
switch (dialedNumber) {
Expand Down Expand Up @@ -200,25 +197,26 @@ public void call(){
isNoPressed = false;
callAnimation.start();
handleKeys = false;
last_type=LAST_TYPE.SUCCESS_CALL;
last_type = LAST_TYPE.SUCCESS_CALL;
audio.PlayMp3(R.raw.dial_tone, this);

dialedNumber = "";
}
}

@Override
public void soundPlayFinished() {
if(!enableCallbacks) return;
switch (last_type){
if (!enableCallbacks) return;
switch (last_type) {
case NONE:
break;
case SUCCESS_CALL:
callAnimation.stop(true);
if (!isNoPressed) {
phone.startSpeaker();
last_type=LAST_TYPE.ANSWER;
audio.PlayMp3(dial_audio_id, this);
}
phone.startSpeaker();
last_type = LAST_TYPE.ANSWER;
audio.PlayMp3(dial_audio_id, this);
}
break;
case ABORT:
callNoAnimation.stop(false);
Expand Down

0 comments on commit 939060d

Please sign in to comment.