PopupActivity.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. package kr.co.icontrols.wallpadoutmoderun;
  2. import com.artncore.WallPadDataMgr.WallpadDeviceSet;
  3. import com.artncore.WallPadDataMgr.WallpadStatusData;
  4. import com.artncore.wallpadapi.WallPadAPI;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.os.Bundle;
  8. import android.os.Handler;
  9. import android.os.Message;
  10. import android.util.Log;
  11. import android.view.KeyEvent;
  12. import android.view.MotionEvent;
  13. import android.view.View;
  14. import android.widget.RelativeLayout;
  15. import com.util.LogUtil;
  16. import kr.co.icontrols.wallpadoutmoderun.declare.Common;
  17. import kr.co.icontrols.wallpadoutmoderun.declare.ID;
  18. import kr.co.icontrols.wallpadoutmoderun.screen.PopupInputPw;
  19. import kr.co.icontrols.wallpadsupport.WpadActivity;
  20. import kr.co.icontrols.wallpadsupport.WpadScale;
  21. /**
  22. * @description
  23. * 월패드 [우리집제어] 팝업화면 관리자 이다.<br>
  24. */
  25. public class PopupActivity extends WpadActivity
  26. {
  27. private final String TAG = "PopupActivity";
  28. private final boolean DEBUG_LOG_ON = true;
  29. private void DebugLogOutput(String s) { if(DEBUG_LOG_ON) Log.d(TAG, s); }
  30. // =================================================================================================
  31. // [[ Declaration ]] region
  32. // =================================================================================================
  33. private static Context mContext = null;
  34. public static Context getContext() { return mContext; }
  35. private WallPadAPI wpapi = null;
  36. private int OPERATION_MODE = Common.MODE;
  37. // Layout
  38. private RelativeLayout AllLayout;
  39. // CurrentScreenId & mCurrentStyle
  40. private int mCurrentScreenId = -1;
  41. private int mCurrentStyle = -1;
  42. private int mTempCurrentScreenId = -1;
  43. // CreateComplete
  44. private static boolean mCreateComplete = false;
  45. protected static boolean getCreateComplete() { return mCreateComplete; }
  46. protected static void setCreateComplete(boolean set) { mCreateComplete = set; }
  47. // Screen
  48. private PopupInputPw mPopupInputPw = null;
  49. private WallpadStatusData wdb = null;
  50. public WallpadStatusData GetDBObj()
  51. {
  52. return wdb;
  53. }
  54. /**
  55. * Static Variables 초기화<br>
  56. * onCreate 도입부, onDestroy 종료시 삽입한다.
  57. */
  58. private void setStaticVariablesInit()
  59. {
  60. mContext = null;
  61. mCreateComplete = false;
  62. if(AllLayout != null)
  63. {
  64. AllLayout.removeAllViews();
  65. AllLayout = null;
  66. }
  67. }
  68. // =================================================================================================
  69. // [[ Activity Life Cycle ]] region
  70. // =================================================================================================
  71. /**
  72. * Activity Constructors
  73. */
  74. @Override
  75. protected void onCreate(Bundle savedInstanceState)
  76. {
  77. Log.i(TAG, "-------------------------------------------------------------");
  78. Log.i(TAG, "------------------ [START - PopupActivity] ------------------");
  79. Log.i(TAG, "-------------------------------------------------------------");
  80. super.onCreate(savedInstanceState);
  81. // 1. 변수 초기화
  82. DebugLogOutput("[Create] - Step1 : Data Create");
  83. setStaticVariablesInit();
  84. mContext = this;
  85. // 2. 자동 종료 셋팅
  86. DebugLogOutput("[Create] - Step2 : Auto Finish Setting");
  87. // 3. API 호출
  88. DebugLogOutput("[Create] - Step3 : API Call");
  89. if(OPERATION_MODE == Common.MODE_NOMAL)
  90. {
  91. Log.d(TAG, "OperationMode = MODE_NOMAL");
  92. wpapi = new WallPadAPI(this);
  93. }
  94. else if(OPERATION_MODE == Common.MODE_BUSINESS_SAMPLE)
  95. {
  96. Log.d(TAG, "OperationMode = MODE_BUSINESS_SAMPLE");
  97. }
  98. try { wdb = new WallpadStatusData(this); }
  99. catch (RuntimeException re) {
  100. LogUtil.errorLogInfo("", TAG, re);
  101. }
  102. catch (Exception e) { Log.e(TAG, "[ExceptionError] - onCreate->WallpadStatusData Create : " + e); }
  103. // 4. Layout registration
  104. DebugLogOutput("[Create] - Step4 : Layout registration");
  105. // 4-1. mainLayout
  106. AllLayout = new RelativeLayout(this);
  107. AllLayout.setId(ID.popup.layout.ALL);
  108. super.setAllLayoutRegistration(AllLayout);
  109. // 5. Start ScreenId Data Get
  110. Intent intent = getIntent();
  111. int ScreenId = intent.getIntExtra("ScreenId", -1);
  112. Log.d(TAG, "ScreenId = " + ScreenId);
  113. if(ScreenId < 0)
  114. {
  115. Log.e(TAG, "[Error] ScreenId Out of range (" + ScreenId + ")");
  116. finish();
  117. }
  118. else
  119. {
  120. // 6. First Show Layout Find
  121. mCreateComplete = true;
  122. // if(OPERATION_MODE == Common.MODE_NOMAL)
  123. // {
  124. // mTempCurrentScreenId = ScreenId;
  125. // //mWallPadApiCheckHandler.sendEmptyMessage(0);
  126. // }
  127. // else
  128. {
  129. if(setChangeScreen(ScreenId, false) == false)
  130. {
  131. Log.e(TAG, "[Error] setChangeScreen false...");
  132. finish();
  133. }
  134. }
  135. }
  136. Log.i(TAG, "End onCreate -------------------------------------------------");
  137. }
  138. /**
  139. * (임시코드) WallPadAPI 초기생성시 Connect 에 시간이 걸리며, <br>
  140. * WallPadAPI 초기화후 바로 Get_GasValveController 등을 사용하여 API 를 가져올수 없기에, <br>
  141. * 본 딜레이 코드를 임시로 적용한다.
  142. */
  143. // @SuppressLint("HandlerLeak")
  144. // protected Handler mWallPadApiCheckHandler = new Handler()
  145. // {
  146. // @SuppressLint("HandlerLeak")
  147. // @Override
  148. // public void handleMessage(Message msg)
  149. // {
  150. // if(msg.what == 0)
  151. // {
  152. // if(wpapi != null)
  153. // {
  154. // if(wpapi.Check_Connect()) mWallPadApiCheckHandler.sendEmptyMessageDelayed(1, 10);
  155. // else mWallPadApiCheckHandler.sendEmptyMessageDelayed(0, 10);
  156. // }
  157. // }
  158. // else if(msg.what == 1)
  159. // {
  160. // setChangeScreen(mTempCurrentScreenId, false);
  161. // }
  162. // }
  163. // };
  164. /**
  165. * onDestroy
  166. */
  167. @Override
  168. protected void onDestroy()
  169. {
  170. setChangeScreen(mCurrentScreenId, true);
  171. if(wdb != null) wdb.closeDB();
  172. setStaticVariablesInit();
  173. MainActivity.setPopupActivityRun(false);
  174. mCreateComplete = false;
  175. super.onDestroy();
  176. Log.i(TAG, "*************************************************************");
  177. Log.i(TAG, "****************** [END - PopupActivity] ******************");
  178. Log.i(TAG, "*************************************************************");
  179. }
  180. /**
  181. * onResume
  182. */
  183. @Override
  184. protected void onResume() {
  185. super.onResume();
  186. if(wpapi != null) wpapi.Resume();
  187. Log.d(TAG, "@@@@@@@@ [onResume] @@@@@@@@");
  188. }
  189. /**
  190. * onPause
  191. */
  192. @Override
  193. protected void onPause() {
  194. super.onPause();
  195. if(wpapi != null) wpapi.Pause();
  196. Log.d(TAG, "@@@@@@@@ [onPause] @@@@@@@@");
  197. }
  198. /* ================================================================================================
  199. * [BroadcastReceiver] Section
  200. ================================================================================================ */
  201. /**
  202. * BroadcastReceiver.onReceive for [WpadActivity]
  203. */
  204. @Override
  205. protected void onBrReceive(Intent intent)
  206. {
  207. super.onBrReceive(intent);
  208. Log.d(TAG, "Receive alert BR " + intent.getAction());
  209. }
  210. /* ================================================================================================
  211. * [Touch & Key Event] Section
  212. ================================================================================================ */
  213. /**
  214. * TouchEvent for [WpadActivity]
  215. */
  216. @Override
  217. protected void onTouchEvent(View v, MotionEvent event) {
  218. super.onTouchEvent(v, event);
  219. }
  220. /**
  221. * H/W Key Event
  222. */
  223. @Override
  224. public boolean onKeyDown(int keyCode, KeyEvent event) {
  225. DebugLogOutput("onKeyDown - " + " / keyCode : " + keyCode + " / Action : " + event.getAction());
  226. return super.onKeyDown(keyCode, event);
  227. }
  228. /* ================================================================================================
  229. * [Screen] Section
  230. ================================================================================================ */
  231. /**
  232. * Screen 에서 Screen 변경을 요청할 경우 호출된다.<br>
  233. * Override 사용하여 Screen 변경을 처리한다.<br>
  234. *
  235. * @param nScreenId - 변경할 Screen ID
  236. * @return (boolean) true : 성공, false : 실패
  237. */
  238. @Override
  239. protected boolean onChangeScreen(int nScreenId) {
  240. super.onChangeScreen(nScreenId);
  241. return setChangeScreen(nScreenId, false);
  242. }
  243. /**
  244. * Screen 등록자<br>
  245. * ScreenLayout 에 현재 Screen 을 삭제하고, 새로운 Screen 을 등록시킨다.
  246. *
  247. * @param nScreenId - 변경할 Screen ID
  248. * @param OnlyRemove - 현재 Screen 을 삭제만 할 경우 (onDestroy 에서 사용)
  249. * @return (boolean) true : 성공, false : 실패
  250. */
  251. private boolean setChangeScreen(int nScreenId, boolean OnlyRemove)
  252. {
  253. DebugLogOutput("setChangeLayout - " + "CurrentScreenId : " + mCurrentScreenId
  254. + " / NextLayoutId : " + nScreenId + " / OnlyRemove : " + OnlyRemove);
  255. if(getCreateComplete() == false)
  256. {
  257. Log.w(TAG, "[Waring] setChangeLayout - CreateComplete is false !!!");
  258. return false;
  259. }
  260. //boolean remove = false;
  261. if(mCurrentScreenId > 0)
  262. {
  263. //remove = true;
  264. AllLayout.removeAllViews();
  265. super.setCurrentScreen(null);
  266. }
  267. if(OnlyRemove) return true;
  268. // 1. 새로운 Layout 표시
  269. mCurrentScreenId = nScreenId;
  270. int Style = Common.POPUP_STYLE_NOMAL;
  271. int FinishTime = Common.FINISH_TIME_POPUP_NORMAL_SEC;
  272. boolean FinshOutSide = true;
  273. try
  274. {
  275. switch(nScreenId)
  276. {
  277. case ID.screen.InputPwPopupScreen:
  278. mPopupInputPw = new PopupInputPw(mContext, AllLayout);
  279. super.setCurrentScreen(mPopupInputPw);
  280. break;
  281. default:
  282. Log.e(TAG, "[Error] setChangeLayout - OnlyRemove Input ID Not found!!!");
  283. return false;
  284. }
  285. }
  286. catch (RuntimeException re) {
  287. LogUtil.errorLogInfo("", TAG, re);
  288. mCurrentScreenId = -1;
  289. return false;
  290. }
  291. catch (Exception e)
  292. {
  293. Log.e(TAG, "[ExceptionError] - setChangeScreen->Screen Create : " + e);
  294. mCurrentScreenId = -1;
  295. return false;
  296. }
  297. this.setFinishOnTouchOutside(FinshOutSide);
  298. // 2. Style 변경시 WindowReSize
  299. if(mCurrentStyle != Style)
  300. {
  301. int ScreenWidth = WpadScale.getWidth(Common.getPopupScreenSize_W(Style));
  302. int ScreenHigh = WpadScale.getHeight(Common.getPopupScreenSize_H(Style));
  303. if( (ScreenWidth <= 0) || (ScreenHigh <= 0) )
  304. {
  305. Log.e(TAG, "[Error] Style UnDefined !!! (" + Style + ")");
  306. return false;
  307. }
  308. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ScreenWidth, ScreenHigh);
  309. AllLayout.setLayoutParams(params);
  310. setContentView(AllLayout);
  311. super.WindowReSize(ScreenWidth, ScreenHigh, false);
  312. mCurrentStyle = Style;
  313. }
  314. // 3. FinishTimer Setting
  315. if(Common.FINISH_TIME_ENABLE)
  316. super.setFinishTimerCreate(FinishTime);
  317. mCurrentScreenId = nScreenId;
  318. return true;
  319. }
  320. // 화면 매뉴얼
  321. private static int mCurrentManualScreenId = -1;
  322. private static boolean ManualActivityRun = false;
  323. public static boolean getManualActivityRun() {
  324. return ManualActivityRun;
  325. }
  326. public static void setManualActivityRun(boolean run) {
  327. ManualActivityRun = run;
  328. if (!ManualActivityRun) resetCurrentManualScreenID();
  329. }
  330. public boolean StartManual(int screenId) {
  331. Log.d(TAG, "[StartManual] ScreenId [" + screenId +"], mCurrentManualScreenId [" + mCurrentManualScreenId + "]" );
  332. if (getManualActivityRun()) {
  333. mCurrentManualScreenId = screenId;
  334. return ((WpadActivity)(ManualActivity.getContext())).ChangeScreen(screenId);
  335. } else {
  336. if (mCurrentManualScreenId == screenId) return false;
  337. mCurrentManualScreenId = screenId;
  338. setManualActivityRun(true);
  339. Intent intent = new Intent(mContext, ManualActivity.class);
  340. intent.putExtra("ScreenId", screenId);
  341. /*if(mCurrentScreenId ==ID.screen.HeatingV2PopupScreen )
  342. {
  343. intent.putExtra("HeatPopInfo", heatingV2PopupScreen.HeatPopManual_Str);
  344. }
  345. else if(mCurrentScreenId ==ID.screen.LightEtcEachPopupRoomScreen )
  346. {
  347. intent.putExtra("EtcMultiPopInfo", lightEtcEachPopupRoomScreen.MultiLightCount);
  348. }*/
  349. overridePendingTransition(0, 0);
  350. startActivityForResult(intent, 0);
  351. return true;
  352. }
  353. }
  354. public static void resetCurrentManualScreenID() {
  355. mCurrentManualScreenId = -1;
  356. }
  357. public boolean GetManualUse() {
  358. WallpadDeviceSet devSet = new WallpadDeviceSet(this.getContext());
  359. String[] DBinfo = devSet.GetSettingData("매뉴얼");
  360. devSet.closeDB();
  361. if (DBinfo != null) {
  362. if (DBinfo[1].indexOf("사용함") > 0) {
  363. Log.d(TAG, "[GetManualUse] Use Manual");
  364. return true;
  365. } else {
  366. Log.d(TAG, "[GetManualUse] Not Use Manual");
  367. return false;
  368. }
  369. } else {
  370. Log.w(TAG, "[GetManualUse] DBInfo is null");
  371. return false;
  372. }
  373. }
  374. public static boolean getManualUse() {
  375. WallpadDeviceSet devSet = new WallpadDeviceSet(getContext());
  376. String[] DBinfo = devSet.GetSettingData("매뉴얼");
  377. devSet.closeDB();
  378. if (DBinfo != null) {
  379. if (DBinfo[1].indexOf("사용함") > 0) {
  380. Log.d("PopupActivity", "[getManualUse] Use Manual");
  381. return true;
  382. } else {
  383. Log.d("PopupActivity", "[getManualUse] Not Use Manual");
  384. return false;
  385. }
  386. } else {
  387. Log.w("PopupActivity", "[getManualUse] DBInfo is null");
  388. return false;
  389. }
  390. }
  391. int nHANDLER_SCREEN_FINISH = 100;
  392. protected Handler PopupScreenHandler = new Handler() {
  393. @Override
  394. public void handleMessage(Message msg) {
  395. if (msg.what == nHANDLER_SCREEN_FINISH) {
  396. finishPopup();
  397. }
  398. }
  399. };
  400. public void sendHandlerMsgDelayed(int what, int arg1, int arg2, long delay) {
  401. try {
  402. Log.d(TAG, "[sendHandlerMsgDelayed] what [" + what + "], arg1 [" + arg1 + "], arg2 [" + arg2 + "], delay [" + delay + "]");
  403. Message HandleMsg = PopupScreenHandler.obtainMessage();
  404. HandleMsg.what = what;
  405. HandleMsg.arg1 = arg1;
  406. HandleMsg.arg2 = arg2;
  407. PopupScreenHandler.sendMessageDelayed(HandleMsg, delay);
  408. } catch (RuntimeException re) {
  409. LogUtil.errorLogInfo("", TAG, re);
  410. }
  411. catch (Exception e) {
  412. Log.e(TAG, "[Exception] sendHandlerMsgDelayed(msg)");
  413. //e.printStackTrace();
  414. LogUtil.errorLogInfo("", TAG, e);
  415. }
  416. }
  417. private void finishPopup() {
  418. try {
  419. super.finish();
  420. } catch (RuntimeException re) {
  421. LogUtil.errorLogInfo("", TAG, re);
  422. }
  423. catch (Exception e) {
  424. Log.e(TAG, "[Exception] finishPopup()");
  425. //e.printStackTrace();
  426. LogUtil.errorLogInfo("", TAG, e);
  427. }
  428. }
  429. }