Advertisement
stirante

filter preview

Feb 8th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. package com.stirante.quizcheat.material;
  2.  
  3.  
  4. import android.content.Context;
  5. import android.os.Bundle;
  6. import android.support.v4.view.ViewPager;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.CheckBox;
  12. import android.widget.CompoundButton;
  13. import android.widget.ImageView;
  14. import android.widget.RelativeLayout;
  15.  
  16. import com.stirante.quizcheat.R;
  17.  
  18. public class MaterialActivity extends AppCompatActivity {
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_material);
  24. ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
  25. ImageAdapter adapter = new ImageAdapter(this);
  26. viewPager.setAdapter(adapter);
  27. }
  28.  
  29. class PreviewHolder extends RecyclerPagerAdapter.ViewHolder {
  30. public PreviewHolder(View itemView) {
  31. super(itemView);//save also filter name or enum or something
  32. ((CheckBox) getItemView().findViewById(R.id.enabled)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  33. @Override
  34. public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  35. //here change if it's enabled
  36. }
  37. });
  38. }
  39.  
  40. public void setImage(int id) {
  41. ((ImageView) getItemView().findViewById(R.id.preview)).setImageResource(id);
  42. }
  43.  
  44. public void setChecked(boolean checked) {
  45. ((CheckBox) getItemView().findViewById(R.id.enabled)).setChecked(checked);
  46. }
  47.  
  48. }
  49.  
  50. class ImageAdapter extends RecyclerPagerAdapter<PreviewHolder> {
  51. Context context;
  52. private int[] GalImages = new int[]{
  53. R.drawable.hefe,
  54. R.drawable.xproll,
  55. R.drawable.toaster
  56. };
  57.  
  58. ImageAdapter(Context context) {
  59. this.context = context;
  60. }
  61.  
  62. @Override
  63. public int getItemCount() {
  64. return GalImages.length;
  65. }
  66.  
  67. @Override
  68. public void onBindViewHolder(PreviewHolder holder, int position) {
  69. holder.setImage(GalImages[position]);//here also set for holder filter name/enum/something about filter
  70. holder.setChecked(false);//set it
  71. //holder.setFilter(filter); //do something like this
  72. }
  73.  
  74. @Override
  75. public PreviewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  76. RelativeLayout layout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.preview_layout, null);
  77. return new PreviewHolder(layout);
  78. }
  79.  
  80. }
  81. }
  82.  
  83. //here is preview_layout
  84. <?xml version="1.0" encoding="utf-8"?>
  85. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  86. android:layout_width="match_parent"
  87. android:layout_height="match_parent"
  88. android:orientation="vertical">
  89.  
  90. <Space
  91. android:id="@+id/center_space"
  92. android:layout_width="0px"
  93. android:layout_height="0px"
  94. android:layout_centerHorizontal="true" />
  95.  
  96. <ImageView
  97. android:id="@+id/preview"
  98. android:layout_width="match_parent"
  99. android:layout_height="match_parent"
  100. android:layout_alignEnd="@+id/center_space"
  101. android:layout_alignParentLeft="true"
  102. android:layout_alignParentStart="true"
  103. android:layout_alignParentTop="true"
  104. android:layout_alignRight="@+id/center_space"
  105. android:layout_toLeftOf="@+id/center_space"
  106. android:layout_toStartOf="@+id/center_space"
  107. android:scaleType="centerCrop"
  108. android:src="@drawable/hefe" />
  109.  
  110. <ImageView
  111. android:id="@+id/imageView"
  112. android:layout_width="match_parent"
  113. android:layout_height="match_parent"
  114. android:layout_alignLeft="@+id/center_space"
  115. android:layout_alignParentTop="true"
  116. android:layout_alignStart="@+id/center_space"
  117. android:layout_toEndOf="@+id/center_space"
  118. android:layout_toRightOf="@+id/center_space"
  119. android:scaleType="centerCrop"
  120. android:src="@drawable/clean" />
  121.  
  122. <LinearLayout
  123. android:layout_width="match_parent"
  124. android:layout_alignParentBottom="true"
  125. android:layout_centerHorizontal="true"
  126. android:background="@drawable/check_bg"
  127. android:gravity="center"
  128. android:layout_height="100dp">
  129.  
  130. <CheckBox
  131. android:id="@+id/enabled"
  132. android:layout_marginTop="15dp"
  133. android:layout_width="wrap_content"
  134. android:layout_height="wrap_content"
  135. android:gravity="center" />
  136.  
  137. </LinearLayout>
  138.  
  139.  
  140. </RelativeLayout>
  141.  
  142. //check_bg drawable
  143. <?xml version="1.0" encoding="utf-8"?>
  144. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  145. <gradient
  146. android:startColor="#88ffffff"
  147. android:centerColor="#88ffffff"
  148. android:endColor="#00ffffff"
  149. android:angle="90"/>
  150. </shape>
  151.  
  152. //activity layout
  153. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  154. android:layout_width="match_parent"
  155. android:layout_height="match_parent">
  156.  
  157. <android.support.v4.view.ViewPager
  158. android:id="@+id/view_pager"
  159. android:layout_width="match_parent"
  160. android:layout_height="match_parent" />
  161.  
  162. </RelativeLayout>
  163.  
  164. //Here is page adapter
  165. 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