import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.lenovo.elec.R;
/**
* 使用向导
*
* @author
*
*/
public class GuideActivity extends Activity {
protected static final String TAG = "GuideActivity";
ViewPager viewPager;
ArrayList<View> list;
ViewGroup main, group;
ImageView imageView;
ImageView[] imageViews;
View view5;
private Button guide_start;
private Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置无标题
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
LayoutInflater inflater = getLayoutInflater();
list = new ArrayList<View>();
list.add(inflater.inflate(R.layout.guideitem1, null));
list.add(inflater.inflate(R.layout.guideitem2, null));
list.add(inflater.inflate(R.layout.guideitem3, null));
list.add(inflater.inflate(R.layout.guideitem4, null));
view5 = inflater.inflate(R.layout.guideitem5, null);
list.add(view5);
imageViews = new ImageView[list.size()];
ViewGroup main = (ViewGroup) inflater.inflate(R.layout.guide, null);
// group是R.layou.guide中的负责包裹小圆点的LinearLayout.
ViewGroup group = (ViewGroup) main.findViewById(R.id.viewGroup);
viewPager = (ViewPager) main.findViewById(R.id.viewPager);
for (int i = 0; i < list.size(); i++) {
imageView = new ImageView(this);
imageView.setLayoutParams(new LayoutParams(30, 20));
imageView.setPadding(15, 0, 15, 0);
imageViews[i] = imageView;
if (i == 0) {
imageViews[i].setBackgroundResource(R.drawable.guide_dot_blue);
// 默认进入程序后第一张图片被选中;
} else {
imageViews[i].setBackgroundResource(R.drawable.guide_dot_white);
}
group.addView(imageView);
}
setContentView(main);
guide_start = (Button) view5.findViewById(R.id.guide_start);
guide_start.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
intent = new Intent(GuideActivity.this, CustomTabActivity.class);
startActivity(intent);
Toast.makeText(getApplicationContext(), "进入我的小屋", 0).show();
finish();
}
});
viewPager.setAdapter(new MyAdapter());
viewPager.setOnPageChangeListener(new MyListener());
}
/**
* 返回键退出
*/
@Override
public void onBackPressed() {
}
class MyAdapter extends PagerAdapter {
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public int getItemPosition(Object object) {
return super.getItemPosition(object);
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView(list.get(arg1));
}
@Override
public Object instantiateItem(View arg0, int arg1) {
((ViewPager) arg0).addView(list.get(arg1));
return list.get(arg1);
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
@Override
public void finishUpdate(View arg0) {
}
}
class MyListener implements OnPageChangeListener {
public void onPageScrollStateChanged(int arg0) {
}
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
public void onPageSelected(int arg0) {
for (int i = 0; i < imageViews.length; i++) {
imageViews[arg0].setBackgroundResource(R.drawable.guide_dot_blue);
if (arg0 != i) {
imageViews[i].setBackgroundResource(R.drawable.guide_dot_white);
}
}
}
}
}