Commits

littledot5566  committed 9109211

*Implementing TreasureActivity. *Added some treasure icons.

  • Participants
  • Parent commits f139352

Comments (0)

Files changed (16)

File AndroidManifest.xml

         <!--  -->
         <activity android:name=".components.HistoryActivity" >
         </activity>
+        <!--  -->
+        <activity android:name=".components.TreasureActivity" >
+        </activity>
     </application>
 
 </manifest>

File release/TODO.txt

 v delete expedition from history.
 * Help/About/Credits button telling users what this app is about, thanks for icons, etc.
 * Expedition statistics. Graph of travelled distance over days, etc.
-* Display treasure in a trophy case.
+* Display treasure in a trophy case.
+* Distance from destination, distance travelled in MapAct.
+* "Displayable" column for Expeditions. Don't delete data. (do last)
+*

File res/drawable/item_iron_ore_24_24.png

Added
New image

File res/drawable/item_leather_24_24.png

Added
New image

File res/drawable/item_wood_24_24.png

Added
New image

File res/layout/chest_act.xml

-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:orientation="vertical" >
-
-    <GridView
-        android:id="@+id/chest_gv_frame"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent"
-        android:columnWidth="90dp"
-        android:gravity="center"
-        android:horizontalSpacing="10dp"
-        android:numColumns="auto_fit"
-        android:stretchMode="columnWidth"
-        android:verticalSpacing="10dp" />
-
-</LinearLayout>

File res/layout/treasure_act.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <GridView
+        android:id="@+id/chest_gv_frame"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:columnWidth="90dp"
+        android:gravity="center"
+        android:horizontalSpacing="10dp"
+        android:numColumns="auto_fit"
+        android:stretchMode="columnWidth"
+        android:verticalSpacing="10dp" />
+
+</LinearLayout>

File res/layout/treasure_item.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <ImageView
+        android:id="@+id/tItem_iv_image"
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent" />
+
+</LinearLayout>

File src/nctuw/littledot/localtreasure/components/HistoryActivityAdapter.java

 
 	private ArrayList<ContentValues> mData = new ArrayList<ContentValues>();
 
-	private ArrayList<String> dbg = new ArrayList<String>();
-
 	public HistoryActivityAdapter(Context ctx) {
 		mCtx = ctx;
 		mDB = new Database(ctx).open(Database.MODE_READ);
 				ContentValues kv = Expedition.toContentValues(cur);
 				kv.putAll(Profile.toContentValues(cur));
 				mData.add(kv);
-				dbg.add(DatabaseUtils.dumpCurrentRowToString(cur));
 
 				cur.moveToNext();
 			}

File src/nctuw/littledot/localtreasure/components/TreasureActivity.java

 
 	private GridView gvTreasure;
 
+	private TreasureActivityAdapter mAdapter;
+
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 
+		setContentView(R.layout.treasure_act);
 		gvTreasure = (GridView) findViewById(R.id.chest_gv_frame);
 
+		mAdapter = new TreasureActivityAdapter(this);
+		gvTreasure.setAdapter(mAdapter);
 	}
 
 	@Override

File src/nctuw/littledot/localtreasure/components/TreasureActivityAdapter.java

 package nctuw.littledot.localtreasure.components;
 
+import java.util.ArrayList;
+
+import nctuw.littledot.localtreasure.R;
 import nctuw.littledot.localtreasure.database.Database;
+import nctuw.littledot.localtreasure.database.Expedition;
+import android.content.Context;
+import android.database.Cursor;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.BaseAdapter;
+import android.widget.ImageView;
 
 public class TreasureActivityAdapter extends BaseAdapter {
-
+	private Context mCtx;
 	private Database mDB;
+	private ArrayList<Expedition> mData = new ArrayList<Expedition>();
+
+	public TreasureActivityAdapter(Context ctx) {
+		mCtx = ctx;
+		mDB = new Database(ctx).open(Database.MODE_READ);
+
+		Cursor cur = mDB.rawQuery(String.format("SELECT * FROM %s WHERE %s>0",
+				Expedition.TABLE_NAME, Expedition.KEY_TREASURE));
+
+		if (cur.moveToFirst()) {
+			while (!cur.isAfterLast()) {
+				mData.add(new Expedition(cur));
+				cur.moveToNext();
+			}
+		}
+
+		cur.close();
+		mDB.close();
+	}
 
 	@Override
 	public int getCount() {
-		return 0;
+		return mData.size();
 	}
 
 	@Override
 	public Object getItem(int arg0) {
-		return null;
+		return mData.get(arg0);
 	}
 
 	@Override
 	public long getItemId(int position) {
-		return 0;
+		return mData.get(position).getEID();
 	}
 
 	@Override
-	public View getView(int position, View convertView, ViewGroup parent) {
-		return null;
-	}
+	public View getView(int position, View view, ViewGroup parent) {
+
+		if (view == null) {
+			LayoutInflater inflater = (LayoutInflater) mCtx
+					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+			view = inflater.inflate(R.layout.treasure_item, parent, false);
+		}
 
+		ImageView ivTreasure = (ImageView) view.findViewById(R.id.tItem_iv_image);
+
+		ivTreasure.setImageResource(mData.get(position).getPrize().getDrawableID());
+
+		return view;
+	}
 }

File src/nctuw/littledot/localtreasure/database/Database.java

 	}
 
 	public ArrayList<Expedition> queryExpeditions(String where) {
-		String query = "";
-		if (where.equals("*"))
-			query = new StringBuilder("select * from ")
-					.append(Expedition.TABLE_NAME).toString();
+		String query = "select * from " + Expedition.TABLE_NAME + ' ';
+		if (!where.equals("*"))
+			query += where;
 
 		Cursor cur = rawQuery(query);
 

File src/nctuw/littledot/localtreasure/database/Expedition.java

 		}
 		if (mPrize != null) {
 			keys.add(KEY_TREASURE);
-			vals.add(mPrize.getID());
+			vals.add(mPrize.getTID());
 		}
 
 		return Database.toContentValues(

File src/nctuw/littledot/localtreasure/database/Query.java

-package nctuw.littledot.localtreasure.database;
-
-public class Query {
-
-}

File src/nctuw/littledot/localtreasure/database/SQL.java

+package nctuw.littledot.localtreasure.database;
+
+public class SQL {
+
+}

File src/nctuw/littledot/localtreasure/database/Treasure.java

 import android.os.Parcelable;
 
 public enum Treasure {
-	APPLE(1, R.drawable.treasure_apple_256, "Apple"),
-	ORANGE(2, R.drawable.treasure_orange_256, "Orange"),
-	BANANA(3, R.drawable.treasure_banana_256, "Banana");
+	WOOD(1, R.drawable.item_wood_24_24, "Wood"),
+	LEATHER(2, R.drawable.item_leather_24_24, "Leather"),
+	IRON_ORE(3, R.drawable.item_iron_ore_24_24, "Iron Ore");
 
 	private final int mID;
 	private final int mDrawableID;
 		mName = n;
 	}
 
-	public int getID() {
+	public int getTID() {
 		return mID;
 	}