diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml
deleted file mode 100644
index f7158b8..0000000
--- a/example/src/main/res/layout/activity_main.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
diff --git a/example/src/main/res/values/strings.xml b/example/src/main/res/values/strings.xml
deleted file mode 100644
index 749be54..0000000
--- a/example/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
- PaletteLoader
-
- Hello world!
- Settings
-
diff --git a/lib/build.gradle b/lib/build.gradle
index 3183ea3..9967e1b 100644
--- a/lib/build.gradle
+++ b/lib/build.gradle
@@ -22,6 +22,7 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:palette-v7:21.0.0'
+ compile 'com.android.support:cardview-v7:22.1.1'
compile 'org.apache.commons:commons-collections4:4.0'
}
diff --git a/lib/src/main/java/com/musenkishi/paletteloader/PaletteLoader.java b/lib/src/main/java/com/musenkishi/paletteloader/PaletteLoader.java
index 704e370..67d34fd 100644
--- a/lib/src/main/java/com/musenkishi/paletteloader/PaletteLoader.java
+++ b/lib/src/main/java/com/musenkishi/paletteloader/PaletteLoader.java
@@ -30,6 +30,7 @@
import android.os.HandlerThread;
import android.os.Message;
import android.support.v7.graphics.Palette;
+import android.support.v7.widget.CardView;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;
@@ -103,7 +104,7 @@ public boolean handleMessage(Message message) {
Message uiMessage = uiHandler.obtainMessage();
uiMessage.what = MSG_DISPLAY_PALETTE;
- uiMessage.obj = new Pair(palette, pair.second);
+ uiMessage.obj = new Pair<>(palette, pair.second);
uiMessage.arg1 = FALSE;
uiHandler.sendMessage(uiMessage);
@@ -185,7 +186,7 @@ public void into(View view) {
} else {
Message bgMessage = backgroundHandler.obtainMessage();
bgMessage.what = MSG_RENDER_PALETTE;
- bgMessage.obj = new Pair(bitmap, paletteTarget);
+ bgMessage.obj = new Pair<>(bitmap, paletteTarget);
backgroundHandler.sendMessage(bgMessage);
}
}
@@ -204,6 +205,9 @@ private static void applyColorToView(final PaletteTarget target, int color, bool
if (target.getView() instanceof TextView) {
applyColorToView((TextView) target.getView(), color, fromCache);
return;
+ } else if (target.getView() instanceof CardView) {
+ applyColorToCardView((CardView) target.getView(), color, fromCache);
+ return;
}
if (fromCache) {
if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) {
@@ -291,6 +295,23 @@ public void onAnimationUpdate(ValueAnimator animator) {
}
}
+ private static void applyColorToCardView(final CardView cardView, int color, boolean fromCache) {
+ if (fromCache) {
+ cardView.setCardBackgroundColor(color);
+ } else {
+ Integer colorFrom = Color.parseColor("#FFFAFAFA"); //Default light CardView color.
+ Integer colorTo = color;
+ ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
+ colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animator) {
+ cardView.setCardBackgroundColor((Integer) animator.getAnimatedValue());
+ }
+ });
+ colorAnimation.start();
+ }
+ }
+
/**
* Is it null? Is that null? What about that one? Is that null too? What about this one?
* And this one? Is this null? Is null even null? How can null be real if our eyes aren't real?
@@ -445,18 +466,4 @@ private static void callListener(Palette palette, OnPaletteRenderedListener onPa
onPaletteRenderedListener.onRendered(palette);
}
}
-
-// /**
-// * Will return a {@link android.support.v7.graphics.Palette} if it's available in the cache
-// * @param id The URL or ID that was used to render the {@link android.support.v7.graphics.Palette}.
-// * @return The desired {@link android.support.v7.graphics.Palette} if available, otherwise null.
-// */
-// public static Palette getPaletteFromCache(String id) {
-// if (paletteCache.containsKey(id)){
-// return paletteCache.get(id);
-// } else {
-// return null;
-// }
-// }
-
}
diff --git a/example/.gitignore b/sample/.gitignore
similarity index 100%
rename from example/.gitignore
rename to sample/.gitignore
diff --git a/example/build.gradle b/sample/build.gradle
similarity index 67%
rename from example/build.gradle
rename to sample/build.gradle
index 339a7b0..7413f7c 100644
--- a/example/build.gradle
+++ b/sample/build.gradle
@@ -5,7 +5,7 @@ android {
buildToolsVersion "22.0.1"
defaultConfig {
- applicationId "com.musenkishi.paletteloader"
+ applicationId "com.musenkishi.paletteloader.sample"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
@@ -21,6 +21,10 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
+ compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
+ compile 'com.android.support:recyclerview-v7:21.0.0'
+ compile 'com.android.support:cardview-v7:22.1.1'
+ compile 'com.github.bumptech.glide:glide:3.6.0'
compile project(':lib')
}
diff --git a/example/proguard-rules.pro b/sample/proguard-rules.pro
similarity index 100%
rename from example/proguard-rules.pro
rename to sample/proguard-rules.pro
diff --git a/example/src/androidTest/java/com/musenkishi/paletteloader/ApplicationTest.java b/sample/src/androidTest/java/com/musenkishi/paletteloader/ApplicationTest.java
similarity index 100%
rename from example/src/androidTest/java/com/musenkishi/paletteloader/ApplicationTest.java
rename to sample/src/androidTest/java/com/musenkishi/paletteloader/ApplicationTest.java
diff --git a/example/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
similarity index 84%
rename from example/src/main/AndroidManifest.xml
rename to sample/src/main/AndroidManifest.xml
index 15aba90..92e7ab5 100644
--- a/example/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -1,6 +1,8 @@
+ package="com.musenkishi.paletteloader.sample" >
+
+
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")
+ }));
+
+}
diff --git a/sample/src/main/java/com/musenkishi/paletteloader/sample/Country.java b/sample/src/main/java/com/musenkishi/paletteloader/sample/Country.java
new file mode 100644
index 0000000..54ddbeb
--- /dev/null
+++ b/sample/src/main/java/com/musenkishi/paletteloader/sample/Country.java
@@ -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;
+ }
+}
diff --git a/sample/src/main/java/com/musenkishi/paletteloader/sample/CountryAdapter.java b/sample/src/main/java/com/musenkishi/paletteloader/sample/CountryAdapter.java
new file mode 100644
index 0000000..e4bad73
--- /dev/null
+++ b/sample/src/main/java/com/musenkishi/paletteloader/sample/CountryAdapter.java
@@ -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 {
+
+ @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 glideDrawableRequestListener = new RequestListener() {
+ @Override
+ public boolean onException(Exception e,
+ String url,
+ Target target,
+ boolean isFirstResource) {
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(GlideDrawable resource,
+ String url,
+ Target 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);
+ }
+ }
+
+}
diff --git a/example/src/main/java/com/musenkishi/paletteloader/MainActivity.java b/sample/src/main/java/com/musenkishi/paletteloader/sample/MainActivity.java
similarity index 65%
rename from example/src/main/java/com/musenkishi/paletteloader/MainActivity.java
rename to sample/src/main/java/com/musenkishi/paletteloader/sample/MainActivity.java
index 19ceb81..0e4422e 100644
--- a/example/src/main/java/com/musenkishi/paletteloader/MainActivity.java
+++ b/sample/src/main/java/com/musenkishi/paletteloader/sample/MainActivity.java
@@ -1,17 +1,24 @@
-package com.musenkishi.paletteloader;
+package com.musenkishi.paletteloader.sample;
-import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
-public class MainActivity extends ActionBarActivity {
+public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+
+ RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
+ LinearLayoutManager layoutManager = new LinearLayoutManager(this);
+ recyclerView.setLayoutManager(layoutManager);
+ recyclerView.setAdapter(new CountryAdapter());
}
@Override
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..42f762a
--- /dev/null
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
diff --git a/sample/src/main/res/layout/list_item.xml b/sample/src/main/res/layout/list_item.xml
new file mode 100644
index 0000000..f1a5ea2
--- /dev/null
+++ b/sample/src/main/res/layout/list_item.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/example/src/main/res/menu/menu_main.xml b/sample/src/main/res/menu/menu_main.xml
similarity index 100%
rename from example/src/main/res/menu/menu_main.xml
rename to sample/src/main/res/menu/menu_main.xml
diff --git a/example/src/main/res/mipmap-hdpi/ic_launcher.png b/sample/src/main/res/mipmap-hdpi/ic_launcher.png
similarity index 100%
rename from example/src/main/res/mipmap-hdpi/ic_launcher.png
rename to sample/src/main/res/mipmap-hdpi/ic_launcher.png
diff --git a/example/src/main/res/mipmap-mdpi/ic_launcher.png b/sample/src/main/res/mipmap-mdpi/ic_launcher.png
similarity index 100%
rename from example/src/main/res/mipmap-mdpi/ic_launcher.png
rename to sample/src/main/res/mipmap-mdpi/ic_launcher.png
diff --git a/example/src/main/res/mipmap-xhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
similarity index 100%
rename from example/src/main/res/mipmap-xhdpi/ic_launcher.png
rename to sample/src/main/res/mipmap-xhdpi/ic_launcher.png
diff --git a/example/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
similarity index 100%
rename from example/src/main/res/mipmap-xxhdpi/ic_launcher.png
rename to sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
diff --git a/sample/src/main/res/values-v21/fonts.xml b/sample/src/main/res/values-v21/fonts.xml
new file mode 100644
index 0000000..15629ea
--- /dev/null
+++ b/sample/src/main/res/values-v21/fonts.xml
@@ -0,0 +1,4 @@
+
+
+ sans-serif-medium
+
\ No newline at end of file
diff --git a/example/src/main/res/values-w820dp/dimens.xml b/sample/src/main/res/values-w820dp/dimens.xml
similarity index 100%
rename from example/src/main/res/values-w820dp/dimens.xml
rename to sample/src/main/res/values-w820dp/dimens.xml
diff --git a/example/src/main/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml
similarity index 100%
rename from example/src/main/res/values/dimens.xml
rename to sample/src/main/res/values/dimens.xml
diff --git a/sample/src/main/res/values/fonts.xml b/sample/src/main/res/values/fonts.xml
new file mode 100644
index 0000000..cf1294a
--- /dev/null
+++ b/sample/src/main/res/values/fonts.xml
@@ -0,0 +1,4 @@
+
+
+ sans-serif
+
\ No newline at end of file
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
new file mode 100644
index 0000000..fac0da4
--- /dev/null
+++ b/sample/src/main/res/values/strings.xml
@@ -0,0 +1,4 @@
+
+ PaletteLoader Sample
+ Settings
+
diff --git a/example/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
similarity index 60%
rename from example/src/main/res/values/styles.xml
rename to sample/src/main/res/values/styles.xml
index 766ab99..ac1962f 100644
--- a/example/src/main/res/values/styles.xml
+++ b/sample/src/main/res/values/styles.xml
@@ -1,7 +1,7 @@
-
diff --git a/settings.gradle b/settings.gradle
index 90c274b..035bb58 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':example', ':lib'
+include ':sample', ':lib'