Skip to content

Commit

Permalink
update demo test.
Browse files Browse the repository at this point in the history
  • Loading branch information
郑晓勇 committed Apr 24, 2017
1 parent b0716f4 commit 457ebd2
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 286 deletions.
12 changes: 9 additions & 3 deletions app/src/main/java/com/zxy/tiny/test/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class BaseActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
Runtime.getRuntime().gc();

gcAndFinalize();
}

void startActivity(Class clazz) {
Expand All @@ -26,6 +25,13 @@ void startActivity(Class clazz) {
@Override
protected void onDestroy() {
super.onDestroy();
Runtime.getRuntime().gc();
gcAndFinalize();
}

void gcAndFinalize() {
Runtime runtime = Runtime.getRuntime();
System.gc();
runtime.runFinalization();
System.gc();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Formatter;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -83,47 +82,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.action_file:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testFile();
}
}, 500);
gcAndFinalize();
testFile();
break;
case R.id.action_bitmap:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testBitmap();
}
}, 500);
gcAndFinalize();
testBitmap();
break;
case R.id.action_res:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testResource();
}
}, 500);
gcAndFinalize();
testResource();
break;
case R.id.action_uri:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testUri();
}
}, 500);
gcAndFinalize();
testUri();
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.text.format.Formatter;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -19,7 +17,7 @@
import java.io.FileOutputStream;
import java.io.InputStream;

public class BatchFileCompressTestActivity extends AppCompatActivity {
public class BatchFileCompressTestActivity extends BaseActivity {

private ImageView mOriginImg1;

Expand Down Expand Up @@ -83,47 +81,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.action_file:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testFile();
}
}, 500);
gcAndFinalize();
testFile();
break;
case R.id.action_bitmap:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testBitmap();
}
}, 500);
gcAndFinalize();
testBitmap();
break;
case R.id.action_res:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testResource();
}
}, 500);
gcAndFinalize();
testResource();
break;
case R.id.action_uri:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testUri();
}
}, 500);
gcAndFinalize();
testUri();
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.text.format.Formatter;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -19,7 +17,7 @@
import java.io.FileOutputStream;
import java.io.InputStream;

public class BatchFileWithReturnBitmapCompressTestActivity extends AppCompatActivity {
public class BatchFileWithReturnBitmapCompressTestActivity extends BaseActivity {

private ImageView mOriginImg1;

Expand Down Expand Up @@ -83,47 +81,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
case R.id.action_file:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testFile();
}
}, 500);
gcAndFinalize();
testFile();
break;
case R.id.action_bitmap:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testBitmap();
}
}, 500);
gcAndFinalize();
testBitmap();
break;
case R.id.action_res:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testResource();
}
}, 500);
gcAndFinalize();
testResource();
break;
case R.id.action_uri:
free();
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testUri();
}
}, 500);
gcAndFinalize();
testUri();
break;
default:
break;
Expand Down
76 changes: 14 additions & 62 deletions app/src/main/java/com/zxy/tiny/test/BitmapCompressTestActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Formatter;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -55,7 +54,8 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
switch (id) {
case R.id.action_config:
if (mConfig == Bitmap.Config.ARGB_8888) {
Expand All @@ -68,77 +68,29 @@ public boolean onOptionsItemSelected(MenuItem item) {

break;
case R.id.action_bytes:
mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
//free memory for test
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testBytes();
}
}, 500);
gcAndFinalize();
testBytes();
break;
case R.id.action_file:
mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testFile();
}
}, 500);
gcAndFinalize();
testFile();
break;
case R.id.action_bitmap:
mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testBitmap();
}
}, 500);
gcAndFinalize();
testBitmap();
break;
case R.id.action_stream:
mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testStream();
}
}, 500);
gcAndFinalize();
testStream();
break;
case R.id.action_res:
mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testResource();
}
}, 500);
gcAndFinalize();
testResource();
break;
case R.id.action_uri:
mOriginImg.setImageBitmap(null);
mCompressImg.setImageBitmap(null);
Runtime.getRuntime().gc();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Runtime.getRuntime().gc();
testUri();
}
}, 500);
gcAndFinalize();
testUri();
break;
default:
break;
Expand Down
Loading

0 comments on commit 457ebd2

Please sign in to comment.