Android Tutorial StateManager - Helps managing Android applications settings and state

Status
Not open for further replies.

Orcino Borges

Member
Licensed User
Longtime User
Save button colors

Hi Erel

In my application when a button is pressed it changes the color and text.

So is saved with the StateManger, but the color of the button is not saved.

How to do this ?

Thank`s

Orcino
 

Vader

Well-Known Member
Licensed User
Longtime User
Updated version [unofficial]

Erel,

I have modified your version 1.11 and am using it as v 1.12 (attached).

Changes:
Public and Private Sub scope added
Spacing around Sub layout (as I prefer a single line between each Sub)

Additions:
Logging (May not be complete at this time)

Variables
Public SettingsDeleteResult As Boolean = False
Public StateDeleteResult As Boolean = False

Subs
Public Sub DeleteState() as Boolean
Public Sub DeleteSettings() as Boolean
Public Sub DeleteStateAndSettings() as Boolean

I hope you don't mind. It adds a few things I wanted/needed, plus I think one or more people may have asked for the DeleteState or DeleteSettings functionality, and it made sense to share.

Dave
 

Attachments

  • Statemanagerv1.12.zip
    10.3 KB · Views: 594

padvou

Active Member
Licensed User
Longtime User
Hi Erel

In my application when a button is pressed it changes the color and text.

So is saved with the StateManger, but the color of the button is not saved.

How to do this ?

Thank`s

Orcino

B4X:
Else If v Is Button Then
        Dim bttn1 As Button
        bttn1 = v
        data = Array As Object(bttn1.Enabled, bttn1.Visible, bttn1.Text, bttn1.TextColor)

B4X:
Else If v Is Button Then
        Dim bttn1 As Button
        bttn1 = v
        data = getNextItem(list1)
        bttn1.Enabled = data(0)
       bttn1.Visible = data(1)
        bttn1.Text = data(2)
      bttn1.TextColor=data(3)
 

luke2012

Well-Known Member
Licensed User
Longtime User

In this case all the UI Activity views are saved ?
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Trying to save an ImageView background and I am getting a index out of range error. Basically data only comes back with a single element.

Is it not possible to save the background?


'---save data
B4X:
     Else If v Is ImageView Then
      Dim img As ImageView = v
      data = Array As Object(img.Tag,img.Background)
      list1.Add(data)


'--- load data back

B4X:
     Else If TheView Is ImageView Then
      Dim img As ImageView
      img = TheView
      data = getNextItem(list1)
      img.Tag = data(0)
      img.Background = data(1) '--- FAILS HERE
 

jeronimovilar2

Member
Licensed User
Longtime User
I just need not pause my timer when the home button is pressed
please. How can i do this?

B4X:
Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed Then
      log("OK. stop the countdown")
   Else
      log("not pause my count down")
   End If

End Sub
 

jeronimovilar2

Member
Licensed User
Longtime User
What can i do to my timer NOT pause when touch in the home button? (Similar to the clock alarm/timer from android samsung).

My code:
B4X:
Sub Process_Globals
   Dim Timer1 As Timer 
   Dim CountDown1 As Int 
   Dim CountDown2 As Int
   Dim mp As MediaPlayer
   Dim p As Phone
   Dim vibrate As PhoneVibrate
   Dim Timer2 As Timer 
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
   Dim Answ As Int
   If KeyCode = KeyCodes.KEYCODE_BACK Then
      Answ = Msgbox2("Sair do programa???", "ATENÇÂO!!!", "Yes", "", "No", Null)
      If Answ = DialogResponse.NEGATIVE Then
         Return True
      Else
         ToastMessageShow("Saindo...", False)
      End If
   End If
      Return False
End Sub
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim LblCountDown1 As Label
   Dim conta_tempo As Int
   Dim Panel1 As Panel   
   Dim TEMPO As Int
   Dim VarLinguagem As String
   Dim corPainel As String
   Dim IMG1 As ImageView
   Dim TAM_tela As Int
   Dim RB2 As RadioButton
   Dim RB1 As RadioButton
   Dim RB3 As RadioButton
   Dim RB4 As RadioButton   
End Sub
Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed Then
      Log("RESET")
   Else
      Log(IsPaused(""))
   End If
End Sub
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   p.SetScreenBrightness(99) ' aumento o brilho ao máxino
   TAM_tela = 0
   Activity.Title = "-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. Cronômetro 2.1 .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-."
   
   Dim LY As LayoutValues
   Dim X, Y As Int
   LY = GetDeviceLayoutValues
   X = LY.Width
   Y=  LY.Height
   
   '----------- Cronometro -------------------
   Timer1.Initialize("Timer1", 1000)    
   CountDown2 = 0
   CountDown1 = 0
   TEMPO = RB1.Text
   Timer1.Enabled = False
   mp.Initialize2("mp")
   mp.Stop
   '------------------------------------------
End Sub

