Android Open Source - callmeter Export Provider






From Project

Back to project page callmeter.

License

The source code is released under:

GNU General Public License

If you think the Android project callmeter 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 de.ub0r.android.callmeter.data;
//from ww  w .  j ava2s  .c  o  m
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.OpenableColumns;

import java.io.File;
import java.io.FileNotFoundException;

import de.ub0r.android.logg0r.Log;

public class ExportProvider extends ContentProvider {

    /** Tag for output. */
    private static final String TAG = "ExportProvider";

    /** Authority. */
    public static final String AUTHORITY = DataProvider.PACKAGE + ".export";

    /** Mime type for export. */
    public static final String EXPORT_MIMETYPE = "application/android.callmeter.export";
    /** {@link Uri} for export Content. */
    public static final Uri EXPORT_RULESET_URI = Uri.parse("content://" + AUTHORITY + "/ruleset");
    /** {@link Uri} for export Content. */
    public static final Uri EXPORT_LOGS_URI = Uri.parse("content://" + AUTHORITY + "/logs");
    /** {@link Uri} for export Content. */
    public static final Uri EXPORT_NUMGROUPS_URI = Uri.parse("content://" + AUTHORITY
            + "/numgroups");
    /** {@link Uri} for export Content. */
    public static final Uri EXPORT_HOURGROUPS_URI = Uri.parse("content://" + AUTHORITY
            + "/hourgroups");
    /** Filename for the actual export file. */
    public static final String EXPORT_RULESET_FILE = "ruleset.xml";
    /** Filename for the actual logs file. */
    public static final String EXPORT_LOGS_FILE = "logs.xml";
    /** Filename for the actual number groups file. */
    public static final String EXPORT_NUMGROUPS_FILE = "numgroups.xml";
    /** Filename for the actual hour groups file. */
    public static final String EXPORT_HOURGROUPS_FILE = "hourgroups.xml";

    /** {@link UriMatcher}. */
    private static final UriMatcher URI_MATCHER;
    /** Internal id: export. */
    private static final int EXPORT_RULESET = 200;
    /** Internal id: export. */
    private static final int EXPORT_LOGS = 201;
    /** Internal id: export. */
    private static final int EXPORT_NUMGROUPS = 202;
    /** Internal id: export. */
    private static final int EXPORT_HOURGROUPS = 203;

    static {
        URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
        URI_MATCHER.addURI(AUTHORITY, "ruleset", EXPORT_RULESET);
        URI_MATCHER.addURI(AUTHORITY, "logs", EXPORT_LOGS);
        URI_MATCHER.addURI(AUTHORITY, "numgroups", EXPORT_NUMGROUPS);
        URI_MATCHER.addURI(AUTHORITY, "hourgroups", EXPORT_HOURGROUPS);
    }

    @Override
    public int delete(final Uri uri, final String selection, final String[] selectionArgs) {
        throw new IllegalStateException("Unsupported operation: delete(" + uri + ")");
    }

    @Override
    public String getType(final Uri uri) {
        switch (URI_MATCHER.match(uri)) {
            case EXPORT_RULESET:
            case EXPORT_LOGS:
            case EXPORT_NUMGROUPS:
            case EXPORT_HOURGROUPS:
                return EXPORT_MIMETYPE;
            default:
                throw new IllegalArgumentException("Unknown URI: " + uri);
        }
    }

    @Override
    public Uri insert(final Uri uri, final ContentValues values) {
        throw new IllegalStateException("Unsupported operation: insert(" + uri + ")");
    }

    @Override
    public boolean onCreate() {
        return true;
    }

    @Override
    public Cursor query(final Uri uri, final String[] projection, final String selection,
            final String[] selectionArgs, final String sortOrder) {
        Log.d(TAG, "export uri: ", uri);
        String fn;
        final int uid = URI_MATCHER.match(uri);

        switch (uid) {
            case EXPORT_RULESET:
                fn = EXPORT_RULESET_FILE;
                break;
            case EXPORT_LOGS:
                fn = EXPORT_LOGS_FILE;
                break;
            case EXPORT_NUMGROUPS:
                fn = EXPORT_NUMGROUPS_FILE;
                break;
            case EXPORT_HOURGROUPS:
                fn = EXPORT_HOURGROUPS_FILE;
                break;
            default:
                throw new IllegalArgumentException("Unknown Uri " + uri);
        }

        final int l = projection.length;
        Object[] retArray = new Object[l];
        for (int i = 0; i < l; i++) {
            if (projection[i].equals(OpenableColumns.DISPLAY_NAME)) {
                retArray[i] = fn;
            } else if (projection[i].equals(OpenableColumns.SIZE)) {
                final File d = Environment.getExternalStorageDirectory();
                final File f = new File(d, DataProvider.PACKAGE + File.separator + fn);
                retArray[i] = f.length();
            }
        }
        final MatrixCursor ret = new MatrixCursor(projection, 1);
        ret.addRow(retArray);
        Log.d(TAG, "query(): ", ret.getCount());
        return ret;
    }

