Explorar el Código

Fix background color generation

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic hace 6 años
padre
commit
7ff6fcd366

+ 1 - 1
app/build.gradle

@@ -109,7 +109,7 @@ dependencies {
     implementation 'com.google.android.material:material:1.0.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
     implementation 'androidx.emoji:emoji-bundled:1.0.0'
-    implementation 'androidx.palette:palette:1.0.0'
+    implementation 'org.michaelevans.colorart:library:0.0.3'
     implementation "android.arch.work:work-runtime:${workVersion}"
     implementation "android.arch.work:work-firebase:${workVersion}"
     androidTestImplementation "android.arch.work:work-testing:${workVersion}"

+ 17 - 19
app/src/main/java/com/nextcloud/talk/controllers/CallNotificationController.java

@@ -25,6 +25,7 @@ import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ColorDrawable;
 import android.media.AudioAttributes;
 import android.media.MediaPlayer;
 import android.net.Uri;
@@ -79,6 +80,7 @@ import com.nextcloud.talk.utils.singletons.AvatarStatusCodeHolder;
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
+import org.michaelevans.colorart.library.ColorArt;
 import org.parceler.Parcels;
 
 import java.io.IOException;
@@ -89,7 +91,6 @@ import javax.inject.Inject;
 
 import androidx.annotation.NonNull;
 import androidx.constraintlayout.widget.ConstraintLayout;
-import androidx.palette.graphics.Palette;
 import autodagger.AutoInjector;
 import butterknife.BindView;
 import butterknife.OnClick;
@@ -436,6 +437,11 @@ public class CallNotificationController extends BaseController {
                                             (getActivity()).getBitmapPool(), resource, avatarSize, avatarSize));
                                 }
 
+                                if (getResources() != null) {
+                                    incomingTextRelativeLayout.setBackground(getResources().getDrawable(R.drawable
+                                            .incoming_gradient));
+                                }
+
                                 if (AvatarStatusCodeHolder.getInstance().getStatusCode() == 200 &&
                                         userBeingCalled.hasSpreedCapabilityWithName("no-ping")) {
                                     final Allocation input = Allocation.createFromBitmap(renderScript, resource);
@@ -447,25 +453,17 @@ public class CallNotificationController extends BaseController {
                                     script.forEach(output);
                                     output.copyTo(resource);
 
-                                    if (getResources() != null) {
-                                        incomingTextRelativeLayout.setBackground(getResources().getDrawable(R.drawable
-                                                .incoming_gradient));
-                                        backgroundImageView.setImageDrawable(new BitmapDrawable(resource));
-                                    }
+                                    backgroundImageView.setImageDrawable(new BitmapDrawable(resource));
                                 } else if (AvatarStatusCodeHolder.getInstance().getStatusCode() == 201) {
-                                    Palette palette = Palette.from(resource).generate();
-                                    if (getResources() != null) {
-                                        int color = palette.getDominantColor(getResources().getColor(R.color.grey950));
-
-                                        if (color != getResources().getColor(R.color.grey950)) {
-                                            float[] hsv = new float[3];
-                                            Color.colorToHSV(color, hsv);
-                                            hsv[2] *= 0.75f;
-                                            color = Color.HSVToColor(hsv);
-                                        }
-
-                                        backgroundImageView.setBackgroundColor(color);
-                                    }
+                                    ColorArt colorArt = new ColorArt(resource);
+                                    int color = colorArt.getBackgroundColor();
+
+                                    float[] hsv = new float[3];
+                                    Color.colorToHSV(color, hsv);
+                                    hsv[2] *= 0.75f;
+                                    color = Color.HSVToColor(hsv);
+
+                                    backgroundImageView.setImageDrawable(new ColorDrawable(color));
                                 }
                             }
                         });