aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/widget
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-22 14:19:03 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-22 14:19:03 +0200
commit60494b249b13b09319d6ff944935b6dbbf71ba6b (patch)
tree8d7a918c32497ecb4af61ebeb3a7b76ce8cc28d7 /src/main/java/de/pixart/messenger/ui/widget
parent13f58b1708b37757a7c4e934badcdd09b9aa12d5 (diff)
introduced sroll to bottom button
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/widget')
-rw-r--r--src/main/java/de/pixart/messenger/ui/widget/UnreadCountCustomView.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/widget/UnreadCountCustomView.java b/src/main/java/de/pixart/messenger/ui/widget/UnreadCountCustomView.java
new file mode 100644
index 000000000..6b4a6de0f
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/widget/UnreadCountCustomView.java
@@ -0,0 +1,77 @@
+package de.pixart.messenger.ui.widget;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Typeface;
+import android.support.v4.content.ContextCompat;
+import android.util.AttributeSet;
+import android.view.View;
+
+import de.pixart.messenger.R;
+
+public class UnreadCountCustomView extends View {
+
+ private int unreadCount;
+ private Paint paint, textPaint;
+ private int backgroundColor = 0xff326130;
+
+ public UnreadCountCustomView(Context context) {
+ super(context);
+ init();
+ }
+
+ public UnreadCountCustomView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initXMLAttrs(context, attrs);
+ init();
+ }
+
+ public UnreadCountCustomView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initXMLAttrs(context, attrs);
+ init();
+ }
+
+ private void initXMLAttrs(Context context, AttributeSet attrs) {
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnreadCountCustomView);
+ //setBackgroundColor(a.getColor(a.getIndex(0), ContextCompat.getColor(context, R.color.accent)));
+ setBackgroundColor(ContextCompat.getColor(context, R.color.accent));
+ a.recycle();
+ }
+
+ void init() {
+ paint = new Paint();
+ paint.setColor(backgroundColor);
+ paint.setAntiAlias(true);
+ textPaint = new Paint();
+ textPaint.setColor(Color.WHITE);
+ textPaint.setTextAlign(Paint.Align.CENTER);
+ textPaint.setAntiAlias(true);
+ textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ float midx = canvas.getWidth() / 2.0f;
+ float midy = canvas.getHeight() / 2.0f;
+ float radius = Math.min(canvas.getWidth(), canvas.getHeight()) / 2.0f;
+ float textOffset = canvas.getWidth() / 6.0f;
+ textPaint.setTextSize(0.95f * radius);
+ canvas.drawCircle(midx, midy, radius * 0.94f, paint);
+ canvas.drawText(unreadCount > 999 ? "\u221E" : String.valueOf(unreadCount), midx, midy + textOffset, textPaint);
+
+ }
+
+ public void setUnreadCount(int unreadCount) {
+ this.unreadCount = unreadCount;
+ invalidate();
+ }
+
+ public void setBackgroundColor(int backgroundColor) {
+ this.backgroundColor = backgroundColor;
+ }
+}