Giter Club home page Giter Club logo

android-support-preference-v7-fix's Introduction

AndroidX Preference eXtended

This library is meant to fix some of the problems found in the official AndroidX preference library. Also, there are new preference types available, such as RingtonePreference, DatePickerPreference, and TimePickerPreference.

Maven Central

Donation

If you would like to support me, you may donate some small amount via PayPal.

Buy me a coffee


How to use the library?

1. Add gradle dependency

Add this to your gradle file:

implementation "androidx.preference:preference:$androidxVersion"
implementation 'com.takisoft.preferencex:preferencex:1.1.0'

2. Use the appropriate class as your fragment's base

import com.takisoft.preferencex.PreferenceFragmentCompat;

public class MyPreferenceFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.settings, rootKey);
	
	// additional setup
    }
}

Warning! Watch out for the correct package name when importing PreferenceFragmentCompat, it should come from com.takisoft.preferencex.

Now you can enjoy using preferenceX.


Extra types

There are additional preferences not part of the official support library, but decided to add them to some extra libraries. You can add them to your project using Gradle.

Preference Dependency Preview
RingtonePreference implementation 'com.takisoft.preferencex:preferencex-ringtone:1.1.0' API 26
DatePickerPreference implementation 'com.takisoft.preferencex:preferencex-datetimepicker:1.1.0' API 26
TimePickerPreference implementation 'com.takisoft.preferencex:preferencex-datetimepicker:1.1.0' API 26
ColorPickerPreference implementation 'com.takisoft.preferencex:preferencex-colorpicker:1.1.0' API 26
SimpleMenuPreference implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.1.0' (can be used independent of preferencex) API 26

Custom solutions

Hijacked EditTextPreference

The support implementation of EditTextPreference ignores many of the basic yet very important attributes as it doesn't forward them to the underlying EditText widget. In my opinion this is a result of some twisted thinking which would require someone to create custom dialog layouts for some simple tasks, like showing a numbers-only dialog. This is the main reason why the EditTextPreference gets hijacked by this lib: it replaces certain aspects of the original class in order to forward all the XML attributes set (such as inputType) on the EditTextPreference to the EditText, and also provides a getEditText() method so it can be manipulated directly.

The sample app shows an example of setting (via XML) and querying (programmatically) the input type of the EditTextPreference:

<EditTextPreference
    android:inputType="phone"
    android:key="edit_text_test" />
EditTextPreference etPref = (EditTextPreference) findPreference("edit_text_test");
if (etPref != null) {
    int inputType = etPref.getEditText().getInputType();
    // do something with inputType
}

Note! Watch out for the correct package name when importing EditTextPreference, it should come from com.takisoft.preferencex. If you import from the wrong package (i.e. androidx.preference), the getEditText() method will not be available, however, the XML attributes will still be forwarded and processed by the EditText.

