Search in sources :

Example 11 with Handler

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();
        //                    }
        //                }
        }
    };
}
Also used : Handler(android.os.Handler) RecyclerView(android.support.v7.widget.RecyclerView)

Example 12 with Handler

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);
}
Also used : Handler(android.os.Handler)

Example 13 with Handler

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);
}
Also used : Handler(android.os.Handler) Intent(android.content.Intent)

Example 14 with Handler

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);
}
Also used : Handler(android.os.Handler)

Example 15 with Handler

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);
    }
}
Also used : SymbolSet(net.sourceforge.zbar.SymbolSet) Symbol(net.sourceforge.zbar.Symbol) Handler(android.os.Handler) Image(net.sourceforge.zbar.Image) Camera(android.hardware.Camera)

Aggregations

Handler (android.os.Handler)1843 Message (android.os.Message)253 View (android.view.View)201 Intent (android.content.Intent)165 HandlerThread (android.os.HandlerThread)135 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 TextView (android.widget.TextView)114 ArrayList (java.util.ArrayList)95 Test (org.junit.Test)80 Context (android.content.Context)67 RemoteException (android.os.RemoteException)63 IOException (java.io.IOException)61 IntentFilter (android.content.IntentFilter)57 ComponentName (android.content.ComponentName)56 ImageView (android.widget.ImageView)55 RecyclerView (android.support.v7.widget.RecyclerView)52 Bundle (android.os.Bundle)51 Looper (android.os.Looper)51 File (java.io.File)45 HashMap (java.util.HashMap)44