Back to project page C2Framework.
The source code is released under:
Apache License
If you think the Android project C2Framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package gaia.c2.content; /* w ww.j av a 2 s .c o m*/ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; import android.util.Log; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.TreeMap; import gaia.c2.receivers.ContextBroadcastReceiver; public abstract class C2ContentProvider { protected Context androidParentContext; private Map<String, QueryHandler> delegates; public C2ContentProvider(Context androidParentContext) { this.androidParentContext = androidParentContext; this.delegates = new TreeMap<String, QueryHandler>(); } public void onCreate() { } public void onDestroy() { } public abstract String getMimeType(); public abstract String getAuthority(); public Context getContext() { return androidParentContext; } public final void handleQuery(String method, Bundle parameters) { Log.i("[C2ContentProvider." + getAuthority() + "]", "Query for method: " + method); QueryHandler r = delegates.get(method); if (r == null) { throw new UnsupportedOperationException(method); } try { r.handle(method, parameters); } catch (Throwable ex) { broadcast(new Exception(ex)); } } protected final void on(String method, QueryHandler r) { if (!delegates.containsKey(method)) { delegates.put(method, r); } } protected final void broadcast(Parcelable obj) { Intent intent = new Intent(); intent.setAction(ContextBroadcastReceiver.CONTENT_MESSAGE_OK); Bundle extra = new Bundle(); extra.putParcelable(ContextBroadcastReceiver.CONTENT_FIELD, obj); extra.putString(ContextBroadcastReceiver.CONTENT_MIME_TYPE, getMimeType()); intent.putExtras(extra); androidParentContext.sendBroadcast(intent); } protected final void broadcast(List<? extends Parcelable> obj) { Intent intent = new Intent(); intent.setAction(ContextBroadcastReceiver.CONTENT_MESSAGE_OK); Bundle extra = new Bundle(); extra.putParcelableArrayList(ContextBroadcastReceiver.CONTENT_FIELD_ARRAY, new ArrayList<Parcelable>(obj)); extra.putString(ContextBroadcastReceiver.CONTENT_MIME_TYPE, getMimeType()); intent.putExtras(extra); androidParentContext.sendBroadcast(intent); } protected final void broadcast(Exception ex) { Intent intent = new Intent(); intent.setAction(ContextBroadcastReceiver.CONTENT_MESSAGE_OK); Bundle extra = new Bundle(); extra.putSerializable(ContextBroadcastReceiver.CONTENT_FIELD, ex); intent.putExtras(extra); androidParentContext.sendBroadcast(intent); } }