Android Open Source - twawm2 U I Act






From Project

Back to project page twawm2.

License

The source code is released under:

Copyright (c) 2014, afnf All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistr...

If you think the Android project twawm2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.appspot.afnf4199ga.twawm.app;
/*from   w  ww  .j av a  2s  .  c  om*/
import android.os.Handler;
import android.widget.Toast;

import com.appspot.afnf4199ga.twawm.router.RouterInfo.COM_TYPE;
import com.appspot.afnf4199ga.utils.AndroidUtils;
import com.appspot.afnf4199ga.utils.Logger;

public class UIAct extends Handler {
    private static UIAct instance = new UIAct();
    private static MainActivity parent;

    private UIAct() {
    }

    public static void init(MainActivity parent) {
        UIAct.parent = parent;
    }

    public static void destroy() {
        UIAct.parent = null;
    }

    static class UpdateActivityButtonRunnable implements Runnable {

        private Boolean enableRouterToggle;
        private Boolean enableWifiToggle;
        private Boolean wifiEnabled;
        private Boolean suppCompleted;
        private Boolean ecoCharge;
        private COM_TYPE comSetting;
        private Boolean wifiSpot;

        public UpdateActivityButtonRunnable(Boolean enableRouterToggle, Boolean enableWifiToggle, Boolean wifiEnabled,
                Boolean suppCompleted, Boolean ecoCharge, COM_TYPE comSetting, Boolean wifiSpot) {
            this.enableRouterToggle = enableRouterToggle;
            this.enableWifiToggle = enableWifiToggle;
            this.wifiEnabled = wifiEnabled;
            this.suppCompleted = suppCompleted;
            this.ecoCharge = ecoCharge;
            this.comSetting = comSetting;
            this.wifiSpot = wifiSpot;
        }

        public void run() {
            if (parent != null) {
                parent.uiactSetRouterToggleButton(enableRouterToggle, suppCompleted);
                parent.uiactSetWifiToggleButton(enableWifiToggle, wifiEnabled);
                parent.uiactSetEcoChargeToggleButton(suppCompleted, ecoCharge);
                parent.uiactSetNadToggleButton(suppCompleted, comSetting, wifiSpot);
            }
        }
    }

    public static void postActivityButton(Boolean enableRouterToggle, Boolean enableWifiToggle, Boolean wifiEnabled,
            Boolean suppCompleted, Boolean ecoCharge, COM_TYPE comSetting, Boolean wifiSpot) {
        if (parent != null) {
            if (AndroidUtils.isUIThread(parent)) {
                parent.uiactSetRouterToggleButton(enableRouterToggle, suppCompleted);
                parent.uiactSetWifiToggleButton(enableWifiToggle, wifiEnabled);
                parent.uiactSetEcoChargeToggleButton(suppCompleted, ecoCharge);
                parent.uiactSetNadToggleButton(suppCompleted, comSetting, wifiSpot);
            }
            else {
                instance.post(new UpdateActivityButtonRunnable(enableRouterToggle, enableWifiToggle, wifiEnabled, suppCompleted,
                        ecoCharge, comSetting, wifiSpot));
            }
        }
    }

    static class UpdateActivityInfoRunnable implements Runnable {

        private Integer wdImageId;
        private String wdText;
        private String trigger;
        private String state;

        public UpdateActivityInfoRunnable(Integer wdImageId, String wdText, String trigger, String state) {
            this.wdImageId = wdImageId;
            this.wdText = wdText;
            this.trigger = trigger;
            this.state = state;
        }

        public void run() {
            if (parent != null) {
                parent.uiactSwitchImage(wdImageId);
                parent.uiactSetMessage(wdText, trigger, state);
            }
        }
    }

    public static void postActivityInfo(Integer wdImageId, String wdText, String trigger, String state) {
        if (parent != null) {
            if (AndroidUtils.isUIThread(parent)) {
                parent.uiactSwitchImage(wdImageId);
                parent.uiactSetMessage(wdText, trigger, state);
            }
            else {
                instance.post(new UpdateActivityInfoRunnable(wdImageId, wdText, trigger, state));
            }
        }
    }

