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

Last edited:
Variable in Summary

I would like to put a variable in the Summary field, showing for example the current value of the parameter. Is it not possible ?
 
Hello corwin42,

wo kann man einstellen das die funktion "AddEditText" nur Zahlen akzeptiert?
Oder ist es gar nicht möglich?

where you can adjust the the function "AddEditText" only accepts numbers?
Or is it impossible?

Ciao,
Filippo
 
This is currently not possible.

If someone wants to expand this library you can get the source on my GitHub repository. Just see my signature for link.
 
Hello corwin42,

I downloaded your code. How can I fix this error in Eclipse?

This is currently not possible.
According to this Link should be possible.

Ciao,
Filippo
 

Attachments

  • Eclipse-Error_AHPreferenceActivity.jpg
    Eclipse-Error_AHPreferenceActivity.jpg
    48.9 KB · Views: 607
Last edited by a moderator:
Hello Filippo,

Easiest way should be to copy the AddPassword() method and name it AddEditText2(). Add a new parameter for the input type.
Instead of calling et.setTransformationMethod(new PasswordTransformationMethod()); you should call et.setInputType().

I think that should be all. I can do it for you but will take some days.
 
Hallo corwin42,

ich hab die Funktion hinzugefügt, wo kann ich dir den geänderte Quellcode senden, damit du es beim 1.Post austauschen kannst?


Ciao,
Filippo
 
Hello,

if used the sample code (that works well) and implemented it in my app.
In the settings section the calenders are showed and are selectable in the right way.

But if i call the Layout1 the choosen calender and the events are not displayed, the both listviews are empty.
 
One possibility I can think of is to use Intent entries with intents that do nothing. I haven't tested it though.

I've been trying for hours now to no avail, and I've googled helplessly - how do I create an intent that does nothing? All my attempts cause my app to crash immediately.
 
new AddEditText2 method

Hi there...

I need a box to set a numeric pin and two boxes to set rows and columns of a table ... not having a way to add a text box to enter only numbers, I downloaded the source code available, and I added a new method.

the new method is this:

Code:
'Adds a preference entry which allows the user to enter free text.
'Key - The preference key associated with the value.
'Title - Entry title.
'Summary - Entry summary (second row).
'DefaultValue - The default value of this preference entry if the key does not already exist.
'InputType - Input type of entry object
'Password - If inputed text have to be hidden (true) or not
'SelectAllOnFocus - Select all text (true) when edit text object got focus.
'Dependency - A key of a preference this preference entry depends on.
Public Sub AddEditText2(Key As String, Title As String, Summary As String, DefaultValue As String, InputType As Int, Password As Boolean, SelectAllOnFocus As Boolean, Dependency As String)

in this way you can use any available InputType, set it as the password if necessary (as in my pin case) and, if desired, you can choose to select all the text, opening the dialog.

I added the parameter SelectAllOnFocus to the method AddEditText also, because I think it perticularly helpful.

I add in download both the compiled library that the source, asking the author to add my changes to the main branch of his project, so that we do not have a fork ...

in hopes of having done something pleasing, I greet you all

bye
 

Attachments

Last edited:
AHPreference multiple screens with light theme

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

Hi all,
Nice library, big thanks Corwin, it works perfectly.
But i still have a little question, how i can keep the 'theme light' of android with multiple preference screens ?

I attach an example where i put in the AndroidManifest file the 'theme light' of Android for the preference screens, who that looks very nice
But only the first screen that i call appears in this theme, the other appears in default theme.
Now my project grows and i have more settings to put in the preference.
That would be a good thing to have multiple screens for manage them than a scrolling in an unique screen
But i don't find any thread about how i could keep the theme on all screens, any idea ?

Thanks for replies if ever there are

Regards
 

Attachments

Hi there...

I need a box to set a numeric pin and two boxes to set rows and columns of a table ... not having a way to add a text box to enter only numbers, I downloaded the source code available, and I added a new method.

.......

in this way you can use any available InputType, set it as the password if necessary (as in my pin case) and, if desired, you can choose to select all the text, opening the dialog.

I added the parameter SelectAllOnFocus to the method AddEditText also, because I think it perticularly helpful.

I add in download both the compiled library that the source, asking the author to add my changes to the main branch of his project, so that we do not have a fork ...