Others

  • Convenience methods in PreferenceFragmentCompat;
  • PreferenceCategory with different colors;
  • AutoSummaryEditTextPreference;
  • PreferenceActivityResultListener;
  • EditTextPreference correctly calls notifyChange. (#66)

Version

The current stable version is 1.1.0.

Notes

This demo / bugfix is set to work on API level 14+.


Sample

Material design - everywhere.

API 15 API 21 API 26
API 15 API 21 API 26

Changelog

See the separate CHANGELOG.md file.

2019-11-26

New version: 1.1.0 (based on v1.1.0)

  • introduced PreferenceFragmentCompatMasterSwitch that can be used as a switch's additional screen for settings; see the sample for details
  • Added pref_disableMessagePaddingFix attribute to the EditTextPreference that can be used to disable the dialog message padding fix.
  • EditText does not receive all attributes from EditTextPreference from now, only the following: inputType, textAllCaps, lines, minLines, maxLines, ems, minEms, maxEms
  • AutoSummaryEditTextPreference is now deprecated, use an appropriate SummaryProvider with the EditTextPreference

For older changelogs, check out the CHANGELOG file.

Feel free to ask / suggest anything on this page by creating a ticket (issues)!

License notes

Apache v2

android-support-preference-v7-fix's People

Contributors

connyduck avatar gregkorossy avatar masmas-studio avatar mgaetan89 avatar mygod avatar pavel-zolotov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-support-preference-v7-fix's Issues

problems when rendering layout

In your sample project, when trying to rendering the layout it crashes, so I neither cannot use it in other projects.

crash

Add @Nullable annotations to parameters

I am using your lib fine in Java, then I switched to use Kotlin. I was then getting an exception in the OnCreate method because the savedInstanceState Bundle was not marked as @nullable, but it was coming in as null from the OS.

I added overrides via the IDE (Android Studio 2.2) but it would likely be better if your source included the annotations directly.

An interesting item is that I see the android PreferenceFragmentCompat does not include the @nullable, but its superclass - Fragment - does include it. So I think it is a bug in the Android SDK too.

How to style dialog from DialogPreference

I apologize if this is not directly related to Preference-V7-Fix - though perhaps it is something it could assist with in the future.

I have been trying to style the popup dialogs from ListPreference, but nothing is working. I have tried overriding dialogPreferenceStyle, alertDialogStyle, etc. but it is always ignored. (I changed my main preferences to use a dark background and white text, which then causes many of the text and controls in the dialogs to be white and white and thus invisible).

Is there an global dialog style in the Fix lib that might help be accomplish this?

Crashes in SwitchPreferencesCompat

Got some crashes from SwitchPreferencesCompat:

java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
at android.support.v7.widget.RecyclerView.assertNotInLayoutOrScroll(RecyclerView.java)
at android.support.v7.widget.RecyclerView$RecyclerViewDataObserver.onItemRangeChanged(RecyclerView.java)
at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyItemRangeChanged(RecyclerView.java)
at android.support.v7.widget.RecyclerView$Adapter.notifyItemChanged(RecyclerView.java)
at android.support.v7.preference.PreferenceGroupAdapter.onPreferenceChange(PreferenceGroupAdapter.java)
at android.support.v7.preference.Preference.notifyChanged(Preference.java)
at android.support.v7.preference.TwoStatePreference.setChecked(TwoStatePreference.java)
at com.takisoft.fix.support.v7.preference.SwitchPreferenceCompat.setChecked(SwitchPreferenceCompat.java)
at android.support.v7.preference.SwitchPreferenceCompat$Listener.onCheckedChanged(SwitchPreferenceCompat.java)
at android.widget.CompoundButton.setChecked(CompoundButton.java:165)
at android.support.v7.widget.SwitchCompat.setChecked(SwitchCompat.java)
at com.takisoft.fix.support.v7.preference.SwitchPreferenceCompat.onBindViewHolder(SwitchPreferenceCompat.java)

This came from developer console and I can't reproduce it from my test devices. Could it be the animation when switching state?

Style of dialog message in EditTextPreference

Hello. Style of dialog message is very different from Material, since there is no padding and too small fonts:

screenshot_20160824-201222
Is it possible to change style?

For example, a simple AlertDialog:
screenshot_20160831-191919

EditTextPreference and design support library

EditTextPreference is displayed incorrectly after adding support library com.android.support:design:23.3.0 into project.
There is only top title header part with no edit entry and bottom buttons.

edittextpreferencefix_title

this screenshot is taken from Android 6.0
Older versions have next error during start process
android.content.res.Resources$NotFoundException: File res/drawable/abc_list_selector_holo_light.xml from color state list resource ID #0x7f020032

Show no divider above first preference

I built in this library so I can use a collapsing toolbar with a PreferenceFragment in the content area. So far I got everything working, unless one small thing: I can't remove the divider above the first preference. The result is, that the grey divider is directly beneath the yellow toolbar, which just doesn't look good...

screenshot_20160523-164559

Just in case it's important, there are only Preferences on my PreferenceScreen.

Upgrade to support library v24.2.0

First thing that occurred to me: API 7 support is dropped, API 9 is the new minSdk version for v24.2.0, even though the package name suggests 7 (hence the v7). It has been reported but I wouldn't really hope in anything.
The library's minSdk version is still going to be set to 7 by overriding this behavior, but I cannot guarantee that it's really compatible with API 7 and 8 as it would require me to go through the API calls this lib ever could make, which is essentially impossible.

The splitter fix doesn't work with animation

When an item's height changed (for example when I removed the summary of a preference), the splitter bumps instantly to the final location while the rest of the content moves there. The inconsistency looks uncomfortable.

Can we provide a more flexible way, for user to turn on and turn off dividers, for category section and non-category section?

In recent commit, I saw custom divider drawing feature is being removed

a32b444

However, I would like to have a feature, where I can have divider on category section, and no divider on non-category section. As a result, I adopt your old code from https://github.com/Gericop/Android-Support-Preference-V7-Fix/blob/9f3595d054f070b1b0b41255c019414f308d02d2/app/src/main/java/android/support/v7/preference/PreferenceFragmentCompatFix.java

I modify the custom divider drawing code, to make sure it only draw on category section - https://gist.github.com/yccheok/9da06876cbde1cb0849182647e030743

It looks something like http://i.imgur.com/pq3piNC.png

Although I able to achieve my own custom divider drawing on category section only, and turn off divider for non-category section. I believe other users might be interested too.

It might good to have such feature in official release of PreferenceFragmentCompatFix.java

Thank you for providing an amazing fix to this problem.

No dividers between preferences?

With suppor lib preferencefragment, we don't see any dividers in between preferences, I thought it should have been fixed in your workaround, its not.

is it normal?

Cannot seem to change the divider Drawable (Just want to change color)

I have a fragment extending PreferenceFragmentCompatDividers

in the onCreatePreferencesFix method

I am using this

setDivider(ResourcesCompat.getDrawable(getResources(), R.drawable.pref_divider, null));
but the divider does not change.

I have also tried setting the divider preferences and height with no luck.

I have even tried getting the drawable with the old getResources.getdrawable method. I know that wouldn't matter just wanted to put it out there.

How can i change the color of the divider?

Is it possible that we can change preference_fallback_accent_color value during run-time

Hi,

Currently, we allow user to switch between the app theme during run-time

public static void updateTheme(Context context) {
    if (Utils.isDarkThemeEnabled()) {
        context.setTheme(R.style.Theme_App_Dark);
    } else {
        context.setTheme(R.style.Theme_App_Light);
    }
}

In your colors_indigo_pink.xml,

<color name="accent">#FF4081</color>
<!-- this is needed as preference_category_material layout is using this color as the text color -->
<color name="preference_fallback_accent_color">@color/accent</color>

It only support 1 color. Is there any way we can change preference_fallback_accent_color during run-time? I wish I can have something like

<color name="accent">?attr/my_accent</color>

But Android doesn't support such.

Some question on build.gradle

Hi Gergely Kล‘rรถssy,

Sorry for that! Since I don't find any better channel to contact you to ask about non-project thingy, I decide to open this issues in order able to ping you.

Recently, I wish to fork some Android library projects from GitHub, perform some modification, publish to maven (or jcenter) for my own usage purpose.

So that I can use them by having the following in my build.gradle

compile 'com.yccheok:my-forked-library-v7:24'

After reading https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en

I expect I shall saw some similar info in your build.gradle

apply plugin: 'com.android.library'
ext {
    bintrayRepo = 'maven'
    bintrayName = 'fb-like'

    publishedGroupId = 'com.inthecheesefactory.thecheeselibrary'
    libraryName = 'FBLike'

However, I found none. They just seem like a normal build.gradle for non-library project.

May I know what is the secret behind, of publishing your Android-Support-Preference-V7-Fix library?

Thank you very much!
Cheok

Cannot set accent color

Hey there,

i want to change the accent color to a different color as the default accent color in the rest of my activity.
Adding <color name="accent">#ff4081</color> <color name="preference_accent">@color/accent</color> to my colors.xml doesn't fix it :(

Is there a other way to overwrite the accentcolor only for the preference fragment?

Use of Semantic Versioning

Hi,

I can't find any official documentation from support libraries which indicates that they are using Semantic Versioning. However judging from past versions, I think they are.

So, from that base, it looks weird that you append a dot and then your version number to their original version. Would you please have a look at Semantic Versioning and try another scheme? For example, I think this one is good: 24.1.1-fix.1, 24.1.1-fix.2, 24.1.1-fix.3...

My own library uses the pre-release section as the whole mirror of major-minor-patch. For example:

  • 24.1.1-1.0.0: first release.
  • 24.1.1-1.0.1: patches.
  • 24.1.1-1.1.0: added some features.
  • ...

But that would become complicated. So it's up to you to choose. But it would be nice if you agree to adapting Semantic Versioning.

Thank you,

[Android Studio] Crash IDE due to duplicate annotation

Stack trace:

Duplicate annotation 'android.support.annotation.IntDef'; for signature: 'com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers divPrefFlags' in the file /home/yaroslav/AndroidStudioProjects/LibreTorrent/app/build/intermediates/exploded-aar/com.takisoft.fix/preference-v7/24.2.0.0/annotations.zip!/com/takisoft/fix/support/v7/preference/annotations.xml
java.lang.Throwable
    at com.intellij.diagnostic.LogMessageEx.error(LogMessageEx.java:136)
    at com.intellij.codeInsight.ExternalAnnotationsManagerImpl.duplicateError(ExternalAnnotationsManagerImpl.java:709)
    at com.intellij.codeInsight.BaseExternalAnnotationsManager$DataParsingSaxHandler.endElement(BaseExternalAnnotationsManager.java:468)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
    at com.intellij.codeInsight.BaseExternalAnnotationsManager.getDataFromFile(BaseExternalAnnotationsManager.java:178)
    at com.intellij.codeInsight.BaseExternalAnnotationsManager.doCollect(BaseExternalAnnotationsManager.java:219)
    at com.intellij.codeInsight.BaseExternalAnnotationsManager.collectExternalAnnotations(BaseExternalAnnotationsManager.java:146)
    at com.intellij.codeInsight.BaseExternalAnnotationsManager.findExternalAnnotations(BaseExternalAnnotationsManager.java:123)
    at org.jetbrains.android.inspections.lint.LombokPsiParser.getAnnotations(LombokPsiParser.java:430)
    at org.jetbrains.android.inspections.lint.LombokPsiParser.access$900(LombokPsiParser.java:57)
    at org.jetbrains.android.inspections.lint.LombokPsiParser$ResolvedPsiMethod.getAnnotations(LombokPsiParser.java:559)
    at com.android.tools.lint.checks.CallSuperDetector.getRequiredSuperMethod(CallSuperDetector.java:164)
    at com.android.tools.lint.checks.CallSuperDetector.checkCallSuper(CallSuperDetector.java:117)
    at com.android.tools.lint.checks.CallSuperDetector.access$000(CallSuperDetector.java:53)
    at com.android.tools.lint.checks.CallSuperDetector$1.visitMethodDeclaration(CallSuperDetector.java:105)
    at com.android.tools.lint.client.api.JavaVisitor$DispatchVisitor.visitMethodDeclaration(JavaVisitor.java:1066)
    at lombok.ast.MethodDeclaration.accept(MethodDeclaration.java:226)
    at lombok.ast.NormalTypeBody.accept(NormalTypeBody.java:57)
    at lombok.ast.ClassDeclaration.accept(ClassDeclaration.java:239)
    at lombok.ast.CompilationUnit.accept(CompilationUnit.java:83)
    at com.android.tools.lint.client.api.JavaVisitor.visitFile(JavaVisitor.java:274)
    at com.android.tools.lint.client.api.LintDriver.checkIndividualJavaFiles(LintDriver.java:1571)
    at com.android.tools.lint.client.api.LintDriver.runFileDetectors(LintDriver.java:1049)
    at com.android.tools.lint.client.api.LintDriver.checkProject(LintDriver.java:908)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:436)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:377)
    at org.jetbrains.android.inspections.lint.AndroidLintExternalAnnotator.doAnnotate(AndroidLintExternalAnnotator.java:168)
    at org.jetbrains.android.inspections.lint.AndroidLintExternalAnnotator.doAnnotate(AndroidLintExternalAnnotator.java:67)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:218)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.access$500(ExternalToolPass.java:44)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.run(ExternalToolPass.java:160)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
    at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.intellij.util.concurrency.QueueProcessor$RunnableConsumer.consume(QueueProcessor.java:298)
    at com.intellij.util.concurrency.QueueProcessor$RunnableConsumer.consume(QueueProcessor.java:295)
    at com.intellij.util.concurrency.QueueProcessor$2$1.run(QueueProcessor.java:110)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.concurrency.QueueProcessor$2.consume(QueueProcessor.java:107)
    at com.intellij.util.concurrency.QueueProcessor$2.consume(QueueProcessor.java:104)
    at com.intellij.util.concurrency.QueueProcessor$3$1.run(QueueProcessor.java:215)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.concurrency.QueueProcessor$3.run(QueueProcessor.java:212)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:366)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:55)

