Android Open Source - savemypics C Remote Image






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.db;
/*from  w w  w . j  a  v a2 s  .co  m*/
import android.content.ContentValues;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.List;

public final class CRemoteImage
{
    private final static String TABLE = "remote_image";
    private final static String ACCOUNT_ID = "account_id";
    private final static String REMOTE_ID = "remote_id";
    private final static String URI = "uri";
    private final static String CREATED = "created";

    private final static String TABLE_CREATE =
        "create table "+TABLE+"("+
        ACCOUNT_ID+" integer not null,"+
        REMOTE_ID+" text not null,"+
        URI+" text not null,"+
        CREATED+" integer not null,"+
        "primary key ("+ACCOUNT_ID+","+REMOTE_ID+"),"+
        "foreign key ("+ACCOUNT_ID+") references "+
        CAccount.TABLE+"("+CAccount._ID+"))";

    private final static String TABLE_INDEX_CREATED =
        "create index "+TABLE+"_"+CREATED+"_index on "+
        TABLE+"("+CREATED+" desc)";

    private final static String TABLE_INDEX_URI =
        "create index "+TABLE+"_"+URI+"_index on "+
        TABLE+"("+URI+")";

    private final static String SELECT_FIELDS =
        "select "+ACCOUNT_ID+","+
        REMOTE_ID+","+
        URI+","+
        CREATED;

    private final static String SELECT_BY_ACCOUNT_LIMIT =
        SELECT_FIELDS+" from "+TABLE+" where "+
        ACCOUNT_ID+"=? order by "+CREATED+" desc limit ?";

    private final static String BY_ACCOUNT_URI =
        ACCOUNT_ID+"=? and "+URI+"=?";

    private final static String SELECT_COUNT_BY_ACCOUNT_URI =
        "select count(1) from "+TABLE+
        " where "+BY_ACCOUNT_URI;

    public final static int deleteByUri
        (SQLiteDatabase db, long aid, String uri)
    {
        return db.delete
            (TABLE, BY_ACCOUNT_URI, new String[] { String.valueOf(aid), uri });
    }

    public final static boolean exists
        (SQLiteDatabase db, long aid, String uri)
    {
        return 1l == DatabaseUtils.longForQuery
            (db, SELECT_COUNT_BY_ACCOUNT_URI,
             new String[] {String.valueOf(aid), uri});
    }

    public final static List<CRemoteImage> getRecents
        (SQLiteDatabase db, long aid, int limit)
    {
        List<CRemoteImage> ret = new ArrayList<CRemoteImage>();
        Cursor c = db.rawQuery
            (SELECT_BY_ACCOUNT_LIMIT,
             new String[] {
                String.valueOf(aid), String.valueOf(limit)
            });
        try {
            while (c.moveToNext()) {
                ret.add(fromCursor(c));
            }
            return ret;
        }
        finally {
            CDb.close(c);
        }
    }

    public final static CRemoteImage addOrReplace
        (SQLiteDatabase db, long aid, String remote_id,
         String uri, long created)
    {
        ContentValues cv = new ContentValues();
        cv.put(ACCOUNT_ID, aid);
        cv.put(REMOTE_ID, remote_id);
        cv.put(URI, uri);
        cv.put(CREATED, created);

        long id = db.insertWithOnConflict
            (TABLE, null, cv, SQLiteDatabase.CONFLICT_REPLACE);
        if (id <= 0) { return null; }
        return new CRemoteImage(aid, remote_id, uri, created);
    }

    private final static CRemoteImage fromCursor(Cursor c)
    {
        return new CRemoteImage
            (c.getLong(0),
             c.getString(1),
             c.getString(2),
             c.getLong(3));
    }


    private CRemoteImage
        (long aid, String remote_id, String uri, long created)
    {
        m_aid = aid;
        m_remote_id = remote_id;
        m_uri = uri;
        m_created = created;
    }
    public long getCreated()
    { return m_created; }
    public String getUri()
    { return m_uri; }
    public long getAccountId()
    { return m_aid; }
    public String getRemoteId()
    { return m_remote_id; }
    private final long m_aid;
    private final String m_remote_id;
    private final String m_uri;
    private final long m_created;

    final static void makeSchema(SQLiteDatabase db)
    {
        db.execSQL(TABLE_CREATE);
        db.execSQL(TABLE_INDEX_CREATED);
    }
}




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