mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
circle icons for accounts with color coding
This commit is contained in:
parent
d9d3424968
commit
7e2c560004
3 changed files with 31 additions and 15 deletions
|
@ -32,17 +32,19 @@
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/drawer_usericon"
|
android:id="@+id/drawer_usericon"
|
||||||
android:layout_width="24dp"
|
android:layout_width="32dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="32dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:src="@drawable/ic_account_circle"
|
android:src="@drawable/ic_account_circle"
|
||||||
|
android:padding="0dp"
|
||||||
|
android:layout_margin="0dp"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_vertical"
|
android:layout_gravity="top"
|
||||||
android:paddingLeft="@dimen/standard_half_padding"
|
android:paddingLeft="@dimen/standard_half_padding"
|
||||||
android:paddingRight="@dimen/standard_half_padding"
|
android:paddingRight="@dimen/standard_half_padding"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.graphics.Color;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.RectF;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,21 +23,23 @@ public class TextDrawable extends Drawable {
|
||||||
|
|
||||||
bg = new Paint();
|
bg = new Paint();
|
||||||
bg.setStyle(Paint.Style.FILL);
|
bg.setStyle(Paint.Style.FILL);
|
||||||
|
bg.setAntiAlias(true);
|
||||||
bg.setColor(color);
|
bg.setColor(color);
|
||||||
|
|
||||||
paint = new Paint();
|
paint = new Paint();
|
||||||
paint.setColor(Color.WHITE);
|
paint.setColor(Color.WHITE);
|
||||||
paint.setTextSize(20);
|
paint.setTextSize(60);
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setFakeBoldText(true);
|
paint.setFakeBoldText(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
//RectF rf = new RectF(0,24,24,0);
|
//float[] radii = {radius, radius, radius, radius, radius, radius, radius, radius};
|
||||||
//canvas.drawRoundRect(rf,24,24,bg);
|
//new RoundRectShape(radii, null, null);
|
||||||
canvas.drawRect(0,-20,20,40,bg);
|
canvas.drawCircle(40, 40, 40, bg);
|
||||||
canvas.drawText(text, 4, 6, paint);
|
//canvas.drawRect(0, -20, 20, 40, bg);
|
||||||
|
canvas.drawText(text, 20, 60, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
|
@ -250,9 +251,9 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
||||||
// add all accounts to list
|
// add all accounts to list
|
||||||
for (int i = 0; i < accounts.length; i++) {
|
for (int i = 0; i < accounts.length; i++) {
|
||||||
try {
|
try {
|
||||||
int[] rgb = calculateRGB(accounts[i]);
|
int[] rgb = calculateRGB(accounts[i].name);
|
||||||
TextDrawable icon = new TextDrawable(accounts[i].name.substring(0, 1).toUpperCase(),
|
TextDrawable icon = new TextDrawable(accounts[i].name.substring(0, 1).toUpperCase()
|
||||||
rgb[0], rgb[1], rgb[2]);
|
, rgb[0], rgb[1], rgb[2]);
|
||||||
mNavigationView.getMenu().add(R.id.drawer_menu_accounts, Menu.NONE, 0, accounts[i].name).setIcon(icon);
|
mNavigationView.getMenu().add(R.id.drawer_menu_accounts, Menu.NONE, 0, accounts[i].name).setIcon(icon);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log_OC.e(TAG, "Error calculating RGB value for account menu item.", 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
|
// using adapted algorithm from /core/js/placeholder.js:50
|
||||||
int lastAtPos = account.name.lastIndexOf("@");
|
int lastAtPos = accountName.lastIndexOf("@");
|
||||||
String username = account.name.substring(0, lastAtPos);
|
String username = accountName.substring(0, lastAtPos);
|
||||||
byte[] seed = username.getBytes("UTF-8");
|
byte[] seed = username.getBytes("UTF-8");
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
// Integer seedMd5Int = Math.abs(new String(Hex.encodeHex(seedMd5))
|
// Integer seedMd5Int = Math.abs(new String(Hex.encodeHex(seedMd5))
|
||||||
|
@ -316,6 +317,18 @@ public abstract class DrawerActivity extends ToolbarActivity {
|
||||||
usernameFull.setText(accountName);
|
usernameFull.setText(accountName);
|
||||||
int lastAtPos = accountName.lastIndexOf("@");
|
int lastAtPos = accountName.lastIndexOf("@");
|
||||||
username.setText(accountName.substring(0, lastAtPos));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue