This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TypeHandler { | |
public String getSQLType() { | |
return "TEXT"; | |
} | |
public Object getSQLValue(Object object) { | |
return object; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean delete(Context context) { | |
boolean result = context.getContentResolver().delete( | |
getPath(getClass(), id), null, null) > 0; | |
if (result) { | |
id = -1; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |