FairEmail/app/src/main/java/eu/faircode/email/FragmentDialogColor.java

110 lines
4.0 KiB
Java
Raw Normal View History

2019-06-30 14:55:15 +00:00
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/>.
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
2019-06-30 14:55:15 +00:00
*/
2022-02-11 09:44:59 +00:00
import static android.app.Activity.RESULT_OK;
2019-09-29 14:31:13 +00:00
import android.app.Dialog;
2020-10-02 11:11:59 +00:00
import android.content.Context;
2019-09-29 14:31:13 +00:00
import android.content.DialogInterface;
import android.graphics.Color;
2019-06-30 14:55:15 +00:00
import android.os.Bundle;
2019-09-29 14:31:13 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2022-11-30 10:02:38 +00:00
import androidx.appcompat.app.AlertDialog;
2019-06-30 14:55:15 +00:00
2019-09-29 14:31:13 +00:00
import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.OnColorChangedListener;
2019-09-29 14:31:13 +00:00
import com.flask.colorpicker.builder.ColorPickerClickListener;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
2019-06-30 14:55:15 +00:00
2019-09-29 14:31:13 +00:00
public class FragmentDialogColor extends FragmentDialogBase {
private int color;
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putInt("fair:color", color);
super.onSaveInstanceState(outState);
}
2019-09-29 14:31:13 +00:00
@NonNull
2019-06-30 14:55:15 +00:00
@Override
2019-09-29 14:31:13 +00:00
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
2019-09-29 17:04:21 +00:00
Bundle args = getArguments();
color = (savedInstanceState == null
? args.getInt("color")
: savedInstanceState.getInt("fair:color"));
2019-09-29 17:04:21 +00:00
String title = args.getString("title");
boolean reset = args.getBoolean("reset", false);
2022-11-30 10:02:38 +00:00
int faq = args.getInt("faq");
2019-09-29 14:31:13 +00:00
2020-10-02 11:11:59 +00:00
Context context = getContext();
int editTextColor = Helper.resolveColor(context, android.R.attr.editTextColor);
2019-09-29 17:04:21 +00:00
ColorPickerDialogBuilder builder = ColorPickerDialogBuilder
2020-10-02 11:11:59 +00:00
.with(context)
2019-09-29 14:31:13 +00:00
.setTitle(title)
2019-10-08 19:46:23 +00:00
.showColorEdit(true)
2020-10-02 11:11:59 +00:00
.setColorEditTextColor(editTextColor)
2019-09-29 14:31:13 +00:00
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(6)
2019-09-29 14:31:13 +00:00
.lightnessSliderOnly()
.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int selectedColor) {
color = selectedColor;
}
})
2019-09-29 14:31:13 +00:00
.setPositiveButton(android.R.string.ok, new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
getArguments().putInt("color", selectedColor);
sendResult(RESULT_OK);
}
2019-09-29 17:04:21 +00:00
});
2019-10-10 15:09:40 +00:00
if (color != Color.TRANSPARENT)
builder.initialColor(color);
2019-09-29 17:04:21 +00:00
if (reset)
builder.setNegativeButton(R.string.title_reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getArguments().putInt("color", Color.TRANSPARENT);
sendResult(RESULT_OK);
}
});
2022-11-30 10:02:38 +00:00
AlertDialog dialog = builder.build();
if (faq > 0)
dialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.title_info),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.viewFAQ(context, faq);
}
});
return dialog;
2019-06-30 14:55:15 +00:00
}
}