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:

enrico

Active Member
Licensed User
Longtime User
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 ?
 
D

Deleted member 103

Guest
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
 

corwin42

Expert
Licensed User
Longtime User
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.
 
D

Deleted member 103

Guest
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: 266
Last edited by a moderator:

corwin42

Expert
Licensed User
Longtime User
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.
 
D

Deleted member 103

Guest
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
 

GMan

Well-Known Member
Licensed User
Longtime User
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.
 

yttrium

Active Member
Licensed User
Longtime User
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.
 

fiaful

Member
Licensed User
Longtime User
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:

B4X:
'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

  • AHPreferenceActivity103.zip
    23.2 KB · Views: 354
  • src.zip
    3.5 KB · Views: 317
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
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

  • Multiprefscreen.zip
    8.8 KB · Views: 288

SandroB4A

Member
Licensed User
Longtime User
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:

B4X:
  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
 

yttrium

Active Member
Licensed User
Longtime User
If I try using the "simple" AddEditText the compiler give the following error:

B4X:
  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.
 

SandroB4A

Member
Licensed User
Longtime User
Hi yttrium, here is

B4X:
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!
 

yttrium

Active Member
Licensed User
Longtime User
Hope you find the problem, thanks in advance!

It's really simple:
B4X:
screen2.AddEditText("op1","Option 1","text for option 1","","chkBox1")
This is the code giving you:
B4X:
  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:
B4X:
screen2.AddEditText("op1","Option 1","text for option 1","",False,"chkBox1")
 

SandroB4A

Member
Licensed User
Longtime User
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:

yttrium

Active Member
Licensed User
Longtime User
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?
 

SandroB4A

Member
Licensed User
Longtime User
Yes, but I get this error:

B4X:
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
 

yttrium

Active Member
Licensed User
Longtime User
Yeah, you're going to need to wait for Corwin to help with this. Sounds like you might have both PreferenceActivity libraries installed though.
 

yttrium

Active Member
Licensed User
Longtime User
For some reason I just can't get intents working here.

B4X:
Dim cat1, cat2 As AHPreferenceCategory
cat2.Initialize("About")
Dim Intent3 As Email
Intent3.To.Add("tyclief@gmail.com")
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?
 
Top