I'm having trouble thinking about how to make an automatic slideshow using ImageSwitchers and Gallery. The only thing I understand is the animation between transitioning pictures when you select them from gallery, like the way they fade or move from left to right.
EDIT
My purpose is trying to make a slideshow the same way when you create gallery and select each pictures then use imageswitcher to display the selected picture on the bottom layout. Just this time, instead actually clicking, I want the pictures to move automatically (next one after the last one), like on Powerpoints and with a timer obviously.
Here's the whole class: package project.CaseStudy;
public class Slideshow extends Activity implements ViewFactory {
//---the images to display---
Integer[] imageIDs = {
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5,
R.drawable.pic6,
R.drawable.pic7
};
TextView legend;
TextView imageID;
CheckBox repeat;
CheckBox image;
CheckBox text;
public int picture;
public int pictureCurrentlySelected;
private ImageSwitcher imageSwitcher;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slideshow);
legend = (TextView) findViewById(R.id.legend);
imageID = (TextView) findViewById(R.id.imagenum);
repeat = (CheckBox) findViewById(R.id.repeat);
image = (CheckBox) findViewById(R.id.number);
text = (CheckBox) findViewById(R.id.text);
//text.setEnabled(true);
//image.setEnabled(true);
//repeat.setEnabled(true);
imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher1);
imageSwitcher.setFactory(this);
imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
/*imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left));
imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right));
*/
pictureCurrentlySelected = -1;
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent,
View v, int position, long id)
{
imageSwitcher.setImageResource(imageIDs[position]);
picture = position;
pictureCurrentlySelected = picture;
check();
}
});
}
public View makeView()
{
ImageView imageView = new ImageView(this);
imageView.setBackgroundColor(0xFF000000);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setLayoutParams(new
ImageSwitcher.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
return imageView;
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private int itemBackground;
public ImageAdapter(Context c)
{
context = c;
//---setting the style---
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
//---returns the number of images---
public int getCount()
{
return imageIDs.length;
}
//---returns the item---
public Object getItem(int position)
{
return position;
}
//---returns the ID of an item---
public long getItemId(int position)
{
return position;
}
//---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
public void onCheckBoxClickListener(View v)
{
boolean checked = ((CheckBox) v).isChecked();
switch(v.getId()){
case R.id.repeat:
/*if(checked)
{
return;
}*/
break;
case R.id.text:
if(!checked)
legend.setText("");
else
{
if(pictureCurrentlySelected == -1)
{
legend.setText("");
}
else
check();
}
break;
case R.id.number:
if(!checked)
imageID.setText("");
else
{
if(pictureCurrentlySelected == -1)
{
legend.setText("");
}
else
check();
}
break;
}
}
private void check()
{
if(text.isChecked())
{
if(picture == 0)
legend.setText("This is San Fransisco's Bridge. A beautiful Sight!");
else if(picture == 1)
legend.setText("This is the train used to pick up the bitches around town.");
else if(picture == 2)
legend.setText("The outstanding lake of San Fransisco");
else if(picture == 3)
legend.setText("A beautiful view of the city!");
else if(picture == 4)
legend.setText("Beauty at its limit.");
else if(picture == 5)
legend.setText("Town at sunset.");
else
legend.setText("Bridge during within a beautiful sight.");
}
/*else
legend.setText("");*/
if(image.isChecked())
{
if(picture == 0)
imageID.setText("Image number 1");
else if(picture == 1)
imageID.setText("Image number 2");
else if(picture == 2)
imageID.setText("Image number 3");
else if(picture == 3)
imageID.setText("Image number 4");
else if(picture == 4)
imageID.setText("Image number 5");
else if(picture == 5)
imageID.setText("Image number 6");
else
imageID.setText("Image number 7");
}
//else
//legend.setText("");
if(repeat.isChecked())
{
}
//else;
}
}
Ignore the last two methods if it's too complicated to understand Im just sketching my program and will eventually fix the redundancy later.
Here's the XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Images of San Francisco" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/repeat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckBoxClickListener"
android:text="Repeat" />
<CheckBox
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckBoxClickListener"
android:text="Image ID" />
<CheckBox
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCheckBoxClickListener"
android:text="Text" />
</LinearLayout>
<Gallery
android:id="@+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.50" >
<ImageSwitcher
android:id="@+id/switcher1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ImageSwitcher>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image number: " />
<TextView
android:id="@+id/imagenum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/legend"
android:layout_width="match_parent"
android:layout_height="57dp"
android:text="" />
</LinearLayout>
</LinearLayout>