Android Open Source - C2Framework C2 Content Provider






From Project

Back to project page C2Framework.

License

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.

Java Source Code

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);
    }
}




Java Source Code List

gaia.c2.content.C2ContentProvider.java
gaia.c2.content.C2ContentService.java
gaia.c2.content.QueryHandler.java
gaia.c2.content.android.CallContentProvider.java
gaia.c2.content.android.DialContentProvider.java
gaia.c2.content.android.VibrationContentProvider.java
gaia.c2.content.android.model.Call.java
gaia.c2.content.android.model.Dial.java
gaia.c2.content.android.model.Vibration.java
gaia.c2.content.model.ContextDependentModel.java
gaia.c2.content.sqlite.C2SQLiteContentProvider.java
gaia.c2.content.sqlite.C2SQLiteHelper.java
gaia.c2.content.tools.C2DownloadsContentProvider.java
gaia.c2.content.tools.model.DownloadStatus.java
gaia.c2.context.C2Context.java
gaia.c2.context.DefaultC2Context.java
gaia.c2.context.view.C2Message.java
gaia.c2.context.view.C2View.java
gaia.c2.receivers.ContextBroadcastReceiver.java
gaia.c2.receivers.ContextEventReceiver.java