takisoft / preferencex-android Goto Github PK
View Code? Open in Web Editor NEWAndroid's "androidx.preference" library has some issues, this lib tries to fix them.
License: Apache License 2.0
Android's "androidx.preference" library has some issues, this lib tries to fix them.
License: Apache License 2.0
I am able to display my com.takisoft.preferencex.PreferenceFragmentCompat
that includes a ringtone. But, when I select the preference to edit the ringtone pref, I get this exception and my program crashes.
2020-05-28 09:04:38.157 20065-20065/my.cool.app.MyApp E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.cool.app.MyApp, PID: 20065
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:228)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2170)
at android.content.res.Resources.getLayout(Resources.java:1170)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at android.view.LayoutInflater.inflate(LayoutInflater.java:383)
at androidx.appcompat.app.AlertController$AlertParams.createListView(AlertController.java:989)
at androidx.appcompat.app.AlertController$AlertParams.apply(AlertController.java:965)
at androidx.appcompat.app.AlertDialog$Builder.create(AlertDialog.java:984)
at androidx.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:158)
at com.takisoft.preferencex.RingtonePreferenceDialogFragmentCompat.onCreateDialog(RingtonePreferenceDialogFragmentCompat.java:171)
at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:419)
at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1484)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7179)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
libs:
androidx_app_compat: 'androidx.appcompat:appcompat:1.1.0',
androidx_app_core: 'androidx.core:core:1.2.0',
androidx_fragment: 'androidx.fragment:fragment:1.2.4',
androidx_cardview: 'androidx.cardview:cardview:1.0.0',
androidx_prefs: 'androidx.preference:preference:1.1.0',
tak_androidx_prefs: ['com.takisoft.preferencex:preferencex:1.1.0', 'com.takisoft.preferencex:preferencex-ringtone:1.1.0'],
Prefs file
<com.takisoft.preferencex.RingtonePreference
android:title="@string/pref_my_ring_title"
android:key="@string/pref_my_ring_key"
android:dialogTitle="my ringer"
android:persistent="false"
android:showDefault="true"
android:showSilent="true"
android:ringtoneType="notification"
app:pref_showAdd="true"
app:pref_summaryHasRingtone="The best ringtone: %s"
/>
Device OS: 9
In TimePickerPreference.java a static SimpleDateFormat FORMAT is defined which saves the local time zone at creation time (line 49) for the entire application process lifetime.
This format is used to parse a time String into a Date object (receives the time zone from FORMAT, line 240) and then the result is assigned to a newly instantiated Calendar object (that has the current local time zone, line 277).
When the System's time zone changes between storing a time String into SharedPreferences and recovering it from SharedPreferences while the application process is still running, then the hours (and probably minutes) are shifted to the new System time zone.
It only happens under very special circumstances, for example if you have an AppWidget and therefore a permanently running process - but that is exactly my use case of your fabulous Preference.
Suggestion to solve the issue: instead of using a static fixed FORMAT have a static method
public static getFORMAT() { return new SimpleDateFormat(PATTERN, Locale.US); }
Then you'll always have a format residing in the current time zone as the Calendar objects do.
12-02 10:42:17.819 20550 20550 E AndroidRuntime: java.lang.NumberFormatException: For input string: "notification_sound"
12-02 10:42:17.819 20550 20550 E AndroidRuntime: at java.lang.Long.parseLong(Long.java:594)
12-02 10:42:17.819 20550 20550 E AndroidRuntime: at java.lang.Long.parseLong(Long.java:636)
12-02 10:42:17.819 20550 20550 E AndroidRuntime: at android.content.ContentUris.parseId(ContentUris.java:89)
12-02 10:42:17.819 20550 20550 E AndroidRuntime: at android.media.RingtoneManager.getRingtonePosition(RingtoneManager.java:513)
12-02 10:42:17.819 20550 20550 E AndroidRuntime: at com.takisoft.preferencex.g.a(Unknown Source:146)
12-02 10:42:17.819 20550 20550 E AndroidRuntime: at com.takisoft.preferencex.g.a(Unknown Source:11)
The error seems to come from here:
It seems Android 10 calls ContentUris.parseId
inside getRingtonePosition
which throws if the last segment of the Uri
isn't a number.
I upgraded to AndroidStudio 4.2 yesterday with the result that the build process for my app complained about not being able to locate com.takisoft.preferencex:preferencex.
After a bit of research it looks to me that your library is only available in jcenter which is now end of live, hence things should be moved to MavenCentral.
Here's where I took this from: https://stackoverflow.com/questions/66400264/jcenter-is-at-end-of-life-android-lint-warning-what-is-the-replacement
show a SimpleMenuPopup, then recreate activity
E/WindowManager: android.view.WindowLeaked: Activity SettingsActivity has leaked window android.widget.PopupWindow$PopupDecorView{1b71233 V.E..V... R....... 0,0-588,546} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:620)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1577)
at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1343)
at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1309)
at com.takisoft.preferencex.widget.SimpleMenuPopupWindow.showPopupMenu(SimpleMenuPopupWindow.java:339)
at com.takisoft.preferencex.widget.SimpleMenuPopupWindow.show(SimpleMenuPopupWindow.java:200)
at com.takisoft.preferencex.SimpleMenuPreference.onClick(SimpleMenuPreference.java:90)
at androidx.preference.Preference.performClick(Preference.java:1182)
at androidx.preference.Preference.performClick(Preference.java:1166)
at androidx.preference.Preference$1.onClick(Preference.java:181)
at android.view.View.performClick(View.java:7259)
at android.view.View.performClickInternal(View.java:7236)
at android.view.View.access$3600(View.java:801)
at android.view.View$PerformClick.run(View.java:27892)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
It would be great to have support for the new preference:1.1.1.
https://developer.android.com/jetpack/androidx/releases/preference#1.1.1
Please I get this error when syncing my project with the dependency. The error is given below.
Gradle sync failed: Could not get unknown property 'androidxVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Update:
Fixed the issue by addding the specific version number of androidx.preference, that is, implementation "androidx.preference:preference:1.0.0". But still wondering wasn't the version number provided by $androidxVersion?
Currently, there has been no updates to this library since September 2018 and as of today (14 Mar 2019), there have been a couple of updates of the AndroidX preference that have broken this library.
In the main build.gradle
, the version that is supported is 1.0.0
of the AndroidX preference library:
preferencex-android/build.gradle
Line 10 in f03e8f1
Recent versions of the AndroidX preference library have broken this library such as the revamping of the SeekBarPreference
(in 1.1.0-alpha04
) which removed a couple of styles that this library still uses.
I was told on an issue that I posted to Google's Issue Tracker that I should post a bug report here regarding the issue I had.
Will there be an update on this library? This is a great library to use if not for the lack of updates.
On the native Android Preference -- android.preference.Preference
-- the preference rows use a divider that has some padding added to the left and right, so that the lines do not go all the way to the edge of the screen.
Also, the native Android Preference has a larger default left and right padding for every list row.
But both the takisoft Preference and the AndroidX library Preference -- androidx.preference.preference
do not have the same divider line style and default padding.
Native Android Preference -- android.preference.PreferenceFragment
AndroidX Library Preference -- androidx.preference.PreferenceFragmentCompat
and com.takisoft.preferencex.PreferenceFragmentCompat
There is a workaround for the general padding of the rows, taken from here:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
... ...
<item name="preferenceTheme">@style/customPreferenceThemeOverlay</item>
</style>
<style name="customPreferenceThemeOverlay" parent="@style/PreferenceThemeOverlay">
<item name="preferenceFragmentListStyle">@style/customPreferenceFragmentList</item>
</style>
<style name="customPreferenceFragmentList">
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingRight">5dp</item>
</style>
But I'm not sure if this is the right approach, because different screen sizes (for example phones and tablets, portrait and landscape) probably had different amounts of padding.
I cannot find a workaround for the divider lines.
So is there a way to make the AndroidX library and takisfot library adopt the same padding styles as the original native preference?
Another perhaps unrelated issue:
These two libraries cause problems with internal Locale/language switching in Android apps, on API 21 (Android 5.0) to 25 (Android 7.1).
implementation "androidx.preference:preference:1.1.0" // version 1.0.0 does not have this problem
implementation 'com.takisoft.preferencex:preferencex:1.1.0'
The problem is discussed here: https://stackoverflow.com/questions/55265834/change-locale-not-work-after-migrate-to-androidx
But is there a way you can fix it internally inside the library?
what is the correct value for this? if basing on the link provided, 0 is default color but even specifying that in xml doesnt work. it says
error: '0' is incompatible with attribute pref_currentColor (attr) reference [weak].
i only wish to set the default value checked icon on the default color specified.
The update 1.1.0 is final. It would be greatly appreciated to see this lib updated.
https://developer.android.com/jetpack/androidx/releases/preference#1.1.0
implementation 'com.takisoft.preferencex:preferencex-ringtone:1.1.0'
<com.takisoft.preferencex.RingtonePreference
android:title="Ringtone"
android:key="ringtone"
app:iconSpaceReserved="false" />
java.lang.IllegalArgumentException: Cannot display dialog for an unknown Preference type: RingtonePreference. Make sure to implement onPreferenceDisplayDialog() to handle displaying a custom dialog for this Preference.
How to use RingtonePreference?
Hello,
I am currently writing an Android application, and I would like to include license terms from all third-party components I use. For this library, I cannot know in whose name or year I should write the copyright notice. Could you please provide additional information?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.