|
@@ -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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|