Android Open Source - smsgateway-android Status Text View






From Project

Back to project page smsgateway-android.

License

The source code is released under:

GNU General Public License

If you think the Android project smsgateway-android 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.nubgames.smsgateway;
/*ww w. ja  v a 2  s . c  o m*/
import java.util.HashMap;
import java.util.LinkedList;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.TextView;

public class StatusTextView extends TextView implements Status {
    public LinkedList<Button> disabledOnDisconnect = new LinkedList<Button>();
    public LinkedList<Button> disabledOnConnect = new LinkedList<Button>();

    public StatusTextView(Context context) {
        this(context, null);
    }

    public StatusTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StatusTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        // Build a text HashMap lookup table.
        // Note: need context to getText, and it's here in the constructor.
        texts.put(FAILED_AUTH,    (String) context.getText(R.string.status_failed_auth));
        texts.put(FAILED_CONNECT, (String) context.getText(R.string.status_failed_connect));
        texts.put(NOT_RUNNING,    (String) context.getText(R.string.status_not_running));
        texts.put(DISCONNECTED,   (String) context.getText(R.string.status_disconnected));
        texts.put(CONNECTING,     (String) context.getText(R.string.status_connecting));
        texts.put(AUTHORIZING,    (String) context.getText(R.string.status_authorizing));
        texts.put(CONNECTED,      (String) context.getText(R.string.status_connected));
        texts.put(RETRYING,       (String) context.getText(R.string.status_retrying));

        // Build a color HashMap lookup table.
        // Note: RED is left as an exercise using the isCritical method.
        colors.put(NOT_RUNNING,   Color.GRAY);
        colors.put(CONNECTING,    Color.YELLOW);
        colors.put(AUTHORIZING,   Color.YELLOW);
        colors.put(CONNECTED,     Color.GREEN);
        colors.put(RETRYING,      Color.YELLOW);
    }

    public boolean isCritical(int flag) {
        return flag <= DISCONNECTED;
    }

    public void update(int flag) {
        // Set default text color for critical flags.
        if (isCritical(flag)) {
            setTextColor(Color.RED);
            disconnected();
        }
        else {
            connecting();
        }

        // Set text.
        String text = texts.get(flag);
        if (text == null) {
            text = "";
        }
        setText(text);

        // Set text color.
        if (colors.containsKey(flag)) {
            setTextColor(colors.get(flag));
        }
    }

    private void disconnected() {
        swapButtons(disabledOnDisconnect, disabledOnConnect);
    }

    private void connecting() {
        swapButtons(disabledOnConnect, disabledOnDisconnect);
    }

    private void swapButtons(LinkedList<Button> disable, LinkedList<Button> enable) {
        for(Button button : disable) {
            button.setEnabled(false);
        }
        for(Button button : enable) {
            button.setEnabled(true);
        }
    }
    
    private HashMap<Integer, String>  texts  = new HashMap<Integer, String>();
    private HashMap<Integer, Integer> colors = new HashMap<Integer, Integer>();
}




Java Source Code List

com.calclab.emite.core.client.EmiteCoreModule.java
com.calclab.emite.core.client.bosh.BoshConnection.java
com.calclab.emite.core.client.bosh.BoshSettings.java
com.calclab.emite.core.client.bosh.Connection.java
com.calclab.emite.core.client.bosh.StreamSettings.java
com.calclab.emite.core.client.packet.AbstractPacket.java
com.calclab.emite.core.client.packet.DelegatedPacket.java
com.calclab.emite.core.client.packet.IPacket.java
com.calclab.emite.core.client.packet.MatcherFactory.java
com.calclab.emite.core.client.packet.NoPacket.java
com.calclab.emite.core.client.packet.PacketMatcher.java
com.calclab.emite.core.client.packet.PacketRenderer.java
com.calclab.emite.core.client.packet.PacketTestSuite.java
com.calclab.emite.core.client.packet.Packet.java
com.calclab.emite.core.client.packet.TextPacket.java
com.calclab.emite.core.client.packet.TextUtils.java
com.calclab.emite.core.client.packet.android.AndroidPacket.java
com.calclab.emite.core.client.services.ConnectorCallback.java
com.calclab.emite.core.client.services.ConnectorException.java
com.calclab.emite.core.client.services.ScheduledAction.java
com.calclab.emite.core.client.services.Services.java
com.calclab.emite.core.client.services.android.AndroidConnector.java
com.calclab.emite.core.client.services.android.AndroidScheduler.java
com.calclab.emite.core.client.services.android.AndroidServices.java
com.calclab.emite.core.client.services.android.AndroidXMLService.java
com.calclab.emite.core.client.xmpp.resource.ResourceBindingManager.java
com.calclab.emite.core.client.xmpp.sasl.AuthorizationTransaction.java
com.calclab.emite.core.client.xmpp.sasl.Base64Coder.java
com.calclab.emite.core.client.xmpp.sasl.SASLManager.java
com.calclab.emite.core.client.xmpp.session.AbstractSession.java
com.calclab.emite.core.client.xmpp.session.IMSessionManager.java
com.calclab.emite.core.client.xmpp.session.IQManager.java
com.calclab.emite.core.client.xmpp.session.SessionComponent.java
com.calclab.emite.core.client.xmpp.session.SessionImpl.java
com.calclab.emite.core.client.xmpp.session.SessionReady.java
com.calclab.emite.core.client.xmpp.session.Session.java
com.calclab.emite.core.client.xmpp.stanzas.BasicStanza.java
com.calclab.emite.core.client.xmpp.stanzas.IQ.java
com.calclab.emite.core.client.xmpp.stanzas.Message.java
com.calclab.emite.core.client.xmpp.stanzas.Presence.java
com.calclab.emite.core.client.xmpp.stanzas.Stanza.java
com.calclab.emite.core.client.xmpp.stanzas.XmppURICache.java
com.calclab.emite.core.client.xmpp.stanzas.XmppURI.java
com.calclab.emite.im.client.InstantMessagingModule.java
com.calclab.emite.im.client.chat.AbstractChat.java
com.calclab.emite.im.client.chat.ChatManager.java
com.calclab.emite.im.client.chat.Chat.java
com.calclab.emite.im.client.chat.PairChatManager.java
com.calclab.emite.im.client.chat.PairChat.java
com.calclab.emite.im.client.presence.PresenceManagerImpl.java
com.calclab.emite.im.client.presence.PresenceManager.java
com.calclab.emite.im.client.roster.RosterImpl.java
com.calclab.emite.im.client.roster.RosterItem.java
com.calclab.emite.im.client.roster.Roster.java
com.calclab.emite.im.client.roster.SubscriptionManagerImpl.java
com.calclab.emite.im.client.roster.SubscriptionManager.java
com.calclab.emite.im.client.roster.SubscriptionState.java
com.calclab.suco.client.SucoCoreModule.java
com.calclab.suco.client.SucoFactory.java
com.calclab.suco.client.Suco.java
com.calclab.suco.client.events.Event0.java
com.calclab.suco.client.events.Event2.java
com.calclab.suco.client.events.Event.java
com.calclab.suco.client.events.Listener0.java
com.calclab.suco.client.events.Listener2.java
com.calclab.suco.client.events.Listener.java
com.calclab.suco.client.ioc.Container.java
com.calclab.suco.client.ioc.Decorator.java
com.calclab.suco.client.ioc.HashMapContainer.java
com.calclab.suco.client.ioc.Provider.java
com.calclab.suco.client.ioc.decorator.Chain.java
com.calclab.suco.client.ioc.decorator.GroupedSingleton.java
com.calclab.suco.client.ioc.decorator.NoDecoration.java
com.calclab.suco.client.ioc.decorator.ProviderCollection.java
com.calclab.suco.client.ioc.decorator.Singleton.java
com.calclab.suco.client.ioc.module.AbstractModule.java
com.calclab.suco.client.ioc.module.Factory.java
com.calclab.suco.client.ioc.module.ModuleBuilderImpl.java
com.calclab.suco.client.ioc.module.ModuleBuilder.java
com.calclab.suco.client.ioc.module.SucoModule.java
com.calclab.suco.client.log.Logger.java
com.calclab.suco.client.signal.Signal0.java
com.calclab.suco.client.signal.Signal2.java
com.calclab.suco.client.signal.Signal.java
com.calclab.suco.client.signal.Slot0.java
com.calclab.suco.client.signal.Slot2.java
com.calclab.suco.client.signal.Slot.java
com.nubgames.smsgateway.BOSHConnection.java
com.nubgames.smsgateway.BootCompleted.java
com.nubgames.smsgateway.Password.java
com.nubgames.smsgateway.SMSGateway.java
com.nubgames.smsgateway.SMSReceiver.java
com.nubgames.smsgateway.Settings.java
com.nubgames.smsgateway.StatusTextView.java
com.nubgames.smsgateway.Status.java
com.nubgames.smsgateway.TextRouter.java