Skip to content

Commit

Permalink
Merge branch 'master' into inline_entity_tiles
Browse files Browse the repository at this point in the history
Conflicts:
	app/res/values/colors.xml
  • Loading branch information
ctsims committed Nov 5, 2014
2 parents 37ebdff + 3aac4b0 commit 80fdda8
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 27 deletions.
3 changes: 3 additions & 0 deletions app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
<classpathentry exported="true" kind="lib" path="/opendatakit.collect/lib/joda-time-2.0.jar"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry exported="true" kind="lib" path="lib/achartengine-1.2.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/htmlcleaner-2.2.1.jar"/>
<classpathentry exported="true" kind="lib" path="lib/osbcp-css-parser-1.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/htmlspanner.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
File renamed without changes.
4 changes: 2 additions & 2 deletions app/res/drawable/background_red.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/red" />
<stroke android:color="@color/red"
<solid android:color="@color/red_soft" />
<stroke android:color="@color/red_soft"
android:width="4dp"/>
<corners android:radius="18dp"/>
</shape>
Expand Down
4 changes: 2 additions & 2 deletions app/res/drawable/background_yellow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/yellow" />
<stroke android:color="@color/yellow"
<solid android:color="@color/yellow_soft" />
<stroke android:color="@color/yellow_soft"
android:width="4dp"/>
<corners android:radius="18dp"/>
</shape>
Expand Down
14 changes: 8 additions & 6 deletions app/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@

<color name="yellow">#FFE88F</color>
<color name="yellow_green">#DDECAC</color>
<color name="yellow_soft">#FFFF99</color>
<color name="green">#87D13E</color>

<color name="red">#FF0000</color>

<color name="bright_green_grad_start">#2C9746</color>
<color name="red">#FF0000</color>
<color name="red_soft">#EE5555</color>

<color name="bright_green_grad_start">#2C9746</color>
<color name="bright_green_grad_end">#247A38</color>
<color name="dark_green_start">#228038</color>
<color name="dark_green_end">#1C662D</color>
<color name="dark_green_start">#228038</color>
<color name="dark_green_end">#1C662D</color>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Hashtable;
import java.util.Vector;

