-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37fbc6d
commit 29eaf92
Showing
27 changed files
with
271 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
example/src/main/AndroidManifest.xml → sample/src/main/AndroidManifest.xml
This file contains 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
28 changes: 28 additions & 0 deletions
28
sample/src/main/java/com/musenkishi/paletteloader/sample/Countries.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.musenkishi.paletteloader.sample; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Sample countries | ||
* Created by frelus on 13/05/15. | ||
*/ | ||
public class Countries { | ||
|
||
public static final ArrayList<Country> countries = new ArrayList<>(Arrays.asList(new Country[]{ | ||
new Country("Sweden", "https://i.imgur.com/7VWkxxU.jpg"), | ||
new Country("Greece", "https://i.imgur.com/sH1yrJD.jpg"), | ||
new Country("France", "https://i.imgur.com/1Gt5ldY.jpg"), | ||
new Country("Japan", "https://i.imgur.com/ypGnx2q.jpg"), | ||
new Country("U.S.A.", "https://i.imgur.com/qfQGh.jpg"), | ||
new Country("China", "https://i.imgur.com/fpgPo.jpg"), | ||
new Country("Australia", "https://i.imgur.com/zW30U2O.jpg"), | ||
new Country("Egypt", "https://i.imgur.com/mXlezUD.jpg"), | ||
new Country("Haiti", "https://i.imgur.com/QS6Dx.jpg"), | ||
new Country("Zambia", "https://gp1.wac.edgecastcdn.net/806614/photos/photos.500px.net/86372017/b367fd0ce34e41f1b357b11942629e7c68dcfb8a/2048.jpg"), | ||
new Country("Chile", "https://i.imgur.com/DcTmjg4.jpg"), | ||
new Country("United Kingdom", "https://i.imgur.com/V0A6N3s.jpg"), | ||
new Country("Canada", "https://i.imgur.com/PLehguA.jpg") | ||
})); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
sample/src/main/java/com/musenkishi/paletteloader/sample/Country.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.musenkishi.paletteloader.sample; | ||
|
||
/** | ||
* Created by frelus on 13/05/15. | ||
*/ | ||
public class Country { | ||
|
||
private String name, url; | ||
|
||
public Country(String name, String url) { | ||
this.name = name; | ||
this.url = url; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
sample/src/main/java/com/musenkishi/paletteloader/sample/CountryAdapter.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.musenkishi.paletteloader.sample; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Color; | ||
import android.support.v7.widget.CardView; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.bumptech.glide.Glide; | ||
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable; | ||
import com.bumptech.glide.load.resource.drawable.GlideDrawable; | ||
import com.bumptech.glide.request.RequestListener; | ||
import com.bumptech.glide.request.target.Target; | ||
import com.musenkishi.paletteloader.PaletteLoader; | ||
import com.musenkishi.paletteloader.PaletteRequest; | ||
|
||
/** | ||
* A simple adapter for loading countries names and images. | ||
* Created by Freddie (Musenkishi) Lust-Hed on 14/05/15. | ||
*/ | ||
public class CountryAdapter extends RecyclerView.Adapter<CountryAdapter.ViewHolder> { | ||
|
||
@Override | ||
public CountryAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) { | ||
LayoutInflater inflater = (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||
final CardView view = (CardView) inflater.inflate(R.layout.list_item, viewGroup, false); | ||
return new ViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(final CountryAdapter.ViewHolder viewHolder, int position) { | ||
|
||
Country country = Countries.countries.get(position); | ||
|
||
viewHolder.textView.setText(country.getName()); | ||
|
||
viewHolder.rootView.setCardBackgroundColor(Color.parseColor("#FFFAFAFA")); | ||
viewHolder.textView.setTextColor(Color.BLACK); | ||
|
||
RequestListener<String, GlideDrawable> glideDrawableRequestListener = new RequestListener<String, GlideDrawable>() { | ||
@Override | ||
public boolean onException(Exception e, | ||
String url, | ||
Target<GlideDrawable> target, | ||
boolean isFirstResource) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean onResourceReady(GlideDrawable resource, | ||
String url, | ||
Target<GlideDrawable> target, | ||
boolean isFromMemoryCache, | ||
boolean isFirstResource) { | ||
Bitmap bitmap = ((GlideBitmapDrawable) resource).getBitmap(); | ||
if (bitmap != null) { | ||
Context context = viewHolder.rootView.getContext(); | ||
PaletteLoader.with(context, url) | ||
.load(bitmap) | ||
.setPaletteRequest(new PaletteRequest( | ||
PaletteRequest.SwatchType.REGULAR_VIBRANT, | ||
PaletteRequest.SwatchColor.BACKGROUND)) | ||
.into(viewHolder.rootView); | ||
PaletteLoader.with(context, url) | ||
.load(bitmap) | ||
.setPaletteRequest(new PaletteRequest( | ||
PaletteRequest.SwatchType.REGULAR_VIBRANT, | ||
PaletteRequest.SwatchColor.TEXT_TITLE)) | ||
.into(viewHolder.textView); | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
Glide.with(viewHolder.rootView.getContext()) | ||
.load(country.getUrl()) | ||
.fitCenter() | ||
.placeholder(Color.TRANSPARENT) | ||
.listener(glideDrawableRequestListener) | ||
.into(viewHolder.imageView); | ||
|
||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return Countries.countries.size(); | ||
} | ||
|
||
public class ViewHolder extends RecyclerView.ViewHolder { | ||
CardView rootView; | ||
ImageView imageView; | ||
TextView textView; | ||
|
||
public ViewHolder(CardView rootView) { | ||
super(rootView); | ||
this.rootView = rootView; | ||
imageView = (ImageView) rootView.findViewById(R.id.image); | ||
textView = (TextView) rootView.findViewById(R.id.text); | ||
} | ||
} | ||
|
||
} |
13 changes: 10 additions & 3 deletions
13
...usenkishi/paletteloader/MainActivity.java → ...hi/paletteloader/sample/MainActivity.java
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemstyleas.android.com/tools" android:layout_width="match_parent" | ||
android:layout_height="match_parent" tools:context=".MainActivity"> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/recyclerview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:clipToPadding="false" | ||
/> | ||
|
||
</RelativeLayout> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:card_view="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="16dp" | ||
card_view:cardCornerRadius="6dp" | ||
card_view:cardUseCompatPadding="true"> | ||
|
||
<LinearLayout | ||
android:id="@+id/root" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<ImageView | ||
android:id="@+id/image" | ||
android:layout_width="match_parent" | ||
android:layout_height="250dp" | ||
android:scaleType="centerCrop" /> | ||
|
||
<TextView | ||
android:id="@+id/text" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fontFamily="@string/font_fontFamily_medium" | ||
android:gravity="center" | ||
android:padding="16dp" | ||
android:textAllCaps="true" | ||
android:textSize="16sp" /> | ||
|
||
</LinearLayout> | ||
</android.support.v7.widget.CardView> |
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="font_fontFamily_medium">sans-serif-medium</string> | ||
</resources> |
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="font_fontFamily_medium">sans-serif</string> | ||
</resources> |
Oops, something went wrong.