Skip to content

Instantly share code, notes, and snippets.

public class StringParser implements NewtorkResponseParser<String> {
@Override
public Response<String> parseResponse(NetworkResponse response) {
String parsed;
try {
parsed = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
} catch (UnsupportedEncodingException e) {
parsed = new String(response.data);
ImageLoader imageLoader = new ExtendedImageLoader(queue, new BitmapLru(64000), new ImageRequestFactory() {
@Override
public Request<?> getImageRequest(String url, Listener<Bitmap> listener,
int maxWidth, int maxHeight, Config config,
ErrorListener errorListener) {
return new MyImageRequest(url, listener, maxWidth, maxHeight, config, errorListener);
}
});
DelegatingRequest<JSONObject> tokenRequest = new DelegatingRequest<JSONObject>(
Method.POST, TOKEN_URL, NewtorkResponseParser.jsonObjectParser,
new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
ACCESS_TOKEN = response.optString("access_token");
// Do the rest of the treatment
}
}, new ErrorListener() {
public class SQLSchema {
private Map<String, TypeHandler> fields = new HashMap<String, TypeHandler>();
private Class<? extends Storable> clazz;
public SQLSchema(Class<? extends Storable> clazz) {
this.clazz = clazz;
Field[] fields = SQLHelper.getFields(clazz);
for (Field field : fields) {
fields.put(field.getName(), TypeHandler.getHandler(field.getType()));
public void save(Context context) {
Map<String, Object> mapRepr = asMap();
Parcel p = Parcel.obtain();
p.writeMap(mapRepr);
p.setDataPosition(0);
ContentValues values = ContentValues.CREATOR.createFromParcel(p);
if (id == -1) {
Uri insertUri = context.getContentResolver().insert(
getPath(getClass()), values);
id = Long.parseLong(insertUri.getLastPathSegment());
public static <T extends Storable> T getById(Context context,
Class<T> clazz, long id) {
try {
T result = clazz.newInstance();
Cursor content = context.getContentResolver().query(
getPath(clazz, id), null, null, null, null);
if (content.moveToFirst()) {
result.loadCursor(content);
}
return result;
public class TypeHandler {
public String getSQLType() {
return "TEXT";
}
public Object getSQLValue(Object object) {
return object;
}
@smaspe
smaspe / Storable.java
Created July 8, 2013 14:08
delete method
public boolean delete(Context context) {
boolean result = context.getContentResolver().delete(
getPath(getClass(), id), null, null) > 0;
if (result) {
id = -1;
}
return result;
}
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
TiledMap map = new TmxMapLoader().load("data/goban19.tmx");
renderer = new OrthogonalTiledMapRenderer(map, unitScale);
camera = new OrthographicCamera();
camera.setToOrtho(true, w * unitScale, h * unitScale);
WIDTH = ((TiledMapTileLayer) map.getLayers().get(0)).getWidth();
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(new ZoomMoveKeyProcessor(camera));
multiplexer.addProcessor(new GestureDetector(new ZoomPanDetector(camera)));
multiplexer.addProcessor(new GestureDetector(new PutStoneDetector(this, camera)));
Gdx.input.setInputProcessor(multiplexer);