import org.commcare.android.database.DbHelper;
import org.commcare.android.database.SqlStorage;
import org.commcare.android.database.SqlStorageIterator;
import org.commcare.android.database.user.models.ACase;
Expand All @@ -22,23 +23,38 @@
public class AndroidLedgerInstanceTreeElement extends LedgerInstanceTreeElement {
SqlStorageIterator<Ledger> iter;

Hashtable<String, Integer> primaryIdMapping;

public AndroidLedgerInstanceTreeElement(AbstractTreeElement instanceRoot, SqlStorage<Ledger> storage) {
super(instanceRoot, storage);
primaryIdMapping = null;
}

@Override
protected Hashtable<String, Integer> getKeyMapping(String keyId) {
if(keyId.equals(Ledger.INDEX_ENTITY_ID) && primaryIdMapping != null) {
return primaryIdMapping;
} else {
return null;
}
}

@Override
protected synchronized void getLedgers() {
if(ledgers != null) {
return;
}
objectIdMapping = new Hashtable<Integer, Integer>();
ledgers = new Vector<LedgerChildElement>();
primaryIdMapping = new Hashtable<String, Integer>();
int mult = 0;
for(IStorageIterator i = ((SqlStorage<ACase>)getStorage()).iterate(false); i.hasMore();) {
int id = i.nextID();
for(IStorageIterator i = ((SqlStorage<ACase>)getStorage()).iterate(false, Ledger.INDEX_ENTITY_ID); i.hasMore();) {
int id = i.peekID();
ledgers.addElement(new LedgerChildElement(this, id, null, mult));
objectIdMapping.put(DataUtil.integer(id), DataUtil.integer(mult));
primaryIdMapping.put(((SqlStorageIterator)i).getPrimaryId(),DataUtil.integer(id));
mult++;
i.nextID();
}
}

Expand Down
20 changes: 20 additions & 0 deletions app/src/org/commcare/android/database/SqlStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ public SqlStorageIterator<T> iterate(boolean includeData) {
}


/**
* Creates a custom iterator for this storage which can either include or exclude the actual data, and
* additionally collects a primary ID that will be returned and available during iteration.
*
* Useful for situations where the iterator is loading data that will be indexed by the primary id
* since it will prevent the need to turn that primary id into the storage key for retrieving each
* record.
*
* TODO: This is a bit too close to comfort to the other custom iterator. It's possible we should just
* have a method to query for all metadata?
*
* @param includeData True to return an iterator with all records. False to return only the index.
* @param primaryId a metadata index that
*/
public SqlStorageIterator<T> iterate(boolean includeData, String primaryId) {
String[] projection = includeData ? new String[] {DbUtil.ID_COL, DbUtil.DATA_COL, TableBuilder.scrubName(primaryId)} : new String[] {DbUtil.ID_COL, TableBuilder.scrubName(primaryId)};
Cursor c = helper.getHandle().query(table, projection, null, null, null, null, DbUtil.ID_COL);
return new SqlStorageIterator<T>(c, this, TableBuilder.scrubName(primaryId));
}

public Iterator<T> iterator() {
return iterate();
}
Expand Down
20 changes: 19 additions & 1 deletion app/src/org/commcare/android/database/SqlStorageIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,24 @@ public class SqlStorageIterator<T extends Persistable> implements IStorageIterat
SqlStorage<T> storage;
boolean isClosedByProgress = false;
int count;

String primaryId;

public SqlStorageIterator(Cursor c, SqlStorage<T> storage) {
this(c, storage, null);
}

/**
* Creates an iterator into either a full or partial sql storage.
*
* @param c The uninitialized cursor for a query.
* @param storage The storage being queried
* @param primaryId An optional key index for a primary id that is part
* of the returned iterator
*/
public SqlStorageIterator(Cursor c, SqlStorage<T> storage, String primaryId) {
this.c = c;
this.storage = storage;
this.primaryId = primaryId;
count = c.getCount();
if(count == 0) {
c.close();
Expand Down Expand Up @@ -113,4 +127,8 @@ private byte[] getBlob() {
private Cursor getRawCursor() {
return c;
}

public String getPrimaryId() {
return c.getString(c.getColumnIndexOrThrow(primaryId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public class CommCareUserOpenHelper extends SQLiteOpenHelper {
/**
* Version History
* V.4 - Added Stock table for tracking quantities. Fixed Case ID index
* V.5 - Fixed Ledger Stock ID's
*/
private static final int USER_DB_VERSION = 4;
private static final int USER_DB_VERSION = 5;

private static final String USER_DB_LOCATOR = "database_sandbox_";

Expand Down Expand Up @@ -91,6 +92,8 @@ public void onCreate(SQLiteDatabase database) {
database.execSQL("CREATE INDEX case_type_index ON AndroidCase (case_type)");
database.execSQL("CREATE INDEX case_status_index ON AndroidCase (case_status)");

database.execSQL("CREATE INDEX ledger_entity_id ON ledger (entity_id)");

database.setVersion(USER_DB_VERSION);

database.setTransactionSuccessful();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public void upgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
oldVersion = 4;
}
}

if(oldVersion == 4) {
if(upgradeFourFive(db, oldVersion, newVersion)) {
oldVersion = 5;
}
}
}

private boolean upgradeOneTwo(final SQLiteDatabase db, int oldVersion, int newVersion) {
Expand Down Expand Up @@ -82,6 +88,17 @@ private boolean upgradeThreeFour(SQLiteDatabase db, int oldVersion, int newVersi
db.endTransaction();
}
}

private boolean upgradeFourFive(SQLiteDatabase db, int oldVersion, int newVersion) {
db.beginTransaction();
try {
db.execSQL("CREATE INDEX ledger_entity_id ON ledger (entity_id)");
db.setTransactionSuccessful();
return true;
} finally {
db.endTransaction();
}
}

private void updateIndexes(SQLiteDatabase db) {
db.execSQL("CREATE INDEX case_id_index ON AndroidCase (case_id)");
Expand Down
4 changes: 2 additions & 2 deletions app/src/org/commcare/android/logic/GlobalConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class GlobalConstants {

public static final String FILE_CC_INSTALL = "commcare/install";
public static final String FILE_CC_UPGRADE = "commcare/upgrade";
public static final String FILE_CC_UPGRADE = "commcare/upgrade/sandbox/";
public static final String FILE_CC_CACHE = "commcare/cache";
public static final String FILE_CC_MEDIA = "commcare/media/";
public static final String FILE_CC_LOGS = "commcare/logs/";
Expand Down Expand Up @@ -31,7 +31,7 @@ public class GlobalConstants {

public static final String INSTALL_REF = "jr://file/commcare/install";

public static final String UPGRADE_REF = "jr://file/commcare/upgrade";
public static final String UPGRADE_REF = "jr://file/commcare/upgrade/sandbox";

public static final String ATTACHMENT_REF = "jr://file/attachments/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
*/
package org.commcare.android.util;

import java.util.HashSet;
import java.util.Vector;

import org.commcare.android.cases.AndroidCaseInstanceTreeElement;
import org.commcare.android.cases.AndroidLedgerInstanceTreeElement;
import org.commcare.android.database.SqlStorage;
import org.commcare.android.database.user.models.ACase;
import org.commcare.android.database.user.models.User;
Expand Down Expand Up @@ -43,7 +41,7 @@ public AbstractTreeElement generateRoot(ExternalDataInstance instance) {
if(ref.indexOf(LedgerInstanceTreeElement.MODEL_NAME) != -1) {
if(stockbase == null) {
SqlStorage<Ledger> storage = app.getUserStorage(Ledger.STORAGE_KEY, Ledger.class);
stockbase = new LedgerInstanceTreeElement(instance.getBase(), storage);
stockbase = new AndroidLedgerInstanceTreeElement(instance.getBase(), storage);
} else {
//re-use the existing model if it exists.
stockbase.rebase(instance.getBase());
Expand Down
27 changes: 20 additions & 7 deletions app/src/org/commcare/android/view/GraphView.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.model.XYValueSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import org.commcare.android.models.RangeXYValueSeries;
Expand Down Expand Up @@ -195,7 +196,9 @@ private void renderAnnotations() {
Vector<AnnotationData> annotations = mData.getAnnotations();
if (!annotations.isEmpty()) {
// Create a fake series for the annotations
XYSeries series = new XYSeries("");
// Using an XYSeries will fail for bubble graphs, but using an
// XYValueSeries will work for both xy graphs and bubble graphs
XYValueSeries series = new XYValueSeries("");
for (AnnotationData a : annotations) {
series.addAnnotation(a.getAnnotation(), a.getX(), a.getY());
}
Expand All @@ -215,7 +218,7 @@ private void renderAnnotations() {
* Apply any user-requested look and feel changes to graph.
*/
private void configureSeries(SeriesData s, XYSeriesRenderer currentRenderer) {
// Default to circular points, but allow Xs or no points at all
// Default to circular points, but allow other shapes or no points at all
String pointStyle = s.getConfiguration("point-style", "circle").toLowerCase();
if (!pointStyle.equals("none")) {
PointStyle style = null;
Expand All @@ -225,8 +228,18 @@ private void configureSeries(SeriesData s, XYSeriesRenderer currentRenderer) {
else if (pointStyle.equals("x")) {
style = PointStyle.X;
}
else if (pointStyle.equals("square")) {
style = PointStyle.SQUARE;
}
else if (pointStyle.equals("triangle")) {
style = PointStyle.TRIANGLE;
}
else if (pointStyle.equals("diamond")) {
style = PointStyle.DIAMOND;
}
currentRenderer.setPointStyle(style);
currentRenderer.setFillPoints(true);
currentRenderer.setPointStrokeWidth(2);
}

String lineColor = s.getConfiguration("line-color");
Expand Down Expand Up @@ -260,16 +273,16 @@ private void configure() {
// Default options
mRenderer.setBackgroundColor(mContext.getResources().getColor(R.drawable.white));
mRenderer.setMarginsColor(mContext.getResources().getColor(R.drawable.white));
mRenderer.setLabelsColor(mContext.getResources().getColor(R.drawable.black));
mRenderer.setXLabelsColor(mContext.getResources().getColor(R.drawable.black));
mRenderer.setYLabelsColor(0, mContext.getResources().getColor(R.drawable.black));
mRenderer.setYLabelsColor(1, mContext.getResources().getColor(R.drawable.black));
mRenderer.setLabelsColor(mContext.getResources().getColor(R.color.grey_darker));
mRenderer.setXLabelsColor(mContext.getResources().getColor(R.color.grey_darker));
mRenderer.setYLabelsColor(0, mContext.getResources().getColor(R.color.grey_darker));
mRenderer.setYLabelsColor(1, mContext.getResources().getColor(R.color.grey_darker));
mRenderer.setXLabelsAlign(Align.CENTER);
mRenderer.setYLabelsAlign(Align.RIGHT);
mRenderer.setYLabelsAlign(Align.LEFT, 1);
mRenderer.setYLabelsPadding(10);
mRenderer.setYAxisAlign(Align.RIGHT, 1);
mRenderer.setAxesColor(mContext.getResources().getColor(R.drawable.black));
mRenderer.setAxesColor(mContext.getResources().getColor(R.color.grey_lighter));
mRenderer.setLabelsTextSize(mTextSize);
mRenderer.setAxisTitleTextSize(mTextSize);
mRenderer.setApplyBackgroundColor(true);
Expand Down

0 comments on commit 80fdda8

Please sign in to comment.