    static class EnableWorkingToggleButtonRunnable implements Runnable {
        public void run() {
            if (parent != null) {
                parent.uiactToggleWorkingToggleButton(true);
            }
        }
    }

    public static void postDelayedEnableWorkingToggleButton() {
        if (parent != null) {
            instance.postDelayed(new EnableWorkingToggleButtonRunnable(), 2000);
        }
    }

    static class EnableComModeToggleButtonRunnable implements Runnable {
        public void run() {
            if (parent != null) {
                parent.uiactToggleComModeToggleButton(true);
            }
        }
    }

    public static void postDelayedEnableComModeToggleButton() {
        if (parent != null) {
            instance.postDelayed(new EnableComModeToggleButtonRunnable(), 8000);
        }
    }

    static class EnableWifiSpotToggleButtonRunnable implements Runnable {
        public void run() {
            if (parent != null) {
                parent.uiactToggleWifiSpotToggleButton(true);
            }
        }
    }

    public static void postDelayedEnableWifiSpotToggleButton() {
        if (parent != null) {
            instance.postDelayed(new EnableWifiSpotToggleButtonRunnable(), 8000);
        }
    }

    static class ToastRunnable implements Runnable {
        private String msg;

        public ToastRunnable(String msg) {
            this.msg = msg;
        }

        @Override
        public void run() {
            try {
                Toast.makeText(parent, msg, Toast.LENGTH_LONG).show();
            }
            catch (Throwable e) {
                Logger.w("toast error", e);
            }
        }
    }

    public static void toast(String msg) {
        if (parent != null) {
            instance.post(new ToastRunnable(msg));
        }
    }
}




Java Source Code List

com.appspot.afnf4199ga.twawm.BluetoothHelper.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.HostnameListTest.java
com.appspot.afnf4199ga.twawm.HostnameList.java
com.appspot.afnf4199ga.twawm.IconSelectorTest.java
com.appspot.afnf4199ga.twawm.IconSelector.java
com.appspot.afnf4199ga.twawm.OnlineChecker.java
com.appspot.afnf4199ga.twawm.StateMachineTest.java
com.appspot.afnf4199ga.twawm.StateMachine.java
com.appspot.afnf4199ga.twawm.TwawmUtils.java
com.appspot.afnf4199ga.twawm.app.BackgroundServiceTest.java
com.appspot.afnf4199ga.twawm.app.BackgroundService.java
com.appspot.afnf4199ga.twawm.app.DefaultWidgetProvider.java
com.appspot.afnf4199ga.twawm.app.InfoActivity.java
com.appspot.afnf4199ga.twawm.app.InitialConfigurationWizardActivity.java
com.appspot.afnf4199ga.twawm.app.LogSendActivity.java
com.appspot.afnf4199ga.twawm.app.MainActivity.java
com.appspot.afnf4199ga.twawm.app.MainApp.java
com.appspot.afnf4199ga.twawm.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.twawm.app.NetworkSwitcher.java
com.appspot.afnf4199ga.twawm.app.StaticIntentListener.java
com.appspot.afnf4199ga.twawm.app.UIAct.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivityTest.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivity.java
com.appspot.afnf4199ga.twawm.ctl.CwacTouchListView.java
com.appspot.afnf4199ga.twawm.ctl.ListItem.java
com.appspot.afnf4199ga.twawm.router.EcoModeControlTest.java
com.appspot.afnf4199ga.twawm.router.EcoModeControl.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.MyHttpClientTest.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttpTest.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.utils.AndroidUtilsTest.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.MyStringUtlisTest.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyTestUtils.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.wmgraph.app.FetchThread.java
com.appspot.afnf4199ga.wmgraph.app.InetLookupThread.java
com.appspot.afnf4199ga.wmgraph.app.InfoActivity.java
com.appspot.afnf4199ga.wmgraph.app.MainActivity.java
com.appspot.afnf4199ga.wmgraph.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.wmgraph.app.UIAct.java
net.afnf.and.twawm2.DexmakerInstrumentationTestCase.java
net.afnf.and.twawm2.MyInstrumentationTestRunner.java