Skip to content

Commit

Permalink
Moved the file to the assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
alt236 committed Jan 30, 2013
1 parent 1631909 commit 6f14acb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
File renamed without changes.
37 changes: 26 additions & 11 deletions src/com/martinadamek/jsonandroid/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.martinadamek.jsonandroid;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -8,16 +9,19 @@
import java.util.Map;

import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends Activity {
private static final String ASSET_TWITTER_TIMELINE = "public_timeline.json";
private static final String DATA_LINE_PADDING = " ";

private static final String TAG = MainActivity.class.getName();
private String mPath;

private TextView mTextView;

private AssetManager mAssetsManager;

private final Runnable mTestTask = new Runnable() {
public void run() {

Expand Down Expand Up @@ -91,29 +95,40 @@ public void run() {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

mTextView = (TextView) findViewById(R.id.text);

mPath = "com/martinadamek/jsonandroid/public_timeline.json";

mTextView.setText("Running tests...");
mAssetsManager = getAssets();

mTextView.setText("Running tests (API Level: " + android.os.Build.VERSION.SDK_INT + ")..." );
writeToTextView("-----------------");

new Thread(mTestTask).start();
}

private InputStream getAssetStream(String assetName){
InputStream res;

try {
res = mAssetsManager.open( assetName );
} catch (IOException e) {
Log.e(TAG, "ERROR opening asset '" + assetName + "': " + e.getMessage(), e);
res = null;
}

return res;
}

private long test(final TestJson testJson, int repeats) {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(mPath);
InputStream inputStream = getAssetStream(ASSET_TWITTER_TIMELINE);

List<Map> result = testJson.parsePublicTimeline(inputStream);
verify(result);

long duration = 0;

for (int i = 0; i < repeats; i++) {
inputStream = getClass().getClassLoader().getResourceAsStream(mPath);
inputStream = getAssetStream(ASSET_TWITTER_TIMELINE);
long start = System.currentTimeMillis();
testJson.parsePublicTimeline(inputStream);
duration += (System.currentTimeMillis() - start);
Expand Down Expand Up @@ -147,7 +162,7 @@ public void run() {
private void warmUp(final TestJson testJson) {
InputStream inputStream;
for (int i = 0; i < 5; i++) {
inputStream = getClass().getClassLoader().getResourceAsStream(mPath);
inputStream = getAssetStream(ASSET_TWITTER_TIMELINE);
testJson.parsePublicTimeline(inputStream);
}
}
Expand Down

0 comments on commit 6f14acb

Please sign in to comment.