This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void subSampleImage(int powerOf2) { | |
if(powerOf2 < 1 || powerOf2 > 8) { | |
Log.e(TAG, "trying to apply upscale or excessive downscale: "+powerOf2); | |
return; | |
} | |
final Resources res = getActivity().getResources(); | |
final BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = false; | |
options.inSampleSize = powerOf2; | |
final Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.brasil, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void readBitmapInfo() { | |
final Resources res = getActivity().getResources(); | |
final BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = true; | |
BitmapFactory.decodeResource(res, R.drawable.brasil, options); | |
final float imageHeight = options.outHeight; | |
final float imageWidth = options.outWidth; | |
final String imageMimeType = options.outMimeType; | |
Log.d(TAG, "w,h, type:"+imageWidth+", "+imageHeight+", "+imageMimeType); | |
Log.d(TAG, "estimated memory required in MB: "+imageWidth * imageHeight * BYTES_PER_PX/MemUtils.BYTES_IN_MB); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final float BYTES_IN_MB = 1024.0f * 1024.0f; | |
public static float megabytesFree() { | |
final Runtime rt = Runtime.getRuntime(); | |
final float bytesUsed = rt.totalMemory(); | |
final float mbUsed = bytesUsed/BYTES_IN_MB; | |
final float mbFree = megabytesAvailable() - mbUsed; | |
return mbFree; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestSample extends AndroidTestCase{ | |
private int mFinalValue; | |
private static final int EXPECTED_VALUE = 10; | |
private final HandlerThread mHandlerThread; | |
private SampleClass mInstance; | |
public void testDoAsync(){ | |
mInstance = new SampleClass(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestSample extends AndroidTestCase{ | |
private int mFinalValue; | |
private static final int EXPECTED_VALUE = 10; | |
public void testDoAsync(){ | |
SampleClass s = new SampleClass(); | |
Listener l = new ListenerImpl(); | |
Semaphore semaphore = new Semaphore(0); | |
s.doAsync(); | |
semaphore.acquire(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestSample extends AndroidTestCase{ | |
public void testDoAsync(){ | |
SampleClass s = new SampleClass(); | |
Listener l = new ListenerImpl(); | |
s.doAsync(); | |
} | |
private class ListenerImpl implements Listener{ | |
public void onValueChanged(int i){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface SampleClass { | |
void doAsync(Listener l); | |
public interface Listener{ | |
void onValueChanged(int i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
//... init code ... | |
ViewTreeObserver vto = mRootView.getViewTreeObserver(); | |
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListenerImpl()); | |
} | |
private void resizeBigView(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean signal = false; | |
synchMethod(){ | |
// do something... | |
callAsycnMethod(callback); | |
synchronized(this){ | |
while(!signal){ | |
try{ |
NewerOlder