It's generated by Studio:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <item name="com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers divPrefFlags">
    <annotation name="android.support.annotation.IntDef">
      <val name="flag" val="true" />
      <val name="value" val="{com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_BETWEEN, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_BEFORE_FIRST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_AFTER_LAST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_BETWEEN, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_BEFORE_FIRST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_AFTER_LAST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PADDING_CHILD, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PADDING_PARENT}" />
    </annotation>
    <annotation name="android.support.annotation.IntDef">
      <val name="value" val="{com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_DEFAULT, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_NONE}" />
    </annotation>
  </item>
  <item name="com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers void applyDividerPreference(android.support.v7.widget.RecyclerView, int) 1">
    <annotation name="android.support.annotation.IntDef">
      <val name="flag" val="true" />
      <val name="value" val="{com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_BETWEEN, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_BEFORE_FIRST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_AFTER_LAST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_BETWEEN, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_BEFORE_FIRST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_AFTER_LAST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PADDING_CHILD, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PADDING_PARENT}" />
    </annotation>
    <annotation name="android.support.annotation.IntDef">
      <val name="value" val="{com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_DEFAULT, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_NONE}" />
    </annotation>
  </item>
  <item name="com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers void setDividerPreferences(int) 0">
    <annotation name="android.support.annotation.IntDef">
      <val name="flag" val="true" />
      <val name="value" val="{com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_BETWEEN, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_BEFORE_FIRST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_CATEGORY_AFTER_LAST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_BETWEEN, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_BEFORE_FIRST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PREFERENCE_AFTER_LAST, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PADDING_CHILD, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_PADDING_PARENT}" />
    </annotation>
    <annotation name="android.support.annotation.IntDef">
      <val name="value" val="{com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_DEFAULT, com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers.DIVIDER_NONE}" />
    </annotation>
  </item>
