My slide show Activity is one of my list view rows , when click the slideshow row it must open slide images with animation but there is a delay of around 25 second till first image appear , i try to change the time here:
int delay = 1000;
but that not fix it ,
any help will be appreciated , thanks
public class SlideShow extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
private int[] IMAGE_IDS = {
R.drawable.day_one_1, R.drawable.day_one_2,R.drawable.day_one_3,
R.drawable.day_one_4, R.drawable.day_one_5,R.drawable.day_one_6,R.drawable.day_one_7,
R.drawable.day_one_8, R.drawable.day_one_9,R.drawable.day_one_10
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.slide);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
TextView tv = (TextView) findViewById(R.id.title_tv1);
tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
tv.setText("slide show");
}
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000;
int period = 5000;
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
private void AnimateandSlideShow() {
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
boolean animation_one = getPrefs.getBoolean("animation_one", true);
boolean animation_two = getPrefs.getBoolean("animation_two", false);
boolean animation_three = getPrefs.getBoolean("animation_three", false);
boolean animation_four = getPrefs.getBoolean("animation_four", false);
boolean animation_five = getPrefs.getBoolean("animation_five", false);
if (animation_one == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
Animation rotateimage1 = AnimationUtils.loadAnimation(this, R.anim.bounce);
//
AnimationSet s = new AnimationSet(false);
s.addAnimation(rotateimage);
s.addAnimation(rotateimage1);
slidingimage.startAnimation(s);
}else if(animation_two == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in);
slidingimage.startAnimation(rotateimage);
}else if(animation_three == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.move);
slidingimage.startAnimation(rotateimage);
}else if(animation_four == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.sequential);
slidingimage.startAnimation(rotateimage);
}else if (animation_five == true) {
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.slide_down);
slidingimage.startAnimation(rotateimage);
}else if(animation_one == false && animation_two == false && animation_three == false
&& animation_four == false && animation_five == false){
slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
slidingimage.startAnimation(rotateimage);
}
}
public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,AttributeSet attrs) {
if (name .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
view .setBackgroundResource(R.drawable.border);
((TextView) view).setTextSize(30);
((TextView) view).setTypeface(FontFactory.getBFantezy(getBaseContext()));
((TextView) view).setTextColor(Color.RED);
}
});
return view;
}
catch (InflateException e) {}
catch (ClassNotFoundException e) {}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.slide_pref:
Intent i = new Intent("com.test.demo.SETTING");
startActivity(i);
break;
}
return false;
}
}