Sub Timer1_Tick
      If CountDown1 = 5 AND CountDown2 = 1 Then  ' ------- 5 min
         Vibra_Toca (False, True, 5)
      End If
      If CountDown1 = 1 AND CountDown2 = 1 Then ' ----------- 1 min
         Vibra_Toca (False, True, 2)      
      End If
      If CountDown1 = 0 AND (CountDown2 = 6 OR CountDown2 = 5 OR CountDown2 = 4 OR CountDown2 = 3 OR CountDown2 = 2)  Then  ' ------- últimos 5 segundos
         Vibra_Toca (False, True, 2) ' ------- últimos 5 seg
      End If
   If CountDown2 = 0 Then
      CountDown2 = 59
      CountDown1 = CountDown1 - 1
      If CountDown1 < 0 Then
         Timer1.Enabled = False
         CountDown2 = 0
         CountDown1 = 0
      End If
   Else
      CountDown2 = CountDown2 -1
   End If
   If CountDown2 < 10 Then
      LblCountDown1.Text = CountDown1 & ":0" & CountDown2
   Else
      LblCountDown1.Text = CountDown1 & ":" & CountDown2
   End If
   If CountDown2 = 0 AND CountDown1 <= 0 Then
      Timer1.Enabled = False
      Vibra_Toca (True, True, 0)
      CountDown2 = 0
      CountDown1 = 0
   End If
End Sub
Sub Vibra_Toca (vibra As Boolean, toca As Boolean, Musica As Int)
   mp.Initialize2("mp")
   mp.Stop
   Dim SOM As String
   vibrate.vibrate(250)
   If Musica = 5 Then
      SOM = "Alarme_05min.mp3"
      LblCountDown1.TextColor = Colors.Yellow
   Else If Musica = 0 Then  'END
      SOM = "ALARME_FINAL.mp3"
      LblCountDown1.TextColor = Colors.Red
   Else If Musica = 2 Then  '1 min ou 5s
      SOM = "ALARM_1S.mp3"
      LblCountDown1.TextColor = Colors.Red
   Else '  START
      SOM = "ALARME_INICIO.mp3"
      LblCountDown1.TextColor = Colors.White
   End If
   If toca = True Then
      p.SetRingerMode(p.RINGER_NORMAL)
      p.SetVolume(p.VOLUME_MUSIC,15,False)
      Dim r As Reflector
      r.Target = "ContentDir"
      r.Target = r.RunMethod("intern")
      mp.Load(File.DirAssets,SOM)
      mp.Play
      vibrate.vibrate(500)
      mp.Play
   End If
End Sub
Sub LblCountDown1_Click
   Dim SQL As String
   If CountDown2 = 0 AND CountDown1 <= 0 Then
      CountDown2 = 00
      '-----tempo do BUTTON
      CountDown1 = TEMPO
      Vibra_Toca(True, True, 15)
      Timer1.Enabled = True
   End If   
End Sub
Sub Timer2_Tick
   conta_tempo = conta_tempo + 1
   Timer1.Enabled = False
   CountDown2 = 0
   CountDown1 = 0
   If conta_tempo = 3 Then
      Timer2.Enabled = False
   End If
   LblCountDown1.Text = CountDown1 & ":0" & CountDown2
End Sub
Sub LblCountDown1_LongClick
   mp.Stop
   Timer1.Enabled = False
   CountDown2 = 0
   CountDown1 = 0
   LblCountDown1.Text = CountDown1 & ":0" & CountDown2
End Sub
Sub IMG1_LongClick
   ToastMessageShow("REDIMENSIONANDO...",False)
   If TAM_tela < 2 Then
      ' PAINEL
      Panel1.Height = Panel1.Height * 1.5
      Panel1.Width = Panel1.Width * 1.5
      Panel1.Top = Panel1.Top * 1.5
      ' TEMPO
      LblCountDown1.Height = LblCountDown1.Height * 1.5
      LblCountDown1.Width = LblCountDown1.Width * 1.5
      LblCountDown1.TextSize = LblCountDown1.TextSize * 1.5
      LblCountDown1.Top = LblCountDown1.Top * 1.5
      'IMAGEM
      IMG1.Top = IMG1.Top * 1.5
      IMG1.Width = IMG1.Width * 1.5
      IMG1.Height = IMG1.Height * 1.5
      '
      TAM_tela = TAM_tela + 1 
   Else
      Dim i As Int
      For i=1 To 2
      ' PAINEL
      Panel1.Height = Panel1.Height / 1.5
      Panel1.Width = Panel1.Width / 1.5
      Panel1.Top = Panel1.Top / 1.5
      ' TEMPO
      LblCountDown1.Height = LblCountDown1.Height / 1.5
      LblCountDown1.Width = LblCountDown1.Width / 1.5
      LblCountDown1.TextSize = LblCountDown1.TextSize / 1.5
      LblCountDown1.Top = LblCountDown1.Top / 1.5
      'IMAGEM
      IMG1.Top = IMG1.Top / 1.5
      IMG1.Width = IMG1.Width / 1.5
      IMG1.Height = IMG1.Height / 1.5
      '
      Next
      TAM_tela = 0
   End If
   
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
   ToastMessageShow("click",False)
End Sub
Sub RB1_CheckedChange(Checked As Boolean)
   If RB1.Checked = True Then
      TEMPO = RB1.Text
   End If
End Sub
Sub RB2_CheckedChange(Checked As Boolean)
   If RB2.Checked = True Then
      TEMPO = RB2.Text
   End If
End Sub
Sub RB3_CheckedChange(Checked As Boolean)
   If RB3.Checked = True Then
      TEMPO = RB3.Text
   End If
End Sub
Sub RB4_CheckedChange(Checked As Boolean)
   If RB4.Checked = True Then
      TEMPO = RB4.Text
   End If
End Sub
 

Felix Maria

Member
Licensed User
Longtime User
Hi,
I have 4 layouts in my main Activity. These layouts often call each other and has many views in each of the layout.
How can I preserve the state of the layouts like the activity state while navigating between the layouts.
Thank You!

Maria
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…