Skip to content

Commit

Permalink
BackgroundTasks, Notifications TestCases
Browse files Browse the repository at this point in the history
  • Loading branch information
pavly-gerges committed May 21, 2021
1 parent b65e49d commit b26442b
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 43 deletions.
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "org.jmonkeyengine:jme3-core:3.4.0-beta3"
implementation "org.jmonkeyengine:jme3-effects:3.4.0-beta3"
implementation "org.jmonkeyengine:jme3-android-native:3.4.0-beta3"
implementation "org.jmonkeyengine:jme3-core:3.4.0-beta4"
implementation "org.jmonkeyengine:jme3-effects:3.4.0-beta4"
implementation "org.jmonkeyengine:jme3-android-native:3.4.0-beta4"
implementation 'com.github.Scrappers-glitch:Superior-Extended-Engine:1.5.1-alpha2'
implementation "androidx.work:work-runtime:2.5.0"
implementation "androidx.concurrent:concurrent-futures:1.1.0"

}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".notifications.OnActionsListener"
/>
</application>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.ImageView;
Expand All @@ -21,9 +24,11 @@
import android.widget.Toast;
import com.jme3.anim.AnimComposer;
import com.jme3.anim.TransformTrack;
import com.jme3.anim.tween.action.Action;
import com.jme3.app.Application;
import com.jme3.app.jmeSurfaceView.JmeSurfaceView;
import com.jme3.app.state.BaseAppState;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.scrappers.dbtraining.R;
Expand All @@ -38,10 +43,16 @@
import com.scrappers.dbtraining.mainScreens.prefaceScreen.renderer.animationWrapper.builders.AnimEventEntity;
import com.scrappers.dbtraining.mainScreens.prefaceScreen.renderer.triggersUtils.TriggerID;
import com.scrappers.dbtraining.mainScreens.prefaceScreen.renderer.triggersUtils.TriggerModel;
import com.scrappers.dbtraining.notifications.NotificationUtils;
import com.scrappers.superiorExtendedEngine.menuStates.UiStateManager;
import com.scrappers.superiorExtendedEngine.menuStates.UiStatesLooper;
import com.scrappers.superiorExtendedEngine.menuStates.uiPager.UiPager;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import static android.view.View.GONE;
Expand All @@ -52,6 +63,7 @@
import static com.scrappers.dbtraining.mainScreens.prefaceScreen.renderer.Scene.defaultStack;
import static com.scrappers.dbtraining.mainScreens.prefaceScreen.renderer.Scene.defaultThree;
import static com.scrappers.dbtraining.mainScreens.prefaceScreen.renderer.Scene.defaultTwo;
import static com.scrappers.dbtraining.notifications.BackgroundTask.NOTIFICATION_REQUEST;

