use of android.os.Handler in project UltimateRecyclerView by cymcsg.
the class SwipeListViewTouchListener method makeScrollListener.
/**
* Return ScrollListener for ListView
*
* @return OnScrollListener
*/
public RecyclerView.OnScrollListener makeScrollListener() {
return new RecyclerView.OnScrollListener() {
private boolean isFirstItem = false;
private boolean isLastItem = false;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
setEnabled(newState != recyclerView.SCROLL_STATE_DRAGGING);
if (swipeClosesAllItemsWhenListMoves && newState == recyclerView.SCROLL_STATE_DRAGGING) {
closeOpenedItems();
}
if (newState == recyclerView.SCROLL_STATE_DRAGGING) {
listViewMoving = true;
setEnabled(false);
}
if (newState != recyclerView.SCROLL_STATE_SETTLING && newState != recyclerView.SCROLL_STATE_DRAGGING) {
listViewMoving = false;
downPosition = ListView.INVALID_POSITION;
swipeListView.resetScrolling();
new Handler().postDelayed(new Runnable() {
public void run() {
setEnabled(true);
}
}, 500);
}
}
@Override
public void onScrolled(RecyclerView view, int dx, int dy) {
// if (isFirstItem) {
// boolean onSecondItemList = firstVisibleItem == 1;
// if (onSecondItemList) {
// isFirstItem = false;
// }
// } else {
// boolean onFirstItemList = firstVisibleItem == 0;
// if (onFirstItemList)
// isFirstItem = true;
// swipeListView.onFirstListItem();
// }
// }
// if (isLastItem) {
// boolean onBeforeLastItemList = firstVisibleItem + visibleItemCount == totalItemCount - 1;
// if (onBeforeLastItemList) {
// isLastItem = false;
// }
// } else {
// boolean onLastItemList = firstVisibleItem + visibleItemCount >= totalItemCount;
// if (onLastItemList) {
// isLastItem = true;
// swipeListView.onLastListItem();
// }
// }
}
};
}
use of android.os.Handler in project UltimateRecyclerView by cymcsg.
the class SwipeListViewTouchListener method handlerPendingDismisses.
/**
* Will call {@link #removePendingDismisses(int)} in animationTime + 100 ms.
*
* @param originalHeight will be used to rest the cells height.
*/
protected void handlerPendingDismisses(final int originalHeight) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
removePendingDismisses(originalHeight);
}
}, animationTime + 100);
}
use of android.os.Handler in project OneClickAndroid by cyngn.
the class MonitorService method onCreate.
@Override
public void onCreate() {
super.onCreate();
mHandler = new Handler();
new Runnable() {
@Override
public void run() {
if (mHandler == null)
return;
if (canContinue()) {
Intent i = new Intent(getBaseContext(), getNextActivityClass());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
cleanupAndShutdown();
return;
}
mHandler.postDelayed(this, 1000);
}
}.run();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
cleanupAndShutdown();
}
}, 60000);
}
use of android.os.Handler in project barcodescanner by dm77.
the class SimpleScannerActivity method handleResult.
@Override
public void handleResult(Result rawResult) {
Toast.makeText(this, "Contents = " + rawResult.getContents() + ", Format = " + rawResult.getBarcodeFormat().getName(), Toast.LENGTH_SHORT).show();
// Note:
// * Wait 2 seconds to resume the preview.
// * On older devices continuously stopping and resuming camera preview can result in freezing the app.
// * I don't know why this is the case but I don't have the time to figure out.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mScannerView.resumeCameraPreview(SimpleScannerActivity.this);
}
}, 2000);
}
use of android.os.Handler in project barcodescanner by dm77.
the class ZBarScannerView method onPreviewFrame.
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (mResultHandler == null) {
return;
}
try {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
int width = size.width;
int height = size.height;
if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) rotatedData[x * height + height - y - 1] = data[x + y * width];
}
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
}
Image barcode = new Image(width, height, "Y800");
barcode.setData(data);
int result = mScanner.scanImage(barcode);
if (result != 0) {
SymbolSet syms = mScanner.getResults();
final Result rawResult = new Result();
for (Symbol sym : syms) {
// In order to retreive QR codes containing null bytes we need to
// use getDataBytes() rather than getData() which uses C strings.
// Weirdly ZBar transforms all data to UTF-8, even the data returned
// by getDataBytes() so we have to decode it as UTF-8.
String symData;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
symData = new String(sym.getDataBytes(), StandardCharsets.UTF_8);
} else {
symData = sym.getData();
}
if (!TextUtils.isEmpty(symData)) {
rawResult.setContents(symData);
rawResult.setBarcodeFormat(BarcodeFormat.getFormatById(sym.getType()));
break;
}
}
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
// Stopping the preview can take a little long.
// So we want to set result handler to null to discard subsequent calls to
// onPreviewFrame.
ResultHandler tmpResultHandler = mResultHandler;
mResultHandler = null;
stopCameraPreview();
if (tmpResultHandler != null) {
tmpResultHandler.handleResult(rawResult);
}
}
});
} else {
camera.setOneShotPreviewCallback(this);
}
} catch (RuntimeException e) {
// TODO: Terrible hack. It is possible that this method is invoked after camera is released.
Log.e(TAG, e.toString(), e);
}
}
Aggregations