mirror of https://github.com/M66B/FairEmail.git
parent
d2b0cba6a6
commit
0f7f0e1ad3
@ -1,35 +0,0 @@
|
||||
package eu.faircode.email;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
import com.android.colorpicker.ColorPickerDialog;
|
||||
|
||||
public class ColorPickerDialogEx extends ColorPickerDialog implements LifecycleObserver {
|
||||
private LifecycleOwner owner;
|
||||
|
||||
private ColorPickerDialogEx() {
|
||||
}
|
||||
|
||||
ColorPickerDialogEx(LifecycleOwner owner) {
|
||||
super();
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(@NonNull FragmentManager manager, @Nullable String tag) {
|
||||
owner.getLifecycle().addObserver(this);
|
||||
super.show(manager, tag);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
public void onOwnerPause() {
|
||||
dismiss();
|
||||
this.owner = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
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.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.colorpicker.ColorPickerDialog;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
public class FragmentColor extends ColorPickerDialog {
|
||||
private Bundle args;
|
||||
|
||||
public void initialize(int title, int color, Bundle args, Context context) {
|
||||
this.args = args;
|
||||
int[] colors = context.getResources().getIntArray(R.array.colorPicker);
|
||||
super.initialize(title, colors, color, 4, colors.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null)
|
||||
this.args = savedInstanceState.getBundle("fair:extra");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putBundle("fair:extra", args);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorSelected(int color) {
|
||||
Fragment target = getTargetFragment();
|
||||
if (target != null) {
|
||||
args.putInt("color", color);
|
||||
|
||||
Intent data = new Intent();
|
||||
data.putExtra("args", args);
|
||||
target.onActivityResult(getTargetRequestCode(), RESULT_OK, data);
|
||||
}
|
||||
|
||||
dismiss();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue