Android Open Source - savemypics C Event Bus






From Project

Back to project page savemypics.

License

The source code is released under:

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

If you think the Android project savemypics 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 org.savemypics.android.event;
//  w ww .j av a  2 s . c  om
import android.os.Handler;
import android.os.Message;
import android.util.SparseArray;
import java.util.ArrayList;
import java.util.List;
import org.savemypics.android.util.CUtils;

public final class CEventBus
{
    public final static int EVENT_EXCEPTION = 1001;
    public final static int EVENT_SNAPFISH_LOGIN = 1002;
    public final static int EVENT_REQUEST_TOKEN = 1003;
    public final static int EVENT_ACCESS_TOKEN = 1004;
    public final static int EVENT_SYNC_INFO = 1005;
    public final static int EVENT_SYNC_PROGRESS = 1006;
    public final static int EVENT_BITMAP_LOADED = 1007;

    public interface Unhandled
    { public void onUnhandled(Message m); }

    public final static void subscribe(Handler handler, int what)
    {
        synchronized (s_map) {
            List<Handler> cur = s_map.get(what);
            if (cur == null) {
                cur = new ArrayList<Handler>();
                s_map.put(what, cur);
            }
            cur.add(handler);
        }
    }

    public final static void unsubscribe(Handler handler, int what)
    {
        synchronized (s_map) {
            List<Handler> cur = s_map.get(what);
            if (cur != null) {
                cur.remove(handler);
            }
            handler.removeMessages(what);
        }
    }

    public final static void publish(Message m)
    { publish(m, null); }

    public final static void publish(Message m, Unhandled uh)
    {
        synchronized (s_map) {
            List<Handler> targets = s_map.get(m.what);
            if ((targets == null) || (targets.size() == 0)) {
                doUnhandled(m, uh);
                return;
            }
            for (Handler h: targets) {
                Message tm = Message.obtain(h);
                tm.what = m.what;
                tm.obj = m.obj;
                h.sendMessage(tm);
            }
        }
    }

    private final static void doUnhandled(Message m, Unhandled uh)
    {
        if (uh == null) {
            CUtils.LOGD
                (TAG, "Unhandled message: what="+m.what+",type="+m.obj);
            return;
        }
        uh.onUnhandled(m);
    }

    private final static SparseArray<List<Handler>> s_map =
        new SparseArray<List<Handler>>();
    private final static String TAG = CUtils.makeLogTag(CEventBus.class);
}




Java Source Code List

android.util.Base64.java
org.savemypics.android.activity.AActivity.java
org.savemypics.android.activity.ABaseSettingsActivity.java
org.savemypics.android.activity.CAccountInfoListAdapter.java
org.savemypics.android.activity.CFlickrSettingsActivity.java
org.savemypics.android.activity.CSnapfishSettingsActivity.java
org.savemypics.android.activity.CStartActivity.java
org.savemypics.android.authenticator.AAuthenticatorActivity.java
org.savemypics.android.authenticator.CAuthenticationService.java
org.savemypics.android.authenticator.CAuthenticator.java
org.savemypics.android.authenticator.CFlickrLoginHookActivity.java
org.savemypics.android.authenticator.CFlickrWebActivity.java
org.savemypics.android.authenticator.CSelectProviderActivity.java
org.savemypics.android.authenticator.CSnapfishLoginActivity.java
org.savemypics.android.db.CAccount.java
org.savemypics.android.db.CDb.java
org.savemypics.android.db.CLocalImage.java
org.savemypics.android.db.CMap.java
org.savemypics.android.db.CRemoteImage.java
org.savemypics.android.event.AEvent.java
org.savemypics.android.event.CEventBus.java
org.savemypics.android.event.CExceptionEvent.java
org.savemypics.android.glue.ABaseGlue.java
org.savemypics.android.glue.CFlickrGlue.java
org.savemypics.android.glue.CSnapfishGlue.java
org.savemypics.android.receiver.CNetworkChangeReceiver.java
org.savemypics.android.service.CTaskQueue.java
org.savemypics.android.sync.CMediaUtils.java
org.savemypics.android.sync.CSyncAdapter.java
org.savemypics.android.sync.CSyncService.java
org.savemypics.android.sync.CSyncUtils.java
org.savemypics.android.util.CBitmapUtils.java
org.savemypics.android.util.CFileCache.java
org.savemypics.android.util.CLruCache.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.util.CUtils.java
org.savemypics.android.view.CMaximumWidthLayout.java
org.savemypics.android.view.CModularLayout.java
org.savemypics.android.view.CRefreshButton.java
org.savemypics.android.view.CRoundedBitmapView.java
org.savemypics.android.view.CStatusCounterView.java
org.savemypics.plugin.CIOUtils.java
org.savemypics.plugin.CPlugin.java
org.savemypics.plugin.flickr.CFlickrAlbum.java
org.savemypics.plugin.flickr.CFlickrUtils.java
org.savemypics.plugin.snapfish.CSnapfishAlbum.java
org.savemypics.plugin.snapfish.CSnapfishFeed.java
org.savemypics.plugin.snapfish.CSnapfishUser.java
org.savemypics.plugin.snapfish.CSnapfishUtils.java