Browse Source

fix not needed try/catch blocks

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 7 years ago
parent
commit
90529c5841

+ 3 - 7
src/main/java/com/owncloud/android/ui/TextDrawable.java

@@ -97,8 +97,7 @@ public class TextDrawable extends Drawable {
      */
     @NonNull
     @NextcloudServer(max = 12)
-    public static TextDrawable createAvatar(String accountName, float radiusInDp) throws
-            UnsupportedEncodingException, NoSuchAlgorithmException {
+    public static TextDrawable createAvatar(String accountName, float radiusInDp) {
         String username = AccountUtils.getAccountUsername(accountName);
         return createNamedAvatar(username, radiusInDp);
     }
@@ -115,8 +114,7 @@ public class TextDrawable extends Drawable {
      */
     @NonNull
     @NextcloudServer(max = 12)
-    public static TextDrawable createAvatarByUserId(String userId, float radiusInDp) throws
-            UnsupportedEncodingException, NoSuchAlgorithmException {
+    public static TextDrawable createAvatarByUserId(String userId, float radiusInDp) {
         return createNamedAvatar(userId, radiusInDp);
     }
 
@@ -127,8 +125,6 @@ public class TextDrawable extends Drawable {
      * @param name       the name
      * @param radiusInDp the circle's radius
      * @return the avatar as a TextDrawable
-     * @throws UnsupportedEncodingException if the charset is not supported when calculating the color values
-     * @throws NoSuchAlgorithmException     if the specified algorithm is not available when calculating the color values
      */
     @NonNull
     public static TextDrawable createNamedAvatar(String name, float radiusInDp) {
@@ -146,7 +142,7 @@ public class TextDrawable extends Drawable {
      * @param canvas The canvas to draw into
      */
     @Override
-    public void draw(Canvas canvas) {
+    public void draw(@NonNull Canvas canvas) {
         canvas.drawCircle(mRadius, mRadius, mRadius, mBackground);
         canvas.drawText(mText, mRadius, mRadius - ((mTextPaint.descent() + mTextPaint.ascent()) / 2), mTextPaint);
     }

+ 3 - 17
src/main/java/com/owncloud/android/ui/adapter/ShareUserListAdapter.java

@@ -34,8 +34,6 @@ import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.ui.TextDrawable;
 
-import java.io.UnsupportedEncodingException;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 
 /**
@@ -93,24 +91,12 @@ public class ShareUserListAdapter extends ArrayAdapter {
             String name = share.getSharedWithDisplayName();
             if (share.getShareType() == ShareType.GROUP) {
                 name = getContext().getString(R.string.share_group_clarification, name);
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_group);
-                }
+                icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
             } else if (share.getShareType() == ShareType.EMAIL) {
                 name = getContext().getString(R.string.share_email_clarification, name);
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_email);
-                }
+                icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
             } else {
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_user);
-                }
+                icon.setImageDrawable(TextDrawable.createNamedAvatar(name, mAvatarRadiusDimension));
             }
             userName.setText(name);
 

+ 2 - 12
src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java

@@ -45,8 +45,6 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 import com.owncloud.android.ui.TextDrawable;
 import com.owncloud.android.utils.DisplayUtils;
 
-import java.io.UnsupportedEncodingException;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 
 /**
@@ -111,18 +109,10 @@ public class UserListAdapter extends ArrayAdapter implements DisplayUtils.Avatar
             String name = share.getSharedWithDisplayName();
             if (share.getShareType() == ShareType.GROUP) {
                 name = getContext().getString(R.string.share_group_clarification, name);
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_group);
-                }
+                icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
             } else if (share.getShareType() == ShareType.EMAIL) {
                 name = getContext().getString(R.string.share_email_clarification, name);
-                try {
-                    icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
-                } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
-                    icon.setImageResource(R.drawable.ic_email);
-                }
+                icon.setImageDrawable(TextDrawable.createNamedAvatar(name, avatarRadiusDimension));
             } else {
                 icon.setTag(share.getShareWith());
                 DisplayUtils.setAvatar(account, share.getShareWith(), this, avatarRadiusDimension,