weathergizmo.luac.lua

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

LUA
1,279
字号
          end
       elseif _application.Store:GetIntValue(Lifetime_Permanent,"Data.AutoDownloadOff") == 0 then
         if declinedRetry == false then
            ForceUpdateWithUserConfirmation(false)
            return 
         end
      end
   end
   local l_29_2 = forecast.currentConditions
   RealWeatherIcon._visible = true
   SetWeatherIconState(RealWeatherIcon, l_29_2.condition)
   if animatingUpOrDown == false then
      SetNewCityInfo()
   end
   ShowForecast(forecast)
   trace("-onBeginGetForecastCompletion")
end

isLegalData = function()
   local cc = weather:GetForecast(cityList[currentCity])
   if cc == nil then
     return false
   end
   local ms = Time_GetMinutesBetweenTheseTwoTimes(cc.lastUpdate, machineStatus.CurrentTime.Value)
   if ms > 7200 then
     return false
   end
   return true
end

nullCompletion = function(l_31_0, l_31_1)
   return 
end

UpdateConditionText = function()
   CityTime._visible = false
   CityPMAM._visible = false
   Condition._visible = false
   _CityLocalTime:DisableUpdate()
   if UpdateStatus == 1 then
      Condition.String = "[[IDS_LOADING_MSG]]"
   elseif UpdateStatus == 2 then
      Condition.String = "[[IDS_NODATA_MSG]]"
   elseif UpdateStatus == 3 then
      Condition._visible = true
      local l_32_0 = weather:GetForecast(cityList[currentCity])
      if l_32_0 ~= nil then
         local l_32_1 = Time_GetMinutesBetweenTheseTwoTimes(l_32_0.lastUpdate, machineStatus.CurrentTime.Value)
         if l_32_1 ~= nil then
            setLastUpdate(l_32_1)
            Condition.String = "[[IDS_STATE_" .. l_32_0.currentConditions.condition .. "]]"
         end
      end
   end
end

fadeInTextUp = function()
   WeatherData.Position.y = -28
   LocationAndCondition.Position.y = -40
   WeatherData.Position:Interpolate(Vector3(0, -8, 0), 10, 0, Interpolate_Linear, nil)
   WeatherData.Opacity:Interpolate(0, 100, 10, 0, Interpolate_Linear)
   LocationAndCondition.Position:Interpolate(Vector3(0, -20, 0), 10, 0, Interpolate_Linear, nil)
   LocationAndCondition.Opacity:Interpolate(0, 100, 10, 0, Interpolate_Linear)
end

fadeInTextDown = function()
   WeatherData.Position.y = 12
   LocationAndCondition.Position.y = 0
   WeatherData.Position:Interpolate(Vector3(0, -8, 0), 10, 0, Interpolate_Linear, nil)
   WeatherData.Opacity:Interpolate(0, 100, 10, 0, Interpolate_Linear)
   LocationAndCondition.Position:Interpolate(Vector3(0, -20, 0), 10, 0, Interpolate_Linear, nil)
   LocationAndCondition.Opacity:Interpolate(0, 100, 10, 0, Interpolate_Linear)
end

clearAndUpdateWeather = function()
  if _config_os == "windowsmobile" then
    DoBeginGetForecast(cityList[currentCity], false)
  end
end

clearAndUpdateCity = function()
   if _config_os == "windowsmobile" then
      Location.String = GetDisplayName(cityList[currentCity])
   end
end

fadeUpCallback = function()
   clearAndUpdateCity()
   _CityLocalTime:Update()
   SetNewCityInfo()
   fadeInTextUp()
   UpdateConditionText()
   animatingUpOrDown = false
end

fadeDownCallback = function()
   clearAndUpdateCity()
   _CityLocalTime:Update()
   SetNewCityInfo()
   fadeInTextDown()
   UpdateConditionText()
   animatingUpOrDown = false
end

