In my Activity I've a Method which must repeat until the user clicks on a button
private void AnimateItem(int i){
((AnimationDrawable) myList.getChildAt(i).getBackground()).start();
}
private void CheckItems(){
int[] items = new int[]{1,3,5};
for(int i = 0; i<items.length(); i++){
AnimateItem(i);
}
}
So, here I'll have:
AnimateItem(1);
AnimateItem(3);
AnimateItem(5);
How to execute methods one by one (when 1st was ended, start 2nd... and repeating cycle after last method end) until button was clicked.
Instead on AnimateItem(i) method of yours, if your activity implements AnimationListener we can over ride following methods
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if (animation == your desired Animation) {
//start your new Animation
}
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
Related
I want to make some text appear after an animation like rotating for 2min.
I tried using method like isRunning() in Animator but didn't work.
ObjectAnimator object = ObjectAnimator.ofFloat(ima, "rotation", 1080);
object.setInterpolator(new AccelerateInterpolator());
object.setDuration(1000);
object.setRepeatCount(0);
object.start();
boolean bo = object.isRunning();
while(!bo) {
Random ran = new Random();
int count = ran.nextInt(10);
String str = Integer.toString(count);
text.setText(str);
bo = true ;
}
Take your animation object and add animation listener to it
rotatationAnimation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
**// set your text visisbilty **
}
});
To listen to an ObjectAnimator, just add the following code :
object.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animator) {
}
#Override
public void onAnimationEnd(Animator animator) {
/*make your text appear*/
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
I hope I could have helped you!
I am using rxjava in eclipse. I cretaed the below posted example.
the issue is,, when i run the code, I receive only
onSubscribe: 0
and I dont receive any output from onNext.
please let me know why I do not receive any output from onNext, and how to fix it
code:
public static void main(String[] args) {
Observable<String> stringObservable = Observable.just("Hello from just Operator1");
stringObservable
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(new Observer<Object>() {
#Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("onComplete: OK");
}
#Override
public void onError(Throwable arg0) {
// TODO Auto-generated method stub
}
#Override
public void onNext(Object arg0) {
// TODO Auto-generated method stub
System.out.println("onNext: " + (String) arg0);
}
#Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
System.out.println("onSubscribe: " + arg0);
}
});
}
I made a game and used an ads company on it (StartApp). I wanna use Interstitial Ads on it. I followed the step they show but can't achieve it. I'm getting error. Here is the LogCat:
http://i.stack.imgur.com/SaIXE.png
Here is the codes:
GameActivity.java
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws IOException
{
StartAppAd.init(this, "10254544", "20454573");
}
MenuScene.java
private StartAppAd startAppAd = new StartAppAd(activity);
#Override
public void createScene() {
startAppAd.showAd();
startAppAd.loadAd();
}
Check the Manifest.xml file. Be sure you wrote the right package name in there.
Try This code and u should update manifest file also
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StartAppSearch.showSearchBox(this);
StartAppAd.init(this, "107181003", "211487617");
StartAppSearch.init(this, "107181003", "211487617");
btnnext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); //load next add
Intent intent=new Intent(getApplicationContext(),Second.class);
startActivity(intent);
}
});
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
boolean _active = true;
}
return true;
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
startAppAd.onPause();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
startAppAd.onResume();
}
#Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
private StartAppAd startAppAd = new StartAppAd(this);
#Override
public void onBackPressed() {
startAppAd.onBackPressed();
super.onBackPressed();
}
and update in manifest file also
You can not use the
startAppAd.showAd();
startAppAd.loadAd();
inside the Scene class (MenuScene). Instead you can try below method.
In GameActivity class you must be having KeyEvent method. put the code to show the startApp ads in there as below,
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
if(SceneManager.getInstance().getCurrentSceneType().toString() == "SCENE_MENU"){
try{
startAppAd.showAd(); // show the ad
startAppAd.loadAd(); // load the next ad
}catch(Exception e){
}
}
try{
SceneManager.getInstance().getCurrentScene().onBackKeyPressed();
}catch(Exception e){
}
}
return false;
}
Regards,
Deepak
i have to read data from finger print reader and convert into image file. I am using Digital Persona 's device U and U 4500 with Platinum SDK . I am new biometric field. Till now I am only able to detect the device means whether it is connected to system or not.Please guide me what should i do to accomplish this task
i have used this Code(only to check whether device is working )
import com.digitalpersona.onetouch.DPFPGlobal;
import com.digitalpersona.onetouch.DPFPSample;
import com.digitalpersona.onetouch.capture.DPFPCapture;
import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
import com.digitalpersona.onetouch.capture.event.DPFPDataListener;
import com.digitalpersona.onetouch.capture.event.DPFPErrorEvent;
import com.digitalpersona.onetouch.capture.event.DPFPErrorListener;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusListener;
import com.digitalpersona.onetouch.capture.event.DPFPSensorEvent;
import com.digitalpersona.onetouch.capture.event.DPFPSensorListener;
public class Demo {
public static void main(String args[]){
//byte[] a=null;
DPFPCapture capture=DPFPGlobal.getCaptureFactory().createCapture();
capture.addReaderStatusListener(new DPFPReaderStatusListener() {
#Override
public void readerDisconnected(DPFPReaderStatusEvent arg0) {
//TODO Auto-generated method stub
System.out.println("I m Dis-connected");
}
#Override
public void readerConnected(DPFPReaderStatusEvent arg0) {
// TODO Auto-generated method stub
System.out.println("I m connected");
}
});
capture.addSensorListener(new DPFPSensorListener() {
#Override
public void imageAcquired(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("acquired");
}
#Override
public void fingerTouched(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("s");
}
#Override
public void fingerGone(DPFPSensorEvent arg0) {
// TODO Auto-generated method stub
System.out.print("gone");
}
});
capture.startCapture();
capture.addDataListener(new DPFPDataListener() {
#Override
public void dataAcquired(DPFPDataEvent arg0) {
// TODO Auto-generated method stub
DPFPSample sample=DPFPGlobal.getSampleFactory().createSample();
sample=arg0.getSample();
byte a[]=sample.serialize();
for(byte i:a){
System.out.print(i);
}
}
});
capture.addErrorListener(new DPFPErrorListener() {
#Override
public void exceptionCaught(DPFPErrorEvent arg0) {
// TODO Auto-generated method stub
System.out.println("error");
}
#Override
public void errorOccured(DPFPErrorEvent arg0) {
// TODO Auto-generated method stub
System.out.println("error");
}
});
}
}
I am also currently working on a Digital Persona Finger Print Reader, I actually had the same Problem but now i have overcome it,
I think the code to add the Listeners should be in the init() method and also start the init method in the constructor of the class
The main method should only instantiate the Class.
I have the following code:
public boolean stopped = false;
public void fadeOut(final ImageView obj, final int time, int delay)
{
if(stopped)
{
stopped = false;
anim = new AlphaAnimation(1.00f, 0.00f);
anim.setDuration(time);
if(delay > 0)
{
anim.setStartOffset(delay);
}
anim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.v("FADER", "Fading out. Duration: " + time + "ms.");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.v("FADER", "Fading out finished.");
//obj.setAlpha(255);
stopped = true;
}
});
obj.startAnimation(anim);
}
}
and this code works fine. My object (an ImageView) fades out beautifully. But when I run this:
public void fadeIn(final ImageView obj, final int time, int delay)
{
if(stopped)
{
stopped = false;
anim = new AlphaAnimation(0, 1);
anim.setDuration(time);
if(delay > 0)
{
anim.setStartOffset(delay);
}
anim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.v("FADER", "Fading in. Duration: " + time + "ms.");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.v("FADER", "Fading in finished.");
//obj.setAlpha(255);
stopped = true;
}
});
obj.startAnimation(anim);
}
}
It doesn't work - there is no fading in. The ImageView stays completely transparent.
Why is this, any ideas?
And for those who are wondering, yes, I have declared and set the boolean stopped, so it's not the issue, because when I look at LogCat, it's printing the text as it runs the fadeIn() function.
Solved!
Turns out, if you use [ImageView Object].setAlpha, and set it to 0 for instance, then when you run AlphaAnimation, it works between the boundaries of 0 and the current alpha of the image.
So, if you want to keep the image invisible after fadeout, the solution is to use [ImageView Object].setVisibility(View.INVISIBLE), and just set it back to View.VISIBLE before you run your animation.
Mission Accomplished.
Is your view's visibility set to View.VISIBLE?