Skip to content

Commit

Permalink
1、fix bugs
Browse files Browse the repository at this point in the history
2、add setBorder setBadgeBackground method
  • Loading branch information
qstumn committed Mar 21, 2017
1 parent f3c24a1 commit 8095051
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 74 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/q/rorbin/badgeviewdemo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package q.rorbin.badgeviewdemo;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand Down Expand Up @@ -57,9 +59,12 @@ protected void onCreate(Bundle savedInstanceState) {
private void initBadge() {
badges = new ArrayList<>();
badges.add(new QBadgeView(this).bindTarget(textview).setBadgeNumber(5));
badges.add(new QBadgeView(this).bindTarget(imageview).setBadgeText("(`・ω・´)ฅ").setBadgeBackgroundColor(0xff5677fc));
badges.add(new QBadgeView(this).bindTarget(button).setBadgeText("新").setBadgeTextSize(15, true)
.setBadgeBackgroundColor(0xffffeb3b).setBadgeTextColor(0xff000000));
badges.add(new QBadgeView(this).bindTarget(imageview).setBadgeText("PNG").setBadgeTextColor(0x00000000)
.setBadgeGravity(Gravity.BOTTOM | Gravity.END).setBadgeBackgroundColor(0xff03a9f4)
.setBadgeBackground(getResources().getDrawable(R.drawable.shape_round_rect)));
badges.add(new QBadgeView(this).bindTarget(button).setBadgeText("新").setBadgeTextSize(13, true)
.setBadgeBackgroundColor(0xffffeb3b).setBadgeTextColor(0xff000000)
.setBorder(0xff000000, 1, true));
}

private void initView() {
Expand Down Expand Up @@ -294,9 +299,9 @@ private void selectorColor(final OnColorClickListener l) {
GridView gv = new GridView(this);
gv.setNumColumns(4);
gv.setAdapter(new BaseAdapter() {
int[] colors = new int[]{0xffffffff, 0xff000000, 0xffe51c23, 0xffE84E40, 0xff9c27b0, 0xff673ab7,
int[] colors = new int[]{Color.TRANSPARENT, 0xffffffff, 0xff000000, 0xffe51c23, 0xffE84E40, 0xff9c27b0, 0xff673ab7,
0xff3f51b5, 0xff5677fc, 0xff03a9f4, 0xff00bcd4, 0xff009688, 0xff259b24, 0xff8bc34a, 0xffcddc39,
0xffffeb3b, 0xffffc107, 0xffff9800, 0xffff5722, 0xff795548, 0xff9e9e9e};
0xffffeb3b, 0xffffc107, 0xffff9800, 0xffff5722, 0xff795548};

@Override
public int getCount() {
Expand Down Expand Up @@ -328,14 +333,15 @@ public void onClick(View v) {
WindowManager wm = (WindowManager) MainActivity.this
.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
GridView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT,
GridView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
(int) (dm.widthPixels / 5f));
v.setLayoutParams(lp);
return v;
}
});
dialog.setView(gv);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0x33FFFFFF));
}

interface OnColorClickListener {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/shape_round_rect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff03a9f4" />
<corners android:radius="2dp" />
</shape>
2 changes: 1 addition & 1 deletion badgeviewlib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ publish {
userOrg = 'qstumn'
groupId = 'q.rorbin'
artifactId = 'badgeview'
publishVersion = '1.0.6'
publishVersion = '1.0.8'
desc = 'android badgeview can drag dismiss like QQ'
website = 'https://github.com/qstumn/BadgeView'
}
Expand Down
1 change: 0 additions & 1 deletion badgeviewlib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
package="q.rorbin.badgeview">

<application />

</manifest>
9 changes: 9 additions & 0 deletions badgeviewlib/src/main/java/q/rorbin/badgeview/Badge.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package q.rorbin.badgeview;

import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.view.View;

/**
Expand Down Expand Up @@ -28,8 +29,16 @@ public interface Badge {

Badge setBadgeBackgroundColor(int color);

Badge setBorder(int color, float width, boolean isDpValue);

int getBadgeBackgroundColor();

Badge setBadgeBackground(Drawable drawable);

Badge setBadgeBackground(Drawable drawable, boolean clip);

Drawable getBadgeBackground();

Badge setBadgeTextColor(int color);

int getBadgeTextColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author chqiu
* Email:[email protected]
* 隐藏动画,动画参考自https://github.com/tyrantgit/ExplosionField
* Animation borrowed from https://github.com/tyrantgit/ExplosionField
*/

public class BadgeAnimator extends ValueAnimator {
Expand Down
68 changes: 68 additions & 0 deletions badgeviewlib/src/main/java/q/rorbin/badgeview/MathUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package q.rorbin.badgeview;

import android.graphics.PointF;

import java.util.List;

/**
* Created by chqiu on 2017/3/20.
*/

public class MathUtil {
public static final double CIRCLE_RADIAN = 2 * Math.PI;

public static double getTanRadian(double atan, int quadrant) {
if (atan < 0) {
atan += CIRCLE_RADIAN / 4;
}
atan += CIRCLE_RADIAN / 4 * (quadrant - 1);
return atan;
}

public static double radianToAngle(double radian) {
return 360 * (radian / CIRCLE_RADIAN);
}

public static int getQuadrant(PointF p, PointF center) {
if (p.x > center.x) {
if (p.y > center.y) {
return 4;
} else if (p.y < center.y) {
return 1;
}
} else if (p.x < center.x) {
if (p.y > center.y) {
return 3;
} else if (p.y < center.y) {
return 2;
}
}
return -1;
}

public static float getPointDistance(PointF p1, PointF p2) {
return (float) Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
}

/**
* this formula is designed by mabeijianxi
* website : http://blog.csdn.net/mabeijianxi/article/details/50560361
*
* @param circleCenter The circle center point.
* @param radius The circle radius.
* @param slopeLine The slope of line which cross the pMiddle.
*/
public static void getInnertangentPoints(PointF circleCenter, float radius, Double slopeLine, List<PointF> points) {
float radian, xOffset, yOffset;
if (slopeLine != null) {
radian = (float) Math.atan(slopeLine);
xOffset = (float) (Math.cos(radian) * radius);
yOffset = (float) (Math.sin(radian) * radius);
} else {
xOffset = radius;
yOffset = 0;
}
points.add(new PointF(circleCenter.x + xOffset, circleCenter.y + yOffset));
points.add(new PointF(circleCenter.x - xOffset, circleCenter.y - yOffset));
}
}
Loading

0 comments on commit 8095051

Please sign in to comment.