fadeOutText = function(l_39_0)
   _CityLocalTime:DisableUpdate()
   animatingUpOrDown = true
   if l_39_0 == "down" then
      ypos = -40
      WeatherData.Position:Interpolate(Vector3(0, ypos, 0), 10, 0, Interpolate_Linear, fadeDownCallback)
   else
      ypos = 12
      WeatherData.Position:Interpolate(Vector3(0, ypos, 0), 10, 0, Interpolate_Linear, fadeUpCallback)
   end
   WeatherData.Opacity:Interpolate(0, 10, 0, Interpolate_Linear)
   LocationAndCondition.Position:Interpolate(Vector3(0, ypos, 0), 10, 0, Interpolate_Linear, nil)
   LocationAndCondition.Opacity:Interpolate(0, 10, 0, Interpolate_Linear)
end

MoveUp = function()
   if getForecastTimer == nil then
      UpArrow.Opacity:Interpolate(100, 25, 5, 0, Interpolate_EaseOutQuad)
      UpArrow.Opacity:Interpolate(25, 100, 5, 5, Interpolate_EaseInQuad)
      fadeOutText("up")
      currentCity = currentCity - 1
      if currentCity == 0 then
         currentCity = cityListSize
      end
      UpdateCityCount()
      clearAndUpdateWeather()
   end
end

MoveDown = function()
   if getForecastTimer == nil then
      DownArrow.Opacity:Interpolate(100, 20, 5, 0, Interpolate_EaseOutQuad)
      DownArrow.Opacity:Interpolate(20, 100, 5, 5, Interpolate_EaseInQuad)
      fadeOutText("down")
      currentCity = currentCity + 1
      if currentCity > cityListSize then
         currentCity = 1
      end
      UpdateCityCount()
      clearAndUpdateWeather()
   end
end

onKeyDown = function(l_42_0, l_42_1, l_42_2)
   if _config_os == "windowsmobile" then
      if currentMode == "EasterEgg" then
         return 
      elseif currentMode == "Gizmo" then
         if l_42_1.Code == KeyCode_Up or l_42_1.Code == KeyCode_SwipeDown then
            MoveUp()
            l_42_2.value = true
         elseif l_42_1.Code == KeyCode_Down or l_42_1.Code == KeyCode_SwipeUp then
            MoveDown()
            l_42_2.value = true
         end
      elseif currentMode == "CityPicker" then
        if (l_42_1.Code == KeyCode_Return or l_42_1.Code == KeyCode_Space) then
            CityPicker_HandleKeyDown(l_42_1)
            l_42_2.value = true
        end
      elseif currentMode == "NoCities" then
        if (l_42_1.Code == KeyCode_Return or l_42_1.Code == KeyCode_Space) then
            ShowCityPicker()
            l_42_2.value = true
        end
      elseif currentMode == "ConnectionError" then
        if (l_42_1.Code == KeyCode_Return) or l_42_1.Code == KeyCode_Space then
             ForceUpdateWithUserConfirmation(false)
             l_42_2.value = true
        end
      end
   elseif l_42_1 == 32 then
        if CurrentDisplay == "Gizmo" then
             SwitchMode("DetailView")
             l_42_2.value = true
        elseif CurrentDisplay == "DetailView" then
             SwitchMode("CityPicker")
             l_42_2.value = true
        else
             SwitchMode("Gizmo")
             l_42_2.value = true
        end
  else
    if l_42_1 == 38 then
        fadeOutText("up")
        mystate = mystate - 1
        l_42_2.value = true
    elseif l_42_1 == 40 then
        fadeOutText("down")
        mystate = mystate + 1
        l_42_2.value = true
    end
    if mystate > 43 then
        mystate = 1
        l_42_2.value = true
    elseif mystate < 1 then
        mystate = 43
        l_42_2.value = true
    end
    if CurrentDisplay == "Gizmo" then
       SetWeatherIconState(RealWeatherIcon, mystate)
    else
       SetWeatherIconStateNoFade(Day1ConditionIcon, mystate)
       SetWeatherIconStateNoFade(Day2ConditionIcon, mystate)
       SetWeatherIconStateNoFade(Day3ConditionIcon, mystate)
       SetWeatherIconStateNoFade(Day4ConditionIcon, mystate)
       SetWeatherIconStateNoFade(Day5ConditionIcon, mystate)
    end
  end
end

ShowCityPicker = function()
   SwitchMode("CityPicker")
end

