Skip to content

Commit

Permalink
Merge branch 'per-contact-colors'
Browse files Browse the repository at this point in the history
  • Loading branch information
moezbhatti committed Jan 5, 2016
2 parents ce2d3aa + 7b04f76 commit 572b744
Show file tree
Hide file tree
Showing 86 changed files with 1,122 additions and 2,571 deletions.
8 changes: 0 additions & 8 deletions QKSMS/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,6 @@
android:theme="@style/AppThemeLightDialog"
android:windowSoftInputMode="adjustResize" />

<!-- Message picker activity -->
<activity
android:name=".ui.popup.MessagePickerActivity"
android:excludeFromRecents="true"
android:noHistory="true"
android:taskAffinity=""
android:theme="@style/AppThemeLightDialog" />

<activity android:name=".ui.mms.SlideshowActivity" />

<receiver
Expand Down
3 changes: 2 additions & 1 deletion QKSMS/src/main/java/com/moez/QKSMS/QKSMSAppBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.moez.QKSMS.data.Contact;
import com.moez.QKSMS.data.Conversation;
import com.moez.QKSMS.transaction.NotificationManager;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.mms.layout.LayoutManager;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;
Expand Down Expand Up @@ -88,6 +89,7 @@ public void onCreate() {
mPduLoaderManager = new PduLoaderManager(context);
mThumbnailManager = new ThumbnailManager(context);

ThemeManager.init(this);
MmsConfig.init(this);
Contact.init(this);
DraftCache.init(this);
Expand All @@ -97,7 +99,6 @@ public void onCreate() {
LayoutManager.init(this);
NotificationManager.init(this);
LiveViewManager.init(this);
//MessagingNotification.init(this);

activePendingMessages();
}
Expand Down
147 changes: 147 additions & 0 deletions QKSMS/src/main/java/com/moez/QKSMS/common/CIELCHEvaluator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.moez.QKSMS.common;

import android.animation.TypeEvaluator;

/**
* Evaluator used for animating between colors in the CIE-LCh color space
* <p>
* For reading see www.stuartdenman.com/improved-color-blending
*/
public class CIELChEvaluator implements TypeEvaluator<Integer> {

/**
* Converting RGB to CIE-LCh is expensive, so since we're only going to be using
* an instance of this evaluator to evaluate between two colors, we'll calculate
* the CIE-LCh values during construction rather than during frames in the
* animation
*/
private final ColorCIELCh mStartColor;
private final ColorCIELCh mEndColor;

public CIELChEvaluator(int startColor, int endColor) {
mStartColor = convertRgbToCIELCH(startColor);
mEndColor = convertRgbToCIELCH(endColor);
}

public Integer evaluate(float fraction) {
return evaluate(fraction, 0, 0);
}

@Override
public Integer evaluate(float fraction, Integer ignored, Integer ignored2) {

// CIELCH to CIELAB
double L = mStartColor.L * (1 - fraction) + mEndColor.L * fraction;
double C = mStartColor.C * (1 - fraction) + mEndColor.C * fraction;
double H = mStartColor.H * (1 - fraction) + mEndColor.H * fraction;

double a = Math.cos(Math.toRadians(H)) * C;
double b = Math.sin(Math.toRadians(H)) * C;

// CIELAB to XYZ
double var_Y = (L + 16) / 116.0;
double var_X = a / 500 + var_Y;
double var_Z = var_Y - b / 200.0;

var_Y = Math.pow(var_Y, 3) > 0.008856 ? Math.pow(var_Y, 3) : (var_Y - 16 / 116.0) / 7.787;
var_X = Math.pow(var_X, 3) > 0.008856 ? Math.pow(var_X, 3) : (var_X - 16 / 116.0) / 7.787;
var_Z = Math.pow(var_Z, 3) > 0.008856 ? Math.pow(var_Z, 3) : (var_Z - 16 / 116.0) / 7.787;

double X = 95.047 * var_X;
double Y = 100.000 * var_Y;
double Z = 108.883 * var_Z;


// XYZ TO RGB
double var_X2 = X / 100.0;
double var_Y2 = Y / 100.0;
double var_Z2 = Z / 100.0;

double var_R = var_X2 * 3.2406 + var_Y2 * -1.5372 + var_Z2 * -0.4986;
double var_G = var_X2 * -0.9689 + var_Y2 * 1.8758 + var_Z2 * 0.0415;
double var_B = var_X2 * 0.0557 + var_Y2 * -0.2040 + var_Z2 * 1.0570;

var_R = var_R > 0.0031308 ? 1.055 * Math.pow(var_R, (1 / 2.4)) - 0.055 : 12.92 * var_R;
var_G = var_G > 0.0031308 ? 1.055 * Math.pow(var_G, (1 / 2.4)) - 0.055 : 12.92 * var_G;
var_B = var_B > 0.0031308 ? 1.055 * Math.pow(var_B, (1 / 2.4)) - 0.055 : 12.92 * var_B;

double R = (var_R * 255);
double G = (var_G * 255);
double B = (var_B * 255);

int red = (int) Math.round(R);
int green = (int) Math.round(G);
int blue = (int) Math.round(B);

red = Math.min(255, Math.max(0, red));
green = Math.min(255, Math.max(0, green));
blue = Math.min(255, Math.max(0, blue));

return (0xff << 24) | (red << 16) | (green << 8) | (blue << 0);
}

private ColorCIELCh convertRgbToCIELCH(int rgb) {

// RGB TO XYZ
int r = 0xff & (rgb >> 16);
int g = 0xff & (rgb >> 8);
int b = 0xff & (rgb >> 0);

double var_R = r / 255.0;
double var_G = g / 255.0;
double var_B = b / 255.0;

var_R = var_R > 0.04045 ? Math.pow((var_R + 0.055) / 1.055, 2.4) : var_R / 12.92;
var_G = var_G > 0.04045 ? Math.pow((var_G + 0.055) / 1.055, 2.4) : var_G / 12.92;
var_B = var_B > 0.04045 ? Math.pow((var_B + 0.055) / 1.055, 2.4) : var_B / 12.92;

var_R = var_R * 100;
var_G = var_G * 100;
var_B = var_B * 100;

double X = var_R * 0.4124 + var_G * 0.3576 + var_B * 0.1805;
double Y = var_R * 0.2126 + var_G * 0.7152 + var_B * 0.0722;
double Z = var_R * 0.0193 + var_G * 0.1192 + var_B * 0.9505;


// XYZ TO CIELAB
double var_X = X / 95.047;
double var_Y = Y / 100.000;
double var_Z = Z / 108.883;

var_X = var_X > 0.008856 ? Math.pow(var_X, (1 / 3.0)) : (7.787 * var_X) + (16 / 116.0);
var_Y = var_Y > 0.008856 ? Math.pow(var_Y, 1 / 3.0) : (7.787 * var_Y) + (16 / 116.0);
var_Z = var_Z > 0.008856 ? Math.pow(var_Z, 1 / 3.0) : (7.787 * var_Z) + (16 / 116.0);

double CIELAB_L = (116 * var_Y) - 16;
double CIELAB_A = 500 * (var_X - var_Y);
double CIELAB_B = 200 * (var_Y - var_Z);


// CIELAB TO CIELCH
double var_H = Math.atan2(CIELAB_B, CIELAB_A);
var_H = var_H > 0 ? (var_H / Math.PI) * 180.0 : 360 - Math.toDegrees(Math.abs(var_H));

double C = Math.hypot(CIELAB_A, CIELAB_B);
double H = var_H;


return new ColorCIELCh(CIELAB_L, C, H);
}

private static class ColorCIELCh {

public final double L, C, H;

public ColorCIELCh(double l, double C, double H) {
L = l;
this.C = C;
this.H = H;
}

@Override
public String toString() {
return "{L:" + L + ", C:" + C + ", H:" + H + "}";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.net.Uri;
import android.preference.PreferenceManager;
import com.moez.QKSMS.R;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment;

public class ConversationPrefsHelper {
Expand All @@ -21,6 +22,10 @@ public ConversationPrefsHelper(Context context, long threadId) {
mConversationPrefs = context.getSharedPreferences(CONVERSATIONS_FILE + threadId, Context.MODE_PRIVATE);
}

public int getColor() {
return Integer.parseInt(mConversationPrefs.getString(SettingsFragment.THEME, "" + ThemeManager.getThemeColor()));
}

public boolean getNotificationsEnabled() {
return getBoolean(SettingsFragment.NOTIFICATIONS, true);
}
Expand Down Expand Up @@ -65,6 +70,15 @@ public boolean getDimissedReadEnabled() {
return getBoolean(SettingsFragment.DISMISSED_READ, false);
}

public void putInt(String key, int value) {
mConversationPrefs.edit().putInt(key, value).apply();
}

public int getInt(String key, int defaultValue) {
int globalValue = mPrefs.getInt(key, defaultValue);
return mConversationPrefs.getInt(key, globalValue);
}

public void putString(String key, String value) {
mConversationPrefs.edit().putString(key, value).apply();
}
Expand Down
2 changes: 1 addition & 1 deletion QKSMS/src/main/java/com/moez/QKSMS/common/FontManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static ColorStateList getTextColor(Context context, int type) {
// Colors and font weight
switch (type) {
case FontManager.TEXT_TYPE_PRIMARY:
boolean isNight = ThemeManager.getTheme() == ThemeManager.Theme.GREY ||
boolean isNight = ThemeManager.getTheme() == ThemeManager.Theme.DARK ||
ThemeManager.getTheme() == ThemeManager.Theme.BLACK;
int id = isNight ? R.color.text_primary_dark : R.color.text_primary_light;
return context.getResources().getColorStateList(id);
Expand Down
Loading

0 comments on commit 572b744

Please sign in to comment.