weathergizmo.luac.lua

来自「htc manila 2 sourcecode」· LUA 代码 · 共 1,279 行 · 第 1/3 页

LUA
1,279
字号
       LastUpdateMinAgo._visible = false
       _application.Navigation.TabVisibility = true
       currentMode = "NoCities"
       SetViewToGizmoMode(UpdateStatus)
       _application:SetLeftSoftkey(Softkey("", nil))
       _application:SetRightSoftkey(Softkey(Locale:GetString("IDS_ADDCITY"), function()
          SwitchMode("CityPicker")
       end))
       ProblemGroup._visible = true
       ProblemText.String = "[[IDS_ADDCITY]]"
    elseif l_19_0 == "ConnectionError" then
       if currentMode ~= "ConnectionError" and declinedRetry == false then
          _application.TouchFlo.HorizontalEnabled = false
          _application.TouchFlo.VerticalEnabled = false
          currentMode = "ConnectionError"
          ShowConnectionErrorDialog()
       else
         CityNumberGroup._visible = true
         UpdateCityCount()
      end
   elseif l_19_0 == "EasterEgg" then
      _application.TouchFlo.HorizontalEnabled = false
      _application.TouchFlo.VerticalEnabled = false
      CityNumberGroup._visible = false
      currentMode = "EasterEgg"
      SetViewToGizmoMode(UpdateStatus)
      _application:SetLeftSoftkey(Softkey(Locale:GetString("IDS_CANCEL"), CancelEasterEgg))
      _application:SetRightSoftkey(Softkey("", nil))
      InitializeEasterEgg()
   else
      _application.TouchFlo.HorizontalEnabled = true
      _application.TouchFlo.VerticalEnabled = true
      if _application.DialogManager:CurrentlyShowingDialog() == false then
         SetGizmoSoftkeys()
      else
         resetSoftkeysOnDialogExit = true
      end
      CityNumberGroup._visible = true
      UpdateCityCount()
      _application.Navigation.Title = "[[IDS_WEATHER]]"
      _application.Navigation.TabVisibility = true
      LastUpdateLabel._visible = true
      LastUpdateMinAgo._visible = true
      IconGroup._visible = true
      if cityListSize == 0 then
         SwitchMode("NoCities")
         return 
      end
      currentMode = "Gizmo"
      SetViewToGizmoMode(UpdateStatus)
      KeyboardHandler:Focus()
   end
   CurrentDisplay = l_19_0
end

DetailOnRelease = function(l_20_0, l_20_1)
   local l_20_2 = cityList[currentCity].accuweatherCode
   local l_20_3 = string.gsub(l_20_2, "|", "/")
   local l_20_4 = "http://www.accuweather.com/m/" .. l_20_3 .. "/details.aspx"
   trace("URL " .. l_20_4)
   Shell_NavigateTo(ShellLocation_Opera, l_20_4)
end

EnableDetailLink = function()
   DeatilOnline.String = "[[IDS_MOREDETAIL]]" .. ">>"
   if DeatilOnline then
      DeatilOnline.onRelease:connect(DetailOnRelease)
      gbDetailConnet = true
   end
end

DisableDetailLink = function()
   if gbDetailConnet == true then
      DeatilOnline.onRelease:disconnect(DetailOnRelease)
      gbDetailConnet = false
   end
end

