Created
May 14, 2019 17:38
-
-
Save Ayyagaries/2d17078c2726da3791066c67301de36c to your computer and use it in GitHub Desktop.
test
This file contains hidden or 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
package com.intellicentrics.sec3ure_badge; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.AsyncTask; | |
import android.util.Log; | |
import androidx.localbroadcastmanager.content.LocalBroadcastManager; | |
import com.ix.ebadgesdk.EBadgeBleManager; | |
import java.util.ArrayList; | |
public class BatchProcess extends AsyncTask<ArrayList<ebadgeJob>,Integer,Integer>{ | |
private static final String TAG = "BatchProcess"; | |
private EBadgeBleManager mBleManager; | |
private boolean bUpdating; | |
private int retCode; | |
private int jobTypeExecuted; | |
private Context context; | |
public BatchProcess(EBadgeBleManager bleManager,Context context ) { | |
mBleManager = bleManager; | |
bUpdating = false; | |
context = context; | |
} | |
@Override | |
protected void onPostExecute(Integer integer) { | |
super.onPostExecute(integer); | |
Log.d("TEST", "I am in POST EXECUTE batch process"); | |
Log.d("sender", "Broadcasting message"); | |
} | |
@Override | |
protected void onPreExecute() { | |
super.onPreExecute(); | |
} | |
@Override | |
protected Integer doInBackground(ArrayList<ebadgeJob>... jobs) { | |
Log.d("TEST", "I am in asyctask batch process do in background"); | |
int count = jobs[0].size(); | |
for (int i = 0; i < count; i++) { | |
try { | |
Log.d(TAG, String.format("executing job: %d", i)); | |
if (bUpdating) { | |
synchronized (this) { | |
this.wait(); | |
} | |
} | |
ebadgeJob job = jobs[0].get(i); | |
Log.d("TEST", "Inside the batch process with JOB type" + job.jobType + ""); | |
switch (job.jobType) { | |
case ebadgeJob.SEND_IMAGE: | |
bUpdating = true; | |
mBleManager.sendImageBuffer(job.imageData); | |
Log.d("TEST","I am in send image"); | |
break; | |
case ebadgeJob.SET_PAGE: | |
bUpdating = true; | |
mBleManager.setImageConfig(job.pageId, 1, job.expireTime, job.timeout, job.imageConfig); | |
Log.d("TEST","I am in set page"); | |
break; | |
case ebadgeJob.REFRESH_PAGE: | |
bUpdating = true; | |
mBleManager.refresh(job.pageId); | |
Log.d("TEST","I am in refresh page"); | |
break; | |
case ebadgeJob.CLEAR_ID: | |
bUpdating = true; | |
mBleManager.deleteImage(job.id_list); | |
Log.d("TEST","I am in clear ids"); | |
break; | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
publishProgress((int) ((i / (float) count) * 100)); | |
// Escape early if cancel() is called | |
if (isCancelled()) break; | |
} | |
return 0; | |
} | |
public boolean readSemaphore() { | |
return bUpdating; | |
} | |
public void clearSemaphore(byte retCode) { | |
if (bUpdating == true) { | |
this.retCode = retCode; | |
Log.d(TAG, String.format("update result: %02X", retCode)); | |
synchronized (this) { | |
bUpdating = false; | |
this.notify(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment