Last active
April 27, 2019 05:40
-
-
Save donrokzon/8635f2fd8b634b784ce32264ed9b958d to your computer and use it in GitHub Desktop.
SlideShow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| private ArrayList<String> imageModelArrayList; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); | |
| setContentView(R.layout.activity_main); | |
| imageModelArrayList = new ArrayList<>(); | |
| imageModelArrayList = new ArrayList<>(); | |
| imageModelArrayList.add("https://wallpaperaccess.com/full/110378.jpg"); | |
| imageModelArrayList.add("https://i.pinimg.com/736x/1b/00/da/1b00da90872fb8d10cf6298eebf9bbed.jpg"); | |
| imageModelArrayList.add("https://i.pinimg.com/originals/3d/af/a8/3dafa86ecafe20de2bae7933e374091c.jpg"); | |
| init(); | |
| FullScreencall(); | |
| } | |
| private void init() { | |
| ViewPager mPager = findViewById(R.id.pager); | |
| mPager.setAdapter(new SlidingImageAdapter(MainActivity.this, imageModelArrayList)); | |
| CirclePageIndicator indicator = findViewById(R.id.indicator); | |
| indicator.setViewPager(mPager); | |
| //AutoSlide //destroy timer timer.cancel();super.onDestroy(); | |
| TimerTask timerTask = new TimerTask() { | |
| @Override | |
| public void run() { | |
| mPager.post(new Runnable() { | |
| @Override | |
| public void run() { | |
| mPager.setCurrentItem((mPager.getCurrentItem() + 1)%imageModelArrayList.size()); | |
| } | |
| }); | |
| } | |
| }; | |
| timer = new Timer(); | |
| timer.schedule(timerTask, 3000, 3000); | |
| } | |
| public void FullScreencall() { | |
| //for new api versions. | |
| View decorView = getWindow().getDecorView(); | |
| int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; | |
| decorView.setSystemUiVisibility(uiOptions); | |
| } | |
| } | |
| public class SlidingImageAdapter extends PagerAdapter { | |
| private ArrayList<String> imageModelArrayList; | |
| private LayoutInflater inflater; | |
| SlidingImageAdapter(Context context, ArrayList<String> imageModelArrayList) { | |
| this.imageModelArrayList = imageModelArrayList; | |
| inflater = LayoutInflater.from(context); | |
| } | |
| @Override | |
| public void destroyItem(ViewGroup container, int position, Object object) { | |
| container.removeView((View) object); | |
| } | |
| @Override | |
| public int getCount() { | |
| return imageModelArrayList.size(); | |
| } | |
| @Override @NonNull | |
| public Object instantiateItem(ViewGroup view, int position) { | |
| View imageLayout = inflater.inflate(R.layout.slidingimages_layout, view, false); | |
| assert imageLayout != null; | |
| final ImageView imageView = imageLayout | |
| .findViewById(R.id.image); | |
| Picasso.get().load(imageModelArrayList.get(position)).into(imageView); | |
| view.addView(imageLayout, 0); | |
| return imageLayout; | |
| } | |
| @Override | |
| public boolean isViewFromObject(View view, Object object) { | |
| return view.equals(object); | |
| } | |
| } | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| > | |
| <ImageView | |
| android:id="@+id/image" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:adjustViewBounds="true" | |
| android:layout_gravity="center" | |
| android:scaleType="centerCrop" /> | |
| </FrameLayout> | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| > | |
| <ProgressBar | |
| android:id="@+id/progressBar" | |
| style="?android:attr/progressBarStyle" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginStart="8dp" | |
| android:layout_marginTop="8dp" | |
| android:layout_marginEnd="8dp" | |
| android:layout_marginBottom="8dp" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintEnd_toEndOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="@+id/pager" /> | |
| <android.support.v4.view.ViewPager | |
| android:id="@+id/pager" | |
| android:layout_width="match_parent" | |
| android:layout_height="0dp" | |
| android:layout_alignParentTop="true" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintEnd_toEndOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:layout_constraintTop_toTopOf="parent" /> | |
| <com.viewpagerindicator.CirclePageIndicator | |
| android:id="@+id/indicator" | |
| android:layout_width="fill_parent" | |
| android:layout_height="wrap_content" | |
| android:layout_alignParentBottom="true" | |
| android:layout_centerHorizontal="true" | |
| android:gravity="bottom" | |
| android:padding="10dip" | |
| app:centered="true" | |
| app:fillColor="#df0623" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintEnd_toEndOf="parent" | |
| app:layout_constraintStart_toStartOf="parent" | |
| app:pageColor="#fff" | |
| app:snap="false" /> | |
| </android.support.constraint.ConstraintLayout> | |
| implementation 'com.squareup.picasso:picasso:2.71828' | |
| implementation ('com.github.JakeWharton:ViewPagerIndicator:2.4.1'){ | |
| exclude module: 'support-v4' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment