From: tobiasKaminsky Date: Wed, 27 May 2015 16:35:21 +0000 (+0200) Subject: Merge branch 'navigationDrawer_update' of github.com:owncloud/android into navigation... X-Git-Tag: oc-android-1.7.2~1^2~23^2~38 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e80828afeda92b2997a25e0d5bb7de0b7501d4a4?ds=inline;hp=--cc Merge branch 'navigationDrawer_update' of github.com:owncloud/android into navigationDrawer_update --- e80828afeda92b2997a25e0d5bb7de0b7501d4a4 diff --cc src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java index a88ecbc7,b53f66f4..0a5b9562 --- a/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java @@@ -29,21 -43,21 +51,24 @@@ import com.owncloud.android.MainApp import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; + import com.owncloud.android.ui.NavigationDrawerItem; +import com.owncloud.android.ui.TextDrawable; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.utils.BitmapUtils; +import org.apache.commons.codec.binary.Hex; + public class NavigationDrawerListAdapter extends BaseAdapter { - private final static String TAG = "NavigationDrawerListAdapter"; + private final static String TAG = NavigationDrawerListAdapter.class.getSimpleName(); + private Context mContext; - private ArrayList mDrawerItems = new ArrayList(); - ArrayList all = new ArrayList(); + + private ArrayList mNavigationDrawerItems; + private ArrayList mAll = new ArrayList(); private Account[] mAccounts; private boolean mShowAccounts; - private Account currentAccount; + private Account mCurrentAccount; private FileDisplayActivity mFileDisplayActivity; @@@ -113,37 -127,26 +138,38 @@@ for (Account account : mAccounts) { RadioButton rb = new RadioButton(mContext); + rb.setText(account.name); + rb.setContentDescription(account.name); + rb.setTextColor(Color.BLACK); + rb.setEllipsize(TextUtils.TruncateAt.MIDDLE); + rb.setSingleLine(); + rb.setCompoundDrawablePadding(30); + try { - byte[] bytesOfMessage = account.name.substring(0,5).getBytes("UTF-8"); + // using adapted algorithm from /core/js/placeholder.js:50 + int lastAtPos = account.name.lastIndexOf("@"); + String username = account.name.substring(0, lastAtPos); + byte[] seed = username.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] digest = md.digest(bytesOfMessage); - int result = Math.abs(ByteBuffer.wrap(digest).getInt()); + byte[] seedMd5 = md.digest(seed); + Integer seedMd5Int = Math.abs(new String(Hex.encodeHex(seedMd5)).hashCode()); + + double maxRange = java.lang.Integer.MAX_VALUE; + float hue = (float) (seedMd5Int / maxRange * 360); + + int[] rgb = BitmapUtils.HSLtoRGB(hue, 90.0f, 65.0f, 1.0f); + +// Drawable drawable = MainApp.getAppContext().getResources().getDrawable(R.drawable.radiobutton_avatar); +// drawable.setColorFilter(Color.rgb(rgb[0], rgb[1], rgb[2]), PorterDuff.Mode.SRC_ATOP); - Log_OC.d(TAG, "Integer: " + result % 100000); - Log_OC.d(TAG, "length: " + digest.length); - Double hue = (result % 100000) / 99999.0; + TextDrawable text = new TextDrawable(username.substring(0, 1).toUpperCase(), rgb[0], rgb[1], rgb[2], rb.getTextSize()); - Log_OC.d(TAG, "hue: " + hue); + rb.setCompoundDrawablesWithIntrinsicBounds(text, null, null, null); - int[] rgb = BitmapUtils.hslToRgb(hue, 0.9, 0.65); - rb.setTextColor(Color.rgb(rgb[0], rgb[1], rgb[2])); - Log_OC.d(TAG, "Color: " + rgb[0] + " " + rgb[1] + rgb[2]); } catch (Exception e){ Log_OC.d(TAG, e.toString());