Shorter delay in android slideshow - android

So im making a slideshow in android that i want to move very fast to look almost as though an animation. Bellow is the code that i am using but i want it go move faster(smaller delay) but i cant make the postDelay any smaller. How would i do this? If its not possible what would a better way to do this be?
private Runnable runnable = new Runnable() {
public void run() {
myslideshow();
handler.postDelayed(this, 1);
}
};
private void myslideshow()
{
if (position < imageIDs.length){
iv.setImageResource(imageIDs[position]);
position++;
}
else{
iv.setImageResource(R.drawable.logo);
}
}

Could the Android Animation API help instead?

You can use a gallery. On click of some button or anything you can run a for loop to
display next element in the gallery till the last element (image in your case) is displayed

Related

android: checking and changing image of button

in my application i'm checking image of button for 1sec.n changing it.what happen is when first time it checks n changes image of button.and the 2nd time its not changing the image.
here is the code-
myTimer.schedule(new TimerTask() {
#Override
public void run() {
runOnUiThread(new Runnable() {
public void run() {
Random rand=new Random();
int num = rand.nextInt(buttonIds.length);
int buttonId = buttonIds[num];
Button bb=(Button) findViewById(buttonId);
Drawable a=bb.getBackground();
if(getResources().getDrawable(R.drawable.happy).equals(a))
{
bb.setBackgroundResource(R.drawable.happy);
}
else
{
bb.setBackgroundResource(R.drawable.whoa);
}
}
});
}
},0, 1000);
first time image of button is happy(name of image file).
how can i change image of button and also check??
Thanku
I think your if condition is not correct, you a checking if the background image is happy, you are again setting happy..instead you should set whoa...
If I were you, I would use a boolean(isHappy) to notify if the picture is happy or not, it is easier and faster since you don't have to instance the current image and maybe it will solve your problem, I am not completely sure about "equals" works like that, but is only my guess.
Anyway I think your code has a small mistake, the condition makes the picture to be always happy.

Highlight buttons one at a time

I am making an Android game modeled after the old Simon game. It is a little different in the layout as it is using a 3x3 layout of buttons. I am trying to get the buttons to light up one at a time inside the loop that randomly selects a button. The trouble I have is that all of the buttons light up at once and only the last (or first, not sure) changes back to the original color. I have tried very thoroughly to find an appropriate answer to my situation but have had no luck here or elsewhere. The button id(s) are in the butts[]. butts[0] is button 1, butts[2] ... Below is my attempt.
public void play()
{
for(int x = 0; x <= numButtons; ++x)
{
spot = randomGenerator.nextInt(9);
playMe[x] = spot;
//butts[spot].setBackgroundColor(Color.parseColor("#540115"));
handler.postDelayed(new Runna(spot), (x+1)*1000);
}
}
class Runna implements Runnable
{
public Runna(int j2)
{
butts[j2].setBackgroundColor(Color.parseColor("#540115"));
}
public void run()
{
butts[spot].setBackgroundColor(Color.LTGRAY);
}
}
I think it has to do with the value of spot. It is global to the functions and you change it every time. It runs, but at the end there is still only one spot and EVERY runnable is trying to change that same spot.
Perhaps save spot in your runnable?
class Runna implements Runnable
{
int s;
public Runna(int j2)
{
s = j2;
butts[s].setBackgroundColor(Color.parseColor("#540115"));
}
public void run()
{
butts[s].setBackgroundColor(Color.LTGRAY);
}
}
Have you tried to invalidate the button each time?
public Runna(int j2)
{
butts[j2].setBackgroundColor(Color.parseColor("#540115"));
butts[j2].invalidate();
}

Android button animations synchronize with timing

I need an advice how to create some animations I want to add in my buttons. Actually I have the animation code, the thing which I need is how to set properly the timing of each one. Here is what I tried already :
fest.setVisibility(View.INVISIBLE);
handler.postDelayed(new Runnable() {
#Override
public void run() {
fest.setVisibility(View.VISIBLE);
fest.startAnimation(anim);
handler.removeCallbacks(this);
}
}, 500);
This is the things which I did for 7 buttons. First I set the visibility to invisible because I want to achieve the effect that they are appearing after 5 miliseconds after onCreate and for every next button I am increasing the delay time with 5 miliseconds so every of them to appear after the previos one. But the problem in this code is that when the next handler starts for the second button for example, the previos button is getting invisible for a part of the seconds and shows again(I hope someone understand what I mean).
Any suggestions for a bette implementation of something like that?
Thanks in advance!
So here is the thing which fixed that problem. I used this for every button and it's working as I want :
final Handler festHandler = new Handler();
festHandler.postDelayed(new Runnable() {
#Override
public void run() {
Animation anim = AnimationUtils.loadAnimation(Menu.this, R.anim.fadein);
fest.setVisibility(View.VISIBLE);
fest.startAnimation(anim);
festHandler.removeCallbacks(this);
}
}, 400);

Dynamic ImageView in android

I'm a newbie in android so please don't judge me hard.
I'm trying to create a screen with two areas, an image area and a text area.
In the image area several images should be changed within a periodical time, 3-4 seconds. (Please see the image: )
Can you please give me an example how can I accomplish this?
Thank you.
You can use CountDownTimer class for this.
Or you can use a Gallery with Thread and Handler to achieve this.
Here is a link to the project called AutoSlideGallery,
https://github.com/nixit28/AutoSlideGallery
The core logic is here,
(new Thread() {
public void run() {
myslideshow();
handler.postDelayed(this, 2000); // execute every two second.
}
}
).start();
And the method which performs the action,
private void myslideshow() {
PicPosition = gallery.getSelectedItemPosition() + 1;
if (PicPosition >= pics.length)
gallery.setSelection(0); // stop
else
gallery.setSelection(PicPosition);// move to the next gallery
// element.
}

Delayed image capturing

I know that is easy to fire an intent for image capturing and then after the user press on the capture button to take the image location of the image...
But I want to do something like this:
-user press a button
-camera app is started
-after 10seconds the image is taken automatically (no user interaction needed)
i think for your custom use case, you could write your own camera activity and then capture at 10 seconds
Edit: you can use this tutorial http://code.google.com/p/openmobster/wiki/CameraTutorial
Also the camera preview is present in apidemos application. It is present at Graphics->CameraPreview.
hmmm, maybe have a handler with a counter updating a TextView every second (So the app isnt seen as frozen) and then once the counter has reached ten take the photo
int counter2 = 0;
private Runnable mUpdateTimeTask2 = new Runnable() {
public void run() {
if (counter2 == 10){
takepicture();
}
counter2++;
mHandler.postDelayed(this, 1000);
}
};

Categories

Resources