OnTimerDrawForecast = function(l_23_0)
   if l_23_0 ~= nil then
      l_23_0:Stop()
   end
   WeatherForecast._visible = true
   EnableDetailLink()
   InitializeWeatherIcon(Day2ConditionIcon, true)
   InitializeWeatherIcon(Day3ConditionIcon, true)
   InitializeWeatherIcon(Day4ConditionIcon, true)
   InitializeWeatherIcon(Day5ConditionIcon, true)
   for i = 2, 5 do
      local l_23_5 = drawForecastData.forecast[i - 1]     
      if i == 2 then
         Day2DayOfWeek.String = "[[IDS_" .. string.upper(tostring(l_23_5.dayOfWeek)) .. "_SHORT" .. "]]"
         SetWeatherIconStateNoFade(Day2ConditionIcon, l_23_5.condition)
         if _celsius == true then
            Day2HighTemperature.String = tostring(l_23_5.highC .. "?")
            Day2LowTemperature.String = tostring(l_23_5.lowC .. "?")
         else
            Day2HighTemperature.String = tostring(l_23_5.highF .. "?")
            Day2LowTemperature.String = tostring(l_23_5.lowF .. "?")
         end
      elseif i == 3 then
         Day3DayOfWeek.String = "[[IDS_" .. string.upper(tostring(l_23_5.dayOfWeek)) .. "_SHORT" .. "]]"
         SetWeatherIconStateNoFade(Day3ConditionIcon, l_23_5.condition)
         if _celsius == true then
            Day3HighTemperature.String = tostring(l_23_5.highC .. "?")
            Day3LowTemperature.String = tostring(l_23_5.lowC .. "?")
         else
            Day3HighTemperature.String = tostring(l_23_5.highF .. "?")
            Day3LowTemperature.String = tostring(l_23_5.lowF .. "?")
         end
      elseif i == 4 then
         Day4DayOfWeek.String = "[[IDS_" .. string.upper(tostring(l_23_5.dayOfWeek)) .. "_SHORT" .. "]]"
         SetWeatherIconStateNoFade(Day4ConditionIcon, l_23_5.condition)
         if _celsius == true then
            Day4HighTemperature.String = tostring(l_23_5.highC .. "?")
            Day4LowTemperature.String = tostring(l_23_5.lowC .. "?")
         else
            Day4HighTemperature.String = tostring(l_23_5.highF .. "?")
            Day4LowTemperature.String = tostring(l_23_5.lowF .. "?")
         end
      elseif i == 5 then
         Day5DayOfWeek.String = "[[IDS_" .. string.upper(tostring(l_23_5.dayOfWeek)) .. "_SHORT" .. "]]"
         SetWeatherIconStateNoFade(Day5ConditionIcon, l_23_5.condition)
         if _celsius == true then
            Day5HighTemperature.String = tostring(l_23_5.highC .. "?")
            Day5LowTemperature.String = tostring(l_23_5.lowC .. "?")
         else
            Day5HighTemperature.String = tostring(l_23_5.highF .. "?")
            Day5LowTemperature.String = tostring(l_23_5.lowF .. "?")
         end
      end
   end
drawForecastData = nil
end

OngetForecastTimerExpired = function(l_24_0)
   l_24_0:Stop()
   getForecastTimer = nil
   if currentMode ~= "CityPicker" then
      trace("---------------Forecast Timer Expired\n")
      SwitchMode("ConnectionError")
   end
end

OnLoadingtimerExpired = function(l_25_0)
   if LastUpdateLabel.String == "[[IDS_LOADING]]" then
      LastUpdateLabel.String = "[[IDS_LOADING]]."
   else
      if LastUpdateLabel.String == "[[IDS_LOADING]]." then
         LastUpdateLabel.String = "[[IDS_LOADING]].."
      else
         if LastUpdateLabel.String == "[[IDS_LOADING]].." then
            LastUpdateLabel.String = "[[IDS_LOADING]]..."
         else
            if LastUpdateLabel.String == "[[IDS_LOADING]]..." then
               LastUpdateLabel.String = "[[IDS_LOADING]]"
            end
         end
      end
   end
end

DoBeginGetForecast = function(l_26_0, l_26_1)
   trace("~~~DoBeginGetForecast for " .. l_26_0.cityName .. "~~~")
   if getForecastTimer ~= nil then
      getForecastTimer:Stop()
   end
   forecastMinutes = -1
   getForecastTimer = timer(90)
   getForecastTimer.OnElapsed:connect(OngetForecastTimerExpired)
   LastUpdateLabel.String = "[[IDS_LOADING]]"
   SetViewToGizmoMode(1)
   LastUpdateMinAgo.String = ""
   weather:BeginGetForecast(l_26_0, l_26_1, onBeginGetForecastCompletion)
end