    @Override
    public int update(final Uri uri, final ContentValues values, final String selection,
            final String[] selectionArgs) {
        throw new IllegalStateException("Unsupported operation: update(" + uri + ")");
    }

    @Override
    public ParcelFileDescriptor openFile(final Uri uri, final String mode)
            throws FileNotFoundException {
        Log.d(TAG, "openFile(", uri.toString(), ")");
        final File d = Environment.getExternalStorageDirectory();
        String fn = null;
        if (uri.equals(EXPORT_RULESET_URI)) {
            fn = EXPORT_RULESET_FILE;
        } else if (uri.equals(EXPORT_LOGS_URI)) {
            fn = EXPORT_LOGS_FILE;
        } else if (uri.equals(EXPORT_NUMGROUPS_URI)) {
            fn = EXPORT_NUMGROUPS_FILE;
        } else if (uri.equals(EXPORT_HOURGROUPS_URI)) {
            fn = EXPORT_HOURGROUPS_FILE;
        }
        if (fn == null) {
            return null;
        }
        final File f = new File(d, DataProvider.PACKAGE + File.separator + fn);
        return ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
    }
}




Java Source Code List

android.preference.DatePreference.java
com.actionbarsherlock.BuildConfig.java
de.ub0r.android.callmeter.Ads.java
de.ub0r.android.callmeter.CallMeter.java
de.ub0r.android.callmeter.TrackingUtils.java
de.ub0r.android.callmeter.data.DataProvider.java
de.ub0r.android.callmeter.data.Device.java
de.ub0r.android.callmeter.data.ExportProvider.java
de.ub0r.android.callmeter.data.LogRunnerReceiver.java
de.ub0r.android.callmeter.data.LogRunnerService.java
de.ub0r.android.callmeter.data.NameCache.java
de.ub0r.android.callmeter.data.NameLoader.java
de.ub0r.android.callmeter.data.RuleMatcher.java
de.ub0r.android.callmeter.data.SysClassNet.java
de.ub0r.android.callmeter.ui.AboutActivity.java
de.ub0r.android.callmeter.ui.AddLogActivity.java
de.ub0r.android.callmeter.ui.AskForPlan.java
de.ub0r.android.callmeter.ui.Common.java
de.ub0r.android.callmeter.ui.HelpActivity.java
de.ub0r.android.callmeter.ui.IntroActivity.java
de.ub0r.android.callmeter.ui.LogsFragment.java
de.ub0r.android.callmeter.ui.PlansFragment.java
de.ub0r.android.callmeter.ui.Plans.java
de.ub0r.android.callmeter.ui.TrackingActivity.java
de.ub0r.android.callmeter.ui.TrackingSherlockActivity.java
de.ub0r.android.callmeter.ui.TrackingSherlockFragmentActivity.java
de.ub0r.android.callmeter.ui.TrackingSherlockPreferenceActivity.java
de.ub0r.android.callmeter.ui.prefs.BillModeListPreference.java
de.ub0r.android.callmeter.ui.prefs.CV2EditTextPreference.java
de.ub0r.android.callmeter.ui.prefs.CVBillModePreference.java
de.ub0r.android.callmeter.ui.prefs.CVCheckBoxPreference.java
de.ub0r.android.callmeter.ui.prefs.CVDatePreference.java
de.ub0r.android.callmeter.ui.prefs.CVEditTextPreference.java
de.ub0r.android.callmeter.ui.prefs.CVListPreference.java
de.ub0r.android.callmeter.ui.prefs.HourGroupEdit.java
de.ub0r.android.callmeter.ui.prefs.HourGroups.java
de.ub0r.android.callmeter.ui.prefs.NumberGroupEdit.java
de.ub0r.android.callmeter.ui.prefs.NumberGroups.java
de.ub0r.android.callmeter.ui.prefs.PlanEdit.java
de.ub0r.android.callmeter.ui.prefs.Plans.java
de.ub0r.android.callmeter.ui.prefs.PreferencesImport.java
de.ub0r.android.callmeter.ui.prefs.PreferencesPlain.java
de.ub0r.android.callmeter.ui.prefs.PreferencesRules.java
de.ub0r.android.callmeter.ui.prefs.Preferences.java
de.ub0r.android.callmeter.ui.prefs.RuleEdit.java
de.ub0r.android.callmeter.ui.prefs.Rules.java
de.ub0r.android.callmeter.ui.prefs.SimplePreferencesChild.java
de.ub0r.android.callmeter.ui.prefs.SimplePreferences.java
de.ub0r.android.callmeter.ui.prefs.UpDownPreference.java
de.ub0r.android.callmeter.ui.prefs.UpdateListener.java
de.ub0r.android.callmeter.widget.LogsAppWidgetConfigure.java
de.ub0r.android.callmeter.widget.LogsAppWidgetProvider.java
de.ub0r.android.callmeter.widget.StatsAppWidgetConfigure.java
de.ub0r.android.callmeter.widget.StatsAppWidgetProvider.java
yuku.ambilwarna.AmbilWarnaDialog.java
yuku.ambilwarna.AmbilWarnaKotak.java