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,110
  • AHPreferenceActivity1_02.zip
    21.4 KB · Views: 2,017
  • AHPreferenceActivity1_04.zip
    22.1 KB · Views: 2,594
  • AHPreferenceActivityExample1_04.zip
    7.1 KB · Views: 2,028
Last edited:

corwin42

Expert
Licensed User
Longtime User
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 works on my N7 without problem, too. Even if I make a list with 1000 entries.
 

peacemaker

Expert
Licensed User
Longtime User
So.... only 5.0 emulator problem ?
 

corwin42

Expert
Licensed User
Longtime User

corwin42

Expert
Licensed User
Longtime User

peacemaker

Expert
Licensed User
Longtime User
Seems, solved - sorry for alarming about the lib, the issue was in resource string using "%" symbol
 

Martin Larsen

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

Martin Larsen

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

Dadeda

Member
Licensed User
Longtime User
is it possible to apply a custom theme to the activity that is created for the preferences ?
 

corwin42

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

corwin42

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

Martin Larsen

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

Dadeda

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

Dadeda

Member
Licensed User
Longtime User
Can you please show what you added?

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

To this :
B4X:
AddApplicationText(
<activity
  android:name="de.amberhome.objects.preferenceactivity"
  android:theme="@style/MyTheme">
</activity>
)
where MyTheme is your custom theme.
 

pesquera

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

corwin42

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

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

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