in hopes of having done something pleasing, I greet you all

bye

Hi fiaful, I'm interested to your AHPreferenceActivity version and I've used it swith success with AHPreferenceCategory object but I didn't find the same for AHPreferenceScreen element.

If I try using the "simple" AddEditText the compiler give the following error:

Code:
  required: String,String,String,String,boolean,String
  found: String,String,String,String,String
  reason: actual and formal argument lists differ in length
1 error

Could you take a look please?

Thanks
 
If I try using the "simple" AddEditText the compiler give the following error:

Code:
  required: String,String,String,String,boolean,String
  found: String,String,String,String,String
  reason: actual and formal argument lists differ in length
1 error

Could you take a look please?

Please give us your code for adding your EditText.
 
Hi yttrium, here is

Code:
Sub Process_Globals
   Dim manager As AHPreferenceManager
   Dim screen,screen2 As AHPreferenceScreen
End Sub

Sub Activity_Create(FirstTime As Boolean)   
   Activity.LoadLayout("Main")
   If FirstTime Then      
      CreateSettings
      If manager.GetAll.Size = 0 Then SetDefaults      
   End If
End Sub

Sub CreateSettings
   Dim cat1, cat2 As AHPreferenceCategory

   screen.Initialize("Settings", "")

   cat1.Initialize("Group1")   
   cat1.AddList("test1","test1","test1 des","","",Array As String("A","B"))
   cat1.AddEditText2("test2", "test2", "I want only numbers", "",2,False,True,"")
   
   screen2.Initialize("Group2","second row")   
   screen2.AddCheckBox("chkBox1","chkBox1","text on","text off",False,"")
'    for screen2 there's not .AddEditText2 so I use AddEditText
   screen2.AddEditText("op1","Option 1","text for option 1","","chkBox1")
   screen2.AddEditText("op2","Option 2","text for option 2","","chkBox1")
   screen2.AddEditText("op3","Option 3","text for option 3","","chkBox1")

   cat2.Initialize("Main group")   
   cat2.AddPreferenceScreen(screen2,"")

   screen.AddPreferenceCategory(cat1)
   screen.AddPreferenceCategory(cat2)
End Sub

Hope you find the problem, thanks in advance!
 
Hope you find the problem, thanks in advance!

It's really simple:
Code:
screen2.AddEditText("op1","Option 1","text for option 1","","chkBox1")
This is the code giving you:
Code:
  required: String,String,String,String,boolean,String
  found: String,String,String,String,String
  reason: actual and formal argument lists differ in length

If you notice, you're giving AddEdittext five strings, but there should actually be four strings, one boolean, and then another string.

Like so:
Code:
screen2.AddEditText("op1","Option 1","text for option 1","",False,"chkBox1")
 
Yes, but the syntax I used it's correct for AddEditText (five strings in case of AHPreferenceScreen), while the compiler expect a boolean more (I also tried using AddEditText2 syntax for AddEditText but didn't work)

The problem seem to be the secondary preference screen.
 
Last edited:
Yes, but the syntax I used it's correct for AddEditText (five strings in case of AHPreferenceScreen), while the compiler expect a boolean more (I also tried using AddEditText2 syntax for AddEditText but didn't work)

The problem seem to be the secondary preference screen.

Have you tried giving it what I said even though it reports the syntax incorrect and seeing if the compiler accepts it?
 
Yes, but I get this error:

Code:
Parsing code.                           0.19
Compiling code.                         Error
Error compiling program.
Error description: Too many parameters.
Occurred on line: 132
screen2.AddEditText("op1","Option 1","text for option 1","",False,"chkBox1")
Word: chkBox1
 
Yeah, you're going to need to wait for Corwin to help with this. Sounds like you might have both PreferenceActivity libraries installed though.
 
For some reason I just can't get intents working here.

Code:
Dim cat1, cat2 As AHPreferenceCategory
cat2.Initialize("About")
Dim Intent3 As Email
Intent3.To.Add("[email protected]")
Intent3.Subject = "[Scrotter4Android] YourIssueHere"
cat2.AddIntent("Contact Us", "via email", Intent3.GetIntent, Null)
PrefScreen.AddPreferenceCategory(cat2)

For some reason clicking my item just causes my app to crash.

Thoughts?
 
Back
Top