B4A Library AHPreferenceActivity Library

This Library is based on Erels PreferenceActivity Library and adds some hopefully useful things:

  • Checkbox entry can show On and Off summary
  • Dependencies to other entries
  • Another Listview type with Map as value/displayvalue pairs
  • AddPassword() for password entries
  • AddRingtone() for selecting notification, ringtone or alert sound

V1.01:
  • Bugfix for FC with nested PreferencesScreens
  • Added support for calling Intents (other activities)
  • Preferencescreens support dependency

V1.02:
  • Bugfix for GetUpdatedKeys not working sometimes (thanks, Erel)

V1.03:
  • Never published

V1.04:
  • Added AddEditText2() method with support for InputType and some other properties
  • !!! Changed package name to "de.amberhome.objects" !!! Change in your Manifest!

For a tutorial see PreferenceActivity Tutorial
 

Attachments

  • AHPreferenceActivityExample.zip
    6.6 KB · Views: 2,094
  • AHPreferenceActivity1_02.zip
    21.4 KB · Views: 2,004
  • AHPreferenceActivity1_04.zip
    22.1 KB · Views: 2,574
  • AHPreferenceActivityExample1_04.zip
    7.1 KB · Views: 2,011
Last edited:

corwin42

Expert
Licensed User
Longtime User
I already have both of those. The crash only happens in landscape mode. When my phone is in portrait mode, I have no problem opening the settings screen :/

This is strange. I can't reproduce it here. Did you test the example? Does this work?
 

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

Is there a way to immediately start another activity (current app. activity) in the settings screen? Just like the openbrowser intent.
 

Robcom69

Member
Licensed User
Longtime User
Hi Everybody,
is it possible to have a preference screen with:

- bar.ShowUpIndicator
- bar.subtitle

Hope someone can help me to achieve this.
Thanks a lot
 

corwin42

Expert
Licensed User
Longtime User
Hi,

Is there a way to immediately start another activity (current app. activity) in the settings screen? Just like the openbrowser intent.

You can start another activity with AddIntent().

Hi Everybody,
is it possible to have a preference screen with:

- bar.ShowUpIndicator
- bar.subtitle

Hope someone can help me to achieve this.
Thanks a lot

No, this is not possible.
 

pjetson

Member
Licensed User
Longtime User
I have some preferences that will not be user-configurable in the current version of my program, but I still want them to have default values that are saved with the rest of the configuration. In a future version of the program, these preferences will become user-configurable.

Is there any way that I can achieve this?
 

pjetson

Member
Licensed User
Longtime User
I've tried a couple of ideas that I was able to come up with. My ideal solution would be that the preferences are hidden completely from the user, but I could also live with the settings being visible but not changeable by the user.

The first idea was to use the name of a non-existent preference setting in the dependency field of the settings that I want to stop the user from changing. That didn't work.

The next idea was to create an extra category, and add a setting to that category, but then not add that category to the screen with Screen.AddPreferenceCategory, and put that setting name in the dependency field of the preferences I don't want the user to change. That didn't work either.

Any ideas?
 

Dadeda

Member
Licensed User
Longtime User
I have a big problem maybe you guys can help, i'm using this lib to set my app settings and it works great.
The problem is that it's a multi language app, and the language is set in the settings, the problem arises when i have a menuitem on my main activity created.
I know i can't delete the menuitem, but i'm trying to rebuild the main activity.
I've got a button that open's ahpreference and then i do a activity.finish to close main, and i would need to start the main again from the end of ahpreference so that main activity can be rebuilt.
I can't simply use startactivity(main) from the activity used by ahpreference because it simply doesn't work, i think i need to use a intent but i don't know how, can anyone give a hand ?
 

corwin42

Expert
Licensed User
Longtime User
I have some preferences that will not be user-configurable in the current version of my program, but I still want them to have default values that are saved with the rest of the configuration. In a future version of the program, these preferences will become user-configurable.

Is there any way that I can achieve this?

If I understand correctly you only want to save a setting and you don't want to show it to the user and the user should not be able to change the setting?

You can simply use the AHPreferenceManager directly and use SetString() or SetBoolean() to set your setting.
 

pjetson

Member
Licensed User
Longtime User
Thanks, corwin. I should have realised that, since the example program does just that to save the default values.
 

Antony Danby

Member
Licensed User
Longtime User
Hi

I am writing an application and I am using a StdActionBar and a StdViewPager and I want to have Preferences as one of the Panels. So :-

Sub Globals
Private bar As StdActionBar
Private vp As StdViewPager
End Sub

In another routine:

'Load the pages layouts
vp.Panels(0).LoadLayout("0")
vp.Panels(1).LoadLayout("1")

'I want to load it here =>
vp.Panels(2). ???

Would you have any ideas on what I need to do?
Thanks
 

corwin42

Expert
Licensed User
Longtime User
Hi

I am writing an application and I am using a StdActionBar and a StdViewPager and I want to have Preferences as one of the Panels. So :-

Since the PreferenceActivity is an activity this is not possible directly with this library.

A solution would be to create your own Layout for the Settings with the Designer and Load this Layout to a Page. Then you can use PrefsManager object to handle your Settings manually.
 

Antony Danby

Member
Licensed User
Longtime User
Yeah; that's what I thought. It's a shame though because the Preference screen's look so good and works well.
Designing mine as a layout will be a chore in comparison and I don't think I will get a result as good.
Is there no way of adding something to this preference library that will pull in the preference screen as a page ?
 

