Saturday, November 7, 2015

REST API WEEK! App a Day 22: Reddit Images

https://github.com/victorman/RedditImagesAndroid



I'm not sure if this one is really accessing an API, technically. Though it does request subreddits in JSON in order to display thumbnails of images which doesn't require any authentication.

REST API WEEK! App a Day 21: Goodreads Authors

https://github.com/victorman/GoodreadsFavoritesAndroid



Classes Used: Service, AbstractThreadedSyncAdapter, XmlPullParser, ContentProvider, ContentResolver SQLiteOpenHelper, Handler, ContentObserver.

I've always wanted to play with the Goodreads API. So here's my first attempt. Responses are in XML only, unfortunately. This makes a request for the books (reviews) in my favorites shelf and lists the authors. Very simple in theory. I was going to do more but I ran out of time.

I finally made some templates files for a SQLite Database, but without any of the provider's URI constants. Just copy the gist code below into a file template.

package ${PACKAGE_NAME};
#parse("File Header.java")
public class ${NAME} {
public ${NAME}() {}
public static class ${ENTRY_CLASS} implements BaseColumns {
public static final String TABLE_NAME = "${TABLE_NAME}";
public static final String COLUMN_NAME_CREATED = "date_created";
}
}
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import ${PACKAGE_NAME}.${CONTRACT_CLASS}.${ENTRY_CLASS};
#parse("File Header.java")
public class ${NAME} extends SQLiteOpenHelper {
/*
* Database version and name.
*/
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "${DATABASE_NAME}";
/*
* quick database type constants and a comma.
* pay attention to where spaces are inside your strings
* when using constants. you don't want to end up with
* something like " INTEGERNOT NULL" for a type.
*/
private static final String TEXT_TYPE = " TEXT";
private static final String INT_TYPE = " INTEGER";
private static final String REAL_TYPE = " REAL";
private static final String C = ",";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + ${ENTRY_CLASS}.TABLE_NAME + " (" +
${ENTRY_CLASS}._ID + INT_TYPE + " PRIMARY KEY AUTOINCREMENT" + C +
${ENTRY_CLASS}.COLUMN_NAME_CREATED + TEXT_TYPE + C +
/*
* TODO Define columns here
* column definitions are comma seperated
* COLUMN_NAME TYPE (example:)
* name TEXT,
* age INTEGER
*/
" )";
private static final String SQL_DELETE_ENTRIES =
"DROP TABLE IF EXISTS " + ${ENTRY_CLASS}.TABLE_NAME;
public ${NAME}(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DELETE_ENTRIES);
onCreate(db);
}
}

Friday, November 6, 2015

REST API WEEK! App a Day 20: Facebook Likes

https://github.com/victorman/FacebookLikesAndroid



Uses Classes: FacebookSdk, LoginButton, FacebookCallback, AsyncTask, Thread, BaseAdapter, GraphRequest, JSONObject, JSONArray.

This uses the Facebook Graph API and SDK to display the first page of the user's likes.

Wednesday, November 4, 2015

REST API WEEK! App a Day 19: Weather Map

https://github.com/victorman/WeatherMapAndroid



Classes Used: ContentProvider, ContentResolver, Service, AbstractThreadedSyncAdapter, GoogleMap, Handler

I think I need to learn a lot in regards to what is possible using data that is already out there. So I'm going to make this REST API week. I'll use different API's in all of my dailies.
This one uses openweathermap.org. Using it's cities in cycle feature it grabs current temperatures for 10 cities near your current GPS location and displays the markers on the map.