Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: hstefan/ThreadingExample
base: 60e20435d4
...
head fork: hstefan/ThreadingExample
compare: 8f713d28d1
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
3  res/layout/main.xml
@@ -2,7 +2,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:layout_margin="10dip"
android:gravity="center_horizontal"
android:orientation="vertical" >
@@ -31,7 +30,7 @@
<ListView
android:id="@+id/lResultList"
- android:layout_width="match_parent"
+ android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
View
28 res/layout/result_item.xml
@@ -2,25 +2,25 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:orientation="vertical" >
+ android:orientation="horizontal" >
- <LinearLayout android:orientation="horizontal"
- android:gravity="left">
- <TextView android:id="@+id/runTimestampDate"
- android:textSize="12sp"/>
- <TextView android:id="@+id/runTimestampTime"
- android:textSize="12sp"/>
- </LinearLayout>
-
- <TextView android:id="@+id/threadNum"
- android:layout_gravity="center"
+ <TextView android:id="@+id/runTimestampDate"
+ android:textSize="12sp"
android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:textSize="16sp" />
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:gravity="left"/>
<TextView android:id="@+id/time"
- android:layout_gravity="right"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:textSize="16sp"
+ android:gravity="center_horizontal"/>
+ <TextView android:id="@+id/threadNum"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1"
+ android:gravity="right"
android:textSize="16sp" />
</LinearLayout>
View
66 src/com/hstefan/threadingexample/ThreadingExampleActivity.java
@@ -1,22 +1,29 @@
package com.hstefan.threadingexample;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.List;
import java.util.concurrent.Executor;
import com.hstefan.threadingexample.DotProductThreadingSingleton.OnDotProductCalculationListener;
+import com.hstefan.threadingexample.db.ResultDbOpenHelper;
import android.app.Activity;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.provider.BaseColumns;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
-import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
-import android.widget.TextView;
+import android.widget.ListView;
+import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class ThreadingExampleActivity extends Activity implements VectorGenerationTask.OnTaskFinishedListener<Float[]>,
@@ -27,8 +34,18 @@
private List<AsyncTask<Integer, Void, Float>> m_Tasks;
private DotProductThreadingSingleton m_dotInstance;
private int m_numThreadsLRun;
+ private ResultDbOpenHelper m_resultsDbHelper;
+ private SQLiteDatabase m_resultDb;
+ private SimpleCursorAdapter m_rAdapter;
+
public static final int VEC_SIZE = 80000;
+ private static String[] RESULT_DB_COLUMNS= new String[]{ BaseColumns._ID,
+ ResultDbOpenHelper.RESULT_DATE, ResultDbOpenHelper.RESULT_NUMTHREADS,
+ ResultDbOpenHelper.RESULT_PROCTIME};
+ private static int RESULT_DB_COLUMNS_LAYOUT[] = new int[]{
+ R.id.runTimestampDate, R.id.threadNum, R.id.time
+ };
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -44,8 +61,31 @@ public void onCreate(Bundle savedInstanceState) {
m_dotInstance.setOnDotProductCalculationListener(this);
m_Tasks = new ArrayList<AsyncTask<Integer,Void,Float>>();
m_numThreadsLRun = 0;
+
+ m_resultsDbHelper = new ResultDbOpenHelper(this);
+ m_resultDb = m_resultsDbHelper.getWritableDatabase();
+
+ Cursor c = m_resultDb.query(ResultDbOpenHelper.RESULT_TABLE,
+ RESULT_DB_COLUMNS, null, null, null, null, null);
+ m_rAdapter = new SimpleCursorAdapter(this, R.layout.result_item, c, new String[]{
+ ResultDbOpenHelper.RESULT_DATE, ResultDbOpenHelper.RESULT_NUMTHREADS,
+ ResultDbOpenHelper.RESULT_PROCTIME} ,
+ RESULT_DB_COLUMNS_LAYOUT);
+
+ ListView lView = (ListView)findViewById(R.id.lResultList);
+ lView.setAdapter(m_rAdapter);
super.onCreate(savedInstanceState);
}
+
+
+
+ @Override
+ protected void onDestroy() {
+ m_resultsDbHelper.getWritableDatabase().close();
+ super.onDestroy();
+ }
+
+
@Override
public void onTaskFinish(Float[][] result) {
@@ -95,15 +135,17 @@ private void calculateDotProduct(int numThreads) {
@Override
public void onDotProductCalculation(float res) {
Log.d("MethodCall", "onDotProductCalculation");
- TextView tView = /*(TextView) findViewById(R.id.tvResult)*/ null;
- StringBuilder sBuilder = new StringBuilder();
- sBuilder.append("Program took ");
- sBuilder.append(m_dotInstance.getElapsedTime());
- sBuilder.append("ms to calculate dot product with ");
- sBuilder.append(m_numThreadsLRun);
- sBuilder.append(" thread(s) running.");
- tView.setText(sBuilder);
+ SQLiteDatabase db = m_resultsDbHelper.getWritableDatabase();
+ ContentValues values = new ContentValues();
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ values.put(ResultDbOpenHelper.RESULT_DATE, dateFormat.format(Calendar.getInstance().getTime()));
+ values.put(ResultDbOpenHelper.RESULT_NUMTHREADS, m_numThreadsLRun);
+ values.put(ResultDbOpenHelper.RESULT_PROCTIME, m_dotInstance.getElapsedTime());
+
+ db.insert(ResultDbOpenHelper.RESULT_TABLE, null, values);
+
+ m_rAdapter.getCursor().requery();
}
-
-
}

No commit comments for this range

Something went wrong with that request. Please try again.