Antony Danby

Member
Licensed User
Longtime User
Or maybe the author of StdViewPager could add something to pull in an Activity, do you think any of these suggestions are possible ?
 

corwin42

Expert
Licensed User
Longtime User
Yeah; that's what I thought. It's a shame though because the Preference screen's look so good and works well.
Designing mine as a layout will be a chore in comparison and I don't think I will get a result as good.
Is there no way of adding something to this preference library that will pull in the preference screen as a page ?

Unfortunately not. All the UI components depend on the PreferenceActivity Class in this library.
 

peacemaker

Expert
Licensed User
Longtime User
Anyone tested this lib under Android 5.0 ?
It seems, .... problem.
The 5.0 emulator hungs during scrolling the pref activity with alert that "app has been stopped."

In Android 4.4 - no such problem.
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Anyone tested this lib under Android 5.0 ?
It seems, .... problem.
The 5.0 emulator hungs during scrolling the pref activity with alert that "app has been stopped."

In Android 4.4 - no such problem.

Can you reproduce this? I use it on a Nexus 7 with the latest preview of 5.0 and have no problems. But my Activity is not that big so I don't have to scroll. But it should work without problem.
 

peacemaker

Expert
Licensed User
Longtime User
corwin42, try 5.0 emulator, please
 

peacemaker

Expert
Licensed User
Longtime User
corwin42, try 5.0 emulator, please

B4X:
** Activity (about) Pause, UserClosed = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


java.util.UnknownFormatConversionException: Conversion: v


    at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1399)
    at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1336)
    at java.util.Formatter.transform(Formatter.java:1442)
    at java.util.Formatter.doFormat(Formatter.java:1081)
    at java.util.Formatter.format(Formatter.java:1042)
    at java.util.Formatter.format(Formatter.java:1011)
    at java.lang.String.format(String.java:1803)
    at java.lang.String.format(String.java:1777)
    at android.preference.ListPreference.getSummary(ListPreference.java:168)
    at android.preference.Preference.onBindView(Preference.java:550)
    at android.preference.Preference.getView(Preference.java:489)
    at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:246)
    at android.widget.AbsListView.obtainView(AbsListView.java:2344)
    at android.widget.ListView.makeAndAddView(ListView.java:1864)
    at android.widget.ListView.fillDown(ListView.java:698)
    at android.widget.ListView.fillGap(ListView.java:662)
    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4968)
    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4512)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    at android.view.Choreographer.doFrame(Choreographer.java:549)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
--------- beginning of crash


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Service (showbattery) Create **


** Service (showbattery) Start **

Here is log with the debugger:
B4X:
** Service (showbattery) Create **


** Service (showbattery) Start **


** Service (showbattery) Destroy **


** Activity (main) Pause, UserClosed = false **


java.util.UnknownFormatConversionException: Conversion: v


    at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1399)
    at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1336)
    at java.util.Formatter.transform(Formatter.java:1442)
    at java.util.Formatter.doFormat(Formatter.java:1081)
    at java.util.Formatter.format(Formatter.java:1042)
    at java.util.Formatter.format(Formatter.java:1011)
    at java.lang.String.format(String.java:1803)
    at java.lang.String.format(String.java:1777)
    at android.preference.ListPreference.getSummary(ListPreference.java:168)
    at android.preference.Preference.onBindView(Preference.java:550)
    at android.preference.Preference.getView(Preference.java:489)
    at android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:246)
    at android.widget.AbsListView.obtainView(AbsListView.java:2344)
    at android.widget.ListView.makeAndAddView(ListView.java:1864)
    at android.widget.ListView.fillDown(ListView.java:698)
    at android.widget.ListView.fillGap(ListView.java:662)
    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4968)
    at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3398)
    at android.widget.AbsListView.onTouchMove(AbsListView.java:3774)
    at android.widget.AbsListView.onTouchEvent(AbsListView.java:3612)
    at android.view.View.dispatchTouchEvent(View.java:8388)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2424)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2314)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1692)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2739)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2275)
    at android.view.View.dispatchPointerEvent(View.java:8578)
    at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4021)
    at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3887)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
    at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3578)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
    at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3635)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
    at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
    at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
    at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
    at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5701)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5675)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5646)


    at android.view.ViewRoo
Message longer than Log limit (4000). Message was truncated.


UPD. But in another app - no problem ! Seems, it's my pereference setting is wrong, but how to understand which ?
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Will try the emulator this evening.

I can't reproduce your problem on the N7. Even scrolling is working perfect.

Are you using B4A 3.82?
 

peacemaker

Expert
Licensed User
Longtime User
Sure, 3.82
Seems, problem with AddList

B4X:
    Dim li2 As List
    li2.Initialize
    Dim lis As String
    For i = 50 To 100
        lis = i
        li2.Add(lis)
    Next

    cat4.AddList("ValueAlarmLevel", Main.ResourceStrings.Get("WARN_settings_cat4_3"), Main.ResourceStrings.Get("WARN_settings_cat4_4"), "100", "ValueAlarm", li2)

this makes the hung.

If the list is initialized as
B4X:
li.Initialize2(Array As String("1", "2", "3", "4", "5", "6", "7", "8", "10", "15", "20", "25"))
it's no problem. But i need long list... :-( and under Android 5.0 also...
 
Last edited:
Top