</root>

Accent color not used on API < 21

I use Version 24.1.1.0 and everything was tested on emulators.

Consider the following screenhots:

API 24

How it should be: API 24

API 16

Not colored correctly: API 16

The preference layout is as follows:

<ListPreference
    android:defaultValue="60"
    android:dependency="pref_news_notifications"
    android:entryValues="@array/news_notifications_interval_values"
    android:key="pref_news_notifications_interval"
    android:summary="%s"
    android:title="@string/preference_news_notifications_interval_title" />

I don't know if this is really a bug, but I thought you may want to take a look at it.

Thanks in advance!

EditTextPreference does not store in the correct type

<EditTextPreference
    android:defaultValue="200"
    android:inputType="number"
    android:key="limit"
    android:summary="title"
    android:title="content" />

When I use

final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return preferences.getInt("limit", 200);

It throws java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer.

Crash on 24.1.0.0

I'm seeing a crash on a user. It's a Note 3 with Android 4.4.2. It seems it's because of the reflection not finding the fields? I can't reproduce this on my Nexus 5.

Here's the stacktrace:

Fatal Exception: java.lang.NullPointerException
       at com.takisoft.fix.support.v7.preference.PreferenceGroupAdapter.getReflectedIds(Unknown Source)
       at com.takisoft.fix.support.v7.preference.PreferenceGroupAdapter.getReflectedIds(Unknown Source)
       at com.takisoft.fix.support.v7.preference.PreferenceGroupAdapter.onCreateViewHolder(Unknown Source)
       at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(Unknown Source)
       at android.support.v7.widget.RecyclerView$Recycler.clear(Unknown Source)
       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(Unknown Source)
       at android.support.v7.widget.LinearLayoutManager$LayoutState.hasMore(Unknown Source)
       at android.support.v7.widget.LinearLayoutManager.generateDefaultLayoutParams(Unknown Source)
       at android.support.v7.widget.LinearLayoutManager.generateDefaultLayoutParams(Unknown Source)
       at android.support.v7.widget.LinearLayoutManager.findViewByPosition(Unknown Source)
       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(Unknown Source)
       at android.support.v7.widget.RecyclerView.dispatchLayout(Unknown Source)
       at android.support.v7.widget.RecyclerView.onLayout(Unknown Source)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
       at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
       at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15648)
       at android.view.ViewGroup.layout(ViewGroup.java:4856)
       at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2245)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1967)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1199)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6383)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
       at android.view.Choreographer.doCallbacks(Choreographer.java:603)
       at android.view.Choreographer.doFrame(Choreographer.java:573)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:157)
       at android.app.ActivityThread.main(ActivityThread.java:5293)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
       at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
       at dalvik.system.NativeStart.main(NativeStart.java)

Reflection solution on support library v24.0.0 does work well with inner preference page

Hi @Gericop ,

I tried to add the following information on the already closed ticket - #25

However, I'm not sure whether you will get notified. Since I found no way to contact you, I try to create a new ticket. I hope that is fine for you.

I realize the reflection solution doesn't work fine for inner preference page.

0

1

Here's the XML for the preference screen - https://gist.github.com/yccheok/4172d782249757b1153cee9edd4c566b

Thanks.

p/s I like the work u had done on this project. In order to show my appreciate, I would like to donate to this project. May I know, does your project accept paypal donation? Thanks.

PreferenceCategory bottom margin too big

First of all, great library! I don't think this is a bug directly for your library, but maybe can add it as a fix? See the comparison below using the regular PreferenceFragment, PreferenceFragmentCompat (using v14 theme), and your PreferenceFragmentCompat respectively.

comparison

I've tried setting my own android:listSeparatorTextViewStyle and Preference_TextAppearanceMaterialBody2 with 0 bottom margin/padding and it doesn't seem to fix it.

Any idea what's causing this issue? Thanks for all the work you put in.

Smaller margin on API 19 compared to API 22 and 23

As they say, a picture is worth a thousand words...

emulators_margin

On API 22 (probably 21 too) and 23 the margin seems alright, but on 19 not so food. There's not much breathing space on the left side. Any thoughts on how to fix this locally or would I have to wait for a possible fix on this library?