/**
* @author pavl_g
Expand All @@ -66,6 +78,8 @@ public class AnimationFactory extends BaseAppState implements View.OnClickListen
private float timer=0.0f;
private static final char SCROLLABLE_CONTENT = 'S' + 'C' + 'R' + 'O' + 'L' + 'L';
private static boolean gridOn = false;
private EmitterTween emitterTween;

public AnimationFactory(Spatial dataBaseStack, JmeSurfaceView jmeSurfaceView) {
this.dataBaseStack=dataBaseStack;
this.jmeSurfaceView=jmeSurfaceView;
Expand Down Expand Up @@ -109,26 +123,26 @@ protected void initialize(Application app) {
getStateManager().attach(new BasicArmature("BasicArmatureTrack", dataBaseStack));
getStateManager().attach(new StackLoops("StackLoopsTrack", dataBaseStack));
getStateManager().attach(new BasicTween("BasicTweenTrack", dataBaseStack));
EmitterTween emitterTween = new EmitterTween("EmitterTween", dataBaseStack);
emitterTween = new EmitterTween("EmitterTween", dataBaseStack);
emitterTween.setAnimationEvents(new AnimEventEntity.AnimationEvents() {
@Override
public void onAnimationStart(AnimComposer animComposer, TransformTrack transformationStart) {
public void onAnimationStart(AnimComposer animComposer, Action transformationStart) {

}

@Override
public void onAnimationEnd(AnimComposer animComposer, TransformTrack transformEnd) {
public void onAnimationEnd(AnimComposer animComposer, Action transformEnd) {
jmeSurfaceView.getLegacyApplication().enqueue(()->{
// emitterTween.electricWaves1.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves2.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves3.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves4.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves5.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves6.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves7.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves8.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves9.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
// emitterTween.electricWaves10.getMaterial().setColor("GlowColor",ColorRGBA.randomColor().mult(ColorRGBA.Blue));
emitterTween.electricWaves1.getMaterial().setColor("GlowColor", ColorRGBA.randomColor());
emitterTween.electricWaves2.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves3.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves4.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves5.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves6.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves7.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves8.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves9.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
emitterTween.electricWaves10.getMaterial().setColor("GlowColor",ColorRGBA.randomColor());
});
}

Expand Down Expand Up @@ -177,6 +191,7 @@ public void update(float tpf) {
}
}

@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onClick(View v) {
if(v.getId()==R.id.animationSettings){
Expand All @@ -200,7 +215,16 @@ public void onClick(View v) {
}
});
Toast.makeText(jmeSurfaceView.getContext(),"Resettled the Scene !", LENGTH_LONG).show();

emitterTween.electricWaves1.getMaterial().setColor("GlowColor", ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves2.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves3.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves4.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves5.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves6.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves7.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves8.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves9.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
emitterTween.electricWaves10.getMaterial().setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
}else if(v.getId() == R.id.gridSwitcher){
if(gridOn){
gridOn = false;
Expand All @@ -217,8 +241,12 @@ public void onClick(View v) {
R.color.lightBlack),ContextCompat.getColor(v.getContext(),R.color.lightBlack)});
invalidateUiPager(gridOn);
}else if(v.getId() == R.id.dismissForever){

((ViewGroup)((ViewGroup)v.getParent()).getParent()).setVisibility(GONE);
Toast.makeText(jmeSurfaceView.getContext(), "Powered By Jme Android", Toast.LENGTH_LONG).show();

NotificationUtils.initializeInBackground(jmeSurfaceView.getContext());

}else if(v.getId() == TriggerID.closeTrigger){

((RelativeLayout)jmeSurfaceView.getParent()).findViewById(R.id.animationSettings).animate().setDuration(600).rotation(-45).start();
Expand Down Expand Up @@ -381,9 +409,7 @@ protected void invalidateUiPager(boolean gridOn){
}
uiPager.attachUiState(relativeLayout, UiPager.SEQUENTIAL_ADD);
}
uiPager.attachUiState(topUpMenu ,0);
uiPager.invalidate();

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class BlendableAnimation extends BaseAppState implements BlendSpace {
private BlendAction blendAction;
private BaseAction baseAction;
private float count = 0;
private static final float minValueOfBlendSlider = 6;
private static final float maxValueOfBlendSlider = 12;
public BlendableAnimation(final String id, final Spatial dataBaseStack){
super(id);
this.dataBaseStack=dataBaseStack;
Expand Down Expand Up @@ -98,8 +100,7 @@ protected void initialize(Application app) {
capRotationClip.setLength(10f);
capRotationClip.setTransitionLength(10f);
//9)feed the BlendableActions to a single BlendAction
float minValueOfBlendSlider = 6;
float maxValueOfBlendSlider = 12;

linearBlendSpace = new LinearBlendSpace(minValueOfBlendSlider, maxValueOfBlendSlider);
linearBlendSpace.setValue(FastMath.interpolateLinear(0.5f, 6, 12));
blendAction=new BlendAction(linearBlendSpace, capRotationClip, bottleTractionClip);
Expand Down Expand Up @@ -139,7 +140,7 @@ protected void onDisable() {
public void update(float tpf) {
count += tpf;
if(count > blendAction.getLength()){
linearBlendSpace.setValue(FastMath.interpolateLinear(1, 6, 12));
linearBlendSpace.setValue(FastMath.interpolateLinear(1f, minValueOfBlendSlider, maxValueOfBlendSlider));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ protected void initialize(Application app) {
electricWavesTrack10.setTarget(electricWaves10);
shockThunderTrack.setTarget(shockThunder);

setTransformTrack(electricWavesTrack1);

//1st track
electricWavesTrack1.setTimes(new float[]{2,4,8,16});
Expand Down Expand Up @@ -324,6 +323,8 @@ protected void initialize(Application app) {
//make a new Animation Layer that would hold a one current running action.....
animComposer.makeLayer(LayerBuilder.LAYER_EMITTER_TWEEN, new ArmatureMask());

setAction(shockMyScreen);

}

@Override
Expand All @@ -346,6 +347,7 @@ protected void onEnable() {
animComposer.setEnabled(true);
//run shockMyScreen action
animComposer.setCurrentAction("ShockMyScreen", LayerBuilder.LAYER_EMITTER_TWEEN);

}
if(shockThunder!=null &&
(shockThunder.getStatus()== AudioSource.Status.Paused || shockThunder.getStatus()== AudioSource.Status.Stopped)){
Expand All @@ -372,7 +374,7 @@ private ParticleEmitter loadElectricWaves(int id){
electrics.setTexture("Texture", getApplication().getAssetManager().loadTexture("AssetsForRenderer/Textures/Fire.png"));
electrics.setTexture("GlowMap", getApplication().getAssetManager().loadTexture("AssetsForRenderer/Textures/Fire.png"));
electrics.selectTechnique("Glow",getApplication().getRenderManager());
electrics.setColor("GlowColor",ColorRGBA.Blue.mult(50f));
electrics.setColor("GlowColor",ColorRGBA.Cyan.mult(50f));
electricWaves.setMaterial(electrics);
electricWaves.getParticleInfluencer().setInitialVelocity(Vector3f.ZERO.negate().mult(5.5f));
electricWaves.setImagesX(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ protected void initialize(Application app) {

/*set the bone or the spatial*/
transformTrack.setTarget(stackOne);
/*set the transformTrack to be used by the animationEvents*/
setTransformTrack(transformTrack);

