11package roryoreilly .makeuprecommender ;
22
3- import android . os . Bundle ;
3+
44import android .app .Activity ;
5+ import android .os .Bundle ;
56import android .support .v7 .widget .LinearLayoutManager ;
67import android .support .v7 .widget .RecyclerView ;
8+ import android .util .Log ;
9+ import android .view .View ;
10+
11+ import com .lsjwzh .widget .recyclerviewpager .RecyclerViewPager ;
712
813import java .util .ArrayList ;
914import java .util .List ;
1015
1116import roryoreilly .makeuprecommender .Recommender .ProductCard ;
1217import roryoreilly .makeuprecommender .Recommender .ProductItem ;
1318import roryoreilly .makeuprecommender .View .ProductCardAdapter ;
14- import roryoreilly .makeuprecommender .View .ProductItemAdapter ;
1519
1620public class RecommendationsActivity extends Activity {
17-
18- List <ProductCard > pCards ;
21+ protected RecyclerViewPager mRecyclerView ;
1922
2023 @ Override
2124 protected void onCreate (Bundle savedInstanceState ) {
@@ -28,28 +31,118 @@ protected void onCreate(Bundle savedInstanceState) {
2831 String shape = getIntent ().getExtras ().getString (StylesActivity .EXTRA_SHAPE );
2932 String occasion = getIntent ().getExtras ().getString (StylesActivity .EXTRA_OCCASION );
3033
31- RecyclerView rvContacts = (RecyclerView ) findViewById (R .id .productCard );
32-
33- // Initialize productItems
34- List <ProductItem > pItems = new ArrayList <ProductItem >();
35- pItems .add (new ProductItem ("Foundation" , "Boo" , true ));
36- pItems .add (new ProductItem ("Concealer" , "Foo" , true ));
37- pItems .add (new ProductItem ("Highlighter" , "Bar" , true ));
38- Integer imgid = R .drawable .essentials_look_blur ;
39-
40- pCards = new ArrayList <>();
41- pCards .add (new ProductCard (pItems , "Face" , imgid , true ));
42- pCards .add (new ProductCard (pItems , "Face" , imgid , true ));
43- pCards .add (new ProductCard (pItems , "Face" , imgid , true ));
44- pCards .add (new ProductCard (pItems , "Face" , imgid , true ));
45- // Create adapter passing in the sample user data
46- ProductCardAdapter adapter = new ProductCardAdapter (pCards , this );
47- // Attach the adapter to the recyclerview to populate items
48- rvContacts .setAdapter (adapter );
49- // Set layout manager to position the items
50- LinearLayoutManager llm =
51- new LinearLayoutManager (this , LinearLayoutManager .HORIZONTAL , false );
52- rvContacts .setLayoutManager (llm );
34+ initViewPager ();
5335 }
5436
55- }
37+ protected void initViewPager () {
38+ mRecyclerView = (RecyclerViewPager )findViewById (R .id .viewpager );
39+ LinearLayoutManager layout = new LinearLayoutManager (this , LinearLayoutManager .HORIZONTAL ,
40+ false );
41+ mRecyclerView .setLayoutManager (layout );
42+
43+
44+ List <ProductItem > items = new ArrayList <>();
45+ items .add (new ProductItem ("Foundation" ,
46+ "Studio Fix Fluid SPF 15" ,
47+ "An oil-controlling formula that offers a natural matte finish with medium to full coverage." ,
48+ R .drawable .foundation ));
49+ items .add (new ProductItem ("Foundation" ,
50+ "Studio Fix Fluid SPF 15" ,
51+ "An oil-controlling formula that offers a natural matte finish with medium to full coverage." ,
52+ R .drawable .foundation ));
53+ items .add (new ProductItem ("Foundation" ,
54+ "Studio Fix Fluid SPF 15" ,
55+ "An oil-controlling formula that offers a natural matte finish with medium to full coverage." ,
56+ R .drawable .foundation ));
57+ items .add (new ProductItem ("Foundation" ,
58+ "Studio Fix Fluid SPF 15" ,
59+ "An oil-controlling formula that offers a natural matte finish with medium to full coverage." ,
60+ R .drawable .foundation ));
61+
62+ List <ProductCard > cards = new ArrayList <>();
63+ cards .add (new ProductCard (items , "Face" , R .drawable .boldlips_look , true ));
64+ cards .add (new ProductCard (items , "Eyes" , R .drawable .glameyes_look , true ));
65+ cards .add (new ProductCard (items , "Lips" , R .drawable .goingout_look , true ));
66+
67+ mRecyclerView .setAdapter (new ProductCardAdapter (this , mRecyclerView , cards ));
68+
69+ // mRecyclerView.setHasFixedSize(true);
70+ mRecyclerView .setLongClickable (true );
71+ mRecyclerView .addOnScrollListener (new RecyclerView .OnScrollListener () {
72+ @ Override
73+ public void onScrollStateChanged (RecyclerView recyclerView , int scrollState ) {
74+ // updateState(scrollState);
75+ }
76+
77+ @ Override
78+ public void onScrolled (RecyclerView recyclerView , int i , int i2 ) {
79+ // mPositionText.setText("First: " + mRecyclerViewPager.getFirstVisiblePosition());
80+ int childCount = mRecyclerView .getChildCount ();
81+ int width = mRecyclerView .getChildAt (0 ).getWidth ();
82+ int padding = (mRecyclerView .getWidth () - width ) / 2 ;
83+ // mCountText.setText("Count: " + childCount);
84+
85+ for (int j = 0 ; j < childCount ; j ++) {
86+ View v = recyclerView .getChildAt (j );
87+ //往左 从 padding 到 -(v.getWidth()-padding) 的过程中,由大到小
88+ float rate = 0 ;
89+ ;
90+ if (v .getLeft () <= padding ) {
91+ if (v .getLeft () >= padding - v .getWidth ()) {
92+ rate = (padding - v .getLeft ()) * 1f / v .getWidth ();
93+ } else {
94+ rate = 1 ;
95+ }
96+ v .setScaleY (1 - rate * 0.1f );
97+ v .setScaleX (1 - rate * 0.1f );
98+
99+ } else {
100+ //往右 从 padding 到 recyclerView.getWidth()-padding 的过程中,由大到小
101+ if (v .getLeft () <= recyclerView .getWidth () - padding ) {
102+ rate = (recyclerView .getWidth () - padding - v .getLeft ()) * 1f / v .getWidth ();
103+ }
104+ v .setScaleY (0.9f + rate * 0.1f );
105+ v .setScaleX (0.9f + rate * 0.1f );
106+ }
107+ }
108+ }
109+ });
110+ mRecyclerView .addOnPageChangedListener (new RecyclerViewPager .OnPageChangedListener () {
111+ @ Override
112+ public void OnPageChanged (int oldPosition , int newPosition ) {
113+ Log .d ("test" , "oldPosition:" + oldPosition + " newPosition:" + newPosition );
114+ }
115+ });
116+
117+ mRecyclerView .addOnLayoutChangeListener (new View .OnLayoutChangeListener () {
118+ @ Override
119+ public void onLayoutChange (View v , int left , int top , int right , int bottom , int oldLeft , int oldTop , int oldRight , int oldBottom ) {
120+ if (mRecyclerView .getChildCount () < 3 ) {
121+ if (mRecyclerView .getChildAt (1 ) != null ) {
122+ if (mRecyclerView .getCurrentPosition () == 0 ) {
123+ View v1 = mRecyclerView .getChildAt (1 );
124+ v1 .setScaleY (0.9f );
125+ v1 .setScaleX (0.9f );
126+ } else {
127+ View v1 = mRecyclerView .getChildAt (0 );
128+ v1 .setScaleY (0.9f );
129+ v1 .setScaleX (0.9f );
130+ }
131+ }
132+ } else {
133+ if (mRecyclerView .getChildAt (0 ) != null ) {
134+ View v0 = mRecyclerView .getChildAt (0 );
135+ v0 .setScaleY (0.9f );
136+ v0 .setScaleX (0.9f );
137+ }
138+ if (mRecyclerView .getChildAt (2 ) != null ) {
139+ View v2 = mRecyclerView .getChildAt (2 );
140+ v2 .setScaleY (0.9f );
141+ v2 .setScaleX (0.9f );
142+ }
143+ }
144+
145+ }
146+ });
147+ }
148+ }
0 commit comments