sharedPreferences = getSharedPreferences("ues", MODE_PRIVATE);
// sharedPreferences = getSharedPreferences("users", MODE_PRIVATE);
boolean user = sharedPreferences.getBoolean("user", false);
if (user){
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
finish();
}else {
initView();
initData();
initAdapter();
initListener();
}
}
private void initListener() {
viewpage.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==imageViews.size()-1){
button.setVisibility(View.VISIBLE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putBoolean("user", true);
edit.commit();
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
finish();
}
});
}else {
button.setVisibility(View.GONE);
}
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
private void initAdapter() {
MyAdapter adapter=new MyAdapter(imageViews);
viewpage.setAdapter(adapter);
}
private void initData() {
imageViews = new ArrayList<>();
for (int i = 0; i <3 ; i++) {
ImageView image=new ImageView(this);
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageResource(resimage[i]);
imageViews.add(image);
}
}
private void initView() {
viewpage = (ViewPager) findViewById(R.id.viewpage);
button = (Button) findViewById(R.id.button);
}