//the frame tracks are in-sequence or in parallel with each transform track , notice it must be in a pattern form , in which the proceeding value
//is delayed by (n) * the preceding value , n is scaleFactor of delayFactor , is determinant by the coder , here its simply 2.
Expand Down Expand Up @@ -106,6 +104,9 @@ protected void initialize(Application app) {
*/
animComposer.addAction(clip.getName(), new ClipAction(clip));
animComposer.makeLayer(LayerBuilder.LAYER_SIMPLE_TRACK, new ArmatureMask());
/*set the transformTrack to be used by the animationEvents*/
setAction(animComposer.getAction(clip.getName()));

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.jme3.anim.AnimComposer;
import com.jme3.anim.TransformTrack;
import com.jme3.anim.tween.action.Action;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.math.FastMath;

public class AnimEventEntity extends BaseAppState {
protected AnimationEvents animationEvents;
private float counter=0f;
private int keyFrameIndex=1;
private AnimComposer animComposer;
private TransformTrack transformTrack;
private Action action;
private float delayStartCounter=0;
private float delayEndCounter=0;
private float delayStart = 0.2f;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void update(float tpf) {
if(delayStartCounter >= delayStart ){
//fire an event on the start of the Animation --works fine--
if ( animationEvents != null ){
animationEvents.onAnimationStart(animComposer, transformTrack);
animationEvents.onAnimationStart(animComposer, action);
}
delayStartCounter = 0f;
}
Expand All @@ -55,22 +55,16 @@ public void update(float tpf) {
counter += tpf;
keyFrameIndex += 1;

if ( (keyFrameIndex < transformTrack.getTimes().length-1) && (counter >= FastMath.interpolateLinear(1, transformTrack.getTimes()[keyFrameIndex-1], transformTrack.getTimes()[keyFrameIndex])) ){
//fire an event between the current interpolated frames --Cannot figure this out--WIP--
if ( animationEvents != null ){
animationEvents.onAnimationShuffle(animComposer ,transformTrack, keyFrameIndex-1, keyFrameIndex);
}
}else if (counter >= transformTrack.getLength()/6f){
if ( delayEndCounter >= delayEnd ){
if (counter > action.getLength()/6f){
//fire an end event --works fine--
if ( animationEvents != null ){
animationEvents.onAnimationEnd(animComposer, transformTrack);
animationEvents.onAnimationEnd(animComposer, action);
}
//reset everything
counter = 0;
keyFrameIndex = 1;
delayEndCounter = 0f;
}

}

}
Expand All @@ -90,12 +84,17 @@ public int getKeyFrameIndex() {
return keyFrameIndex;
}

public void setTransformTrack(TransformTrack transformTrack) {
this.transformTrack = transformTrack;
public void setAction(Action action) {
this.action = action;
}

public Action getAction() {
return action;
}

public interface AnimationEvents{
void onAnimationStart(AnimComposer animComposer, TransformTrack transformationStart);
void onAnimationEnd(AnimComposer animComposer, TransformTrack transformEnd);
void onAnimationStart(AnimComposer animComposer, Action transformationStart);
void onAnimationEnd(AnimComposer animComposer, Action transformEnd);
void onAnimationShuffle(AnimComposer animComposer, TransformTrack transformTrack, int i, int keyFrameIndex);
}

Expand Down
Loading

0 comments on commit b26442b

Please sign in to comment.