Android Open Source - qrcode-android Z X Scan Helper






From Project

Back to project page qrcode-android.

License

The source code is released under:

MIT License

If you think the Android project qrcode-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 eu.livotov.zxscan;
//  w w w .  ja  v a  2 s.  c  o m
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.support.v4.app.Fragment;
import android.text.TextUtils;

import com.google.zxing.client.android.CaptureActivity;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.camera.FrontLightMode;

/**
 * Created with IntelliJ IDEA.
 * User: dlivotov
 * Date: 26.08.12
 * Time: 21:14
 * To change this template use File | Settings | File Templates.
 */
public class ZXScanHelper
{

    private static int customScanLayout = 0;
    private static int customScanSound = 0;
    private static boolean safeMode = false;
    private static boolean playSoundOnRead = true;
    private static boolean vibrateOnRead = true;
    private static boolean useExternalApplicationIfAvailable = false;
    private static boolean blockCameraRotation = true;
    private static FrontLightMode frontLightMode = FrontLightMode.AUTO;
    private static AutofocusMode autofocusMode = AutofocusMode.On;
    private static ZXUserCallback userCallback;
    private static Class<? extends CaptureActivity> captureActivityClass;

    public final static void scan(Activity ctx, int requestCode)
    {
      Intent scanIntent = getScanIntent(ctx);
      
        ctx.startActivityForResult(scanIntent, requestCode);
    }
    
    public final static void scan(Fragment frag, int requestCode) 
    {
      Intent scanIntent = getScanIntent(frag.getActivity());
      
      frag.startActivityForResult(scanIntent, requestCode);
    }
    
    private final static Intent getScanIntent(Activity ctx) 
    {
      Intent scanIntent = useExternalApplicationIfAvailable ? getExternalApplicationIntent(ctx) : null;

        if (scanIntent == null)
        {
            scanIntent = new Intent(ctx, captureActivityClass != null ? captureActivityClass : CaptureActivity.class);
        }
        
        return scanIntent;
    }

    private static Intent getExternalApplicationIntent(final Context ctx)
    {
        PackageManager pm = ctx.getPackageManager();
        Intent intent = new Intent(Intents.Scan.ACTION);

        List<ResolveInfo> availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

        for (ResolveInfo availableApp : availableApps)
        {
            final String packageName = availableApp.activityInfo.packageName;
            if (!TextUtils.isEmpty(packageName))
            {
                if (packageName.contains("com.google.zxing.client.android") || packageName.contains("com.srowen.bs.android"))
                {
                    return intent;
                }
            }
        }

        return null;
    }

    public final static String getScannedCode(Intent resultData)
    {
        return resultData != null ? resultData.getStringExtra(Intents.Scan.RESULT) : null;
    }
    
    public final static String getCodeFormat(Intent resultData)
  {
    return resultData != null ? resultData.getStringExtra(Intents.Scan.RESULT_FORMAT) : null;
  }

    public static void setCustomScanLayout(final int customScanLayoutRes)
    {
        ZXScanHelper.customScanLayout = customScanLayoutRes;
    }

    public static int getCustomScanLayout()
    {
        return customScanLayout;
    }

    public static ZXUserCallback getUserCallback()
    {
        return userCallback;
    }

    public static void setUserCallback(final ZXUserCallback userCallback)
    {
        ZXScanHelper.userCallback = userCallback;
    }

    public static int getCustomScanSound()
    {
        return customScanSound;
    }

    public static void setCustomScanSound(final int customScanSound)
    {
        ZXScanHelper.customScanSound = customScanSound;
    }

    public static boolean isUseExternalApplicationIfAvailable()
    {
        return useExternalApplicationIfAvailable;
    }

    public static void setUseExternalApplicationIfAvailable(final boolean b)
    {
        useExternalApplicationIfAvailable = b;
    }

    public static boolean isPlaySoundOnRead()
    {
        return playSoundOnRead;
    }

    public static void setPlaySoundOnRead(final boolean playSoundOnRead)
    {
        ZXScanHelper.playSoundOnRead = playSoundOnRead;
    }

    public static boolean isVibrateOnRead()
    {
        return vibrateOnRead;
    }

    public static boolean isSafeMode()
    {
        return safeMode;
    }

    public static void setSafeMode(final boolean safeMode)
    {
        ZXScanHelper.safeMode = safeMode;
    }

    public static void setVibrateOnRead(final boolean vibrateOnRead)
    {
        ZXScanHelper.vibrateOnRead = vibrateOnRead;
    }

    public static AutofocusMode getAutofocusMode()
    {
        return autofocusMode;
    }

    public static void setAutofocusMode(final AutofocusMode autofocusMode)
    {
        ZXScanHelper.autofocusMode = autofocusMode;
    }

    public static boolean isBlockCameraRotation()
    {
        return blockCameraRotation;
    }

    public static void setBlockCameraRotation(final boolean blockCameraRotation)
    {
        ZXScanHelper.blockCameraRotation = blockCameraRotation;
    }


    public static void setCustomActivityClass(Class<? extends CaptureActivity> captureActivityClass)
    {
        ZXScanHelper.captureActivityClass = captureActivityClass;
    }

    public static FrontLightMode getFrontLightMode()
    {
        return frontLightMode;
    }

    public static void setFrontLightMode(final FrontLightMode frontLightMode)
    {
        ZXScanHelper.frontLightMode = frontLightMode;
    }
}




Java Source Code List

com.google.zxing.client.android.BeepManager.java
com.google.zxing.client.android.CaptureActivityHandler.java
com.google.zxing.client.android.CaptureActivity.java
com.google.zxing.client.android.Contents.java
com.google.zxing.client.android.DecodeFormatManager.java
com.google.zxing.client.android.DecodeHandler.java
com.google.zxing.client.android.DecodeHintManager.java
com.google.zxing.client.android.DecodeThread.java
com.google.zxing.client.android.FinishListener.java
com.google.zxing.client.android.InactivityTimer.java
com.google.zxing.client.android.IntentSource.java
com.google.zxing.client.android.Intents.java
com.google.zxing.client.android.LocaleManager.java
com.google.zxing.client.android.ViewfinderResultPointCallback.java
com.google.zxing.client.android.ViewfinderView.java
com.google.zxing.client.android.camera.AutoFocusManager.java
com.google.zxing.client.android.camera.CameraConfigurationManager.java
com.google.zxing.client.android.camera.CameraManager.java
com.google.zxing.client.android.camera.FrontLightMode.java
com.google.zxing.client.android.camera.PreviewCallback.java
com.google.zxing.client.android.camera.exposure.DefaultExposureInterface.java
com.google.zxing.client.android.camera.exposure.ExposureInterface.java
com.google.zxing.client.android.camera.exposure.ExposureManager.java
com.google.zxing.client.android.camera.exposure.FroyoExposureInterface.java
com.google.zxing.client.android.camera.open.DefaultOpenCameraInterface.java
com.google.zxing.client.android.camera.open.GingerbreadOpenCameraInterface.java
com.google.zxing.client.android.camera.open.OpenCameraInterface.java
com.google.zxing.client.android.camera.open.OpenCameraManager.java
com.google.zxing.client.android.common.PlatformSupportManager.java
com.google.zxing.client.android.common.executor.AsyncTaskExecInterface.java
com.google.zxing.client.android.common.executor.AsyncTaskExecManager.java
com.google.zxing.client.android.common.executor.DefaultAsyncTaskExecInterface.java
com.google.zxing.client.android.common.executor.HoneycombAsyncTaskExecInterface.java
com.google.zxing.extra.RGBLuminanceSource.java
eu.livotov.zxscan.AutofocusMode.java
eu.livotov.zxscan.ZXScanHelper.java
eu.livotov.zxscan.ZXUserCallback.java
tw.soleil.constant.Constants.java
tw.soleil.qrcodereadertest.QRCodeReaderTestActivity.java
tw.soleil.service.InvoiceService.java
tw.soleil.to.InvoiceDtl.java
tw.soleil.to.Invoice.java
tw.soleil.util.DateUtil.java
tw.soleil.util.Utils.java