Android Open Source - savemypics A Event






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;
/*from  w  w  w  .  j a va2 s. c  o  m*/
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.SparseArray;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public abstract class AEvent
{
    public interface Listener {}

    protected final static void doSubscribe(final Listener l, final int id)
    {
        Looper looper = Looper.myLooper();
        if (Looper.getMainLooper() != looper) {
            throw new IllegalStateException
                ("Can only subscribe on main thread");
        }
        doSubscribe(looper, l, id);
    }

    protected final static void doSubscribe
        (final Looper looper, final Listener l, final int id)
    {
        Handler h = removeHandlerFor(l, id);
        if (h != null) {
            CEventBus.unsubscribe(h, id);
        }

        h = new Handler(looper) {
                @Override public void handleMessage(Message m) {
                    if (m.what != id) {
                        throw new IllegalArgumentException
                            ("Unexpected event: "+m.what);
                    }
                    ((AEvent) m.obj).onUpdate(l);
                }
            };
        setHandlerFor(l, id, h);
        CEventBus.subscribe(h, id);
    }

    protected final static void doUnsubscribe(final Listener l, final int id)
    {
        Handler h = removeHandlerFor(l, id);
        if (h != null) {
            CEventBus.unsubscribe(h, id);
        }
    }

    protected final void doPublish(final int id)
    {
        Message m = Message.obtain();
        m.what = id;
        m.obj = this;
        CEventBus.publish(m);
    }

    protected abstract void onUpdate(Listener l);

    private final static Handler removeHandlerFor(Listener l, int id)
    {
        synchronized (s_lmap) {
            SparseArray<Handler> handlers = s_lmap.get(l);
            if (handlers == null) { return null; }
            Handler ret = handlers.get(id);
            if (ret == null) { return null; }
            handlers.remove(id);
            return ret;
        }
    }

    private final static Handler setHandlerFor(Listener l, int id, Handler h)
    {
        synchronized (s_lmap) {
            SparseArray<Handler> handlers = s_lmap.get(l);
            if (handlers == null) {
                handlers = new SparseArray<Handler>();
                s_lmap.put(l, handlers);
            }
            handlers.put(id, h);
            return h;
        }
    }

    private final static Map<Listener, SparseArray<Handler>> s_lmap =
        new HashMap<Listener, SparseArray<Handler>>();
}




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