Android Open Source - adme Content Provider Uris






From Project

Back to project page adme.

License

The source code is released under:

Apache License

If you think the Android project adme 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 com.danielesegato.adme.db;
/*from ww w .  ja va  2  s  .  c om*/
import android.content.UriMatcher;
import android.net.Uri;
import android.util.SparseArray;

/**
 * Helper class to define {@link android.net.Uri}s for a {@link android.content.ContentProvider} backed by a database
 */
public class ContentProviderUris {
    public static final String URI_FORMAT = "content://%s/%s";
    public static final String MIMETYPE_DIR_FORMAT = "vnd.android.cursor.dir/vnd.%s.%s";

    /**
     * Build an {@link android.net.Uri} and return it
     *
     * @param authority  the {@link android.content.ContentProvider} authority
     * @param entityName the entity (table) name
     * @return the Uri
     */
    public static final Uri buildUri(final String authority, final String entityName) {
        return Uri.parse(String.format(URI_FORMAT, authority, entityName));
    }

    /**
     * Build an {@link android.net.Uri}, add it to an {@link android.content.UriMatcher} and return the Uri.
     *
     * @param authority  the {@link android.content.ContentProvider} authority
     * @param entityName the entity (table) name
     * @param matcher    the Uri matcher
     * @param match      the match for this Uri
     * @return the Uri
     */
    public static final Uri buildUriAndAddMatch(final String authority, final String entityName, final UriMatcher matcher, final int match) {
        final Uri uri = buildUri(authority, entityName);
        matcher.addURI(authority, entityName, match);
        return uri;
    }

    /**
     * Build an Uri and add it to a {@link ContentProviderUris}, return the Uri
     *
     * @param cProviderUris the ContentProviderUris helper class
     * @param entityName    the entity (table) name
     * @param match         the match for this Uri
     * @return the Uri
     */
    public static final Uri buildUriAndAdd(final ContentProviderUris cProviderUris, final String entityName, final int match) {
        return cProviderUris.buildAndAddUri(entityName, match);
    }

    private final String mAuthority;
    private final UriMatcher mUriMatcher;
    private final SparseArray<String> mEntityNameMap;
    private final SparseArray<Uri> mUriMap;

    public ContentProviderUris(final String authority) {
        mAuthority = authority;
        mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        mEntityNameMap = new SparseArray<String>();
        mUriMap = new SparseArray<Uri>();
    }

    public String getAuthority() {
        return mAuthority;
    }

    public UriMatcher getUriMatcher() {
        return mUriMatcher;
    }

    public String getEntityName(int match) {
        return mEntityNameMap.get(match);
    }

    public String getEntityName(Uri uri) {
        return getEntityName(mUriMatcher.match(uri));
    }

    public Uri buildAndAddUri(final String entityName, final int match) {
        Uri uri = buildUriAndAddMatch(mAuthority, entityName, mUriMatcher, match);
        mEntityNameMap.put(match, entityName);
        mUriMap.put(match, uri);
        return uri;
    }

    public String getMimetype(Uri uri) {
        return String.format(MIMETYPE_DIR_FORMAT, mAuthority, getEntityName(uri));
    }
}




Java Source Code List

com.danielesegato.adme.ADME.java
com.danielesegato.adme.annotation.ADMEEntity.java
com.danielesegato.adme.annotation.ADMEField.java
com.danielesegato.adme.annotation.ADMEIndexConstraint.java
com.danielesegato.adme.config.ADMEConfigUtils.java
com.danielesegato.adme.config.ADMEEntityConfig.java
com.danielesegato.adme.config.ADMEFieldConfig.java
com.danielesegato.adme.config.ADMEIndexConstraintConfig.java
com.danielesegato.adme.config.OnForeignUpdateDelete.java
com.danielesegato.adme.config.SQLiteType.java
com.danielesegato.adme.db.ADMESerializerMapping.java
com.danielesegato.adme.db.ADMESerializer.java
com.danielesegato.adme.db.ContentProviderUris.java
com.danielesegato.adme.db.SQLiteContentProvider.java
com.danielesegato.adme.db.serializer.BaseADMESerializer.java
com.danielesegato.adme.db.serializer.BigDecimalADMESerializer.java
com.danielesegato.adme.db.serializer.BooleanADMESerializer.java
com.danielesegato.adme.db.serializer.BooleanObjectADMESerializer.java
com.danielesegato.adme.db.serializer.CurrencyADMESerializer.java
com.danielesegato.adme.db.serializer.DateAsStringADMESerializer.java
com.danielesegato.adme.db.serializer.DateAsTimestampADMESerializer.java
com.danielesegato.adme.db.serializer.DoubleADMESerializer.java
com.danielesegato.adme.db.serializer.DoubleObjectADMESerializer.java
com.danielesegato.adme.db.serializer.EnumIntADMESerializer.java
com.danielesegato.adme.db.serializer.EnumStringADMESerializer.java
com.danielesegato.adme.db.serializer.IntADMESerializer.java
com.danielesegato.adme.db.serializer.IntObjectADMESerializer.java
com.danielesegato.adme.db.serializer.LongADMESerializer.java
com.danielesegato.adme.db.serializer.LongObjectADMESerializer.java
com.danielesegato.adme.db.serializer.StringADMESerializer.java
com.danielesegato.adme.provider.ADMEContentProviderComponent.java
com.danielesegato.adme.provider.ADMEContentProvider.java
com.danielesegato.adme.utils.DateHelper.java
com.danielesegato.adme.utils.SQLStringHelper.java
com.danielesegato.adme.utils.SQLiteScriptParser.java
com.danielesegato.demo.adme.ADMEDemoMainActivity.java
com.danielesegato.demo.adme.NavigationDrawerFragment.java