Merge branch 'navigationDrawer_update' of github.com:owncloud/android into navigation...
authortobiasKaminsky <tobias@kaminsky.me>
Wed, 27 May 2015 16:35:21 +0000 (18:35 +0200)
committertobiasKaminsky <tobias@kaminsky.me>
Wed, 27 May 2015 16:35:21 +0000 (18:35 +0200)
1  2 
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<String> mDrawerItems = new ArrayList<String>();
-     ArrayList<Object> all = new ArrayList<Object>();
+     private ArrayList<NavigationDrawerItem> mNavigationDrawerItems;
+     private ArrayList<Object> mAll = new ArrayList<Object>();
      private Account[] mAccounts;
      private boolean mShowAccounts;
-     private Account currentAccount;
+     private Account mCurrentAccount;
      private FileDisplayActivity mFileDisplayActivity;
  
  
  
                  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());