Comments (11)
Are there any Updates to this issue? Prefrence- and PreferenceFragments-support would be really nice.
from androidannotations.
No. Go ahead if you want to write some spec :)
from androidannotations.
I need this feature, so i want to implement this ASAP.
This is what i thought:
@PreferenceScreen
calls addPreferencesFromResource
in init body
@Preference
ovverides addPreferencesFromResource
, and inject the prefs there
@AfterPreferences
ovverides addPreferencesFromResource
, and calls the method
The preference change listener would do the same as the @Preference
annotation.
@yDelouis, @DayS, @dodgex WDYT?
from androidannotations.
uhm, i think you hav a copy/paste bug in your comment. our shoud @Preference
and @AfterPReferences
override addPreferencesFromResource
? :D
@PreferenceScreen(R.xml.pref)
callsaddPreferencesFromResource(R.xml.pref)
in init body@AfterPreferences("prefName")
implementOnSharedPreferenceChangeListener
and overrideonSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
to call the annotated method ifkey == "prefName"
(also callun-
/registerOnSharedPreferenceChangeListener(this)
in Resume/Pause or whereever)
not sure what you mean with @Preference
.
this should support PreferenceActivity
, PreferenceFragment
and thier corresporending support-v4 versions if they exist.
from androidannotations.
@Preference
(or better@PreferenceByKey
) is an annotation to inject aPreference
object. So yes, it should overrideaddPreferencesFromResource
, so we inject the pref object after the screen has been added.@AfterPreferences
provides a callback for the user to setup the injectedPreference
objects, like@AfterViews
@PreferenceChange
should be the annotation for adding a listener, and notOnSharedPreferenceChangeListener
, butPreference.OnPreferenceChangeListener
listener.
from androidannotations.
okay. sure. got it. sorry ;)
about @PreferenceChange
i can't say much. in my projecst PreferenceFragment
i use the SharedPreferences version of the ChangeListener. so maybe listener for both cases could be usefull? eg a shared = true
flag?
from androidannotations.
I vote for Preference.OnPreferenceChangeListener
because it has several benefits:
- it is not related to the global
SharedPreferences
, so we do not have to remove the listener when theActivity
/Fragment
is destroyed, we do not have memory leaks. - It gives the user more control, because it gets called before the value is persisted, the programmer even can change the value.
- It works with non-persistent
Preference
s,OnSharedPreferenceChangeListener
only gets called if the preference store itself is modified.
from androidannotations.
hm. okay. i'm not very familiar with the preferences stuff.
so i could replace the code that currently uses the shared preferences in my PreferenceFragment
with the new code that would get generated by AA and stuff still would work? :)
btw this is what i'm doing in my change listener:
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("tracklist_load_releaseimage")) {
ListPreference connectionPref = (ListPreference) findPreference(key);
if (connectionPref != null) {
connectionPref.setSummary(connectionPref.getEntry());
}
} else if (key.equals("alarmclock_timeout")) {
ListPreference alarmTimeoutPref = (ListPreference) findPreference(key);
if (alarmTimeoutPref != null) {
alarmTimeoutPref.setSummary(getString(R.string.pref_alarmclock_timeout_summary, alarmTimeoutPref.getEntry()));
}
} else if (key.equals("analytics_optout")) {
// pref is from @SharedPref(value = Scope.APPLICATION_DEFAULT)
GoogleAnalytics.getInstance(getActivity()).setAppOptOut(pref.analytics_optout().get());
}
}
from androidannotations.
Yes, but only if you do not modify the SharedPreferences
programmatically, becuse in that case Preference.OnPreferenceChangeListener
is not called, only OnSharedPreferenceChangeListener
.
from androidannotations.
in my PreferencesFragment i do not modify the preferences at all in my code, i only need the change listener to update the summaries or enable/disable google analytics.
anyway: you got my ok for your suggestion. ๐ (not that it would count ^^)
from androidannotations.
Forgot to close this. ๐
from androidannotations.
Related Issues (20)
- Android Gradle Plugin 4.0 HOT 6
- Compile warning after upgrade to AA 4.7.0 HOT 1
- Kotlin kapt keeps failing after updating from `4.6.0` to `4.7.0` on Windows machines! HOT 1
- Project unbuildable with classes at the root src/main/java level HOT 6
- Example code showcases 4.7.0 annotation processor is not incremental HOT 2
- AA doesn't work with Kotlin1.4 HOT 8
- Error: Trying to create the same field twice: fragmentSupport_ HOT 1
- AA / Kotlin 1.4 / Gradle plugin warning HOT 2
- AA KaptException with kotlin 1.4 HOT 4
- Faulty import statement generated HOT 2
- Error: Cannot find symbol HOT 3
- How to integrate Hilt? HOT 1
- Why is String not a โpreference simple typeโ and what should I use instead? HOT 1
- Error while trying to inject system service ROLE_SERVICE HOT 2
- androidx.viewbinding.ViewBinding vs ViewDataBinding HOT 2
- Failed resolution of: Lorg/androidannotations/rest/spring/api/RestClientHeaders; HOT 1
- Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them as annotation attributes HOT 3
- After update Android Studio from 4.1.3 to version 4.2.1 SharedPrefs_ always null HOT 3
- Support Android Gradle Plugin 7.0+ HOT 10
- Is this plugin is still active in 2022? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidannotations.