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
had another thought! i love the way this thing works. however, is there a way you could make it work also using a user specified file/directory to store other settings. for example, using the lib is great for storing general app settings. however, in my app i also have other Images/views that the user can modify various attributes on, eg. colors,fonts, etc. it would be nice to be able to use this library and its features to store these secondary attributes. specifically i have multiple "dashboards" with various gauges on it (analog, digital, etc.). each gauge can be customized using a common set (20 to 30) of attributes. it would be fantastic if i could attach a secondary "preference" activity for each dashboard using your library vs implementing some type of custom listview.

****edit 2****
or even an internal object of some sort that could be populated from another source and then used as the "map" for the preference activity, with all changes being stored back to the internal map object which could then be distributed back to the original source.

This is already possible. With the (AH)PreferenceManager and the setXXX methods you can set any key/value pair you want.
 

corwin42

Expert
Licensed User
Longtime User
1. Is it possible to add a button at the bottom of the preference screen. If yes. then kindly let me know how to go about it.

2. I need to add the settings screen as view in a panel. but since the Preference screen is not a view i am not able to do it.

Sorry both of your suggestions/questions are not possible.

For your second question you can create the preference view manually in the designer and use the (AH)PreferencesManager to save and load your settings. Another solution would be to use the StateManager Code Module from Erel
 

mterveen

Member
Licensed User
Longtime User
maybe i wasn't too clear. i like the ease that this library allows in setting up categories and options for various settings. however, it i understand correctly, all the options are stored in one big file accessible only by the program (at least on an unrooted device). i want to be able to use these "methods" to create additional setup/configuration screens particular to a created object, in my case various gauges (which may be added/deleted in the program by the user). currently, now when i want to "configure" a gauge, i have to use a custom list view, generate "headers", then add panels for each type of gauge option that includes a description and field to modify (e.g. text,int, double, boolean, etc) and place them under the appropriate header. since this info is dynamic and is unique for each type of gauge which may be part of many different layouts, it would be nice to be able to use the methods/techniques in this library to save/restore the data from a file specific to the gauge or layout. i do not want to have all the various combinations stored in the main preference library.
 

corwin42

Expert
Licensed User
Longtime User
@mterveen
I don't see any advantage in handling multiple settings files with this library. Why not put all settings for all your gauges in one file?
 

shashkiranr

Active Member
Licensed User
Longtime User
One more question Corwin,

1. I need a category when clicked it should open custom Dialog like date dialog or file dialog

2. It would also be great when any button is clicked i can open an activity.

Is it possible?. If not, is there a workaround which i can use.

Kindly let me know your Inputs and Suggestions.

Regards,
SK
 

corwin42

Expert
Licensed User
Longtime User
One more question Corwin,

1. I need a category when clicked it should open custom Dialog like date dialog or file dialog

2. It would also be great when any button is clicked i can open an activity.

Is it possible?. If not, is there a workaround which i can use.

Kindly let me know your Inputs and Suggestions.

Regards,
SK

It is not possible to open custom dialogs. What you can try is to open a new (invisible) activity which immediately opens a custom dialog. On exiting the dialog you can close the activity then.

You can use the AddIntent() method to open an activity:

B4X:
...
    Dim activityIntent As Intent
    activityIntent.Initialize("your.package.name.action.OPENACTIVITY", "")
    activityIntent.SetComponent(GetPackageName & "/.myactivity")
    catXY.AddIntent("Open Activity", "", activityIntent, "")
...

Sub GetPackageName As String
    Dim r As Reflector
    Return r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
End Sub

And add this to the manifest so the activity listens to the action:

B4X:
AddActivityText(MyActivity, <intent-filter>
              <action android:name="your.package.name.action.OPENACTIVITY" />
              <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>)

you can use any string for the action.
 

gabor

New Member
Licensed User
Longtime User
Hi!

Will the SeekBar be supported in the future? The only thing I miss from this awsome library.

Regards,
Gabor
 

wl

Well-Known Member
Licensed User
Longtime User
Any chance of having an editbox that only accepts numeric values ?

Tx
 

corwin42

Expert
Licensed User
Longtime User
Any chance of having an editbox that only accepts numeric values ?

Tx
Should be possible already with AddEditText2()
 
  • Like
Reactions: wl

BumForALiving

Member
Licensed User
Longtime User
Can we do an inverse to dependency or can the feature be added? In other words, if a box is checked like "Use default" an edit field is not enabled.

If not and adding it would be considered, my thought is to have a - in the dependency string like:

B4X:
cat1.AddCheckBox("check1", "Checkbox1", "Use default setting", "", True, "")
cat1.AddEditText("edit1", "EditText1", "This is the alternative setting", "", "-check1")

Also, is there a way to launch the settings Activity with a specific settings field already open to edit?
 

corwin42

Expert
Licensed User
Longtime User
The dependancy feature is a feature of the PreferenceActivity Class. Unforunately there is no simple way to use it for inverse dependency.
So I'm sorry but this is not possible.
 

FabioG

Active Member
Licensed User
Longtime User
Hi,

after clicking on this checkbox
B4X:
Tweaks.AddCheckBox("ADJ","Adjust Settings","","",ADJSettings,"")

how do I call a sub?

I need to call a sub to update the config file immediately

Thanks
 

FabioG

Active Member
Licensed User
Longtime User
This is not possible for now.

you think to implement this?


I have another problem, I have the following scenario
B4X:
Dim Device As AHPreferenceCategory
 Device.Initialize("Device Settings")
 Device.AddList("Interface","Interface","",InterfaceVar,"",InterfaceList)
 Device.AddList("Method","Method","",MethodVar,"",MethodList)
 Device.AddCheckBox("Port","Select Port","","",PortVar,"Method")

I need the CheckBox "Port" is active only when I select a particular item from the List "Method"

how can I manage this dependence?
 

corwin42

Expert
Licensed User
Longtime User
Events would be quite complicate to handle with this library.

The dependency system is very limited and what you want to do is not possible with the library. I think it would be easier to implement a custom activity for such "complicated" features. You can still use the PreferencesManager to save your preferences, then.
 
Top