Skip to content

Commit

Permalink
Finished ColorFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Jan 5, 2016
1 parent 9be3f31 commit 7a0b3d7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public enum PURE_COLOR{CYAN, TEAL}
public static final int PURE_CYAN = 1;
public static final int PURE_TEAL = 2;

public static final int SHARP666 = Color.parseColor("#FF666666");
public static final int SHARP00BCD4 = Color.parseColor("#FF00BCD4");
public static final int SHARP009688 = Color.parseColor("#FF009688");
public static final int SHARP666666 = Color.parseColor("#FF666666");
public static final int SHARP727272 = Color.parseColor("#FF727272");

private static final String[] COLORS = new String[]{RED, LIGHTBLUE, AMBER, ORANGE, YELLOW,
LIME, BLUE, INDIGO, LIGHTGREEN, GREY, DEEPPURPLE, TEAL, CYAN};
Expand All @@ -48,16 +47,15 @@ public static int[] onRandomBuild(){
int random = (int)(Math.random() * COLORS.length);
int bgColor = Color.parseColor("#" + BG_COLOR_ALPHA + COLORS[random]);
int bdColor = Color.parseColor("#" + BD_COLOR_ALPHA + COLORS[random]);
int tColor = SHARP666;
int tColor = SHARP666666;
return new int[]{bgColor, bdColor, tColor};
}

public static int[] onPureBuild(PURE_COLOR type){
String color = type == PURE_COLOR.CYAN ? CYAN : TEAL;
int textColor = type == PURE_COLOR.CYAN ? SHARP00BCD4 : SHARP009688;
int bgColor = Color.parseColor("#" + BG_COLOR_ALPHA + color);
int bdColor = Color.parseColor("#" + BD_COLOR_ALPHA + color);
int tColor = textColor;
int tColor = SHARP727272;
return new int[]{bgColor, bdColor, tColor};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import android.view.ViewGroup;

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

/**
* Author: lujun(http://blog.lujun.co)
* Date: 2015-12-30 17:14
*/
public class ContainerLayout extends ViewGroup {
public class TagContainerLayout extends ViewGroup {

/** Vertical interval, default 5(dp)*/
private float mVerticalInterval;
Expand Down Expand Up @@ -79,15 +80,15 @@ public class ContainerLayout extends ViewGroup {
/** Default tag min length*/
private static final int TAG_MIN_LENGTH = 3;

public ContainerLayout(Context context) {
public TagContainerLayout(Context context) {
this(context, null);
}

public ContainerLayout(Context context, AttributeSet attrs) {
public TagContainerLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public ContainerLayout(Context context, AttributeSet attrs, int defStyleAttr){
public TagContainerLayout(Context context, AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
init(context, attrs, defStyleAttr);
}
Expand Down Expand Up @@ -221,7 +222,6 @@ private int getChildLines(int childCount){

private int[] onUpdateColorFactory(){
int[] colors;
// FIXME , random color bg & bd not match
if (mTheme == ColorFactory.RANDOM){
colors = ColorFactory.onRandomBuild();
}else if (mTheme == ColorFactory.PURE_TEAL){
Expand Down Expand Up @@ -253,10 +253,11 @@ private void onAddTag(String text, int position){
}else {
tagView.setTag(position);
}
int[] colors = onUpdateColorFactory();
tagView.setTagMaxLength(mTagMaxLength);
tagView.setTagBackgroundColor(onUpdateColorFactory()[0]);
tagView.setTagBorderColor(onUpdateColorFactory()[1]);
tagView.setTagTextColor(onUpdateColorFactory()[2]);
tagView.setTagBackgroundColor(colors[0]);
tagView.setTagBorderColor(colors[1]);
tagView.setTagTextColor(colors[2]);
addView(tagView, position);
}

Expand Down Expand Up @@ -408,6 +409,15 @@ public void setTags(List<String> tags){
onSetTag();
}

/**
* Set tags
* @param tags
*/
public void setTags(String... tags){
mTags = Arrays.asList(tags);
onSetTag();
}

/**
* Set OnTagClickListener for TagView.
* @param listener
Expand Down
21 changes: 10 additions & 11 deletions sample/src/main/java/co/lujun/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import java.util.ArrayList;
import java.util.List;

import co.lujun.androidtagview.ColorFactory;
import co.lujun.androidtagview.ContainerLayout;
import co.lujun.androidtagview.TagContainerLayout;
import co.lujun.androidtagview.TagView;

public class MainActivity extends AppCompatActivity {

private ContainerLayout mContainerLayout;
private TagContainerLayout mTagContainerLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -25,8 +24,8 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

mContainerLayout = (ContainerLayout) findViewById(R.id.containerLayout);
mContainerLayout.setOnTagClickListener(new TagView.OnTagClickListener() {
mTagContainerLayout = (TagContainerLayout) findViewById(R.id.tagcontainerLayout);
mTagContainerLayout.setOnTagClickListener(new TagView.OnTagClickListener() {
@Override
public void onTagClick(int position, String text) {
Toast.makeText(MainActivity.this, "position:" + position + ", text:" + text,
Expand All @@ -45,23 +44,23 @@ public void onTagClick(int position, String text) {
list.add("Html");
list.add("Hello, this is a TAG example.");
list.add("Welcome to use AndroidTagView!");
// mContainerLayout.setTagMaxLength(4);
mContainerLayout.setTheme(ColorFactory.RANDOM);
mContainerLayout.setTags(list);
// mTagContainerLayout.setTagMaxLength(4);
// mTagContainerLayout.setTheme(ColorFactory.PURE_CYAN);
mTagContainerLayout.setTags(list);

Button btnAddTag = (Button) findViewById(R.id.btn_add_tag);
btnAddTag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mContainerLayout.addTag("This is a TAG u added!");
// mContainerLayout.addTag("This is a TAG u added!", 4);
mTagContainerLayout.addTag("This is a TAG u added!");
// mTagContainerLayout.addTag("This is a TAG u added!", 4);
}
});
Button btnRemoveTag = (Button) findViewById(R.id.btn_remove_tag);
btnRemoveTag.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mContainerLayout.removeTag(5);
mTagContainerLayout.removeTag(5);
}
});
}
Expand Down
13 changes: 8 additions & 5 deletions sample/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
Expand All @@ -13,8 +12,8 @@
tools:context="co.lujun.sample.MainActivity"
tools:showIn="@layout/activity_main">

<co.lujun.androidtagview.ContainerLayout
android:id="@+id/containerLayout"
<co.lujun.androidtagview.TagContainerLayout
android:id="@+id/tagcontainerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
Expand All @@ -29,11 +28,15 @@
android:id="@+id/btn_add_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="add tag" />

<Button
android:id="@+id/btn_remove_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="remove tag" />
</LinearLayout>
</RelativeLayout>

0 comments on commit 7a0b3d7

Please sign in to comment.