Although this does not look good to me, could this be the expected behavior?

Upgrade to support library v24.0.0

Working on the problem, but it seems like it's a bit more work than replacing some numbers in the gradle build files. Looks like Google messed up something with the preferences' paddings on API levels below 21...

Bad padding on API 17:

device-2016-06-16-174349


Good padding on API 21:

device-2016-06-16-174555

Different background color on API 22 compared to API 19 and 23

As they say, a picture is worth a thousand words...

emulators_margin

On API 19 and 23 the background color looks good, the white I specified as <item name="android:windowBackground">@android:color/white</item> on my application theme. But it looks odd on API 22 (probably 21 too). Any thoughts on how to fix this locally or would I have to wait for a possible fix on this library?

Although this does not look good to me, could this be the expected behavior?

Divider settings are not applied when returning from backstack

The problem can be demonstrated using the sample app. Just uncomment the setDividerPreferences() call in MyPreferenceFragment.onCreateView() and set the dividers to DIVIDER_NONE.

When the app is started, dividers are correctly hidden. Then press "PreferenceSrceen test" and return from the subscreen. The dividers are not hidden anymore.

I test this on a Nexus 7/2013, Android 6.0.1

Apparently, when the fragment is restored, the check "divPrefFlags == flags && !divPrefInvalid" in setDividerPreferences() is true and thus, the divider preferences are not applied.