RemoveCurrentCity = function()
   if cityListSize > 1 then
      for i = currentCity, cityListSize do
         cityList[i] = cityList[i + 1]
      end
   end
   cityList[cityListSize] = nil
   cityListSize = cityListSize - 1
   if currentCity > cityListSize then
      currentCity = cityListSize
   end
   PersistCityList()
   UpdateCityCount()
   if cityListSize > 0 then
      Location.String = cityList[currentCity].cityName
      clearAndUpdateWeather()
   else
      SwitchMode("NoCities")
   end
end

if _config_os == "windowsmobile" then
   strsplit = function(l_45_0, l_45_1)
     local l_45_2 = {}
     local l_45_3 = 1
     if string.find("", l_45_0, 1) then
        error("delimiter matches empty string!")
     end
     while true do
       local l_45_4, l_45_5 = string.find(l_45_1, l_45_0, l_45_3)
       if l_45_4 then
          table.insert(l_45_2, string.sub(l_45_1, l_45_3, l_45_4 - 1))
          l_45_3 = l_45_5 + 1
       else
          table.insert(l_45_2, string.sub(l_45_1, l_45_3))
          break;
       end
     end
     return l_45_2     
   end
   PersistCityList = function()
      local l_46_0 = ""     
      if cityListSize >= 1 then
         for i = 1, cityListSize do
            l_46_0 = l_46_0 .. cityList[i].accuweatherCode
            if i < cityListSize then
               l_46_0 = l_46_0 .. ","
            end
         end
      end
      _application.Store:SetStringValue(Lifetime_Permanent, "Weather.CityList", l_46_0)
      if cityListSize == 0 then
         currentCity = 0
         _application.Store:SetIntValue(Lifetime_Permanent, "Weather.CurrentCity", currentCity)
      end
   end
   ProblemGroupOnRelease = function(l_47_0, l_47_1)
      if currentMode == "NoCities" then
         l_47_1.value = true
         SwitchMode("CityPicker")
      elseif currentMode == "ConnectionError" then
         l_47_1.value = true
         ForceUpdateWithUserConfirmation(false)
      end
   end
   AddCity = function(l_48_0, l_48_1)
      local l_48_2 = weather:SearchCities(l_48_0, 1 + l_48_1)
      if l_48_2:GetCount() >= l_48_1 + 1 then
         cityListSize = cityListSize + 1
         cityList[cityListSize] = l_48_2:GetItem(l_48_1)
      end
      return 
   end
   LoadCityList = function()
      cityList = {}
      local l_49_0 = _application.Store:GetIntValue(Lifetime_Permanent, "Weather.PostFirstRun")
      if l_49_0 ~= 1 then
         cityListSize = 0
         AddCity("Taipei", 0)
         AddCity("Barcelona", 0)
         AddCity("London", 1)
         AddCity("Seattle", 0)
         AddCity("Paris", 0)
         AddCity("Tokyo", 0)
         PersistCityList()
      else
         cityListSize = 0
         local asg = _application.Store:GetStringValue(Lifetime_Permanent, "Weather.CityList")
         if asg ~= "" then
            local ss = strsplit(",", asg)
            for i_1,i_2 in ipairs(ss) do
               cityListSize = cityListSize + 1
               cityList[cityListSize] = weather:GetCityFromCode(i_2)
               if cityList[cityListSize].accuweatherCode == "" then
                  _application.Store:SetIntValue(Lifetime_Permanent, "Weather.PostFirstRun", 0)
                  LoadCityList()
               end
            end
         end
      end
      if l_49_0 ~= 1 then
         currentCity = 1
         _application.Store:SetIntValue(Lifetime_Permanent, "Weather.CurrentCity", currentCity)
      else
         currentCity = _application.Store:GetIntValue(Lifetime_Permanent, "Weather.CurrentCity")
         if (currentCity == 0 and cityListSize ~= 0) or currentCity > cityListSize then
            currentCity = 1
            _application.Store:SetIntValue(Lifetime_Permanent, "Weather.CurrentCity", 1)
         end
      end
      if l_49_0 ~= 1 then
         _application.Store:SetIntValue(Lifetime_Permanent, "Weather.PostFirstRun", 1)
      end
   end
   OnPageInit1 = function()
      machineStatus = MachineStatus()
      minutetimer = timer(60)
      minutetimer.OnElapsed:connect(onTimePulse)
      _CityLocalTime = CityLocalTime(machineStatus, nil, CityTime, CityPMAM)
      weather = AccuWeather(_application:GetScopedLog("weather"), _application.Store)
      LoadCityList()
      KeyboardHandler.onKeyDown:connect(onKeyDown)
      KeyboardHandler:Focus()
   end
