martin-stone / hsv-alpha-color-picker-android

A color picker and a color preference for use in Android applications.
Apache License 2.0
290 stars 60 forks source link

ColorPreference: read from disk on UI thead #44

Closed Doctoror closed 6 years ago

Doctoror commented 6 years ago

Hello

Please see this StrictMode report

D/StrictMode: StrictMode policy violation; ~duration=116 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=65599 violation=2
    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1440)
    at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:251)
    at java.io.File.exists(File.java:807)
    at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:572)
    at android.app.ContextImpl.ensurePrivateDirExists(ContextImpl.java:563)
    at android.app.ContextImpl.getPreferencesDir(ContextImpl.java:519)
    at android.app.ContextImpl.getSharedPreferencesPath(ContextImpl.java:714)
    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:368)
    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:167)
    at android.preference.PreferenceManager.getSharedPreferences(PreferenceManager.java:510)
    at android.preference.Preference.getSharedPreferences(Preference.java:1204)
    at com.rarepebble.colorpicker.ColorPreference.getPersistedIntDefaultOrNull(ColorPreference.java:120)
    at com.rarepebble.colorpicker.ColorPreference.onBindView(ColorPreference.java:71)

Thanks

Edit: after some investigation, I see that this is how Preferences are generally designed to work. But as an improvement, you may omit using getSharedPreferences() in case isPersistent() is false.

In my case I do not store this color under the default storage provided by the Preference, so I would like to have the ability to disable this behavior with isPersistent flag.

martin-stone commented 6 years ago

Yeah, looks like this isn't a major issue, but it should be possible to make it respect the isPersistent flag.

martin-stone commented 6 years ago

Now respecting isPersistent() in 2.4.0.