Change typeface

Is there any way to change the typeface and set a custom font type?

Crash in ListPreference during rotation

Hello. If you rotate device 2 times with the open dialog then occurs crash:

java.lang.IllegalStateException: Failure saving state: ListPreferenceDialogFragmentCompat{9d3f3e08 #1 android.support.v7.preference.PreferenceFragment.DIALOG} has target not in fragment manager: SettingsFragment{9d3f3c08}
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1935)
at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:134)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:568)
at android.support.v7.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:511)
at android.app.Activity.performSaveInstanceState(Activity.java:1153)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1223)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3712)
at android.app.ActivityThread.access$900(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Invisible Background Bug

@Gericop @MGaetan89
Even after importing the library via gradle and setting <item name="android:activatedBackgroundIndicator">?android:attr/selectableItemBackground</item> in my main styles xml file i'm still seeing a transparent background when my preference fragment launches.

More background:

I'm setting the following theme on my preference fragment:

<style name="MyMaterialTheme" parent="Theme.AppCompat">
		...
        <item name="preferenceTheme">@style/PreferenceFixTheme</item>
        <item name="android:activatedBackgroundIndicator">?android:attr/selectableItemBackground</item>
    </style>

and i'm using the following code for my PreferenceFragmentCompat fix class extension:

public class FragmentSettingsMenu extends com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Load the preferences from the XML resource
        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
        getView().setBackgroundColor(ContextCompat.getColor(getContext(), R.color.preference_fallback_accent_color));
    }
}

but despite all these fixes, my preference fragment still has a transparent background.

Is this a bug in the library or am I not applying this fix correctly?

Migrating to gradle based solution

Currently, I have an app which I need to support Android 4 and above.

Previously, I'm using solution from https://github.com/Gericop/Android-Support-Preference-V7-Fix/tree/c42097b2e733aeb2ca69a5c43e9437f6f21ac541

It looks like

screenshot_20160721-222720

In previously solution, I'm using multiple styles.xml which looks like

values/styles.xml

<!-- https://github.com/Gericop/Android-Support-Preference-V7-Fix -->
<!-- http://stackoverflow.com/questions/32070670/preferencefragmentcompat-requires-preferencetheme-to-be-set -->
<style name="Theme.JStock.Light" parent="@style/Theme.JStock.Base.Light">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
    <!-- Overriding the category views as they don't look good -->
    <item name="android:listSeparatorTextViewStyle">@style/MyListSeparatorTextView</item>
</style>

<style name="Theme.JStock.Dark" parent="@style/Theme.JStock.Base.Dark">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
    <!-- Overriding the category views as they don't look good -->
    <item name="android:listSeparatorTextViewStyle">@style/MyListSeparatorTextView</item>
</style>

<!-- Overriding preference theme to eliminate left-right padding -->
<!-- Actually it would require one to provide the custom layout files with the padding INSIDE
the preference layouts, not on the preference list itself, thus, I'll not do this now

<style name="PreferenceThemeOverlayFix" parent="@style/PreferenceThemeOverlay">
    <item name="preferenceFragmentListStyle">@style/PreferenceFragmentListFix</item>
