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: 1,988
  • AHPreferenceActivity1_02.zip
    21.4 KB · Views: 1,908
  • AHPreferenceActivity1_04.zip
    22.1 KB · Views: 2,465
  • AHPreferenceActivityExample1_04.zip
    7.1 KB · Views: 1,883
Last edited:

Ionut Indigo

Member
Licensed User
Longtime User
Thanks Erel and corwin42, i had both libraries activated and that was the problem when compiling, but right now i'm getting this message and i think i missed something... (tsss.ssst... is the testing application)
I tried adding the activity declaration to the AndroidManifest.xml, but don't know what should i write exactly.
 

Attachments

  • issue.jpg
    issue.jpg
    40.4 KB · Views: 248

corwin42

Expert
Licensed User
Longtime User
You have to add this line to the manifest editor:

B4X:
AddApplicationText(<activity android:name="anywheresoftware.b4a.objects.preferenceactivity"/>)

Please read the tutorial. All Info should be in there
 

mjtaryan

Active Member
Licensed User
Longtime User
Corwin,

Your additions are very useful. I have two or three questions that I think might be helpful.

1. Could you provide an addendum tutorial that specifically addresses the additions you've made, including the AddIntent.
2. Can the AddIntent be used to call the various pickers (i.e. ringtones, color picker and get a returned value from the picker that gets set as the value for a preference. What I (and probably others) would like to do is to use a picker rather than producing a list of the values.
3. If #2 isn't possible or the way to do it then please either a) add a way to do this or b) explain how it can be done with AHPrefAct as it is.

Thanks a heap.
Mike
 

corwin42

Expert
Licensed User
Longtime User
About 1.: Sorry, I currently don't have enought time to write a tutorial for this. I think most new features are shown in the example app.

About 2.: No. The ringtone-picker is included in AHPreferencesActivity (see example). There is no standard color picker in Android. Possibly a custom color picker will be added to the AHPreferenceActivity library since I need one myself in the near future.

About 3.: For ringtone picker see the example. A color picker is currently not possible.
 

Gargoyle

Member
Licensed User
Longtime User
Is it possible to go straight from the main activity to a sub-preference.

Using example, on main screen create a new button, that when pressed goes straight to the Intents sub-page, or brings up the 'Choose colour' option.
 

Laurent95

Active Member
Licensed User
Longtime User
Hello,
Thanks for this nice library, that work fine.
Just i have a problem that i can't solve yet. I have see in the help popup about the startActivity that we can't start an activity from a service.
But i want start a preference screen from an AppWidget, called widget also.
I'm new with B4A then can you tell me how i can start my preference screen without show any application screen before ?
Actually when i start the preference activity from my event click image of the widget, that's work. But i can't have any advice if the preference was changed, that's my problem because i start the activity directly from a service and the library haven't event.

How is the good way for update my widget when the preference are modified, i have try to find the response but actually i have found nothing about.

Thanks for your response, regards.
 

corwin42

Expert
Licensed User
Longtime User
I think there is currently no solution for your problem.

One "hack" I can think of is to use an invisible dummy Activity. On Activity Create you can open your preference screen and on activity resume check for prefs changes and then call your service for updating and exit the activity.
 

Laurent95

Active Member
Licensed User
Longtime User
I think there is currently no solution for your problem.

One "hack" I can think of is to use an invisible dummy Activity. On Activity Create you can open your preference screen and on activity resume check for prefs changes and then call your service for updating and exit the activity.

Hello Corwin42,

Thank you for your reply. Mmm that's what i feared.

Ok i will try this way.
 

Laurent95

Active Member
Licensed User
Longtime User
One "hack" I can think of is to use an invisible dummy Activity.

Hello Corwin42,

Thanks for the help, it work now, yeeppeeee :sign0098:
Just one thing who is important in this case :
Kill activity, only in "Activity_pause" Sub, and when the "Userclosed" is true. Because you start another Activity, and that's not return in this one but on the widget otherwise..... and you haven't your results.

Just in case someone do the same mistake, the "Activity_resume" Sub is called twice. But only the second time you have your results.

Regards
 

peacemaker

Expert
Licensed User
Longtime User
Date and time separately, possible to add ?
With corresponding dialogues to select.
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
Corwin42,

I need to put the version string of my app on the Preference Screen along with someother sutff... pretty much like the ICS Settings -> System -> About the tablet. There are itens on the menu that are displayed but they are readonly.

How can that be done?

Thanks
 

corwin42

Expert
Licensed User
Longtime User
Date and time separately, possible to add ?
With corresponding dialogues to select.

Would be possible but complicated to use. This has to be implemented as a DialogPreference class and you can only use XML layouts for such a class. I don't think that I add such a feature in the near future.

I need to put the version string of my app on the Preference Screen along with someother sutff... pretty much like the ICS Settings -> System -> About the tablet. There are itens on the menu that are displayed but they are readonly.

How can that be done?

One possibility I can think of is to use Intent entries with intents that do nothing. I haven't tested it though.
 

peacemaker

Expert
Licensed User
Longtime User
Would be possible but complicated to use. This has to be implemented as a DialogPreference class and you can only use XML layouts for such a class. I don't think that I add such a feature in the near future.

One possibility I can think of is to use Intent entries with intents that do nothing. I haven't tested it though.

Why layout ?
I guess, simple Label (containing "HH:mm:ss" or "d, MMMM YYYY"), tapping it starts the date or time change dialogue.
Some parameter containing the Long result value...
 

corwin42

Expert
Licensed User
Longtime User

peacemaker

Expert
Licensed User
Longtime User
Storing passwords needs some encription.
Is it possible to add encription\decription internally (before\after saving\loading a password preference)?

Say like here:

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim Bconv As ByteConverter
End Sub

Sub Get(Text As String, Mode As Int) As String   'mode= 0/1 = encode/decode
   If Text = Null OR Text = "" Then Return ""
   Dim key(0) As Byte
   Dim data(0) As Byte   
   Dim bytes(0) As Byte   

   key = Array As Byte(1, 2, 8, 4, 6, 6, 1, 8)
   ' use DES on raw data in multiples of 8 bytes
   Dim Kg As KeyGenerator
   Dim c As Cipher
   c.Initialize("DES/ECB/NoPadding") ' just "DES" actually performs "DES/ECB/PKCS5Padding". 
   Kg.Initialize("DES")
   Kg.KeyFromBytes(key)

   If Mode = 0 Then   
      Text = padString(Text)
      data = Bconv.StringToBytes(Text, "UTF8")
      data = c.Encrypt(data, Kg.key, False)
      Return Bconv.HexFromBytes(data)
   Else If Mode = 1 Then
      data = Bconv.HexToBytes(Text)
      bytes = c.Decrypt(data, Kg.key, False)
      Return Bconv.StringFromBytes(bytes,"UTF8").Trim
   End If
End Sub

Sub padString(source As String) As String
Dim paddingChar As String, size, x, padLength As Int
paddingChar = " "
size = 16
x = source.Length Mod size
padLength = size - x

For i = 0 To padLength - 1
   source = source & paddingChar
Next
Return source
End Sub
 

iz0ndg

Active Member
Licensed User
Longtime User
Hi Corwin42,
I would like to know if you can force to enter only numeric values in to
preference edittext.

Thanks.
 

marcel

Active Member
Licensed User
Longtime User
Slider

Hi,

Is there a way to add a slider/seekbar to this library?
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Storing passwords needs some encription.
Is it possible to add encription\decription internally (before\after saving\loading a password preference)?

Encryption is currently not supported.

Hi Corwin42,
I would like to know if you can force to enter only numeric values in to
preference edittext.

Thanks.

No, this is currently not supported.

Hi,

Is there a way to add a slider/seekbar to this library?

It would be possible.

I have added these three suggestions to the todo list but I don't know when I have time to add these.
 
Top