xm
2021-11-25 47fbfe1cd58bb82b45dfc0a5398799bd856b1fb0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
  public class AddInputType : FrameLayout
  {
    public AddInputType()
    {
      Tag = "Logic";
    }
    public void Show()
    {
      LogicView.TopView topView = new LogicView.TopView();
      this.AddChidren(topView.FLayoutView());
      topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
      {
        RemoveFromParent();
      };
      topView.topNameBtn.TextID = StringId.selectionCondition;
 
      FrameLayout viewLayout = new FrameLayout
      {
        Y = Application.GetRealHeight(64),
        Width = Application.GetRealWidth(LogicView.TextSize.view375),
        Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64),
        BackgroundColor = CSS.CSS_Color.viewMiddle,
      };
      this.AddChidren(viewLayout);
      #region 时间  功能 室外变化
      //时间
      LogicView.SelectTypeView timeView = new LogicView.SelectTypeView();
      timeView.btnText.TextID = StringId.time;
      timeView.btnIcon.UnSelectedImagePath = "LogicIcon/time.png";
      if (MainView.IsGatewayType)
      {
        viewLayout.AddChidren(timeView.FLayoutView());
      }
 
      //功能
      LogicView.SelectTypeView functionView = new LogicView.SelectTypeView();
      functionView.frameLayout.Y = timeView.frameLayout.Bottom;
      functionView.btnText.TextID = StringId.funLogic;
      functionView.btnIcon.UnSelectedImagePath = "LogicIcon/functionicon.png";
      viewLayout.AddChidren(functionView.FLayoutView());
      if (!MainView.IsGatewayType)
      {
        functionView.frameLayout.Y = Application.GetRealHeight(0);
      }
 
      //场景
      LogicView.SelectTypeView sceneView = new LogicView.SelectTypeView();
      sceneView.frameLayout.Y = functionView.frameLayout.Bottom;
      sceneView.btnText.TextID = StringId.Scenes;
      sceneView.btnIcon.UnSelectedImagePath = "LogicIcon/scene.png";
      viewLayout.AddChidren(sceneView.FLayoutView());
 
      //室外变化
      LogicView.SelectTypeView shiwaiView = new LogicView.SelectTypeView();
      shiwaiView.frameLayout.Y = sceneView.frameLayout.Bottom;
      shiwaiView.btnText.TextID = StringId.shiwaibainhua;
      shiwaiView.btnIcon.UnSelectedImagePath = "LogicIcon/changesinoutdoor.png";
 
      if (MainView.IsGatewayType)
      {
        viewLayout.AddChidren(shiwaiView.FLayoutView());
      }
 
      //地理围栏
      LogicView.SelectTypeView likiadaodaView = new LogicView.SelectTypeView();
      likiadaodaView.frameLayout.Y = shiwaiView.frameLayout.Bottom;
      likiadaodaView.btnText.TextID = StringId.likiadaoda;
      likiadaodaView.btnIcon.UnSelectedImagePath = "LogicIcon/location.png";
 
      if (MainView.IsGatewayType)
      {
        viewLayout.AddChidren(likiadaodaView.FLayoutView());
      }
 
      #endregion
 
      #region  所有点击事件
      //时间
      timeView.btnClick.MouseUpEventHandler += (sen, e) =>
      {
        TimeTpye timeTpye = new TimeTpye();
        MainPage.BasePageView.AddChidren(timeTpye);
        timeTpye.Show();
        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
      };
      //功能
      functionView.btnClick.MouseUpEventHandler += (sen, e) =>
      {
        FunTpye funTpye = new FunTpye();
        MainPage.BasePageView.AddChidren(funTpye);
        funTpye.Show(LogicMethod.condition_if);
        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
      };
      //场景点击事件
      sceneView.btnClick.MouseUpEventHandler += (sen, e) =>
      {
        SceneMethod();
      };
      //室外变化
      shiwaiView.btnClick.MouseUpEventHandler += (sen, e) =>
      {
        //if (string.IsNullOrEmpty(Entity.DB_ResidenceData.Instance.CurrentRegion.homeAddress))//.longitude == 0 && Entity.DB_ResidenceData.Instance.CurrentRegion.latitude == 0)
        //{
        //    new PublicAssmebly().TipMsg(StringId.tip, StringId.GatewayLocationInformationIsNotConfigured);
        //    return;
        //}
        Weather weather = new Weather();
        MainPage.BasePageView.AddChidren(weather);
        weather.Show();
        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
      };
 
      //地理围栏
      likiadaodaView.btnClick.MouseUpEventHandler += (sen, e) =>
      {
        LocationView(this, false);
      };
      #endregion
 
    }
 
    /// <summary>
    /// 添加场景
    /// </summary>
    public void SceneMethod()
    {
      var sceneList = LogicMethod.CurrLogicMethod.GetSceneList();
      List<string> nameList = new List<string>();
      for (int i = 0; i < sceneList.Count; i++)
      {
        var scene = sceneList[i];
        nameList.Add(scene.name);
      }
      PublicInterface publicInterface = new PublicInterface();
      publicInterface.FrameOrVv(this, nameList, new List<string> { }, StringId.addSceneLogic, (index) =>
      {
        var sceneSelecetd = sceneList[index];
        Input input = new Input();
        input.sid = sceneSelecetd.sid;
        input.condition_type = "10";
        Dictionary<string, string> dic = new Dictionary<string, string>();
        LogicMethod.CurrLogicMethod.dictionary(dic, "key", "scene");
        LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", "=");
        LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", "string");
        LogicMethod.CurrLogicMethod.dictionary(dic, "value", "on");
        input.condition.Add(dic);
        AddCondition(input);
        LogicMethod.CurrLogicMethod.RemoveAllView();
        AddLogic addLogic = new AddLogic();
        MainPage.BasePageView.AddChidren(addLogic);
        addLogic.Show();
        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
      });
    }
    /// <summary>
    /// 添加地理围栏
    /// </summary>
    /// <param name="flMain">Fl main.</param>
    /// <param name="edit">If set to <c>true</c> edit.</param>
    public void LocationView(FrameLayout flMain, bool edit)
    {
      string strname = "";
      ///通过调试宝给的经纬度<标准GPS>
      double latitude = Entity.DB_ResidenceData.Instance.CurrentRegion.latitude;//纬度
      double longitude = Entity.DB_ResidenceData.Instance.CurrentRegion.longitude;//经度
      LogicMethod.CurrLogicMethod.WGS84_to_GCJ02(Entity.DB_ResidenceData.Instance.CurrentRegion.longitude, Entity.DB_ResidenceData.Instance.CurrentRegion.latitude, out longitude, out latitude);
      int r = 500;//默认半径
      if (edit)
      {
        for (var i = 0; i < Logic.currlogic.input.Count; i++)
        {
          var input = Logic.currlogic.input[i];
          if (input.condition_type != "8")
          {
            continue;
          }
          if (input.condition[0]["value"] == "arrive")
          {
            //到达某地
            strname = Language.StringByID(StringId.daoda);
          }
          else
          {
            //离开地点
            strname = Language.StringByID(StringId.likai);
          }
          //再一次编辑地理围栏 <控件暂时不支持显示记录上一次的状态>
          if (!string.IsNullOrEmpty(input.geo_fence.latitude) && !string.IsNullOrEmpty(input.geo_fence.longitude))
          {
            ////纬度
            //var latitude1 = Convert.ToDouble(input.geo_fence.latitude);
            ////经度
            //var longitude1 = Convert.ToDouble(input.geo_fence.longitude);
            //半径
            r = int.Parse(input.geo_fence.radius);
            //WGS84坐标转高德坐标
            //LogicMethod.CurrLogicMethod.WGS84_to_GCJ02(longitude1, latitude1, out longitude, out latitude);
          }
        }
      }
      PublicInterface publicInterface = new PublicInterface();
      var list = publicInterface.GetViewList("地理围栏");
      publicInterface.SingleSelectionShow(flMain, list, Language.StringByID(StringId.likiadaoda), strname, (str) =>
       {
 
         string valueStr = "arrive";
         if (str == Language.StringByID(StringId.daoda))
         {
           //到达某地
           valueStr = "arrive";
         }
         else
         {
           //离开
           valueStr = "leave";
         }
 
#if __Android__
                 //申请定位权限
                 ((BaseActivity)Application.Activity).SetGPSLocationPermission((result1) =>
                  {
                    if (result1 == false) { return; }
 
                  //申请允许程序写入外部存储,如SD卡上写文件
                  ((BaseActivity)Application.Activity).SetPermission((result2) =>
                  {
                    if (result2 == false) { return; }
                       //读取电话状态权限
                       ((BaseActivity)Application.Activity).SetPermission((result3) =>
                       {
                         if (result3 == false) { return; }
                         //调用方法,跳转页面
                         Location(valueStr, strname, latitude, longitude, r);
                       }, "android.permission.READ_PHONE_STATE");
 
                  }, "android.permission.WRITE_EXTERNAL_STORAGE");
                  });
#endif
#if __IOS__
               //调用方法,跳转页面
                  Location(valueStr, strname, latitude, longitude, r);
#endif
       });
 
 
    }
    /// <summary>
    /// 地理围栏View
    /// </summary>
    /// <param name="valueStr">进入(arrive)或者离开(leave)</param>
    /// <param name="strname"></param>
    /// <param name="latitude">纬度</param>
    /// <param name="longitude">经度</param>
    /// <param name="r">半径(默认500米)</param>
    private void Location(string valueStr, string strname, double latitude, double longitude, int r)
    {
      if (r == 0)
      {
        //按道理说不会出现
        r = 500;
      }
      //调用方法,跳转页面
      GDMapKit.Show((mLatitude, mLongitude, mRadius, name) =>
      {
        //高德坐标转WGS84坐标(高德地图设置GPS)
        double out_lng, out_lat;
        LogicMethod.CurrLogicMethod.GCJ02_to_WGS84(mLongitude, mLatitude, out out_lng, out out_lat);
        Input input = new Input();
        input.sid = LogicMethod.CurrLogicMethod.NewSid();
        input.condition_type = "8";
        Dictionary<string, string> dic = new Dictionary<string, string>();
        LogicMethod.CurrLogicMethod.dictionary(dic, "key", "direction");
        LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", "=");
        LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", "string");
        LogicMethod.CurrLogicMethod.dictionary(dic, "value", valueStr);
        input.condition.Add(dic);
        //纬度
        input.geo_fence.latitude = out_lat.ToString();
        //经度
        input.geo_fence.longitude = out_lng.ToString();
        //半径<单位米>
        input.geo_fence.radius = mRadius.ToString();
        AddCondition(input);
        LogicMethod.CurrLogicMethod.RemoveAllView();
        AddLogic addLogic = new AddLogic();
        MainPage.BasePageView.AddChidren(addLogic);
        addLogic.Show();
        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
      }, strname, Language.StringByID(StringId.save), true, latitude, longitude, r);
    }
    /// <summary>
    /// 添加条件
    /// </summary>
    /// <param name="input"></param>
    private void AddCondition(Input input)
    {
      ///记录索引值
      int index = -1;
      for (var i = 0; i < Logic.currlogic.input.Count; i++)
      {
        var condition_type = Logic.currlogic.input[i].condition_type;
        if (condition_type == "10" || condition_type == "8")
        {
          //支持场景=10,地理围栏=8
          ///找到标记索引,退出循环体
          index = i;
          break;
        }
      }
      if (index != -1)
      {
        //移除旧数据
        Logic.currlogic.input.RemoveAt(index);
        //新数据插入旧数据的位置
        Logic.currlogic.input.Insert(index, input);
      }
      else
      {
        Logic.currlogic.input.Add(input);
      }
    }
  }
}