</style>

<style name="PreferenceFragmentListFix">
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
</style>-->

<!-- The default category looks bad, so overriding its appearance now -->
<style name="MyListSeparatorTextView">
    <item name="android:textSize">14sp</item>
    <item name="android:textStyle">bold</item>
    <item name="android:paddingTop">16dp</item>
    <item name="android:layout_marginBottom">16dp</item>
</style>

values-v14/styles.xml

<!-- https://github.com/Gericop/Android-Support-Preference-V7-Fix -->
<!-- http://stackoverflow.com/questions/32070670/preferencefragmentcompat-requires-preferencetheme-to-be-set -->
<style name="Theme.JStock.Light" parent="@style/Theme.JStock.Base.Light">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

<style name="Theme.JStock.Dark" parent="@style/Theme.JStock.Base.Dark">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

<!-- This is needed because the default PreferenceCategory appearance doesn't use bold text style -->
<style name="Preference_TextAppearanceMaterialBody2">
    <item name="android:textSize">14sp</item>
    <item name="android:fontFamily">sans-serif-medium</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">?android:attr/textColorPrimary</item>
</style>

<!-- END OF HACKING -->
# values-v17/styles.xml
<!-- https://github.com/Gericop/Android-Support-Preference-V7-Fix -->
<!-- http://stackoverflow.com/questions/32070670/preferencefragmentcompat-requires-preferencetheme-to-be-set -->
<style name="Theme.JStock.Light" parent="@style/Theme.JStock.Base.Light">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
    <!-- Padding fix -->
    <item name="android:listPreferredItemPaddingStart">16dp</item>
    <item name="android:listPreferredItemPaddingEnd">16dp</item>
</style>

<style name="Theme.JStock.Dark" parent="@style/Theme.JStock.Base.Dark">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
    <!-- Padding fix -->
    <item name="android:listPreferredItemPaddingStart">16dp</item>
    <item name="android:listPreferredItemPaddingEnd">16dp</item>
</style>

<!-- This is needed because the default PreferenceCategory appearance doesn't use bold text style -->
<style name="Preference_TextAppearanceMaterialBody2">
    <item name="android:textSize">14sp</item>
    <item name="android:fontFamily">sans-serif-medium</item>
    <item name="android:textStyle">bold</item>
    <item name="android:textColor">?android:attr/textColorPrimary</item>
</style>

<!-- END OF HACKING -->
# values-v21/styles.xml
<!-- https://github.com/Gericop/Android-Support-Preference-V7-Fix -->
<!-- http://stackoverflow.com/questions/32070670/preferencefragmentcompat-requires-preferencetheme-to-be-set -->
<style name="Theme.JStock.Light" parent="@style/Theme.JStock.Base.Light">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

<style name="Theme.JStock.Dark" parent="@style/Theme.JStock.Base.Dark">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style>

After migrating to latest gradle based solution, I was wondering, whether those multiple styles.xml are still necessary? As, I remove all styles.xml except values/styles.xml

values/styles.xml

<style name="Theme.JStock.Light" parent="@style/Theme.JStock.Base.Light">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

<style name="Theme.JStock.Dark" parent="@style/Theme.JStock.Base.Dark">
    <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>

But, it looks like this.

screenshot_20160721-230224

Does that means, I should leave all my multiple styles.xml unchanged?

EditTextPreference should use AppCompatEditText

Hello,

Many thanks for this project: it has helped me out when trying to upgrade my own project to app compat 23.0.1.

I found another issue related to the EditTextPreference: it creates an EditText. It should create an AppCompatEditText instead, or else the theming will not be correct on versions < Lollipop.

For info, my own collection of hacks to work around app compat v7 prefs issues is currently in one package in this project: https://github.com/caarmen/network-monitor/tree/app-compat-preferences/networkmonitor/src/main/java/ca/rmen/android/networkmonitor/app/prefs/hack

I haven't taken the time out to make an isolated reusable project like you have though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.