Revision 01d34e10
Added by Leszek Koltunski almost 9 years ago
| src/main/java/org/distorted/examples/save/SaveActivity.java | ||
|---|---|---|
| 75 | 75 |
@Override |
| 76 | 76 |
protected void onPause() |
| 77 | 77 |
{
|
| 78 |
SaveWorkerThread.stopSending(); |
|
| 79 |
|
|
| 80 | 78 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView); |
| 81 | 79 |
view.onPause(); |
| 82 | 80 |
|
| ... | ... | |
| 93 | 91 |
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.saveSurfaceView); |
| 94 | 92 |
view.onResume(); |
| 95 | 93 |
|
| 96 |
SaveWorkerThread.startSending(this);
|
|
| 94 |
SaveWorkerThread.create(this);
|
|
| 97 | 95 |
} |
| 98 | 96 |
|
| 99 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/examples/save/SaveWorkerThread.java | ||
|---|---|---|
| 37 | 37 |
{
|
| 38 | 38 |
private static Vector<WorkLoad> mBuffers; |
| 39 | 39 |
private static SaveWorkerThread mThis=null; |
| 40 |
private static volatile boolean mPaused; |
|
| 41 | 40 |
private static WeakReference<Activity> mWeakAct; |
| 42 | 41 |
|
| 43 | 42 |
private static class WorkLoad |
| ... | ... | |
| 64 | 63 |
|
| 65 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 66 | 65 |
|
| 67 |
static void startSending(Activity act)
|
|
| 66 |
static void create(Activity act)
|
|
| 68 | 67 |
{
|
| 69 | 68 |
mWeakAct = new WeakReference(act); |
| 70 | 69 |
|
| 71 |
mPaused = false; |
|
| 72 |
|
|
| 73 | 70 |
if( mThis==null ) |
| 74 | 71 |
{
|
| 75 | 72 |
mBuffers = new Vector<>(); |
| 76 | 73 |
mThis = new SaveWorkerThread(); |
| 77 | 74 |
mThis.start(); |
| 78 | 75 |
} |
| 79 |
else |
|
| 80 |
{
|
|
| 81 |
synchronized(mThis) |
|
| 82 |
{
|
|
| 83 |
mThis.notify(); |
|
| 84 |
} |
|
| 85 |
} |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 |
|
|
| 90 |
static void stopSending() |
|
| 91 |
{
|
|
| 92 |
mPaused = true; |
|
| 93 | 76 |
} |
| 94 | 77 |
|
| 95 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 106 | 89 |
process(load); |
| 107 | 90 |
} |
| 108 | 91 |
|
| 109 |
if( mPaused )
|
|
| 92 |
synchronized(mThis)
|
|
| 110 | 93 |
{
|
| 111 |
synchronized(mThis) |
|
| 112 |
{
|
|
| 113 |
try { mThis.wait(); }
|
|
| 114 |
catch(InterruptedException ex) { }
|
|
| 115 |
} |
|
| 94 |
try { mThis.wait(); }
|
|
| 95 |
catch(InterruptedException ex) { }
|
|
| 116 | 96 |
} |
| 117 | 97 |
} |
| 118 | 98 |
} |
| ... | ... | |
| 123 | 103 |
{
|
| 124 | 104 |
WorkLoad load = new WorkLoad(buffer,width,height,filename); |
| 125 | 105 |
mBuffers.add(load); |
| 106 |
|
|
| 107 |
synchronized(mThis) |
|
| 108 |
{
|
|
| 109 |
mThis.notify(); |
|
| 110 |
} |
|
| 126 | 111 |
} |
| 127 | 112 |
|
| 128 | 113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Fix the 'Save' app so that the saving thread does not run all the time in a tight loop