Skip to content

Commit f6a94a6

Browse files
author
roryoreilly
committed
Product card display with product list inside cards
1 parent 208293e commit f6a94a6

21 files changed

+462
-295
lines changed

app/app.iml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@
6969
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
7070
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7171
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
72-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
72+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.2.0/jars" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.2.0/jars" />
7374
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/multidex/1.0.1/jars" />
74-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.2.0/jars" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.0/jars" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.2.0/jars" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.lsjwzh.RecyclerViewPager/lib/v1.1.0-beta5/jars" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/org.solovyev.android.views/linear-layout-manager/0.5/jars" />
7680
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7781
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
7882
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
@@ -85,15 +89,19 @@
8589
</content>
8690
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
8791
<orderEntry type="sourceFolder" forTests="false" />
88-
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
89-
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
90-
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
91-
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
92+
<orderEntry type="library" exported="" name="linear-layout-manager-0.5" level="project" />
93+
<orderEntry type="library" exported="" name="support-v4-23.2.0" level="project" />
9294
<orderEntry type="library" exported="" name="butterknife-7.0.1" level="project" />
93-
<orderEntry type="library" exported="" name="httpmime-4.3.1" level="project" />
94-
<orderEntry type="library" exported="" name="httpcore-4.3.1" level="project" />
9595
<orderEntry type="library" exported="" name="weka" level="project" />
9696
<orderEntry type="library" exported="" name="multidex-1.0.1" level="project" />
97+
<orderEntry type="library" exported="" name="animated-vector-drawable-23.2.0" level="project" />
98+
<orderEntry type="library" exported="" name="support-annotations-23.2.0" level="project" />
99+
<orderEntry type="library" exported="" name="recyclerview-v7-23.2.0" level="project" />
100+
<orderEntry type="library" exported="" name="httpcore-4.3.1" level="project" />
101+
<orderEntry type="library" exported="" name="httpmime-4.3.1" level="project" />
102+
<orderEntry type="library" exported="" name="support-vector-drawable-23.2.0" level="project" />
103+
<orderEntry type="library" exported="" name="appcompat-v7-23.2.0" level="project" />
104+
<orderEntry type="library" exported="" name="lib-v1.1.0-beta5" level="project" />
97105
<orderEntry type="library" exported="" name="commons-math3-3.5" level="project" />
98106
</component>
99107
</module>

app/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ android {
3535
}
3636
}
3737

38+
repositories {
39+
maven { url "https://jitpack.io" }
40+
}
41+
3842
dependencies {
3943
// compile fileTree(dir: 'libs', include: ['*.jar'])
40-
compile 'com.android.support:appcompat-v7:23.1.1'
41-
compile 'com.android.support:recyclerview-v7:23.1.1'
44+
compile 'com.android.support:appcompat-v7:23.2.0'
45+
compile 'com.android.support:recyclerview-v7:23.2.0'
4246
compile 'com.android.support:multidex:1.0.1'
4347
compile 'com.jakewharton:butterknife:7.0.1'
4448
compile 'org.apache.commons:commons-math3:3.5'
4549
compile files('libs/weka.jar')
4650
compile 'org.apache.httpcomponents:httpmime:4.3.1'
4751
compile 'org.apache.httpcomponents:httpcore:4.3.1'
52+
compile 'com.github.lsjwzh.RecyclerViewPager:lib:v1.1.0-beta5'
53+
compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
4854
}

app/src/main/java/roryoreilly/makeuprecommender/Model/EyeModel.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package roryoreilly.makeuprecommender.Model;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import roryoreilly.makeuprecommender.Recommender.SkinTone;
7+
38
/**
49
* Created by roryorilly on 15/02/16.
510
*/
611
public class SkinModel {
12+
private List<SkinTone> tones;
713
public static String findClass(float[] values) {
814

915
return "light-warm";
1016
}
17+
18+
private void setUpSkinTones(){
19+
tones = new ArrayList<>();
20+
tones.add(new SkinTone("N"));
21+
}
1122
}
Lines changed: 120 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package roryoreilly.makeuprecommender;
22

3-
import android.os.Bundle;
3+
44
import android.app.Activity;
5+
import android.os.Bundle;
56
import android.support.v7.widget.LinearLayoutManager;
67
import android.support.v7.widget.RecyclerView;
8+
import android.util.Log;
9+
import android.view.View;
10+
11+
import com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager;
712

813
import java.util.ArrayList;
914
import java.util.List;
1015

1116
import roryoreilly.makeuprecommender.Recommender.ProductCard;
1217
import roryoreilly.makeuprecommender.Recommender.ProductItem;
1318
import roryoreilly.makeuprecommender.View.ProductCardAdapter;
14-
import roryoreilly.makeuprecommender.View.ProductItemAdapter;
1519

1620
public 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+
}

app/src/main/java/roryoreilly/makeuprecommender/Recommender/ProductCard.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public ProductCard(List<ProductItem> items, String type, Integer image, boolean
1717
mType = type;
1818
mMainImage = image;
1919
mOnline = online;
20-
mProductItems = new ArrayList<ProductItem>();
2120
}
2221

2322
public String getType() {

app/src/main/java/roryoreilly/makeuprecommender/Recommender/ProductItem.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
public class ProductItem {
77
private String mType;
88
private String mName;
9-
private boolean mOnline;
9+
private String mDescription;
10+
private Integer mImageResource;
1011

11-
public ProductItem(String type, String name, boolean online) {
12+
public ProductItem(String type, String name, String description, Integer imageRes) {
1213
mType = type;
1314
mName = name;
14-
mOnline = online;
15+
mDescription = description;
16+
mImageResource = imageRes;
1517
}
1618

1719
public String getType() {
@@ -22,7 +24,11 @@ public String getName() {
2224
return mName;
2325
}
2426

25-
public boolean isOnline() {
26-
return mOnline;
27+
public Integer getImageResource() {
28+
return mImageResource;
29+
}
30+
31+
public String getDescription() {
32+
return mDescription;
2733
}
2834
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package roryoreilly.makeuprecommender.Recommender;
2+
3+
4+
/**
5+
* Created by roryoreilly on 29/02/16.
6+
*/
7+
public class SkinTone {
8+
private String code;
9+
private String name;
10+
private float[] hue;
11+
12+
public SkinTone (String code) {
13+
this.code = code;
14+
this.name = "";
15+
16+
}
17+
18+
public SkinTone(String code, float[] hue) {
19+
this.code = code;
20+
this.name = nameFromCode(code);
21+
this.hue = hue;
22+
}
23+
24+
public double distance(float[] skin) {
25+
return Math.sqrt(Math.pow(hue[0] - skin[0], 2)
26+
+ Math.pow(hue[1] - skin[1], 2)
27+
+ Math.pow(hue[2] - skin[2], 2));
28+
}
29+
30+
public String nameFromCode(String code) {
31+
String name ="";
32+
int value = Integer.valueOf(code.substring(2));
33+
if (value <= 10) {
34+
name += "Pale";
35+
} else if (value <= 15) {
36+
name += "Fair";
37+
} else if (value <= 25) {
38+
name += "Light";
39+
} else if (value <= 35) {
40+
name += "Medium";
41+
} else if (value <= 45) {
42+
name += "Olive";
43+
} else if (value <= 55) {
44+
name += "Brown";
45+
} else {
46+
name += "Black";
47+
}
48+
49+
String type = code.substring(0, 1);
50+
if (type.equals("NW")) {
51+
name += "-Cool";
52+
} else if (type.equals("NC")) {
53+
name += "-Warm";
54+
}
55+
56+
return name;
57+
}
58+
59+
public String getCode() {
60+
return code;
61+
}
62+
63+
public String getName() {
64+
return name;
65+
}
66+
}

0 commit comments

Comments
 (0)