SetNewCityInfo = function()
   if forecast == nil then
      trace("forecast is nil!\n")
   else
      forecastMinutes = Time_GetMinutesBetweenTheseTwoTimes(forecast.lastUpdate, machineStatus.CurrentTime.Value)
   end
   if forecast == nil then
     DoBeginGetForecast(cityList[currentCity], false)
     TemperatureHundreds.String = ""
     TemperatureTens.String = ""
     TemperatureOnes.String = ""
     TemperatureDegrees.String = ""
     Condition.String = ""
     HighLabel.String = ""
     LowLabel.String = ""
     HighTemp.String = ""
     LowTemp.String = ""
     return 
   end
   local l_27_0 = weather:GetForecast(cityList[currentCity])
   if l_27_0 == nil then
      TemperatureHundreds.String = ""
      TemperatureTens.String = ""
      TemperatureOnes.String = ""
      TemperatureDegrees.String = ""
      Condition.String = ""
      HighLabel.String = ""
      LowLabel.String = ""
      HighTemp.String = ""
      LowTemp.String = ""
      RealWeatherIcon._visible = false
      Day2DayOfWeek.String = ""
      Day3DayOfWeek.String = ""
      Day4DayOfWeek.String = ""
      Day5DayOfWeek.String = ""
      Day2LowTemperature.String = ""
      Day2HighTemperature.String = ""
      Day3LowTemperature.String = ""
      Day3HighTemperature.String = ""
      Day4LowTemperature.String = ""
      Day4HighTemperature.String = ""
      Day5LowTemperature.String = ""
      Day5HighTemperature.String = ""
      WeatherForecast._visible = false
      return 
   end
   local l_27_1 = forecast.currentConditions
   local l_27_2 = 0
   if _celsius == true then
      l_27_2 = l_27_1.temperatureC
   else
      l_27_2 = l_27_1.temperatureF
   end
   if l_27_2 < -99 or l_27_2 > 199 then
      trace("Out of range temperature: " .. tostring(l_27_2))
   end
   if l_27_2 < 0 then
      TemperatureNegative.String = "-"
      if l_27_2 < -9 then
         TemperatureNegative._visible = true
         TemperatureHundreds._visible = false
         TemperatureTens._visible = true
         TemperatureOnes._visible = true
         TemperatureNegative.Position.x = 0
         TemperatureTens.Position.x = 42
         TemperatureOnes.Position.x = 85
         TemperatureDegrees.Position.x = 129
      else
         TemperatureNegative._visible = true
         TemperatureHundreds._visible = false
         TemperatureTens._visible = false
         TemperatureOnes._visible = true
         TemperatureNegative.Position.x = 0
         TemperatureOnes.Position.x = 50
         TemperatureDegrees.Position.x = 97
      end
   elseif l_27_2 < 10 then
      TemperatureNegative._visible = false
      TemperatureHundreds._visible = false
      TemperatureTens._visible = false
      TemperatureOnes._visible = true
      TemperatureOnes.Position.x = 20
      TemperatureDegrees.Position.x = 67
   elseif l_27_2 < 100 then
      TemperatureNegative._visible = false
      TemperatureHundreds._visible = false
      TemperatureTens._visible = true
      TemperatureOnes._visible = true
      TemperatureTens.Position.x = 17
      TemperatureOnes.Position.x = 64
      TemperatureDegrees.Position.x = 110
   else
      TemperatureNegative._visible = false
      TemperatureHundreds._visible = true
      TemperatureTens._visible = true
      TemperatureOnes._visible = true
      TemperatureHundreds.Position.x = -3
      TemperatureTens.Position.x = 27
      TemperatureOnes.Position.x = 73
      TemperatureDegrees.Position.x = 120
   end
  if l_27_2 < 0 then
    l_27_2 = l_27_2 * -1
  end
  TemperatureHundreds.String = tostring(NumberUtilities_GetDigit(l_27_2, 3))
  TemperatureTens.String = tostring(NumberUtilities_GetDigit(l_27_2, 2))
  TemperatureOnes.String = tostring(NumberUtilities_GetDigit(l_27_2, 1))
  TemperatureDegrees.String = "?"
  HighLabel.String = "[[IDS_HIGHTEMPLABEL]]"
  LowLabel.String = "[[IDS_LOWTEMPLABEL]]"
  if l_27_1.condition == 8 then
    l_27_1.condition = 7
  end
  Condition.String = "[[IDS_STATE_" .. l_27_1.condition .. "]]"
  setLastUpdate(forecastMinutes)
  forecastPoint = forecast.forecast[0]
  if _celsius == true then
    HighTemp.String = tostring(forecastPoint.highC .. "?")
    LowTemp.String = tostring(forecastPoint.lowC .. "?")
  else
    HighTemp.String = tostring(forecastPoint.highF .. "?")
    LowTemp.String = tostring(forecastPoint.lowF .. "?")
  end
  Location.String = GetDisplayName(cityList[currentCity])
end

