Android Open Source - Simple-Scanner-Android Main Activity






From Project

Back to project page Simple-Scanner-Android.

License

The source code is released under:

Apache License

If you think the Android project Simple-Scanner-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package garin.artemiy.simplescanner.example;
/*from  w  ww  .ja  v a2  s.  c o  m*/
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentActivity;
import android.view.WindowManager;
import android.widget.Toast;
import garin.artemiy.simplescanner.R;
import garin.artemiy.simplescanner.library.fragments.SimpleScannerFragment;
import garin.artemiy.simplescanner.library.listeners.ScannerListener;

@SuppressWarnings("SameParameterValue")
public class MainActivity extends FragmentActivity implements ScannerListener {

    private static final long DELAY = 5000;
    private static final Handler handler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_layout);

        SimpleScannerFragment simpleScannerFragment =
                (SimpleScannerFragment) getSupportFragmentManager().findFragmentById(R.id.scannerFragment);
        simpleScannerFragment.setScannerListener(this);

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                configureFullScreen(true);
            }
        }, DELAY);
    }

    private void configureFullScreen(boolean isEnabled) {
        if (isEnabled) {
            WindowManager.LayoutParams attrs = getWindow().getAttributes();
            attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            getWindow().setAttributes(attrs);
        } else {
            WindowManager.LayoutParams attrs = getWindow().getAttributes();
            attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().setAttributes(attrs);
        }
    }

    @Override
    public void onDataReceive(String data, int barcodeType) {
        Toast.makeText(this, data, Toast.LENGTH_LONG).show();
    }

}




Java Source Code List

garin.artemiy.simplescanner.example.MainActivity.java
garin.artemiy.simplescanner.library.fragments.SimpleScannerFragment.java
garin.artemiy.simplescanner.library.listeners.ScannerListener.java
garin.artemiy.simplescanner.library.views.SimpleCameraView.java