use of android.os.Messenger in project android_frameworks_base by ResurrectionRemix.
the class ScreenrecordTile method takeScreenRecord.
private void takeScreenRecord() {
synchronized (mScreenrecordLock) {
if (mScreenrecordConnection != null) {
return;
}
Intent intent = new Intent(mContext, TakeScreenrecordService.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
synchronized (mScreenrecordLock) {
if (mScreenrecordConnection != this) {
return;
}
Messenger messenger = new Messenger(service);
Message msg = Message.obtain(null, 1);
final ServiceConnection myConn = this;
Handler h = new Handler(mHandler.getLooper()) {
@Override
public void handleMessage(Message msg) {
synchronized (mScreenrecordLock) {
if (mScreenrecordConnection == myConn) {
mContext.unbindService(mScreenrecordConnection);
mScreenrecordConnection = null;
mRecording = false;
mHandler.removeCallbacks(mScreenrecordTimeout);
}
}
}
};
msg.replyTo = new Messenger(h);
msg.arg1 = msg.arg2 = 0;
// Take the screenrecord
try {
messenger.send(msg);
} catch (RemoteException e) {
// Do nothing here
}
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
// Do nothing here
}
};
if (mContext.bindService(intent, conn, mContext.BIND_AUTO_CREATE)) {
mScreenrecordConnection = conn;
mRecording = true;
mHandler.postDelayed(mScreenrecordTimeout, 100000);
}
}
}
use of android.os.Messenger in project k-9 by k9mail.
the class OpenPgpApi method executeApiAsync.
public <T> CancelableBackgroundOperation executeApiAsync(Intent data, OpenPgpDataSource dataSource, OpenPgpDataSink<T> dataSink, final IOpenPgpSinkResultCallback<T> callback) {
Messenger messenger = new Messenger(new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
callback.onProgress(message.arg1, message.arg2);
return true;
}
}));
data.putExtra(EXTRA_PROGRESS_MESSENGER, messenger);
OpenPgpSourceSinkAsyncTask<T> task = new OpenPgpSourceSinkAsyncTask<>(data, dataSource, dataSink, callback);
// http://commonsware.com/blog/2012/04/20/asynctask-threading-regression-confirmed.html
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
} else {
task.execute((Void[]) null);
}
return task;
}
use of android.os.Messenger in project cw-omnibus by commonsguy.
the class Downloader method onHandleIntent.
@Override
public void onHandleIntent(Intent i) {
HttpGet getMethod = new HttpGet(i.getData().toString());
int result = Activity.RESULT_CANCELED;
try {
ResponseHandler<byte[]> responseHandler = new ByteArrayResponseHandler();
byte[] responseBody = client.execute(getMethod, responseHandler);
File output = new File(Environment.getExternalStorageDirectory(), i.getData().getLastPathSegment());
if (output.exists()) {
output.delete();
}
FileOutputStream fos = new FileOutputStream(output.getPath());
fos.write(responseBody);
fos.close();
result = Activity.RESULT_OK;
} catch (IOException e2) {
Log.e(getClass().getName(), "Exception in download", e2);
}
Bundle extras = i.getExtras();
if (extras != null) {
Messenger messenger = (Messenger) extras.get(EXTRA_MESSENGER);
Message msg = Message.obtain();
msg.arg1 = result;
try {
messenger.send(msg);
} catch (android.os.RemoteException e1) {
Log.w(getClass().getName(), "Exception sending message", e1);
}
}
}
use of android.os.Messenger in project cw-android by commonsguy.
the class Downloader method onHandleIntent.
@Override
public void onHandleIntent(Intent i) {
HttpGet getMethod = new HttpGet(i.getData().toString());
int result = Activity.RESULT_CANCELED;
try {
ResponseHandler<byte[]> responseHandler = new ByteArrayResponseHandler();
byte[] responseBody = client.execute(getMethod, responseHandler);
File output = new File(Environment.getExternalStorageDirectory(), i.getData().getLastPathSegment());
if (output.exists()) {
output.delete();
}
FileOutputStream fos = new FileOutputStream(output.getPath());
fos.write(responseBody);
fos.close();
result = Activity.RESULT_OK;
} catch (IOException e2) {
Log.e(getClass().getName(), "Exception in download", e2);
}
Bundle extras = i.getExtras();
if (extras != null) {
Messenger messenger = (Messenger) extras.get(EXTRA_MESSENGER);
Message msg = Message.obtain();
msg.arg1 = result;
try {
messenger.send(msg);
} catch (android.os.RemoteException e1) {
Log.w(getClass().getName(), "Exception sending message", e1);
}
}
}
use of android.os.Messenger in project cw-android by commonsguy.
the class DownloaderDemo method doTheDownload.
public void doTheDownload(View v) {
b.setEnabled(false);
Intent i = new Intent(this, Downloader.class);
i.setData(Uri.parse("http://commonsware.com/Android/excerpt.pdf"));
i.putExtra(Downloader.EXTRA_MESSENGER, new Messenger(handler));
startService(i);
}
Aggregations