From 7e2c5600048646e9a1543dbd7a3930167970d8ae Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 24 Mar 2016 01:28:57 +0100 Subject: [PATCH] circle icons for accounts with color coding --- res/layout/drawer_header.xml | 8 +++--- src/com/owncloud/android/ui/TextDrawable.java | 13 +++++----- .../android/ui/activity/DrawerActivity.java | 25 ++++++++++++++----- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/res/layout/drawer_header.xml b/res/layout/drawer_header.xml index a94061d777..76471c8aeb 100644 --- a/res/layout/drawer_header.xml +++ b/res/layout/drawer_header.xml @@ -32,17 +32,19 @@ diff --git a/src/com/owncloud/android/ui/TextDrawable.java b/src/com/owncloud/android/ui/TextDrawable.java index c858a43f27..70dd3521f5 100644 --- a/src/com/owncloud/android/ui/TextDrawable.java +++ b/src/com/owncloud/android/ui/TextDrawable.java @@ -5,7 +5,6 @@ import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; -import android.graphics.RectF; import android.graphics.drawable.Drawable; /** @@ -24,21 +23,23 @@ public class TextDrawable extends Drawable { bg = new Paint(); bg.setStyle(Paint.Style.FILL); + bg.setAntiAlias(true); bg.setColor(color); paint = new Paint(); paint.setColor(Color.WHITE); - paint.setTextSize(20); + paint.setTextSize(60); paint.setAntiAlias(true); paint.setFakeBoldText(true); } @Override public void draw(Canvas canvas) { - //RectF rf = new RectF(0,24,24,0); - //canvas.drawRoundRect(rf,24,24,bg); - canvas.drawRect(0,-20,20,40,bg); - canvas.drawText(text, 4, 6, paint); + //float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius}; + //new RoundRectShape(radii, null, null); + canvas.drawCircle(40, 40, 40, bg); + //canvas.drawRect(0, -20, 20, 40, bg); + canvas.drawText(text, 20, 60, paint); } @Override diff --git a/src/com/owncloud/android/ui/activity/DrawerActivity.java b/src/com/owncloud/android/ui/activity/DrawerActivity.java index 599386b4c0..9eec4bf18f 100644 --- a/src/com/owncloud/android/ui/activity/DrawerActivity.java +++ b/src/com/owncloud/android/ui/activity/DrawerActivity.java @@ -4,6 +4,7 @@ import android.accounts.Account; import android.accounts.AccountManager; import android.content.Intent; import android.content.res.Configuration; +import android.graphics.Color; import android.os.Bundle; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; @@ -250,9 +251,9 @@ public abstract class DrawerActivity extends ToolbarActivity { // add all accounts to list for (int i = 0; i < accounts.length; i++) { try { - int[] rgb = calculateRGB(accounts[i]); - TextDrawable icon = new TextDrawable(accounts[i].name.substring(0, 1).toUpperCase(), - rgb[0], rgb[1], rgb[2]); + int[] rgb = calculateRGB(accounts[i].name); + TextDrawable icon = new TextDrawable(accounts[i].name.substring(0, 1).toUpperCase() + , rgb[0], rgb[1], rgb[2]); mNavigationView.getMenu().add(R.id.drawer_menu_accounts, Menu.NONE, 0, accounts[i].name).setIcon(icon); } catch (Exception e) { Log_OC.e(TAG, "Error calculating RGB value for account menu item.", e); @@ -267,10 +268,10 @@ public abstract class DrawerActivity extends ToolbarActivity { } } - private int[] calculateRGB(Account account) throws UnsupportedEncodingException, NoSuchAlgorithmException { + private int[] calculateRGB(String accountName) throws UnsupportedEncodingException, NoSuchAlgorithmException { // using adapted algorithm from /core/js/placeholder.js:50 - int lastAtPos = account.name.lastIndexOf("@"); - String username = account.name.substring(0, lastAtPos); + int lastAtPos = accountName.lastIndexOf("@"); + String username = accountName.substring(0, lastAtPos); byte[] seed = username.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); // Integer seedMd5Int = Math.abs(new String(Hex.encodeHex(seedMd5)) @@ -316,6 +317,18 @@ public abstract class DrawerActivity extends ToolbarActivity { usernameFull.setText(accountName); int lastAtPos = accountName.lastIndexOf("@"); username.setText(accountName.substring(0, lastAtPos)); + + ImageView usericon = (ImageView) ((NavigationView) findViewById(R.id.nav_view)) + .getHeaderView(0).findViewById(R.id.drawer_usericon); + try { + int[] rgb = calculateRGB(accountName); + TextDrawable icon = new TextDrawable( + accountName.substring(0, 1).toUpperCase(), rgb[0], rgb[1], rgb[2]); + usericon.setImageDrawable(icon); + } catch (Exception e) { + Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e); + usericon.setImageResource(R.drawable.ic_account_circle); + } } }