mirror of https://github.com/M66B/FairEmail.git
parent
a685da21a9
commit
97bc466942
@ -1,3 +1,6 @@
|
|||||||
[submodule "colorpicker"]
|
[submodule "colorpicker"]
|
||||||
path = colorpicker
|
path = colorpicker
|
||||||
url = https://github.com/M66B/colorpicker.git
|
url = https://github.com/M66B/colorpicker.git
|
||||||
|
[submodule "qcolorpicker"]
|
||||||
|
path = qcolorpicker
|
||||||
|
url = https://github.com/QuadFlask/colorpicker.git
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of FairEmail.
|
||||||
|
|
||||||
|
FairEmail is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FairEmail is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.GradientDrawable;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.AppCompatButton;
|
||||||
|
import androidx.core.graphics.ColorUtils;
|
||||||
|
|
||||||
|
public class ButtonColor extends AppCompatButton {
|
||||||
|
private int color = Color.TRANSPARENT;
|
||||||
|
|
||||||
|
public ButtonColor(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonColor(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonColor(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Parcelable onSaveInstanceState() {
|
||||||
|
Parcelable superState = super.onSaveInstanceState();
|
||||||
|
return new SavedState(superState, this.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRestoreInstanceState(Parcelable state) {
|
||||||
|
SavedState savedState = (SavedState) state;
|
||||||
|
super.onRestoreInstanceState(savedState.getSuperState());
|
||||||
|
setColor(savedState.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
void setColor(Integer color) {
|
||||||
|
if (color == null)
|
||||||
|
color = Color.TRANSPARENT;
|
||||||
|
this.color = color;
|
||||||
|
|
||||||
|
GradientDrawable background = new GradientDrawable();
|
||||||
|
background.setColor(color);
|
||||||
|
background.setStroke(
|
||||||
|
Helper.dp2pixels(getContext(), 1),
|
||||||
|
Helper.resolveColor(getContext(), R.attr.colorSeparator));
|
||||||
|
setBackground(background);
|
||||||
|
|
||||||
|
double lum = ColorUtils.calculateLuminance(color);
|
||||||
|
setTextColor(lum < 0.5 ? Color.WHITE : Color.BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getColor() {
|
||||||
|
return this.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class SavedState extends View.BaseSavedState {
|
||||||
|
private int color;
|
||||||
|
|
||||||
|
private SavedState(Parcelable superState, int color) {
|
||||||
|
super(superState);
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SavedState(Parcel in) {
|
||||||
|
super(in);
|
||||||
|
color = in.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getColor() {
|
||||||
|
return this.color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel destination, int flags) {
|
||||||
|
super.writeToParcel(destination, flags);
|
||||||
|
destination.writeInt(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
||||||
|
public SavedState createFromParcel(Parcel in) {
|
||||||
|
return new SavedState(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SavedState[] newArray(int size) {
|
||||||
|
return new SavedState[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 3583e34ac3895b3c01e89bab6a7d32bca124a974
|
Loading…
Reference in new issue