else
   cityListSize = 4
   currentCity = 1
   cityList = {[1] = "Seattle, WA", [2] = "London, UK", [3] = "Taipei, TW", [4] = "S?o Paulo, Brazil"}
   mystate = 0
end

OnLastUpdateRelease = function(l_51_0, l_51_1)
   l_51_1.value = true
   ForceUpdateWithUserConfirmation(true)
end

OnPostPageInit3 = function()
   cityPickerLayout = TileLayout()
   cityPickerLayout:SetItemSize(480, 81, 0)
   CityPickerList:SetLayout(cityPickerLayout)
   cityPickerLayout.SelectionNode = CityPickerSelector
   countryPickerLayout = TileLayout()
   countryPickerLayout:SetItemSize(480, 81, 0)
   CountryPickerList:SetLayout(countryPickerLayout)
   countryPickerLayout.SelectionNode = CountryPickerSelector
   CityPickerListScrollPhysics = ScrollPhysics(CityPickerList, CityPickerList, HandleCityListSelection)
   CountryPickerListScrollPhysics = ScrollPhysics(CountryPickerList, CountryPickerList, HandleCountryListSeletion)
   SwitchMode("Gizmo")
   UpArrowDetector.onRelease:connect(function(l_1_0, l_1_1)
      l_1_1.value = true
      MoveUp()
   end)
   DownArrowDetector.onRelease:connect(function(l_2_0, l_2_1)
      l_2_1.value = true
      MoveDown()
   end)
   ProblemText.onRelease:connect(ProblemGroupOnRelease)
   if _config_os == "windowsmobile" then 
     if cityListSize > 0 then
       local l_52_0 = weather:IsRoaming()
       local l_52_1 = weather:DownloadWhenRoaming()     
       if _application.Store:GetIntValue(Lifetime_Permanent, "Data.AutoDownloadOff") == 1 then
         declinedRetry = true
       end
       OnLoadGetForecasts(false)
     else
       SwitchMode("NoCities")
     end
   end
   LastUpdateHitDetector.onRelease:connect(OnLastUpdateRelease)
end

OnMenuExit = function(l_53_0)
   if resetSoftkeysOnDialogExit == true then
      SetGizmoSoftkeys()
      resetSoftkeysOnDialogExit = false
   end
   if l_53_0.Result.ExitType ~= DialogExitType_Cancel then
      if l_53_0.Result.UserValue == "Add City..." then
         ShowCityPicker()
      elseif l_53_0.Result.UserValue == "Remove This City" then
         RemoveCurrentCity()
      elseif l_53_0.Result.UserValue == "Remove All Cities" then
        while cityListSize > 0 do
         RemoveCurrentCity()
        end
      elseif l_53_0.Result.UserValue == "Fahrenheit" then
        _application.Store:SetIntValue(Lifetime_Permanent, "Weather.Fahrenheit", 1)
        _celsius = false
        DoBeginGetForecast(cityList[currentCity], false)
      elseif l_53_0.Result.UserValue == "Celsius" then
        _application.Store:SetIntValue(Lifetime_Permanent, "Weather.Fahrenheit", 0)
        _celsius = true
        DoBeginGetForecast(cityList[currentCity], false)
      elseif l_53_0.Result.UserValue == "Update Now" then
        ForceUpdateWithUserConfirmation(true)
      elseif l_53_0.Result.UserValue == "Settings" then
        _application.Navigation:Navigate(URL("Manila://settings/updatesanddata/updatesanddata.page"), true)
      elseif l_53_0.Result.UserValue == "MoreInfo" then
        DetailOnRelease()
      elseif l_53_0.Result.UserValue == "About" then
        Shell_NavigateTo(ShellLocation_Opera, "file:/windows/weather_about.html")
      end
   end
end

⌨️ 快捷键说明

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