Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	readme.md
  • Loading branch information
musenkishi committed May 14, 2015
2 parents 1b94892 + 2547bfc commit 6a701b9
Show file tree
Hide file tree
Showing 29 changed files with 306 additions and 66 deletions.
5 changes: 1 addition & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'

classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -15,8 +15,5 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
11 changes: 0 additions & 11 deletions example/src/main/res/layout/activity_main.xml

This file was deleted.

6 changes: 0 additions & 6 deletions example/src/main/res/values/strings.xml

This file was deleted.

12 changes: 11 additions & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'android-maven'

android {
compileSdkVersion 22
Expand All @@ -22,5 +22,15 @@ 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'
}

// build a jar with source files
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
49 changes: 28 additions & 21 deletions lib/src/main/java/com/musenkishi/paletteloader/PaletteLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +104,7 @@ public boolean handleMessage(Message message) {

Message uiMessage = uiHandler.obtainMessage();
uiMessage.what = MSG_DISPLAY_PALETTE;
uiMessage.obj = new Pair<Palette, PaletteTarget>(palette, pair.second);
uiMessage.obj = new Pair<>(palette, pair.second);
uiMessage.arg1 = FALSE;

uiHandler.sendMessage(uiMessage);
Expand Down Expand Up @@ -143,8 +144,8 @@ public PaletteBuilder load(Bitmap bitmap) {
return this;
}

public PaletteBuilder load(Palette colorScheme) {
this.palette = colorScheme;
public PaletteBuilder load(Palette palette) {
this.palette = palette;
return this;
}

Expand Down Expand Up @@ -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>(bitmap, paletteTarget);
bgMessage.obj = new Pair<>(bitmap, paletteTarget);
backgroundHandler.sendMessage(bgMessage);
}
}
Expand All @@ -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()) {
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -331,12 +352,12 @@ private PaletteRenderer(Bitmap bitmap, PaletteTarget paletteTarget) {
@Override
public void run() {
if (bitmap != null && !bitmap.isRecycled()) {
Palette colorScheme = Palette.generate(bitmap);
paletteCache.put(paletteTarget.getId(), colorScheme);
Palette palette = Palette.generate(bitmap);
paletteCache.put(paletteTarget.getId(), palette);

PalettePresenter palettePresenter = new PalettePresenter(
paletteTarget,
colorScheme,
palette,
false
);
uiHandler.post(palettePresenter);
Expand Down Expand Up @@ -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;
// }
// }

}
35 changes: 19 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PaletteLoader

![](https://img.shields.io/github/release/Musenkishi/PaletteLoader.svg?label=JitPack%20Maven)

This is a library aiming to simplify the use of Palette, especially in lists such as ListView, GridView, or RecyclerView.

## Download
Expand All @@ -13,9 +15,9 @@ repositories {
}
```

Now, you can add the RxBonjour dependency:
Now, you can add the PaletteLoader dependency:
```groovy
compile 'com.github.Musenkishi:PaletteLoader:1.0'
compile 'com.github.Musenkishi:PaletteLoader:1.1.0'
```

## Usage
Expand All @@ -24,8 +26,9 @@ Currently PaletteLoader supports classes (and extensions of):
* View
* ImageView (masking and background)
* TextView
* CardView

If the supplied view is or extends `View`, PaletteLoader will apply the color to the background. If view extends `ImageView` and you use `.mask()`, PaletteLoader will apply the color to the image, not the background. And lastly if view is, or extends `TextView`, the color will be applied to the text, not the background.
If the supplied view is or extends `View`, PaletteLoader will apply the color to the background. If view extends `ImageView` and you use `.mask()`, PaletteLoader will apply the color to the image, not the background. And lastly if view is, or extends `TextView`, the color will be applied to the text, not the background. If view is or extends `CardView`, PaletteLoader will apply the color through `.setCardBackgroundColor()`.

```java
PaletteLoader.with(context, uniqueStringForBitmap) //For reuse purposes uniqueStringForBitmap could be the url for the image.
Expand All @@ -42,15 +45,15 @@ In this example [Glide][glide] is used, which is similar to Picasso:
```java
RequestListener<String, GlideDrawable> glideDrawableRequestListener = new RequestListener<String, GlideDrawable>() {
@Override
public boolean onResourceReady(GlideDrawable resource,
String model,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
public boolean onResourceReady(GlideDrawable resource,
String model,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
boolean isFirstResource) {
Bitmap bitmap = ((GlideBitmapDrawable) resource).getBitmap();
if (bitmap != null) {
Context context = viewHolder.bottomBar.getContext();

//Set color to a View's background
PaletteLoader.with(context, model)
.load(bitmap)
Expand All @@ -59,32 +62,32 @@ RequestListener<String, GlideDrawable> glideDrawableRequestListener = new Reques
PaletteRequest.SwatchType.REGULAR_VIBRANT,
PaletteRequest.SwatchColor.BACKGROUND))
.into(viewHolder.bottomBar);

//Set color to text in a TextView
PaletteLoader.with(context, model)
.load(bitmap)
.setPaletteRequest(
new PaletteRequest(
PaletteRequest.SwatchType.REGULAR_VIBRANT,
PaletteRequest.SwatchType.REGULAR_VIBRANT,
PaletteRequest.SwatchColor.TEXT_TITLE))
.into(viewHolder.textViewResolution);
//Colorize an ImageView/ImageButton with .mask().

//Colorize an ImageView/ImageButton with .mask().
//Best result is accomplished with a white image (transparent bakground).
PaletteLoader.with(context, model)
.load(bitmap)
.fallbackColor(viewHolder.textViewResolution.getCurrentTextColor())
.setPaletteRequest(
new PaletteRequest(
PaletteRequest.SwatchType.REGULAR_VIBRANT,
PaletteRequest.SwatchType.REGULAR_VIBRANT,
PaletteRequest.SwatchColor.TEXT_TITLE))
.mask()
.into(viewHolder.imageButton);
}
return false;
}
};

Glide.with(viewHolder.bottomBar.getContext())
.load(imageUrl)
.fitCenter()
Expand All @@ -111,7 +114,7 @@ PaletteLoader will generate the palette in a seperate thread (up to 5 threads on
See the License for the specific language governing permissions and
limitations under the License.


[jmdns]: https://github.com/openhab/jmdns
[jit]: https://jitpack.io
[glide]: https://github.com/bumptech/glide
[glide]: https://github.com/bumptech/glide
File renamed without changes.
6 changes: 5 additions & 1 deletion example/build.gradle → sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.musenkishi.paletteloader" >
package="com.musenkishi.paletteloader.sample" >

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
Expand Down
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")
}));

}
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;
}
}
Loading

0 comments on commit 6a701b9

Please sign in to comment.