Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.stirante.quizcheat.material;
- import android.content.Context;
- import android.os.Bundle;
- import android.support.v4.view.ViewPager;
- import android.support.v7.app.AppCompatActivity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.ImageView;
- import android.widget.RelativeLayout;
- import com.stirante.quizcheat.R;
- public class MaterialActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_material);
- ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
- ImageAdapter adapter = new ImageAdapter(this);
- viewPager.setAdapter(adapter);
- }
- class PreviewHolder extends RecyclerPagerAdapter.ViewHolder {
- public PreviewHolder(View itemView) {
- super(itemView);//save also filter name or enum or something
- ((CheckBox) getItemView().findViewById(R.id.enabled)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- //here change if it's enabled
- }
- });
- }
- public void setImage(int id) {
- ((ImageView) getItemView().findViewById(R.id.preview)).setImageResource(id);
- }
- public void setChecked(boolean checked) {
- ((CheckBox) getItemView().findViewById(R.id.enabled)).setChecked(checked);
- }
- }
- class ImageAdapter extends RecyclerPagerAdapter<PreviewHolder> {
- Context context;
- private int[] GalImages = new int[]{
- R.drawable.hefe,
- R.drawable.xproll,
- R.drawable.toaster
- };
- ImageAdapter(Context context) {
- this.context = context;
- }
- @Override
- public int getItemCount() {
- return GalImages.length;
- }
- @Override
- public void onBindViewHolder(PreviewHolder holder, int position) {
- holder.setImage(GalImages[position]);//here also set for holder filter name/enum/something about filter
- holder.setChecked(false);//set it
- //holder.setFilter(filter); //do something like this
- }
- @Override
- public PreviewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- RelativeLayout layout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.preview_layout, null);
- return new PreviewHolder(layout);
- }
- }
- }
- //here is preview_layout
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <Space
- android:id="@+id/center_space"
- android:layout_width="0px"
- android:layout_height="0px"
- android:layout_centerHorizontal="true" />
- <ImageView
- android:id="@+id/preview"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignEnd="@+id/center_space"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:layout_alignParentTop="true"
- android:layout_alignRight="@+id/center_space"
- android:layout_toLeftOf="@+id/center_space"
- android:layout_toStartOf="@+id/center_space"
- android:scaleType="centerCrop"
- android:src="@drawable/hefe" />
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignLeft="@+id/center_space"
- android:layout_alignParentTop="true"
- android:layout_alignStart="@+id/center_space"
- android:layout_toEndOf="@+id/center_space"
- android:layout_toRightOf="@+id/center_space"
- android:scaleType="centerCrop"
- android:src="@drawable/clean" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:background="@drawable/check_bg"
- android:gravity="center"
- android:layout_height="100dp">
- <CheckBox
- android:id="@+id/enabled"
- android:layout_marginTop="15dp"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="center" />
- </LinearLayout>
- </RelativeLayout>
- //check_bg drawable
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android">
- <gradient
- android:startColor="#88ffffff"
- android:centerColor="#88ffffff"
- android:endColor="#00ffffff"
- android:angle="90"/>
- </shape>
- //activity layout
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v4.view.ViewPager
- android:id="@+id/view_pager"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </RelativeLayout>
- //Here is page adapter
- https://github.com/henrytao-me/recycler-pager-adapter/blob/master/recycler-pager-adapter%2Fsrc%2Fmain%2Fjava%2Fme%2Fhenrytao%2Frecyclerpageradapter%2FRecyclerPagerAdapter.java
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement