Fix text views, update queue time
This commit is contained in:
parent
887b6a4d36
commit
671728b315
22 changed files with 367 additions and 196 deletions
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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.
|
||||
*/
|
||||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
import code.name.monkey.appthemehelper.R;
|
||||
|
||||
public class ATEListPreference extends ListPreference {
|
||||
|
||||
public ATEListPreference(Context context) {
|
||||
super(context);
|
||||
init(context, null);
|
||||
}
|
||||
|
||||
public ATEListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
public ATEListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
setLayoutResource(R.layout.ate_preference_custom_support);
|
||||
if (getSummary() == null || getSummary().toString().trim().isEmpty())
|
||||
setSummary("%s");
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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.
|
||||
*/
|
||||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.ListPreference
|
||||
import code.name.monkey.appthemehelper.R
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
|
||||
|
||||
class ATEListPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0,
|
||||
defStyleRes: Int = 0
|
||||
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
init {
|
||||
icon?.setColorFilter(ThemeStore.textColorSecondary(context), PorterDuff.Mode.SRC_IN)
|
||||
layoutResource = R.layout.ate_preference_custom_support
|
||||
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
|
||||
summary = "%s"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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.
|
||||
*/
|
||||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7
|
||||
|
||||
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment
|
||||
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
|
||||
override fun onDisplayPreferenceDialog(preference: Preference) {
|
||||
if (callbackFragment is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
|
||||
(callbackFragment as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
||||
return
|
||||
}
|
||||
|
||||
if (activity is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
|
||||
(activity as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
||||
return
|
||||
}
|
||||
|
||||
if (fragmentManager!!.findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
|
||||
val dialogFragment = onCreatePreferenceDialog(preference)
|
||||
|
||||
if (dialogFragment != null) {
|
||||
dialogFragment.setTargetFragment(this, 0)
|
||||
dialogFragment.show(fragmentManager!!, "android.support.v7.preference.PreferenceFragment.DIALOG")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
super.onDisplayPreferenceDialog(preference)
|
||||
}
|
||||
|
||||
open fun onCreatePreferenceDialog(preference: Preference): DialogFragment? {
|
||||
if (preference is ATEListPreference) {
|
||||
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey())
|
||||
} else if (preference is ATEDialogPreference) {
|
||||
return ATEPreferenceDialogFragment.newInstance(preference.getKey())
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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.
|
||||
*/
|
||||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference;
|
||||
|
||||
/**
|
||||
* Created by hemanths on 2019-09-03.
|
||||
*/
|
||||
public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment {
|
||||
private int mClickedDialogEntryIndex;
|
||||
|
||||
@NonNull
|
||||
public static ATEListPreferenceDialogFragmentCompat newInstance(@NonNull String key) {
|
||||
final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putString(ARG_KEY, key);
|
||||
fragment.setArguments(b);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
private ATEListPreference getListPreference() {
|
||||
return (ATEListPreference) getPreference();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(@NonNull MaterialAlertDialogBuilder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
|
||||
final ListPreference preference = getListPreference();
|
||||
|
||||
if (preference.getEntries() == null || preference.getEntryValues() == null) {
|
||||
throw new IllegalStateException(
|
||||
"ListPreference requires an entries array and an entryValues array.");
|
||||
}
|
||||
|
||||
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue());
|
||||
builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialogInterface, i) -> {
|
||||
mClickedDialogEntryIndex = i;
|
||||
});
|
||||
|
||||
builder.setPositiveButton("Ok", null);
|
||||
builder.setNegativeButton("", null);
|
||||
builder.setNeutralButton("", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
final ListPreference preference = getListPreference();
|
||||
if (positiveResult && mClickedDialogEntryIndex >= 0 &&
|
||||
preference.getEntryValues() != null) {
|
||||
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
|
||||
if (preference.callChangeListener(value)) {
|
||||
preference.setValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* @Override
|
||||
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
||||
mClickedDialogEntryIndex = which;
|
||||
onClick(dialog, DialogAction.POSITIVE);
|
||||
dismiss();
|
||||
return true;
|
||||
}*/
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This 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.
|
||||
*
|
||||
* This software 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.
|
||||
*/
|
||||
|
||||
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.DialogPreference;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ATEPreferenceDialogFragment extends DialogFragment {
|
||||
protected static final String ARG_KEY = "key";
|
||||
|
||||
private DialogPreference mPreference;
|
||||
|
||||
public static ATEPreferenceDialogFragment newInstance(String key) {
|
||||
ATEPreferenceDialogFragment fragment = new ATEPreferenceDialogFragment();
|
||||
Bundle b = new Bundle(1);
|
||||
b.putString(ARG_KEY, key);
|
||||
fragment.setArguments(b);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Fragment rawFragment = this.getTargetFragment();
|
||||
if (!(rawFragment instanceof DialogPreference.TargetFragment)) {
|
||||
throw new IllegalStateException("Target fragment must implement TargetFragment interface");
|
||||
} else {
|
||||
DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment;
|
||||
String key = this.getArguments().getString(ARG_KEY);
|
||||
this.mPreference = (DialogPreference) fragment.findPreference(key);
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
MaterialAlertDialogBuilder materialDialog = new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setTitle(mPreference.getTitle())
|
||||
.setIcon(mPreference.getIcon())
|
||||
.setMessage(mPreference.getDialogMessage())
|
||||
.setPositiveButton(mPreference.getPositiveButtonText(), (dialogInterface, i) -> {
|
||||
onDialogClosed(true);
|
||||
})
|
||||
.setNegativeButton(mPreference.getNegativeButtonText(), (dialogInterface, i) -> {
|
||||
onDialogClosed(false);
|
||||
});
|
||||
|
||||
this.onPrepareDialogBuilder(materialDialog);
|
||||
AlertDialog dialog = materialDialog.create();
|
||||
if (this.needInputMethod()) {
|
||||
this.requestInputMethod(dialog);
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public DialogPreference getPreference() {
|
||||
return this.mPreference;
|
||||
}
|
||||
|
||||
protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
|
||||
}
|
||||
|
||||
protected boolean needInputMethod() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void requestInputMethod(Dialog dialog) {
|
||||
Window window = dialog.getWindow();
|
||||
window.setSoftInputMode(5);
|
||||
}
|
||||
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
|
@ -35,13 +34,13 @@
|
|||
|
||||
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
|
||||
android:id="@android:id/title"
|
||||
style="@style/TextViewSubtitle1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal"
|
||||
style="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:singleLine="true"
|
||||
tools:text="Title" />
|
||||
|
||||
|
@ -54,7 +53,7 @@
|
|||
android:layout_alignLeft="@android:id/title"
|
||||
android:layout_marginTop="2dp"
|
||||
android:maxLines="4"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
||||
android:textAppearance="@style/TextViewBody2"
|
||||
tools:text="Summary" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -54,8 +54,8 @@
|
|||
android:layout_alignLeft="@android:id/title"
|
||||
android:layout_marginTop="2dp"
|
||||
android:maxLines="4"
|
||||
android:textAppearance="@style/TextAppearance.MaterialComponents.Body2"
|
||||
tools:text="Summary" />
|
||||
android:textAppearance="@style/TextViewBody2"
|
||||
tools:text="I have one solution for you.you can change font size for specific preference by managing layout file." />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -24,18 +24,18 @@
|
|||
android:orientation="vertical"
|
||||
android:padding="0dip">
|
||||
|
||||
<TextView
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/custom_list_view_row_text_view"
|
||||
style="@style/TextAppearance.MaterialComponents.Subtitle1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="22dip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:textAppearance="@style/TextViewSubtitle1"
|
||||
android:textColor="#000000" />
|
||||
|
||||
<TextView
|
||||
<code.name.monkey.appthemehelper.common.views.ATESecondaryTextView
|
||||
android:id="@+id/custom_list_view_row_subtext_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="18dip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="#000000"
|
||||
android:textSize="12sp" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue