Skip to content

Commit

Permalink
fix issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
misakuo committed Feb 6, 2016
1 parent dfd3069 commit bc6dadc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.moxun:tagcloudlib:1.0.3'
//compile 'com.moxun:tagcloudlib:1.0.3'
compile project(path: ':tagcloudlib')
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/moxun/tagcloud/TextTagsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Object getItem(int position) {

@Override
public int getPopularity(int position) {
return Math.abs(new Random().nextInt(5) + 2);
return position % 7;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:autoScrollMode="uniform"
app:lightColor="#0fe291"
app:darkColor="#123456"
app:lightColor="#ffff0000"
app:darkColor="#ff00ff00"
app:radiusPercent="0.5"
app:scrollSpeed="3"/>

Expand Down
2 changes: 1 addition & 1 deletion tagcloudlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.0.3"
version = "1.1.0"
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "23.0.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moxun.tagcloudlib.view;

import android.graphics.Color;
import android.util.Log;

/**
* Copyright © 2016 moxun
Expand Down Expand Up @@ -132,9 +133,10 @@ public void setColorByArray(float[] rgb) {
public int getColor() {
int[] result = new int[4];
for (int i = 0; i < 4; i++) {
result[i] = (int) (this.argb[i] * 256);
result[i] = (int) (this.argb[i] * 0xff);
}
int color = Color.argb(result[0], result[1], result[2], result[3]);
Log.e("TAG","#" + Integer.toHexString(color));
return color;
}
}
21 changes: 12 additions & 9 deletions tagcloudlib/src/main/java/com/moxun/tagcloudlib/view/TagCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -132,8 +134,8 @@ public void update() {

private void initTag(Tag tag) {
float percentage = getPercentage(tag);
float[] tempColor = getColorFromGradient(percentage); //(rgb Alpha)
tag.setColorByArray(tempColor);
float[] argb = getColorFromGradient(percentage);
tag.setColorByArray(argb);
}

private float getPercentage(Tag tag) {
Expand Down Expand Up @@ -225,13 +227,14 @@ private void updateAll() {
}
}

private float[] getColorFromGradient(float perc) {
float[] tempRGB = new float[4];
tempRGB[0] = (perc * (tagColorLight[0])) + ((1 - perc) * (tagColorDark[0]));
tempRGB[1] = (perc * (tagColorLight[1])) + ((1 - perc) * (tagColorDark[1]));
tempRGB[2] = (perc * (tagColorLight[2])) + ((1 - perc) * (tagColorDark[2]));
tempRGB[3] = 1;
return tempRGB;
private float[] getColorFromGradient(float percentage) {
//perc: 1.0 full dark; 0.0 full light
float[] rgba = new float[4];
rgba[0] = 1f; //Alpha is 1.0 when init.
rgba[1] = (percentage * (tagColorDark[0])) + ((1f - percentage) * (tagColorLight[0]));
rgba[2] = (percentage * (tagColorDark[1])) + ((1f - percentage) * (tagColorLight[1]));
rgba[3] = (percentage * (tagColorDark[2])) + ((1f - percentage) * (tagColorLight[2]));
return rgba;
}

private void sineCosine(float mAngleX, float mAngleY, float mAngleZ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public class TagCloudView extends ViewGroup implements Runnable, TagsAdapter.OnD
private float radius;
private float radiusPercent = 0.9f;

private float[] darkColor = new float[]{1f, 0f, 0f, 1};
private float[] lightColor = new float[]{0.9412f, 0.7686f, 0.2f, 1};
private float[] darkColor = new float[]{1f, 0f, 0f, 1f};//rgba
private float[] lightColor = new float[]{0.9412f, 0.7686f, 0.2f, 1f};//rgba

public static final int MODE_DISABLE = 0;
public static final int MODE_DECELERATE = 1;
Expand All @@ -68,41 +68,41 @@ public class TagCloudView extends ViewGroup implements Runnable, TagsAdapter.OnD

public TagCloudView(Context context) {
super(context);
setFocusableInTouchMode(true);
init(context,null);
}

public TagCloudView(Context context, AttributeSet attrs) {
super(context, attrs);
setFocusableInTouchMode(true);
init(context,attrs);
}

public TagCloudView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setFocusableInTouchMode(true);
init(context,attrs);
}

private void init(Context context, AttributeSet attrs) {
setFocusableInTouchMode(true);
mTagCloud = new TagCloud();
if (attrs != null) {
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TagCloudView);

String m = typedArray.getString(R.styleable.TagCloudView_autoScrollMode);
mode = Integer.valueOf(m);

int light = typedArray.getColor(R.styleable.TagCloudView_lightColor,Color.GREEN);
int light = typedArray.getColor(R.styleable.TagCloudView_lightColor,Color.WHITE);
setLightColor(light);

int dark = typedArray.getColor(R.styleable.TagCloudView_darkColor,Color.GRAY);
int dark = typedArray.getColor(R.styleable.TagCloudView_darkColor,Color.BLACK);
setDarkColor(dark);

float p = typedArray.getFloat(R.styleable.TagCloudView_radiusPercent,radiusPercent);
setRadiusPercent(p);

float s = typedArray.getFloat(R.styleable.TagCloudView_scrollSpeed,2f);
setScrollSpeed(s);

typedArray.recycle();
}

WindowManager wm = (WindowManager) getContext() .getSystemService(Context.WINDOW_SERVICE);
Expand Down Expand Up @@ -130,21 +130,21 @@ public final void setAdapter(TagsAdapter adapter) {

public void setLightColor(int color) {
float[] argb = new float[4];
argb[0] = Color.alpha(color) /1.0f / 255;
argb[1] = Color.red(color) /1.0f / 255;
argb[2] = Color.green(color) /1.0f / 255;
argb[3] = Color.blue(color) /1.0f / 255;
argb[3] = Color.alpha(color) /1.0f / 0xff;
argb[0] = Color.red(color) /1.0f / 0xff;
argb[1] = Color.green(color) /1.0f / 0xff;
argb[2] = Color.blue(color) /1.0f / 0xff;

lightColor = argb.clone();
onChange();
}

public void setDarkColor(int color) {
float[] argb = new float[4];
argb[0] = Color.alpha(color) /1.0f / 255;
argb[1] = Color.red(color) /1.0f / 255;
argb[2] = Color.green(color) /1.0f / 255;
argb[3] = Color.blue(color) /1.0f / 255;
argb[3] = Color.alpha(color) /1.0f / 0xff;
argb[0] = Color.red(color) /1.0f / 0xff;
argb[1] = Color.green(color) /1.0f / 0xff;
argb[2] = Color.blue(color) /1.0f / 0xff;

darkColor = argb.clone();
onChange();
Expand Down

0 comments on commit bc6dadc

Please sign in to comment.