package com.example.mypandatv; import android.content.Intent; import android.content.SharedPreferences; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import java.util.ArrayList; import java.util.List; public class GuideActivity extends AppCompatActivity implements View.OnClickListener{ private ViewPager vp; private LinearLayout line; private Button btn; private int [] imgarr = {R.drawable.guide_one,R.drawable.guide_two,R.drawable.guide_three}; private List<ImageView> initimage; private List<ImageView> initdot; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide_page); SharedPreferences baocui = getSharedPreferences("baocui",0); int anInt = baocui.getInt("int", 0); if(anInt!=0){ Intent intent=new Intent(GuideActivity.this,MainActivity.class); startActivity(intent); } initView(); initData(); initAdapter(); initListener(); } private void initListener() { vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { for (int i = 0; i < 3; i++) { if (position==i){ initdot.get(i).setImageResource(R.drawable.guide_selectshape); }else{ initdot.get(i).setImageResource(R.drawable.guide_noselectshape); } if(position==initimage.size()-1){ line.setVisibility(View.GONE); btn.setVisibility(View.VISIBLE); }else{ line.setVisibility(View.VISIBLE); btn.setVisibility(View.GONE); } } } @Override public void onPageScrollStateChanged(int state) { } }); } private void initAdapter() { MyGuideAdapter adapter = new MyGuideAdapter(initimage); vp.setCurrentItem(0); vp.setAdapter(adapter); } private void initData() { initimage = new ArrayList<>(); for (int i = 0; i < 3; i++) { ImageView imageView = new ImageView(this); imageView.setImageResource(imgarr[i]); initimage.add(imageView); } initdot = new ArrayList<>(); for (int i = 0; i < 4; i++) { ImageView imageView = new ImageView(this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.leftMargin = 10; layoutParams.rightMargin = 10; layoutParams.width = 18; layoutParams.height = 18; if(i==0){ imageView.setImageResource(R.drawable.guide_selectshape); }else{ imageView.setImageResource(R.drawable.guide_noselectshape); } line.addView(imageView,layoutParams); initdot.add(imageView); } } private void initView() { vp = (ViewPager) findViewById(R.id.guide_vp); line = (LinearLayout) findViewById(R.id.guide_line); btn = (Button) findViewById(R.id.guide_btn); btn.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.guide_btn: SharedPreferences baocui = getSharedPreferences("baocui", 0); SharedPreferences.Editor edit = baocui.edit(); edit.putInt("int",-100); edit.commit(); Intent intent = new Intent(GuideActivity.this,MainActivity.class); startActivity(intent); break; } } }