Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ajustes estéticos.

Arreglado bug que hacía que el parseo json fallara si no había descripcion
  • Loading branch information...
commit 37a597de6c5a0812ef645da82bbdce945459c625 1 parent 32d8454
@francho authored
View
49 kitaos-android-test/assets/talks.json
@@ -0,0 +1,49 @@
+{ "22001" : { "date" : "2012-06-23",
+ "description" : "Una cosas de esas que molan",
+ "duration" : 1,
+ "room" : { "name" : "sala1" },
+ "session" : 1,
+ "speaker" : { "city" : "Madriz",
+ "computers_needed" : true,
+ "email" : "froilan@casareal.es",
+ "first_name" : "Felipe Juan Froilán",
+ "last_name" : "Borbón",
+ "speaker" : true,
+ "twitter_id" : "FJFROILAN"
+ },
+ "time" : "9:30",
+ "title" : "Agilismo 1"
+},
+ "23001" : { "date" : "2012-06-23",
+ "description" : "¿Es libre o no?",
+ "duration" : 1,
+ "room" : { "name" : "sala2" },
+ "session" : 1,
+ "speaker" : { "city" : "Pamplona",
+ "computers_needed" : true,
+ "email" : "richard@gnu.org",
+ "first_name" : "Richard",
+ "last_name" : "Stallman",
+ "speaker" : true,
+ "twitter_id" : "GNUplusLINUX"
+ },
+ "time" : "9:30",
+ "title" : "TDD"
+ },
+ "24001" : { "date" : "2012-06-23",
+ "description" : "¿Cuanto nos paga?",
+ "duration" : 1,
+ "room" : { "name" : "sala3" },
+ "session" : 1,
+ "speaker" : { "city" : "Zaragoza",
+ "computers_needed" : false,
+ "email" : "bill@microsoft.com",
+ "first_name" : "Bill",
+ "last_name" : "Gates",
+ "speaker" : true,
+ "twitter_id" : "fbgblog"
+ },
+ "time" : "9:30",
+ "title" : "Android"
+ }
+}
View
20 kitaos-android-test/src/org/agilespain/kitaos/KitaosProviderTest.java
@@ -109,37 +109,49 @@ public void testInsert() throws Exception {
int id = 123;
String title = "title";
+ String description="description";
String date = "2012-05-23 10:30";
double duration = 2;
String room = "room";
String speaker = "speaker";
+ String speaker_email = "em@ail.com";
+ String speaker_twitter = "cocoliso";
values.put(KitaosContract.Talks._ID, id);
values.put(KitaosContract.Talks.TITLE, title);
+ values.put(KitaosContract.Talks.DESCRIPTION, description);
values.put(KitaosContract.Talks.START_DATE, date);
values.put(KitaosContract.Talks.END_DATE, duration);
values.put(KitaosContract.Talks.ROOM, room);
values.put(KitaosContract.Talks.SPEAKER, speaker);
+ values.put(KitaosContract.Talks.SPEAKER_TWITTER, speaker_twitter);
+ values.put(KitaosContract.Talks.SPEAKER_EMAIL, speaker_email);
mProvider.insert(KitaosContract.Talks.uri(),values);
String[] projection = {
KitaosContract.Talks._ID,
KitaosContract.Talks.TITLE,
+ KitaosContract.Talks.DESCRIPTION,
KitaosContract.Talks.START_DATE,
KitaosContract.Talks.END_DATE,
KitaosContract.Talks.ROOM,
KitaosContract.Talks.SPEAKER,
+ KitaosContract.Talks.SPEAKER_TWITTER,
+ KitaosContract.Talks.SPEAKER_EMAIL,
};
Cursor cursor = mProvider.query(KitaosContract.Talks.uri(id),projection,null,null,null);
cursor.moveToFirst();
assertEquals(id, cursor.getInt(0));
assertEquals(title, cursor.getString(1));
- assertEquals(date, cursor.getString(2));
- assertEquals(duration, cursor.getDouble(3));
- assertEquals(room, cursor.getString(4));
- assertEquals(speaker, cursor.getString(5));
+ assertEquals(description, cursor.getString(2));
+ assertEquals(date, cursor.getString(3));
+ assertEquals(duration, cursor.getDouble(4));
+ assertEquals(room, cursor.getString(5));
+ assertEquals(speaker, cursor.getString(6));
+ assertEquals(speaker_twitter, cursor.getString(7));
+ assertEquals(speaker_email, cursor.getString(8));
cursor.close();
View
82 kitaos-android-test/src/org/agilespain/kitaos/TalksJsonHandlerTest.java
@@ -1,7 +1,10 @@
package org.agilespain.kitaos;
import android.content.ContentProviderOperation;
+import android.content.Context;
+import android.content.res.AssetManager;
import android.database.Cursor;
+import android.test.AndroidTestCase;
import android.test.ProviderTestCase2;
import android.text.format.DateFormat;
import org.agilespain.kitaos.provider.KitaosContract;
@@ -9,18 +12,23 @@
import org.agilespain.kitaos.provider.KitaosContract.Talks;
import org.agilespain.kitaos.provider.KitaosProvider;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
/**
* Test the json handler for the talks service
+ *
* @author francho
*/
-public class TalksJsonHandlerTest extends ProviderTestCase2<KitaosProvider> {
+public class TalksJsonHandlerTest extends ProviderTestCase2<KitaosProvider> {
// private KitaosProvider mProvider;
private TalksJsonHandler mTalksHandler;
- public TalksJsonHandlerTest(){
+
+ public TalksJsonHandlerTest() {
super(KitaosProvider.class, KitaosContract.CONTENT_AUTHORITY);
}
@@ -28,49 +36,71 @@ public void setUp() throws Exception {
super.setUp();
mTalksHandler = new TalksJsonHandler();
}
-
+
+ /**
+ * Exposes method {@code getTestContext()} in {@link AndroidTestCase}, which
+ * is hidden for now. Useful for obtaining access to the test assets.
+ */
+ public static Context getTestContext(AndroidTestCase testCase) throws IllegalAccessException,
+ InvocationTargetException, NoSuchMethodException {
+ return (Context) AndroidTestCase.class.getMethod("getTestContext").invoke(testCase);
+ }
+
+
+
private String getDummyJson() {
+ InputStream mockTalks=null;
String json = "";
- json += "{ \"2\" : { \"date\" : \"2012-06-23\", ";
- json += " \"duration\" : 1, ";
- json += " \"hour\" : 11, ";
- json += " \"room\" : { \"name\" : \"sala1\" },";
- json += " \"time\" : \"11:0\", ";
- json += " \"title\" : \"Android\" ";
- json += "}, ";
- json += " \"4001\" : { \"date\" : \"2012-06-23\", ";
- json += " \"duration\" : 1, ";
- json += " \"hour\" : 9, ";
- json += " \"room\" : { \"name\" : \"sala2\" }, ";
- json += " \"time\" : \"9:0\", ";
- json += " \"title\" : \"Kanban\" ";
- json += "} ";
- json += "} ";
+ try {
+ mockTalks = getTestContext(this).getAssets().open("talks.json");
+ int size = mockTalks.available();
+ byte[] buffer = new byte[size];
+ mockTalks.read(buffer);
+ mockTalks.close();
+
+ // byte buffer into a string
+ json = new String(buffer);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ try {
+ mockTalks.close();
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+ }
return json;
}
-
+
public void testParseTalksJson() throws Exception {
ArrayList<ContentProviderOperation> batch = mTalksHandler.parse(getDummyJson(), getContext().getContentResolver());
- assertEquals(3, batch.size());
+ assertEquals(4, batch.size());
getProvider().applyBatch(batch);
- Cursor cursor = getProvider().query(Talks.uri(2), null, null, null, null);
+ Cursor cursor = getProvider().query(Talks.uri(24001), null, null, null, null);
cursor.moveToFirst();
assertEquals("Android", cursor.getString(cursor.getColumnIndex(Talks.TITLE)));
long datetimestamp = cursor.getLong(cursor.getColumnIndex(Talks.START_DATE));
- CharSequence date = DateFormat.format("yyyy-MM-dd h:mm", new Date(datetimestamp));
- assertEquals("2012-06-23 11:00", date);
+ CharSequence date = DateFormat.format("yyyy-MM-dd h:mm", new Date(datetimestamp));
+ assertEquals("2012-06-23 9:30", date);
int duration = (int) ((cursor.getLong(cursor.getColumnIndex(Talks.END_DATE)) - datetimestamp) / (60 * 60 * 1000));
assertEquals(1, duration);
- assertEquals("sala1", cursor.getString(cursor.getColumnIndex(Talks.ROOM)));
+ assertEquals("sala3", cursor.getString(cursor.getColumnIndex(Talks.ROOM)));
+
+ assertEquals("bill@microsoft.com", cursor.getString(cursor.getColumnIndex(Talks.SPEAKER_EMAIL)));
+ assertEquals("fbgblog", cursor.getString(cursor.getColumnIndex(Talks.SPEAKER_TWITTER)));
+ assertEquals("Bill Gates", cursor.getString(cursor.getColumnIndex(Talks.SPEAKER)));
+ assertEquals("¿Cuanto nos paga?", cursor.getString(cursor.getColumnIndex(Talks.DESCRIPTION)));
+
}
-
+
public void testGetMillis() throws Exception {
String expected = "2012-02-29 10:30";
@@ -78,6 +108,6 @@ public void testGetMillis() throws Exception {
Date date = new Date(millis);
CharSequence actual = DateFormat.format("yyyy-MM-dd h:mm", date);
- assertEquals(expected,actual);
+ assertEquals(expected, actual);
}
}
View
BIN  kitaos-android/assets/fonts/TulpenOne-Regular.ttf
Binary file not shown
View
6 kitaos-android/src/org/agilespain/kitaos/service/TalksJsonHandler.java
@@ -74,7 +74,11 @@ public TalksJsonHandler() {
builder = ContentProviderOperation.newInsert(Talks.uri());
builder.withValue(Talks._ID, id);
builder.withValue(Talks.TITLE, curTalk.getString(TalksJson.TITLE).trim());
- builder.withValue(Talks.DESCRIPTION, curTalk.getString(TalksJson.DESCRIPTION).trim());
+
+ if(curTalk.has(Talks.DESCRIPTION)) {
+ builder.withValue(Talks.DESCRIPTION, curTalk.getString(TalksJson.DESCRIPTION).trim());
+ }
+
builder.withValue(Talks.ROOM, curTalk.getJSONObject(TalksJson.ROOM).getString(TalksJson.NAME).trim());
String date = curTalk.getString(TalksJson.DATE).trim() + " " + normalizeTime(curTalk.getString(TalksJson.HOUR)) ;
View
23 kitaos-android/src/org/agilespain/kitaos/widget/PostitView.java
@@ -21,19 +21,14 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
-import android.graphics.Typeface;
-import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.text.TextUtils;
-import android.util.Log;
import android.view.Gravity;
import android.view.View;
-import android.widget.TextView;
import org.agilespain.kitaos.R;
import org.agilespain.kitaos.provider.KitaosContract;
-import java.io.IOException;
import java.util.Random;
/**
@@ -56,19 +51,27 @@ public PostitView(Context context, long blockId, String title, long startTime,
setTextColor(Color.BLACK);
setPostitTypeface();
- Random random = new Random();
+ initRotation(title.length());
- rotation = random.nextInt(5) * (random.nextBoolean()?-1:1);
-
- setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL | Gravity.FILL_VERTICAL);
+ setMaxLines(4);
+ setGravity(Gravity.CENTER);
- setMaxLines(2);
setEllipsize(TextUtils.TruncateAt.END);
this._id = blockId;
setOnClickListener(this);
}
+ /**
+ * Rotate the text to simulate handmade writing
+ * @param length
+ */
+ protected void initRotation(int length) {
+ //Random random = new Random();
+ rotation = (length % 5) * (length>10?-1:1);
+ }
+
+
@Override
protected void onDraw(Canvas c) {
c.rotate(rotation);
View
3  kitaos-android/src/org/agilespain/kitaos/widget/TypefaceUtils.java
@@ -12,7 +12,8 @@
*/
public class TypefaceUtils {
public static Typeface getNormalFont(Context context) {
- String ttf = "fonts/ShadowsIntoLightTwo-Regular.ttf";
+ // String ttf = "fonts/ShadowsIntoLightTwo-Regular.ttf";
+ String ttf = "fonts/TulpenOne-Regular.ttf";
return Typeface.createFromAsset(context.getAssets(), ttf);
}
Please sign in to comment.
Something went wrong with that request. Please try again.