diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java
index 1c9e66e2..902e10c8 100644
--- a/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java
+++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/MainActivity.java
@@ -33,6 +33,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
+import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -46,6 +47,7 @@ import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.GravityCompat;
+import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
@@ -77,6 +79,7 @@ import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.data.PodUserProfile;
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
+import com.github.dfa.diaspora_android.ui.BadgeDrawable;
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
import com.github.dfa.diaspora_android.ui.CustomWebViewClient;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
@@ -699,25 +702,21 @@ public class MainActivity extends AppCompatActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main__menu_top, menu);
- return true;
+ return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- MenuItem itemNotification = menu.findItem(R.id.action_notifications);
- if (itemNotification != null) {
- if (podUserProfile.getNotificationCount() > 0) {
- itemNotification.setIcon(R.drawable.ic_notifications_colored_48px);
- } else {
- itemNotification.setIcon(R.drawable.ic_notifications_white_48px);
- }
+ MenuItem item;
- MenuItem itemConversation = menu.findItem(R.id.action_conversations);
- if (podUserProfile.getUnreadMessagesCount() > 0) {
- itemConversation.setIcon(R.drawable.ic_email_colored_48px);
- } else {
- itemConversation.setIcon(R.drawable.ic_mail_white_48px);
- }
+ if ((item = menu.findItem(R.id.action_notifications)) != null) {
+ LayerDrawable icon = (LayerDrawable) item.getIcon();
+ BadgeDrawable.setBadgeCount(this, icon, podUserProfile.getNotificationCount());
+ }
+
+ if ((item = menu.findItem(R.id.action_conversations)) != null) {
+ LayerDrawable icon = (LayerDrawable) item.getIcon();
+ BadgeDrawable.setBadgeCount(this, icon, podUserProfile.getUnreadMessagesCount());
}
return super.onPrepareOptionsMenu(menu);
}
diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java
new file mode 100644
index 00000000..03460aa9
--- /dev/null
+++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/BadgeDrawable.java
@@ -0,0 +1,127 @@
+package com.github.dfa.diaspora_android.ui;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+import android.support.v4.content.ContextCompat;
+
+import com.github.dfa.diaspora_android.R;
+
+public class BadgeDrawable extends Drawable {
+ // Source: http://mobikul.com/adding-badge-count-on-menu-items-like-cart-notification-etc/
+ private static final String BADGE_VALUE_OVERFLOW = "*";
+
+ private Paint badgeBackground;
+ private Paint badgeStroke;
+ private Paint badgeText;
+ private Rect textRect = new Rect();
+
+ private String badgeValue = "";
+ private boolean shouldDraw;
+
+ public BadgeDrawable(Context context) {
+ float textSize = context.getResources().getDimension(R.dimen.textsize_badge_count);
+
+ badgeBackground = new Paint();
+ badgeBackground.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.accent));
+ badgeBackground.setAntiAlias(true);
+ badgeBackground.setStyle(Paint.Style.FILL);
+ badgeStroke = new Paint();
+ badgeStroke.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.colorPrimaryDark));
+ badgeStroke.setAntiAlias(true);
+ badgeStroke.setStyle(Paint.Style.FILL);
+
+ badgeText = new Paint();
+ badgeText.setColor(Color.WHITE);
+ badgeText.setTypeface(Typeface.DEFAULT);
+ badgeText.setTextSize(textSize);
+ badgeText.setAntiAlias(true);
+ badgeText.setTextAlign(Paint.Align.CENTER);
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ if (!shouldDraw) {
+ return;
+ }
+ Rect bounds = getBounds();
+ float width = bounds.right - bounds.left;
+ float height = bounds.bottom - bounds.top;
+
+ // Position the badge in the top-right quadrant of the icon.
+ float radius = ((Math.max(width, height) / 2)) / 2;
+ float centerX = (width - radius - 1) + 5;
+ float centerY = radius - 5;
+ if (badgeValue.length() <= 2) {
+ // Draw badge circle.
+ canvas.drawCircle(centerX, centerY, (int) (radius + 7.5), badgeStroke);
+ canvas.drawCircle(centerX, centerY, (int) (radius + 5.5), badgeBackground);
+ } else {
+ canvas.drawCircle(centerX, centerY, (int) (radius + 8.5), badgeStroke);
+ canvas.drawCircle(centerX, centerY, (int) (radius + 6.5), badgeBackground);
+ //canvas.drawRoundRect(radius, radius, radius, radius, 10, 10, badgeBackground);
+ }
+ // Draw badge count text inside the circle.
+ badgeText.getTextBounds(badgeValue, 0, badgeValue.length(), textRect);
+ float textHeight = textRect.bottom - textRect.top;
+ float textY = centerY + (textHeight / 2f);
+ if (badgeValue.length() > 2)
+ canvas.drawText(BADGE_VALUE_OVERFLOW, centerX, textY, badgeText);
+ else
+ canvas.drawText(badgeValue, centerX, textY, badgeText);
+ }
+
+ /*
+ Sets the count (i.e notifications) to display.
+ */
+ public void setCount(String count) {
+ badgeValue = count;
+
+ // Only draw a badge if there are notifications.
+ shouldDraw = !count.equalsIgnoreCase("0");
+ invalidateSelf();
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ // do nothing
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ // do nothing
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.UNKNOWN;
+ }
+
+ public static void setBadgeCount(Context context, LayerDrawable icon, Integer count) {
+ setBadgeCount(context, icon, count.toString());
+ }
+
+ public static void setBadgeCount(Context context, LayerDrawable icon, String count) {
+
+ BadgeDrawable badge;
+
+ // Reuse drawable if possible
+ Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
+ if (reuse != null && reuse instanceof BadgeDrawable) {
+ badge = (BadgeDrawable) reuse;
+ } else {
+ badge = new BadgeDrawable(context);
+ }
+
+ badge.setCount(count);
+ icon.mutate();
+ icon.setDrawableByLayerId(R.id.ic_badge, badge);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_email_colored_48px.xml b/app/src/main/res/drawable/ic_email_colored_48px.xml
index ab034128..c79ed6bc 100644
--- a/app/src/main/res/drawable/ic_email_colored_48px.xml
+++ b/app/src/main/res/drawable/ic_email_colored_48px.xml
@@ -1,4 +1,4 @@
-
+
diff --git a/app/src/main/res/drawable/ic_mail_white_48px__layer.xml b/app/src/main/res/drawable/ic_mail_white_48px__layer.xml
new file mode 100644
index 00000000..983a98bf
--- /dev/null
+++ b/app/src/main/res/drawable/ic_mail_white_48px__layer.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_notifications_colored_48px.xml b/app/src/main/res/drawable/ic_notifications_colored_48px.xml
deleted file mode 100644
index c1a647cc..00000000
--- a/app/src/main/res/drawable/ic_notifications_colored_48px.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
diff --git a/app/src/main/res/drawable/ic_notifications_white_48px__layer.xml b/app/src/main/res/drawable/ic_notifications_white_48px__layer.xml
new file mode 100644
index 00000000..971baea6
--- /dev/null
+++ b/app/src/main/res/drawable/ic_notifications_white_48px__layer.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/progressbar.xml b/app/src/main/res/drawable/progressbar.xml
new file mode 100644
index 00000000..44815b57
--- /dev/null
+++ b/app/src/main/res/drawable/progressbar.xml
@@ -0,0 +1,15 @@
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/main__content.xml b/app/src/main/res/layout/main__content.xml
index a50f9875..6794e928 100644
--- a/app/src/main/res/layout/main__content.xml
+++ b/app/src/main/res/layout/main__content.xml
@@ -1,13 +1,13 @@
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:id="@+id/content_layout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior"
+ tools:context=".activity.MainActivity"
+ tools:showIn="@layout/main__app_bar">
+ android:progressDrawable="@drawable/progressbar"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
\ No newline at end of file
diff --git a/app/src/main/res/layout/splash__activity.xml b/app/src/main/res/layout/splash__activity.xml
index 5adde8d1..5f65f563 100644
--- a/app/src/main/res/layout/splash__activity.xml
+++ b/app/src/main/res/layout/splash__activity.xml
@@ -26,11 +26,7 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
- android:layout_marginBottom="15dp"
- android:shadowColor="@color/black"
- android:shadowDx="-4"
- android:shadowDy="4"
- android:shadowRadius="6"
+ android:layout_marginBottom="30dp"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
diff --git a/app/src/main/res/layout/webview.xml b/app/src/main/res/layout/webview.xml
index aa258767..7bece82a 100644
--- a/app/src/main/res/layout/webview.xml
+++ b/app/src/main/res/layout/webview.xml
@@ -1,13 +1,12 @@
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ android:layout_height="fill_parent" />
\ No newline at end of file
diff --git a/app/src/main/res/menu/main__menu_top.xml b/app/src/main/res/menu/main__menu_top.xml
index 06e8f3ec..d6c873b7 100644
--- a/app/src/main/res/menu/main__menu_top.xml
+++ b/app/src/main/res/menu/main__menu_top.xml
@@ -5,13 +5,13 @@
diff --git a/app/src/main/res/values/color.xml b/app/src/main/res/values/color.xml
index 7595c3fc..29bb3179 100644
--- a/app/src/main/res/values/color.xml
+++ b/app/src/main/res/values/color.xml
@@ -8,11 +8,11 @@
#3F51B5
#303F9F
#C5CAE9
- #4CAF50
+ #FF5300
#212121
- #757575
+ #727272
#FFFFFF
- #BDBDBD
+ #B6B6B6
#ffffff
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index e65ac3f4..1009fc6a 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -11,4 +11,7 @@
250dp
+
+
+ 11sp