ShowForecast = function(l_28_0)
   trace("show forecast")
   if l_28_0 == nil then
      return 
   end
   if drawForecastData ~= nil then
      drawForecastData = nil
   end
   drawForecastData = l_28_0
   if drawForecastTimerInterval ~= nil then
      WeatherForecast._visible = false
   end
   if drawForecastTimer ~= nil then
      drawForecastTimer:Stop()
   end
   if drawForecastTimerInterval ~= 0 then
      drawForecastTimer = timer(drawForecastTimerInterval)
      drawForecastTimer.OnElapsed:connect(OnTimerDrawForecast)
      drawForecastTimerInterval = 0
   else
      OnTimerDrawForecast()
   end
end

onBeginGetForecastCompletion = function(l_29_0, l_29_1)
   trace("+onBeginGetForecastCompletion")
   if l_29_0 == true then
     local isr = weather:IsRoaming()
     local dwr = weather:DownloadWhenRoaming()
     local dado = _application.Store:GetIntValue(Lifetime_Permanent,"Data.AutoDownloadOff") ~= 0
     if forceRoaming == false and isr == true and dwr == false and dado == false then
       skiperrorbox = false
       if navigatingIn == true then
          functionForAfterOnNavigateIn = function()
             ShowUpdateNowConfirmationDialog(function()
                OnLoadGetForecasts(true)
             end)
          end
       else
          ShowUpdateNowConfirmationDialog(function()
             OnLoadGetForecasts(true)
          end)         
       end
       trace("~~~ return 1 ")
       return            
     end
     if getForecastTimer ~= nil then
         getForecastTimer:Stop()
         getForecastTimer = nil
     end
     local wgfc = weather:GetForecast(cityList[currentCity]);
     if wgfc ~= nil then
         trace("~~~ has forecast ~~~")
         forecast = wgfc
     else
         trace("~~~ no forecast ~~~")
         if l_29_1.cityName == cityList[currentCity].cityName then
           trace("@@@@@Show NoDataGroup city=" .. l_29_1.cityName .. "@@@@@ current city=" .. cityList[currentCity].cityName)
           TemperatureHundreds.String = ""
           TemperatureTens.String = ""
           TemperatureOnes.String = ""
           TemperatureDegrees.String = ""
           Condition.String = ""
           HighLabel.String = ""
           LowLabel.String = ""
           HighTemp.String = ""
           LowTemp.String = ""
           RealWeatherIcon._visible = false
           SetViewToGizmoMode(2)
         else
           trace("@@@@@Do not show NoDataGroup city=" .. l_29_1.cityName .. "@@@@@ current city=" .. cityList[currentCity].cityName)
         end
     end
     if (declinedRetry == false or dado == false) and skiperrorbox == false then
        trace("---------------onBeginGetForecastCompletionError\n")
        LastUpdateLabel.String = "[[IDS_LASTUPDATELABEL]]"
        SwitchMode("ConnectionError")
     else
        LastUpdateLabel.String = "[[IDS_LASTUPDATELABEL]]"
     end
     skiperrorbox = false
     trace("~~~ return 2 ")
     return
   end
   skiperrorbox = false
   if l_29_1.cityName ~= cityList[currentCity].cityName then
      trace("~~~ return 3 ")
      return 
   end
   if currentMode == "ConnectionError" then
      SwitchMode("Gizmo")
      return 
   end
   loadedCity = true
   UpdateCityCount()
   LastUpdateLabel.String = "[[IDS_LASTUPDATELABEL]]"
   SetViewToGizmoMode(3)
   if getForecastTimer ~= nil then
      getForecastTimer:Stop()
      getForecastTimer = nil
   end
   forecast = weather:GetForecast(cityList[currentCity])
   forecastMinutes = Time_GetMinutesBetweenTheseTwoTimes(forecast.lastUpdate, machineStatus.CurrentTime.Value)
   if forecastMinutes < 0 then
      weather:ClearCache(cityList[currentCity])
      DoBeginGetForecast(cityList[currentCity], false)
      return 
   end
   _CityLocalTime:Reset(forecast)
   if forecastMinutes > 180 then
      local l_29_2 = weather:IsRoaming()
      local l_29_3 = weather:DownloadWhenRoaming()
      if forceRoaming == false and l_29_2 == true and l_29_3 == false then
          if navigatingIn == true then
            functionForAfterOnNavigateIn = function()
              ShowUpdateNowConfirmationDialog(function()
                 OnLoadGetForecasts(true)
              end)
           end
          else
            if declinedRetry == false then
               ShowUpdateNowConfirmationDialog(function()
                  OnLoadGetForecasts(true)
               end)
            end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?