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:
Seems, problem with AddList

Code: Copy
    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 works on my N7 without problem, too. Even if I make a list with 1000 entries.
 
So.... only 5.0 emulator problem ?
 
Seems, solved - sorry for alarming about the lib, the issue was in resource string using "%" symbol
 
Thanks for this great library!

Is there a way to add an edit text with numbers only? To use for phonenumbers ...

Also, what about a negative dependency? Only enable a setting if a checkbox is not clicked?

Like:

Invoice address [ somewhere ]
Use same for shipping [ X ]
Shipping address (disabled because we use the same address)

I know I could negate the sentence! but is it possible to negate the condition?
 
Last edited:
Sorry, one more question.

The font size for the titles in the setting is pretty large. How can I change the font size for these?
 
is it possible to apply a custom theme to the activity that is created for the preferences ?
 
is it possible to apply a custom theme to the activity that is created for the preferences ?

It should be possible to set the theme for the PreferenceActivity in the manifest. But be aware this works only for the main preference activity. SubActivities will not have the theme. This is a drawback of the PreferenceActivity.
 
Thanks for this great library!

Is there a way to add an edit text with numbers only? To use for phonenumbers ...

Also, what about a negative dependency? Only enable a setting if a checkbox is not clicked?

With AddEditText2() you can specify an InputType. Set it to EditText.INPUT_TYPE_NUMBERS or EditText.INPUT_TYPE_PHONE.

Negative dependencies are not possible.

Sorry, one more question.

The font size for the titles in the setting is pretty large. How can I change the font size for these?

The Style of the PreferenceActivity should be the default style of the device. The only way I can think of changing this would be to create a custom theme for the PreferenceActivity and make the changes in the Theme.
 
The Style of the PreferenceActivity should be the default style of the device. The only way I can think of changing this would be to create a custom theme for the PreferenceActivity and make the changes in the Theme.

For some reason the font is about 50% bigger than in the settings of all my other apps. Could be something in my manifest, will look into it.
 
It should be possible to set the theme for the PreferenceActivity in the manifest. But be aware this works only for the main preference activity. SubActivities will not have the theme. This is a drawback of the PreferenceActivity.
I've done that, added a custom theme in the manifest editor and it works great ;-)
 
Can you please show what you added?

Just change this line you have to add initially :
Code: Copy
AddApplicationText(<activity android:name="de.amberhome.objects.preferenceactivity"/>)

To this :
Code: Copy
AddApplicationText(
<activity
  android:name="de.amberhome.objects.preferenceactivity"
  android:theme="@style/MyTheme">
</activity>
)
where MyTheme is your custom theme.
 
Hi, I need to open an Activity into a PreferenceActivity. That Activity is for getting an image (photo)
I'm doing something wrong. How can I do that?
Code: Copy
    Dim loc_Intent As Intent
    loc_Intent.Initialize(loc_Intent.ACTION_MAIN,"scr_mifoto")
    loc_Categoria_Parametros.AddIntent("Mi Foto", "xxx", loc_Intent,"")
Thanks in advance
 
Try the following:

If your activity that gets the image is called "GetImageActivity" add the following in the manifest editor (replace <your package name> with the apps package name):

Code: Copy
AddActivityText(GetImageActivity, <intent-filter>
               <action android:name="<your package name>.action.GETIMAGE" />
               <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>)

Code: Copy
Dim loc_intent As Intent
loc_intent.Initialize("<your package name>.action.GETIMAGE", "")
loc_intent.SetComponent(Application.PackageName & "/.getimageactivity")
loc_Categoria_Parametros.AddIntent("Mi Foto", "", loc_Intent, "")

Because of Application.PackageName this only works with B4A 4.0 and above. If you use an older version search the forum how to get the package name.
You can name the action whatever you want. It just should be unique so I added the package name.
 
Back
Top