commit b2c8455a6c560808ae849d2e90b77563db4f5db1 Author: JOETION <1322874562@qq.com> Date: Tue Nov 10 01:45:14 2020 +0800 修改eclipse项目为as项目 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..33890b9 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +ChaoRan-PDA-Client \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b1415f4 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2b389c6 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..f5a9999 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f0934fc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..9828d06 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 29 + buildToolsVersion "30.0.2" + + defaultConfig { + applicationId "com.chaoran" + minSdkVersion 8 + targetSdkVersion 15 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + lintOptions { + abortOnError false + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) +} \ No newline at end of file diff --git a/app/jni/Android.mk b/app/jni/Android.mk new file mode 100644 index 0000000..1fd95e8 --- /dev/null +++ b/app/jni/Android.mk @@ -0,0 +1,26 @@ +# +# Copyright 2009 Cedric Priscal +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +TARGET_PLATFORM := android-8 +LOCAL_MODULE := serial_port +LOCAL_SRC_FILES := SerialPort.c +LOCAL_LDLIBS := -llog + +include $(BUILD_SHARED_LIBRARY) diff --git a/app/jni/SerialPort.c b/app/jni/SerialPort.c new file mode 100644 index 0000000..b4926b3 --- /dev/null +++ b/app/jni/SerialPort.c @@ -0,0 +1,286 @@ +/* + * Copyright 2009 Cedric Priscal + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "android/log.h" +static const char *TAG="serial_port"; +#define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, TAG, fmt, ##args) +#define LOGD(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, TAG, fmt, ##args) +#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, TAG, fmt, ##args) + + +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: com_android_barcode_SerialPort + * Method: open + * Signature: (Ljava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_android_barcode_SerialPort_open + (JNIEnv *, jclass, jstring, jint); + +/* + * Class: com_android_barcode_SerialPort + * Method: write + * Signature: (ILjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_com_android_barcode_SerialPort_write + (JNIEnv *, jobject, jint, jstring, jint); + +/* + * Class: com_android_barcode_SerialPort + * Method: read + * Signature: (II)[B + */ +JNIEXPORT jbyteArray JNICALL Java_com_android_barcode_SerialPort_read + (JNIEnv *, jobject, jint, jint); + +/* + * Class: com_android_barcode_SerialPort + * Method: close + * Signature: (I)V + */ +JNIEXPORT void JNICALL Java_com_android_barcode_SerialPort_close + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif + +static speed_t getBaudrate(jint baudrate) +{ + switch(baudrate) { + case 0: return B0; + case 50: return B50; + case 75: return B75; + case 110: return B110; + case 134: return B134; + case 150: return B150; + case 200: return B200; + case 300: return B300; + case 600: return B600; + case 1200: return B1200; + case 1800: return B1800; + case 2400: return B2400; + case 4800: return B4800; + case 9600: return B9600; + case 19200: return B19200; + case 38400: return B38400; + case 57600: return B57600; + case 115200: return B115200; + case 230400: return B230400; + case 460800: return B460800; + case 500000: return B500000; + case 576000: return B576000; + case 921600: return B921600; + case 1000000: return B1000000; + case 1152000: return B1152000; + case 1500000: return B1500000; + case 2000000: return B2000000; + case 2500000: return B2500000; + case 3000000: return B3000000; + case 3500000: return B3500000; + case 4000000: return B4000000; + default: return -1; + } +} + +/* + * Class: cedric_serial_SerialPort + * Method: open + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT jint JNICALL Java_com_android_barcode_SerialPort_open + (JNIEnv *env, jobject thiz, jstring path, jint baudrate) +{ + int fd; + speed_t speed; + + /* Check arguments */ + { + speed = getBaudrate(baudrate); + if (speed == -1) { + /* TODO: throw an exception */ + LOGE("Invalid baudrate"); + } + } + + /* Opening device */ + { + jboolean iscopy; + const char *path_utf = (*env)->GetStringUTFChars(env, path, &iscopy); + LOGD("Opening serial port %s", path_utf); + fd = open(path_utf, O_RDWR | O_SYNC); + LOGD("open() fd = %d", fd); + (*env)->ReleaseStringUTFChars(env, path, path_utf); + if (fd == -1) + { + /* Throw an exception */ + LOGE("Cannot open port"); + /* TODO: throw an exception */ + } + } + + /* Configure device */ + { + struct termios cfg; + LOGD("Configuring serial port"); + if (tcgetattr(fd, &cfg)) + { + LOGE("tcgetattr() failed"); + close(fd); + /* TODO: throw an exception */ + } + + cfmakeraw(&cfg); + cfsetispeed(&cfg, speed); + cfsetospeed(&cfg, speed); + /*******************************/ + cfg.c_cflag &= ~CSIZE; + cfg.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG); + cfg.c_oflag &= ~OPOST; + //'8' bit + cfg.c_cflag |= CS8; + //'N' PARENB + cfg.c_cflag &= ~PARENB; + cfg.c_iflag &= ~INPCK; + //'1' STOP + cfg.c_cflag &= ~CSTOPB; + + cfg.c_cc[VTIME] = 15; + cfg.c_cc[VMIN] = 0; + tcflush(fd, TCIFLUSH); + /*********************************/ + + if (tcsetattr(fd, TCSANOW, &cfg)) + { + LOGE("tcsetattr() failed"); + close(fd); + /* TODO: throw an exception */ + } + } + + + return fd; +} +/* + * Class: cedric_serial_SerialPort + * Method: write + * Signature: ()V + */ + +JNIEXPORT jint JNICALL Java_com_android_barcode_SerialPort_write + (JNIEnv *env, jobject obj, jint fd, jstring str, jint len) +{ + jboolean iscopy; + const char *buff_utf = (*env)->GetStringUTFChars(env, str, &iscopy); + int wlen = 0; + wlen = write(fd, buff_utf, len); + if(wlen > 0) + { + LOGD("Write serial port %s\n", buff_utf); + } + else + { + LOGE("Write failed\n"); + } + (*env)->ReleaseStringUTFChars(env, str, buff_utf); + LOGD("Write finish!\n"); + return wlen; +} +/* + * Class: cedric_serial_SerialPort + * Method: read + * Signature: ()V + */ + +JNIEXPORT jbyteArray JNICALL Java_com_android_barcode_SerialPort_read + (JNIEnv *env, jobject obj, jint fd, jint len) +{ + int reval; + int nread = 0; + char buff[len]; + char result[len]; + struct timeval tv; + jbyteArray jba; + fd_set rfds; + + while(1) + { + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + tv.tv_sec = 0; + tv.tv_usec = 100000; + if ((reval = select(1 + fd, &rfds, NULL, NULL, &tv)) > 0) + { + if(FD_ISSET(fd, &rfds)) + { + int temp = read(fd, buff + nread, len); + nread += temp; + LOGD("%i us is used", 100000 - tv.tv_usec); + LOGD("wo have data %d\n", temp); + } + } + else if(reval == 0 && nread != 0) //timeout means + { +// int ffd; + buff[nread]=0; +// ffd = open("/data/ndk", O_WRONLY | O_TRUNC); +// write(ffd, buff, nread); +// close(ffd); + int i, j; + for(i = 0, j = 0; i < nread; i++) + { + if(buff[i] != 0) + { + result[j] = buff[i]; + j++; + } + // LOGD("0x%2x ", buff[i]); + } + //LOGD("\n"); + //result[j] = 0; + jba = (*env)->NewByteArray(env, j); + (*env)->SetByteArrayRegion(env, jba, 0, j, result); +/* jba = (*env)->NewByteArray(env, nread); + (*env)->SetByteArrayRegion(env, jba, 0, nread, buff);*/ + LOGD("readlength=%d\n, reallength=%d\n, all data received!\n", nread, j); + return jba; + } + else + { + return NULL; + } + } +} +/* + * Class: cedric_serial_SerialPort + * Method: close + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_android_barcode_SerialPort_close + (JNIEnv *env, jobject obj, jint fd) +{ + close(fd); +} diff --git a/app/libs/android-support-v4.jar b/app/libs/android-support-v4.jar new file mode 100644 index 0000000..428bdbc Binary files /dev/null and b/app/libs/android-support-v4.jar differ diff --git a/app/libs/armeabi/libBMapApiEngine_v1_3_3.so b/app/libs/armeabi/libBMapApiEngine_v1_3_3.so new file mode 100644 index 0000000..a0eea1d Binary files /dev/null and b/app/libs/armeabi/libBMapApiEngine_v1_3_3.so differ diff --git a/app/libs/armeabi/libIAL.so b/app/libs/armeabi/libIAL.so new file mode 100644 index 0000000..4d20bed Binary files /dev/null and b/app/libs/armeabi/libIAL.so differ diff --git a/app/libs/armeabi/libSDL.so b/app/libs/armeabi/libSDL.so new file mode 100644 index 0000000..5496deb Binary files /dev/null and b/app/libs/armeabi/libSDL.so differ diff --git a/app/libs/armeabi/libbarcodereader.so b/app/libs/armeabi/libbarcodereader.so new file mode 100644 index 0000000..9973b51 Binary files /dev/null and b/app/libs/armeabi/libbarcodereader.so differ diff --git a/app/libs/armeabi/libjni_gpio.so b/app/libs/armeabi/libjni_gpio.so new file mode 100644 index 0000000..f82d73c Binary files /dev/null and b/app/libs/armeabi/libjni_gpio.so differ diff --git a/app/libs/armeabi/liblocSDK3.so b/app/libs/armeabi/liblocSDK3.so new file mode 100644 index 0000000..4451144 Binary files /dev/null and b/app/libs/armeabi/liblocSDK3.so differ diff --git a/app/libs/armeabi/librfidtestnew.so b/app/libs/armeabi/librfidtestnew.so new file mode 100644 index 0000000..1ee8e47 Binary files /dev/null and b/app/libs/armeabi/librfidtestnew.so differ diff --git a/app/libs/armeabi/libserial_port.so b/app/libs/armeabi/libserial_port.so new file mode 100644 index 0000000..3ea9b56 Binary files /dev/null and b/app/libs/armeabi/libserial_port.so differ diff --git a/app/libs/armeabi/libserialport.so b/app/libs/armeabi/libserialport.so new file mode 100644 index 0000000..2c05405 Binary files /dev/null and b/app/libs/armeabi/libserialport.so differ diff --git a/app/libs/armeabi/libtiny-tools.so b/app/libs/armeabi/libtiny-tools.so new file mode 100644 index 0000000..ed1561e Binary files /dev/null and b/app/libs/armeabi/libtiny-tools.so differ diff --git a/app/libs/baidumapapi.jar b/app/libs/baidumapapi.jar new file mode 100644 index 0000000..048400c Binary files /dev/null and b/app/libs/baidumapapi.jar differ diff --git a/app/libs/classes.jar b/app/libs/classes.jar new file mode 100644 index 0000000..ee4553d Binary files /dev/null and b/app/libs/classes.jar differ diff --git a/app/libs/dom4j-1.6.1.jar b/app/libs/dom4j-1.6.1.jar new file mode 100644 index 0000000..c8c4dbb Binary files /dev/null and b/app/libs/dom4j-1.6.1.jar differ diff --git a/app/libs/flex-messaging-core.jar b/app/libs/flex-messaging-core.jar new file mode 100644 index 0000000..25a843e Binary files /dev/null and b/app/libs/flex-messaging-core.jar differ diff --git a/app/libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar b/app/libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar new file mode 100644 index 0000000..bf4ebe2 Binary files /dev/null and b/app/libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar differ diff --git a/app/libs/locSDK_3.3.jar b/app/libs/locSDK_3.3.jar new file mode 100644 index 0000000..c7a6ef3 Binary files /dev/null and b/app/libs/locSDK_3.3.jar differ diff --git a/app/libs/scan.jar b/app/libs/scan.jar new file mode 100644 index 0000000..cf6de4d Binary files /dev/null and b/app/libs/scan.jar differ diff --git a/app/libs/zxing.jar b/app/libs/zxing.jar new file mode 100644 index 0000000..29fa881 Binary files /dev/null and b/app/libs/zxing.jar differ diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e76315e --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/android/gpio/GpioJNI.java b/app/src/main/java/android/gpio/GpioJNI.java new file mode 100644 index 0000000..cbfd6d5 --- /dev/null +++ b/app/src/main/java/android/gpio/GpioJNI.java @@ -0,0 +1,65 @@ +package android.gpio; + +public class GpioJNI { + + static public native void gpio_switch_gps_bluetooth(int flag); + + static public native int gpio_get_gps_bluetooth(); + + static public native void gpio_switch_gps_power(int flag); + + static public native int gpio_get_gps_power(); + + static public native void gpio_switch_rs485_rs232(int flag); + + static public native int gpio_get_rs485_rs232(); + + static public native void gpio_switch_rs485_power(int flag); + + static public native int gpio_get_rs485_power(); + + static public native void gpio_switch_rs232_power(int flag); + + static public native int gpio_get_rs232_power(); + + static public native void gpio_switch_scan_rf_ired(int flag); + + static public native int gpio_get_scan_rf_ired(); + + static public native void gpio_switch_rf_power(int flag); + + static public native int gpio_get_rf_power(); + + static public native void gpio_switch_scan_power(int flag); + + static public native int gpio_get_scan_power(); + + static public native void gpio_switch_scan_powerdown(int flag); + + static public native int gpio_get_scan_powerdown(); + + static public native void gpio_switch_scan_trig(int flag);// �?���?��出光扫描 + + static public native int gpio_get_scan_trig(); + + static public native void gpio_switch_scan_reset(int flag); + + static public native int gpio_get_scan_reset(); + + static public native void gpio_switch_rf_reset(int flag); + + static public native int gpio_get_rf_reset(); + + static public native void gpio_switch_ired(int flag); + + static public native int gpio_get_ired(); + + static { + try { + System.loadLibrary("jni_gpio"); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/android_serialport_api/SerialPort.java b/app/src/main/java/android_serialport_api/SerialPort.java new file mode 100644 index 0000000..2274fa7 --- /dev/null +++ b/app/src/main/java/android_serialport_api/SerialPort.java @@ -0,0 +1,61 @@ +package android_serialport_api; + +import android.util.Log; + +import java.io.*; + +public class SerialPort { + + private static final String TAG = "SerialPort"; + private FileDescriptor mFd; + private FileInputStream mFileInputStream; + private FileOutputStream mFileOutputStream; + + public SerialPort(File device, int baudrate, int bits, char event, int stop, int flags) throws SecurityException, + IOException { + + if (!device.canRead() || !device.canWrite()) { + try { + Process su; + su = Runtime.getRuntime().exec("/system/bin/su"); + String cmd = "chmod 777 " + device.getAbsolutePath() + "\n" + "exit\n"; + su.getOutputStream().write(cmd.getBytes()); + + if ((su.waitFor() != 0) || !device.canRead() || !device.canWrite()) { + throw new SecurityException(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new SecurityException(); + } + } + mFd = open(device.getAbsolutePath(), baudrate, bits, event, stop, flags); + Log.i("info", "open device!!"); + if (mFd == null) { + Log.e(TAG, "native open returns null"); + throw new IOException(); + } + mFileInputStream = new FileInputStream(mFd); + mFileOutputStream = new FileOutputStream(mFd); + + } + + public InputStream getInputStream() { + + return mFileInputStream; + } + + public OutputStream getOutputStream() { + + return mFileOutputStream; + } + + private native static FileDescriptor open(String path, int baudrate, int bits, char event, int stop, int flags); + + public native void close(); + + static { + + System.loadLibrary("serialport"); + } +} diff --git a/app/src/main/java/com/chaoran/component/AntLine.java b/app/src/main/java/com/chaoran/component/AntLine.java new file mode 100644 index 0000000..75a5a8c --- /dev/null +++ b/app/src/main/java/com/chaoran/component/AntLine.java @@ -0,0 +1,52 @@ +package com.chaoran.component; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.view.View; + +public class AntLine extends View { + private Paint mPaint; + private int color; + private int size=6; + public int getSize() { + return size; + } + public void setSize(int size) { + this.size = size; + } + public AntLine(Context context) { + super(context); + // TODO Auto-generated constructor stub + init(); + } + public AntLine(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + private void init(){ + color=Color.GREEN; + mPaint = new Paint(); + mPaint.setStyle(Paint.Style.STROKE); +// mPaint.setStrokeWidth(6); +// mPaint.setColor(Color.RED); + } + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + mPaint.setColor(color); + mPaint.setStrokeWidth(size); + int wz=size/2;//计算画笔离边的宽度 + Rect r=new Rect(wz,wz, this.getWidth()-wz,this.getHeight()-wz); + canvas.drawRect(r, mPaint); + } + public int getColor() { + return color; + } + public void setColor(int color) { + this.color = color; + } +} diff --git a/app/src/main/java/com/chaoran/component/ButAdapter.java b/app/src/main/java/com/chaoran/component/ButAdapter.java new file mode 100644 index 0000000..ed94ee0 --- /dev/null +++ b/app/src/main/java/com/chaoran/component/ButAdapter.java @@ -0,0 +1,101 @@ +package com.chaoran.component; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.chaoran.db.DBManager; +import com.chaoran.lx.activity.DownDataActivity; +import com.example.chaoran.DjActivity; +import com.example.chaoran.R; + +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.os.Handler; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.View.OnClickListener; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.TextView; + +public class ButAdapter extends BaseAdapter { + private LayoutInflater inflater; + public ArrayList list; + // private String filedName; + private DownDataActivity context; + private ProgressDialog pd; + private DBManager dbManager; + // private Handler handler; + private String tableName; + private String showFilde; + public ButAdapter(DownDataActivity context, ArrayList list, + ProgressDialog pd, DBManager dbManager, String tableName,String showFilde) { + inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.list = list; + this.context = context; + this.pd = pd; + this.dbManager = dbManager; + // this.handler = handler; + this.tableName = tableName; + this.showFilde=showFilde; + } + + @Override + public int getCount() { + return this.list != null ? this.list.size() : 0; + } + + @Override + public Object getItem(int position) { + return this.list.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final HashMap map = (HashMap) list.get(position); + if (convertView == null) { + convertView = inflater.inflate(R.layout.butadapter_list_child, + null, false); + } + final TextView tablename = (TextView) convertView + .findViewById(R.id.tablename); + String table = map.get(tableName).toString(); + Object ob=map.get(showFilde); + String lb =""; + if(ob!=null){ + lb=ob.toString(); + } + if (dbManager.existsTable(table.toUpperCase()) > 0) { + lb = lb.concat("(").concat(String.valueOf(dbManager.rsCount(table))) + .concat(")"); + } + tablename.setText(lb); + Button button = (Button) convertView.findViewById(R.id.downbut); + button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + context.downData(map, tablename); + } + }); + return convertView; + } + + public void clean() { + inflater = null; + context = null; + list = null; + // filedName=null; + pd = null; + // handler = null; + dbManager = null; + } + +} diff --git a/app/src/main/java/com/chaoran/component/ImageAdpter.java b/app/src/main/java/com/chaoran/component/ImageAdpter.java new file mode 100644 index 0000000..84c6ddc --- /dev/null +++ b/app/src/main/java/com/chaoran/component/ImageAdpter.java @@ -0,0 +1,82 @@ +package com.chaoran.component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.example.chaoran.R; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.GridView; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +public class ImageAdpter extends BaseAdapter { + private List list; + private Activity context; + + public ImageAdpter(List menuData, Activity context) { + this.list = menuData; + this.context = context; + } + + @Override + public int getCount() { + return list.size(); + } + + @Override + public Object getItem(int position) { + return position; + } + + @Override + public long getItemId(int id) { + return id; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater li = context.getLayoutInflater(); + View view = li.inflate(R.layout.imageadpter, null); + ImageView iv = (ImageView) view.findViewById(R.id.gridimg); + // 设置View的height和width:这样保证无论image原来的尺寸,每个图像将重新适合这个指定的尺寸。 +// iv.setLayoutParams(new RelativeLayout.LayoutParams(85, 85)); +// /* +// * ImageView.ScaleType.CENTER 但不执行缩放比例 +// * ImageView.ScaleType.CENTER_CROP +// * 按比例统一缩放图片(保持图片的尺寸比例)便于图片的两维(宽度和高度)等于或大于相应的视图维度 +// * ImageView.ScaleType.CENTER_INSIDE +// * 按比例统一缩放图片(保持图片的尺寸比例)便于图片的两维(宽度和高度)等于或小于相应的视图维度 +// */ + iv.setScaleType(ImageView.ScaleType.CENTER_CROP); +// iv.setPadding(8, 8, 8, 8); + Map map = (Map) list.get(position); + if (map.containsKey("img")&&map.get("img") != null) { + + byte[] byt = (byte[]) map.get("img"); + iv.setImageBitmap(BitmapFactory.decodeByteArray(byt, 0, byt.length)); + }else{ + iv.setImageResource(R.drawable.logo); + } + ((TextView) view.findViewById(R.id.gridtitle)).setText(map.get("mname") + .toString()); + // ImageView iv=(ImageView)view.findViewById(R.id.imageView1); + // iv.setImageResource(images[position]); + // TextView tv=(TextView)view.findViewById(R.id.ItemText); + // tv.setText(texts[position]); + // tv.setTextColor(Color.BLUE); + // tv.setTextSize(20); + // return view; + return view; + } + +} diff --git a/app/src/main/java/com/chaoran/component/MyAdapter.java b/app/src/main/java/com/chaoran/component/MyAdapter.java new file mode 100644 index 0000000..923f40c --- /dev/null +++ b/app/src/main/java/com/chaoran/component/MyAdapter.java @@ -0,0 +1,100 @@ +package com.chaoran.component; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.chaoran.entiry.Zujian; +import com.example.chaoran.DjActivity; +import com.example.chaoran.R; +import com.util.DialogUtil; +import com.util.SysUtil; + +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +public class MyAdapter extends BaseAdapter { + private LayoutInflater inflater; + private ArrayList list; + public int cur_pos = -1; + private String filedName; + private Context context; + public MyAdapter(Context context, ArrayList list, String filedName) { + inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.list = list; + this.filedName = filedName; + this.context=context; + } + + @Override + public int getCount() { + return this.list != null ? this.list.size() : 0; + } + + @Override + public Object getItem(int position) { + return this.list.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + public void clear(){ + inflater=null; + if(list!=null){ + list.clear(); + list=null; + context=null; + } + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Zujian zj = null; + if (convertView == null) { + // System.out.println("创建新的对象-------------------------------"); + zj = new Zujian(); + convertView = inflater.inflate(R.layout.list_child, null, false); + zj.tv = (TextView) convertView.findViewById(R.id.list_child_text);// 显示文字 + convertView.setTag(zj); + } else { + zj = (Zujian) convertView.getTag(); + } + HashMap map = (HashMap) list.get(position); + zj.tv.setText(map.get(filedName).toString()); + if (position == cur_pos) {// 如果当前的行就是ListView中选中的一行,就更改显示样式 + convertView.setBackgroundColor(Color.LTGRAY);// 更改整行的背景色 + zj.tv.setTextColor(Color.RED);// 更改字体颜色 + } else { + try { + int bcolor = Color.WHITE; + if (map.containsKey("__BCOLOR")) { + String colorValue = ((String) map.get("__BCOLOR")); + if (colorValue != null && colorValue.trim().length() > 0) { + bcolor = SysUtil.toColor(Integer.decode(colorValue + .trim())); + } + } + convertView.setBackgroundColor(bcolor);// 更改整行的背景色 + int fcolor = Color.BLACK; + if (map.containsKey("__FCOLOR")) { + String fcolorValue = ((String) map.get("__FCOLOR")); + if (fcolorValue != null && fcolorValue.trim().length() > 0) { + fcolor = SysUtil.toColor(Integer.decode(fcolorValue + .trim())); + } + } + zj.tv.setTextColor(fcolor);// 更改字体颜色 + } catch (NumberFormatException exception) { + DialogUtil.builder(context, "错误信息",exception.toString(),0); + } + } + return convertView; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/chaoran/component/SelfHRule.java b/app/src/main/java/com/chaoran/component/SelfHRule.java new file mode 100644 index 0000000..dd4d09b --- /dev/null +++ b/app/src/main/java/com/chaoran/component/SelfHRule.java @@ -0,0 +1,41 @@ +package com.chaoran.component; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.util.AttributeSet; +import android.view.View; + +public class SelfHRule extends View { + private Paint mPaint; + private int color; + public SelfHRule(Context context) { + super(context); + init(); + } + public SelfHRule(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + private void init(){ + color=Color.GRAY; + mPaint = new Paint(); + mPaint.setStyle(Paint.Style.FILL_AND_STROKE); +// mPaint.setColor(Color.RED); + } + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + mPaint.setColor(color); + Rect r=new Rect(0,0, this.getWidth(),this.getHeight()); + canvas.drawRect(r, mPaint); + } + public int getColor() { + return color; + } + public void setColor(int color) { + this.color = color; + } +} diff --git a/app/src/main/java/com/chaoran/db/DBManager.java b/app/src/main/java/com/chaoran/db/DBManager.java new file mode 100644 index 0000000..855c70e --- /dev/null +++ b/app/src/main/java/com/chaoran/db/DBManager.java @@ -0,0 +1,211 @@ +package com.chaoran.db; + +import java.io.ByteArrayInputStream; +import java.io.ObjectInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.chaoran.entiry.DanJuEntity; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +public class DBManager { + private SqlHelpUtil helper; + private SQLiteDatabase db; + + public DBManager(Context context) { + helper = new SqlHelpUtil(context); + // 因为getWritableDatabase内部调用了mContext.openOrCreateDatabase(mName, 0, + // mFactory); + // 所以要确保context已初始化,我们可以把实例化DBManager的步骤放在Activity的onCreate里 + db = helper.getWritableDatabase(); + } + + /* + * 判断表是否创建SELECT COUNT(*) as TabCount FROM sqlite_master where type='table' + * and name='T1' + */ + public int existsTable(String tableName) { + String sql = "SELECT COUNT(*) FROM sqlite_master where type='table' and name='" + + tableName + "' "; + Cursor cursor = db.rawQuery(sql, null); + cursor.moveToFirst(); + int count = cursor.getInt(0); + cursor.close(); + return count; + } + + public int rsCount(String tableName) { + String sql = "SELECT COUNT(*) FROM " + tableName + ";"; + Cursor cursor = db.rawQuery(sql, null); + int count=0; + if(cursor.moveToFirst()){ + count = cursor.getInt(0); + } + cursor.close(); + return count; + } + public void batchSave(String sql,Map map){ + Set set = map.keySet(); + db.beginTransaction(); + for (String s : set) { + System.out.println(s+"--=============-"+map.get(s)); + db.execSQL(sql.toString(), new Object[]{s,map.get(s)}); + } + db.setTransactionSuccessful(); + db.endTransaction(); + } + public void batchSave(List list, String tableName) { + HashMap map = (HashMap) list.get(0); + Set set = map.keySet(); + ArrayList keys = new ArrayList(); + StringBuilder sql = new StringBuilder("insert into "); + sql.append(tableName).append("("); + StringBuilder column = new StringBuilder(); + StringBuilder value = new StringBuilder(); + for (String key : set) { + if(key.toUpperCase().equals("ROWNUMBER")){ + continue; + } + keys.add(key); + if (column.length() > 0) { + column.append(","); + value.append(","); + } + column.append(key); + value.append("?"); + } + sql.append(column.toString()).append(") values (").append(value) + .append(")"); + int len = keys.size(); + System.out.println(sql.toString()); + String runSql=sql.toString(); + try { + db.beginTransaction(); + int listLen = list.size(); + Object param[] = new Object[len]; + for (HashMap hmp : list) { + for (int i = 0; i < len; i++) { + Object tempObject=hmp.get(keys.get(i)); +// System.out.println(keys.get(i)+"---"+tempObject); +// if(tempObject instanceof byte[]){ +// System.out.println("length---"+((byte[])tempObject).length); +// ByteArrayInputStream bin = new ByteArrayInputStream((byte[])tempObject); +// try { +// ObjectInputStream oin = new ObjectInputStream(bin); +// DanJuEntity danJuEntity=(DanJuEntity) oin.readObject(); +// System.out.println(danJuEntity.pageNr + "--------"); +// } catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// } + if(tempObject==null){ + param[i]=""; + }else{ + param[i] = tempObject; + } + } + db.execSQL(runSql, param); + } + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + + public void exeSql(String sql) { + db.execSQL(sql); + } + + public void exeSql(String sql, Object object[]) { + db.execSQL(sql, object); + } + + public Cursor query(String sql) { + System.out.println(sql); + return db.rawQuery(sql, null); + + } + + /** + * add persons + * + * @param persons + */ + // public void add(List persons) { + // db.beginTransaction(); //开始事务 + // try { + // for (Person person : persons) { + // db.execSQL("INSERT INTO person VALUES(null, ?, ?, ?)", new + // Object[]{person.name, person.age, person.info}); + // } + // db.setTransactionSuccessful(); //设置事务成功完成 + // } finally { + // db.endTransaction(); //结束事务 + // } + // } + // + // /** + // * update person's age + // * @param person + // */ + // public void updateAge(Person person) { + // ContentValues cv = new ContentValues(); + // cv.put("age", person.age); + // db.update("person", cv, "name = ?", new String[]{person.name}); + // } + // + // /** + // * delete old person + // * @param person + // */ + // public void deleteOldPerson(Person person) { + // db.delete("person", "age >= ?", new + // String[]{String.valueOf(person.age)}); + // } + // + // /** + // * query all persons, return list + // * @return List + // */ + // public List query() { + // ArrayList persons = new ArrayList(); + // Cursor c = queryTheCursor(); + // while (c.moveToNext()) { + // Person person = new Person(); + // person._id = c.getInt(c.getColumnIndex("_id")); + // person.name = c.getString(c.getColumnIndex("name")); + // person.age = c.getInt(c.getColumnIndex("age")); + // person.info = c.getString(c.getColumnIndex("info")); + // persons.add(person); + // } + // c.close(); + // return persons; + // } + // + // /** + // * query all persons, return cursor + // * @return Cursor + // */ + // public Cursor queryTheCursor() { + // Cursor c = db.rawQuery("SELECT * FROM person", null); + // return c; + // } + + /** + * close database + */ + public void closeDB() { + db.close(); + helper.close(); + db = null; + helper = null; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/chaoran/db/SqlHelpUtil.java b/app/src/main/java/com/chaoran/db/SqlHelpUtil.java new file mode 100644 index 0000000..ba0aec2 --- /dev/null +++ b/app/src/main/java/com/chaoran/db/SqlHelpUtil.java @@ -0,0 +1,35 @@ +package com.chaoran.db; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.database.sqlite.SQLiteOpenHelper; + +public class SqlHelpUtil extends SQLiteOpenHelper { + //建立表 desc 是说明 + String createTable="create table systable(col1 varchar(20),col2 varchar(10),col3 varchar(20),desc varchar(20));"; + private static final int VERSION = 1; + private static final String dataBaseName = "store.db"; + public SqlHelpUtil(Context context, String name, CursorFactory factory, + int version) { + super(context, name, factory, version); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(createTable); + } + public SqlHelpUtil(Context context, String name, int version) { + this(context, name, null, version); + } + public SqlHelpUtil(Context context) { + this(context, dataBaseName, VERSION); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // TODO Auto-generated method stub + + } + +} diff --git a/app/src/main/java/com/chaoran/entiry/Basemodel.java b/app/src/main/java/com/chaoran/entiry/Basemodel.java new file mode 100644 index 0000000..6fea61a --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/Basemodel.java @@ -0,0 +1,188 @@ +package com.chaoran.entiry; + +import java.io.Serializable; + +/* + *数据集 模块主表(basemodel)实体类 + *此类在当前系统中无用 只是为了与服务器映射 + */ +public class Basemodel implements Serializable{ + private String modelid;// 模块ID 主键 + private String modellx;// 模块类型 + private String model_proc;// 模块计算存储过程 + private String modelname;// 模块名称 + private String meizhu;// 备注 + private String show_fs;// 展现方式 + private String url;// BI报表运行路径 + private String save_tb;// 临时表名 + private String is_zuhe;// 模块集合 + private String usemodel;// 调用数据模块ID + private String chartName;// 图形英文名 + private String chartChinaName;// 图形中文名 + private String groupByColumn;// 聚合列 + private String sumColumn;// 求和列 + private String xcolumn;// 横轴列 + private String modelSQL;// 模块集合SQL + private String gridType;//表格类型 + private String dimension;//维度 + private String pivotText;//下钻内容 + + + public String getPivotText() { + return pivotText; + } + + public void setPivotText(String pivotText) { + this.pivotText = pivotText; + } + + public String getIs_zuhe() { + return is_zuhe; + } + + public void setIs_zuhe(String is_zuhe) { + this.is_zuhe = is_zuhe; + } + + public String getGridType() { + return gridType; + } + + public void setGridType(String gridType) { + this.gridType = gridType; + } + + public String getDimension() { + return dimension; + } + + public void setDimension(String dimension) { + this.dimension = dimension; + } + + public String getUsemodel() { + return usemodel; + } + + public void setUsemodel(String usemodel) { + this.usemodel = usemodel; + } + + public String getModelSQL() { + return modelSQL; + } + + public void setModelSQL(String modelSQL) { + this.modelSQL = modelSQL; + } + + public String getModelid() { + return modelid; + } + + public void setModelid(String modelid) { + this.modelid = modelid; + } + + public String getModellx() { + return modellx; + } + + public void setModellx(String modellx) { + this.modellx = modellx; + } + + public String getModel_proc() { + return model_proc; + } + + public void setModel_proc(String model_proc) { + this.model_proc = model_proc; + } + + public String getModelname() { + return modelname; + } + + public void setModelname(String modelname) { + this.modelname = modelname; + } + + public String getMeizhu() { + return meizhu; + } + + public void setMeizhu(String meizhu) { + this.meizhu = meizhu; + } + + public String getShow_fs() { + return show_fs; + } + + public void setShow_fs(String show_fs) { + this.show_fs = show_fs; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getSave_tb() { + return save_tb; + } + + public void setSave_tb(String save_tb) { + this.save_tb = save_tb; + } + + public String getChartName() { + return chartName; + } + + public void setChartName(String chartName) { + this.chartName = chartName; + } + + public String getChartChinaName() { + return chartChinaName; + } + + public void setChartChinaName(String chartChinaName) { + this.chartChinaName = chartChinaName; + } + + public String getGroupByColumn() { + return groupByColumn; + } + + public void setGroupByColumn(String groupByColumn) { + this.groupByColumn = groupByColumn; + } + + public String getSumColumn() { + return sumColumn; + } + + public void setSumColumn(String sumColumn) { + this.sumColumn = sumColumn; + } + + public String getXcolumn() { + return xcolumn; + } + + public void setXcolumn(String xcolumn) { + this.xcolumn = xcolumn; + } + + + + + + +} diff --git a/app/src/main/java/com/chaoran/entiry/DanJuEntity.java b/app/src/main/java/com/chaoran/entiry/DanJuEntity.java new file mode 100644 index 0000000..098d482 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/DanJuEntity.java @@ -0,0 +1,14 @@ +package com.chaoran.entiry; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Map; + +public class DanJuEntity implements Serializable{ + public FangAtyjk fangAtyjkVO;//方案通用接口数据源 + public DjMxZt djMxZtVo; // 明细总体数据源 + public ArrayList mxzdArray; // 明细字段数据源 + public ArrayList menuArray;// 单据菜单数据源 + public String pageNr;// 页面内容 + public String rightMenu;//右键菜单内容 +} diff --git a/app/src/main/java/com/chaoran/entiry/DataGrid.java b/app/src/main/java/com/chaoran/entiry/DataGrid.java new file mode 100644 index 0000000..e1b29d0 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/DataGrid.java @@ -0,0 +1,47 @@ +package com.chaoran.entiry; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +public class DataGrid implements Serializable { + private ArrayList tableHead;//保存表头数据 + private ArrayList tableData;//保存表格数据 + private ArrayList otherData;//保存其它数据 +// private Basemodel basemodel; +// +// public Basemodel getBasemodel() { +// return basemodel; +// } +// +// public void setBasemodel(Basemodel basemodel) { +// this.basemodel = basemodel; +// } + + public ArrayList getTableHead() { + return tableHead; + } + + public void setTableHead(ArrayList tableHead) { + this.tableHead = tableHead; + } + + public ArrayList getTableData() { + return tableData; + } + + public void setTableData(ArrayList tableData) { + this.tableData = tableData; + } + + public ArrayList getOtherData() { + return otherData; + } + + public void setOtherData(ArrayList otherData) { + this.otherData = otherData; + } + +} diff --git a/app/src/main/java/com/chaoran/entiry/DjMxZt.java b/app/src/main/java/com/chaoran/entiry/DjMxZt.java new file mode 100644 index 0000000..92aecfb --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/DjMxZt.java @@ -0,0 +1,19 @@ +package com.chaoran.entiry; + +import java.io.Serializable; + +/* + * 单据明细总体实体类 + */ +public class DjMxZt implements Serializable{ + public String fgdxzt;//非固定行字体 + public String gdxzt;//固定行字体 + public Boolean lbgx;//列表格线 + public Boolean xbgx;//行表格线 + public int fgdxbjs;//非固定行背景色 + public String rsSubFun;//记录提交执行函数 + public String rsDelFun;//记录删除执行函数 + public String rsAddFun;//记录增加执行函数 + public String rsCheckFun;//记录校验执行函数 + public String rsMoveFun;//记录移动执行函数 +} diff --git a/app/src/main/java/com/chaoran/entiry/Djselefa.java b/app/src/main/java/com/chaoran/entiry/Djselefa.java new file mode 100644 index 0000000..904db01 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/Djselefa.java @@ -0,0 +1,76 @@ +package com.chaoran.entiry; + +public class Djselefa implements java.io.Serializable{ + private String fangalx; + private String fangabh; + private String fangamch; + private String emptylyb; + private String selectmx; + private String t_sql; + private String hz_sql; + private String mx_sql; + + public String getFangalx() { + return fangalx; + } + + public void setFangalx(String fangalx) { + this.fangalx = fangalx; + } + + public String getFangabh() { + return fangabh; + } + + public void setFangabh(String fangabh) { + this.fangabh = fangabh; + } + + public String getFangamch() { + return fangamch; + } + + public void setFangamch(String fangamch) { + this.fangamch = fangamch; + } + + public String getEmptylyb() { + return emptylyb; + } + + public void setEmptylyb(String emptylyb) { + this.emptylyb = emptylyb; + } + + public String getSelectmx() { + return selectmx; + } + + public void setSelectmx(String selectmx) { + this.selectmx = selectmx; + } + + public String getT_sql() { + return t_sql; + } + + public void setT_sql(String t_sql) { + this.t_sql = t_sql; + } + + public String getHz_sql() { + return hz_sql; + } + + public void setHz_sql(String hz_sql) { + this.hz_sql = hz_sql; + } + + public String getMx_sql() { + return mx_sql; + } + + public void setMx_sql(String mx_sql) { + this.mx_sql = mx_sql; + } +} diff --git a/app/src/main/java/com/chaoran/entiry/FangAtyjk.java b/app/src/main/java/com/chaoran/entiry/FangAtyjk.java new file mode 100644 index 0000000..c6b8959 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/FangAtyjk.java @@ -0,0 +1,13 @@ +package com.chaoran.entiry; + +import java.io.Serializable; + +/*单据中的*方案通用接口维护实体类*/ +public class FangAtyjk implements Serializable{ + + public String djInit;//单据进入初始化函数 + public String newDjInit;//新开单据初始化函数 + public String djExit;//单据退出执行函数 + public String djTiming;//单据定时函数 + public String djRecordedBefore;//单据入账前执行函数 +} diff --git a/app/src/main/java/com/chaoran/entiry/PhotographUi.java b/app/src/main/java/com/chaoran/entiry/PhotographUi.java new file mode 100644 index 0000000..90e2feb --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/PhotographUi.java @@ -0,0 +1,50 @@ +package com.chaoran.entiry; + +import com.example.chaoran.MainActivity; +import com.util.DialogUtil; +import com.util.SysUtil; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.view.Gravity; +import android.view.View; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.LinearLayout; + +public class PhotographUi extends LinearLayout { + private SelfImage image; + private Button pz; + + public PhotographUi(Context context, int h) { + super(context); + this.setOrientation(VERTICAL); + setGravity(Gravity.CENTER_VERTICAL); + this.setVerticalGravity(1); + image = new SelfImage(context,true); + addView(image, new LayoutParams(LayoutParams.MATCH_PARENT, + h)); + pz = new Button(context); + pz.setText("拍照"); + addView(pz, new LayoutParams(LayoutParams.MATCH_PARENT, + LayoutParams.WRAP_CONTENT)); + } + public void setOnClickListener(OnClickListener clickListener){ + pz.setOnClickListener(clickListener); + } + public void setImageOnClickListener(OnClickListener clickListener){ + image.setOnClickListener(clickListener); + } + public void setImageBitmap(Bitmap bitmap){ + image.setBitmap(bitmap); + } + public Bitmap getImageBitmap(){ + return image.getBitmap(); + } +} diff --git a/app/src/main/java/com/chaoran/entiry/SelfButton.java b/app/src/main/java/com/chaoran/entiry/SelfButton.java new file mode 100644 index 0000000..b45cc89 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/SelfButton.java @@ -0,0 +1,13 @@ +package com.chaoran.entiry; + +import android.content.Context; +import android.widget.Button; + +public class SelfButton extends Button { + public String clickFun; + public String nextFocus; + public SelfButton(Context context) { + super(context); + } + +} diff --git a/app/src/main/java/com/chaoran/entiry/SelfCheckBox.java b/app/src/main/java/com/chaoran/entiry/SelfCheckBox.java new file mode 100644 index 0000000..f831005 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/SelfCheckBox.java @@ -0,0 +1,34 @@ +package com.chaoran.entiry; + +import com.example.chaoran.R; + +import android.content.Context; +import android.util.TypedValue; +import android.widget.CheckBox; +import android.widget.CompoundButton; + +public class SelfCheckBox extends CheckBox { + + public SelfCheckBox(Context context) { + super(context); + setButtonDrawable(R.drawable.checkbox_empty); + this.setPadding((int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, 24, context.getResources() + .getDisplayMetrics()), 0, 0,0); + setOnCheckedChangeListener(new OnCheckedChangeListener(){ + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + // TODO Auto-generated method stub + if(isChecked){ + setButtonDrawable(R.drawable.checkbox_full); + }else{ + setButtonDrawable(R.drawable.checkbox_empty); + } + } + }); + + // TODO Auto-generated constructor stub + } + +} diff --git a/app/src/main/java/com/chaoran/entiry/SelfDateField.java b/app/src/main/java/com/chaoran/entiry/SelfDateField.java new file mode 100644 index 0000000..ac448a2 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/SelfDateField.java @@ -0,0 +1,216 @@ +package com.chaoran.entiry; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import android.app.DatePickerDialog; +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.text.Editable; +import android.view.View; +import android.widget.DatePicker; +import android.widget.ImageButton; +import android.widget.RelativeLayout; + +import com.chaoran.imp.InputInterface; +import com.example.chaoran.R; + +public class SelfDateField extends RelativeLayout implements InputInterface { + private SelfEditText et; + private ImageButton but; + private Dialog dialog; + private Calendar calendar; + private SimpleDateFormat dateFormat; + private SimpleDateFormat format; + public String formatString = "yyyy-MM-dd"; + + public SelfDateField(final Context context) { + super(context); + et = new SelfEditText(context); + LayoutParams params = new LayoutParams( + LayoutParams.FILL_PARENT, + LayoutParams.FILL_PARENT); + params.leftMargin = 0; + params.rightMargin = 48; + params.bottomMargin = 0; + et.setPadding(0, 0, 0, 0); + et.setSingleLine(true); + // et.setLayoutParams(params); + et.setId(1); + addView(et, params); + but = new ImageButton(context); + // but.setScaleType(ScaleType.FIT_XY); + LayoutParams butParams = new LayoutParams( + 48, 48); + but.setPadding(0, 0, 0, 0); + but.setBackgroundResource(R.drawable.calendar); + butParams.addRule(RelativeLayout.CENTER_VERTICAL); + butParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + addView(but, butParams); + format = new SimpleDateFormat(formatString); + but.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (dialog == null) { + calendar = Calendar.getInstance(); + dialog = new DatePickerDialog(context, + new DatePickerDialog.OnDateSetListener() { + public void onDateSet(DatePicker view, + int year, int monthOfYear, + int dayOfMonth) { + // TODO Auto-generated method stub + if (dateFormat == null) { + dateFormat = new SimpleDateFormat( + formatString); + } + Date date = null; + try { + date = format.parse(year + "-" + + (monthOfYear + 1) + "-" + + dayOfMonth); + et.setText(dateFormat.format(date)); + } catch (ParseException e) { + et.setText("error"); + } + } + }, calendar.get(Calendar.YEAR), calendar + .get(Calendar.MONTH), calendar + .get(Calendar.DAY_OF_MONTH)); + } + dialog.show(); + + } + }); + } + + @Override + public void setOnFocusChangeListener(OnFocusChangeListener l) { + et.setOnFocusChangeListener(l); + } + + public void setText(CharSequence text) { + if (dateFormat == null) { + dateFormat = new SimpleDateFormat(formatString); + } + Date date = null; + try { + date = format.parse(text.toString()); + et.setText(dateFormat.format(date)); + } catch (ParseException e) { + et.setText(text); + } + } + + public Editable getText() { + return et.getText(); + } + + public void setTextSize(float size) { + et.setTextSize(size); + } + + public void setEnabled(boolean b) { + et.setEnabled(b); + but.setEnabled(b); + } + + public void setTag(Object tag) { + et.setTag(tag); + } + + public Object getTag() { + return et.getTag(); + } + + @Override + public void setBackgroundDrawable(Drawable gd) { + et.setBackgroundDrawable(gd); + } + + /* 接口方法 */ + public String getDefaultValue() { + return et.defaultValue; + } + + public void setDefaultValue(String defaultValue) { + et.defaultValue = defaultValue; + } + + public void setNextFocus(String focus) { + et.nextFocus = focus; + } + + public void setFocusInFun(String fun) { + et.focusInFun = fun; + } + + public void setFocusOutFun(String fun) { + et.focusOutFun = fun; + } + + public void setInputType(int type) { + et.setInputType(type); + } + + public boolean getCloseKeyBoard() { + return et.getCloseKeyBoard(); + } + + public void setCloseKeyBoard(boolean closeKeyBoard) { + et.setCloseKeyBoard(closeKeyBoard); + } + + @Override + public String getNextFocus() { + return et.getNextFocus(); + } + + @Override + public String getFocusInFun() { + return et.getFocusInFun(); + } + + @Override + public String getFocusOutFun() { + return et.getFocusOutFun(); + } + + @Override + public boolean getIsNull() { + return et.getIsNull(); + } + + @Override + public void setIsNull(boolean isNull) { + et.setIsNull(isNull); + } + + @Override + public String getLabel() { + return et.getLabel(); + } + + @Override + public void setLabel(String label) { + et.setLabel(label); + } + + @Override + public boolean getIsTextChange() { + return et.getIsTextChange(); + } + + @Override + public void setIsTextChange(boolean isTextChange) { + et.setIsTextChange(isTextChange); + } + + @Override + public void setTextColor(int color) { + et.setTextColor(color); + } + +} diff --git a/app/src/main/java/com/chaoran/entiry/SelfEditText.java b/app/src/main/java/com/chaoran/entiry/SelfEditText.java new file mode 100644 index 0000000..04684f1 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/SelfEditText.java @@ -0,0 +1,174 @@ +package com.chaoran.entiry; + +import com.chaoran.imp.InputInterface; + +import android.R; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.Paint.Style; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.AttributeSet; +import android.widget.EditText; + +public class SelfEditText extends EditText implements InputInterface { + public String defaultValue = ""; + public String nextFocus;// 下一个组件焦点 + + public String focusInFun;// + public String focusOutFun; + public boolean isNull; + public String label; + public boolean isTextChange = false; + public boolean closeKeyBoard; + public String showBorder="inset"; + private Paint paint; + + public SelfEditText(Context context) { + super(context); + setBackgroundResource(R.drawable.editbox_background); + this.addTextChangedListener(textWatcher); + } + + public SelfEditText(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onDraw(Canvas canvas) { + if (!showBorder.equals("none")) { + if (paint == null) { + paint = new Paint(); + } + paint.setStyle(Style.STROKE); + paint.setStrokeWidth(5); + if (this.isFocused() == true){ + paint.setColor(Color.parseColor("#FFA500")); + }else if (this.isEnabled()) { + paint.setColor(Color.parseColor("#708090")); + paint.setShadowLayer(5, 3, 3, Color.parseColor("#DCDCDC")); + } else { + paint.setColor(Color.parseColor("#DCDCDC")); + } + canvas.drawRoundRect(new RectF(this.getScrollX(), + this.getScrollY(), this.getWidth() - 1 + this.getScrollX(), + this.getHeight() + this.getScrollY() - 1), 3, 3, paint); + } + super.onDraw(canvas); + + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + public String getNextFocus() { + return nextFocus; + } + + public void setNextFocus(String nextFocus) { + this.nextFocus = nextFocus; + } + + public String getFocusInFun() { + return focusInFun; + } + + public void setFocusInFun(String focusInFun) { + this.focusInFun = focusInFun; + } + + public String getFocusOutFun() { + return focusOutFun; + } + + public void setFocusOutFun(String focusOutFun) { + this.focusOutFun = focusOutFun; + } + + public boolean getIsNull() { + return isNull; + } + + public void setIsNull(boolean isNull) { + this.isNull = isNull; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public boolean getIsTextChange() { + return isTextChange; + } + + public void setIsTextChange(boolean isTextChange) { + this.isTextChange = isTextChange; + } + + public boolean getCloseKeyBoard() { + return closeKeyBoard; + } + + public void setCloseKeyBoard(boolean closeKeyBoard) { + this.closeKeyBoard = closeKeyBoard; + } + + private TextWatcher textWatcher = new TextWatcher() { + private int start = 0; + private int length = 0; + private boolean isCome = true; + private boolean isGood = false; + @Override + public void onTextChanged(CharSequence s, int start, int before, + int count) { + if (!isTextChange) { + isTextChange = true; + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + if (/*"TIAOMA".equalsIgnoreCase(nextFocus) && start != 0 && */ after > 1 && isCome) { + this.start = start; + this.length = after; + isGood = true; + } + } + + @Override + public void afterTextChanged(Editable s) { + if (isGood) { + isGood = false; + isCome = false; + if (isNumeric(s.toString())) { + CharSequence str = s.subSequence(start, start + length); + s.clear(); + s.append(str); + } + isCome = true; + } + } + }; + + public static boolean isNumeric(String str) { + for (int i = 0; i < str.length(); i++) { + if (!Character.isLetterOrDigit(str.charAt(i))) { + return false; + } + } + return true; + } +} diff --git a/app/src/main/java/com/chaoran/entiry/SelfImage.java b/app/src/main/java/com/chaoran/entiry/SelfImage.java new file mode 100644 index 0000000..5459389 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/SelfImage.java @@ -0,0 +1,53 @@ +package com.chaoran.entiry; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.widget.ImageView; + +public class SelfImage extends ImageView { + private Bitmap bitmap; + private boolean isDrawBound; + + public Bitmap getBitmap() { + return bitmap; + } + + public void setBitmap(Bitmap bitmap) { + if (this.bitmap != null) { + setImageBitmap(null); + this.bitmap.recycle(); + this.bitmap = null; + } + setImageBitmap(bitmap); + this.bitmap = bitmap; + } + + public SelfImage(Context context) { + super(context); + } + + public SelfImage(Context context, boolean isDrawBound) { + super(context); + this.isDrawBound = isDrawBound; + } + + @Override + protected void onDraw(Canvas canvas) { + // TODO Auto-generated method stub + super.onDraw(canvas); + if (isDrawBound) { + Rect rec = canvas.getClipBounds(); + rec.bottom--; + rec.right--; + Paint paint = new Paint(); + paint.setColor(Color.RED); + paint.setStyle(Paint.Style.STROKE); + paint.setStrokeWidth(5); + canvas.drawRect(rec, paint); + } + } +} diff --git a/app/src/main/java/com/chaoran/entiry/SelfTextBut.java b/app/src/main/java/com/chaoran/entiry/SelfTextBut.java new file mode 100644 index 0000000..4d8ce62 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/SelfTextBut.java @@ -0,0 +1,189 @@ +package com.chaoran.entiry; + +import com.chaoran.imp.InputInterface; + +import com.example.chaoran.R; +import android.content.Context; +import android.graphics.Color; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.GradientDrawable; +import android.text.Editable; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RelativeLayout; + +public class SelfTextBut extends RelativeLayout implements InputInterface { + private SelfEditText et; + private SelfButton but; + + public SelfTextBut(Context context) { + super(context); + int w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, + 30, context.getResources().getDisplayMetrics()); + et = new SelfEditText(context); + LayoutParams params = new LayoutParams( + LayoutParams.FILL_PARENT, + LayoutParams.FILL_PARENT); + params.setMargins(0, 0, 0, 0); + et.setPadding(0, 0, w, 0); + et.setSingleLine(true); + // et.setLayoutParams(params); + et.setId(1); + addView(et, params); + but = new SelfButton(context); + LayoutParams butParams = new LayoutParams( + w, LayoutParams.FILL_PARENT); + + butParams.rightMargin = 0; + // butParams.leftMargin=this.getWidth()-10; + butParams.topMargin = 5; + butParams.bottomMargin = -2; + but.setPadding(0, 0, 0, 20); + // butParams.addRule(RelativeLayout.ALIGN_BASELINE, et.getId()); + butParams.addRule(RelativeLayout.ALIGN_RIGHT, et.getId()); + // butParams.addRule(RelativeLayout.ALIGN_TOP, et.getId()); + // butParams.addRule(RelativeLayout.ALIGN_BOTTOM, et.getId()); + // butParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + // but.setBackgroundColor(Color.BLUE); + but.setText("…"); + // but.setGravity(Gravity.TOP); + // Drawable dw1 = + // this.getResources().getDrawable(R.drawable.ic_action_search); + // but.setBackgroundResource(R.drawable.cang1); + addView(but, butParams); + } + + @Override + public void setOnFocusChangeListener(OnFocusChangeListener l) { + et.setOnFocusChangeListener(l); + } + + @Override + public void setOnClickListener(OnClickListener l) { + // TODO Auto-generated method stub + but.setOnClickListener(l); + } + + public void setText(CharSequence text) { + et.setText(text); + } + + public Editable getText() { + return et.getText(); + } + + public void setClickFun(String fun) { + but.clickFun = fun; + } + + public String getClickFun() { + return but.clickFun; + } + + public void setTextSize(float size) { + et.setTextSize(size); + } + + public void setEnabled(boolean b) { + et.setEnabled(b); + but.setEnabled(b); + } + + public void setTag(Object tag) { + et.setTag(tag); + } + + public Object getTag() { + return et.getTag(); + } + + @Override + public void setBackgroundDrawable(Drawable gd) { + et.setBackgroundDrawable(gd); + } + + /* 接口方法 */ + public String getDefaultValue() { + return et.defaultValue; + } + + public void setDefaultValue(String defaultValue) { + et.defaultValue = defaultValue; + } + + public void setNextFocus(String focus) { + et.nextFocus = focus; + } + + public void setFocusInFun(String fun) { + et.focusInFun = fun; + } + + public void setFocusOutFun(String fun) { + et.focusOutFun = fun; + } + + public void setInputType(int type) { + et.setInputType(type); + } + + public boolean getCloseKeyBoard() { + return et.getCloseKeyBoard(); + } + + public void setCloseKeyBoard(boolean closeKeyBoard) { + et.setCloseKeyBoard(closeKeyBoard); + } + + @Override + public String getNextFocus() { + return et.getNextFocus(); + } + + @Override + public String getFocusInFun() { + return et.getFocusInFun(); + } + + @Override + public String getFocusOutFun() { + return et.getFocusOutFun(); + } + + @Override + public boolean getIsNull() { + return et.getIsNull(); + } + + @Override + public void setIsNull(boolean isNull) { + et.setIsNull(isNull); + } + + @Override + public String getLabel() { + return et.getLabel(); + } + + @Override + public void setLabel(String label) { + et.setLabel(label); + } + + @Override + public boolean getIsTextChange() { + return et.getIsTextChange(); + } + + @Override + public void setIsTextChange(boolean isTextChange) { + et.setIsTextChange(isTextChange); + } + + @Override + public void setTextColor(int color) { + et.setTextColor(color); + } +} diff --git a/app/src/main/java/com/chaoran/entiry/Sys_DanJuFormsOptions.java b/app/src/main/java/com/chaoran/entiry/Sys_DanJuFormsOptions.java new file mode 100644 index 0000000..d9e56d9 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/Sys_DanJuFormsOptions.java @@ -0,0 +1,178 @@ +package com.chaoran.entiry; + +import java.io.Serializable; + +public class Sys_DanJuFormsOptions implements Serializable { + + private String FORMlx;// 单据类型 + private String FORMbs;// 单据标识 + private String FORMmch;// 单据名称 + private String FORMsm;// 单据说明 + private String mxactive;// 是否存在单据明细 + private String runtitle;// 运行标题 + private String beizhu;// 备注 + private String defaultFouseField;// 默认的焦点字段 + private int dialog_hei;// 单据展现高度 + private int dialog_wid;// 单据展现宽度 + private String rv_hz_sql;// 单据再现汇总SQL语句 + private String rv_mx_sql;// 单据再现明细SQL语句 + private String cannewmx;// 是否能手工增加明细 + private String candelmx;// 是否能删除明细 + private String suffix;// 单据后缀 + private byte[] FORM;// 单据内容 + private String chkupfld;// 查重字段(在单据操作过程中检查单据明细内是否有重复记录,重复记录以此字段内记录的字段为准) + private String isAndroid; + private String is_lx; + + public String getIs_lx() { + return is_lx; + } + + public void setIs_lx(String is_lx) { + this.is_lx = is_lx; + } + + public String getIsAndroid() { + return isAndroid; + } + + public void setIsAndroid(String isAndroid) { + this.isAndroid = isAndroid; + } + + public String getFORMlx() { + return FORMlx; + } + + public void setFORMlx(String mlx) { + FORMlx = mlx; + } + + public String getFORMbs() { + return FORMbs; + } + + public void setFORMbs(String mbs) { + FORMbs = mbs; + } + + public String getFORMmch() { + return FORMmch; + } + + public void setFORMmch(String mmch) { + FORMmch = mmch; + } + + public String getFORMsm() { + return FORMsm; + } + + public void setFORMsm(String msm) { + FORMsm = msm; + } + + public String getMxactive() { + return mxactive; + } + + public void setMxactive(String mxactive) { + this.mxactive = mxactive; + } + + public String getRuntitle() { + return runtitle; + } + + public void setRuntitle(String runtitle) { + this.runtitle = runtitle; + } + + public String getBeizhu() { + return beizhu; + } + + public void setBeizhu(String beizhu) { + this.beizhu = beizhu; + } + + public int getDialog_hei() { + return dialog_hei; + } + + public void setDialog_hei(int dialog_hei) { + this.dialog_hei = dialog_hei; + } + + public int getDialog_wid() { + return dialog_wid; + } + + public void setDialog_wid(int dialog_wid) { + this.dialog_wid = dialog_wid; + } + + public String getRv_hz_sql() { + return rv_hz_sql; + } + + public void setRv_hz_sql(String rv_hz_sql) { + this.rv_hz_sql = rv_hz_sql; + } + + public String getRv_mx_sql() { + return rv_mx_sql; + } + + public void setRv_mx_sql(String rv_mx_sql) { + this.rv_mx_sql = rv_mx_sql; + } + + public String getCannewmx() { + return cannewmx; + } + + public void setCannewmx(String cannewmx) { + this.cannewmx = cannewmx; + } + + public String getCandelmx() { + return candelmx; + } + + public void setCandelmx(String candelmx) { + this.candelmx = candelmx; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(String suffix) { + this.suffix = suffix; + } + + public byte[] getFORM() { + return FORM; + } + + public void setFORM(byte[] form) { + FORM = form; + } + + public String getChkupfld() { + return chkupfld; + } + + public void setChkupfld(String chkupfld) { + this.chkupfld = chkupfld; + } + + public String getDefaultFouseField() { + return defaultFouseField; + } + + public void setDefaultFouseField(String defaultFouseField) { + this.defaultFouseField = defaultFouseField; + } +} diff --git a/app/src/main/java/com/chaoran/entiry/Test.java b/app/src/main/java/com/chaoran/entiry/Test.java new file mode 100644 index 0000000..12dcbc6 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/Test.java @@ -0,0 +1,25 @@ +package com.chaoran.entiry; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class Test { + public static void main(String[] args) { + Map m=new HashMap(); + m.put("a","1"); + m.put("b","2"); + m.put("c","3"); + Set set=m.keySet(); + for(String a:set){ + System.out.println(a+"---"); + if(a.equals("a")){ + //set.remove(a); + } + } + Set set1=m.keySet(); + for(String b:set1){ + System.out.println(b); + } + } +} diff --git a/app/src/main/java/com/chaoran/entiry/UpdataInfo.java b/app/src/main/java/com/chaoran/entiry/UpdataInfo.java new file mode 100644 index 0000000..fc08cfd --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/UpdataInfo.java @@ -0,0 +1,31 @@ +package com.chaoran.entiry; +/*更新实体类*/ +public class UpdataInfo { + private String version; + private String url; + private String description; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/app/src/main/java/com/chaoran/entiry/UserList.java b/app/src/main/java/com/chaoran/entiry/UserList.java new file mode 100644 index 0000000..ef6c568 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/UserList.java @@ -0,0 +1,133 @@ +package com.chaoran.entiry; + +import java.io.Serializable; + +public class UserList implements Serializable{ + private int userid; + private String username; + private String lgnname; + private String pass; + private String udesc; + private int rid;// 对应的角色id + private String jigid;// 用户所对应的机构 + private String displaymode;//对应的角色显示方式 + + private String zhiyid_yw; + private String zhiybh_yw; + private String zhiyname_yw; + + private String wldwid; + private String wldwname; + private String state; + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getWldwid() { + return wldwid; + } + + public void setWldwid(String wldwid) { + this.wldwid = wldwid; + } + + public String getWldwname() { + return wldwname; + } + + public void setWldwname(String wldwname) { + this.wldwname = wldwname; + } + + public String getJigid() { + return jigid; + } + + public void setJigid(String jigid) { + this.jigid = jigid; + } + + public int getRid() { + return rid; + } + + public void setRid(int rid) { + this.rid = rid; + } + + public int getUserid() { + return userid; + } + + public void setUserid(int userid) { + this.userid = userid; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getLgnname() { + return lgnname; + } + + public void setLgnname(String lgnname) { + this.lgnname = lgnname; + } + + public String getPass() { + return pass; + } + + public void setPass(String pass) { + this.pass = pass; + } + + public String getUdesc() { + return udesc; + } + + public void setUdesc(String udesc) { + this.udesc = udesc; + } + + public String getZhiyid_yw() { + return zhiyid_yw; + } + + public void setZhiyid_yw(String zhiyid_yw) { + this.zhiyid_yw = zhiyid_yw; + } + + public String getZhiybh_yw() { + return zhiybh_yw; + } + + public void setZhiybh_yw(String zhiybh_yw) { + this.zhiybh_yw = zhiybh_yw; + } + + public String getZhiyname_yw() { + return zhiyname_yw; + } + + public void setZhiyname_yw(String zhiyname_yw) { + this.zhiyname_yw = zhiyname_yw; + } + + public String getDisplaymode() { + return displaymode; + } + + public void setDisplaymode(String displaymode) { + this.displaymode = displaymode; + } +} diff --git a/app/src/main/java/com/chaoran/entiry/Zujian.java b/app/src/main/java/com/chaoran/entiry/Zujian.java new file mode 100644 index 0000000..39f8ac3 --- /dev/null +++ b/app/src/main/java/com/chaoran/entiry/Zujian.java @@ -0,0 +1,8 @@ +package com.chaoran.entiry; + +import android.widget.ImageView; +import android.widget.TextView; + +public class Zujian { + public TextView tv; +} diff --git a/app/src/main/java/com/chaoran/imp/InputInterface.java b/app/src/main/java/com/chaoran/imp/InputInterface.java new file mode 100644 index 0000000..c94b35c --- /dev/null +++ b/app/src/main/java/com/chaoran/imp/InputInterface.java @@ -0,0 +1,61 @@ +package com.chaoran.imp; + +import android.graphics.drawable.Drawable; +import android.text.Editable; +import android.view.View.OnFocusChangeListener; + +public interface InputInterface { + public String getDefaultValue(); + public void setDefaultValue(String defaultValue); + + public String getNextFocus(); + + public void setNextFocus(String nextFocus); + + public String getFocusInFun(); + + public void setFocusInFun(String focusInFun); + + public String getFocusOutFun(); + + public void setFocusOutFun(String focusOutFun); + + public boolean getIsNull(); + + public void setIsNull(boolean isNull); + + public String getLabel(); + + public void setLabel(String label); + + public boolean getIsTextChange(); + + public void setIsTextChange(boolean isTextChange); + + public void setTag(final Object tag); + + public Object getTag(); + + public void setTextSize(float size); + + public void setOnFocusChangeListener(OnFocusChangeListener l); + + public boolean getCloseKeyBoard(); + + public void setCloseKeyBoard(boolean closeKeyBoard); + + public void setEnabled(boolean enabled); + + public void setBackgroundDrawable(Drawable d); + + public void setText(CharSequence text); + + public Editable getText(); + + public void setPadding(int left, int top, int right, int bottom); + + public void setGravity(int gravity); + + public void setInputType(int type); + public void setTextColor(int color); +} diff --git a/app/src/main/java/com/chaoran/listener/ImageClickListener.java b/app/src/main/java/com/chaoran/listener/ImageClickListener.java new file mode 100644 index 0000000..04a756a --- /dev/null +++ b/app/src/main/java/com/chaoran/listener/ImageClickListener.java @@ -0,0 +1,69 @@ +package com.chaoran.listener; + +import android.app.Activity; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.drawable.BitmapDrawable; +import android.view.Display; +import android.view.Gravity; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.View.OnKeyListener; +import android.view.ViewGroup.LayoutParams; +import android.widget.ImageView; +import android.widget.PopupWindow; + +import com.chaoran.entiry.SelfImage; +import com.example.chaoran.R; + +public class ImageClickListener implements OnClickListener { + private Activity activity; + + public ImageClickListener(Activity activity) { + this.activity = activity; + } + + @Override + public void onClick(View v) { + SelfImage img = (SelfImage) v; + if(img.getBitmap()==null){ + return; + } + View contentView = LayoutInflater + .from(activity.getApplicationContext()).inflate(R.layout.popup, + null); + // 设置popupWindow的背景颜色 + contentView.setBackgroundColor(Color.BLACK); + // 声明一个弹出框 + final PopupWindow popupWindow = new PopupWindow(contentView, + LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); + popupWindow.setFocusable(true); + popupWindow.setBackgroundDrawable(new BitmapDrawable());//加上这句返回键才对PopupWindow起作用 + popupWindow.showAtLocation(v, Gravity.CENTER_VERTICAL, 0, 0); + Display display = activity.getWindowManager().getDefaultDisplay(); + ImageView imageView = (ImageView) contentView + .findViewById(R.id.zoomimg); + // int width = display.getWidth(); + // int height = display.getHeight(); + // //将图片设置为宽100,高200,在这儿就可以实现图片的大小缩放 + // Bitmap resize=Bitmap.createScaledBitmap(img.getBitmap(), + // width,height, true); + // Matrix m=new Matrix(); + // // m.setRotate(90); //逆时针旋转15度 + // // //做好旋转与大小之后,重新创建位图,0-width宽度上显示的区域,高度类似 + // Bitmap b=Bitmap.createBitmap(resize, 0, 0, resize.getWidth(), + // resize.getHeight(),m, true); + // 显示图片 + imageView.setImageBitmap(img.getBitmap()); + imageView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + popupWindow.dismiss(); + } + }); + } + +} diff --git a/app/src/main/java/com/chaoran/listener/PzClickListener.java b/app/src/main/java/com/chaoran/listener/PzClickListener.java new file mode 100644 index 0000000..dfed85b --- /dev/null +++ b/app/src/main/java/com/chaoran/listener/PzClickListener.java @@ -0,0 +1,54 @@ +package com.chaoran.listener; + +import java.io.File; +import java.io.IOException; + +import com.chaoran.entiry.PhotographUi; +import com.example.chaoran.DjActivity; +import com.util.DialogUtil; +import com.util.SysUtil; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.provider.MediaStore; +import android.view.View; +import android.view.View.OnClickListener; + +public class PzClickListener implements OnClickListener { + private DjActivity activity; + + public PzClickListener(DjActivity activity) { + this.activity = activity; + } + + @Override + public void onClick(View v) { + if (SysUtil.isHasSdcard()) { + activity.photographUi=(PhotographUi) v.getParent(); + String root=android.os.Environment + .getExternalStorageDirectory().getAbsolutePath(); + Intent intent = new Intent(); + activity.pzImgPath = root+"/DCIM/Camera/pz.jpg"; + File dir = new File(root+"/DCIM/Camera"); + if (!dir.exists()) { + dir.mkdirs(); + } + File mPhotoFile = new File(activity.pzImgPath); + if (!mPhotoFile.exists()) { + try { + mPhotoFile.createNewFile(); + } catch (IOException e) { + DialogUtil.builder(activity, "提示信息", + "创建文件失败:" + e.toString(),0); + } + } + intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPhotoFile)); + intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); + activity.startActivityForResult(intent,8888); + } else { + DialogUtil.builder(activity, "提示信息", "请插入存储卡!",0); + } + } + +} diff --git a/app/src/main/java/com/chaoran/lx/activity/DownDataActivity.java b/app/src/main/java/com/chaoran/lx/activity/DownDataActivity.java new file mode 100644 index 0000000..9fd7947 --- /dev/null +++ b/app/src/main/java/com/chaoran/lx/activity/DownDataActivity.java @@ -0,0 +1,188 @@ +package com.chaoran.lx.activity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Set; + +import org.kobjects.base64.Base64; + +import com.chaoran.component.ButAdapter; +import com.chaoran.db.DBManager; +import com.chaoran.lx.thread.LxDataDownThread; +import com.example.chaoran.R; +import com.example.chaoran.RunYmupThread; +import com.example.chaoran.R.id; +import com.example.chaoran.R.layout; +import com.util.DialogUtil; +import com.util.IoUtil; + +import android.R.integer; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Intent; +import android.view.Menu; +import android.widget.ListView; +import android.widget.TextView; + +public class DownDataActivity extends Activity { + private ListView listView; + private ArrayList mData; + private ButAdapter butAdapter; + private ProgressDialog pd; + private DBManager dbManager; + private TextView tv;// 有参数页面的才保存到这里 ,没参数页面的次控件随流程走 以免后期改造成多线程下载造成并发问题; + private Handler dataDownHandler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + if (msg.what == 10) { + pd.setMessage(msg.obj.toString()); + } else if (msg.what == -1) { + pd.dismiss(); + DialogUtil.builder(DownDataActivity.this, "错误信息", "下载数据失败!" + + msg.obj,0); + } else { + pd.dismiss(); + ArrayList tempList = (ArrayList) msg.obj; + String tablename = tempList.get(0).toString(); + int size = dbManager.rsCount(tablename); + DialogUtil.builder(DownDataActivity.this, "提示信息", "下载数据成功!共下载" + + size + "条",0); + ((TextView) tempList.get(1)).setText(tempList.get(2).toString().concat("(") + .concat(String.valueOf(size)).concat(")")); + } + } + }; + private Handler tableDownhandler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == -1) { + pd.dismiss(); + DialogUtil.builder(DownDataActivity.this, "错误信息", "下载资料表失败!" + + msg.obj,0); + } else { + mData = (ArrayList) msg.obj; + butAdapter = new ButAdapter(DownDataActivity.this, mData, pd, + dbManager, "tablename","fanganmc"); + listView.setAdapter(butAdapter); + pd.dismiss(); + } + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.down_data_activity); + pd = new ProgressDialog(DownDataActivity.this); + pd.setCancelable(false); + DialogUtil.setDialog(pd, "信息提示", "正在下载离线表资料"); + new RunYmupThread(null, tableDownhandler, "tableListDown", 1).start(); + listView = (ListView) findViewById(R.id.downlist); + dbManager = new DBManager(this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + return true; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (butAdapter != null) { + butAdapter.clean(); + butAdapter = null; + } + if (mData != null) { + mData.clear(); + mData = null; + } + if (dbManager != null) { + dbManager.closeDB(); + dbManager = null; + } + if (listView != null) { + listView = null; + } + if (pd != null) { + pd.dismiss(); + pd = null; + } + tv = null; + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + switch (resultCode) { + case 1: + Bundle bunde = data.getExtras(); + HashMap map = (HashMap) bunde.getSerializable("map"); + runDownThread(map, tv); + break; + default: + break; + } + } + + public void downData(HashMap map, TextView tv) { + Object formlx = map.get("formlx"); + System.out.println(formlx.toString() + + "==================================="); + if (formlx != null && formlx.toString().trim().length() > 0) { + this.tv = tv; + Bundle bundle = new Bundle(); + bundle.putSerializable("map", map); + Intent intent = new Intent(); + intent.putExtras(bundle); + intent.setClass(getApplicationContext(), Lx_Param_Activity.class); + startActivityForResult(intent, 1); + } else { + runDownThread(map, tv); + // HashMap paramMap=new HashMap(); + // String + // sql="select * from (".concat(map.get("downsql").toString()).concat(") temptable where rowNumber between") + // paramMap.put("sql",map.get("downsql")); + // if(map.containsKey("param")){ + // paramMap.put("param", map.get("param")); + // } + // byte[] b; + // try { + // b = IoUtil.getbyte(paramMap); + // String paramString = Base64.encode(b); + // new RunYmupThread(paramString, dataDownHandler , "lxDataDown", + // 1).start(); + // DialogUtil.setDialog(pd, "下载数据", + // "正在下载"+map.get("tablename")+"表数据"); + // } catch (Exception e) { + // DialogUtil.builder(DownDataActivity.this, "错误信息", + // "组织下载数据失败!" + e.toString()); + // } + } + } + + public void runDownThread(HashMap map, TextView tv) { + HashMap param = null; + if (map.containsKey("param")) { + param = (HashMap) map.get("param"); + } + Set set = map.keySet(); + for (String s : set) { + System.out.println(s + "-----" + map.get(s)); + } + LxDataDownThread lxDataDownThread = new LxDataDownThread( + dataDownHandler, 1, Integer.parseInt(map.get("paging") + .toString()), dbManager, map.get("downsql").toString().toUpperCase(), + param, map.get("tablename").toString().toUpperCase(), map.get( + "createtabelsql").toString().toUpperCase(), pd, tv, map.get("fanganmc").toString()); + new Thread(lxDataDownThread).start(); + DialogUtil.setDialog(pd, "下载数据", "正在下载" + map.get("tablename") + + "表数据,第1页"); + } +} diff --git a/app/src/main/java/com/chaoran/lx/activity/Lx_Param_Activity.java b/app/src/main/java/com/chaoran/lx/activity/Lx_Param_Activity.java new file mode 100644 index 0000000..c6ebde4 --- /dev/null +++ b/app/src/main/java/com/chaoran/lx/activity/Lx_Param_Activity.java @@ -0,0 +1,135 @@ +package com.chaoran.lx.activity; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.dom4j.DocumentException; + +import com.chaoran.entiry.DanJuEntity; +import com.chaoran.entiry.Sys_DanJuFormsOptions; +import com.chaoran.thread.DownDJRun; +import com.example.chaoran.DjActivity; +import com.example.chaoran.R; +import com.example.chaoran.R.layout; +import com.example.chaoran.R.menu; +import com.util.DialogUtil; +import com.util.IoUtil; +import com.util.LxParamPageCreate; +import com.util.SqlUtil; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Intent; +import android.view.Menu; +import android.view.View; +import android.widget.RelativeLayout; + +public class Lx_Param_Activity extends Activity { + private HashMap map; + private RelativeLayout lx_page; + private ProgressDialog pd; + private Handler downDJhandler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + super.handleMessage(msg); + pd.dismiss(); + if (msg.what == -1) { + DialogUtil.builder(Lx_Param_Activity.this, "错误信息", + "查询参数页面内容失败:" + msg.obj,0); + } else { + Object initOb = msg.obj; + if (initOb instanceof Map) { + HashMap djInitMap = (HashMap) initOb; + Sys_DanJuFormsOptions danju = (Sys_DanJuFormsOptions) djInitMap + .get("danju"); + ByteArrayInputStream in = null; + try { + DanJuEntity dj = (DanJuEntity) IoUtil.byte_obj2(danju + .getFORM()); + String[] arrs = dj.pageNr.split("\\^"); + if (arrs.length > 1) { + dj.pageNr = arrs[0]; + } + in = new ByteArrayInputStream(dj.pageNr.getBytes()); + } catch (Exception e) { + DialogUtil.builder(Lx_Param_Activity.this, "错误信息", + "生成参数页面失败!" + e.toString(),0); + } finally { + try { + in.close(); + LxParamPageCreate.lxParamPageCreate(in, + Lx_Param_Activity.this, lx_page); + + } catch (IOException e) { + DialogUtil.builder(Lx_Param_Activity.this, "错误信息", + "生成参数页面流失败!" + e.toString(),0); + } catch (DocumentException e) { + DialogUtil.builder(Lx_Param_Activity.this, "错误信息", + "生成参数页面失败!" + e.toString(),0); + } + in = null; + } + }else{ + if (initOb.equals("0")) { + DialogUtil.builder(Lx_Param_Activity.this, "提示信息", "PDA未注册!",0); + } else if (initOb.equals("1")) { + DialogUtil.builder(Lx_Param_Activity.this, "提示信息", + "PDA还未授权使用!",0); + } else if (initOb.equals("2")) { + DialogUtil.builder(Lx_Param_Activity.this, "提示信息", "试用期已过!",0); + } else if (initOb.equals("该模块未授权")) { + DialogUtil.builder(Lx_Param_Activity.this, "提示信息", "该模块未授权!",0); + } + } + } + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.lx_param_activity); + Bundle bundle = this.getIntent().getExtras(); + map = (HashMap) bundle.getSerializable("map"); + lx_page = (RelativeLayout) findViewById(R.id.lx_page); + pd = new ProgressDialog(Lx_Param_Activity.this); + pd.setCancelable(false); + DialogUtil.setDialog(pd, "信息提示", "正在下载参数页面数据"); + new Thread(new DownDJRun(map.get("formlx").toString(), downDJhandler)) + .start(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + return true; + } + @Override + protected void onDestroy() { + super.onDestroy(); + if(map!=null){ + map.clear(); + map=null; + } + lx_page=null; + pd=null; + } + + public void sub_back(View v) { + HashMap tempMap = SqlUtil + .regSql(map.get("downsql").toString(), lx_page); + map.put("downsql", tempMap.get("sql")); + map.put("param", tempMap.get("param")); + Bundle bundle = new Bundle(); + bundle.putSerializable("map", map); + Intent intent = getIntent(); + intent.putExtras(bundle); + setResult(1, intent); + finish(); + } +} diff --git a/app/src/main/java/com/chaoran/lx/thread/LxDJNrThread.java b/app/src/main/java/com/chaoran/lx/thread/LxDJNrThread.java new file mode 100644 index 0000000..454b595 --- /dev/null +++ b/app/src/main/java/com/chaoran/lx/thread/LxDJNrThread.java @@ -0,0 +1,135 @@ +package com.chaoran.lx.thread; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.StreamCorruptedException; +import java.util.HashMap; +import java.util.List; + +import android.database.Cursor; +import android.os.Handler; +import android.os.Message; + +import com.chaoran.db.DBManager; +import com.chaoran.entiry.DanJuEntity; +import com.chaoran.entiry.Sys_DanJuFormsOptions; +import com.util.DateUtil; + +import flex.messaging.io.ArrayList; + +public class LxDJNrThread implements Runnable { + private DBManager dbManager; + private Handler menuHandler; + private String formlx; + + public LxDJNrThread(DBManager dbManager, Handler menuHandler, String formlx) { + this.dbManager = dbManager; + this.menuHandler = menuHandler; + this.formlx = formlx; + } + + @Override + public void run() { + String sql = "select FORMbs,mxactive,candelmx,cannewmx,defaultFouseField,dialog_hei,dialog_wid,FORMsm,FORM from Sys_DanJuFormsOptions where rtrim(formlx)='" + + formlx + "'"; + Cursor cur = dbManager.query(sql); + Sys_DanJuFormsOptions danju = null; + if (cur.moveToFirst()) { + danju = new Sys_DanJuFormsOptions(); + danju.setFORMbs(cur.getString(0)); + danju.setMxactive(cur.getString(1)); + danju.setCandelmx(cur.getString(2)); + danju.setCannewmx(cur.getString(3)); + danju.setDefaultFouseField(cur.getString(4)); + danju.setDialog_hei(Integer.parseInt(cur.getString(5))); + danju.setDialog_wid(Integer.parseInt(cur.getString(6))); + danju.setFORMsm(cur.getString(7)); + System.out.println(cur.getColumnIndex("FORM")); + byte[] b = cur.getBlob(8); + // System.out.println(b); + danju.setFORM(b); + } + cur.close(); + HashMap fangAMap = new HashMap(); + if (dbManager.existsTable("sys_SearchOptions".toUpperCase()) > 0) { + sql = "select functitle,upper('SEARCH_'+rtrim(functionname)) as funName,fangalx,dialog_wid,dialog_hei,dialog_cap,zdysql,(CASE return_one WHEN '是' THEN'Y' ELSE 'N' END )AS return_one ,audioFld from sys_SearchOptions where rtrim(fangalx)='" + + formlx + "'"; + cur = dbManager.query(sql); + HashMap tempMap = null; + int len = cur.getColumnCount(); + for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { + tempMap = new HashMap(); + for (int i = 0; i < len; i++) { + tempMap.put(cur.getColumnName(i), cur.getString(i)); + } + fangAMap.put(tempMap.get("funName"), tempMap); + } + cur.close(); + } + System.out.println(dbManager.existsTable("sys_YmupOptions" + .toUpperCase()) + "-----------------------"); + if (dbManager.existsTable("sys_YmupOptions".toUpperCase()) > 0) { + sql = "select upper('YMUP_'||rtrim(fangabh)) as funName,zdysql as zdysql from Sys_YmupOptions where rtrim(fangalx)='" + + formlx + "'"; + cur = dbManager.query(sql); + HashMap tempMap = null; + int len = cur.getColumnCount(); + System.out.println(len + "--------len---------------" + + cur.getCount()); + for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { + System.out.println("-------------=========-------------"); + tempMap = new HashMap(); + for (int i = 0; i < len; i++) { + tempMap.put(cur.getColumnName(i), cur.getString(i)); + System.out.println(cur.getColumnName(i) + "------" + + cur.getString(i)); + } + fangAMap.put(tempMap.get("funName"), tempMap); + } + cur.close(); + } + if (dbManager.existsTable("Djselefa".toUpperCase()) > 0) { + sql = "select upper('DJTQ_'+rtrim(fangabh)) as funName,fangalx,fangamch, emptylyb, selectmx, t_sql, hz_sql, mx_sql from Djselefa where rtrim(fangalx)='" + + formlx + "'"; + cur = dbManager.query(sql); + HashMap tempMap = null; + int len = cur.getColumnCount(); + for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { + tempMap = new HashMap(); + for (int i = 0; i < len; i++) { + tempMap.put(cur.getColumnName(i), cur.getString(i)); + } + fangAMap.put(tempMap.get("funName"), tempMap); + } + cur.close(); + } + HashMap djInitMap = new HashMap(); + djInitMap.put("danju", danju); + djInitMap.put("GZID", ""); + djInitMap.put("RQ", DateUtil.getDateAndTime()); + djInitMap.put("ONTIME", DateUtil.getTime()); + // djInitMap.put("searchList", new ArrayList()); + // djInitMap.put("ymupList", new ArrayList()); + // djInitMap.put("djtqList", new ArrayList()); + Message message = new Message(); +// ArrayList tempList = new ArrayList(); +// tempList.add(djInitMap); +// tempList.add(fangAMap); + djInitMap.put("fangAMap",fangAMap); + message.obj = fangAMap; + menuHandler.sendMessage(message); + // if (danju != null) { + // System.out.println(danju.getFORM().length+"---------------------------------"); + // ByteArrayInputStream bin = new ByteArrayInputStream(danju.getFORM()); + // try { + // ObjectInputStream oin = new ObjectInputStream(bin); + // DanJuEntity danJuEntity=(DanJuEntity) oin.readObject(); + // System.out.println(danJuEntity.pageNr + "--------"); + // } catch (Exception e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // } + } +} diff --git a/app/src/main/java/com/chaoran/lx/thread/LxDataDownThread.java b/app/src/main/java/com/chaoran/lx/thread/LxDataDownThread.java new file mode 100644 index 0000000..854340e --- /dev/null +++ b/app/src/main/java/com/chaoran/lx/thread/LxDataDownThread.java @@ -0,0 +1,142 @@ +package com.chaoran.lx.thread; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.kobjects.base64.Base64; +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; +import org.xmlpull.v1.XmlPullParserException; + +import com.chaoran.db.DBManager; +import com.sys.SysData; +import com.util.IoUtil; + +import android.app.ProgressDialog; +import android.os.Handler; +import android.os.Message; +import android.widget.TextView; + +public class LxDataDownThread implements Runnable { + private Handler handler; + private int currentPage; + private int pagingNum;// 每页条数 + private DBManager dbManager; + private String sql; + private HashMap param; + private String tablename; + private String createtablesql; + private ProgressDialog pd; + private TextView tv; + private String showTvStr; + + public LxDataDownThread(Handler handler, int currentPage, int pagingNum, + DBManager dbManager, String sql, HashMap param, String tablename, + String createtablesql, ProgressDialog pd, TextView tv,String showTvStr) { + this.handler = handler; + this.currentPage = currentPage; + this.pagingNum = pagingNum; + this.dbManager = dbManager; + this.sql = sql; + this.param = param; + this.tablename = tablename; + this.createtablesql = createtablesql; + this.pd = pd; + this.tv = tv; + this.showTvStr=showTvStr; + } + + @Override + public void run() { + try { + luoji(); + Message msg = new Message(); + msg.what = 1; + ArrayList tempList = new ArrayList(); + tempList.add(tablename); + tempList.add(tv); + tempList.add(showTvStr); + msg.obj = tempList; + handler.sendMessage(msg); + } catch (Exception e) { + e.printStackTrace(); + Message msg = new Message(); + msg.what = -1; + msg.obj = e.toString(); + handler.sendMessage(msg); + } finally { + dbManager = null; + } + } + + private void luoji() throws Exception { + System.gc(); + String url = SysData.url + "/webservice/offLineInventoryInterface?wsdl"; + String method = "lxDataDown"; + SoapObject rpc = new SoapObject("", method); + int start = (currentPage - 1) * pagingNum + 1; + String tempSql = "select * from (".concat(sql).concat( + ") temptable where rowNumber between '" + start + "' and '" + + currentPage * pagingNum + "'"); + HashMap tempParamMap = new HashMap(); + tempParamMap.put("sql", tempSql); + if (currentPage == 1) { + tempParamMap.put("currentPage", currentPage); + tempParamMap.put("mac", SysData.clientid); + } + if (param != null) { + tempParamMap.put("param", param); + } + byte[] b = IoUtil.getbyte(tempParamMap); + String paramString = Base64.encode(b); + rpc.addProperty("param", paramString); + HttpTransportSE ht = new HttpTransportSE(url); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + byte[] bb = Base64.decode(envelope.getResponse() + .toString()); + Object ob = IoUtil.byte_obj(bb); + if (!(ob instanceof List)) { + throw new Exception(ob.toString()); + } + + List list = (List) ob; + if (currentPage == 1) { + System.out.println(tablename+"--------------------"+dbManager.existsTable(tablename)); + if (dbManager.existsTable(tablename) > 0) { + dbManager.exeSql("drop table ".concat(tablename)); + } + dbManager.exeSql(createtablesql); + } + if (list != null && list.size() > 0) { + dbManager.batchSave(list, tablename); + } + if (list.size() == pagingNum) { + list.clear(); + list = null; + currentPage++; + Message msg = new Message(); + msg.what = 10; + msg.obj = "正在下载" + tablename + "表数据,第" + currentPage + "页"; + handler.sendMessage(msg); + // pd.setMessage("正在下载"+tablename+"表数据,第"+currentPage+"页"); + luoji(); + } + // HashMap map=new HashMap(); + // map.put("obj", IoUtil.byte_obj(bb)); + // map.put("tableName",tablename); + // map.put("currentPage", currentPage); + // msg.obj = map; + // handler.sendMessage(msg); + } + +} diff --git a/app/src/main/java/com/chaoran/lx/thread/LxMenuQueryThread.java b/app/src/main/java/com/chaoran/lx/thread/LxMenuQueryThread.java new file mode 100644 index 0000000..3f7c0bf --- /dev/null +++ b/app/src/main/java/com/chaoran/lx/thread/LxMenuQueryThread.java @@ -0,0 +1,39 @@ +package com.chaoran.lx.thread; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import android.database.Cursor; +import android.os.Handler; +import android.os.Message; + +import com.chaoran.db.DBManager; + +public class LxMenuQueryThread implements Runnable { + private DBManager dbManager; + private List menuData; + private Handler menuHandler; + public LxMenuQueryThread(DBManager dbManager,Handler menuHandler,List menuData){ + this.dbManager=dbManager; + this.menuData=menuData; + this.menuHandler=menuHandler; + } + @Override + public void run() { + Cursor cur=dbManager.query("select formlx as gn_no,formsm as mname from Sys_danjuformsoptions"); + ArrayList list=new ArrayList(); + HashMap map; + while(cur.moveToNext()){ + map=new HashMap(); + map.put("gn_no", cur.getString(0)); + map.put("mname", cur.getString(1)); + list.add(map); + } + cur.close(); + menuData.addAll(list); + Message message = new Message(); + menuHandler.sendMessage(message); + } + +} diff --git a/app/src/main/java/com/chaoran/lx/thread/LxRunYmupThread.java b/app/src/main/java/com/chaoran/lx/thread/LxRunYmupThread.java new file mode 100644 index 0000000..8d1584e --- /dev/null +++ b/app/src/main/java/com/chaoran/lx/thread/LxRunYmupThread.java @@ -0,0 +1,54 @@ +package com.chaoran.lx.thread; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import android.database.Cursor; +import android.os.Handler; +import android.os.Message; + +import com.chaoran.db.DBManager; + +import flex.messaging.io.ArrayList; + +public class LxRunYmupThread implements Runnable { + private DBManager dbManager; + private String ymupSql; + private Map hzData; + private Handler handler; + public LxRunYmupThread(DBManager dbManager,String ymupSql,Map hzData,Handler handler){ + this.dbManager=dbManager; + this.ymupSql=ymupSql; + this.hzData=hzData; + this.handler=handler; + } + @Override + public void run() { + System.out.println(dbManager.rsCount("TEMP_BI_DJHZ")+"-=====------------------条"); + dbManager.exeSql("delete from TEMP_BI_DJHZ"); + System.out.println(dbManager.rsCount("TEMP_BI_DJHZ")+"-=====------------------条"); + String hzSql="insert into TEMP_BI_DJHZ(FIELDNAME,FIELDVALUE) values(?,?)"; + dbManager.batchSave(hzSql, hzData); + Cursor cursor=dbManager.query(ymupSql); + String mess=null; + if(cursor.moveToFirst()){ + mess=cursor.getString(0); + } + cursor.close(); + cursor=dbManager.query("select fieldname,fieldvalue from TEMP_BI_DJHZ"); + ArrayList list=new ArrayList(); + for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){ + HashMap hzMap=new HashMap(); + hzMap.put(cursor.getString(0),cursor.getString(1)); + list.add(hzMap); + } + HashMap returnMap=new HashMap(); + returnMap.put("mes", mess); + returnMap.put("hz", list); + Message msg = new Message(); + msg.arg1 = 2; + handler.sendMessage(msg); + System.out.println(dbManager.rsCount("TEMP_BI_DJHZ")+"-------------------条"); + } +} diff --git a/app/src/main/java/com/chaoran/thread/DownApk.java b/app/src/main/java/com/chaoran/thread/DownApk.java new file mode 100644 index 0000000..5da34ac --- /dev/null +++ b/app/src/main/java/com/chaoran/thread/DownApk.java @@ -0,0 +1,43 @@ +package com.chaoran.thread; + +import java.io.File; + +import android.app.ProgressDialog; +import android.content.Context; +import android.os.Handler; +import android.os.Message; + +import com.util.DownloadManager; + +public class DownApk implements Runnable{ + private ProgressDialog pd; + private String url; + private Context context; + private Handler handler; + + public DownApk(ProgressDialog pd,String url, Context context,Handler handler) { + this.pd = pd; + this.url= url; + this.context = context; + this.handler=handler; + } + + @Override + public void run() { + try { + File file = DownloadManager.getFileFromServer( + url, pd, context); + Thread.currentThread().sleep(3000); + pd.dismiss(); + Message msg = new Message(); + msg.what=2; + msg.obj = file; + handler.sendMessage(msg); + } catch (Exception e) { + Message msg = new Message(); + msg.what =-5; + handler.sendMessage(msg); + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/com/chaoran/thread/DownDJRun.java b/app/src/main/java/com/chaoran/thread/DownDJRun.java new file mode 100644 index 0000000..842af7e --- /dev/null +++ b/app/src/main/java/com/chaoran/thread/DownDJRun.java @@ -0,0 +1,60 @@ +package com.chaoran.thread; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + +import com.sys.SysData; +import com.util.IoUtil; + +import android.os.Handler; +import android.os.Message; + +public class DownDJRun implements Runnable { + private String formlx; + private Handler handler; + public DownDJRun(String formlx,Handler handler){ + this.formlx=formlx; + this.handler=handler; + } + @Override + public void run() { + Object ob; + try { + ob = getWeather(formlx); + Message message = new Message(); + message.obj = ob; + handler.sendMessage(message); + } catch (Exception e) { + Message message = new Message(); + message.obj = e.toString(); + message.what = -1; + handler.sendMessage(message); + } + } + public Object getWeather(String FORMlx) throws Exception { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + String method = "querydjNrWs"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("FORMlx", FORMlx); + rpc.addProperty("mac", SysData.clientid); + rpc.addProperty("userid", SysData.userid); + HttpTransportSE ht = new HttpTransportSE(url,SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + Object djInitMap = null; + if (envelope.getResponse() != null) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + byte[] bb = org.kobjects.base64.Base64.decode(envelope + .getResponse().toString()); + djInitMap = IoUtil.byte_obj(bb); + } + return djInitMap; + } + +} diff --git a/app/src/main/java/com/chaoran/thread/ImageUrl.java b/app/src/main/java/com/chaoran/thread/ImageUrl.java new file mode 100644 index 0000000..d81c7f5 --- /dev/null +++ b/app/src/main/java/com/chaoran/thread/ImageUrl.java @@ -0,0 +1,42 @@ +package com.chaoran.thread; + +import java.io.IOException; +import java.util.HashMap; + +import com.chaoran.entiry.SelfImage; +import com.util.BitMapUtil; + +import android.graphics.Bitmap; +import android.os.Handler; +import android.os.Message; +import android.widget.ImageView; + +public class ImageUrl implements Runnable { + private SelfImage img; + private String url; + private Handler handler; + + public ImageUrl(SelfImage img, String url, Handler handler) { + this.img = img; + this.url = url; + this.handler = handler; + } + + @Override + public void run() { + Bitmap bitMap; + Message msg = new Message(); + try { + bitMap = BitMapUtil.generateBitMap(url); + HashMap map=new HashMap(); + map.put("image", img); + map.put("bitMap", bitMap); + msg.obj =map; + handler.sendMessage(msg); + } catch (IOException e) { + msg.what=-1; + handler.sendMessage(msg); + } + } + +} diff --git a/app/src/main/java/com/chaoran/thread/UpdatePwdThread.java b/app/src/main/java/com/chaoran/thread/UpdatePwdThread.java new file mode 100644 index 0000000..edc069a --- /dev/null +++ b/app/src/main/java/com/chaoran/thread/UpdatePwdThread.java @@ -0,0 +1,51 @@ +package com.chaoran.thread; + +import java.io.IOException; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; +import org.xmlpull.v1.XmlPullParserException; + +import com.sys.SysData; + +import android.os.Handler; +import android.os.Message; +public class UpdatePwdThread implements Runnable { + private Handler handler; + private String userid; + private String newPwd; + public UpdatePwdThread(Handler handler,String userid,String newPwd) { + this.handler=handler; + this.userid=userid; + this.newPwd=newPwd; + } + @Override + public void run() { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + String method = "updatePwd"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("userid",userid); + rpc.addProperty("newPwd",newPwd); + HttpTransportSE ht = new HttpTransportSE(url,SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + Message msg = new Message(); + try { + ht.call("", envelope); + String backmsg=envelope.getResponse().toString(); + msg.obj =backmsg; + handler.sendMessage(msg); + } catch (Exception e) { + msg.obj =e.toString(); + msg.what = -1; + handler.sendMessage(msg); + } + } + +} diff --git a/app/src/main/java/com/cr5w/scan/CR5WScanControl.java b/app/src/main/java/com/cr5w/scan/CR5WScanControl.java new file mode 100644 index 0000000..70c0473 --- /dev/null +++ b/app/src/main/java/com/cr5w/scan/CR5WScanControl.java @@ -0,0 +1,72 @@ +package com.cr5w.scan; + +import android.app.Instrumentation; +import android.content.Context; +import android.util.Log; +import android.widget.Toast; + +public class CR5WScanControl { + + private boolean isRun = true; + private boolean isOpen = true; + + public boolean getIsOpen() { + return this.isOpen; + } + + public void setIsOpen(boolean isOpen) { + this.isOpen = isOpen; + } + + public void init(final Context context) { + new Thread() { + public void run() { + try { + while (true) { + if (isRun && 1 == ScanHelper.getScanModel(context)) { + Instrumentation inst = new Instrumentation(); + Log.v("cr5w-SetScanHeader", "scan: send key begin"); + inst.sendKeyDownUpSync(220); + inst.sendKeyDownUpSync(221); + Log.v("cr5w-SetScanHeader", "scan: send key end"); + } + sleep(500); + } +// init(context); + } catch (Exception e) { + e.printStackTrace(); + } + } + + }.start(); + } + + public void start(Context context) { + if (!this.isOpen) + return; + Log.v("cr5w-SetScanHeader", "scan: start begin"); + ScanHelper.setScanSwitchLeft(context, true); + ScanHelper.setScanSwitchRight(context, true); + Log.v("cr5w-SetScanHeader", "scan: start end"); + if (!isRun) { + isRun = true; + } + } + + public void stop(Context context) { + Log.v("cr5w-SetScanHeader", "scan: stop begin"); + ScanHelper.setScanSwitchLeft(context, false); + ScanHelper.setScanSwitchRight(context, false); + Log.v("cr5w-SetScanHeader", "scan: stop end"); + isRun = false; + } + + public void restart(Context context) { + stop(context); + start(context); + } + + public void clear() { + isRun = false; + } +} diff --git a/app/src/main/java/com/cr5w/scan/ScanHelper.java b/app/src/main/java/com/cr5w/scan/ScanHelper.java new file mode 100644 index 0000000..f67deb9 --- /dev/null +++ b/app/src/main/java/com/cr5w/scan/ScanHelper.java @@ -0,0 +1,283 @@ +package com.cr5w.scan; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.provider.Settings; +public class ScanHelper { + /** scan settings show 0 : no; 1 : yes*/ + public static final String SCAN_SETTINGS_HAVED = "scan_settings_haved"; + /** scan settings left enable 0 : no; 1 : yes*/ + public static final String SCAN_SETTINGS_LEFT = "scan_settings_left"; + /** scan settings right enable 0 : no; 1 : yes*/ + public static final String SCAN_SETTINGS_RIGHT = "scan_settings_right"; + /** scan models settings 0 : noraml; 1 : continue auto; 2 : continue manual*/ + public static final String SCAN_MODLES_SETTINGS = "scan_models_settings"; + /** scan continue delay settings 0 : none; 1 : 0.5s; 2 : 1s; 3 : custom*/ + public static final String SCAN_CONTINUE_DELAY_SETTINGS = "scan_continue_delay_settings"; + /** scan continue delay value */ + public static final String SCAN_CONTINUE_DELAY_CUSTOM_VALUE = "scan_continue_delay_custom_value"; + /** barcode receive model 0 : fast; 1 : slow; 2 : broadcast*/ + public static final String BARCODE_RECEIVE_MODELS_SETTINGS = "barcode_receive_models_settings"; + /** barcode separator model 0 : none; 1 : '\n'; 2 : Enter*/ + public static final String BARCODE_SEPARATOR_SETTINGS = "barcode_separator_settings"; + /** barcode separator prefix settings 0 : no; 1 : yes*/ + public static final String BARCODE_SEPARATOR_PREFIX_SETTINGS = "barcode_separator_prefix_settings"; + /** barcode separator prefix content */ + public static final String BARCODE_SEPARATOR_PREFIX = "barcode_separator_prefix"; + /** barcode separator suffix settings 0 : no; 1 : yes*/ + public static final String BARCODE_SEPARATOR_SUFFIX_SETTINGS = "barcode_separator_suffix_settings"; + /** barcode separator suffix content */ + public static final String BARCODE_SEPARATOR_SUFFIX = "barcode_separator_suffix"; + /** scan sound settings 0 : no; 1 : yes*/ + public static final String SCAN_SOUND_SETTINGS = "scan_sound_settings"; + /** scan vibrate settings 0 : no; 1 : yes*/ + public static final String SCAN_VIBRATE_SETTINGS = "scan_vibrate_settings"; + + public static boolean getScanToggleState(Context context) { + boolean flag = false; + boolean scan_left = Settings.System.getInt(context.getContentResolver(), + SCAN_SETTINGS_LEFT, 0) != 0; + boolean scan_right = Settings.System.getInt(context.getContentResolver(), + SCAN_SETTINGS_RIGHT, 0) != 0; + if(scan_left != false || scan_right != false){ + flag = true; + } + return flag; + } + /** + * scan left state + * @param context + * @return + */ + public static boolean getScanSwitchLeft(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_SETTINGS_LEFT, 0) != 0; + } + + /** + * set scan left state + * @param context + * @param flag + */ + public static void setScanSwitchLeft(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_SETTINGS_LEFT, flag ? 1 : 0); + } + + /** + * scan right state + * @param context + * @return + */ + public static boolean getScanSwitchRight(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_SETTINGS_RIGHT, 0) != 0; + } + + /** + * set scan right state + * @param context + * @param flag + */ + public static void setScanSwitchRight(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_SETTINGS_RIGHT, flag ? 1 : 0); + } + + /** + * scan model state + * @param context + * @return 0 : normal; 1 : continue auto; 2 : continue manual + */ + public static int getScanModel(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_MODLES_SETTINGS, 0); + } + + /** + * set scan model state + * @param context + * @param flag 0 : normal; 1 : continue auto; 2 : continue manual + */ + public static void setScanModel(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), SCAN_MODLES_SETTINGS, state); + } + + /** + * scan delay state + * @param context + * @return 0 : none; 1 : 0.5s; 2 : 1s;3 : custom delay + */ + public static int getScanDelaySetting(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_CONTINUE_DELAY_SETTINGS, 0); + } + + /** + * set scan delay state + * @param context + * @param flag 0 : none; 1 : 0.5s; 2 : 1s;3 : custom delay + */ + public static void setScanDelaySetting(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), SCAN_CONTINUE_DELAY_SETTINGS, state); + } + + /** + * scan delay value + * @param context + * @return delay + */ + public static float getScanDelay(Context context){ + return Settings.System.getFloat(context.getContentResolver(), SCAN_CONTINUE_DELAY_CUSTOM_VALUE, 0); + } + + /** + * set scan delay value + * @param context + * @param delay + */ + public static void setScanDelay(Context context, float delay){ + Settings.System.putFloat(context.getContentResolver(), SCAN_CONTINUE_DELAY_CUSTOM_VALUE, delay); + } + + /** + * barcode receive model state + * @param context + * @return 0 : fast; 1 : slow; 2 : broadcast + */ + public static int getBarcodeReceiveModel(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_RECEIVE_MODELS_SETTINGS, 0); + } + + /** + * set broadcast receive model state + * @param context + * @param flag 0 : fast; 1 : slow; 2 : broadcast + */ + public static void setBarcodeReceiveModel(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), BARCODE_RECEIVE_MODELS_SETTINGS, state); + } + + /** + * barcode separator state + * @param context + * @return 0 : none; 1 : newline; 2 : enter + */ + public static int getBarcodeSeparator(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_SEPARATOR_SETTINGS, 0); + } + + /** + * set barcode separator state + * @param context + * @param flag 0 : none; 1 : newline; 2 : enter + */ + public static void setBarcodeSeparator(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), BARCODE_SEPARATOR_SETTINGS, state); + } + + /** + * barcode Prefix state + * @param context + * @return 0 : close; 1 : open + */ + public static boolean getBarcodePrefixState(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX_SETTINGS, 0) != 0; + } + + /** + * set barcode Prefix state + * @param context + * @param flag 0 : close; 1 : open + */ + public static void setBarcodePrefixState(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX_SETTINGS, flag ? 1 : 0); + } + + /** + * barcode Prefix + * @param context + * @return + */ + public static String getBarcodePrefix(Context context){ + return Settings.System.getString(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX); + } + + /** + * set barcode Prefix + * @param context + * @param + */ + public static void setBarcodePrefix(Context context, String prefix){ + Settings.System.putString(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX, prefix); + } + + /** + * barcode Suffix state + * @param context + * @return 0 : close; 1 : open + */ + public static boolean getBarcodeSuffixState(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX_SETTINGS, 0) != 0; + } + + /** + * set barcode Suffix state + * @param context + * @param flag 0 : close; 1 : open + */ + public static void setBarcodeSuffixState(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX_SETTINGS, flag ? 1 : 0); + } + + /** + * barcode Suffix + * @param context + * @return + */ + public static String getBarcodeSuffix(Context context){ + return Settings.System.getString(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX); + } + + /** + * set barcode Suffix + * @param context + * @param + */ + public static void setBarcodeSuffix(Context context, String suffix){ + Settings.System.putString(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX, suffix); + } + + /** + * scan sound state + * @param context + * @return + */ + public static boolean getScanSound(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_SOUND_SETTINGS, 0) != 0; + } + + /** + * set scan sound state + * @param context + * @param flag + */ + public static void setScanSound(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_SOUND_SETTINGS, flag ? 1 : 0); + } + + /** + * scan Vibrate state + * @param context + * @return + */ + public static boolean getScanVibrate(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_VIBRATE_SETTINGS, 0) != 0; + } + + /** + * set scan Vibrate state + * @param context + * @param flag + */ + public static void setScanVibrate(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_VIBRATE_SETTINGS, flag ? 1 : 0); + } +} diff --git a/app/src/main/java/com/cr5w/scan/ScanKeyEventRunnable.java b/app/src/main/java/com/cr5w/scan/ScanKeyEventRunnable.java new file mode 100644 index 0000000..7b2f011 --- /dev/null +++ b/app/src/main/java/com/cr5w/scan/ScanKeyEventRunnable.java @@ -0,0 +1,26 @@ +package com.cr5w.scan; + +import android.content.Context; +import android.content.Intent; + +public class ScanKeyEventRunnable implements Runnable { + public boolean isrun = true; + private Context context; + + public ScanKeyEventRunnable(Context context) { + this.context = context; + } + + public void run() { + while (isrun) { + Intent intent = new Intent(); + intent.setAction("com.barcode.sendBroadcastScan"); + context.sendBroadcast(intent); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/app/src/main/java/com/cr5w/scan/SysBarcodeUtil.java b/app/src/main/java/com/cr5w/scan/SysBarcodeUtil.java new file mode 100644 index 0000000..2a639c1 --- /dev/null +++ b/app/src/main/java/com/cr5w/scan/SysBarcodeUtil.java @@ -0,0 +1,296 @@ +/** + * use permission: + * + */ +package com.cr5w.scan; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.provider.Settings; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + + +/** + * @author wpx + * + */ +public class SysBarcodeUtil { + private SysBarcodeUtil(){ + /* cannot be instantiated */ + throw new UnsupportedOperationException("cannot be instantiated"); + } + + private static final String BARCODE_SETTINGS_LEFT = "barcode_settings_left"; + private static final String BARCODE_SETTINGS_LEFT_SELECTED = "barcode_settings_left_selected"; + private static final String BARCODE_SETTINGS_RIGHT = "barcode_settings_right"; + private static final String BARCODE_SETTINGS_RIGHT_SELECTED = "barcode_settings_right_selected"; + private static final String BARCODE_TYPE = "barcode_typemessage_settings"; + private static final String BARCODE_INTERVAL_SETTINGS = "BARCODE_INTERVAL_SETTINGS"; + private static final String BARCODE_SENDMESSAGE_SETTINGS = "barcode_sendmessage_settings"; + private static final String BARCODE_NEWPARAGRAPH_SETTINGS = "barcode_newparagraph_settings"; + + /** + * + */ + private static final String BARCODE_ACTION = "com.barcode.sendBroadcast"; + /** + * + */ + private static final String BARCODE_PARAM = "BARCODE"; + + /** + * + */ + private static Object object; + /** + * + */ + private static BroadcastReceiver barcodeReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + // TODO Auto-generated method stub + String action = intent.getAction(); + if(BARCODE_ACTION.equals(action)){ + String barcode = intent.getStringExtra(BARCODE_PARAM); + if(object == null){ + Toast.makeText(context, "Object is null.", Toast.LENGTH_SHORT).show(); + return; + } + + if(object instanceof EditText){ + ((EditText)object).setText(barcode); + }else if(object instanceof TextView){ + ((TextView)object).setText(barcode); + }else{ + Toast.makeText(context, "Object is not fit.", Toast.LENGTH_SHORT).show(); + } + } + } + }; + + /** + * + * @param obj + * @return + */ + public static BroadcastReceiver getBarcodeReceiver(Object obj){ + object = obj; + return barcodeReceiver; + } + + /** + * + * @return + */ + public static IntentFilter getBarcodeFilter(){ + return new IntentFilter(BARCODE_ACTION); + } + + private static SysBarcodeUtil Instance = null; + private static Context mContext = null; + public static SysBarcodeUtil getInstance(Context context){ + if(Instance == null){ + Instance = new SysBarcodeUtil(); + } + mContext = context; + return Instance; + } + + /** + * + * @return + */ + public String getSysBarcodeDefaultValue(){ + StringBuilder strValues = new StringBuilder(); + strValues.append(getLeftSwitchState(mContext)).append(","); + strValues.append(getLeftScanSelected(mContext)).append(","); + strValues.append(getRightSwitchState(mContext)).append(","); + strValues.append(getRightScanSelected(mContext)).append(","); + strValues.append(getBarcodeSendMode(mContext)).append(","); + strValues.append(getBarcodeNewParagraphMode(mContext)); + + return strValues.toString(); + } + + /** + * + * @param LeftSwitchState false : 0, true : 1 + * @param LeftScanSelected 0 : hardware, 1 : camera + * @param RightSwitchState false : 0, true : 1 + * @param RightScanSelected 0 : hardware, 1 : camera + * @param BarcodeSendMode 0 : fast, 1 : slow, 2 : broadcast + * @param BarcodeNewParagraphMode 0 : "Enter newline" ; 1 : "\n newline"; 2 : "no newline" + */ + public void setSysBarcodeValue(boolean LeftSwitchState, + int LeftScanSelected, + boolean RightSwitchState, + int RightScanSelected, + int BarcodeSendMode, + int BarcodeNewParagraphMode){ + + setLeftSwitchState(mContext, LeftSwitchState); + setLeftScanSelected(mContext, LeftScanSelected); + setRightSwitchState(mContext, RightSwitchState); + setRightScanSelected(mContext, RightScanSelected); + setBarcodeSendMode(mContext, BarcodeSendMode); + setBarcodeNewParagraphMode(mContext, BarcodeNewParagraphMode); + + sendBroadcastSysBarcode(); + } + + /** + * + */ + public void sendBroadcastSysBarcode(){ + Intent intent = new Intent("SysScanSettingChanged"); + mContext.sendBroadcast(intent); + } + + /** + * get left scan key state 0 : close , 1 : open + * @return + */ + public static boolean getLeftSwitchState(Context context){ + return Settings.System.getInt(context.getContentResolver(), + BARCODE_SETTINGS_LEFT, 0) != 0; + } + + /** + * set left scan state + * @param flag false : 0, true : 1 + */ + public static void setLeftSwitchState(Context context,boolean flag){ + Settings.System.putInt(context.getContentResolver(), + BARCODE_SETTINGS_LEFT,flag ? 1 : 0); + } + + /** + * get left scan selected(hardware or camera) + * @return 0 : hardware, 1 : camera + */ + public static int getLeftScanSelected(Context context){ + return Settings.System.getInt(context.getContentResolver(), + BARCODE_SETTINGS_LEFT_SELECTED, 0); + } + + /** + * set left scan selected(hardware or camera) + * type 0 : hardware, 1 : camera + */ + public static void setLeftScanSelected(Context context,int type){ + Settings.System.putInt(context.getContentResolver(), + BARCODE_SETTINGS_LEFT_SELECTED, type); + } + + /** + * set right scan key state 0 : close , 1 : open + * @return + */ + public static boolean getRightSwitchState(Context context){ + return Settings.System.getInt(context.getContentResolver(), + BARCODE_SETTINGS_RIGHT, 0) != 0; + } + + /** + * get right scan state + * @param flag false : 0, true : 1 + */ + public static void setRightSwitchState(Context context,boolean flag){ + Settings.System.putInt(context.getContentResolver(), + BARCODE_SETTINGS_RIGHT,flag ? 1 : 0); + } + + /** + * get right scan selected(hardware or camera) + * @return 0 : hardware, 1 : camera + */ + public static int getRightScanSelected(Context context){ + return Settings.System.getInt(context.getContentResolver(), + BARCODE_SETTINGS_RIGHT_SELECTED, 0); + } + + /** + * set left scan selected(hardware or camera) + * type 0 : hardware, 1 : camera + */ + public static void setRightScanSelected(Context context,int type){ + Settings.System.putInt(context.getContentResolver(), + BARCODE_SETTINGS_RIGHT_SELECTED, type); + } + + /** + * get send barcode type + * @return Mode 0 normal,2 repeat + */ + public static int getBarcodeType(Context context) { + return Settings.System.getInt(context.getContentResolver(), + BARCODE_TYPE, 0); + } + + /** + * set send barcode interval + * @param Mode + */ + public static void setBarcodeInterval(Context context,int mode) { + Settings.System.putInt(context.getContentResolver(), + BARCODE_INTERVAL_SETTINGS, mode); + } + + /** + * get send barcode interval + * @return + */ + public static int getBarcodeInterval(Context context) { + return Settings.System.getInt(context.getContentResolver(), + BARCODE_INTERVAL_SETTINGS, 30000); + } + + /** + * set send barcode type + * @param Mode 0 normal,2 repeat + */ + public static void setBarcodeType(Context context,int mode) { + Settings.System.putInt(context.getContentResolver(), + BARCODE_TYPE, mode); + } + + /** + * get send barcode mode + * @return Mode 0 is fast,1 is slow,2 is broadcast + */ + public static int getBarcodeSendMode(Context context) { + return Settings.System.getInt(context.getContentResolver(), + BARCODE_SENDMESSAGE_SETTINGS, 0); + } + + /** + * set send barcode mode + * @param mode Send Mode 0 is fast,1 is slow,2 is broadcast + */ + public static void setBarcodeSendMode(Context context,int mode) { + Settings.System.putInt(context.getContentResolver(), + BARCODE_SENDMESSAGE_SETTINGS, mode); + } + + /** + * get newlins way mode + * @return 0 : "Enter newline" ; 1 : "\n newline"; 2 : "no newline" + */ + public static int getBarcodeNewParagraphMode(Context context) { + return Settings.System.getInt(context.getContentResolver(), + BARCODE_NEWPARAGRAPH_SETTINGS, 0); + } + + /** + * set newlines way mode 0 : "Enter newline" ; 1 : "\n newline"; 2 : "no newline" + * @param mode + */ + public static void setBarcodeNewParagraphMode(Context context,int mode) { + Settings.System.putInt(context.getContentResolver(), + BARCODE_NEWPARAGRAPH_SETTINGS, mode); + } +} diff --git a/app/src/main/java/com/cr5w/scan/aht70/ScanHelper.java b/app/src/main/java/com/cr5w/scan/aht70/ScanHelper.java new file mode 100644 index 0000000..c9d7bef --- /dev/null +++ b/app/src/main/java/com/cr5w/scan/aht70/ScanHelper.java @@ -0,0 +1,284 @@ +package com.cr5w.scan.aht70; + + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.provider.Settings; +public class ScanHelper { + /** scan settings show 0 : no; 1 : yes*/ + public static final String SCAN_SETTINGS_HAVED = "scan_settings_haved"; + /** scan settings left enable 0 : no; 1 : yes*/ + public static final String SCAN_SETTINGS_LEFT = "scan_settings_left"; + /** scan settings right enable 0 : no; 1 : yes*/ + public static final String SCAN_SETTINGS_RIGHT = "scan_settings_right"; + /** scan models settings 0 : noraml; 1 : continue auto; 2 : continue manual*/ + public static final String SCAN_MODLES_SETTINGS = "scan_models_settings"; + /** scan continue delay settings 0 : none; 1 : 0.5s; 2 : 1s; 3 : custom*/ + public static final String SCAN_CONTINUE_DELAY_SETTINGS = "scan_continue_delay_settings"; + /** scan continue delay value */ + public static final String SCAN_CONTINUE_DELAY_CUSTOM_VALUE = "scan_continue_delay_custom_value"; + /** barcode receive model 0 : fast; 1 : slow; 2 : broadcast*/ + public static final String BARCODE_RECEIVE_MODELS_SETTINGS = "barcode_receive_models_settings"; + /** barcode separator model 0 : none; 1 : '\n'; 2 : Enter*/ + public static final String BARCODE_SEPARATOR_SETTINGS = "barcode_separator_settings"; + /** barcode separator prefix settings 0 : no; 1 : yes*/ + public static final String BARCODE_SEPARATOR_PREFIX_SETTINGS = "barcode_separator_prefix_settings"; + /** barcode separator prefix content */ + public static final String BARCODE_SEPARATOR_PREFIX = "barcode_separator_prefix"; + /** barcode separator suffix settings 0 : no; 1 : yes*/ + public static final String BARCODE_SEPARATOR_SUFFIX_SETTINGS = "barcode_separator_suffix_settings"; + /** barcode separator suffix content */ + public static final String BARCODE_SEPARATOR_SUFFIX = "barcode_separator_suffix"; + /** scan sound settings 0 : no; 1 : yes*/ + public static final String SCAN_SOUND_SETTINGS = "scan_sound_settings"; + /** scan vibrate settings 0 : no; 1 : yes*/ + public static final String SCAN_VIBRATE_SETTINGS = "scan_vibrate_settings"; + + public static boolean getScanToggleState(Context context) { + boolean flag = false; + boolean scan_left = Settings.System.getInt(context.getContentResolver(), + SCAN_SETTINGS_LEFT, 0) != 0; + boolean scan_right = Settings.System.getInt(context.getContentResolver(), + SCAN_SETTINGS_RIGHT, 0) != 0; + if(scan_left != false || scan_right != false){ + flag = true; + } + return flag; + } + /** + * scan left state + * @param context + * @return + */ + public static boolean getScanSwitchLeft(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_SETTINGS_LEFT, 0) != 0; + } + + /** + * set scan left state + * @param context + * @param flag + */ + public static void setScanSwitchLeft(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_SETTINGS_LEFT, flag ? 1 : 0); + } + + /** + * scan right state + * @param context + * @return + */ + public static boolean getScanSwitchRight(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_SETTINGS_RIGHT, 0) != 0; + } + + /** + * set scan right state + * @param context + * @param flag + */ + public static void setScanSwitchRight(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_SETTINGS_RIGHT, flag ? 1 : 0); + } + + /** + * scan model state + * @param context + * @return 0 : normal; 1 : continue auto; 2 : continue manual + */ + public static int getScanModel(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_MODLES_SETTINGS, 0); + } + + /** + * set scan model state + * @param context + * @param flag 0 : normal; 1 : continue auto; 2 : continue manual + */ + public static void setScanModel(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), SCAN_MODLES_SETTINGS, state); + } + + /** + * scan delay state + * @param context + * @return 0 : none; 1 : 0.5s; 2 : 1s;3 : custom delay + */ + public static int getScanDelaySetting(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_CONTINUE_DELAY_SETTINGS, 0); + } + + /** + * set scan delay state + * @param context + * @param flag 0 : none; 1 : 0.5s; 2 : 1s;3 : custom delay + */ + public static void setScanDelaySetting(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), SCAN_CONTINUE_DELAY_SETTINGS, state); + } + + /** + * scan delay value + * @param context + * @return delay + */ + public static float getScanDelay(Context context){ + return Settings.System.getFloat(context.getContentResolver(), SCAN_CONTINUE_DELAY_CUSTOM_VALUE, 0); + } + + /** + * set scan delay value + * @param context + * @param delay + */ + public static void setScanDelay(Context context, float delay){ + Settings.System.putFloat(context.getContentResolver(), SCAN_CONTINUE_DELAY_CUSTOM_VALUE, delay); + } + + /** + * barcode receive model state + * @param context + * @return 0 : fast; 1 : slow; 2 : broadcast + */ + public static int getBarcodeReceiveModel(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_RECEIVE_MODELS_SETTINGS, 0); + } + + /** + * set broadcast receive model state + * @param context + * @param flag 0 : fast; 1 : slow; 2 : broadcast + */ + public static void setBarcodeReceiveModel(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), BARCODE_RECEIVE_MODELS_SETTINGS, state); + } + + /** + * barcode separator state + * @param context + * @return 0 : none; 1 : newline; 2 : enter + */ + public static int getBarcodeSeparator(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_SEPARATOR_SETTINGS, 0); + } + + /** + * set barcode separator state + * @param context + * @param flag 0 : none; 1 : newline; 2 : enter + */ + public static void setBarcodeSeparator(Context context, int state){ + Settings.System.putInt(context.getContentResolver(), BARCODE_SEPARATOR_SETTINGS, state); + } + + /** + * barcode Prefix state + * @param context + * @return 0 : close; 1 : open + */ + public static boolean getBarcodePrefixState(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX_SETTINGS, 0) != 0; + } + + /** + * set barcode Prefix state + * @param context + * @param flag 0 : close; 1 : open + */ + public static void setBarcodePrefixState(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX_SETTINGS, flag ? 1 : 0); + } + + /** + * barcode Prefix + * @param context + * @return + */ + public static String getBarcodePrefix(Context context){ + return Settings.System.getString(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX); + } + + /** + * set barcode Prefix + * @param context + * @param + */ + public static void setBarcodePrefix(Context context, String prefix){ + Settings.System.putString(context.getContentResolver(), BARCODE_SEPARATOR_PREFIX, prefix); + } + + /** + * barcode Suffix state + * @param context + * @return 0 : close; 1 : open + */ + public static boolean getBarcodeSuffixState(Context context){ + return Settings.System.getInt(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX_SETTINGS, 0) != 0; + } + + /** + * set barcode Suffix state + * @param context + * @param flag 0 : close; 1 : open + */ + public static void setBarcodeSuffixState(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX_SETTINGS, flag ? 1 : 0); + } + + /** + * barcode Suffix + * @param context + * @return + */ + public static String getBarcodeSuffix(Context context){ + return Settings.System.getString(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX); + } + + /** + * set barcode Suffix + * @param context + * @param + */ + public static void setBarcodeSuffix(Context context, String suffix){ + Settings.System.putString(context.getContentResolver(), BARCODE_SEPARATOR_SUFFIX, suffix); + } + + /** + * scan sound state + * @param context + * @return + */ + public static boolean getScanSound(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_SOUND_SETTINGS, 0) != 0; + } + + /** + * set scan sound state + * @param context + * @param flag + */ + public static void setScanSound(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_SOUND_SETTINGS, flag ? 1 : 0); + } + + /** + * scan Vibrate state + * @param context + * @return + */ + public static boolean getScanVibrate(Context context){ + return Settings.System.getInt(context.getContentResolver(), SCAN_VIBRATE_SETTINGS, 0) != 0; + } + + /** + * set scan Vibrate state + * @param context + * @param flag + */ + public static void setScanVibrate(Context context, boolean flag){ + Settings.System.putInt(context.getContentResolver(), SCAN_VIBRATE_SETTINGS, flag ? 1 : 0); + } +} diff --git a/app/src/main/java/com/device/zk_r322a/ZKR322AControl.java b/app/src/main/java/com/device/zk_r322a/ZKR322AControl.java new file mode 100644 index 0000000..e2a1bb7 --- /dev/null +++ b/app/src/main/java/com/device/zk_r322a/ZKR322AControl.java @@ -0,0 +1,64 @@ +package com.device.zk_r322a; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import android.gpio.GpioJNI; +import android.util.Log; +import android_serialport_api.SerialPort; + +public class ZKR322AControl { + private SerialPort mSerialPort = null; + private OutputStream mOutputStream = null; + private InputStream mInputStream = null; + //private boolean readVal = false; + + public ZKR322AControl() throws SecurityException, IOException { + mSerialPort = new SerialPort(new File("/dev/ttyS4"), 115200, 8, 'N', 1,0); + mOutputStream = mSerialPort.getOutputStream(); + mInputStream = mSerialPort.getInputStream(); + } + + public String getData() { + if (mInputStream == null) return ""; + try { + int size = mInputStream.available(); + byte[] buffer = new byte[size]; + size = mInputStream.read(buffer); + if (size > 0) { + return new String(buffer); + } + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } + + public void start() { + //readVal = true; + // GpioJNI.gpio_switch_scan_trig(1); + } + + public void stop() { + //readVal = false; + // GpioJNI.gpio_switch_scan_trig(0); + } + + //public boolean isRead() { + // return readVal; + //} + + public void close() { + if (mSerialPort != null) { + mSerialPort.close(); + } + } + + + public void initScan() { + // GpioJNI.gpio_switch_scan_rf_ired(0); + // GpioJNI.gpio_switch_scan_power(1); + } +} diff --git a/app/src/main/java/com/example/chaoran/DjActivity.java b/app/src/main/java/com/example/chaoran/DjActivity.java new file mode 100644 index 0000000..0ffda0a --- /dev/null +++ b/app/src/main/java/com/example/chaoran/DjActivity.java @@ -0,0 +1,2549 @@ +package com.example.chaoran; + +import android.app.AlertDialog; +import android.app.Instrumentation; +import android.app.ProgressDialog; +import android.app.TabActivity; +import android.content.*; +import android.content.DialogInterface.OnCancelListener; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.media.MediaPlayer.OnCompletionListener; +import android.media.SoundPool; +import android.net.wifi.WifiManager; +import android.net.wifi.WifiManager.WifiLock; +import android.os.*; +import android.os.PowerManager.WakeLock; +import android.speech.tts.TextToSpeech; +import android.speech.tts.TextToSpeech.OnInitListener; +import android.util.Log; +import android.view.*; +import android.view.View.OnClickListener; +import android.view.ViewGroup.LayoutParams; +import android.view.inputmethod.InputMethodManager; +import android.widget.*; +import android.widget.AdapterView.OnItemClickListener; +import com.chaoran.component.ImageAdpter; +import com.chaoran.component.MyAdapter; +import com.chaoran.db.DBManager; +import com.chaoran.entiry.*; +import com.chaoran.listener.ImageClickListener; +import com.chaoran.listener.PzClickListener; +import com.chaoran.lx.thread.LxDJNrThread; +import com.chaoran.lx.thread.LxMenuQueryThread; +import com.chaoran.lx.thread.LxRunYmupThread; +import com.chaoran.thread.DownDJRun; +import com.cr5w.scan.CR5WScanControl; +import com.cr5w.scan.aht70.ScanHelper; +import com.device.zk_r322a.ZKR322AControl; +import com.honeywell.aidc.*; +import com.jiebao.h518.scan.BeepManager; +import com.jiebao.h518.scan.NewScanControler; +import com.lianxin.nr510.Engine; +import com.seuic.scan.SeuicScanKeyEventRunnable; +import com.seuic.scanner.DecodeInfo; +import com.seuic.scanner.DecodeInfoCallBack; +import com.seuic.scanner.ScannerFactory; +import com.seuic.scanner.ScannerKey; +import com.sys.SysData; +import com.util.*; +import org.kobjects.base64.Base64; +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.*; + +/** + * 富力叶不兼容版本代码 + * import com.olc.scan.IScanCallBack; + * import com.olc.scan.ScanManager; + **/ + +/* + * DecodeInfoCallBack 接口 是seuic的 扫描 后 的 回调接口 + */ +public class DjActivity extends TabActivity implements OnInitListener, DecodeInfoCallBack, + BarcodeReader.BarcodeListener, + BarcodeReader.TriggerListener { + /* 振动 */ + public Vibrator vibrator; + /* 拍照用的属性 */ + public PhotographUi photographUi;// 当前拍照的组件 + public String pzImgPath;// 照相的图片路径 + /*----------------------*/ + public String phoneModel;// 电话类型 + public Map djInitMap = null; + public HashMap pageMap = new HashMap();// 页面参数 + public String mxTempTable;// 明细临时表 + public String mxSql;// 明细数据插入sql + private String mxQuerySql;// 明细查询sql + private String defaultFocus;// 初始化进入单据时的默认焦点 + private String defaultFocus2;// 初始化进入单据时的默认焦点 + private String nextFocusTag;// 下一个需要获得焦点组件Tag + private WakeLock wakeLock = null; + private WakeLock linghtScreen = null;// 点亮屏幕 + PowerManager pm = null; + private boolean isLinghtScreen = false; + private WifiLock wifiLock; + /* 菜单栏变量 */ + private AbsListView menuList; + private List menuData; + private BaseAdapter menuAdapter; + private String formlx; + private int currentDjId; + public ProgressDialog pd; + + public TabHost tabhost; + public TabHost hzTab; + public HashMap fangAMap = new HashMap();// 保存所有方案 + /* 明细内容 */ + private TextView mxTitle; + private ListView mxList; + public ArrayList mxData = new ArrayList(); + private MyAdapter mxAdapter; + private Button mxRefreshBut; + private int cur_pos = -1;// 当前选中的行 + + /* 语音播放变量 */ + private int MY_DATA_CHECK_CODE = 0; + private TextToSpeech tts; + private MediaPlayer diPlayer = null; + private MediaPlayer duPlayer = null; + // + public static View m_view = null; + + // 正在执行是否支持重复读取条形码 + private boolean reReadCode = true; + + /* 数据操作变量 */ + private DBManager dbManager; + private String ttsNr; + private OnCompletionListener completionListener = new OnCompletionListener() { + // @Override + public void onCompletion(MediaPlayer mp) { + if (ttsNr != null) { + if (tts != null) { + tts.speak(ttsNr, TextToSpeech.QUEUE_ADD, null); + } + ttsNr = null; + } + } + };// 声音提示停止接口 + // /* 单据内容查询 */ + // public Runnable downloadRun = new Runnable() { + // public void run() { + // Object ob; + // try { + // ob = getWeather(formlx); + // Message message = new Message(); + // message.obj = ob; + // handler.sendMessage(message); + // } catch (Exception e) { + // Message message = new Message(); + // message.obj = e.toString(); + // message.what = -1; + // handler.sendMessage(message); + // } + // } + // }; + /* 菜单栏查询 */ + Runnable menuRun = new Runnable() { + public void run() { + purview(); + } + }; + /* 显示网络图片Handler */ + public Handler imgHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == -1) { + DialogUtil.builder(DjActivity.this, "错误信息", "图片地址不正确", 0); + } else { + Map map = (Map) msg.obj; + ((SelfImage) map.get("image")).setBitmap((Bitmap) map.get("bitMap")); + } + } + + }; + /* 单据内容查询后更新页面 */ + private Handler handler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + super.handleMessage(msg); + System.out.println("=========sd=================================" + msg.what); + if (msg.what == -1) { + if (pd != null) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "初始化失败:" + msg.obj, 0); + } + } else { + Object initOb = msg.obj; + if (initOb instanceof Map) { + djInitMap = (Map) initOb; + createDj(1); + } else { + if (initOb.equals("0")) { + DialogUtil.builder(DjActivity.this, "提示信息", "PDA未注册!", 0); + } else if (initOb.equals("1")) { + DialogUtil.builder(DjActivity.this, "提示信息", "PDA还未授权使用!", 0); + } else if (initOb.equals("2")) { + DialogUtil.builder(DjActivity.this, "提示信息", "试用期已过!", 0); + } else if (initOb.equals("该模块未授权")) { + DialogUtil.builder(DjActivity.this, "提示信息", "该模块未授权!", 0); + } + pd.cancel(); + } + } + } + + }; + /* 菜单查询后更新页面 */ + private Handler menuHandler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == -1) { + DialogUtil.builder(DjActivity.this, "错误信息", "下载单据菜单失败!" + msg.obj, 0); + } else { + menuAdapter.notifyDataSetChanged(); + } + pd.cancel(); + } + + }; + private Handler sqlHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == -1) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "提取方案SQL失败!" + msg.obj, 0); + } else { + if (msg.arg1 == 0) { + try { + HashMap faMap = (HashMap) IoUtil.byte_obj((byte[]) msg.obj); + Map map = SqlUtil.regSql(faMap.get("sql").toString(), hzTab, pageMap); + pd.setMessage("正在执行检索方案"); + String audioFld = ""; + if (faMap.get("audioFld") != null) { + audioFld = faMap.get("audioFld").toString().toUpperCase(); + } + runSearch(map, faMap.get("return_one").toString(), audioFld); + } catch (Exception e) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "检索方案内容解析失败!", 0); + } + // String sql = msg.obj.toString(); + // String return_one = sql.substring(0, 1); + // sql = sql.substring(1, sql.length()); + // Map map = SqlUtil.regSql(sql, hzTab, pageMap); + // pd.setMessage("正在执行检索方案"); + // runSearch(map, return_one); + } else if (msg.arg1 == 1) { + String sql = null; + try { + sql = (String) IoUtil.byte_obj((byte[]) msg.obj); + } catch (Exception e) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "页面修改方案内容解析失败!", 0); + return; + } + Map map = SqlUtil.regSql(sql, hzTab, pageMap); + // if (mxData.size() > 0) { + // map.put("mxSql", mxSql); + // map.put("mxData", + // DjUtil.organizationMxData(mxData, + // pageMap.get("GZID"))); + // } else { + // map.put("mxSql", ""); + // map.put("mxData", null); + // } + map.put("gzid", pageMap.get("GZID")); + map.put("mxTempTable", mxTempTable); + Map hzData = DjUtil.organizationHzData(hzTab, pageMap.get("GZID")); + hzData.putAll(pageMap); + map.put("hzData", hzData); + try { + byte[] b = IoUtil.getbyte(map); + String paramString = Base64.encode(b); + pd.setMessage("正在执行页面修改方案"); + runYmup(paramString); + } catch (Exception e) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "页面修改方案组织数据失败!", 0); + } + } else if (msg.arg1 == 2) {// 页面提取方案 + Djselefa djselefa = null; + try { + djselefa = (Djselefa) IoUtil.byte_obj((byte[]) msg.obj); + } catch (Exception e) { + e.printStackTrace(); + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "提取方案内容解析失败!", 0); + return; + } + HashMap map = SqlUtil.regSql(djselefa.getT_sql(), hzTab, pageMap); + pd.cancel(); + Intent intent = new Intent(); + djselefa.setT_sql(map.get("sql").toString()); + HashMap paramMap = new HashMap(); + paramMap.put("djselefa", djselefa); + paramMap.put("t_sqlParam", (HashMap) map.get("param")); + paramMap.put("mxTempTable", mxTempTable); + paramMap.put("GZID", pageMap.get("GZID")); + intent.putExtra("paramMap", paramMap); + intent.setClass(getApplicationContext(), DjtqActivity.class); + startActivityForResult(intent, 2); + } + } + } + }; + public Handler runHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + View rootview = DjActivity.this.getWindow().getDecorView(); + View aaa = rootview.findFocus(); + // View bbb = + // hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + // if (aaa == bbb && defaultFocus2 != null) { + // DjUtil.setFocus(hzTab, defaultFocus2); + // } + if (aaa instanceof SelfEditText) { + m_view = aaa; + SelfEditText set = (SelfEditText)aaa; + if (set.getText().length() > 0) + set.selectAll(); + } + /* + if (defaultFocus2 != null) { + View bbb = hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + if (bbb instanceof SelfEditText) { + if (((SelfEditText)bbb).getText().length() > 0) + DjUtil.setFocus(hzTab, defaultFocus2); + } + }*/ + if (msg.what == -1) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "检索方案执行失败:" + msg.obj.toString(), 0); + } else if (msg.what == -2) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "页面修改方案执行失败:" + msg.obj.toString(), 0); + WifiManager wifiManager = (WifiManager) DjActivity.this.getSystemService(Context.WIFI_SERVICE); + wifiManager.disconnect(); + wifiManager.reconnect(); + } else if (msg.what == -3) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "单据保存失败:" + msg.obj.toString(), 0); + } else if (msg.what == -4) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "单据退出失败:" + msg.obj.toString(), 0); + } else if (msg.what == -5) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "查询明细失败:" + msg.obj.toString(), 0); + } else { + if (msg.obj == null) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "方案执行失败!", 0); + } else { + if (msg.arg1 == 1) {// 检索方案 + Map map = (Map) msg.obj; + DataGrid dg = (DataGrid) map.get("dg"); + int len = dg.getTableData().size(); + if (len < 1) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "提示信息", "当前查询没有记录!", 0); + return; + } + String speakFld = (map.get("audioFld")).toString(); + if (map.get("return_one").equals("Y") && len < 2) { + // System.out.println("检索方案"); + // if (len > 0) { + Map paramValueMap = (Map) dg.getTableData().get(0); + play(paramValueMap, speakFld); + DjUtil.setUiValue(hzTab, paramValueMap, pageMap, imgHandler); + // } + } else { + Intent intent = new Intent(); + intent.setClass(getApplicationContext(), ParamActivity.class); + intent.putExtra("dg", dg); + intent.putExtra("audioFld", speakFld); + startActivityForResult(intent, 1); + } + if (defaultFocus != null) { + DjUtil.setFocus(hzTab, defaultFocus); + defaultFocus = null; + } + pd.cancel(); + } else if (msg.arg1 == 2) {// 页面修改方案 + // byte[] bb = org.kobjects.base64.Base64.decode(msg.obj + // .toString()); + Object ob = msg.obj; + // try { + // ob = IoUtil.byte_obj(bb); + // } catch (Exception e) { + // DialogUtil.builder(DjActivity.this, "提示信息", + // "数据转换失败"); + // } + // if (ob instanceof Map) { + // Map map = (Map) ob; + // DjUtil.setUiValue(hzTab, (List) map.get("hz"), + // pageMap, imgHandler); + // // mxData.clear(); + // // mxData.addAll((List) map.get("mx")); + // // mxAdapter.notifyDataSetChanged(); + // // System.out.println(map.get("msg")); + // if (map.get("msg") != null) { + // DialogUtil.builder(DjActivity.this, "提示信息", map + // .get("msg").toString()); + // } + // } else { + // DialogUtil.builder(DjActivity.this, "提示信息", + // ob.toString()); + // } + if (ob instanceof Map) { + Map map = (Map) ob; + List> list = (List>) map.get("hz"); + Map paramValueMap = new HashMap(); + for (Map tm : list) { + if ("MESSAGE_A".equals(tm.get(" fieldname"))) { + paramValueMap = tm; + } else if ("MESSAGE_AUDIO".equals(tm.get("fieldname"))) + paramValueMap = tm; + } + // Map paramValueMap = (Map) + // dg.getTableData().get(0); + // String speakFld = + // (map.get("audioFld")).toString(); + play(paramValueMap, "fieldValue"); + DjUtil.setUiValue(hzTab, (List) map.get("hz"), pageMap, imgHandler); + + if (map.get("msg") != null) { + String ymup_msg = map.get("msg").toString(); + if (ymup_msg.toUpperCase().indexOf("JUMP_") == 0) { + String ymup_msgs[] = ymup_msg.split("_"); + String newOpenDjFromlx = ymup_msgs[1].toUpperCase(); + int dj_no = -1; + int len = menuData.size(); + for (int i = 0; i < len; i++) { + Map tempMap = (Map) menuData.get(i); + String tempgn_no = tempMap.get("gn_no").toString().toUpperCase(); + if (newOpenDjFromlx.equals(tempgn_no)) { + dj_no = i; + break; + } + } + if (dj_no == -1) { + DialogUtil.builder(DjActivity.this, "提示信息", "当前操作员不具有" + newOpenDjFromlx + "单据操作权限!", 0); + } else { + tabhost.setCurrentTab(0); + currentDjId = dj_no; + DialogUtil.builderCancel(DjActivity.this, "提示", "是否退出该单据", okClick); + } + } else { + String returnMsg[] = map.get("msg").toString().split("@"); + int fontsize = 0; + if (returnMsg.length > 1) { + fontsize = Integer.parseInt(returnMsg[1]); + } + DialogUtil.builder(DjActivity.this, "提示信息", returnMsg[0], fontsize); + } + } + } else { + DialogUtil.builder(DjActivity.this, "提示信息", ob.toString(), 0); + } + pd.cancel(); + } else if (msg.arg1 == 3) { + String mess = msg.obj.toString(); + if (mess.substring(0, 2).equals("ok")) { + String djbh = mess.substring(2, mess.length()); + // if(pageMap.containsKey("DJBH")){ + // djbh=pageMap.get("DJBH").toString(); + // }else{ + // View et=hzTab.findViewWithTag("DJBH"); + // if(et instanceof InputInterface){ + // djbh=((InputInterface)et).getText().toString(); + // } + // } + mxData.clear(); + mxAdapter.notifyDataSetChanged(); + hzTab.setCurrentTab(0); + hzTab.clearAllTabs(); + pageMap.clear(); + mxTempTable = null; + mxSql = null; + mxQuerySql = null; + createDj(0); + DialogUtil.builder(DjActivity.this, "提示信息", "单据保存成功\n单据编号:".concat(djbh), 0); + } else { + DialogUtil.builder(DjActivity.this, "提示信息", mess, 0); + } + pd.cancel(); + } else if (msg.arg1 == 4) { + if (tabhost.getCurrentTab() != 0) { + // hzTab.setCurrentTab(0); + hzTab.clearAllTabs(); + mxData.clear(); + fangAMap.clear(); + djInitMap.clear(); + djInitMap = null; + pageMap.clear(); + mxTempTable = null; + mxSql = null; + mxQuerySql = null; + formlx = null; + pd.cancel(); + tabhost.setCurrentTab(0); + } else { + pd.cancel(); + openNewDj(); + } + } else if (msg.arg1 == 5) { + mxData.clear(); + try { + byte[] bb = Base64.decode(msg.obj.toString()); + mxData.addAll((List) IoUtil.byte_obj(bb)); + } catch (Exception e) { + DialogUtil.builder(DjActivity.this, "提示信息", "数据转换失败", 0); + } + mxAdapter.notifyDataSetChanged(); + pd.cancel(); + } + } + + } + if (nextFocusTag != null) { + // System.out.println(nextFocusTag + // + "----------------------------"); + setNextFocus(nextFocusTag); + nextFocusTag = null; + } + if (isLinghtScreen) { + releaseLinghtScreen(); + } + // if (dc != null) { + // dc.start(); + // } + if (newScanControler != null) { + newScanControler.scanOnce();// 如果PDA是ht518 则一进入单据就打开扫描 + } + if (seuicScanner != null && islxscan.equals("0")) { + seuicScanner.startScan(); + } + + if (androidHandheldTerminal0 != null) { + androidHandheldTerminal0.start(); + } + if (cr5wScanControl != null) + cr5wScanControl.start(DjActivity.this); + if (androidHandheldTerminal != null) + androidHandheldTerminal.start(); + if (nr510ScanControl != null) + nr510ScanControl.start(DjActivity.this); + + if (barcodeReader != null) { + continuousScanning(true); + } + if (zkr322aControl != null) { + zkr322aControl.start(); + } + if (haixinN1SDemoReceiver != null) { + haixinN1sStart(); + } + reReadCode = true; + } + }; + /* + * mt35a 扫描所需变量 private DeviceControl DevCtrl; private SerialPort + * mSerialPort; public int fd; private ReadThread mReadThread; private + * static final String TAG = "SerialPort"; private boolean key_start = + * true;// 指明scan键的状态 private boolean Powered = false;// 指明扫头是否上电 private + * boolean Opened = false;// // 指明串口是否打开 private Timer timer = new Timer(); + * private Timer retrig_timer = new Timer(); private SoundPool soundPool; + * private int soundId; private Handler succeed_handler = null; private + * Handler t_handler = null; private Handler n_handler = null; private + * boolean ops = false;// 指明程序是否初始化** + */ + /* 事件 */ + public OnFocusChangeEvent focusEvent; + public OnClickEvent clickEvent; + public PzClickListener pzClickEvent;// 拍照事件 + public ImageClickListener imgClickEvent; + + private void createDj(int ty) { + if (ty == 1) {// 为0表示保存后新开单据 + fangAMap.clear(); + if (!SysData.is_lx) { + DjUtil.assembleFangA(fangAMap, (ArrayList) djInitMap.get("searchList")); + DjUtil.assembleFangA(fangAMap, (ArrayList) djInitMap.get("ymupList")); + DjUtil.assembleFangA(fangAMap, (ArrayList) djInitMap.get("djtqList")); + djInitMap.remove("searchList"); + djInitMap.remove("ymupList"); + djInitMap.remove("djtqList"); + } else { + fangAMap = (HashMap) djInitMap.get("fangAMap"); + djInitMap.remove("fangAMap"); + } + } + Sys_DanJuFormsOptions danju = (Sys_DanJuFormsOptions) djInitMap.get("danju"); + ByteArrayInputStream in = null; + try { + DanJuEntity dj = (DanJuEntity) IoUtil.byte_obj2(danju.getFORM()); + if (SysData.is_lx) {// 如果是离线单据就在PDA上生成临时表 + System.out.println(danju.getFORMbs() + "-----" + formlx); + String tableName = "CR_DJBS_".concat(danju.getFORMbs()).concat(formlx); + String createMxTableSql = "create table ".concat(tableName).concat("(gzid char(11),dj_sn int null default 0,"); + HashMap mxFiledMap = null; + for (int i = 0; i < dj.mxzdArray.size(); i++) { + mxFiledMap = (HashMap) dj.mxzdArray.get(i); + createMxTableSql = createMxTableSql.concat(mxFiledMap.get("fdname").toString()); + String fdtype = mxFiledMap.get("fdtype").toString(); + if (fdtype.equals("字符")) { + createMxTableSql = createMxTableSql.concat("varchar (").concat(mxFiledMap.get("fdsize").toString()).concat(") null default '',"); + } else if (fdtype.equals("整型") || fdtype.equals("整数")) { + createMxTableSql = createMxTableSql.concat(" int null default 0,"); + } else if (fdtype.equals("时间")) { + createMxTableSql = createMxTableSql.concat(" datetime null ,"); + } else if (fdtype.equals("位图") || fdtype.equals("二进")) { + createMxTableSql = createMxTableSql.concat(" blob null ,"); + } else if (fdtype.equals("文本")) { + createMxTableSql = createMxTableSql.concat(" text ,"); + } else if (fdtype.equals("实数")) { + createMxTableSql = createMxTableSql.concat(" decimal(").concat(mxFiledMap.get("fdsize").toString()).concat(",") + .concat(mxFiledMap.get("fddec").toString()).concat(") null default 0 ,"); + } + } + createMxTableSql = createMxTableSql.concat(" CONSTRAINT cr_").concat(danju.getFORMbs()).concat("_").concat(formlx) + .concat("_PK PRIMARY KEY (gzid,dj_sn))"); + System.out.println(dj.mxzdArray.size() + "------------sql:" + createMxTableSql); + if (dbManager.existsTable(tableName) > 0) { + dbManager.exeSql("drop table ".concat(tableName)); + } + dbManager.exeSql(createMxTableSql); + } + String[] arrs = dj.pageNr.split("\\^"); + if (arrs.length > 1) { + dj.pageNr = arrs[0]; + } + in = new ByteArrayInputStream(dj.pageNr.getBytes()); + pageMap.put("RQ", djInitMap.get("RQ").toString()); + Dom4jUtil.testParseXMLData(in, DjActivity.this); + if (dj.mxzdArray.size() > 0) { + mxTitle.setText(((Map) dj.mxzdArray.get(0)).get("chnname").toString().trim()); + // mxAdapter = new SimpleAdapter( + // DjActivity.this, + // mxData, + // R.layout.activity_menu, + // new String[] { ((Map) dj.mxzdArray.get(0)) + // .get("fdname").toString().trim().toUpperCase() }, + // new int[] { R.id.title }); + if (mxAdapter != null) { + mxAdapter.clear(); + } + mxAdapter = new MyAdapter(DjActivity.this, mxData, ((Map) dj.mxzdArray.get(0)).get("fdname").toString().trim().toUpperCase()); + mxList.setAdapter(mxAdapter); + } + mxTempTable = "CR_DJBS_".concat(danju.getFORMbs()).concat(formlx); + mxSql = DjUtil.createMxSql(dj.mxzdArray, mxTempTable); + mxQuerySql = DjUtil.createMxQuerySql(dj.mxzdArray, mxTempTable); + if (mxQuerySql == null) { + mxRefreshBut.setEnabled(false); + mxTempTable = null; + } else { + mxRefreshBut.setEnabled(true); + } + pageMap.put("GZID", djInitMap.get("GZID").toString().trim()); + pageMap.put("DJLX", formlx); + pageMap.put("DJBH", danju.getFORMbs().trim().concat("草")); + pageMap.put("DJBS", danju.getFORMbs().trim()); + pageMap.put("RQ", djInitMap.get("RQ").toString()); + pageMap.put("ONTIME", djInitMap.get("ONTIME").toString()); + pageMap.put("JIGID", SysData.jigid); + pageMap.put("ZHIYID", SysData.userid); + pageMap.put("USERID", SysData.userid); + pageMap.put("USERNAME", SysData.lgnname); + pageMap.put("CLIENTID", SysData.clientid); + DjUtil.setUiValue2(hzTab, pageMap, imgHandler); + String newDjInit = null; + if (dj.fangAtyjkVO != null) { + newDjInit = dj.fangAtyjkVO.newDjInit.trim(); + } + if (newDjInit != null && newDjInit.length() > 0) { + defaultFocus = danju.getDefaultFouseField(); + defaultFocus2 = defaultFocus; + eventHandler(newDjInit, null); + } else { + defaultFocus2 = danju.getDefaultFouseField(); + DjUtil.setFocus(hzTab, danju.getDefaultFouseField()); + } + pd.cancel(); + } catch (Exception e) { + e.printStackTrace(); + DialogUtil.builder(this, "错误信息", "生成单据页面失败!" + e.toString(), 0); + pd.cancel(); + } finally { + try { + if (in != null) { + in.close(); + in = null; + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + public DialogInterface.OnClickListener okClick = new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub + new DjMenuFun().exitDj(DjActivity.this); + } + }; + public DialogInterface.OnClickListener cancelClick = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub + + } + }; + + public void queryMx(View v) { + if (mxQuerySql == null) { + // DialogUtil.builder(DjActivity.this, "提示信息", "明细未设置", 0); + return; + } + DialogUtil.setDialog(pd, "正在查询单据内容", "正在查询明细……"); + new ExitThread(pageMap.get("GZID"), mxQuerySql, runHandler, "queryMx").start(); + } + + public void openNewDj() { + if (SysData.is_lx) { + if (dbManager.existsTable("sys_DanJuFormsOptions".toUpperCase()) < 1) { + DialogUtil.builder(DjActivity.this, "提示信息", "请下载单据表", 0); + return; + } + // if (dbManager.existsTable("sys_SearchOptions".toUpperCase()) < 1) + // { + // DialogUtil.builder(DjActivity.this, "提示信息", "请下载检索方案表"); + // return; + // } + // if (dbManager.existsTable("sys_YmupOptions".toUpperCase()) < 1) { + // DialogUtil.builder(DjActivity.this, "提示信息", "请下载页面修改方案表"); + // return; + // } + } + DialogUtil.setDialog(pd, "正在查询单据内容", "正在下载……"); + Map map = (Map) menuData.get(currentDjId); + formlx = map.get("gn_no").toString(); + mxData.clear(); + pageMap.clear(); + if (djInitMap != null) { + djInitMap.clear(); + djInitMap = null; + } + fangAMap.clear(); + mxTempTable = null; + mxSql = null; + tabhost.setCurrentTab(1); + // hzTab.setCurrentTab(0); + hzTab.clearAllTabs(); + if (SysData.is_lx) { + new Thread(new LxDJNrThread(dbManager, handler, formlx)).start(); + } else { + new Thread(new DownDJRun(formlx, handler)).start(); + } + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_dj); + // layout = new RelativeLayout(this); + // layout.setLayoutParams(new RelativeLayout.LayoutParams(-1, -1)); + // layout.setBackgroundColor(Color.WHITE); + // setContentView(layout); + if (SysData.url != null) { + this.setTitle(SysData.no + " " + SysData.url.substring(SysData.url.indexOf("//") + 2, 24)); + } + focusEvent = new OnFocusChangeEvent(); + clickEvent = new OnClickEvent(); + imgClickEvent = new ImageClickListener(this); + pzClickEvent = new PzClickListener(this); + /* 检测语音包资源 如果有合适的资源 就在onActivityResult中实例化一个TTS */ + Intent checkIntent = new Intent(); + checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); + startActivityForResult(checkIntent, MY_DATA_CHECK_CODE); + mxRefreshBut = (Button) findViewById(R.id.mxbut); + /*--------------*/ + pd = ProgressDialog.show(DjActivity.this, "正在查询单据菜单", "正在下载……"); + pd.setOnCancelListener(new OnCancelListener() { + + @Override + public void onCancel(DialogInterface dialog) { + if (m_view != null) { + if (m_view instanceof SelfEditText) { + ((SelfEditText)m_view).selectAll(); + } + m_view = null; + } + } + }); + menuData = new ArrayList(); + if (SysData.is_lx) { + dbManager = new DBManager(this); + new Thread(new LxMenuQueryThread(dbManager, menuHandler, menuData)).start(); + } else { + new Thread(menuRun).start();// 查询单据菜单 + } + tabhost = getTabHost(); + tabhost.addTab(tabhost.newTabSpec("djmenu").setIndicator("菜单").setContent(R.id.djmenu)); + // tabhost.addTab(tabhost.newTabSpec("hz").setIndicator("汇总") + // .setContent(R.id.hz)); + // mxActivity=new MxActivity(); + tabhost.addTab(tabhost.newTabSpec("hz").setIndicator("汇总").setContent(R.id.hz)); + tabhost.addTab(tabhost.newTabSpec("mx").setIndicator("明细").setContent(R.id.mx)); + TabWidget tabwidget = tabhost.getTabWidget(); + setTabwidgetAtt(tabwidget); + Intent intent = getIntent(); + String displaymode = intent.getStringExtra("displaymode"); + islxscan = intent.getStringExtra("islxscan"); + if (displaymode.equals("grid")) { + menuAdapter = new ImageAdpter(menuData, this); + menuList = new GridView(this); + GridView gv = (GridView) menuList; + gv.setNumColumns(3); + gv.setVerticalSpacing(20); + ((AdapterView) menuList).setAdapter(menuAdapter); + RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); + layoutParams.topMargin = 0; + layoutParams.leftMargin = 0; + ((LinearLayout) findViewById(R.id.djmenu)).addView(menuList, layoutParams); + } else { + menuAdapter = new SimpleAdapter(this, menuData, R.layout.activity_menu, new String[] { "mname" }, new int[] { R.id.title }); + // menuList = (ListView) findViewById(R.id.munuList); + menuList = new ListView(this); + RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); + layoutParams.topMargin = 0; + layoutParams.leftMargin = 0; + ((LinearLayout) findViewById(R.id.djmenu)).addView(menuList, layoutParams); + ((AdapterView) menuList).setAdapter(menuAdapter); + } + OnItemClickListener lis1 = new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { + if (formlx != null) { + currentDjId = arg2; + DialogUtil.builderCancel(DjActivity.this, "提示", "是否退出该单据", okClick); + } else { + currentDjId = arg2; + openNewDj(); + } + } + }; + menuList.setOnItemClickListener(lis1); + + hzTab = (TabHost) findViewById(R.id.hz); + hzTab.setup(); + mxTitle = (TextView) findViewById(R.id.mxtitle); + mxList = (ListView) findViewById(R.id.mxlist); + mxList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);// 一定要设置这个属性,否则ListView不会刷新 + mxList.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(AdapterView arg0, View arg1, int position, long id) { + cur_pos = position;// 更新当前行 + mxAdapter.cur_pos = cur_pos; + } + }); + + tabhost.getTabWidget().getChildAt(2).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + ((Button) findViewById(R.id.mxbut)).performClick(); + tabhost.setCurrentTab(2); + // tabhost.getTabWidget().setCurrentTab(2); + // DialogUtil.builder(DjActivity.this, "测试标题","测试内容!" + + // v.getLeft(), 18); + } + }); + + tabhost.getTabWidget().getChildAt(1).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + tabhost.setCurrentTab(1); + if (defaultFocus2 != null) { + DjUtil.setFocus(hzTab, defaultFocus2); + } + } + }); + + // mxAdapter = new SimpleAdapter(this, mxData, R.layout.activity_menu, + // new String[] { "mname" }, new int[] { R.id.title }); + phoneModel = android.os.Build.MODEL.toLowerCase(); + System.out.println(phoneModel + "--------------phoneModel---------------"); + if (phoneModel.equals("zk-r322a") || phoneModel.equals("zk-r322")|| phoneModel.equals("zk-r323")|| phoneModel.equals("zk-r323a")) { + zkr322aNew(); + }/* else if (phoneModel.equals("n1s")) { + haixinN1SInit(); + } */else if (phoneModel.equals("ht518")) { + // ht518Init(); + ht518InitNew(); + } else if (phoneModel.equals("al9") /*|| "cruise".equals(phoneModel)*/) { + seuicIint(); + } else if ("cr-5w".equals(phoneModel) /*|| "android handheld terminal".equals(phoneModel)*/) { + cr5wScanControl = new CR5WScanControl(); + cr5wScanControl.init(DjActivity.this); + } else if("android handheld terminal".equals(phoneModel)) { + androidHandheldTerminal0 = new AndroidHandheldTerminal0(DjActivity.this); + //androidHandheldTerminal = new AndroidHandheldTerminal(); + } else if ("nr510".equals(phoneModel) || "android".equals(phoneModel)) { + nr510ScanControl = new Nr510ScanControl(); + } else if ("scanpal eda50".equals(phoneModel)) { + // get bar code instance from MainActivity + // DialogUtil.builder(DjActivity.this, "信息", "初始化失败:111111111111111111", 0); + //if (barcodeReader != null) { + /// continuousScanning(true); + //} else { + barcodeReader = MainActivity.getBarcodeObject(); + + if (barcodeReader != null) { + + // register bar code event listener + barcodeReader.addBarcodeListener(this); + + // set the trigger mode to client control + try { + //barcodeReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE, + // BarcodeReader.TRIGGER_CONTROL_MODE_AUTO_CONTROL); + // set the trigger mode to client control + barcodeReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE, + BarcodeReader.TRIGGER_CONTROL_MODE_CLIENT_CONTROL); + + } catch (UnsupportedPropertyException e) { + Toast.makeText(this, "Failed to apply properties", Toast.LENGTH_SHORT).show(); + } + // register trigger state change listener + barcodeReader.addTriggerListener(this); + + Map properties = new HashMap(); + // Set Symbologies On/Off + properties.put(BarcodeReader.PROPERTY_CODE_128_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_GS1_128_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_QR_CODE_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_CODE_39_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_DATAMATRIX_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_UPC_A_ENABLE, true); + properties.put(BarcodeReader.PROPERTY_EAN_13_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_AZTEC_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_CODABAR_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_INTERLEAVED_25_ENABLED, true); + properties.put(BarcodeReader.PROPERTY_PDF_417_ENABLED, true); + // Set Max Code 39 barcode length + properties.put(BarcodeReader.PROPERTY_CODE_39_MAXIMUM_LENGTH, 10); + // Turn on center decoding + properties.put(BarcodeReader.PROPERTY_CENTER_DECODE, true); + // Enable bad read response + properties.put(BarcodeReader.PROPERTY_NOTIFICATION_BAD_READ_ENABLED, false); + properties.put(BarcodeReader.PROPERTY_EAN_13_CHECK_DIGIT_TRANSMIT_ENABLED, true); + // Apply the settings + barcodeReader.setProperties(properties); + } + try { + barcodeReader.claim(); + } catch (ScannerUnavailableException e) { + e.printStackTrace(); + Toast.makeText(this, "Scanner unavailable", Toast.LENGTH_SHORT).show(); + } + // } + } + acquireWakeLock(); + WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); + wifiLock = wifiManager.createWifiLock("crtechWIFI"); + wifiLock.acquire(); + System.out.println(wifiLock.isHeld() + "-----------------===-----------锁住"); + /**** + * mt35a初始化扫描变量 try { DevCtrl = new DeviceControl("/proc/driver/scan"); + * System.out.println("DevCtrl初始化扫描"); } catch (SecurityException e) { + * e.printStackTrace(); } catch (IOException e) { Log.d(TAG, "AAA"); new + * AlertDialog.Builder(this) .setTitle(R.string.DIA_ALERT) + * .setMessage(R.string.DEV_OPEN_ERR) + * .setPositiveButton(R.string.DIA_CHECK, new + * DialogInterface.OnClickListener() { + * + * @Override public void onClick(DialogInterface dialog, int which) { // + * TODO Auto-generated method stub finish(); } }).show(); + * return; } ops = true;// 指明程序是否初始化 + * + * soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); + * soundId = + * soundPool.load("/system/media/audio/ui/VideoRecord.ogg", + * 0); + * + * t_handler = new Handler() { + * @Override public void handleMessage(Message msg) { + * super.handleMessage(msg); if (msg.what == 1) { try { + * DevCtrl.PowerOffDevice(); } catch (IOException e) { + * Log.d(TAG, "BBB"); // TODO Auto-generated catch block + * e.printStackTrace(); }// powersave Powered = false; } } }; + * + * n_handler = new Handler() { + * @Override public void handleMessage(Message msg) { + * super.handleMessage(msg); if (msg.what == 1) { try { if + * (key_start == false) { DevCtrl.TriggerOffDevice(); timer = + * new Timer(); // 启动一个计时器,当机器闲置一段时间后,切断电源,节省能源。 + * timer.schedule(new MyTask(), 60000); key_start = true; } } + * catch (IOException e) { // TODO Auto-generated catch block + * e.printStackTrace(); } } } }; + * + * succeed_handler = new Handler() { + * @Override public void handleMessage(Message msg) { + * super.handleMessage(msg); if (msg.what == 1 && key_start == + * false) { String buff1 = msg.obj.toString(); // + * mReception.append(buff+"---"); View view = + * DjActivity.this.getCurrentFocus(); if (view != null && view + * instanceof EditText) { ((EditText) view).setText(buff1); + * view.clearFocus(); View nextView = layout + * .findViewWithTag(((SelfEditText) view).nextFocus); if + * (nextView != null) { nextView.requestFocus(); } } + * + * soundPool.play(soundId, 1, 1, 0, 0, 1); key_start = true; + * retrig_timer.cancel(); } } }; + ***/ + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + // if (resultCode == 1) { + // Map map = (Map) data.getSerializableExtra("param"); + // DjUtil.setUiValue(hzTab, map, pageMap, imgHandler); + // } + if (requestCode == MY_DATA_CHECK_CODE) { + if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { + // success, create the TTS instance + tts = new TextToSpeech(this, this); + } else { + Intent installIntent = new Intent(); + installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); + startActivity(installIntent); + } + } else if (requestCode == 1) { + if (resultCode == 1) { + Map map = (Map) data.getSerializableExtra("param"); + String speakFld = data.getSerializableExtra("audioFld").toString(); + if (tts != null) { + play(map, speakFld); + } + DjUtil.setUiValue(hzTab, map, pageMap, imgHandler); + } + } else if (requestCode == 2) { + if (resultCode == 2) { + DjUtil.setUiValue(hzTab, (HashMap) data.getSerializableExtra("param"), pageMap, imgHandler); + System.out.println(nextFocusTag + "-------------------------------------------------------------------"); + if (nextFocusTag != null) { + setNextFocus(nextFocusTag); + nextFocusTag = null; + } + } + } else if (requestCode == 3) { + if (resultCode == 3) { + HashMap tempmap = (HashMap) data.getSerializableExtra("param"); + // for (Object key : tempmap.keySet()) { + // System.out.println(tempmap.get(key) + "-------------------"); + // } + DjUtil.setUiValue(hzTab, tempmap, pageMap, imgHandler); + } + } else if (requestCode == 4) { + View view = null; + if (data != null) { + String uiId = data.getExtras().getString("uiId"); + view = hzTab.findViewWithTag(uiId.toUpperCase()); + if (view != null && view instanceof EditText) { + view.requestFocus(); + ((EditText) view).setText(data.getExtras().getString("tm")); + } + } + if (nextFocusTag != null) { + if (view != null) { + view.clearFocus(); + } + setNextFocus(nextFocusTag); + nextFocusTag = null; + } + } + if (requestCode == 8888) { + Bitmap bitmap = BitmapFactory.decodeFile(pzImgPath, null); + photographUi.setImageBitmap(bitmap); + } + } + + public void setTabwidgetAtt(TabWidget tabwidget) { + for (int i = 0; i < tabwidget.getChildCount(); i++) { + // 设置页签高度和页签内字体属性 + TextView tv = (TextView) tabwidget.getChildAt(i).findViewById(android.R.id.title); + tabwidget.getChildAt(i).getLayoutParams().height = UnitConversionUtil.convertDIP2PX(20.0); + // tv.setTextSize(20); + // float t = tv.getTextSize() * SysData.t_scale * 2 / 3; + // tv.setTextSize(t); + // System.out.println(tv.getTextSize()); + tv.setTextColor(Color.WHITE); + tv.setGravity(Gravity.CENTER_HORIZONTAL); + } + } + + public void purview() { + try { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + System.out.println(url); + String method = "selectAndroidPurview"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("userid", SysData.userid); + HttpTransportSE ht = new HttpTransportSE(url, SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (envelope.getResponse() != null) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + byte[] bb = Base64.decode(envelope.getResponse().toString()); + List list = (List) IoUtil.byte_obj(bb); + // for(int i=0;i 0) { Log.d(TAG, "opened"); Opened = true; } } if + * (mReadThread == null) { mReadThread = new ReadThread(); + * mReadThread.start(); System.out.println("线程创建并启动"); } else + * { if (!mReadThread.isAlive()) { mReadThread.start(); + * System.out.println("线程只启动"); } } } Log.d(TAG, "onResume"); + ****/ + super.onResume(); + System.out.println("onResume"); + if (cr5wScanControl != null) + cr5wScanControl.start(DjActivity.this); + else if (androidHandheldTerminal != null) + androidHandheldTerminal.start(); + else if (nr510ScanControl != null) + nr510ScanControl.start(DjActivity.this); + else if (androidHandheldTerminal0 != null) { + androidHandheldTerminal0.start(); + } else if (haixinN1SDemoReceiver != null) { + haixinN1sStart(); + } + if (seuicScanner != null) {// seuic PDA操作 + boolean b = seuicScanner.open(); + System.out.println(b + "----seuicScanner.open()"); + seuicScanner.setDecodeInfoCallBack(this); + // ScannerKey.open(); + // if (!seuicScannerThread.isrun) { + // System.out.println("------------------------onResume"); + // seuicScannerThread.isrun = true; + // new Thread(seuicScannerThread).start(); + // } + } + if (barcodeReader != null) { + continuousScanning(true); + } + if (zkr322aControl != null) { + zkr322aControl.start(); + } + reReadCode = true; + } + + @Override + protected void onStart() { + super.onStart(); + System.out.println("onStart"); + if (newScanControler != null) { + newScanControler.scanOnce(); + } + else if (seuicScanner != null) { + seuicScanner.setDecodeInfoCallBack(this); + seuicScanner.open(); + } + else if (cr5wScanControl != null) + cr5wScanControl.start(DjActivity.this); + else if (nr510ScanControl != null) + nr510ScanControl.start(DjActivity.this); + else if (androidHandheldTerminal != null) + androidHandheldTerminal.start(); + else if (barcodeReader != null) + continuousScanning(true); + else if (haixinN1SDemoReceiver != null) { + haixinN1sStart(); + } +// else if(androidHandheldTerminal0 != null) +// androidHandheldTerminal0.start(); + if (zkr322aControl != null) { + zkr322aControl.start(); + } + reReadCode = true; + } + + @Override + protected void onPause() { + // TODO Auto-generated method stub + super.onPause(); + if (newScanControler != null) { + newScanControler.stopScan(); + } + else if (cr5wScanControl != null) + cr5wScanControl.stop(DjActivity.this); + else if (nr510ScanControl != null) + nr510ScanControl.stop(DjActivity.this); + else if (androidHandheldTerminal != null) + androidHandheldTerminal.stop(); + else if (androidHandheldTerminal0 != null) { + androidHandheldTerminal0.stop(); + } else if (haixinN1SDemoReceiver != null) { + haixinN1sStop(); + } + System.out.println("onPause"); + if (seuicScanner != null) {// seuic PDA操作 + System.out.println("seuicScanner.close"); + seuicScanner.stopScan(); + seuicScanner.close(); + seuicScanner.setDecodeCallBack(null); + // ScannerKey.close(); + // if (seuicScannerThread.isrun) { + // seuicScannerThread.isrun = false; + // } + } + if (barcodeReader != null) { + // release the scanner claim so we don't get any scanner + // notifications while paused. +// barcodeReader.release(); + continuousScanning(false); + } + if (zkr322aControl != null) { + zkr322aControl.stop(); + } + } + + @Override + protected void onStop() { + // TODO Auto-generated method stub + super.onStop(); + } + + public void onDestroy() { + // if (seuicScanner != null) {// seuic PDA操作 + // ScannerKey.close(); + // com.seuic.scanner.Scanner.stopScanService(this); + // } + // TODO Auto-generated method stub + /** + * mt35a 调用 System.out.println("杀死---------------------------------"); + * if (ops == true) { try { + * System.out.println("杀死123---------------------------------"); + * mReadThread.interrupt(); soundPool.release(); DevCtrl.DeviceClose(); + * } catch (IOException e) { Log.d(TAG, "EEE"); // TODO Auto-generated + * catch block e.printStackTrace(); } } + ****/ + super.onDestroy(); + + + if (barcodeReader != null) { + barcodeReader.release(); + // unregister barcode event listener + barcodeReader.removeBarcodeListener(this); + + // unregister trigger state change listener + barcodeReader.removeTriggerListener(this); + barcodeReader = null; + // triggerState = true; + } + + if (diPlayer != null) { + diPlayer.stop(); + diPlayer.release(); + diPlayer = null; + } + if (duPlayer != null) { + duPlayer.stop(); + duPlayer.release(); + duPlayer = null; + } + if (vibrator != null) { + vibrator.cancel(); + } +// if (seuicScanner != null) { +// seuicScanner.stopScan(); +// seuicScanner.close(); +// seuicScanner.setDecodeCallBack(null); +// } + completionListener = null; + // if (washeld) { + // washeld = false; + + + } + + private void exitClear() { + System.out.println("---退出清理---"); + if (dbManager != null) { + dbManager.closeDB(); + dbManager = null; + } + if (djInitMap != null) { + djInitMap.clear(); + djInitMap = null; + } + fangAMap.clear(); + fangAMap = null; + pageMap.clear(); + pageMap = null; + if (menuList != null) { + menuList = null; + } + if (menuAdapter != null) { + menuAdapter = null; + } + if (menuData != null) { + menuData.clear(); + menuData = null; + } + if (menuAdapter != null) { + menuAdapter = null; + } + if (mxList != null) { + mxList = null; + } + System.out.println(phoneModel + "---------------------------------phoneModel1"); + mxData.clear(); + mxData = null; + if (mxAdapter != null) { + mxAdapter.clear(); + mxAdapter = null; + } + releaseWakeLock(); + linghtScreen = null; + wifiLock.release(); + wifiLock = null; + if (pm != null) { + pm = null; + } + if (tts != null) { + tts.shutdown(); + } + if (phoneModel.equals("ht518")) { + ht518Clear(); + // DiemensionalCodeControler.setDiemensionalConNull();//ht518旧扫描头清除 + } + if (zkr322aControl != null) { + zkr322aClear(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_dj, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + super.onOptionsItemSelected(item); + switch (item.getItemId())// 得到被点击的item的itemId + { + case R.id.updatePwd: // 对应的ID就是在add方法中所设定的Id + Intent intent = new Intent(); + intent.setClass(getApplicationContext(), UpdatePwdActivity.class); + startActivity(intent); + break; + default: + break; + } + return true; + } + + /* + * mt35a 调用 public boolean onKeyDown(int keyCode, KeyEvent event) { + * System.out.println(keyCode + "==================="); switch (keyCode) { + * case 111: try { if (key_start == true) { if (Powered == false) { Powered + * = true; DevCtrl.PowerOnDevice(); } timer.cancel(); + * DevCtrl.TriggerOnDevice(); key_start = false; retrig_timer = new Timer(); + * retrig_timer.schedule(new RetrigTask(), 3500); } } catch (IOException e) + * { Log.d(TAG, "FFF"); // TODO Auto-generated catch block + * e.printStackTrace(); } break; case 4: dialog(); break; } + * + * return super.onKeyDown(keyCode, event); } + */ + @Override + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (!isKeyDown) { + isKeyDown = true; + } + return super.onKeyUp(keyCode, event); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + super.onKeyDown(keyCode, event); + String temp = String.valueOf(keyCode); + System.err.println(temp + "---------------------1" + seuicScanner + "--" + isKeyDown); + if (temp.equals("132")) {// ht518专用 + event.startTracking();// 加了这句 键盘长按事件才有效 + return true; + } + if (seuicScanner != null && temp.equals("0") && isKeyDown) { + seuicScanner.startScan(); + isKeyDown = false; + return true; + } + return super.onKeyDown(keyCode, event); + } + + private boolean isCurrentFocus_EditText() {// 判断当前焦点组件是否是输入框 + View view = DjActivity.this.getCurrentFocus(); + if (view != null && view instanceof EditText) { + return true; + } else { + return false; + } + } + + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + // System.out.println(event.getKeyCode() + "---------------------"); + int keyCode = event.getKeyCode(); + // DialogUtil.builder(DjActivity.this, "提示信息", "keyCode = " + keyCode, 0); + // if (event.getAction() != KeyEvent.ACTION_UP) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + switch (keyCode) { + case 120: + break; + case 211: + break; + case 212: + break; + case 113: + View view = DjActivity.this.getCurrentFocus(); + if (view != null && view instanceof EditText) { + setFcous(view); + } + break; + case KeyEvent.KEYCODE_BACK: + dialog(); + break; + case KeyEvent.KEYCODE_ENTER: + View view1 = DjActivity.this.getCurrentFocus(); + if (view1 != null && view1 instanceof EditText) { + setFcous(view1); + } + break; + case 132: + // if (!isOpen) { + // isOpen = true; + // dc.start(); + // } + if (newScanControler != null) { + newScanControler.scanOnce(); + } + break; + case 510: + if (nr510ScanControl != null) { + nr510ScanControl.start(DjActivity.this); + } + break; + default: + return super.dispatchKeyEvent(event); + } + // return true; + } else if (event.getAction() == KeyEvent.ACTION_UP) { + if (keyCode == 120 || keyCode == 211 || keyCode == 212) { + } else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { // 阻止系统的enter事件 + return true; + } + // else if (keyCode == 132) { + // if (isOpen) { + // isOpen = false; + // } + // } + } + return super.dispatchKeyEvent(event); + } + + // @Override + // public boolean onKeyUp(int keyCode, KeyEvent event) { + // super.onKeyUp(keyCode, event); + // if(keyCode==132&&isOpen){ + // isOpen = false; + // } + // return true; + // } + + public boolean onKeyLongPress(int keyCode, KeyEvent event) { + super.onKeyLongPress(keyCode, event); + String temp = String.valueOf(keyCode); + if (temp.equals("132")) { + // dc.stop(); + // dc.doHandsFree(); + } + return true; + } + + // public boolean onKeyDown(int keyCode, KeyEvent event) { + // System.out.println(keyCode + "--------------------------------"); + // switch (keyCode) { + // case 120: + // if (SysUtil.isTopApp(this)) { + // if (mScanManager.getTriggerLockState()) { + // mScanManager.unlockTriggler(); + // } + // } else { + // if (!mScanManager.getTriggerLockState()) { + // mScanManager.lockTriggler(); + // } + // } + // break; + // case 4: + // dialog(); + // break; + // case 113: + // View view = DjActivity.this.getCurrentFocus(); + // if (view != null && view instanceof EditText) { + // setFcous(view); + // } + // break; + // } + // return super.onKeyDown(keyCode, event); + // } + + protected void dialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(DjActivity.this); + builder.setMessage("确定要退出吗?"); + builder.setTitle("提示"); + builder.setPositiveButton("确认", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (pageMap.containsKey("GZID")) { + new ExitThread(pageMap.get("GZID"), mxTempTable, null, "clearDj").start(); + } + dialog.cancel(); + DjActivity.this.finish(); + exitClear(); + } + }); + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + builder.create().show(); + } + + /* + * 扫描所需要的内容 class MyTask extends TimerTask { + * + * @Override public void run() { // TODO Auto-generated method stub Message + * message = new Message(); message.what = 1; + * t_handler.sendMessage(message); } } + */ + /* + * class RetrigTask extends TimerTask { + * + * @Override public void run() { // TODO Auto-generated method stub Message + * message = new Message(); message.what = 1; + * n_handler.sendMessage(message); } } + * + * private class ReadThread extends Thread { + * + * @Override public void run() { super.run(); while + * (!Thread.currentThread().isInterrupted()) { try { Log.d(TAG, "read"); + * String buff = mSerialPort.ReadSerial(fd, 1024); Log.d(TAG, "end"); if + * (buff != null) { Message msg = new Message(); msg.what = 1; msg.obj = + * buff; succeed_handler.sendMessage(msg); timer = new Timer(); + * timer.schedule(new MyTask(), 60000); } else { Message msg = new + * Message(); msg.what = 0; succeed_handler.sendMessage(msg); } } catch + * (SecurityException e) { e.printStackTrace(); } catch + * (UnsupportedEncodingException e) { // TODO Auto-generated catch block + * e.printStackTrace(); } } } } + */ + class OnFocusChangeEvent implements View.OnFocusChangeListener { + @Override + public void onFocusChange(View v, boolean hasFocus) { + // System.out.println(v.toString()); + if (hasFocus) { + if (v instanceof SelfEditText) { + SelfEditText focusInSet = (SelfEditText) v; + // focusInSet.setInputType(InputType.TYPE_NULL); + // System.out.println(focusInSet.getTag()+"的到焦点------------"); + if (focusInSet.closeKeyBoard) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(focusInSet.getWindowToken(), 0); + } + if (focusInSet.isTextChange) { + focusInSet.isTextChange = false; + } + focusInSet.selectAll(); + eventHandler(focusInSet.focusInFun, v); + } + } else { + if (v instanceof SelfEditText) { + SelfEditText set = (SelfEditText) v; + // System.out.println(set.getTag()+"失去焦点------------" + + // set.isTextChange); + if (set.isTextChange) { + nextFocusTag = set.nextFocus; + eventHandler(((SelfEditText) v).focusOutFun, v); + } + } + } + } + } + + class OnClickEvent implements OnClickListener { + + @Override + public void onClick(View v) { + View view = DjActivity.this.getCurrentFocus(); + if (view instanceof SelfEditText) { + if (((SelfEditText) view).isTextChange) { + DjActivity.this.hzTab.requestFocus(); + return; + } + } + SelfButton selfBut = (SelfButton) v; + nextFocusTag = selfBut.nextFocus; + eventHandler(selfBut.clickFun, null); + } + + } + + public void openRunWin() { + DialogUtil.builder(DjActivity.this, "提示信息", "PDA不兼容", 0); + } + + public void eventHandler(String funName, View view) { + if (!SysData.isreg.equals("Y")) { + openRunWin(); + } + if (funName == null) { + return; + } + funName = funName.trim(); + if (funName.length() < 1) { + return; + } + String funType = ""; + String functionname = null; + if (funName.indexOf("_") > -1) { + funType = funName.substring(0, funName.indexOf("_")).toUpperCase(); + // functionname = funName.substring(funName.indexOf("_") + 1, + // funName.length()); + } + HashMap faMap = (HashMap) fangAMap.get(funName.toUpperCase()); + if (faMap == null && (funType.equals("SEARCH") || funType.equals("YMUP") || funType.equals("DJTQ"))) { + DialogUtil.builder(DjActivity.this, "错误信息", "方案不存在!", 0); + return; + } + if (funType.equals("SEARCH")) {// 检索方案函数 + if (cr5wScanControl != null) + cr5wScanControl.stop(DjActivity.this); + else if (androidHandheldTerminal != null) + androidHandheldTerminal.stop(); + else if (nr510ScanControl != null) + nr510ScanControl.stop(DjActivity.this); + else if (haixinN1SDemoReceiver != null) { + haixinN1sStop(); + } + // else if (androidHandheldTerminal0 != null) + // androidHandheldTerminal0.stop(); + if (barcodeReader != null) { + // continuousScanning(false); + } + if (zkr322aControl != null) { + zkr322aControl.stop(); + } + DialogUtil.setDialog(pd, "检索方案", "正在执行检索方案……"); + // new SearchThread(formlx, functionname, sqlHandler, 0).start(); + Map map = SqlUtil.regSql(faMap.get("zdysql").toString(), hzTab, pageMap); + String audioFld = ""; + if (faMap.get("audioFld") != null) { + audioFld = faMap.get("audioFld").toString().toUpperCase(); + } + runSearch(map, faMap.get("return_one").toString(), audioFld); + } else if (funType.equals("YMUP")) {// 页面修改函数 + if (cr5wScanControl != null) + cr5wScanControl.stop(DjActivity.this); + else if (nr510ScanControl != null) + nr510ScanControl.stop(DjActivity.this); + else if (androidHandheldTerminal != null) + androidHandheldTerminal.stop(); + else if (haixinN1SDemoReceiver != null) { + haixinN1sStop(); + } + // else if (androidHandheldTerminal0 != null) + // androidHandheldTerminal0.stop(); + if (barcodeReader != null) { + // continuousScanning(false); + } + if (zkr322aControl != null) { + zkr322aControl.stop(); + } + DialogUtil.setDialog(pd, "页面修改方案", "正在执行页面修改方案"); + // new SearchThread(formlx, functionname, sqlHandler, 1).start(); + Map map = SqlUtil.regSql(faMap.get("zdysql").toString(), hzTab, pageMap); + System.out.println(pageMap.get("GZID") + "------------------gzid"); + map.put("gzid", pageMap.get("GZID")); + map.put("mxTempTable", mxTempTable); + Map hzData = DjUtil.organizationHzData(hzTab, pageMap.get("GZID")); + ((HashMap) hzData.get("hzData")).putAll(pageMap); + map.put("hzData", hzData); + try { + if (!SysData.is_lx) { + byte[] b = IoUtil.getbyte(map); + String paramString = Base64.encode(b); + runYmup(paramString); + } else { + new Thread(new LxRunYmupThread(dbManager, faMap.get("zdysql").toString(), (Map) hzData.get("hzData"), runHandler)).start(); + } + } catch (Exception e) { + pd.cancel(); + DialogUtil.builder(DjActivity.this, "错误信息", "页面修改方案组织数据失败!", 0); + } + } else if (funType.equals("DJTQ")) { + DialogUtil.setDialog(pd, "提取方案", "加载提取方案函数……"); + // new SearchThread(formlx, functionname, sqlHandler, 2).start(); + Djselefa djselefa = new Djselefa(); + djselefa.setT_sql(faMap.get("t_sql").toString()); + djselefa.setHz_sql(faMap.get("hz_sql").toString()); + djselefa.setMx_sql(faMap.get("mx_sql").toString()); + djselefa.setFangamch(faMap.get("fangamch").toString()); + HashMap map = SqlUtil.regSql(djselefa.getT_sql(), hzTab, pageMap); + pd.cancel(); + Intent intent = new Intent(); + djselefa.setT_sql(map.get("sql").toString()); + HashMap paramMap = new HashMap(); + paramMap.put("djselefa", djselefa); + paramMap.put("t_sqlParam", (HashMap) map.get("param")); + paramMap.put("mxTempTable", mxTempTable); + paramMap.put("GZID", pageMap.get("GZID")); + intent.putExtra("paramMap", paramMap); + intent.setClass(getApplicationContext(), DjtqActivity.class); + startActivityForResult(intent, 2); + } else { + DjMenuFun menufun = new DjMenuFun(); + Class cla = menufun.getClass(); + Method method = null; + try { + if (funName.substring(0, 1).equals("M")) { + method = cla.getDeclaredMethod(funName, DjActivity.class); + method.invoke(menufun, DjActivity.this); + } else if (funName.substring(0, 4).toUpperCase().equals("SCAN")) { + method = cla.getDeclaredMethod(funName.substring(0, 4), DjActivity.class, String.class); + method.invoke(menufun, DjActivity.this, funName); + } else { + method = cla.getDeclaredMethod(funName); + if (method != null && view instanceof EditText) { + ((EditText) view).setText(method.invoke(menufun).toString()); + } + } + } catch (Exception e) { + DialogUtil.builder(DjActivity.this, "系统错误", "生成函数失败", 0); + e.printStackTrace(); + } + } + } + + /* 运行检索方案 */ + public void runSearch(Map map, String return_one, String audioFld) { + // new SearchThread(formlx, "WMSW87_01", sqlHandler).start(); + try { + new RunSearchThread(map.get("sql").toString(), IoUtil.ob_base64(map.get("param")), runHandler, return_one, audioFld).start(); + } catch (IOException e) { + // TODO Auto-generated catch block + DialogUtil.builder(this, "错误信息", "转换成Base64编码失败!", 0); + // e.printStackTrace(); + } + } + + /* 运行页面修改过方案 */ + public void runYmup(String param) { + new RunYmupThread(param, runHandler, "runYmup", 0).start(); + } + + @Override + public void onInit(int status) { + if (status == TextToSpeech.SUCCESS) { + tts.setLanguage(Locale.CHINA); + } + + else if (status == TextToSpeech.ERROR) { + Toast.makeText(DjActivity.this, "始化文本到语音引擎时发生错误", Toast.LENGTH_LONG).show(); + } + } + + public void play(Map map, String speakFld) { + if (map.containsKey(speakFld)) { + String speakNr = map.get(speakFld).toString(); + int isZd = 0; + if (speakNr.indexOf("退药") > -1 || speakNr.indexOf("批次错误") > -1) { + if (diPlayer == null) { + diPlayer = MediaPlayer.create(this, R.raw.didi); + diPlayer.setOnCompletionListener(completionListener); + } + ttsNr = map.get(speakFld).toString(); + diPlayer.start(); + } else if (speakNr.indexOf("错误") > -1) { + if (duPlayer == null) { + duPlayer = MediaPlayer.create(this, R.raw.dudu); + duPlayer.setOnCompletionListener(completionListener); + } + ttsNr = map.get(speakFld).toString(); + duPlayer.start(); + } else { + isZd = 1; + if (tts != null) { + tts.speak(map.get(speakFld).toString(), TextToSpeech.QUEUE_ADD, null); + } + } + if (isZd == 0) { + if (vibrator == null) { + vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + } + vibrator.vibrate(2000); + } + // tts.speak(map.get(speakFld).toString(), TextToSpeech.QUEUE_ADD, + // null); + } + + } + + private void setFcous(View view) { + ((EditText) view).clearFocus(); + setNextFocus(((SelfEditText) view).nextFocus); + } + + private void setNextFocus(String focusName) { + View nextView = hzTab.findViewWithTag(focusName); + if (nextView != null) { + nextView.requestFocus(); + } + } + + private void zyFcous(String tiaoma) { + if (!reReadCode) { + return; + } + View view = DjActivity.this.getCurrentFocus(); + if (view != null && view instanceof EditText) { + reReadCode = false; + ((EditText) view).setText(tiaoma); + setFcous(view); + } + } + + public void acquireWakeLock() { + if (pm == null) { + pm = (PowerManager) getSystemService(Context.POWER_SERVICE); + } + if (wakeLock == null) { + wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "crtech"); + } + if (linghtScreen == null) { + linghtScreen = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); + } + if (wakeLock != null) { + System.out.println(wakeLock + "------------------锁定"); + wakeLock.acquire(); + } + } + + // 释放设备电源锁 + public void releaseWakeLock() { + if (wakeLock != null) { + wakeLock.release(); + System.out.println("------------------解除锁定"); + wakeLock = null; + } + } + + public void releaseLinghtScreen() { + if (isLinghtScreen) { + isLinghtScreen = false; + linghtScreen.release(); + } + } + + /* ht518 扫描 */ + // DiemensionalCodeControler dc; + // DiemensionalScanListener scanListener; + // private boolean isOpen = false;// 判断扫描是否开始 + // + // /* ht518初始化(带旧版扫描头) */ + // private void ht518Init() { + // DiemensionalCodeControler.setDiemensionalConNull(); + // scanListener = new ScanListener(); + // dc = DiemensionalCodeControler.getCodeControler(this, scanListener); + // } + // public class ScanListener implements DiemensionalScanListener { + // + // @Override + // public void onDiemensionalScanComplete(String result, String error) { + // KeyguardManager km = (KeyguardManager) + // getSystemService(Context.KEYGUARD_SERVICE); + // if (km.inKeyguardRestrictedInputMode()) { + // System.out.println("解锁屏幕------------"); + // // 得到键盘锁管理器对象 + // KeyguardLock kl = km.newKeyguardLock("unLock"); + // // 参数是LogCat里用的Tag + // kl.disableKeyguard(); // 解锁 + // } + // // System.out.println(wakeLock+"------------"+washeld); + // // if (washeld) { + // // washeld = false; + // // wakeLock.release(); + // // System.out.println(wakeLock); + // // } + // // System.out.println(wakeLock + "------------"); + // // wakeLock.acquire(); + // // washeld = true; + // + // // 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag + // if (!pm.isScreenOn()) { + // linghtScreen.acquire();// 点亮屏幕 + // isLinghtScreen = true; + // System.out.println(wakeLock + "------------"); + // } + // if (result != null) { + // zyFcous(result); + // } else { + // if (error.equals("解码超时")) { + // dc.start(); + // } else { + // tts.speak(error, TextToSpeech.QUEUE_ADD, null); + // } + // } + // } + // } + + // 富力叶 android handheld terminal 扫描头 + AndroidHandheldTerminal0 androidHandheldTerminal0 = null; + public class AndroidHandheldTerminal0 { + public boolean running = true; + public AndroidHandheldTerminal0(final Context context) { + ScanHelper.setScanSwitchLeft(context, true); + ScanHelper.setScanSwitchRight(context, true); + ScanHelper.setBarcodeReceiveModel(context, 2); + m_Broadcastname = "com.barcode.sendBroadcast"; + final IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(m_Broadcastname); + registerReceiver(myCodeReceiver, intentFilter); + } + + + public void start() { + running = true; + } + + public void stop() { + //ScanHelper.setScanSwitchLeft(context, false); + //ScanHelper.setScanSwitchRight(context, false); +// ScanHelper.setBarcodeReceiveModel(context, 2); +// if (!state) { +// synchronized (lock) { +// if (!state) { +// state = true; +// unregisterReceiver(myCodeReceiver); +// } +// } +// } + running = false; + } + } + + private String m_Broadcastname = null; + private MyCodeReceiver myCodeReceiver = new MyCodeReceiver(); + public class MyCodeReceiver extends BroadcastReceiver + { + private static final String TAG = "MycodeReceiver"; + @Override + public void onReceive(Context context, Intent intent) { + if(androidHandheldTerminal0.running && intent.getAction().equals(m_Broadcastname)) { + String str = intent.getStringExtra("BARCODE"); + if (!"".equals(str)) { + View rootview = DjActivity.this.getWindow().getDecorView(); + View aaa = rootview.findFocus(); + // View bbb = + // hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + // if (aaa == bbb && defaultFocus2 != null) { + // DjUtil.setFocus(hzTab, defaultFocus2); + // } + if (aaa instanceof SelfEditText) { + SelfEditText set = (SelfEditText)aaa; + set.setText(str); + //if (set.closeKeyBoard) { +// set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); +// set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)); + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + Instrumentation inst = new Instrumentation(); + inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER); + } + }).start(); + //} + } + } + } + } + } + // 海信 n1s 设备扫描头控制 + public static final String HAIXIN_N1S_ACTION_SCAN_RESULT = "android.provider.sdlMessage"; + public static boolean haixinN1SStart = false; + + private static IntentFilter haixinN1SMakeDemoIntentFilter() { + final IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(HAIXIN_N1S_ACTION_SCAN_RESULT); + return intentFilter; + } + + private BroadcastReceiver haixinN1SDemoReceiver = null; + + public void haixinN1SInit() { + haixinN1SDemoReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + // + final String action = intent.getAction(); + if (HAIXIN_N1S_ACTION_SCAN_RESULT.equals(action)) { + // The string is the scan result value. + final String scanResultStr = intent.getStringExtra("msg"); + + if (scanResultStr != null && scanResultStr.trim().length() > 0) { + handler.post(new Runnable() { + public void run() { + View rootview = DjActivity.this.getWindow().getDecorView(); + View aaa = rootview.findFocus(); + // View bbb = + // hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + // if (aaa == bbb && defaultFocus2 != null) { + // DjUtil.setFocus(hzTab, defaultFocus2); + // } + if (aaa instanceof SelfEditText) { + SelfEditText set = (SelfEditText)aaa; + set.setText(scanResultStr); + // + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + Instrumentation inst = new Instrumentation(); + inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER); + } + }).start(); + } + } + }); + } + } + // + } + }; + } + + public void haixinN1sStart() { + if (!haixinN1SStart) { + haixinN1SStart = true; + registerReceiver(haixinN1SDemoReceiver, haixinN1SMakeDemoIntentFilter()); + } + } + + public void haixinN1sStop() { + if (haixinN1SStart) { + haixinN1SStart = false; + unregisterReceiver(haixinN1SDemoReceiver); + } + } + + + // 富力叶 android handheld terminal 扫描头 + + public static AndroidHandheldTerminal androidHandheldTerminal = null; + /* 富力叶不兼容代码 + private Handler androidHandheldTerminalHandler = new MainHandler(); + + + private class MainHandler extends Handler { + @SuppressLint("HandlerLeak") + @Override + public void handleMessage(Message msg) { + if (msg.what == 1) { + + String readerdata = (String) msg.obj; + // + View rootview = DjActivity.this.getWindow().getDecorView(); + View aaa = rootview.findFocus(); + // View bbb = + // hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + // if (aaa == bbb && defaultFocus2 != null) { + // DjUtil.setFocus(hzTab, defaultFocus2); + // } + if (aaa instanceof SelfEditText) { + SelfEditText set = (SelfEditText)aaa; + set.setText(readerdata); + //set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); + //set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)); + } + // + + } + + } +} + + private IScanCallBack androidHandheldTerminalcb = new IScanCallBack.Stub() { + + @Override + public void doScanResult(String barCode) throws RemoteException { + + Message msg = new Message(); + msg.what = 1; + msg.obj = barCode; + androidHandheldTerminalHandler.sendMessage(msg); + + } +};*/ + public class AndroidHandheldTerminal { + /* 富力叶不兼容代码 + private ScanManager scan = null; + + public AndroidHandheldTerminal() { + scan = (ScanManager) getSystemService("olc_service_scan"); + } +*/ + public void start() {/* 富力叶不兼容代码 + if (scan != null) { + Log.v("AndroidHandheldTerminal", "scan: start begin"); + scan.setScanSwitchLeft(true); + scan.setScanSwitchRight(true); + + scan.startRead(androidHandheldTerminalcb); + Log.v("AndroidHandheldTerminal", "scan: start end"); + } else + Log.v("AndroidHandheldTerminal", "scan: start fail");*/ + } + + public void stop() {/* 富力叶不兼容代码 + if (scan != null) { + Log.v("AndroidHandheldTerminal", "scan: stop begin"); + scan.setScanSwitchLeft(false); + scan.setScanSwitchRight(false); + Log.v("AndroidHandheldTerminal", "scan: stop end"); + } else + Log.v("AndroidHandheldTerminal", "scan: stop fail");*/ + } + + public void restart() { + stop(); + start(); + } + } + + /** + * zkr322a 大屏 工业一体机 + */ + private boolean zkr322aIsReciverThread = true; + private Thread zkr322aReciverThread = null; + private ZKR322AControl zkr322aControl = null; + private Handler zkr322aHandler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + zyFcous(msg.obj.toString()); + } + }; + + private void zkr322aNew() { + try { + zkr322aControl = new ZKR322AControl(); + zkr322aControl.initScan(); + zkr322aReciverThread = new Thread(zkr322aReciverDataRunable); + zkr322aReciverThread.start(); + } catch (Exception e) { + DialogUtil.builder(DjActivity.this, "错误信息", "[ZKR322A]初始化失败:" + e.getMessage(), 0); + } + } + + public void zkr322aClear() { + zkr322aIsReciverThread = false; + zkr322aReciverThread = null; + zkr322aControl.stop(); + zkr322aControl.close(); + zkr322aControl = null; + zkr322aHandler = null; + } + + Runnable zkr322aReciverDataRunable = new Runnable() { + @Override + public void run() { + while (zkr322aIsReciverThread && zkr322aControl != null) { + String msg = zkr322aControl.getData(); + if (msg != null && msg.length() > 0) { + Message message = new Message(); + message.obj = msg; + zkr322aHandler.sendMessage(message); + } + } + + } + }; + /** + * cr5w 设备扫描头控制 + * */ + public static CR5WScanControl cr5wScanControl = null; + + /** + * 联新 nr510 控制 + */ + public static Nr510ScanControl nr510ScanControl = null; + + public class Nr510ScanControl extends BroadcastReceiver { + private boolean usecloseState = true; + private Engine engine = new Engine(); + private boolean islxScan = false; + + public Nr510ScanControl() { + Intent intent = getIntent(); + String checkBox = intent.getStringExtra("islxscan"); + islxScan = "0".equals(checkBox) ? true : false; + } + + public void start(Context context) { + if (usecloseState) { + usecloseState = false; + if (islxScan) + engine.start(context); + IntentFilter filter = new IntentFilter(); + filter.addAction("lachesis_barcode_value_notice_broadcast"); + registerReceiver(this, filter); + } + } + + public void stop(Context context) { + if (!usecloseState) { + unregisterReceiver(this); + if (islxScan) + engine.stop(context); + usecloseState = true; + } + } + + @Override + public void onReceive(Context arg0, Intent arg1) { + Log.i("NR510GetValue", "onReceive......"); + final String value = arg1 + .getStringExtra("lachesis_barcode_value_notice_broadcast_data_string"); + //final String value = "1234567890"; + if (value.length() > 10) { + handler.post(new Runnable() { + public void run() { + View rootview = DjActivity.this.getWindow().getDecorView(); + View aaa = rootview.findFocus(); + // View bbb = + // hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + // if (aaa == bbb && defaultFocus2 != null) { + // DjUtil.setFocus(hzTab, defaultFocus2); + // } + if (aaa instanceof SelfEditText) { + SelfEditText set = (SelfEditText)aaa; + if (set.closeKeyBoard) { + set.setText(value); + set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); + set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)); + } + } + } + }); + } + } + } + + /** + * Honeywell 设备扫描头控制 + */ + public static BarcodeReader barcodeReader = null; +// public static boolean triggerState = false; + + /* + * ht518初始化(带新版扫描头) 包括android_serialport_api包和android.gpio包 + * 和com.jiebao.h518.scan.NewScanControler类 + */ + private NewScanControler newScanControler; + private Thread reciverThread; + private boolean isReciverThread = true; + private BeepManager bManager; + private Handler ht518handler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + bManager.playBeepSoundAndVibrate(); + zyFcous(msg.obj.toString()); + newScanControler.stopScan(); + } + }; + + public void ht518Clear() { + isReciverThread = false; + reciverThread = null; + newScanControler.stopScan(); + newScanControler.close(); + newScanControler = null; + ht518handler = null; + bManager.release(); + } + + private void ht518InitNew() { + try { + newScanControler = new NewScanControler(); + newScanControler.initScan(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + reciverThread = new Thread(ReciverDataRunable); + reciverThread.start(); + bManager = new BeepManager(this); + } + + Runnable ReciverDataRunable = new Runnable() { + @Override + public void run() { + while (isReciverThread) { + String msg = newScanControler.getData(); + if (msg != null && msg.length() > 0) { + Message message = new Message(); + message.obj = msg; + ht518handler.sendMessage(message); + } + } + + } + }; + + /* + * seuic PDA + */ + private com.seuic.scanner.Scanner seuicScanner; + private SoundPool soundpool = null; + private int soundid; + private boolean isKeyDown = true; + private String islxscan; + + private SeuicScanKeyEventRunnable seuicScannerThread; + + public void seuicIint() { + soundpool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 100); // MODE_RINGTONE + soundid = soundpool.load(this, R.raw.beep, 1); + if (seuicScanner == null) { + seuicScanner = ScannerFactory.getScanner(DjActivity.this); + } + ScannerKey.close(); + seuicScannerThread = new SeuicScanKeyEventRunnable(seuicScanner); + new Thread(seuicScannerThread).start(); + } + + @Override + public void onDecodeComplete(DecodeInfo info) { + if (!SysData.isreg.equals("Y")) { + openRunWin(); + } + soundpool.play(soundid, 1, 1, 0, 0, 1); + zyFcous(info.barcode); + } + + @Override + public void onTriggerEvent(TriggerStateChangeEvent event) { + // TODO Auto-generated method stub + +// if (event.getState()) { +// //turn on/off aimer, illumination and decoding +// try { +// barcodeReader.aim(!triggerState); +// barcodeReader.light(!triggerState); +// barcodeReader.decode(!triggerState); +// +// triggerState = !triggerState; +// } catch (ScannerNotClaimedException e) { +// e.printStackTrace(); +// } catch (ScannerUnavailableException e) { +// e.printStackTrace(); +// } +// } + } + + @Override + public void onBarcodeEvent(BarcodeReadEvent event) { + // TODO Auto-generated method stub + + final BarcodeReadEvent event2 = event; + runOnUiThread(new Runnable() { + @Override + public void run() { + /* + // update UI to reflect the data + List list = new ArrayList(); + list.add("Barcode data: " + event.getBarcodeData()); + list.add("Character Set: " + event.getCharset()); + list.add("Code ID: " + event.getCodeId()); + list.add("AIM ID: " + event.getAimId()); + list.add("Timestamp: " + event.getTimestamp()); + + final ArrayAdapter dataAdapter = new ArrayAdapter( + AutomaticBarcodeActivity.this, android.R.layout.simple_list_item_1, list); + + barcodeList.setAdapter(dataAdapter); +*/ + // +// Toast.makeText(DjActivity.this, event2.getBarcodeData(), Toast.LENGTH_SHORT).show(); + if (barcodeReader == null) return; + View rootview = DjActivity.this.getWindow().getDecorView(); + // boolean isfindEdit = true; + if (rootview != null) { + View aaa = rootview.findFocus(); + if (aaa != null && aaa instanceof SelfEditText) { + final SelfEditText set = (SelfEditText)aaa; + set.setText(event2.getBarcodeData()); +// set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); +// set.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)); + new Thread(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + Instrumentation inst = new Instrumentation(); + inst.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER); + } + }).start(); + } else { + // isfindEdit = false; + } + } else { + // isfindEdit = false; + } + /* if (!isfindEdit) { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + + @Override + public void run() { + // TODO Auto-generated method stub + triggerState = false; + continuousScanning(true); + } + }, 1000); + }*/ + /* + if (defaultFocus2 != null) { + View bbb = hzTab.findViewWithTag(defaultFocus2.toUpperCase().trim()); + if (bbb instanceof SelfEditText) { + if (((SelfEditText)bbb).getText().length() > 0) + DjUtil.setFocus(hzTab, defaultFocus2); + } + }*/ + + // +// try { +// Thread.sleep(1000);//sleep 1s waiting for another barcode +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// continuousScanning(true); + continuousScanning(true); + } + }); + } + + public void continuousScanning(final boolean bState){ +// if (triggerState && bState) return; +// triggerState = bState; + + new Thread(new Runnable() { + @Override + public void run() { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + barcodeReader.light(bState); //turn on/off backlight + barcodeReader.aim(bState); //开关瞄准线 + barcodeReader.decode(bState); //开关解码功能 + } catch (ScannerUnavailableException e) { + e.printStackTrace(); + } catch (ScannerNotClaimedException e) { + e.printStackTrace(); + } + } + }).start(); + } + + @Override + public void onFailureEvent(BarcodeFailureEvent arg0) { + // TODO Auto-generated method stub + //continuousScanning(true); + } + +} diff --git a/app/src/main/java/com/example/chaoran/DjtqActivity.java b/app/src/main/java/com/example/chaoran/DjtqActivity.java new file mode 100644 index 0000000..b7b1008 --- /dev/null +++ b/app/src/main/java/com/example/chaoran/DjtqActivity.java @@ -0,0 +1,185 @@ +package com.example.chaoran; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.kobjects.base64.Base64; + +import com.chaoran.component.MyAdapter; +import com.chaoran.entiry.DataGrid; +import com.chaoran.entiry.Djselefa; +import com.example.chaoran.R; +import com.util.DialogUtil; +import com.util.IoUtil; +import com.util.SqlUtil; +import com.util.SysUtil; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.KeyEvent; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.ListView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.TextView; + +public class DjtqActivity extends Activity { + private ListView listview; + private int cur_pos = -1;// 当前显示的一行 + // private ArrayList items_text = new ArrayList(); + private Djselefa djselefa; + public ProgressDialog pd; + public MyAdapter adapter; + private ArrayList listdata; + private String filedName;// 显示字段的名字 + private String gzid; + private String mxTempTable; + private Intent intent; + private Handler runHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.what == -1) { + DialogUtil.builder(DjtqActivity.this, "错误信息", "提取方案初始化失败:" + + msg.obj.toString(),0); + } else if (msg.what == -4) { + DialogUtil.builder(DjtqActivity.this, "错误信息", "提取方案运行失败:" + + msg.obj.toString(),0); + } else { + if (msg.arg1 == 4) { + Object ob = msg.obj; + if (ob instanceof ArrayList) { + ArrayList list = (ArrayList) ob; + if (list.size() > 0) { + intent.putExtra("param", (HashMap) list.get(0)); + setResult(2, intent); + } + clear(); + } else { + DialogUtil.builder(DjtqActivity.this, "提示信息", + ob.toString(),0); + } + } else { + HashMap map = (HashMap) msg.obj; + DataGrid dg = (DataGrid) map.get("dg"); + listdata = dg.getTableData(); + if(listdata==null||listdata.size()<1){ + filedName=""; + }else{ + filedName=SysUtil.mapFirst(listdata); + } + if (adapter == null) { + adapter = new MyAdapter(DjtqActivity.this, listdata, + filedName); + listview.setAdapter(adapter); + } + } + } + if (pd != null) { + pd.dismiss(); + } + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.list); + listview = (ListView) findViewById(R.id.mxlist); + intent = getIntent(); + HashMap paramMap = (HashMap) intent.getSerializableExtra("paramMap"); + djselefa = (Djselefa) paramMap.get("djselefa"); + pd = ProgressDialog.show(DjtqActivity.this, "正在执行提取方案", "正在下载……"); + try { + new RunSearchThread(djselefa.getT_sql(), IoUtil.ob_base64(paramMap + .get("t_sqlParam")), runHandler).start(); + } catch (IOException e) { + // e.printStackTrace(); + DialogUtil.builder(this, "错误信息", "转换成Base64编码失败!",0); + } + gzid = paramMap.get("GZID").toString(); + mxTempTable = paramMap.get("mxTempTable").toString(); + intent.removeExtra("paramMap"); + TextView tv = (TextView) findViewById(R.id.mxtitle); + tv.setText(djselefa.getFangamch()); + ((Button) findViewById(R.id.mxbut)).setText("提取"); + listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);// 一定要设置这个属性,否则ListView不会刷新 + listview.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(AdapterView arg0, View arg1, + int position, long id) { + cur_pos = position;// 更新当前行 + adapter.cur_pos = cur_pos; + } + }); + } + + public void queryMx(View v) { + try { + if (cur_pos < 0) { + DialogUtil.builder(this, "提示信息", "请选择一行!",0); + } else { + if (mxTempTable == null || mxTempTable.length() < 0) { + DialogUtil.builder(this, "提示信息", "明细表不存在!",0); + } + HashMap item = (HashMap) listdata.get(cur_pos); + HashMap hzData = SqlUtil.regSql(djselefa.getHz_sql(), item); + HashMap mxData = SqlUtil.regSql(djselefa.getMx_sql(), item); + HashMap hm = new HashMap(); + hm.put("gzid", gzid); + hm.put("mxTempTable", mxTempTable); + hm.put("hzSql", hzData.get("sql")); + hm.put("hzParam", hzData.get("param")); + hm.put("mxSql", mxData.get("sql")); + hm.put("mxParam", mxData.get("param")); + byte[] b = IoUtil.getbyte(hm); + DialogUtil.setDialog(pd, "提示信息", "正在运行提取方案"); + new RunYmupThread(Base64.encode(b), runHandler, "runTqfa",0) + .start(); + } + } catch (Exception e) { + pd.dismiss(); + DialogUtil.builder(DjtqActivity.this, "错误信息", "提取修改方案组织数据失败!",0); + } + } + + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() + && !event.isCanceled()) { + clear(); + return true; + } + return super.onKeyUp(keyCode, event); + } + + private void clear() { + listview = null; + if (pd != null) { + pd.dismiss(); + pd = null; + } + djselefa = null; + adapter = null; + if (listdata != null) { + listdata.clear(); + listdata = null; + } + filedName = null; + gzid = null; + mxTempTable = null; + intent = null; + runHandler = null; + intent = null; + finish(); + } + +} diff --git a/app/src/main/java/com/example/chaoran/ExitThread.java b/app/src/main/java/com/example/chaoran/ExitThread.java new file mode 100644 index 0000000..f5c1409 --- /dev/null +++ b/app/src/main/java/com/example/chaoran/ExitThread.java @@ -0,0 +1,75 @@ +package com.example.chaoran; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +import com.sys.SysData; + +public class ExitThread extends Thread { + public String gzid; + public String mxTempTable; + public Handler handler; + public String method; + + public ExitThread(String gzid, String mxTempTable, Handler handler, + String method) { + this.gzid = gzid; + this.mxTempTable = mxTempTable; + this.handler = handler; + this.method = method; + } + + public void run() { + super.run(); + Log.v("SearchThread", "run执行"); + try { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + // method = "exitDj"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("gzid", gzid); + rpc.addProperty("mxTempTable", mxTempTable); + HttpTransportSE ht = new HttpTransportSE(url); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (handler != null) { + if (envelope.getResponse() != null) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + Message msg = new Message(); + msg.obj = envelope.getResponse(); + if (method.equals("exitDj")) { + msg.arg1 = 4; + } else if (method.equals("queryMx")) { + msg.arg1 = 5; + } + handler.sendMessage(msg); + } else { + Message msg = new Message(); + msg.obj = null; + handler.sendMessage(msg); + } + } + } catch (Exception e) { + if (handler != null) { + Message msg = new Message(); + if (method.equals("exitDj")) { + msg.what = -4; + } else if (method.equals("queryMx")) { + msg.what = -5; + } + msg.obj = e.toString(); + handler.sendMessage(msg); +// e.printStackTrace(); + } + } + } +} diff --git a/app/src/main/java/com/example/chaoran/MainActivity.java b/app/src/main/java/com/example/chaoran/MainActivity.java new file mode 100644 index 0000000..5e2f32a --- /dev/null +++ b/app/src/main/java/com/example/chaoran/MainActivity.java @@ -0,0 +1,698 @@ +package com.example.chaoran; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Properties; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; +import org.xmlpull.v1.XmlPullParserException; + +import com.chaoran.db.DBManager; +import com.chaoran.db.SqlHelpUtil; +import com.chaoran.entiry.UpdataInfo; +import com.chaoran.entiry.UserList; +import com.chaoran.lx.activity.DownDataActivity; +import com.chaoran.thread.DownApk; +import com.example.chaoran.R; +import com.honeywell.aidc.AidcManager; +import com.honeywell.aidc.AidcManager.CreatedCallback; +import com.honeywell.aidc.BarcodeReader; +import com.sys.SysData; +import com.util.DialogUtil; +import com.util.Dom4jUtil; +import com.util.InstallUtil; +import com.util.IoUtil; +import com.util.SysUtil; + +import android.content.pm.ActivityInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; + +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.pm.PackageManager; +import android.content.res.Configuration; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +public class MainActivity extends Activity { + SqlHelpUtil db; + SQLiteDatabase sDatabase; + EditText name; + EditText pwd; + private CheckBox checkBox; + private CheckBox islxScan; + public ProgressDialog pd; + private int loginTy;// 登录类型,1为在线登录 2为离线数据下载 + private TextView regts; + public String versionStr; + + public static float def_pbl = 0.9f; // 屏幕比列 + + //Honeywell 扫描设备控制 + private static BarcodeReader barcodeReader = null; + private AidcManager manager = null; + + private Handler handler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + if (msg.what == -1) { + DialogUtil.builder(MainActivity.this, "错误信息", "连接服务器失败,请检查网络!" + + msg.obj,0); + } else if (msg.what == -2) { + DialogUtil.builder(MainActivity.this, "错误信息", "用户名或密码错误!",0); + } else if (msg.what == -3) { + DialogUtil.builder(MainActivity.this, "错误信息", "解析xml失败!",0); + } else if (msg.what == -4) { + DialogUtil.builder(MainActivity.this, "错误信息", "检查更新失败,请检查网络!",0); + } else if (msg.what == -5) { + DialogUtil.builder(MainActivity.this, "错误信息", "更新文件失败!",0); + } else if (msg.what == 1) { + UpdataInfo info = (UpdataInfo) msg.obj; + System.out.println(info+"---------------------"); + System.out.println(versionStr+"---------------------"); + if (info!=null&&!info.getVersion().equals(versionStr)) { + showUpdataDialog(info); + } + } else if (msg.what == 2) { + new InstallUtil().installApk((File) msg.obj, MainActivity.this); + } else { + if (msg.obj.equals("该功能未授权")) { + DialogUtil.builder(MainActivity.this, "提示信息", "该功能未授权!",0); + } else { + UserList user = (UserList) msg.obj; + // System.out.println(so.hasProperty("lgnname")); + if (user.getLgnname() == null) { + String udesc = user.getUdesc(); + if (udesc.equals("0")) { + DialogUtil.builder(MainActivity.this, "提示信息", + "PDA未注册!",0); + } else if (udesc.equals("1")) { + DialogUtil.builder(MainActivity.this, "提示信息", + "PDA还未授权使用!",0); + } else if (udesc.equals("2")) { + DialogUtil.builder(MainActivity.this, "提示信息", + "试用期已过!",0); + } else if (udesc.equals("3")) { + DialogUtil.builder(MainActivity.this, "提示信息", + "超出最大站点数,请联系管理员",0); + } else if (udesc.equals("-1")) { + DialogUtil.builder(MainActivity.this, "提示信息", + "用户名或密码错误!",0); + } + + } else { + // SysData.username= + // so.getProperty("username").toString().trim(); + SysData.is_lx = false; + login_end(user); + // SysData.jigid = user.getJigid(); + // SysData.lgnname = user.getLgnname(); + // SysData.userid = String.valueOf(user.getUserid()); + // SysData.scale = MainActivity.this.getResources() + // .getDisplayMetrics().density + 1; + // SharedPreferences sp = MainActivity.this + // .getSharedPreferences("userTxt", MODE_PRIVATE); + // Editor editor = sp.edit(); + // editor.putString("name", name.getText().toString() + // .trim()); + // editor.putString("pwd", + // pwd.getText().toString().trim()); + // editor.commit(); + // Intent intent = new Intent(); + // intent.putExtra("displaymode", + // user.getDisplaymode()); + // intent.setClass(getApplicationContext(), + // DjActivity.class); + // startActivity(intent); + } + } + } + if (pd != null) { + pd.dismiss(); + } + } + }; + private Handler regHandler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + if (msg.what != -1) { + if(msg.equals("-1")){ + regts.setText("正式 注册"); + }else{ + regts.setText("软件到期时间"+msg.obj); + } + } + } + }; + public void login_end(UserList user) { + SysData.jigid = user.getJigid(); + SysData.lgnname = user.getLgnname(); + SysData.userid = String.valueOf(user.getUserid()); + SysData.scale = MainActivity.this.getResources().getDisplayMetrics().density + 1; + //SysData.t_scale = MainActivity.this.getResources().getDisplayMetrics().densityDpi >= 200f ? 200f / MainActivity.this.getResources().getDisplayMetrics().densityDpi : 200f * 0.95f / MainActivity.this.getResources().getDisplayMetrics().densityDpi; + SysData.t_scale = MainActivity.this.getResources().getDisplayMetrics().densityDpi >= 300f ? 1 : 300f * def_pbl / MainActivity.this.getResources().getDisplayMetrics().densityDpi; + SysData.exectime=Integer.parseInt(user.getUdesc() == null ? "60" : user.getUdesc()); + System.out.println(SysData.exectime+"---------------------------------------SysData.exectime"); + SharedPreferences sp = MainActivity.this.getSharedPreferences( + "userTxt", MODE_PRIVATE); + // Editor editor = sp.edit(); + // editor.putString("name", name.getText().toString().trim()); + // editor.putString("pwd", pwd.getText().toString().trim()); + // editor.commit(); + if (checkBox.isChecked()) { + Editor editor = sp.edit(); + editor.putString("name", name.getText().toString().trim()); + editor.putString("pwd", pwd.getText().toString().trim()); + editor.putBoolean("islxScan",islxScan.isChecked()); + editor.commit(); + } else { + sp.edit().clear().commit(); + name.setText(""); + pwd.setText(""); + } + if (loginTy == 1) { + String islxscan="1"; + if(islxScan.isChecked()){ + islxscan="0"; + } + Intent intent = new Intent(); + intent.putExtra("displaymode", user.getDisplaymode()); + intent.putExtra("islxscan", islxscan); + intent.setClass(getApplicationContext(), DjActivity.class); + startActivity(intent); + } else if (loginTy == 2) { + Intent intent = new Intent(); + intent.setClass(getApplicationContext(), DownDataActivity.class); + startActivity(intent); + } + SysData.no = name.getText().toString().trim(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + System.setProperty("http.keepAlive", "false"); + setContentView(R.layout.activity_main); + SharedPreferences sp = getSharedPreferences("userTxt", MODE_PRIVATE); + name = (EditText) findViewById(R.id.name); + pwd = (EditText) findViewById(R.id.pwd); + regts=(TextView) findViewById(R.id.regts); + checkBox = (CheckBox) findViewById(R.id.cb); + islxScan=(CheckBox)findViewById(R.id.lxs); + if (!sp.contains("name")) { + checkBox.setChecked(false); + } else { + name.setText(sp.getString("name", "")); + pwd.setText(sp.getString("pwd", "")); + islxScan.setChecked(sp.getBoolean("islxScan", true)); + } + TextView version = (TextView) findViewById(R.id.version); + versionStr=getVersionName(); + version.setText("版本".concat(versionStr)); + // SysData.clientid = Secure.getString(getContentResolver(), + // Secure.ANDROID_ID); + SysData.clientid = SysUtil.getLocalMacAddress(MainActivity.this); + db = new SqlHelpUtil(getApplicationContext()); + sDatabase = db.getWritableDatabase(); + String selectStr = "select col1,col2,col3 from systable where desc='network'"; + Cursor select_cursor = sDatabase.rawQuery(selectStr, null); + if (select_cursor.moveToFirst()) { + SysData.url = "http://".concat(select_cursor.getString(0)) + .concat(":").concat(select_cursor.getString(1)).concat("/") + .concat(select_cursor.getString(2)); + } + select_cursor.close(); + selectStr = "select col1 from systable where desc='pdaState'"; + select_cursor = sDatabase.rawQuery(selectStr, null); + if (select_cursor.moveToFirst()) { + SysData.isreg = select_cursor.getString(0); + System.out.println(SysData.isreg+"---------------------"); + } + select_cursor.close(); + if (SysData.url != null) { + new Thread(new CheckVersionTask()).start(); + new Thread(queryZcrq).start(); + } + // + BufferedReader br = null; + BufferedWriter bw = null; + File file = new File(getFilesDir().getAbsolutePath() + "/cr_pda_config"); + try { + if (!file.exists()) + file.createNewFile(); + FileInputStream fis = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(fis); + br = new BufferedReader(isr); + String s = br.readLine(); + if (s == null || s.trim().length() < 1) + throw new Exception("Update config data."); + def_pbl = Float.parseFloat(s); + if (def_pbl < 0.1 || def_pbl > 10.0) + throw new Exception("请填写 0.1~10.0 之间的浮点数!"); + } catch (Exception e) { + def_pbl = 0.9f; + try { + FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos); + bw = new BufferedWriter(osw); + bw.append(Float.toString(def_pbl)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (bw != null) { + try { + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + // + if ("scanpal eda50".equals(android.os.Build.MODEL.toLowerCase())) { + AidcManager.create(this, new CreatedCallback() { + + @Override + public void onCreated(AidcManager aidcManager) { + manager = aidcManager; + barcodeReader = manager.createBarcodeReader(); + } + }); + } + + } + + public static BarcodeReader getBarcodeObject() { + return barcodeReader; + } + + Runnable downloadRun = new Runnable() { + public void run() { + login(name.getText().toString().trim(), pwd.getText().toString() + .trim()); + } + }; + Runnable queryZcrq = new Runnable() { + public void run() { + try { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + // System.out + // .println(url + // + + // "--------------============================================"); + String method = "regEndRq"; + SoapObject rpc = new SoapObject("", method); + HttpTransportSE ht = new HttpTransportSE(url, SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + Message message = new Message(); + message.obj = envelope.getResponse().toString(); + regHandler.sendMessage(message); + } catch (Exception e) { + Message message = new Message(); + message.what = -1; + message.obj = e.toString(); + regHandler.sendMessage(message); + } + + } + }; + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_main, menu); + return true; + } + + /* + * 获取当前程序的版本号 + */ + private String getVersionName() { + // 获取packagemanager的实例 + PackageManager packageManager = getPackageManager(); + // getPackageName()是你当前类的包名,0代表是获取版本信息 + PackageInfo packInfo = null; + try { + packInfo = packageManager.getPackageInfo(getPackageName(), 0); + } catch (NameNotFoundException e) { + DialogUtil.builder(MainActivity.this, "错误信息", "获取版本号失败!",0); + } + return packInfo.versionName; + } + + // 设置按钮监听 + public void onset(View v) { + Intent intent = new Intent(); + intent.setClass(this, NetWorkSet.class); + // intent.setClass(getApplicationContext(), BDMapActivity.class); + startActivity(intent); + // startActivityForResult(intent,0); + } + + public void onopentest(View v) { + DialogUtil.builder(this, "测试标题","测试内容!open" + v.getLeft(), 18); +// ScanManager sm = (ScanManager) getSystemService("olc_service_scan"); +// +// sm.setScanSwitchLeft(false); +// sm.setScanSwitchRight(false); +// sm.setScanSwitchMiddle(false); + } + + public void onclosetest(View v) { + DialogUtil.builder(this, "测试标题","测试内容!close" + v.getLeft(), 18); +// ScanManager sm = (ScanManager) getSystemService("olc_service_scan"); +// +// sm.setScanSwitchLeft(true); +// sm.setScanSwitchRight(true); +// sm.setScanSwitchMiddle(true); + } + + // 设置按钮监听 + public void onRotation(View v) { + int i = MainActivity.this.getRequestedOrientation(); + // name.setText(i+"--"+ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT+"--"+ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + if (i == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { + MainActivity.this + .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + // 纵屏反方向 + else if (i == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || i == 3) { + MainActivity.this + .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT); + } + } + + public boolean isNull() { + if (name.getText().toString().trim().equals("")) { + DialogUtil.builder(this, "错误信息", "用户名不能为空!",0); + name.requestFocus(); + return false; + } + if (pwd.getText().toString().trim().equals("")) { + DialogUtil.builder(this, "错误信息", "密码不能为空!",0); + pwd.requestFocus(); + return false; + } + return true; + } + + // 设置按钮监听 + public void onsub(View v) { + // if (SysData.url == null) { + // DialogUtil.builder(this, "错误信息", "请检查网络!"); + // return; + // } + loginTy = 1; + start_login(); + } + + public void start_login() { + if (!isNull()) { + return; + } + if (!SysUtil.isNetworkConnected(MainActivity.this)) { + DialogUtil.builder(MainActivity.this, "提示", "网络没连接!请检查网络",0); + return; + } + if (name.getText().toString().trim().equals("crtech") + && pwd.getText().toString().trim().equals("crtech")) { + Intent pdaIntent = new Intent(); + pdaIntent.setClass(this, PdaRegActivity.class); + startActivity(pdaIntent); + return; + } + if (SysData.url == null || SysData.url.trim().length() < 1) { + DialogUtil.builder(this, "错误信息", "请设置URL!",0); + return; + } + if (SysData.clientid.trim().length() < 1) { + DialogUtil.builder(this, "错误信息", "mac地址为空,请检查网络!",0); + return; + } + if (pd == null) { + pd = ProgressDialog.show(this, "提示", "正在登录……"); + } else { + DialogUtil.setDialog(pd, "提示", "正在登录……"); + } + + // DialogUtil.setDialog(pd, "提示", "" + MainActivity.this.getResources().getDisplayMetrics().densityDpi); + new Thread(downloadRun).start(); + } + + public void login(String name, String pwd) { + // WifiManager wifiManager=(WifiManager) + // this.getSystemService(Context.WIFI_SERVICE); + // wifiManager.disconnect(); + // wifiManager.reconnect(); + try { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + // System.out + // .println(url + // + "--------------============================================"); + String method = "login"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("name", name); + rpc.addProperty("pwd", pwd); + rpc.addProperty("mac", SysData.clientid); + HttpTransportSE ht = new HttpTransportSE(url, SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (envelope.getResponse() != null) { + // SoapObject result = (SoapObject) envelope.bodyIn; + // SoapObject soapChilds = (SoapObject) result.getProperty(0); + // System.out.println(soapChilds+"---"+soapChilds.getProperty("jigid")); + // System.out.println(soapChilds.getProperty("jigid")); + byte[] bb = org.kobjects.base64.Base64.decode(envelope + .getResponse().toString()); + Message message = new Message(); + message.obj = IoUtil.byte_obj(bb); + handler.sendMessage(message); + } else { + Message message = new Message(); + message.what = -2; + handler.sendMessage(message); + } + } catch (Exception e) { + Message message = new Message(); + message.what = -1; + message.obj = e.toString(); + handler.sendMessage(message); + } + + } + + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (event.KEYCODE_BACK == keyCode) { + if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + } + return super.onKeyDown(keyCode, event); + } + + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (db != null) { + db.close(); + sDatabase.close(); + } + if (barcodeReader != null) { + // close BarcodeReader to clean up resources. + barcodeReader.close(); + barcodeReader = null; + } + + if (manager != null) { + // close AidcManager to disconnect from the scanner service. + // once closed, the object can no longer be used. + manager.close(); + } + } + + private void showUpdataDialog(final UpdataInfo info) { + Builder builer = new Builder(this); + builer.setTitle("版本升级"); + builer.setMessage(info.getDescription()); + // 当点确定按钮时从服务器上下载 新的apk 然后安装 + builer.setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + downLoadApk(SysData.url.concat(info.getUrl())); + } + }); + // 当点取消按钮时进行登录 + builer.setNegativeButton("取消", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + AlertDialog dialog = builer.create(); + dialog.show(); + } + + private void downLoadApk(String url) { + ProgressDialog pd = new ProgressDialog(this); + pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + pd.setMessage("正在下载更新"); + pd.show(); + new Thread(new DownApk(pd, url, this.getApplicationContext(), handler)) + .start(); + } + + public class CheckVersionTask implements Runnable { + public void run() { + InputStream is = null; + HttpURLConnection conn = null; + try { + String path = SysData.url + "/apk.xml"; + System.out.println(path+"----------------------"); + URL url = new URL(path); + conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(5000); + if (conn.getResponseCode() == 200) { + is = conn.getInputStream(); + // UpdataInfo info = getUpdataInfo(is); + Message msg = new Message(); + msg.what = 1; + System.out.println(versionStr); + msg.obj = Dom4jUtil.parserXml(is,versionStr); + handler.sendMessage(msg); + } + } catch (Exception e) { + Message msg = new Message(); + msg.what = -4; + handler.sendMessage(msg); + } finally { + try { + if (is != null) + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + super.onOptionsItemSelected(item); + switch (item.getItemId())// 得到被点击的item的itemId + { + case R.id.lxdatadown: + loginTy = 2; + start_login(); + // Intent intent = new Intent(); + // intent.setClass(getApplicationContext(), DownDataActivity.class); + // startActivity(intent); + break; + case R.id.lxlogin: + if (!isNull()) { + return true; + } + DBManager dbManager = new DBManager(this); + if (dbManager.existsTable("userlist".toUpperCase()) < 1) { + DialogUtil.builder(MainActivity.this, "信息提示", "请下载用户资料表!",0); + } else { + String sql = "select jigid,lgnname,userid from userlist where username='" + + name.getText().toString().trim() + + "' and pass='" + + pwd.getText().toString().trim() + "'"; + Cursor cur = dbManager.query(sql); + if (cur.getCount() == 0) { + DialogUtil.builder(MainActivity.this, "信息提示", "用户账号错误!",0); + } else { + SysData.is_lx = true; + UserList user = new UserList(); + if (cur.moveToFirst()) { + user.setJigid(cur.getString(0)); + user.setLgnname(cur.getString(1)); + user.setUserid(cur.getInt(2)); + user.setDisplaymode("grid"); + loginTy = 1; + login_end(user); + } + if (dbManager.existsTable("TEMP_BI_DJHZ".toUpperCase()) < 1) { + dbManager + .exeSql("create table TEMP_BI_DJHZ(FIELDNAME varchar(200),FIELDVALUE VARCHAR(8000))"); + } + } + cur.close(); + cur = null; + } + dbManager.closeDB(); + break; + default: + break; + } + return true; + } + + /** + * 该方法解决屏幕旋转程序崩溃,需要对应 AndroidManifest.xml 文件 android:configChanges="orientation|screenSize|keyboardHidden" 配置 + */ + public void onConfigurationChanged(Configuration newConfig) { + // TODO Auto-generated method stub + super.onConfigurationChanged(newConfig); + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + Toast.makeText(this, "转换横屏", Toast.LENGTH_SHORT).show(); + } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { + Toast.makeText(this, "转换竖屏", Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/app/src/main/java/com/example/chaoran/MenuActivity.java b/app/src/main/java/com/example/chaoran/MenuActivity.java new file mode 100644 index 0000000..48c5e87 --- /dev/null +++ b/app/src/main/java/com/example/chaoran/MenuActivity.java @@ -0,0 +1,122 @@ +package com.example.chaoran; + +import java.io.ByteArrayInputStream; +import java.io.ObjectInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + + +import com.chaoran.entiry.DanJuEntity; +import com.example.chaoran.R; +import com.sys.SysData; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.app.Activity; +import android.content.Intent; +import android.view.Menu; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.AdapterView.OnItemClickListener; + +public class MenuActivity extends Activity { + private ListView listView; + private List mData; + SimpleAdapter adapter; + Runnable downloadRun = new Runnable() { + public void run() { + purview(); + } + }; + private Handler handler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + adapter.notifyDataSetChanged(); + } + + }; + public void purview(){ + try { + String url = SysData.url+"/ChaoRanBI/webservice/ServiceInterface?wsdl"; + System.out.println(url); + String method = "selectAndroidPurview"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("userid",SysData.userid); + HttpTransportSE ht = new HttpTransportSE(url); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (envelope.getResponse() != null) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + byte[] bb = org.kobjects.base64.Base64.decode(envelope + .getResponse().toString()); + ByteArrayInputStream bin = new ByteArrayInputStream(bb); + ObjectInputStream oin = new ObjectInputStream(bin); + List list= (List) oin.readObject(); +// for(int i=0;i arg0, View arg1, int arg2, + long arg3) { + Map map=(Map)mData.get(arg2); +// System.out.println(map.get("gn_no")); + Intent intent = new Intent(); + intent.putExtra("formlx", map.get("gn_no").toString()); + intent.setClass(getApplicationContext(), DjActivity.class); + startActivity(intent); + } + }; + listView.setOnItemClickListener(lis1); + setContentView(listView); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_menu, menu); + return true; + } +} diff --git a/app/src/main/java/com/example/chaoran/MipcaActivityCapture.java b/app/src/main/java/com/example/chaoran/MipcaActivityCapture.java new file mode 100644 index 0000000..457807f --- /dev/null +++ b/app/src/main/java/com/example/chaoran/MipcaActivityCapture.java @@ -0,0 +1,229 @@ +package com.example.chaoran; + + +import java.io.IOException; +import java.util.Vector; + +import android.app.Activity; +import android.content.Intent; +import android.content.res.AssetFileDescriptor; +import android.graphics.Bitmap; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.media.MediaPlayer.OnCompletionListener; +import android.os.Bundle; +import android.os.Handler; +import android.os.Vibrator; +import android.view.SurfaceHolder; +import android.view.SurfaceHolder.Callback; +import android.view.SurfaceView; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.Toast; + +import com.example.chaoran.R; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import com.mining.app.zxing.camera.CameraManager; +import com.mining.app.zxing.decoding.CaptureActivityHandler; +import com.mining.app.zxing.decoding.InactivityTimer; +import com.mining.app.zxing.view.ViewfinderView; +/** + * 摄像头扫描条码 + */ +public class MipcaActivityCapture extends Activity implements Callback { + + private CaptureActivityHandler handler; + private ViewfinderView viewfinderView; + private boolean hasSurface; + private Vector decodeFormats; + private String characterSet; + private InactivityTimer inactivityTimer; + private MediaPlayer mediaPlayer; + private boolean playBeep; + private static final float BEEP_VOLUME = 0.10f; + private boolean vibrate; + private String uiId; + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.camerascansctivity); + //ViewUtil.addTopView(getApplicationContext(), this, R.string.scan_card); + CameraManager.init(getApplication()); + viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); + Intent intent = getIntent(); + uiId = intent.getStringExtra("uiId"); + Button mButtonBack = (Button) findViewById(R.id.button_back); + mButtonBack.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + MipcaActivityCapture.this.finish(); + + } + }); + hasSurface = false; + inactivityTimer = new InactivityTimer(this); + } + + @Override + protected void onResume() { + super.onResume(); + SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view); + SurfaceHolder surfaceHolder = surfaceView.getHolder(); + if (hasSurface) { + initCamera(surfaceHolder); + } else { + surfaceHolder.addCallback(this); + surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); + } + decodeFormats = null; + characterSet = null; + + playBeep = true; + AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE); + if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) { + playBeep = false; + } + initBeepSound(); + vibrate = true; + + } + + @Override + protected void onPause() { + super.onPause(); + if (handler != null) { + handler.quitSynchronously(); + handler = null; + } + CameraManager.get().closeDriver(); + } + + @Override + protected void onDestroy() { + inactivityTimer.shutdown(); + super.onDestroy(); + } + + /** + * 处理扫描结果 + * @param result + * @param barcode + */ + public void handleDecode(Result result, Bitmap barcode) { + inactivityTimer.onActivity(); + playBeepSoundAndVibrate(); + String resultString = result.getText(); + if (resultString.equals("")) { + Toast.makeText(MipcaActivityCapture.this, "Scan failed!", Toast.LENGTH_SHORT).show(); + }else { + Intent resultIntent = new Intent(); + Bundle bundle = new Bundle(); + bundle.putString("tm", resultString); + bundle.putString("uiId",uiId); + System.out.println(resultString+"==============-"+uiId+"--------------------------------------------------------"); +// bundle.putParcelable("bitmap", barcode); + resultIntent.putExtras(bundle); + this.setResult(4, resultIntent); + } + MipcaActivityCapture.this.finish(); + } + + private void initCamera(SurfaceHolder surfaceHolder) { + try { + CameraManager.get().openDriver(surfaceHolder); + } catch (IOException ioe) { + return; + } catch (RuntimeException e) { + return; + } + if (handler == null) { + handler = new CaptureActivityHandler(this, decodeFormats, + characterSet); + } + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, + int height) { + + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + if (!hasSurface) { + hasSurface = true; + initCamera(holder); + } + + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + hasSurface = false; + + } + + public ViewfinderView getViewfinderView() { + return viewfinderView; + } + + public Handler getHandler() { + return handler; + } + + public void drawViewfinder() { + viewfinderView.drawViewfinder(); + + } + + private void initBeepSound() { + if (playBeep && mediaPlayer == null) { + // The volume on STREAM_SYSTEM is not adjustable, and users found it + // too loud, + // so we now play on the music stream. + setVolumeControlStream(AudioManager.STREAM_MUSIC); + mediaPlayer = new MediaPlayer(); + mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + mediaPlayer.setOnCompletionListener(beepListener); + + AssetFileDescriptor file = getResources().openRawResourceFd( + R.raw.beep); + try { + mediaPlayer.setDataSource(file.getFileDescriptor(), + file.getStartOffset(), file.getLength()); + file.close(); + mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); + mediaPlayer.prepare(); + } catch (IOException e) { + mediaPlayer = null; + } + } + } + + private static final long VIBRATE_DURATION = 200L; + + private void playBeepSoundAndVibrate() { + if (playBeep && mediaPlayer != null) { + mediaPlayer.start(); + } +// if (vibrate) { +// Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); +// vibrator.vibrate(VIBRATE_DURATION); +// } + } + + /** + * When the beep has finished playing, rewind to queue up another one. + */ + private final OnCompletionListener beepListener = new OnCompletionListener() { + public void onCompletion(MediaPlayer mediaPlayer) { + mediaPlayer.seekTo(0); + } + }; + +} diff --git a/app/src/main/java/com/example/chaoran/NetWorkSet.java b/app/src/main/java/com/example/chaoran/NetWorkSet.java new file mode 100644 index 0000000..d4d098f --- /dev/null +++ b/app/src/main/java/com/example/chaoran/NetWorkSet.java @@ -0,0 +1,241 @@ +package com.example.chaoran; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.HashMap; + +import org.kobjects.base64.Base64; + +import com.chaoran.db.SqlHelpUtil; +import com.example.chaoran.R; +import com.sys.SysData; +import com.util.DialogUtil; +import com.util.IoUtil; +import com.util.SysUtil; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.provider.Settings.Secure; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.util.DisplayMetrics; +import android.view.Menu; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +@SuppressLint("NewApi") +public class NetWorkSet extends Activity { + private EditText ip; + private EditText port; + private EditText itemName; + private EditText bz; + private SqlHelpUtil db; + private SQLiteDatabase sDatabase; + + private Handler regHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + if (msg.obj.equals("0")) { + DialogUtil.builder(NetWorkSet.this, "提示信息", "注册成功!", 0); + } else if (msg.obj.equals("1")) { + DialogUtil.builder(NetWorkSet.this, "提示信息", "该PDA已注册!", 0); + } else { + DialogUtil.builder(NetWorkSet.this, "提示信息", "注册失败!" + msg.obj.toString(), 0); + } + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // + BufferedReader br = null; + BufferedWriter bw = null; + File file = new File(getFilesDir().getAbsolutePath() + "/cr_pda_config"); + try { + if (!file.exists()) { + file.createNewFile(); + //DialogUtil.builder(NetWorkSet.this, "错误信息", "文件不存在!", 0); + } + FileInputStream fis = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(fis); + br = new BufferedReader(isr); + String s = br.readLine(); + if (s == null || s.trim().length() < 1) + throw new Exception("Update config data."); + MainActivity.def_pbl = Float.parseFloat(s); + if (MainActivity.def_pbl < 0.1 || MainActivity.def_pbl > 10.0) + throw new Exception("请填写 0.1~10.0 之间的浮点数!"); + } catch (Exception e) { + DialogUtil.builder(NetWorkSet.this, "错误信息", e.getMessage(), 0); + MainActivity.def_pbl = 0.9f; + try { + FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos); + bw = new BufferedWriter(osw); + bw.append(Float.toString(MainActivity.def_pbl)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (bw != null) { + try { + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + // + setContentView(R.layout.activity_net_work_set); + ip = (EditText) findViewById(R.id.ip); + port = (EditText) findViewById(R.id.port); + itemName = (EditText) findViewById(R.id.itemName); + bz = (EditText) findViewById(R.id.bz); + TextView mactv = (TextView) findViewById(R.id.mac); + mactv.setText("mac:" + SysUtil.getLocalMacAddress(NetWorkSet.this)); + TextView androidIDtv = (TextView) findViewById(R.id.androidID); + androidIDtv.setText("sn:" + SysUtil.getSn()); + EditText te = (EditText) findViewById(R.id.itemName91); + te.setText(Float.toString(MainActivity.def_pbl)); + // MainActivity.this.getResources().getDisplayMetrics().densityDpi + TextView modeltv = (TextView) findViewById(R.id.model); + modeltv.setText("型号:" + android.os.Build.MODEL.toLowerCase()); + // + TextView phoneDpi = (TextView) findViewById(R.id.phoneDpi); + phoneDpi.setText("密度:" + getResources().getDisplayMetrics().densityDpi); + // + db = new SqlHelpUtil(getApplicationContext()); + sDatabase = db.getWritableDatabase(); + System.out.println(sDatabase.getMaximumSize() + "--------------------------"); + String selectStr = "select col1,col2,col3 from systable where desc='network'"; + Cursor select_cursor = sDatabase.rawQuery(selectStr, null); + if (select_cursor.moveToFirst()) { + ip.setText(select_cursor.getString(0)); + port.setText(select_cursor.getString(1)); + itemName.setText(select_cursor.getString(2)); + } + select_cursor.close(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_net_work_set, menu); + return true; + } + + public void onsub(View v) { + EditText te = (EditText) findViewById(R.id.itemName91); + try { + MainActivity.def_pbl = Float.parseFloat(te.getText().toString()); + } catch (Exception ex) { + DialogUtil.builder(NetWorkSet.this, "错误信息", "请填写 0.1~10.0 之间的浮点数!", 0); + MainActivity.def_pbl = 0.9f; + } finally { + if (MainActivity.def_pbl < 0.1 || MainActivity.def_pbl > 10.0) { + DialogUtil.builder(NetWorkSet.this, "错误信息", "请填写 0.1~10.0 之间的浮点数!", 0); + MainActivity.def_pbl = 0.9f; + } + } + // + BufferedWriter bw = null; + File file = new File(getFilesDir().getAbsolutePath() + "/cr_pda_config"); + + try { + FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos); + bw = new BufferedWriter(osw); + bw.append(Float.toString(MainActivity.def_pbl)); + } catch (IOException e1) { + e1.printStackTrace(); + } finally { + if (bw != null) { + try { + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + // + // DialogUtil.builder(NetWorkSet.this, "错误信息", "请检查网络!" + + // MainActivity.def_pbl,0); + if (ip.getText().toString().trim().equals("")) { + DialogUtil.builder(NetWorkSet.this, "错误信息", "请填写IP!", 0); + ip.requestFocus(); + return; + } + if (port.getText().toString().trim().equals("")) { + DialogUtil.builder(NetWorkSet.this, "错误信息", "请填写端口!", 0); + port.requestFocus(); + return; + } + if (itemName.getText().toString().trim().equals("")) { + DialogUtil.builder(NetWorkSet.this, "错误信息", "请填写工程名!", 0); + itemName.requestFocus(); + return; + } + String selectStr = "select col1 from systable where desc='network'"; + Cursor select_cursor = sDatabase.rawQuery(selectStr, null); + String ipValue = ip.getText().toString().trim(); + String portValue = port.getText().toString().trim(); + String itemNameValue = itemName.getText().toString().trim(); + if (select_cursor.moveToFirst()) { + sDatabase.execSQL("update systable set col1='" + ipValue + "',col2='" + portValue + "',col3='" + itemNameValue + "' where desc='network'"); + } else { + sDatabase.execSQL("insert into systable (col1,col2,col3,desc) values('" + ipValue + "','" + portValue + "','" + itemNameValue + "','network')"); + } + select_cursor.close(); + SysData.url = "http://".concat(ipValue).concat(":").concat(portValue).concat("/").concat(itemNameValue); + DialogUtil.builder(NetWorkSet.this, "提示", "设置成功!", 0); + } + + public void onback(View v) { + // Intent intent = this.getIntent(); + // setResult(0, intent); + finish(); + + } + + public void pdaRegister(View v) throws Exception { + String mac = SysData.clientid; + if (mac == null || mac.length() < 1) { + DialogUtil.builder(NetWorkSet.this, "提示", "mac地址为空,请检查网络", 0); + return; + } + HashMap map = new HashMap(); + map.put("mac", mac); + map.put("bz", bz.getText().toString().trim()); + byte[] b = IoUtil.getbyte(map); + String paramString = Base64.encode(b); + new RunYmupThread(paramString, regHandler, "pdaRegister", 0).start(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (db != null) { + db.close(); + sDatabase.close(); + } + } + +} diff --git a/app/src/main/java/com/example/chaoran/ParamActivity.java b/app/src/main/java/com/example/chaoran/ParamActivity.java new file mode 100644 index 0000000..96cb04e --- /dev/null +++ b/app/src/main/java/com/example/chaoran/ParamActivity.java @@ -0,0 +1,111 @@ +package com.example.chaoran; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.chaoran.component.MyAdapter; +import com.chaoran.entiry.DataGrid; +import com.example.chaoran.R; +import com.util.DialogUtil; + +import android.os.Bundle; +import android.app.Activity; +import android.content.Intent; +import android.graphics.Color; +import android.view.KeyEvent; +import android.view.Menu; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.TextView; +import android.widget.AdapterView.OnItemClickListener; + +public class ParamActivity extends Activity { + private ListView listView; + private List listdata; + private TextView tv; + private MyAdapter mxAdapter; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_param); + listView = (ListView) findViewById(R.id.list); + tv = (TextView) findViewById(R.id.tvtitle); + final Intent intent = getIntent(); + DataGrid dg = (DataGrid) intent.getSerializableExtra("dg"); + listdata = dg.getTableData(); + // SimpleAdapter mxAdapter = new SimpleAdapter(this,listdata, + // R.layout.activity_menu, + // new String[] {dg.getTableHead().get(0).get("columnName").toString()}, + // new int[] { R.id.title }); + + mxAdapter = new MyAdapter(this, (ArrayList) listdata, dg.getTableHead() + .get(0).get("columnName").toString()); + tv.setText(dg.getTableHead().get(0).get("columnChineseName").toString()); + listView.setAdapter(mxAdapter); + // listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);// + // 一定要设置这个属性,否则ListView不会刷新 + OnItemClickListener lis1 = new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView arg0, View arg1, int arg2, + long arg3) { + // mxAdapter.cur_pos=arg2; + arg1.setBackgroundColor(Color.GREEN); + Serializable map = (Serializable) listdata.get(arg2); + // Intent int =getIntent(); + // intent.putExtra("param",map); + intent.putExtra("param", map); + intent.putExtra("audioFld", + intent.getSerializableExtra("audioFld")); + setResult(1, intent); + clear(); + } + }; + listView.setOnItemClickListener(lis1); + } + + public void onback(View v) { + clear(); + } + + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking() + && !event.isCanceled()) { + clear(); + return true; + } + if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { + if (mxAdapter.cur_pos < listdata.size()) { + mxAdapter.cur_pos++; + listView.setSelection(mxAdapter.cur_pos); + mxAdapter.notifyDataSetChanged(); + } + } + if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { + if (mxAdapter.cur_pos >0) { + mxAdapter.cur_pos--; + listView.setSelection(mxAdapter.cur_pos); + mxAdapter.notifyDataSetChanged(); + } + } + return super.onKeyUp(keyCode, event); + } + + private void clear() { + listView = null; + tv = null; + if (listdata != null) { + listdata.clear(); + listdata = null; + mxAdapter.clear(); + mxAdapter = null; + } + finish(); + } + +} diff --git a/app/src/main/java/com/example/chaoran/PdaRegActivity.java b/app/src/main/java/com/example/chaoran/PdaRegActivity.java new file mode 100644 index 0000000..0cce99a --- /dev/null +++ b/app/src/main/java/com/example/chaoran/PdaRegActivity.java @@ -0,0 +1,190 @@ +package com.example.chaoran; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + +import com.chaoran.db.SqlHelpUtil; +import com.example.chaoran.R; +import com.sys.SysData; +import com.util.DialogUtil; +import com.util.IoUtil; +import com.util.SysUtil; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.app.Activity; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.view.Menu; +import android.view.View; +import android.widget.EditText; + +public class PdaRegActivity extends Activity { + private EditText ip; + private EditText port; + private EditText itemName; + private SqlHelpUtil db; + private SQLiteDatabase sDatabase; + private Handler handler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + if (msg.what == -1) { + DialogUtil.builder(PdaRegActivity.this, "错误信息", "连接服务器失败,请检查网络!" + + msg.obj,0); + } else if (msg.what == -2) { + DialogUtil.builder(PdaRegActivity.this, "错误信息", "返回值为空!",0); + } else{ + String retunVal=msg.obj.toString(); + if(retunVal.equals("-1")){ + DialogUtil.builder(PdaRegActivity.this, "提示信息", "序列号还未注册!",0); + }else if(!retunVal.equals("Y")){ + DialogUtil.builder(PdaRegActivity.this, "提示信息", "序列号还未启用!",0); + }else{ + DialogUtil.builder(PdaRegActivity.this, "提示信息", "操作成功!",0); + String selectStr = "select col1 from systable where desc='pdaState'"; + Cursor select_cursor = sDatabase.rawQuery(selectStr, null); + if (select_cursor.moveToFirst()) { + sDatabase.execSQL("update systable set col1='Y' where desc='pdaState'"); + } else { + sDatabase + .execSQL("insert into systable (col1,desc) values('Y','pdaState')"); + } + select_cursor.close(); + SysData.isreg="Y"; + } + } + } + }; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_pda_reg); + ip = (EditText) findViewById(R.id.ip); + port = (EditText) findViewById(R.id.port); + itemName = (EditText) findViewById(R.id.itemName); + db = new SqlHelpUtil(getApplicationContext()); + sDatabase = db.getWritableDatabase(); + String selectStr = "select col1,col2,col3 from systable where desc='pdaRegServer'"; + Cursor select_cursor = sDatabase.rawQuery(selectStr, null); + if (select_cursor.moveToFirst()) { + ip.setText(select_cursor.getString(0)); + port.setText(select_cursor.getString(1)); + itemName.setText(select_cursor.getString(2)); + } + select_cursor.close(); + } + + public void onsub(View v) { + if (ip.getText().toString().trim().equals("")) { + DialogUtil.builder(PdaRegActivity.this, "错误信息", "请填写服务器IP!",0); + ip.requestFocus(); + return; + } + if (port.getText().toString().trim().equals("")) { + DialogUtil.builder(PdaRegActivity.this, "错误信息", "请填写服务器端口!",0); + port.requestFocus(); + return; + } + if (itemName.getText().toString().trim().equals("")) { + DialogUtil.builder(PdaRegActivity.this, "错误信息", "请填写工程名!",0); + itemName.requestFocus(); + return; + } + String selectStr = "select col1 from systable where desc='pdaRegServer'"; + Cursor select_cursor = sDatabase.rawQuery(selectStr, null); + String ipValue = ip.getText().toString().trim(); + String portValue = port.getText().toString().trim(); + String itemNameValue = itemName.getText().toString().trim(); + if (select_cursor.moveToFirst()) { + sDatabase.execSQL("update systable set col1='" + ipValue + + "',col2='" + portValue + "',col3='" + itemNameValue + + "' where desc='pdaRegServer'"); + } else { + sDatabase + .execSQL("insert into systable (col1,col2,col3,desc) values('" + + ipValue + + "','" + + portValue + + "','" + + itemNameValue + "','pdaRegServer')"); + } + select_cursor.close(); + SysData.url = "http://".concat(ipValue).concat(":").concat(portValue) + .concat("/").concat(itemNameValue); + DialogUtil.builder(PdaRegActivity.this, "提示", "保存成功,请点下面的PDA注册按钮进行注册!",0); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_pda_reg, menu); + return true; + } + + public void onback(View v) { + finish(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (db != null) { + db.close(); + sDatabase.close(); + } + } + + public void pdaRegister(View v) throws Exception { + String sn = SysUtil.getSn(); + if (sn == null || sn.length() < 1) { + DialogUtil.builder(PdaRegActivity.this, "提示", "序列号为空,请联系供应商",0); + return; + } + new Thread(new PdaRegValidate()).start(); + } + + public class PdaRegValidate implements Runnable { + public void run() { + String ipValue = ip.getText().toString().trim(); + String portValue = port.getText().toString().trim(); + String itemNameValue = itemName.getText().toString().trim(); + String url = "http://".concat(ipValue).concat(":") + .concat(portValue).concat("/").concat(itemNameValue); + url = url + "/webservice/ServiceInterface?wsdl"; + System.out.println(url); + String method = "pdaZcValidate"; + SoapObject rpc = new SoapObject("", method); + System.out.println(SysUtil.getSn()); + rpc.addProperty("sn", SysUtil.getSn()); + try { + HttpTransportSE ht = new HttpTransportSE(url, SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (envelope.getResponse() != null) { + String s=envelope.getResponse().toString(); + Message message = new Message(); + message.obj = s; + handler.sendMessage(message); + }else{ + Message message = new Message(); + message.what = -2; + handler.sendMessage(message); + } + } catch (Exception e) { + e.printStackTrace(); + Message message = new Message(); + message.what = -1; + message.obj = e.toString(); + handler.sendMessage(message); + } + } + } +} diff --git a/app/src/main/java/com/example/chaoran/RunSearchThread.java b/app/src/main/java/com/example/chaoran/RunSearchThread.java new file mode 100644 index 0000000..0398eac --- /dev/null +++ b/app/src/main/java/com/example/chaoran/RunSearchThread.java @@ -0,0 +1,92 @@ +package com.example.chaoran; + +import java.io.ByteArrayInputStream; +import java.io.ObjectInputStream; +import java.util.HashMap; +import java.util.Map; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +import com.chaoran.entiry.DataGrid; +import com.chaoran.entiry.Sys_DanJuFormsOptions; +import com.sys.SysData; +import com.util.IoUtil; + +/*运行检索方案线程*/ +public class RunSearchThread extends Thread { + private String sql; + private String param; + private Handler handler; + private String return_one;// 是否单行返回 + private String audioFld;// 声音播放字段 + + public RunSearchThread(String sql, String param, Handler handler, + String return_one, String audioFld) { + this.sql = sql; + this.param = param; + this.handler = handler; + this.return_one = return_one; + this.audioFld = audioFld; + } + + public RunSearchThread(String sql, String param, Handler handler) { + this.sql = sql; + this.param = param; + this.handler = handler; + } + + public void run() { + super.run(); + Log.v("RunSearchThread", "run执行"); + try { + String url = SysData.url + "/webservice/ServiceInterface?wsdl"; + String method = "runSearch"; + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("sql", sql); + rpc.addProperty("base64Param", param); + HttpTransportSE ht = new HttpTransportSE(url,SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + byte[] bb = org.kobjects.base64.Base64.decode(envelope + .getResponse().toString()); + Object ob = IoUtil.byte_obj(bb); + if (ob instanceof DataGrid) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + DataGrid dg = (DataGrid) ob; + Map map = new HashMap(); + if (return_one != null) { + map.put("return_one", return_one); + } + if (audioFld != null) { + map.put("audioFld", audioFld); + } + map.put("dg", dg); + Message msg = new Message(); + msg.obj = map; + msg.arg1 = 1; + handler.sendMessage(msg); + } else { + Message msg = new Message(); + msg.obj = ob.toString(); + msg.what = -1; + handler.sendMessage(msg); + } + } catch (Exception e) { + Message msg = new Message(); + msg.what = -1; + msg.obj = e.toString(); + handler.sendMessage(msg); + } + } +} diff --git a/app/src/main/java/com/example/chaoran/RunYmupThread.java b/app/src/main/java/com/example/chaoran/RunYmupThread.java new file mode 100644 index 0000000..32c5eba --- /dev/null +++ b/app/src/main/java/com/example/chaoran/RunYmupThread.java @@ -0,0 +1,102 @@ +package com.example.chaoran; + +import java.util.HashMap; +import java.util.Map; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; + +import com.chaoran.entiry.DataGrid; +import com.sys.SysData; +import com.util.IoUtil; + +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +public class RunYmupThread extends Thread { + private String param; + private Handler handler; + private String methodName; + private int urlTy;// 0表示访问ServiceInterface,1表示访问offLineInventoryInterface + + public RunYmupThread(String param, Handler handler, String methodName, + int urlTy) { + this.param = param; + this.handler = handler; + this.methodName = methodName; + this.urlTy = urlTy; + } + + public void run() { + super.run(); + Log.v("SearchThread", "run执行"); + try { + String url = null; + if (urlTy == 0) { + url = SysData.url + "/webservice/ServiceInterface?wsdl"; + } else if (urlTy == 1) { + url = SysData.url + + "/webservice/offLineInventoryInterface?wsdl"; + } + String method = methodName; + SoapObject rpc = new SoapObject("", method); + if (param != null) { + rpc.addProperty("param", param); + } + HttpTransportSE ht = new HttpTransportSE(url, SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (envelope.getResponse() != null) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + // byte[] bb = org.kobjects.base64.Base64.decode(envelope + // .getResponse().toString()); + // Map map= (Map)IoUtil.byte_obj(bb); + // Message msg = new Message(); + // msg.obj = map; + // msg.arg1=2; + // handler.sendMessage(msg); + Message msg = new Message(); + if (methodName.equals("saveDj")) { + msg.arg1 = 3; + msg.obj = envelope.getResponse().toString(); + } else if (methodName.equals("pdaRegister")) { + msg.obj = envelope.getResponse().toString(); + } else { + byte[] bb = org.kobjects.base64.Base64.decode(envelope + .getResponse().toString()); + msg.obj = IoUtil.byte_obj(bb); + if (methodName.equals("runYmup")) { + msg.arg1 = 2; + } else if (methodName.equals("runTqfa")) { + msg.arg1 = 4; + } + } + handler.sendMessage(msg); + } else { + Message msg = new Message(); + msg.obj = null; + handler.sendMessage(msg); + } + } catch (Exception e) { + Message msg = new Message(); + if (methodName.equals("runYmup")) { + msg.what = -2; + } else if (methodName.equals("saveDj")) { + msg.what = -3; + } else if (methodName.equals("runTqfa")) { + msg.what = -4; + }else{ + msg.what = -1; + } + msg.obj = e.toString(); + handler.sendMessage(msg); + } + } +} diff --git a/app/src/main/java/com/example/chaoran/SearchThread.java b/app/src/main/java/com/example/chaoran/SearchThread.java new file mode 100644 index 0000000..2b6bd7b --- /dev/null +++ b/app/src/main/java/com/example/chaoran/SearchThread.java @@ -0,0 +1,66 @@ +package com.example.chaoran; + +import org.ksoap2.SoapEnvelope; +import org.ksoap2.serialization.SoapObject; +import org.ksoap2.serialization.SoapSerializationEnvelope; +import org.ksoap2.transport.HttpTransportSE; +import com.sys.SysData; + +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +public class SearchThread extends Thread { + private String fangalx; + private String functionname; + private Handler handler; + private int type;// 0 表示检索方案 1表示 页面修改方案,2表示提取方案 + + public SearchThread(String fangalx, String functionname, Handler handler, + int type) { + this.fangalx = fangalx; + this.functionname = functionname; + this.handler = handler; + this.type = type; + } + + public void run() { + super.run(); + Log.v("SearchThread", "run执行"); + try { + String url = SysData.url + + "/webservice/ServiceInterface?wsdl"; + String method = null; + if (type == 0) { + method = "queryZdysql"; + } else if(type==1) { + method = "selectYmupSql"; + }else if(type==2) { + method = "selectDjtqFun"; + } + SoapObject rpc = new SoapObject("", method); + rpc.addProperty("fangalx", fangalx); + rpc.addProperty("functionname", functionname); + HttpTransportSE ht = new HttpTransportSE(url,SysData.timeout); + ht.debug = true; + SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( + SoapEnvelope.VER11); + envelope.bodyOut = rpc; + envelope.dotNet = true; + envelope.setOutputSoapObject(rpc); + ht.call("", envelope); + if (envelope.getResponse() != null) {// 判断是否返回结果,因为我这个是一个查询操作,是带有返回值的。 + Message msg = new Message(); + msg.obj = org.kobjects.base64.Base64.decode(envelope + .getResponse().toString()); + msg.arg1 = type; + handler.sendMessage(msg); + } + } catch (Exception e) { + Message msg = new Message(); + msg.what = -1; + msg.obj = e.toString(); + handler.sendMessage(msg); + } + } +} diff --git a/app/src/main/java/com/example/chaoran/UpdatePwdActivity.java b/app/src/main/java/com/example/chaoran/UpdatePwdActivity.java new file mode 100644 index 0000000..5a9b47d --- /dev/null +++ b/app/src/main/java/com/example/chaoran/UpdatePwdActivity.java @@ -0,0 +1,92 @@ +package com.example.chaoran; + +import java.io.File; + +import org.ksoap2.serialization.SoapObject; + +import com.chaoran.entiry.UpdataInfo; +import com.chaoran.thread.UpdatePwdThread; +import com.example.chaoran.R; +import com.sys.SysData; +import com.util.DialogUtil; +import com.util.InstallUtil; + +import android.R.color; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Intent; +import android.graphics.Color; +import android.view.Menu; +import android.view.View; +import android.widget.EditText; + +public class UpdatePwdActivity extends Activity { + private EditText newPwd; + private EditText CfNewPwd; + public ProgressDialog pd; + private Handler handler = new Handler() { + @Override + // 当有消息发送出来的时候就执行Handler的这个方法 + public void handleMessage(Message msg) { + if (pd != null) { + pd.dismiss(); + } + if (msg.what == -1) { + DialogUtil.builder(UpdatePwdActivity.this, "错误信息", msg.obj.toString(),0); + }else{ + if(msg.obj.equals("0")){ + DialogUtil.builder(UpdatePwdActivity.this, "提示信息","修改密码成功",0); + }else{ + DialogUtil.builder(UpdatePwdActivity.this, "错误信息","修改密码失败".concat( msg.obj.toString()),0); + } + + } + } + + }; + + @Override + public void onCreate(Bundle savedInstaneceState) { + super.onCreate(savedInstaneceState); + setContentView(R.layout.activity_update_pwd); + ((EditText)findViewById(R.id.name)).setText(SysData.lgnname); + newPwd=(EditText)findViewById(R.id.newpwd); + CfNewPwd=(EditText)findViewById(R.id.cfnewpwd); + newPwd.requestFocus(); + } + public void onsub(View v) { + String newPwdValue=newPwd.getText().toString().trim(); + if(newPwdValue.equals("")){ + DialogUtil.builder(this, "错误信息", "请填写新密码!",0); + newPwd.requestFocus(); + return; + } + String CfNewPwdValue=CfNewPwd.getText().toString().trim(); + if(CfNewPwdValue.equals("")){ + DialogUtil.builder(this, "错误信息", "请填写重复密码!",0); + CfNewPwd.requestFocus(); + return; + } + if(!CfNewPwdValue.equals(newPwdValue)){ + DialogUtil.builder(this, "错误信息", "新密码和重复密码不一致!",0); + newPwd.requestFocus(); + return; + } + if (pd == null) { + pd = ProgressDialog.show(this, "提示", "正在操作……"); + } else { + DialogUtil.setDialog(pd, "提示", "正在操作……"); + } + new Thread(new UpdatePwdThread(handler,SysData.userid,newPwdValue)).start(); + } + protected void onDestroy() { + super.onDestroy(); + if (pd != null) { + pd=null; + } + handler=null; + } +} diff --git a/app/src/main/java/com/jiebao/h518/scan/BeepManager.java b/app/src/main/java/com/jiebao/h518/scan/BeepManager.java new file mode 100644 index 0000000..7791cf9 --- /dev/null +++ b/app/src/main/java/com/jiebao/h518/scan/BeepManager.java @@ -0,0 +1,109 @@ +package com.jiebao.h518.scan; + +import android.app.Activity; +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.os.Vibrator; +import android.util.Log; + +import java.io.IOException; + +import com.example.chaoran.R; + + + + + +public final class BeepManager { + + private static final String TAG = BeepManager.class.getSimpleName(); + + private static final float BEEP_VOLUME = 0.3f; + private static final long VIBRATE_DURATION = 200L; + + private final Activity activity; + private MediaPlayer mediaPlayer; + private boolean playBeep = true; + private boolean vibrate = false; + + public BeepManager(Activity activity) { + this.activity = activity; + initMediaPlayer(); + } + + public boolean isPlayBeep() { + return playBeep; + } + + public void setPlayBeep(boolean playBeep) { + this.playBeep = playBeep; + } + + public boolean isVibrate() { + return vibrate; + } + public void turnOffV(){ + mediaPlayer.setVolume(0, 0); + } + public void turnOnV(){ + mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); + } + public void setVibrate(boolean vibrate) { + this.vibrate = vibrate; + } + + void initMediaPlayer() { + activity.setVolumeControlStream(AudioManager.STREAM_MUSIC); + mediaPlayer = buildMediaPlayer(activity); + } + + public void playBeepSoundAndVibrate() { + if (playBeep && mediaPlayer != null) { + + mediaPlayer.start(); + } + if (vibrate) { + Vibrator vibrator = (Vibrator) activity + .getSystemService(Context.VIBRATOR_SERVICE); + vibrator.vibrate(VIBRATE_DURATION); + } + } + public void release(){ + if(mediaPlayer != null) + mediaPlayer.stop(); + mediaPlayer.release(); + mediaPlayer = null; + } + + private MediaPlayer buildMediaPlayer(Context activity) { + + + MediaPlayer mediaPlayer = new MediaPlayer(); + mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + + mediaPlayer + .setOnCompletionListener(new MediaPlayer.OnCompletionListener() { + public void onCompletion(MediaPlayer player) { + player.seekTo(0); + } + }); + + AssetFileDescriptor file = activity.getResources().openRawResourceFd( + R.raw.beep); + try { + mediaPlayer.setDataSource(file.getFileDescriptor(), + file.getStartOffset(), file.getLength()); + file.close(); + mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); + mediaPlayer.prepare(); + } catch (IOException ioe) { + Log.w(TAG, ioe); + mediaPlayer = null; + } + return mediaPlayer; + } + + +} diff --git a/app/src/main/java/com/jiebao/h518/scan/DiemensionalCodeControler.java b/app/src/main/java/com/jiebao/h518/scan/DiemensionalCodeControler.java new file mode 100644 index 0000000..83ce0f6 --- /dev/null +++ b/app/src/main/java/com/jiebao/h518/scan/DiemensionalCodeControler.java @@ -0,0 +1,290 @@ +package com.jiebao.h518.scan; + + +import com.jiebao.h518.scan.BeepManager; +import com.motorolasolutions.adc.decoder.BarCodeReader; + +import android.app.Activity; +import android.content.Context; +import android.media.AudioManager; +import android.media.SoundPool; +import android.media.ToneGenerator; +import android.util.Log; +import android.widget.SlidingDrawer; + + +public class DiemensionalCodeControler implements BarCodeReader.DecodeCallback { + public interface DiemensionalScanListener{ + public void onDiemensionalScanComplete(String result,String error); + } + static final int STATE_IDLE = 0; + static final int STATE_DECODE = 1; + static final int STATE_HANDSFREE = 2; + //static final int STATE_PREVIEW = 3; // snapshot preview mode + //static final int STATE_SNAPSHOT = 4; + //static final int STATE_VIDEO = 5; + private BarCodeReader bcr; +// private SqliteService sqlite; + private Activity context; + //private ToneGenerator tg = null; + //private SoundPool soundpool = null; + private int trigMode = BarCodeReader.ParamVal.LEVEL; + private int state = STATE_IDLE; + private int soundid; + private BeepManager beepManager; + private DiemensionalScanListener scanListener; + private static DiemensionalCodeControler controler; + static { + System.loadLibrary("IAL"); + System.loadLibrary("SDL"); + System.loadLibrary("barcodereader"); + } + + private DiemensionalCodeControler(Activity context,DiemensionalScanListener scanListener) { + open(); + this.context=context; + this.scanListener=scanListener; +// sqlite = new SqliteService(context); +// if(sqlite.getCount() == 0){ +// sqlite.initCodeTpye(); +// } + beepManager=new BeepManager(context); + + } + /** + * 在程序退出时调用 + */ + public static void setDiemensionalConNull(){ + if(controler!=null){ + controler.setIdle(); + controler.release(); + controler=null; + } + } + public static DiemensionalCodeControler getCodeControler(Activity context,DiemensionalScanListener scanListener) { + if (controler == null) { + controler = new DiemensionalCodeControler(context,scanListener); + } + return controler; + } + private void beep() { + playSound(); + } + private synchronized void playSound() { + + beepManager.playBeepSoundAndVibrate(); + + + } + public void open() { + + + if (bcr == null) { + try { + bcr = BarCodeReader.open(1); + if(bcr!=null) + bcr.setDecodeCallback(this); + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + throw new RuntimeException("device open failed"); + } + } + + } + + private void release() { + try { + if(beepManager!=null)beepManager.release(); + beepManager=null; + if (bcr != null) + bcr.release(); + bcr = null; + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + + } + private int doSetParam(BarCodeReader bcr,int num, int val) { + String s = ""; + + int ret = bcr.setParameter(num, val); + if (ret != BarCodeReader.BCR_ERROR) { + if (num == BarCodeReader.ParamNum.PRIM_TRIG_MODE) { + trigMode = val; + if (val == BarCodeReader.ParamVal.HANDSFREE) { + s = "HandsFree"; + } else if (val == BarCodeReader.ParamVal.AUTO_AIM) { + s = "AutoAim"; + ret = bcr + .startHandsFreeDecode(BarCodeReader.ParamVal.AUTO_AIM); + if (ret != BarCodeReader.BCR_SUCCESS) { + //dspErr("AUtoAIm start FAILED"); + } + } else if (val == BarCodeReader.ParamVal.LEVEL) { + s = "Level"; + } + } else if (num == BarCodeReader.ParamNum.IMG_VIDEOVF) { + //if (snapPreview = (val == 1)) + // s = "SnapPreview"; + } + } else{ + s = " FAILED (" + ret + ")"; + } + //dspStat(": Set #" + num + " to " + val + " " + s); + return ret; + } + private int setIdle() { + int prevState = state; + int ret = prevState; // for states taking time to chg/end + + state = STATE_IDLE; + switch (prevState) { + case STATE_HANDSFREE: //当前状态为自动扫描 + resetTrigger(); //取消自动扫描 + break; + case STATE_DECODE: //当前状态了正在扫描 + //dspStat("decode stopped"); + bcr.stopDecode(); //取消扫描 + break; + default: + ret = STATE_IDLE; + } + return ret; + } + private void resetTrigger() { + doSetParam(bcr,BarCodeReader.ParamNum.PRIM_TRIG_MODE, + BarCodeReader.ParamVal.LEVEL); + trigMode = BarCodeReader.ParamVal.LEVEL; + } + /** + * 启动连续扫描 + * @return + */ + public boolean doHandsFree(){ + System.out.println("长按----------------------------------------"); + if (setIdle() != STATE_IDLE) + return false; + + int ret = bcr.startHandsFreeDecode(BarCodeReader.ParamVal.HANDSFREE); + System.out.println("长按----------------------------------------"); + //判断返回值ret 若不等于0 启动连续扫描失败 + if (ret != BarCodeReader.BCR_SUCCESS){ + return false; + //dspStat("startHandFree FAILED"); + }else { + trigMode = BarCodeReader.ParamVal.HANDSFREE; + state = STATE_HANDSFREE; //状态为连续扫描 + return true; + //dspStat("HandsFree decoding"); + } + } + private boolean doDecode() { + if (setIdle() != STATE_IDLE) + return false; + + state = STATE_DECODE; + //dspData(""); + // dspStat(R.string.decoding); + bcr.startDecode(); // start decode (callback gets results) + return true; + } + /** + * 启动一次性扫描 + * @return + */ + public boolean start(){ + doSetParam(bcr,298, 1); + doSetParam(bcr,306, 1); + return doDecode(); + } + /** + * 停止扫描,适应一次或连续 + */ + public void stop(){ + if(state==STATE_DECODE)bcr.stopDecode(); + if(state==STATE_HANDSFREE)resetTrigger(); + state=STATE_IDLE; + } + public void onDecodeComplete(int symbology, int length, byte[] data, + BarCodeReader reader) { + // TODO Auto-generated method stub + if(state == STATE_DECODE){ + stop(); + } + if (length > 0) { + + //if (isHandsFree() == false && isAutoAim() == false) + //bcr.stopDecode(); + + + if (symbology == 0x99) // type 99? + { + symbology = data[0]; + int n = data[1]; + int s = 2; + int d = 0; + int len = 0; + byte d99[] = new byte[data.length]; + for (int i = 0; i < n; ++i) { + s += 2; + len = data[s++]; + System.arraycopy(data, s, d99, d, len); + s += len; + d += len; + } + d99[d] = 0; + data = d99; + } +// String codeType = sqlite.searchCode(symbology); +// if(codeType == null || codeType.equals("") ){//未知条码 类型 +// //dspStat("[" + decodes + "] type: " + "unknown type" + " len: " + length); +// scanListener.onDiemensionalScanComplete(null, "未知条码类型"); +// return; +// }else{ +// //dspStat("[" + decodes + "] type: " + codeType + " len: " + length); +// } + // dspData(byte2hex(data)); + try{ + String Result = new String(data,"GB2312"); + scanListener.onDiemensionalScanComplete(Result, null); + //dspData(isSettingCode(SDLguiActivity.this,Result)); + + }catch(Exception e){ + Log.i("info", "excption == "+e.getMessage()); + scanListener.onDiemensionalScanComplete(null, "转码错误"); + } + beep(); + } else // no-decode + { + //dspData(""); + //根据length来判断当前状态 + switch (length) { + + case BarCodeReader.DECODE_STATUS_TIMEOUT: //解码超时, 在指定的时间内没有扫到码 + //dspStat("decode timed out"); + scanListener.onDiemensionalScanComplete(null, "解码超时"); + break; + + case BarCodeReader.DECODE_STATUS_CANCELED: //取消扫描 + //dspStat("decode cancelled"); + scanListener.onDiemensionalScanComplete(null, "取消扫描"); + break; + + case BarCodeReader.DECODE_STATUS_ERROR: //扫描出错 + default: + // dspStat("decode failed"); + scanListener.onDiemensionalScanComplete(null, "扫描出错"); + break; + } + } + + } + + public void onEvent(int event, int info, byte[] data, BarCodeReader reader) { + // TODO Auto-generated method stub + + } + +} diff --git a/app/src/main/java/com/jiebao/h518/scan/NewScanControler.java b/app/src/main/java/com/jiebao/h518/scan/NewScanControler.java new file mode 100644 index 0000000..0b80745 --- /dev/null +++ b/app/src/main/java/com/jiebao/h518/scan/NewScanControler.java @@ -0,0 +1,90 @@ +package com.jiebao.h518.scan; + +import android.gpio.GpioJNI; +import android.util.Log; +import android_serialport_api.SerialPort; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class NewScanControler { + protected SerialPort mSerialPort; + protected OutputStream mOutputStream; + private InputStream mInputStream; + + public NewScanControler() throws SecurityException, IOException { + mSerialPort = new SerialPort(new File("/dev/ttySAC1"), 9600, 8, 'N', 1, + 0); + mOutputStream = mSerialPort.getOutputStream(); + mInputStream = mSerialPort.getInputStream(); + } + + public void close() { + + mSerialPort.close(); + } + + public String getData() { + int size; + try { + if (mInputStream == null) { + return ""; + } + int cout = mInputStream.available(); + byte[] buffer1 = new byte[cout]; + + cout = 0; + buffer1 = null; + + cout = mInputStream.available(); + buffer1 = new byte[cout]; + + size = mInputStream.read(buffer1); + if (size > 0) { + String data = new String(buffer1); + return data; + } + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + return ""; + } + + public void initScan() { + GpioJNI.gpio_switch_scan_rf_ired(0); + GpioJNI.gpio_switch_scan_power(1); + } + + public void stopScan() { + GpioJNI.gpio_switch_scan_trig(0); + + } + + public void scanOnce() { + int triggerVal = GpioJNI.gpio_get_scan_trig(); + if (triggerVal == 1) { + GpioJNI.gpio_switch_scan_trig(0); + } else { + // checkIsSleep(); + GpioJNI.gpio_switch_scan_trig(1); + } +// Log.i("info", "-----"); + } + + void checkIsSleep() { + int triggerVal = GpioJNI.gpio_get_scan_trig(); + if (triggerVal == 1) { + Log.i("info", "+++++"); + GpioJNI.gpio_switch_scan_trig(0); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } +} diff --git a/app/src/main/java/com/jiebao/h518/scan/SqliteConnect.java b/app/src/main/java/com/jiebao/h518/scan/SqliteConnect.java new file mode 100644 index 0000000..52d42d1 --- /dev/null +++ b/app/src/main/java/com/jiebao/h518/scan/SqliteConnect.java @@ -0,0 +1,144 @@ +package com.jiebao.h518.scan; + +import android.content.ContentValues; +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class SqliteConnect extends SQLiteOpenHelper { + private static final String DATABASENAME = "h518.db"; + private static final int DATABASEVERSION = 1; + + public static final String TN_Account = "acount"; + public static final String Account_C_Name = "name"; + public static final String Account_C_Pwd = "pwd"; + + public static final String TN_Goods = "goods"; + public static final String Goods_C_BarCode = "barcode"; + public static final String Goods_C_Id = "goods_Id"; + public static final String Goods_C_Name = "name"; + public static final String Goods_C_Name_PinYin = "name_pinyin"; + public static final String Goods_C_ProducingArea = "producing_area"; + public static final String Goods_C_Standard = "standard"; + public static final String Goods_C_Unit = "unit"; + public static final String Goods_C_BroughtPrice = "brought_price"; + public static final String Goods_C_SellPrice = "sell_price"; + + public static final String TN_Order = "order_msg"; + public static final String Order_C_Id = "order_id"; + public static final String Order_C_Barcode = "barcode"; + public static final String Order_C_per_price = "per_price"; + public static final String Order_C_total_price = "total_price"; + public static final String Order_C_remark = "remark"; + public static final String Order_C_Count = "count"; + + public static final String TN_Order_Details = "order_details"; + public static final String OrderD_C_Id = "order_id"; + public static final String OrderD_C_OrderDate = "order_date"; + public static final String OrderD_C_Operator = "operator"; + public static final String OrderD_C_remark = "remark"; + public static final String OrderD_C_total_price = "total_price"; + + public static final String TN_PSOrder = "psorder_msg"; + public static final String PSOrder_C_Id = "order_id"; + public static final String PSOrder_C_date = "order_date"; + public static final String PSOrder_C_shop_Id = "shop_id"; + public static final String PSOrder_C_remark = "remark"; + + public static final String TN_PSOrderGoods = "psordergoods_msg"; + public static final String PSOrderGoods_c_Id = "order_id"; + public static final String PSOrderGoods_c_Barcode = "barcode"; + public static final String PSOrderGoods_c_count = "count"; + public static final String PSOrderGoods_c_per_price = "per_price"; + public static final String PSOrderGoods_c_total_price = "total_price"; + public static final String PSOrderGoods_c_remark = "remark"; + + public static final String TN_GoodsSold = "goods_sold"; + public static final String GoodsSold_C_Order_Id = "order_id"; + public static final String GoodsSold_C_Goods_Id = "goods_id"; + public static final String GoodsSold_C_Barcode = "barcode"; + public static final String GoodsSold_C_Count = "count"; + public static final String GoodsSold_C_totalPrice = "total_price"; + + public SqliteConnect(Context context) { + super(context, DATABASENAME, null, DATABASEVERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + + try { + db.execSQL("CREATE TABLE if not exists " + TN_Account + + "(id integer primary key autoincrement," + "" + + Account_C_Name + " text," + Account_C_Pwd + " text)"); + ContentValues values = new ContentValues(); + values.put(Account_C_Name, "5180000010"); + values.put(Account_C_Pwd, "123"); + db.insert(TN_Account, null, values); + + db.execSQL("create table if not exists " + TN_Goods + + "(id integer primary key autoincrement," + Goods_C_BarCode + + " text," + Goods_C_BroughtPrice + " text," + Goods_C_Id + + " text," + Goods_C_Name + " text," + Goods_C_Name_PinYin + + " text," + Goods_C_ProducingArea + " text," + + Goods_C_SellPrice + " double," + Goods_C_Standard + " text," + + Goods_C_Unit + ")"); + db.execSQL("CREATE TABLE if not exists " + TN_Order + + "(id integer primary key autoincrement," + "" + Order_C_Barcode + + " text," + Order_C_Count + " long," + Order_C_Id + " text," + + Order_C_per_price + " double," + Order_C_remark + " text," + + Order_C_total_price + " double)"); + db.execSQL("create table if not exists " + TN_Order_Details + + "(id integer primary key autoincrement," + OrderD_C_Id + + " text," + OrderD_C_Operator + " text," + OrderD_C_OrderDate + + " datetime," + OrderD_C_remark + " text," + + OrderD_C_total_price + " double)"); + db.execSQL("create table if not exists " + TN_PSOrder + "(" + + PSOrder_C_date + " datetime," + PSOrder_C_Id + " text," + + PSOrder_C_remark + " text," + PSOrder_C_shop_Id + " text)"); + db.execSQL("create table if not exists " + TN_PSOrderGoods + "(" + + PSOrderGoods_c_count + " long," + PSOrderGoods_c_Barcode + + " text," + PSOrderGoods_c_Id + " text," + + PSOrderGoods_c_per_price + " double," + PSOrderGoods_c_remark + + " text," + PSOrderGoods_c_total_price + " double)"); + db.execSQL("create table if not exists " + TN_GoodsSold + "(" + + GoodsSold_C_Barcode + " text," + GoodsSold_C_Count + " long," + + GoodsSold_C_Goods_Id + " text," + GoodsSold_C_Order_Id + + " text," + GoodsSold_C_totalPrice + " double)"); + + db.execSQL("CREATE TABLE if not exists CodeType(id integer primary key autoincrement," + + "type_name text,type_id integer)" ); + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + + + + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("DROP TABLE IF EXISTS " + TN_Account); + db.execSQL("DROP TABLE IF EXISTS " + TN_Goods); + db.execSQL("DROP TABLE IF EXISTS " + TN_Order); + db.execSQL("drop table if exists " + TN_Order_Details); + db.execSQL("drop table if exists " + TN_PSOrder); + db.execSQL("drop table if exists " + TN_PSOrderGoods); + db.execSQL("drop table if exists " + TN_GoodsSold); + db.execSQL("DROP TABLE IF EXISTS CodeType"); + onCreate(db); + } + + public void clearAllMsgButAccount(SQLiteDatabase db) { + db.execSQL("DROP TABLE IF EXISTS " + TN_Goods); + db.execSQL("DROP TABLE IF EXISTS " + TN_Order); + db.execSQL("drop table if exists " + TN_Order_Details); + db.execSQL("drop table if exists " + TN_PSOrder); + db.execSQL("drop table if exists " + TN_PSOrderGoods); + db.execSQL("drop table if exists " + TN_GoodsSold); + onCreate(db); + } + + +} diff --git a/app/src/main/java/com/jiebao/h518/scan/SqliteService.java b/app/src/main/java/com/jiebao/h518/scan/SqliteService.java new file mode 100644 index 0000000..42cb092 --- /dev/null +++ b/app/src/main/java/com/jiebao/h518/scan/SqliteService.java @@ -0,0 +1,276 @@ +package com.jiebao.h518.scan; + +import java.util.ArrayList; +import java.util.List; + + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +public class SqliteService { + private SqliteConnect sqlCon; + + public SqliteService(Context context){ + if(this.sqlCon == null){ + sqlCon = new SqliteConnect(context); + } + } + + public synchronized String searchCode(int codeID){ + SQLiteDatabase db = sqlCon.getReadableDatabase(); + String sql = "select * from CodeType where type_id = "+codeID; + Cursor cursor = db.rawQuery(sql,new String[]{}); + String typeName = ""; + while(cursor.moveToNext()){ + typeName = cursor.getString(1); + } + db.close(); + return typeName; + } + + + public synchronized void initCodeTpye() + { + SQLiteDatabase db = sqlCon.getWritableDatabase(); + db.beginTransaction(); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 39',1)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Codabar',2)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 128',3)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Discrete (Standard) 2 of 5',4)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('IATA',5)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Interleaved 2 of 5',6)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 93',7)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-A',8)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-E0',9)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-8',10)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-13',11)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 11',12)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 49',13)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('MSI',14)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-128',15)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-E1',16)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('PDF-417',17)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 16K',18)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 39 Full ASCII',19)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-D',20)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 39 Trioptic',21)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Bookland',22)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Coupon Code',23)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('NW-7',24)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('ISBT-128',25)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Micro PDF',26)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('DataMatrix',27)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('QR Code',28)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Micro PDF CCA',29)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('PostNet US',30)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Planet Code',31)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Code 32',32)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('ISBT-128 Con',33)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Japan Postal',34)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Australian Postal',35)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Dutch Postal',36)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('MaxiCode',37)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Canadian Postal',38)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UK Postal',39)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Macro PDF',40)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Macro QR',41)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Micro QR',44)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Aztec',45)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Aztec Rune',46)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('GS1 DataBar-14',48)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('GS1 DataBar Limited',49)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('GS1 DataBar Expanded',50)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('USPS 4CB',52)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPU 4State',53)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('ISSN',54)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Scanlet',55)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CueCode',56)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Matrix 2 of 5',57)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-A + 2 Supplemental',72)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-E0 + 2 Supplemental',73)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-8 + 2 Supplemental',74)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-13 + 2 Supplemental',75)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-E1 + 2 Supplemental',80)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA EAN-13',82)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA EAN-8',83)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA GS1 DataBar Expanded',84)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA GS1 DataBar Limited',85)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA GS1 DataBar-14',86)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA UPC-A',87)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCA UPC-E',88)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCC EAN-128',89)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('TLC-39',90)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB EAN-128',97)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB EAN-13',98)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB EAN-8',99)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB GS1 DataBar Expanded',100)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB GS1 DataBar Limited',101)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB GS1 DataBar-14',102)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB UPC-A',103)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('CCB UPC-E',104)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Signature Capture',105)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Chinese 2 of 5',114)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Korean 3 of 5',115)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-A + 5 supplemental',136)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-E0 + 5 supplemental',137)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-8 + 5 supplemental',138)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('EAN-13 + 5 supplemental',139)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('UPC-E1 + 5 Supplemental',144)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('Macro Micro PDF',154)"); + db.execSQL("insert into CodeType(type_name,type_id)" + +"values('GS1 Databar Coupon',180)"); + db.setTransactionSuccessful(); + db.endTransaction(); + db.close(); + } +// public synchronized void saveResult(List scanUntil){ +// SQLiteDatabase db = sqlCon.getWritableDatabase(); +// +// for(int i=0;i readResult(){ +// SQLiteDatabase db = sqlCon.getReadableDatabase(); +// Cursor cur = db.rawQuery("select * from scan_result order by id desc", new String[]{}); +// List list = new ArrayList(); +// ScanUntil until; +// while(cur.moveToNext()){ +// until = new ScanUntil(); +// until.setScanResult(cur.getString(1)); +// until.setScanDate(cur.getString(2)); +// list.add(until); +// } +// db.close(); +// return list; +// } + + public synchronized int getCount(){ + SQLiteDatabase db = sqlCon.getReadableDatabase(); + String sql = "select count(id) from CodeType "; + Cursor cur = db.rawQuery(sql, new String[]{}); + + int sum = 0; + while (cur.moveToNext()) { + sum = cur.getInt(0); + } + Log.i("info", "sum == "+sum); + return sum; + } + /** + * @param pagesize 每页的记录数 + * @param count 总记录数 + * @return 总页�? + */ + public static int computeTotalPagesBasedOnCount(int pagesize, int count) { + if (pagesize <= 0 || count <= 0) + return -1; // �?��数不可能小于或等�? 或�?总数也不能小于或者等�?0,否则返�?1 + int x = count / pagesize + 1; // 不满�?��,也进位 + return x; + } + +// public synchronized List fenye(int i){ +// SQLiteDatabase db = sqlCon.getReadableDatabase(); +// String sql = "select * from scan_result order by id desc limit 100 offset "+ i*100; +// Cursor cur = db.rawQuery(sql, new String[]{}); +// List list = new ArrayList(); +// ScanUntil until; +// while(cur.moveToNext()){ +// until = new ScanUntil(); +// until.setScanResult(cur.getString(1)); +// until.setScanDate(cur.getString(2)); +// list.add(until); +// } +// db.close(); +// Log.i("info", "分页数量 == "+list.size()); +// return list; +// } +} diff --git a/app/src/main/java/com/lianxin/nr510/Engine.java b/app/src/main/java/com/lianxin/nr510/Engine.java new file mode 100644 index 0000000..64fe5e1 --- /dev/null +++ b/app/src/main/java/com/lianxin/nr510/Engine.java @@ -0,0 +1,64 @@ +package com.lianxin.nr510; + +import android.content.Context; +import android.content.Intent; + +public class Engine { + + private NR510Running runEngine = null; + + public void start(Context context) { + if (runEngine == null) { + runEngine = new NR510Running(context); + new Thread(runEngine).start(); + } + } + + public void stop(Context context) { + if (runEngine != null) { + Intent intent = new Intent("com.lachesis.barcode.STOP_BARCODE"); + context.sendBroadcast(intent); + runEngine.closeRunning(); + runEngine = null; + } + } + + private class NR510Running implements Runnable { + + private boolean scanRunning = true; + private Context context; + + public NR510Running(Context context) { + this.context = context; + } + + public void closeRunning() { + scanRunning = false; + } + + @Override + public void run() { + while (true) { + if (scanRunning) { + Intent intent = new Intent("com.lachesis.barcode.START_BARCODE"); + context.sendBroadcast(intent); + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + intent = new Intent("com.lachesis.barcode.STOP_BARCODE"); + context.sendBroadcast(intent); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else + break; + } + } + + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/camera/AutoFocusCallback.java b/app/src/main/java/com/mining/app/zxing/camera/AutoFocusCallback.java new file mode 100644 index 0000000..e8db1b0 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/camera/AutoFocusCallback.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.camera; + +import android.hardware.Camera; +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +final class AutoFocusCallback implements Camera.AutoFocusCallback { + + private static final String TAG = AutoFocusCallback.class.getSimpleName(); + + private static final long AUTOFOCUS_INTERVAL_MS = 1500L; + + private Handler autoFocusHandler; + private int autoFocusMessage; + + void setHandler(Handler autoFocusHandler, int autoFocusMessage) { + this.autoFocusHandler = autoFocusHandler; + this.autoFocusMessage = autoFocusMessage; + } + + public void onAutoFocus(boolean success, Camera camera) { + if (autoFocusHandler != null) { + Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success); + autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS); + autoFocusHandler = null; + } else { + Log.d(TAG, "Got auto-focus callback, but no handler for it"); + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/camera/CameraConfigurationManager.java b/app/src/main/java/com/mining/app/zxing/camera/CameraConfigurationManager.java new file mode 100644 index 0000000..2acc6ea --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/camera/CameraConfigurationManager.java @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.camera; + +import android.content.Context; +import android.graphics.Point; +import android.hardware.Camera; +import android.os.Build; +import android.util.Log; +import android.view.Display; +import android.view.WindowManager; + +import java.lang.reflect.Method; +import java.util.regex.Pattern; + +final class CameraConfigurationManager { + + private static final String TAG = CameraConfigurationManager.class.getSimpleName(); + + private static final int TEN_DESIRED_ZOOM = 27; + private static final int DESIRED_SHARPNESS = 30; + + private static final Pattern COMMA_PATTERN = Pattern.compile(","); + + private final Context context; + private Point screenResolution; + private Point cameraResolution; + private int previewFormat; + private String previewFormatString; + + CameraConfigurationManager(Context context) { + this.context = context; + } + + /** + * Reads, one time, values from the camera that are needed by the app. + */ + void initFromCameraParameters(Camera camera) { + Camera.Parameters parameters = camera.getParameters(); + previewFormat = parameters.getPreviewFormat(); + previewFormatString = parameters.get("preview-format"); + Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); + WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + Display display = manager.getDefaultDisplay(); + screenResolution = new Point(display.getWidth(), display.getHeight()); + Log.d(TAG, "Screen resolution: " + screenResolution); + cameraResolution = getCameraResolution(parameters, screenResolution); + Log.d(TAG, "Camera resolution: " + screenResolution); + } + + /** + * Sets the camera up to take preview images which are used for both preview and decoding. + * We detect the preview format here so that buildLuminanceSource() can build an appropriate + * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest, + * and the planar Y can be used for barcode scanning without a copy in some cases. + */ + void setDesiredCameraParameters(Camera camera) { + Camera.Parameters parameters = camera.getParameters(); + Log.d(TAG, "Setting preview size: " + cameraResolution); + parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); + setFlash(parameters); + setZoom(parameters); + //setSharpness(parameters); + //modify here + +// camera.setDisplayOrientation(90); + setDisplayOrientation(camera, 90); + camera.setParameters(parameters); + } + + Point getCameraResolution() { + return cameraResolution; + } + + Point getScreenResolution() { + return screenResolution; + } + + int getPreviewFormat() { + return previewFormat; + } + + String getPreviewFormatString() { + return previewFormatString; + } + + private static Point getCameraResolution(Camera.Parameters parameters, Point screenResolution) { + + String previewSizeValueString = parameters.get("preview-size-values"); + // saw this on Xperia + if (previewSizeValueString == null) { + previewSizeValueString = parameters.get("preview-size-value"); + } + + Point cameraResolution = null; + + if (previewSizeValueString != null) { + Log.d(TAG, "preview-size-values parameter: " + previewSizeValueString); + cameraResolution = findBestPreviewSizeValue(previewSizeValueString, screenResolution); + } + + if (cameraResolution == null) { + // Ensure that the camera resolution is a multiple of 8, as the screen may not be. + cameraResolution = new Point( + (screenResolution.x >> 3) << 3, + (screenResolution.y >> 3) << 3); + } + + return cameraResolution; + } + + private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) { + int bestX = 0; + int bestY = 0; + int diff = Integer.MAX_VALUE; + for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) { + + previewSize = previewSize.trim(); + int dimPosition = previewSize.indexOf('x'); + if (dimPosition < 0) { + Log.w(TAG, "Bad preview-size: " + previewSize); + continue; + } + + int newX; + int newY; + try { + newX = Integer.parseInt(previewSize.substring(0, dimPosition)); + newY = Integer.parseInt(previewSize.substring(dimPosition + 1)); + } catch (NumberFormatException nfe) { + Log.w(TAG, "Bad preview-size: " + previewSize); + continue; + } + + int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y); + if (newDiff == 0) { + bestX = newX; + bestY = newY; + break; + } else if (newDiff < diff) { + bestX = newX; + bestY = newY; + diff = newDiff; + } + + } + + if (bestX > 0 && bestY > 0) { + return new Point(bestX, bestY); + } + return null; + } + + private static int findBestMotZoomValue(CharSequence stringValues, int tenDesiredZoom) { + int tenBestValue = 0; + for (String stringValue : COMMA_PATTERN.split(stringValues)) { + stringValue = stringValue.trim(); + double value; + try { + value = Double.parseDouble(stringValue); + } catch (NumberFormatException nfe) { + return tenDesiredZoom; + } + int tenValue = (int) (10.0 * value); + if (Math.abs(tenDesiredZoom - value) < Math.abs(tenDesiredZoom - tenBestValue)) { + tenBestValue = tenValue; + } + } + return tenBestValue; + } + + private void setFlash(Camera.Parameters parameters) { + // FIXME: This is a hack to turn the flash off on the Samsung Galaxy. + // And this is a hack-hack to work around a different value on the Behold II + // Restrict Behold II check to Cupcake, per Samsung's advice + //if (Build.MODEL.contains("Behold II") && + // CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) { + if (Build.MODEL.contains("Behold II") && CameraManager.SDK_INT == 3) { // 3 = Cupcake + parameters.set("flash-value", 1); + } else { + parameters.set("flash-value", 2); + } + // This is the standard setting to turn the flash off that all devices should honor. + parameters.set("flash-mode", "off"); + } + + private void setZoom(Camera.Parameters parameters) { + + String zoomSupportedString = parameters.get("zoom-supported"); + if (zoomSupportedString != null && !Boolean.parseBoolean(zoomSupportedString)) { + return; + } + + int tenDesiredZoom = TEN_DESIRED_ZOOM; + + String maxZoomString = parameters.get("max-zoom"); + if (maxZoomString != null) { + try { + int tenMaxZoom = (int) (10.0 * Double.parseDouble(maxZoomString)); + if (tenDesiredZoom > tenMaxZoom) { + tenDesiredZoom = tenMaxZoom; + } + } catch (NumberFormatException nfe) { + Log.w(TAG, "Bad max-zoom: " + maxZoomString); + } + } + + String takingPictureZoomMaxString = parameters.get("taking-picture-zoom-max"); + if (takingPictureZoomMaxString != null) { + try { + int tenMaxZoom = Integer.parseInt(takingPictureZoomMaxString); + if (tenDesiredZoom > tenMaxZoom) { + tenDesiredZoom = tenMaxZoom; + } + } catch (NumberFormatException nfe) { + Log.w(TAG, "Bad taking-picture-zoom-max: " + takingPictureZoomMaxString); + } + } + + String motZoomValuesString = parameters.get("mot-zoom-values"); + if (motZoomValuesString != null) { + tenDesiredZoom = findBestMotZoomValue(motZoomValuesString, tenDesiredZoom); + } + + String motZoomStepString = parameters.get("mot-zoom-step"); + if (motZoomStepString != null) { + try { + double motZoomStep = Double.parseDouble(motZoomStepString.trim()); + int tenZoomStep = (int) (10.0 * motZoomStep); + if (tenZoomStep > 1) { + tenDesiredZoom -= tenDesiredZoom % tenZoomStep; + } + } catch (NumberFormatException nfe) { + // continue + } + } + + // Set zoom. This helps encourage the user to pull back. + // Some devices like the Behold have a zoom parameter + if (maxZoomString != null || motZoomValuesString != null) { + parameters.set("zoom", String.valueOf(tenDesiredZoom / 10.0)); + } + + // Most devices, like the Hero, appear to expose this zoom parameter. + // It takes on values like "27" which appears to mean 2.7x zoom + if (takingPictureZoomMaxString != null) { + parameters.set("taking-picture-zoom", tenDesiredZoom); + } + } + + public static int getDesiredSharpness() { + return DESIRED_SHARPNESS; + } + + /** + * compatible 1.6 + * @param camera + * @param angle + */ + protected void setDisplayOrientation(Camera camera, int angle){ + Method downPolymorphic; + try + { + downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class }); + if (downPolymorphic != null) + downPolymorphic.invoke(camera, new Object[] { angle }); + } + catch (Exception e1) + { + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/camera/CameraManager.java b/app/src/main/java/com/mining/app/zxing/camera/CameraManager.java new file mode 100644 index 0000000..43ddc03 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/camera/CameraManager.java @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.camera; + +import java.io.IOException; + +import android.content.Context; +import android.graphics.PixelFormat; +import android.graphics.Point; +import android.graphics.Rect; +import android.hardware.Camera; +import android.os.Build; +import android.os.Handler; +import android.util.Log; +import android.view.SurfaceHolder; + +/** + * This object wraps the Camera service object and expects to be the only one talking to it. The + * implementation encapsulates the steps needed to take preview-sized images, which are used for + * both preview and decoding. + * + */ +public final class CameraManager { + + private static final String TAG = CameraManager.class.getSimpleName(); + + private static final int MIN_FRAME_WIDTH = 600; + private static final int MIN_FRAME_HEIGHT = 600; + private static final int MAX_FRAME_WIDTH = 600; + private static final int MAX_FRAME_HEIGHT = 600; + + private static CameraManager cameraManager; + + static final int SDK_INT; // Later we can use Build.VERSION.SDK_INT + static { + int sdkInt; + try { + sdkInt = Integer.parseInt(Build.VERSION.SDK); + } catch (NumberFormatException nfe) { + // Just to be safe + sdkInt = 10000; + } + SDK_INT = sdkInt; + } + + private final Context context; + private final CameraConfigurationManager configManager; + private Camera camera; + private Rect framingRect; + private Rect framingRectInPreview; + private boolean initialized; + private boolean previewing; + private final boolean useOneShotPreviewCallback; + /** + * Preview frames are delivered here, which we pass on to the registered handler. Make sure to + * clear the handler so it will only receive one message. + */ + private final PreviewCallback previewCallback; + /** Autofocus callbacks arrive here, and are dispatched to the Handler which requested them. */ + private final AutoFocusCallback autoFocusCallback; + + /** + * Initializes this static object with the Context of the calling Activity. + * + * @param context The Activity which wants to use the camera. + */ + public static void init(Context context) { + if (cameraManager == null) { + cameraManager = new CameraManager(context); + } + } + + /** + * Gets the CameraManager singleton instance. + * + * @return A reference to the CameraManager singleton. + */ + public static CameraManager get() { + return cameraManager; + } + + private CameraManager(Context context) { + + this.context = context; + this.configManager = new CameraConfigurationManager(context); + + // Camera.setOneShotPreviewCallback() has a race condition in Cupcake, so we use the older + // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use + // the more efficient one shot callback, as the older one can swamp the system and cause it + // to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK. + //useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.CUPCAKE; + useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > 3; // 3 = Cupcake + + previewCallback = new PreviewCallback(configManager, useOneShotPreviewCallback); + autoFocusCallback = new AutoFocusCallback(); + } + + /** + * Opens the camera driver and initializes the hardware parameters. + * + * @param holder The surface object which the camera will draw preview frames into. + * @throws IOException Indicates the camera driver failed to open. + */ + public void openDriver(SurfaceHolder holder) throws IOException { + if (camera == null) { + camera = Camera.open(); + if (camera == null) { + throw new IOException(); + } + camera.setPreviewDisplay(holder); + + if (!initialized) { + initialized = true; + configManager.initFromCameraParameters(camera); + } + configManager.setDesiredCameraParameters(camera); + + //FIXME + // SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + //�Ƿ�ʹ��ǰ�� +// if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) { +// FlashlightManager.enableFlashlight(); +// } + FlashlightManager.enableFlashlight(); + } + } + + /** + * Closes the camera driver if still in use. + */ + public void closeDriver() { + if (camera != null) { + FlashlightManager.disableFlashlight(); + camera.release(); + camera = null; + } + } + + /** + * Asks the camera hardware to begin drawing preview frames to the screen. + */ + public void startPreview() { + if (camera != null && !previewing) { + camera.startPreview(); + previewing = true; + } + } + + /** + * Tells the camera to stop drawing preview frames. + */ + public void stopPreview() { + if (camera != null && previewing) { + if (!useOneShotPreviewCallback) { + camera.setPreviewCallback(null); + } + camera.stopPreview(); + previewCallback.setHandler(null, 0); + autoFocusCallback.setHandler(null, 0); + previewing = false; + } + } + + /** + * A single preview frame will be returned to the handler supplied. The data will arrive as byte[] + * in the message.obj field, with width and height encoded as message.arg1 and message.arg2, + * respectively. + * + * @param handler The handler to send the message to. + * @param message The what field of the message to be sent. + */ + public void requestPreviewFrame(Handler handler, int message) { + if (camera != null && previewing) { + previewCallback.setHandler(handler, message); + if (useOneShotPreviewCallback) { + camera.setOneShotPreviewCallback(previewCallback); + } else { + camera.setPreviewCallback(previewCallback); + } + } + } + + /** + * Asks the camera hardware to perform an autofocus. + * + * @param handler The Handler to notify when the autofocus completes. + * @param message The message to deliver. + */ + public void requestAutoFocus(Handler handler, int message) { + if (camera != null && previewing) { + autoFocusCallback.setHandler(handler, message); + //Log.d(TAG, "Requesting auto-focus callback"); + camera.autoFocus(autoFocusCallback); + } + } + + /** + * Calculates the framing rect which the UI should draw to show the user where to place the + * barcode. This target helps with alignment as well as forces the user to hold the device + * far enough away to ensure the image will be in focus. + * + * @return The rectangle to draw on screen in window coordinates. + */ + public Rect getFramingRect() { + Point screenResolution = configManager.getScreenResolution(); + if (framingRect == null) { + if (camera == null) { + return null; + } + int width = screenResolution.x * 3 / 4; + if (width < MIN_FRAME_WIDTH) { + width = MIN_FRAME_WIDTH; + } else if (width > MAX_FRAME_WIDTH) { + width = MAX_FRAME_WIDTH; + } + int height = screenResolution.y * 3 / 4; + if (height < MIN_FRAME_HEIGHT) { + height = MIN_FRAME_HEIGHT; + } else if (height > MAX_FRAME_HEIGHT) { + height = MAX_FRAME_HEIGHT; + } + int leftOffset = (screenResolution.x - width) / 2; + int topOffset = (screenResolution.y - height) / 2; + framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height); + Log.d(TAG, "Calculated framing rect: " + framingRect); + } + return framingRect; + } + + /** + * Like {@link #getFramingRect} but coordinates are in terms of the preview frame, + * not UI / screen. + */ + public Rect getFramingRectInPreview() { + if (framingRectInPreview == null) { + Rect rect = new Rect(getFramingRect()); + Point cameraResolution = configManager.getCameraResolution(); + Point screenResolution = configManager.getScreenResolution(); + //modify here +// rect.left = rect.left * cameraResolution.x / screenResolution.x; +// rect.right = rect.right * cameraResolution.x / screenResolution.x; +// rect.top = rect.top * cameraResolution.y / screenResolution.y; +// rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y; + rect.left = rect.left * cameraResolution.y / screenResolution.x; + rect.right = rect.right * cameraResolution.y / screenResolution.x; + rect.top = rect.top * cameraResolution.x / screenResolution.y; + rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y; + framingRectInPreview = rect; + } + return framingRectInPreview; + } + + /** + * Converts the result points from still resolution coordinates to screen coordinates. + * + * @param points The points returned by the Reader subclass through Result.getResultPoints(). + * @return An array of Points scaled to the size of the framing rect and offset appropriately + * so they can be drawn in screen coordinates. + */ + /* + public Point[] convertResultPoints(ResultPoint[] points) { + Rect frame = getFramingRectInPreview(); + int count = points.length; + Point[] output = new Point[count]; + for (int x = 0; x < count; x++) { + output[x] = new Point(); + output[x].x = frame.left + (int) (points[x].getX() + 0.5f); + output[x].y = frame.top + (int) (points[x].getY() + 0.5f); + } + return output; + } + */ + + /** + * A factory method to build the appropriate LuminanceSource object based on the format + * of the preview buffers, as described by Camera.Parameters. + * + * @param data A preview frame. + * @param width The width of the image. + * @param height The height of the image. + * @return A PlanarYUVLuminanceSource instance. + */ + public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { + Rect rect = getFramingRectInPreview(); + int previewFormat = configManager.getPreviewFormat(); + String previewFormatString = configManager.getPreviewFormatString(); + switch (previewFormat) { + // This is the standard Android format which all devices are REQUIRED to support. + // In theory, it's the only one we should ever care about. + case PixelFormat.YCbCr_420_SP: + // This format has never been seen in the wild, but is compatible as we only care + // about the Y channel, so allow it. + case PixelFormat.YCbCr_422_SP: + return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, + rect.width(), rect.height()); + default: + // The Samsung Moment incorrectly uses this variant instead of the 'sp' version. + // Fortunately, it too has all the Y data up front, so we can read it. + if ("yuv420p".equals(previewFormatString)) { + return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, + rect.width(), rect.height()); + } + } + throw new IllegalArgumentException("Unsupported picture format: " + + previewFormat + '/' + previewFormatString); + } + + public Context getContext() { + return context; + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/camera/FlashlightManager.java b/app/src/main/java/com/mining/app/zxing/camera/FlashlightManager.java new file mode 100644 index 0000000..2d33754 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/camera/FlashlightManager.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.camera; + +import android.os.IBinder; +import android.util.Log; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * This class is used to activate the weak light on some camera phones (not flash) + * in order to illuminate surfaces for scanning. There is no official way to do this, + * but, classes which allow access to this function still exist on some devices. + * This therefore proceeds through a great deal of reflection. + * + * See + * http://almondmendoza.com/2009/01/05/changing-the-screen-brightness-programatically/ and + * + * http://code.google.com/p/droidled/source/browse/trunk/src/com/droidled/demo/DroidLED.java. + * Thanks to Ryan Alford for pointing out the availability of this class. + */ +final class FlashlightManager { + + private static final String TAG = FlashlightManager.class.getSimpleName(); + + private static final Object iHardwareService; + private static final Method setFlashEnabledMethod; + static { + iHardwareService = getHardwareService(); + setFlashEnabledMethod = getSetFlashEnabledMethod(iHardwareService); + if (iHardwareService == null) { + Log.v(TAG, "This device does supports control of a flashlight"); + } else { + Log.v(TAG, "This device does not support control of a flashlight"); + } + } + + private FlashlightManager() { + } + + static void enableFlashlight() { + setFlashlight(false); + } + + static void disableFlashlight() { + setFlashlight(false); + } + + private static Object getHardwareService() { + Class serviceManagerClass = maybeForName("android.os.ServiceManager"); + if (serviceManagerClass == null) { + return null; + } + + Method getServiceMethod = maybeGetMethod(serviceManagerClass, "getService", String.class); + if (getServiceMethod == null) { + return null; + } + + Object hardwareService = invoke(getServiceMethod, null, "hardware"); + if (hardwareService == null) { + return null; + } + + Class iHardwareServiceStubClass = maybeForName("android.os.IHardwareService$Stub"); + if (iHardwareServiceStubClass == null) { + return null; + } + + Method asInterfaceMethod = maybeGetMethod(iHardwareServiceStubClass, "asInterface", IBinder.class); + if (asInterfaceMethod == null) { + return null; + } + + return invoke(asInterfaceMethod, null, hardwareService); + } + + private static Method getSetFlashEnabledMethod(Object iHardwareService) { + if (iHardwareService == null) { + return null; + } + Class proxyClass = iHardwareService.getClass(); + return maybeGetMethod(proxyClass, "setFlashlightEnabled", boolean.class); + } + + private static Class maybeForName(String name) { + try { + return Class.forName(name); + } catch (ClassNotFoundException cnfe) { + // OK + return null; + } catch (RuntimeException re) { + Log.w(TAG, "Unexpected error while finding class " + name, re); + return null; + } + } + + private static Method maybeGetMethod(Class clazz, String name, Class... argClasses) { + try { + return clazz.getMethod(name, argClasses); + } catch (NoSuchMethodException nsme) { + // OK + return null; + } catch (RuntimeException re) { + Log.w(TAG, "Unexpected error while finding method " + name, re); + return null; + } + } + + private static Object invoke(Method method, Object instance, Object... args) { + try { + return method.invoke(instance, args); + } catch (IllegalAccessException e) { + Log.w(TAG, "Unexpected error while invoking " + method, e); + return null; + } catch (InvocationTargetException e) { + Log.w(TAG, "Unexpected error while invoking " + method, e.getCause()); + return null; + } catch (RuntimeException re) { + Log.w(TAG, "Unexpected error while invoking " + method, re); + return null; + } + } + + private static void setFlashlight(boolean active) { + if (iHardwareService != null) { + invoke(setFlashEnabledMethod, iHardwareService, active); + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/camera/PlanarYUVLuminanceSource.java b/app/src/main/java/com/mining/app/zxing/camera/PlanarYUVLuminanceSource.java new file mode 100644 index 0000000..1b5866f --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/camera/PlanarYUVLuminanceSource.java @@ -0,0 +1,133 @@ +/* + * Copyright 2009 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.camera; + +import com.google.zxing.LuminanceSource; + +import android.graphics.Bitmap; + +/** + * This object extends LuminanceSource around an array of YUV data returned from the camera driver, + * with the option to crop to a rectangle within the full data. This can be used to exclude + * superfluous pixels around the perimeter and speed up decoding. + * + * It works for any pixel format where the Y channel is planar and appears first, including + * YCbCr_420_SP and YCbCr_422_SP. + * + * @author dswitkin@google.com (Daniel Switkin) + */ +public final class PlanarYUVLuminanceSource extends LuminanceSource { + private final byte[] yuvData; + private final int dataWidth; + private final int dataHeight; + private final int left; + private final int top; + + public PlanarYUVLuminanceSource(byte[] yuvData, int dataWidth, int dataHeight, int left, int top, + int width, int height) { + super(width, height); + + if (left + width > dataWidth || top + height > dataHeight) { + throw new IllegalArgumentException("Crop rectangle does not fit within image data."); + } + + this.yuvData = yuvData; + this.dataWidth = dataWidth; + this.dataHeight = dataHeight; + this.left = left; + this.top = top; + } + + @Override + public byte[] getRow(int y, byte[] row) { + if (y < 0 || y >= getHeight()) { + throw new IllegalArgumentException("Requested row is outside the image: " + y); + } + int width = getWidth(); + if (row == null || row.length < width) { + row = new byte[width]; + } + int offset = (y + top) * dataWidth + left; + System.arraycopy(yuvData, offset, row, 0, width); + return row; + } + + @Override + public byte[] getMatrix() { + int width = getWidth(); + int height = getHeight(); + + // If the caller asks for the entire underlying image, save the copy and give them the + // original data. The docs specifically warn that result.length must be ignored. + if (width == dataWidth && height == dataHeight) { + return yuvData; + } + + int area = width * height; + byte[] matrix = new byte[area]; + int inputOffset = top * dataWidth + left; + + // If the width matches the full width of the underlying data, perform a single copy. + if (width == dataWidth) { + System.arraycopy(yuvData, inputOffset, matrix, 0, area); + return matrix; + } + + // Otherwise copy one cropped row at a time. + byte[] yuv = yuvData; + for (int y = 0; y < height; y++) { + int outputOffset = y * width; + System.arraycopy(yuv, inputOffset, matrix, outputOffset, width); + inputOffset += dataWidth; + } + return matrix; + } + + @Override + public boolean isCropSupported() { + return true; + } + + public int getDataWidth() { + return dataWidth; + } + + public int getDataHeight() { + return dataHeight; + } + + public Bitmap renderCroppedGreyscaleBitmap() { + int width = getWidth(); + int height = getHeight(); + int[] pixels = new int[width * height]; + byte[] yuv = yuvData; + int inputOffset = top * dataWidth + left; + + for (int y = 0; y < height; y++) { + int outputOffset = y * width; + for (int x = 0; x < width; x++) { + int grey = yuv[inputOffset + x] & 0xff; + pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101); + } + inputOffset += dataWidth; + } + + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + bitmap.setPixels(pixels, 0, width, 0, 0, width, height); + return bitmap; + } +} diff --git a/app/src/main/java/com/mining/app/zxing/camera/PreviewCallback.java b/app/src/main/java/com/mining/app/zxing/camera/PreviewCallback.java new file mode 100644 index 0000000..4950230 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/camera/PreviewCallback.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.camera; + +import android.graphics.Point; +import android.hardware.Camera; +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +final class PreviewCallback implements Camera.PreviewCallback { + + private static final String TAG = PreviewCallback.class.getSimpleName(); + + private final CameraConfigurationManager configManager; + private final boolean useOneShotPreviewCallback; + private Handler previewHandler; + private int previewMessage; + + PreviewCallback(CameraConfigurationManager configManager, boolean useOneShotPreviewCallback) { + this.configManager = configManager; + this.useOneShotPreviewCallback = useOneShotPreviewCallback; + } + + void setHandler(Handler previewHandler, int previewMessage) { + this.previewHandler = previewHandler; + this.previewMessage = previewMessage; + } + + public void onPreviewFrame(byte[] data, Camera camera) { + Point cameraResolution = configManager.getCameraResolution(); + if (!useOneShotPreviewCallback) { + camera.setPreviewCallback(null); + } + if (previewHandler != null) { + Message message = previewHandler.obtainMessage(previewMessage, cameraResolution.x, + cameraResolution.y, data); + message.sendToTarget(); + previewHandler = null; + } else { + Log.d(TAG, "Got preview callback, but no handler for it"); + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/CaptureActivityHandler.java b/app/src/main/java/com/mining/app/zxing/decoding/CaptureActivityHandler.java new file mode 100644 index 0000000..bb566bd --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/CaptureActivityHandler.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; + +import java.util.Vector; + +import android.app.Activity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.util.Log; + +import com.example.chaoran.MipcaActivityCapture; +import com.example.chaoran.R; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import com.mining.app.zxing.camera.CameraManager; +import com.mining.app.zxing.view.ViewfinderResultPointCallback; + +/** + * This class handles all the messaging which comprises the state machine for capture. + */ +public final class CaptureActivityHandler extends Handler { + + private static final String TAG = CaptureActivityHandler.class.getSimpleName(); + + private final MipcaActivityCapture activity; + private final DecodeThread decodeThread; + private State state; + + private enum State { + PREVIEW, + SUCCESS, + DONE + } + + public CaptureActivityHandler(MipcaActivityCapture activity, Vector decodeFormats, + String characterSet) { + this.activity = activity; + decodeThread = new DecodeThread(activity, decodeFormats, characterSet, + new ViewfinderResultPointCallback(activity.getViewfinderView())); + decodeThread.start(); + state = State.SUCCESS; + // Start ourselves capturing previews and decoding. + CameraManager.get().startPreview(); + restartPreviewAndDecode(); + } + + @Override + public void handleMessage(Message message) { + switch (message.what) { + case R.id.auto_focus: + //Log.d(TAG, "Got auto-focus message"); + // When one auto focus pass finishes, start another. This is the closest thing to + // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do. + if (state == State.PREVIEW) { + CameraManager.get().requestAutoFocus(this, R.id.auto_focus); + } + break; + case R.id.restart_preview: + Log.d(TAG, "Got restart preview message"); + restartPreviewAndDecode(); + break; + case R.id.decode_succeeded: + Log.d(TAG, "Got decode succeeded message"); + state = State.SUCCESS; + Bundle bundle = message.getData(); + + /***********************************************************************/ + Bitmap barcode = bundle == null ? null : + (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳� + + activity.handleDecode((Result) message.obj, barcode);//���ؽ��? /***********************************************************************/ + break; + case R.id.decode_failed: + // We're decoding as fast as possible, so when one decode fails, start another. + state = State.PREVIEW; + CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); + break; + case R.id.return_scan_result: + Log.d(TAG, "Got return scan result message"); + activity.setResult(Activity.RESULT_OK, (Intent) message.obj); + activity.finish(); + break; + case R.id.launch_product_query: + Log.d(TAG, "Got product query message"); + String url = (String) message.obj; + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); + activity.startActivity(intent); + break; + } + } + + public void quitSynchronously() { + state = State.DONE; + CameraManager.get().stopPreview(); + Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit); + quit.sendToTarget(); + try { + decodeThread.join(); + } catch (InterruptedException e) { + // continue + } + + // Be absolutely sure we don't send any queued up messages + removeMessages(R.id.decode_succeeded); + removeMessages(R.id.decode_failed); + } + + private void restartPreviewAndDecode() { + if (state == State.SUCCESS) { + state = State.PREVIEW; + CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); + CameraManager.get().requestAutoFocus(this, R.id.auto_focus); + activity.drawViewfinder(); + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/DecodeFormatManager.java b/app/src/main/java/com/mining/app/zxing/decoding/DecodeFormatManager.java new file mode 100644 index 0000000..0ba427a --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/DecodeFormatManager.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; + +import java.util.Arrays; +import java.util.List; +import java.util.Vector; +import java.util.regex.Pattern; + +import android.content.Intent; +import android.net.Uri; +import com.google.zxing.BarcodeFormat; + +final class DecodeFormatManager { + + private static final Pattern COMMA_PATTERN = Pattern.compile(","); + + static final Vector PRODUCT_FORMATS; + static final Vector ONE_D_FORMATS; + static final Vector QR_CODE_FORMATS; + static final Vector DATA_MATRIX_FORMATS; + static { + PRODUCT_FORMATS = new Vector(5); + PRODUCT_FORMATS.add(BarcodeFormat.UPC_A); + PRODUCT_FORMATS.add(BarcodeFormat.UPC_E); + PRODUCT_FORMATS.add(BarcodeFormat.EAN_13); + PRODUCT_FORMATS.add(BarcodeFormat.EAN_8); + PRODUCT_FORMATS.add(BarcodeFormat.RSS14); + ONE_D_FORMATS = new Vector(PRODUCT_FORMATS.size() + 4); + ONE_D_FORMATS.addAll(PRODUCT_FORMATS); + ONE_D_FORMATS.add(BarcodeFormat.CODE_39); + ONE_D_FORMATS.add(BarcodeFormat.CODE_93); + ONE_D_FORMATS.add(BarcodeFormat.CODE_128); + ONE_D_FORMATS.add(BarcodeFormat.ITF); + QR_CODE_FORMATS = new Vector(1); + QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE); + DATA_MATRIX_FORMATS = new Vector(1); + DATA_MATRIX_FORMATS.add(BarcodeFormat.DATA_MATRIX); + } + + private DecodeFormatManager() {} + + static Vector parseDecodeFormats(Intent intent) { + List scanFormats = null; + String scanFormatsString = intent.getStringExtra(Intents.Scan.SCAN_FORMATS); + if (scanFormatsString != null) { + scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString)); + } + return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE)); + } + + static Vector parseDecodeFormats(Uri inputUri) { + List formats = inputUri.getQueryParameters(Intents.Scan.SCAN_FORMATS); + if (formats != null && formats.size() == 1 && formats.get(0) != null){ + formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0))); + } + return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE)); + } + + private static Vector parseDecodeFormats(Iterable scanFormats, + String decodeMode) { + if (scanFormats != null) { + Vector formats = new Vector(); + try { + for (String format : scanFormats) { + formats.add(BarcodeFormat.valueOf(format)); + } + return formats; + } catch (IllegalArgumentException iae) { + // ignore it then + } + } + if (decodeMode != null) { + if (Intents.Scan.PRODUCT_MODE.equals(decodeMode)) { + return PRODUCT_FORMATS; + } + if (Intents.Scan.QR_CODE_MODE.equals(decodeMode)) { + return QR_CODE_FORMATS; + } + if (Intents.Scan.DATA_MATRIX_MODE.equals(decodeMode)) { + return DATA_MATRIX_FORMATS; + } + if (Intents.Scan.ONE_D_MODE.equals(decodeMode)) { + return ONE_D_FORMATS; + } + } + return null; + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/DecodeHandler.java b/app/src/main/java/com/mining/app/zxing/decoding/DecodeHandler.java new file mode 100644 index 0000000..1e2e41d --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/DecodeHandler.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; +import java.util.Hashtable; + +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; + +import com.example.chaoran.MipcaActivityCapture; +import com.example.chaoran.R; +import com.google.zxing.BinaryBitmap; +import com.google.zxing.DecodeHintType; +import com.google.zxing.MultiFormatReader; +import com.google.zxing.ReaderException; +import com.google.zxing.Result; +import com.google.zxing.common.HybridBinarizer; +import com.mining.app.zxing.camera.CameraManager; +import com.mining.app.zxing.camera.PlanarYUVLuminanceSource; + +final class DecodeHandler extends Handler { + + private static final String TAG = DecodeHandler.class.getSimpleName(); + + private final MipcaActivityCapture activity; + private final MultiFormatReader multiFormatReader; + + DecodeHandler(MipcaActivityCapture activity, Hashtable hints) { + multiFormatReader = new MultiFormatReader(); + multiFormatReader.setHints(hints); + this.activity = activity; + } + + @Override + public void handleMessage(Message message) { + switch (message.what) { + case R.id.decode: + //Log.d(TAG, "Got decode message"); + decode((byte[]) message.obj, message.arg1, message.arg2); + break; + case R.id.quit: + Looper.myLooper().quit(); + break; + } + } + + /** + * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, + * reuse the same reader objects from one decode to the next. + * + * @param data The YUV preview frame. + * @param width The width of the preview frame. + * @param height The height of the preview frame. + */ + private void decode(byte[] data, int width, int height) { + long start = System.currentTimeMillis(); + Result rawResult = null; + + //modify here + 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; // Here we are swapping, that's the difference to #11 + width = height; + height = tmp; + + PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(rotatedData, width, height); + BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); + try { + rawResult = multiFormatReader.decodeWithState(bitmap); + } catch (ReaderException re) { + // continue + } finally { + multiFormatReader.reset(); + } + + if (rawResult != null) { + long end = System.currentTimeMillis(); + Log.d(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString()); + Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, rawResult); + Bundle bundle = new Bundle(); + bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap()); + message.setData(bundle); + //Log.d(TAG, "Sending decode succeeded message..."); + message.sendToTarget(); + } else { + Message message = Message.obtain(activity.getHandler(), R.id.decode_failed); + message.sendToTarget(); + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/DecodeThread.java b/app/src/main/java/com/mining/app/zxing/decoding/DecodeThread.java new file mode 100644 index 0000000..7c46e98 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/DecodeThread.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; + +import java.util.Hashtable; +import java.util.Vector; +import java.util.concurrent.CountDownLatch; + +import android.os.Handler; +import android.os.Looper; + +import com.example.chaoran.MipcaActivityCapture; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.DecodeHintType; +import com.google.zxing.ResultPointCallback; + +/** + * This thread does all the heavy lifting of decoding the images. + * �����߳� + */ +final class DecodeThread extends Thread { + + public static final String BARCODE_BITMAP = "barcode_bitmap"; + private final MipcaActivityCapture activity; + private final Hashtable hints; + private Handler handler; + private final CountDownLatch handlerInitLatch; + + DecodeThread(MipcaActivityCapture activity, + Vector decodeFormats, + String characterSet, + ResultPointCallback resultPointCallback) { + + this.activity = activity; + handlerInitLatch = new CountDownLatch(1); + + hints = new Hashtable(3); + + if (decodeFormats == null || decodeFormats.isEmpty()) { + decodeFormats = new Vector(); + decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS); + decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); + decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS); + } + + hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats); + + if (characterSet != null) { + hints.put(DecodeHintType.CHARACTER_SET, characterSet); + } + + hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback); + } + + Handler getHandler() { + try { + handlerInitLatch.await(); + } catch (InterruptedException ie) { + // continue? + } + return handler; + } + + @Override + public void run() { + Looper.prepare(); + handler = new DecodeHandler(activity, hints); + handlerInitLatch.countDown(); + Looper.loop(); + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/FinishListener.java b/app/src/main/java/com/mining/app/zxing/decoding/FinishListener.java new file mode 100644 index 0000000..9e8cd47 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/FinishListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; + +import android.app.Activity; +import android.content.DialogInterface; + +/** + * Simple listener used to exit the app in a few cases. + * + */ +public final class FinishListener + implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener, Runnable { + + private final Activity activityToFinish; + + public FinishListener(Activity activityToFinish) { + this.activityToFinish = activityToFinish; + } + + public void onCancel(DialogInterface dialogInterface) { + run(); + } + + public void onClick(DialogInterface dialogInterface, int i) { + run(); + } + + public void run() { + activityToFinish.finish(); + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/InactivityTimer.java b/app/src/main/java/com/mining/app/zxing/decoding/InactivityTimer.java new file mode 100644 index 0000000..44bdaa9 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/InactivityTimer.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import android.app.Activity; + +/** + * Finishes an activity after a period of inactivity. + */ +public final class InactivityTimer { + + private static final int INACTIVITY_DELAY_SECONDS = 5 * 60; + + private final ScheduledExecutorService inactivityTimer = + Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory()); + private final Activity activity; + private ScheduledFuture inactivityFuture = null; + + public InactivityTimer(Activity activity) { + this.activity = activity; + onActivity(); + } + + public void onActivity() { + cancel(); + inactivityFuture = inactivityTimer.schedule(new FinishListener(activity), + INACTIVITY_DELAY_SECONDS, + TimeUnit.SECONDS); + } + + private void cancel() { + if (inactivityFuture != null) { + inactivityFuture.cancel(true); + inactivityFuture = null; + } + } + + public void shutdown() { + cancel(); + inactivityTimer.shutdown(); + } + + private static final class DaemonThreadFactory implements ThreadFactory { + public Thread newThread(Runnable runnable) { + Thread thread = new Thread(runnable); + thread.setDaemon(true); + return thread; + } + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/decoding/Intents.java b/app/src/main/java/com/mining/app/zxing/decoding/Intents.java new file mode 100644 index 0000000..0c2553a --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/decoding/Intents.java @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.decoding; + +/** + * This class provides the constants to use when sending an Intent to Barcode Scanner. + * These strings are effectively API and cannot be changed. + */ +public final class Intents { + private Intents() { + } + + public static final class Scan { + /** + * Send this intent to open the Barcodes app in scanning mode, find a barcode, and return + * the results. + */ + public static final String ACTION = "com.google.zxing.client.android.SCAN"; + + /** + * By default, sending Scan.ACTION will decode all barcodes that we understand. However it + * may be useful to limit scanning to certain formats. Use Intent.putExtra(MODE, value) with + * one of the values below ({@link #PRODUCT_MODE}, {@link #ONE_D_MODE}, {@link #QR_CODE_MODE}). + * Optional. + * + * Setting this is effectively shorthnad for setting explicit formats with {@link #SCAN_FORMATS}. + * It is overridden by that setting. + */ + public static final String MODE = "SCAN_MODE"; + + /** + * Comma-separated list of formats to scan for. The values must match the names of + * {@link com.google.zxing.BarcodeFormat}s, such as {@link com.google.zxing.BarcodeFormat#EAN_13}. + * Example: "EAN_13,EAN_8,QR_CODE" + * + * This overrides {@link #MODE}. + */ + public static final String SCAN_FORMATS = "SCAN_FORMATS"; + + /** + * @see com.google.zxing.DecodeHintType#CHARACTER_SET + */ + public static final String CHARACTER_SET = "CHARACTER_SET"; + + /** + * Decode only UPC and EAN barcodes. This is the right choice for shopping apps which get + * prices, reviews, etc. for products. + */ + public static final String PRODUCT_MODE = "PRODUCT_MODE"; + + /** + * Decode only 1D barcodes (currently UPC, EAN, Code 39, and Code 128). + */ + public static final String ONE_D_MODE = "ONE_D_MODE"; + + /** + * Decode only QR codes. + */ + public static final String QR_CODE_MODE = "QR_CODE_MODE"; + + /** + * Decode only Data Matrix codes. + */ + public static final String DATA_MATRIX_MODE = "DATA_MATRIX_MODE"; + + /** + * If a barcode is found, Barcodes returns RESULT_OK to onActivityResult() of the app which + * requested the scan via startSubActivity(). The barcodes contents can be retrieved with + * intent.getStringExtra(RESULT). If the user presses Back, the result code will be + * RESULT_CANCELED. + */ + public static final String RESULT = "SCAN_RESULT"; + + /** + * Call intent.getStringExtra(RESULT_FORMAT) to determine which barcode format was found. + * See Contents.Format for possible values. + */ + public static final String RESULT_FORMAT = "SCAN_RESULT_FORMAT"; + + /** + * Setting this to false will not save scanned codes in the history. + */ + public static final String SAVE_HISTORY = "SAVE_HISTORY"; + + private Scan() { + } + } + + public static final class Encode { + /** + * Send this intent to encode a piece of data as a QR code and display it full screen, so + * that another person can scan the barcode from your screen. + */ + public static final String ACTION = "com.google.zxing.client.android.ENCODE"; + + /** + * The data to encode. Use Intent.putExtra(DATA, data) where data is either a String or a + * Bundle, depending on the type and format specified. Non-QR Code formats should + * just use a String here. For QR Code, see Contents for details. + */ + public static final String DATA = "ENCODE_DATA"; + + /** + * The type of data being supplied if the format is QR Code. Use + * Intent.putExtra(TYPE, type) with one of Contents.Type. + */ + public static final String TYPE = "ENCODE_TYPE"; + + /** + * The barcode format to be displayed. If this isn't specified or is blank, + * it defaults to QR Code. Use Intent.putExtra(FORMAT, format), where + * format is one of Contents.Format. + */ + public static final String FORMAT = "ENCODE_FORMAT"; + + private Encode() { + } + } + + public static final class SearchBookContents { + /** + * Use Google Book Search to search the contents of the book provided. + */ + public static final String ACTION = "com.google.zxing.client.android.SEARCH_BOOK_CONTENTS"; + + /** + * The book to search, identified by ISBN number. + */ + public static final String ISBN = "ISBN"; + + /** + * An optional field which is the text to search for. + */ + public static final String QUERY = "QUERY"; + + private SearchBookContents() { + } + } + + public static final class WifiConnect { + /** + * Internal intent used to trigger connection to a wi-fi network. + */ + public static final String ACTION = "com.google.zxing.client.android.WIFI_CONNECT"; + + /** + * The network to connect to, all the configuration provided here. + */ + public static final String SSID = "SSID"; + + /** + * The network to connect to, all the configuration provided here. + */ + public static final String TYPE = "TYPE"; + + /** + * The network to connect to, all the configuration provided here. + */ + public static final String PASSWORD = "PASSWORD"; + + private WifiConnect() { + } + } + + + public static final class Share { + /** + * Give the user a choice of items to encode as a barcode, then render it as a QR Code and + * display onscreen for a friend to scan with their phone. + */ + public static final String ACTION = "com.google.zxing.client.android.SHARE"; + + private Share() { + } + } +} diff --git a/app/src/main/java/com/mining/app/zxing/view/ViewfinderResultPointCallback.java b/app/src/main/java/com/mining/app/zxing/view/ViewfinderResultPointCallback.java new file mode 100644 index 0000000..61ea1a1 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/view/ViewfinderResultPointCallback.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.view; + +import com.google.zxing.ResultPoint; +import com.google.zxing.ResultPointCallback; + +public final class ViewfinderResultPointCallback implements ResultPointCallback { + + private final ViewfinderView viewfinderView; + + public ViewfinderResultPointCallback(ViewfinderView viewfinderView) { + this.viewfinderView = viewfinderView; + } + + public void foundPossibleResultPoint(ResultPoint point) { + viewfinderView.addPossibleResultPoint(point); + } + +} diff --git a/app/src/main/java/com/mining/app/zxing/view/ViewfinderView.java b/app/src/main/java/com/mining/app/zxing/view/ViewfinderView.java new file mode 100644 index 0000000..56a76b3 --- /dev/null +++ b/app/src/main/java/com/mining/app/zxing/view/ViewfinderView.java @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mining.app.zxing.view; + +import java.util.Collection; +import java.util.HashSet; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.Typeface; +import android.util.AttributeSet; +import android.view.View; + +import com.example.chaoran.R; +import com.google.zxing.ResultPoint; +import com.mining.app.zxing.camera.CameraManager; + +/** + * This view is overlaid on top of the camera preview. It adds the viewfinder + * rectangle and partial transparency outside it, as well as the laser scanner + * animation and result points. + * + */ +public final class ViewfinderView extends View { + private static final String TAG = "log"; + /** + * 刷新界面的时间 + */ + private static final long ANIMATION_DELAY = 10L; + private static final int OPAQUE = 0xFF; + + /** + * 四个绿色边角对应的长度 + */ + private int ScreenRate; + + /** + * 四个绿色边角对应的长度 + */ + private static final int CORNER_WIDTH = 10; + /** + *扫描框中的中间线的宽度 + */ + private static final int MIDDLE_LINE_WIDTH = 6; + + /** + * 扫描框中的中间线的与扫描框左右的间隙 + */ + private static final int MIDDLE_LINE_PADDING = 5; + + /** + * 中间那条线每次刷新移动的距离 + */ + private static final int SPEEN_DISTANCE = 5; + + /** + * 手机的屏幕密度 + */ + private static float density; + /** + *字体大小 + */ + private static final int TEXT_SIZE = 16; + /** + * 字体距离扫描框下面的距离 + */ + private static final int TEXT_PADDING_TOP = 30; + + /** + * 画笔对象的引用 + */ + private Paint paint; + + /** + * 中间滑动线的最顶端位置 + */ + private int slideTop; + + /** + * 中间滑动线的最底端位置 + */ + private int slideBottom; + + /** + * 将扫描的二维码拍下来,这里没有这个功能,暂时不考虑 + */ + private Bitmap resultBitmap; + private final int maskColor; + private final int resultColor; + + private final int resultPointColor; + private Collection possibleResultPoints; + private Collection lastPossibleResultPoints; + + boolean isFirst; + + public ViewfinderView(Context context, AttributeSet attrs) { + super(context, attrs); + + density = context.getResources().getDisplayMetrics().density; + //将像素转换成dp + ScreenRate = (int)(20 * density); + + paint = new Paint(); + Resources resources = getResources(); + maskColor = resources.getColor(R.color.viewfinder_mask); + resultColor = resources.getColor(R.color.result_view); + + resultPointColor = resources.getColor(R.color.possible_result_points); + possibleResultPoints = new HashSet(5); + } + + @Override + public void onDraw(Canvas canvas) { + //中间的扫描框,你要修改扫描框的大小,去CameraManager里面修改 + Rect frame = CameraManager.get().getFramingRect(); + if (frame == null) { + return; + } + + //初始化中间线滑动的最上边和最下边 + if(!isFirst){ + isFirst = true; + slideTop = frame.top; + slideBottom = frame.bottom; + } + + //获取屏幕的宽和高 + int width = canvas.getWidth(); + int height = canvas.getHeight(); + + paint.setColor(resultBitmap != null ? resultColor : maskColor); + + //画出扫描框外面的阴影部分,共四个部分,扫描框的上面到屏幕上面,扫描框的下面到屏幕下面 + //扫描框的左边面到屏幕左边,扫描框的右边到屏幕右边 + canvas.drawRect(0, 0, width, frame.top, paint); + canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint); + canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, + paint); + canvas.drawRect(0, frame.bottom + 1, width, height, paint); + + + + if (resultBitmap != null) { + // Draw the opaque result bitmap over the scanning rectangle + paint.setAlpha(OPAQUE); + canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint); + } else { + + //画扫描框边上的角,总共8个部分 + paint.setColor(Color.GREEN); + canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, + frame.top + CORNER_WIDTH, paint); + canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + + ScreenRate, paint); + canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, + frame.top + CORNER_WIDTH, paint); + canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + + ScreenRate, paint); + canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + + ScreenRate, frame.bottom, paint); + canvas.drawRect(frame.left, frame.bottom - ScreenRate, + frame.left + CORNER_WIDTH, frame.bottom, paint); + canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, + frame.right, frame.bottom, paint); + canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, + frame.right, frame.bottom, paint); + + + //绘制中间的线,每次刷新界面,中间的线往下移动SPEEN_DISTANCE + slideTop += SPEEN_DISTANCE; + if(slideTop >= frame.bottom){ + slideTop = frame.top; + } + canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - MIDDLE_LINE_WIDTH/2, frame.right - MIDDLE_LINE_PADDING,slideTop + MIDDLE_LINE_WIDTH/2, paint); + + + //画扫描框下面的字 + paint.setColor(Color.WHITE); + paint.setTextSize(TEXT_SIZE * density); + paint.setAlpha(0x40); + paint.setTypeface(Typeface.create("System", Typeface.BOLD)); + canvas.drawText(getResources().getString(R.string.scan_text), frame.left, (float) (frame.bottom + (float)TEXT_PADDING_TOP *density), paint); + + + + Collection currentPossible = possibleResultPoints; + Collection currentLast = lastPossibleResultPoints; + if (currentPossible.isEmpty()) { + lastPossibleResultPoints = null; + } else { + possibleResultPoints = new HashSet(5); + lastPossibleResultPoints = currentPossible; + paint.setAlpha(OPAQUE); + paint.setColor(resultPointColor); + for (ResultPoint point : currentPossible) { + canvas.drawCircle(frame.left + point.getX(), frame.top + + point.getY(), 6.0f, paint); + } + } + if (currentLast != null) { + paint.setAlpha(OPAQUE / 2); + paint.setColor(resultPointColor); + for (ResultPoint point : currentLast) { + canvas.drawCircle(frame.left + point.getX(), frame.top + + point.getY(), 3.0f, paint); + } + } + + + //只刷新扫描框的内容,其他地方不刷新 + postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, + frame.right, frame.bottom); + + } + } + + public void drawViewfinder() { + resultBitmap = null; + invalidate(); + } + + /** + * Draw a bitmap with the result points highlighted instead of the live + * scanning display. + * + * @param barcode + * An image of the decoded barcode. + */ + public void drawResultBitmap(Bitmap barcode) { + resultBitmap = barcode; + invalidate(); + } + + public void addPossibleResultPoint(ResultPoint point) { + possibleResultPoints.add(point); + } + +} diff --git a/app/src/main/java/com/motorolasolutions/adc/decoder/BarCodeReader.java b/app/src/main/java/com/motorolasolutions/adc/decoder/BarCodeReader.java new file mode 100644 index 0000000..9deb2d5 --- /dev/null +++ b/app/src/main/java/com/motorolasolutions/adc/decoder/BarCodeReader.java @@ -0,0 +1,3227 @@ +/* + * BarCodeReader.java + * + * Class used to access a Motorola Solutions imaging bar code reader. + * + * Copyright (C) 2011 Motorola Solutions, Inc. + */ + +package com.motorolasolutions.adc.decoder; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.StringTokenizer; +import java.io.IOException; + +import android.util.Log; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.graphics.ImageFormat; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; + +/** + * The BarCodeReader class is used to set bar code reader settings, start/stop + * preview, snap pictures, and capture frames for encoding for video. This class + * is a client for the Camera service, which manages the actual Camera hardware. + * + *

+ * To decode bar codes with this class, use the following steps: + *

+ * + *
    + *
  1. Obtain an instance of BarCodeReader with {@link #open(int)}. + * + *
  2. Get the current settings with {@link #getParameters()}. + * + *
  3. If necessary, modify the returned {@link Parameters} object + * and call {@link #setParameters(Parameters)}. + * + *
  4. Call {@link #setDecodeCallback(DecodeCallback)} to register + * a bar code decode event handler. + * + *
  5. If a view finder is desired, pass a fully initialized + * {@link SurfaceHolder} to {@link #setPreviewDisplay(SurfaceHolder)}. + * + *
  6. To begin a decode session, call {@link #startDecode()} or + * {@link #startHandsFreeDecode(int)}. Your registered DecodeCallback will be + * called when a successful decode occurs or if the configured timeout expires. + * + *
  7. Call {@link #stopDecode()} to end the decode session. + * + *
  8. Important: Call {@link #release()} to release the BarCodeReader + * for use by other applications. Applications should release the BarCodeReader + * immediately in {@link android.app.Activity#onPause()} (and re-{@link #open()} + * it in {@link android.app.Activity#onResume()}). + *
+ * + *

+ * This class is not thread-safe, and is meant for use from one event thread. + * Callbacks will be invoked on the event thread {@link #open(int)} was called + * from. This class's methods must never be called from multiple threads at + * once. + *

+ */ + +public class BarCodeReader { + private static final String TAG = "BarCodeReader"; + + // These match the enums in frameworks/base/include/bcreader/BCReader.h + private static final int BCRDR_MSG_ERROR = 0x000001; + private static final int BCRDR_MSG_SHUTTER = 0x000002; + private static final int BCRDR_MSG_FOCUS = 0x000004; + private static final int BCRDR_MSG_ZOOM = 0x000008; + private static final int BCRDR_MSG_PREVIEW_FRAME = 0x000010; + private static final int BCRDR_MSG_VIDEO_FRAME = 0x000020; + private static final int BCRDR_MSG_POSTVIEW_FRAME = 0x000040; + private static final int BCRDR_MSG_RAW_IMAGE = 0x000080; + private static final int BCRDR_MSG_COMPRESSED_IMAGE = 0x000100; + // Add bar code reader specific values here + private static final int BCRDR_MSG_DECODE_COMPLETE = 0x010000; + private static final int BCRDR_MSG_DECODE_TIMEOUT = 0x020000; + private static final int BCRDR_MSG_DECODE_CANCELED = 0x040000; + private static final int BCRDR_MSG_DECODE_ERROR = 0x080000; + private static final int BCRDR_MSG_DECODE_EVENT = 0x100000; + private static final int BCRDR_MSG_FRAME_ERROR = 0x200000; + private static final int BCRDR_MSG_ALL_MSGS = 0x3F01FF; + + private static final int DECODE_MODE_PREVIEW = 1; + private static final int DECODE_MODE_VIEWFINDER = 2; + private static final int DECODE_MODE_VIDEO = 3; + + private int mNativeContext; // accessed by native methods + private EventHandler mEventHandler; + private AutoFocusCallback mAutoFocusCallback; + private DecodeCallback mDecodeCallback; + private ErrorCallback mErrorCallback; + private VideoCallback mVideoCallback; + private PictureCallback mSnapshotCallback; + private PreviewCallback mPreviewCallback; + private OnZoomChangeListener mZoomListener; + private boolean mOneShot; + private boolean mWithBuffer; + + // /////////////////////////////////////////////////////////////// + // Private native functions + // /////////////////////////////////////////////////////////////// + + private native final void native_autoFocus(); + + private native final void native_cancelAutoFocus(); + + private native final String native_getParameters(); + + private native final void native_release(); + + private native final int setNumParameter(int paramNum, int paramVal); + + private native final int setStrParameter(int paramNum, String paramVal); + + private native final void native_setParameters(String params); + + private native final void native_setup(Object reader_this, int readerId); + + private native final void native_startPreview(int mode); + + private native final void native_takePicture(); + + private native final void setHasPreviewCallback(boolean installed, + boolean manualBuffer); + + private native final void setPreviewDisplay(Surface surface); + + // /////////////////////////////////////////////////////////////// + // Public native functions + // /////////////////////////////////////////////////////////////// + + /** + * Returns the number of physical readers available on this device. + */ + public native static int getNumberOfReaders(); + + /** + * Returns the information about a particular reader. If + * {@link #getNumberOfReaders()} returns N, the valid id is 0 to N-1. + */ + public native static void getReaderInfo(int readerId, + ReaderInfo readerInfo); + + /** + * Re-locks the reader to prevent other processes from accessing it. + * BarCodeReader objects are locked by default unless {@link #unlock()} is + * called. Normally {@link #reconnect()} is used instead. + * + *

+ * If you are not recording video, you probably do not need this method. + * + * @throws RuntimeException + * if the reader cannot be re-locked (for example, if the reader + * is still in use by another process). + */ + public native final void lock(); + + /** + * Unlocks the reader to allow another process to access it. Normally, the + * reader is locked to the process with an active BarCodeReader object until + * {@link #release()} is called. To allow rapid handoff between processes, + * you can call this method to release the reader temporarily for another + * process to use; once the other process is done you can call + * {@link #reconnect()} to reclaim the reader. + * + *

+ * This must be done before calling + * {@link android.media.MediaRecorder#setCamera(BarCodeReader)}. + * + *

+ * If you are not recording video, you probably do not need this method. + * + * @throws RuntimeException + * if the reader cannot be unlocked. + */ + public native final void unlock(); + + /** + * Reconnects to the reader service after another process used it. After + * {@link #unlock()} is called, another process may use the reader; when the + * process is done, you must reconnect to the reader, which will re-acquire + * the lock and allow you to continue using the reader. + * + *

+ * This must be done after {@link android.media.MediaRecorder} is done + * recording if {@link android.media.MediaRecorder#setReader(BarCodeReader)} + * was used. + * + *

+ * If you are not recording video, you probably do not need this method. + * + * @throws IOException + * if a connection cannot be re-established (for example, if the + * reader is still in use by another process). + */ + public native final void reconnect() throws IOException; + + /** + * Returns the value of a specified bar code reader numeric property or + * BCR_ERROR if the specified property number is invalid. + */ + public native final int getNumProperty(int propNum); + + /** + * Returns the value of a specified bar code reader string property or null + * if the specified property number is invalid. + */ + public native final String getStrProperty(int propNum); + + /** + * Returns the value of a specified bar code reader numeric parameter or + * BCR_ERROR if the specified parameter number is invalid. + */ + public native final int getNumParameter(int paramNum); + + /** + * Returns the value of a specified bar code reader string parameter or + * BCR_ERROR if the specified parameter number is invalid. + */ + public native final String getStrParameter(int paramNum); + + /** + * Sets the value of a specified bar code reader numeric parameter. Returns + * BCR_SUCCESS if successful or BCR_ERROR if the specified parameter number + * or value is invalid. + */ + public final int setParameter(int paramNum, int paramVal) { + return (setNumParameter(paramNum, paramVal)); + } + + /** + * Sets the value of a specified bar code reader string parameter. + * + * @param paramNum + * The parameter number to set + * @param paramVal + * The new value for the parameter + * + * @return BCR_SUCCESS if successful or BCR_ERROR if the specified parameter + * number or value is invalid. + */ + public final int setParameter(int paramNum, String paramVal) { + return (setStrParameter(paramNum, paramVal)); + } + + /** + * Sets all bar code reader parameters to their default values. + */ + public native final void setDefaultParameters(); + + /** + * Adds a pre-allocated buffer to the preview callback buffer queue. + * Applications can add one or more buffers to the queue. When a preview + * frame arrives and there is still at least one available buffer, the + * buffer will be used and removed from the queue. Then preview callback is + * invoked with the buffer. If a frame arrives and there is no buffer left, + * the frame is discarded. Applications should add buffers back when they + * finish processing the data in them. + * + *

+ * The size of the buffer is determined by multiplying the preview image + * width, height, and bytes per pixel. The width and height can be read from + * {@link Parameters#getPreviewSize()}. Bytes per pixel can be + * computed from {@link ImageFormat#getBitsPerPixel(int)} / + * 8, using the image format from + * {@link Parameters#getPreviewFormat()}. + * + *

+ * This method is only necessary when + * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} is used. When + * {@link #setOneShotPreviewCallback(PreviewCallback)} is used, buffers are + * automatically allocated. + * + * @param callbackBuffer + * the buffer to add to the queue. The size should be width * + * height * bits_per_pixel / 8. + * @see #setPreviewCallbackWithBuffer(PreviewCallback) + */ + public native final void addCallbackBuffer(byte[] callbackBuffer); + + /** + * Starts capturing frames in video mode. If a surface has been supplied + * with {@link #setPreviewDisplay(SurfaceHolder)}, the frames will be drawn + * to the surface. + * + *

+ * {@link VideoCallback#onVideoFrame(format, width, height, byte[], BarCodeReader)} + * will be called when preview data becomes available. The data passed will + * be in the format and resolution specified by ParamNum.IMG_FILE_FORMAT and + * ParamNum.IMG_VIDEOSUB. + */ + public final void startVideoCapture(VideoCallback cb) { + mVideoCallback = cb; + native_startPreview(DECODE_MODE_VIDEO); + } + + /** + * Starts capturing frames in view finder mode in preparation of taking a + * snapshot. If a surface has been supplied with + * {@link #setPreviewDisplay(SurfaceHolder)}, the frames will be drawn to + * the surface. + */ + public final void startViewFinder() { + native_startPreview(DECODE_MODE_VIEWFINDER); + } + + /** + * Starts capturing frames in preview mode. If a surface has been supplied + * with {@link #setPreviewDisplay(SurfaceHolder)}, the frames will be drawn + * to the surface. + * + *

+ * If {@link #setOneShotPreviewCallback(PreviewCallback)} or + * {@link #setPreviewCallbackWithBuffer(PreviewCallback)} was + * called, + * {@link PreviewCallback#onPreviewFrame(byte[], BarCodeReader)} + * will be called when preview data becomes available. + * + *

+ * If {@link #setImageCallback(BarCodeReader.ImageCallback)} was called, + * {@link PreviewCallback#onVideoFrame(format, width, height, byte[], BarCodeReader)} + * will be called when preview data becomes available. The data passed will + * be in the format and resolution specified by ParamNum.IMG_FILE_FORMAT and + * ParamNum.IMG_VIDEOSUB. + */ + public final void startPreview() { + native_startPreview(DECODE_MODE_PREVIEW); + } + + /** + * Stops capturing and drawing preview frames to the surface, and resets the + * reader for a future call to {@link #startPreview()}. + */ + public native final void stopPreview(); + + /** + * Starts capturing frames and passes the captured frames to the decoder. If + * a surface has been supplied with + * {@link #setPreviewDisplay(SurfaceHolder)}, the frames will be drawn to + * the surface. When a decode occurs or timeout expires and + * {@link #setDecodeCallback(DecodeCallback)} was called, + * {@link #BarCodeReader.DecodeCallback.onDecodeComplete(int, int, byte[], BarCodeReader)} + * will be called with the decode results. + */ + public native final void startDecode(); + + /** + * Starts capturing frames and passes the captured frames to the decoder. If + * a surface has been supplied with + * {@link #setPreviewDisplay(SurfaceHolder)}, the frames will be drawn to + * the surface. If motion is detected, a motion event is generated. If a + * decode occurs a decode event is generated. Decoding continues until + * {@link #stopDecode()} is called. + * + * @param mode + * Indicates the trigger mode to use. It must be either + * {@link #ParamVal.HANDSFREE} or {@link #ParamVal.AUTO_AIM}. + * + * @return BCR_SUCCESS if hands-free mode is successfully started or + * BCR_ERROR if an invalid mode is specified or if a decode session + * is already in progress. + */ + public native final int startHandsFreeDecode(int mode); + + /** + * Stops capturing and decoding frames. + */ + public native final void stopDecode(); + + /** + * Return current preview state. + * + * FIXME: Unhide before release + * + * @hide + */ + public native final boolean previewEnabled(); + + /** + * Zooms to the requested value smoothly. The driver will notify + * {@link OnZoomChangeListener} of the zoom value and whether zoom is + * stopped at the time. For example, suppose the current zoom is 0 and + * startSmoothZoom is called with value 3. The + * {@link OnZoomChangeListener#onZoomChange(int, boolean, BarCodeReader)} + * method will be called three times with zoom values 1, 2, and 3. + * Applications can call {@link #stopSmoothZoom} to stop the zoom earlier. + * Applications should not call startSmoothZoom again or change the zoom + * value before zoom stops. If the supplied zoom value equals to the current + * zoom value, no zoom callback will be generated. This method is supported + * if + * {@link Parameters#isSmoothZoomSupported} + * returns true. + * + * @param value + * zoom value. The valid range is 0 to + * {@link Parameters#getMaxZoom} + * . + * @throws IllegalArgumentException + * if the zoom value is invalid. + * @throws RuntimeException + * if the method fails. + * @see #setZoomChangeListener(OnZoomChangeListener) + */ + public native final void startSmoothZoom(int value); + + /** + * Stops the smooth zoom. Applications should wait for the + * {@link OnZoomChangeListener} to know when the zoom is actually stopped. + * This method is supported if + * {@link Parameters#isSmoothZoomSupported} + * is true. + * + * @throws RuntimeException + * if the method fails. + */ + public native final void stopSmoothZoom(); + + /** + * Set the clockwise rotation of preview display in degrees. This affects + * the preview frames and the picture displayed after snapshot. This method + * is useful for portrait mode applications. Note that preview display of + * front-facing readers is flipped horizontally before the rotation, that + * is, the image is reflected along the central vertical axis of the reader + * sensor. So the users can see themselves as looking into a mirror. + * + *

+ * This does not affect the order of byte array passed in + * {@link PreviewCallback#onPreviewFrame}, JPEG pictures, or recorded + * videos. This method is not allowed to be called during preview. + * + *

+ * If you want to make the reader image show in the same orientation as the + * display, you can use the following code. + * + *

+	 * #import com.motorolasolutions.adc.decoder;
+	 * 
+	 * public static void setReaderDisplayOrientation(Activity activity, int readerId, BarCodeReader reader)
+	 * {
+	 * 	int		result;
+	 * 	int		degrees = 0;
+	 * 	int		rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
+	 *  	BarCodeReader.ReaderInfo	info = new BarCodeReader.ReaderInfo();
+	 * 	BarCodeReader.getReaderInfo(readerId, info);
+	 * 	switch (rotation)
+	 * 	{
+	 * 	case Surface.ROTATION_0:
+	 * 		degrees = 0;
+	 * 		break;
+	 * 	case Surface.ROTATION_90:
+	 * 		degrees = 90;
+	 * 		break;
+	 * 	case Surface.ROTATION_180:
+	 * 		degrees = 180;
+	 * 		break;
+	 * 	case Surface.ROTATION_270:
+	 * 		degrees = 270;
+	 * 		break;
+	 * 	default:
+	 * 		break;
+	 * 	}
+	 * 
+	 * 	if ( info.facing == BarCodeReader.ReaderInfo.BCRDR_FACING_FRONT )
+	 * 	{
+	 * 		result = (info.orientation + degrees) % 360;
+	 * 		result = (360 - result) % 360;	// compensate the mirror
+	 * 	}
+	 * 	else
+	 * 	{
+	 * 		// back-facing
+	 * 		result = (info.orientation - degrees + 360) % 360;
+	 * 	}
+	 * 	reader.setDisplayOrientation(result);
+	 * }
+	 * 
+ * + * @param degrees + * the angle that the picture will be rotated clockwise. Valid + * values are 0, 90, 180, and 270. The starting position is 0 + * (landscape). + * @see #setPreviewDisplay(SurfaceHolder) + */ + public native final void setDisplayOrientation(int degrees); + + // Result codes for functions that return and integer status + + /** + * Function completed successfully + */ + public static final int BCR_SUCCESS = 0; + + /** + * Function failed + */ + public static final int BCR_ERROR = -1; + + // onDecodeComplete status codes passed as the length value + + /** + * onDecodeComplete length value indicating that the decode timed out + */ + public static final int DECODE_STATUS_TIMEOUT = 0; + + /** + * onDecodeComplete length value indicating that the decode was canceled + */ + public static final int DECODE_STATUS_CANCELED = -1; + + /** + * onDecodeComplete length value indicating that an error occurred + */ + public static final int DECODE_STATUS_ERROR = -2; + + // Miscellaneous event ID's + + /** + * Scan mode changed event ID + */ + public static final int BCRDR_EVENT_SCAN_MODE_CHANGED = 5; + + /** + * Motion detected event ID + */ + public static final int BCRDR_EVENT_MOTION_DETECTED = 6; + + /** + * Scanner reset event ID + */ + public static final int BCRDR_EVENT_SCANNER_RESET = 7; + + /** + * Unspecified reader error. + * + * @see ErrorCallback + */ + public static final int BCRDR_ERROR_UNKNOWN = 1; + + /** + * Media server died. In this case, the application must release the + * BarCodeReader object and instantiate a new one. + * + * @see ErrorCallback + */ + public static final int BCRDR_ERROR_SERVER_DIED = 100; + + /** + * Information about a bar code reader + */ + public static class ReaderInfo { + /* + * The facing of the reader is opposite to that of the screen. + */ + public static final int BCRDR_FACING_BACK = 0; + + /** + * The facing of the reader is the same as that of the screen. + */ + public static final int BCRDR_FACING_FRONT = 1; + + /** + * The direction to which the reader faces. It must be BCRDR_FACING_BACK + * or BCRDR_FACING_FRONT. + */ + public int facing; + + /** + * The orientation of the reader image. The value is the angle that the + * reader image needs to be rotated clockwise so it shows correctly on + * the display in its natural orientation. It should be 0, 90, 180, or + * 270. + * + * For example, suppose a device has a naturally tall screen. The + * back-facing reader sensor is mounted in landscape. You are looking at + * the screen. If the top side of the reader sensor is aligned with the + * right edge of the screen in natural orientation, the value should be + * 90. If the top side of a front-facing reader sensor is aligned with + * the right of the screen, the value should be 270. + * + * @see #setDisplayOrientation(int) + * @see Parameters#setRotation(int) + * @see Parameters#setPreviewSize(int, int) + * @see Parameters#setPictureSize(int, int) + * @see Parameters#setJpegThumbnailSize(int, int) + */ + public int orientation; + }; + + /** + * Parameter numbers + */ + public static class ParamNum { + /* Name Number Min Max Default */ + public static final short CODE39 = 0; // 0 1 1 + public static final short UPCA = 1; // 0 1 1 + public static final short UPCE = 2; // 0 1 1 + public static final short EAN13 = 3; // 0 1 1 + public static final short EAN8 = 4; // 0 1 1 + public static final short D25 = 5; // 0 1 0 + public static final short I25 = 6; // 0 1 1 + public static final short CODABAR = 7; // 0 1 0 + public static final short CODE128 = 8; // 0 1 1 + public static final short CODE93 = 9; // 0 1 0 + public static final short CODE11 = 10; // 0 1 0 + public static final short MSI = 11; // 0 1 0 + public static final short UPCE1 = 12; // 0 1 0 + public static final short TRIOPTIC = 13; // 0 1 0 + public static final short EAN128 = 14; // 0 1 1 + public static final short PDF = 15; // 0 1 1 + public static final short SUPPS = 16; // 0 12 SUPP_NONE + public static final short C39_FULL_ASCII = 17; // 0 1 0 + public static final short C39_LEN1 = 18; // 0 55 2 + public static final short C39_LEN2 = 19; // 0 55 55 + public static final short D25_LEN1 = 20; // 0 55 12 + public static final short D25_LEN2 = 21; // 0 55 0 + public static final short I25_LEN1 = 22; // 0 55 14 + public static final short I25_LEN2 = 23; // 0 55 0 + public static final short CBR_LEN1 = 24; // 0 55 5 + public static final short CBR_LEN2 = 25; // 0 55 55 + public static final short C93_LEN1 = 26; // 0 55 4 + public static final short C93_LEN2 = 27; // 0 55 55 + public static final short C11_LEN1 = 28; // 0 55 4 + public static final short C11_LEN2 = 29; // 0 55 55 + public static final short MSI_LEN1 = 30; // 0 55 4 + public static final short MSI_LEN2 = 31; // 0 55 55 + public static final short UPCA_PREAM = 34; // 0 2 1 + public static final short UPCE_PREAM = 35; // 0 2 1 + public static final short UPCE1_PREAM = 36; // 0 2 1 + public static final short UPCE_TO_A = 37; // 0 1 0 + public static final short UPCE1_TO_A = 38; // 0 1 0 + public static final short EAN8_TO_13 = 39; // 0 1 0 + public static final short UPCA_CHK = 40; // 0 1 1 + public static final short UPCE_CHK = 41; // 0 1 1 + public static final short UPCE1_CHK = 42; // 0 1 1 + public static final short XMIT_C39_CHK = 43; // 0 1 0 + public static final short XMIT_I25_CHK = 44; // 0 1 0 + public static final short XMIT_CODE_ID = 45; // 0 2 0 + public static final short XMIT_MSI_CHK = 46; // 0 1 0 + public static final short XMIT_C11_CHK = 47; // 0 1 0 + public static final short C39_CHK_EN = 48; // 0 1 0 + public static final short I25_CHK_TYPE = 49; // 0 2 0 + public static final short MSI_CHK_1_2 = 50; // 0 1 0 + public static final short MSI_CHK_SCHEME = 51; // 0 1 1 + public static final short C11_CHK_TYPE = 52; // 0 2 0 + public static final short CLSI = 54; // 0 1 0 + public static final short NOTIS = 55; // 0 1 0 + public static final short UPC_SEC_LEV = 77; // 0 3 1 + public static final short LIN_SEC_LEV = 78; // 1 4 1 + public static final short SUPP_REDUN = 80; // 2 30 10 + public static final short I25_TO_EAN13 = 82; // 0 1 0 + public static final short BOOKLAND = 83; // 0 1 0 + public static final short ISBT_128 = 84; // 0 1 1 + public static final short COUPON = 85; // 0 1 0 + public static final short CODE32 = 86; // 0 1 0 + public static final short POST_US1 = 89; // 0 1 1 + public static final short POST_US2 = 90; // 0 1 1 + public static final short POST_UK = 91; // 0 1 1 + public static final short SIGNATURE = 93; // 0 1 0 + public static final short XMIT_NO_READ = 94; // 0 1 0 + public static final short POST_US_PARITY = 95; // 0 1 1 + public static final short POST_UK_PARITY = 96; // 0 1 1 + public static final short EMUL_EAN128 = 123; // 0 1 0 + public static final short LASER_ON_PRIM = 136; // 5 99 99 + public static final short LASER_OFF_PRIM = 137; // 0 99 6 + public static final short PRIM_TRIG_MODE = 138; // N/A N/A LEVEL + public static final short C128_LEN1 = 209; // 0 55 0 + public static final short C128_LEN2 = 210; // 0 55 0 + public static final short ISBT_MAX_TRY = 223; // 0 0 10 + public static final short UPDF = 227; // 0 1 0 + public static final short C32_PREFIX = 231; // 0 1 0 + public static final short POSTAL_JAP = 290; // 0 1 1 + public static final short POSTAL_AUS = 291; // 0 1 1 + public static final short DATAMATRIX = 292; // 0 1 1 + public static final short QRCODE = 293; // 0 1 1 + public static final short MAXICODE = 294; // 0 1 1 + public static final short IMG_ILLUM = 298; // 0 1 1 + public static final short IMG_AIM_SNAPSHOT = 300; // 0 1 1 + public static final short IMG_CROP = 301; // 0 1 0 + public static final short IMG_SUBSAMPLE = 302; // 0 3 0 + public static final short IMG_BPP = 303; // 0 2 IMG_BPP_8 + public static final short IMG_FILE_FORMAT = 304; // 1 4 IMG_FORMAT_JPEG + public static final short IMG_JPEG_QUAL = 305; // 5 100 65 + public static final short IMG_AIM_MODE = 306; // 0 2 AIM_ON + public static final short IMG_SIG_FMT = 313; // 1 4 1 + public static final short IMG_SIG_BPP = 314; // 0 2 IMG_BPP_8 + public static final short IMG_CROP_TOP = 315; // 0 479 0 + public static final short IMG_CROP_LEFT = 316; // 0 751 0 + public static final short IMG_CROP_BOT = 317; // 0 479 479 + public static final short IMG_CROP_RIGHT = 318; // 0 751 751 + public static final short IMG_SNAPTIMEOUT = 323; // 0 9 0 + public static final short IMG_VIDEOVF = 324; // 0 1 0 + public static final short POSTAL_DUTCH = 326; // 0 1 1 + public static final short RSS_14 = 338; // 0 1 1 + public static final short RSS_LIM = 339; // 0 1 0 + public static final short RSS_EXP = 340; // 0 1 0 + public static final short CCC_ENABLE = 341; // 0 1 0 + public static final short CCAB_ENABLE = 342; // 0 1 0 + public static final short UPC_COMPOSITE = 344; // 0 2 UPC_ALWAYS + public static final short IMG_IMAGE_ILLUM = 361; // 0 1 1 + public static final short SIGCAP_WIDTH = 366; // 16 752 400 + public static final short SIGCAP_HEIGHT = 367; // 16 480 100 + public static final short TCIF = 371; // 0 1 0 + public static final short MARGIN_RATIO = 381; // N/A N/A 6 + public static final short DEMOTE_RSS = 397; // 0 1 0 + public static final short PICKLIST_MODE = 402; // 0 2 PICKLIST_NEVER + public static final short C25 = 408; // 0 1 0 + public static final short IMAGE_SIG_JPEG_QUALITY = 421; // 5 100 65 + public static final short EMUL_UCCEAN128 = 427; // 0 1 0 + public static final short MIRROR_IMAGE = 537; // 0 2 MIRROR_NEVER + public static final short IMG_ENHANCEMENT = 564; // 0 4 IMG_ENHANCE_OFF + public static final short UQR_EN = 573; // 0 1 1 + public static final short AZTEC = 574; // 0 1 1 + public static final short BOOKLAND_FORMAT = 576; // 0 1 0 + public static final short ISBT_CONCAT_MODE = 577; // 0 0 + // ISBT_CONCAT_NONE + public static final short CHECK_ISBT_TABLE = 578; // 0 0 1 + public static final short SUPP_USER_1 = 579; // N/A N/A 0xFFFF + public static final short SUPP_USER_2 = 580; // N/A N/A 0xFFFF + public static final short K35 = 581; // 0 1 0 + public static final short ONE_D_INVERSE = 586; // 0 2 REGULAR_ONLY + public static final short QR_INVERSE = 587; // 0 2 REGULAR_ONLY + public static final short DATAMATRIX_INVERSE = 588; // 0 2 REGULAR_ONLY + public static final short AZTEC_INVERSE = 589; // 0 2 REGULAR_ONLY + public static final short AIMMODEHANDSFREE = 590; // 0 1 AIM_ON + public static final short POST_US3 = 592; // 0 1 0 + public static final short POST_US4 = 611; // 0 1 0 + public static final short ISSN_EAN_EN = 617; // 0 1 0 + public static final short MATRIX_25_EN = 618; // 0 1 0 + public static final short MATRIX_25_LEN1 = 619; // 0 55 14 + public static final short MATRIX_25_LEN2 = 620; // 0 55 0 + public static final short MATRIX_25_REDUN = 621; // 0 1 0 + public static final short MATRIX_25_CHK_EN = 622; // 0 1 0 + public static final short MATRIX_25_XMIT_CHK = 623; // 0 1 0 + public static final short AIMID_SUPP_FORMAT = 672; // 0 2 1 + public static final short POST_AUS_FMT = 718; // 0 3 0 + public static final short DATABAR_LIM_SEC_LEV = 728; // 0 4 3 + public static final short COUPON_REPORT = 730; // 0 2 1 + public static final short IMG_MOTIONILLUM = 762; // 0 1 1 + }; + + public static class ParamVal { + /** + * Valid values for ParamNum.SUPPS + */ + public static final byte SUPP_NONE = 0; + public static final byte SUPP_ONLY = 1; + public static final byte SUPP_AUTOD = 2; + public static final byte SUPP_SMART = 3; + public static final byte SUPP_378_379 = 4; + public static final byte SUPP_978_979 = 5; + public static final byte SUPP_414_419_434_439 = 6; + public static final byte SUPP_977 = 7; + public static final byte SUPP_491 = 8; + public static final byte SUPP_PROG_1 = 9; + public static final byte SUPP_PROG_1_AND_2 = 10; + public static final byte SUPP_SMART_PLUS_1 = 11; + public static final byte SUPP_SMART_PLUS_1_2 = 12; + + /** + * Valid values for ParamNum.PRIM_TRIG_MODE + */ + public static final byte LEVEL = 0; // Normal soft-trigger mode + public static final byte HANDSFREE = 7; // Presentation/hands-free + // trigger mode + public static final byte AUTO_AIM = 9; // Motion detection turns AIM + // reticle on + + /** + * Valid values for ParamNum.IMG_BPP and ParamNum. IMG_SIG_BPP + */ + public static final byte IMG_BPP_1 = 0; + public static final byte IMG_BPP_4 = 1; + public static final byte IMG_BPP_8 = 2; + + /** + * Valid values for ParamNum.IMG_FILE_FORMAT + */ + public static final byte IMG_FORMAT_JPEG = 1; + public static final byte IMG_FORMAT_BMP = 3; + public static final byte IMG_FORMAT_TIFF = 4; + + /** + * Valid values for ParamNum.IMG_SUBSAMPLE and ParamNum.IMG_VIDEOSUB + */ + public static final byte IMG_SUBSAMPLE_FACTOR_1 = 0; // Full size image + public static final byte IMG_SUBSAMPLE_FACTOR_2 = 1; // Width and height + // divided by 2 + // (1/4 size) + public static final byte IMG_SUBSAMPLE_FACTOR_3 = 2; // Width and height + // divided by 3 + // (1/9 size) + public static final byte IMG_SUBSAMPLE_FACTOR_4 = 3; // Width and height + // divided by 4 + // (1/16 size) + + /** + * Valid values for ParamNum.IMG_AIM_MODE and ParamNum.AIMMODEHANDSFREE + */ + public static final byte AIM_OFF = 0; + public static final byte AIM_ON = 1; + public static final byte AIM_ON_ALWAYS = 2; + + /** + * Valid values for ParamNum.UPC_COMPOSITE + */ + public static final byte UPC_NEVER = 0; + public static final byte UPC_ALWAYS = 1; + public static final byte UPC_AUTOD = 2; + + /** + * Valid values for ParamNum.PICKLIST_MODE + */ + public static final byte PICKLIST_NEVER = 0; + public static final byte PICKLIST_OUT_OF_SCANSTAND = 1; + public static final byte PICKLIST_ALWAYS = 1; + + /** + * Valid values for ParamNum.PICKLIST_MODE + */ + public static final byte MIRROR_NEVER = 0; + public static final byte MIRROR_ALWAYS = 1; + public static final byte MIRROR_AUTO = 2; + + /** + * Valid values for ParamNum.IMG_ENHANCEMENT + */ + public static final byte IMG_ENHANCE_OFF = 0; + public static final byte IMG_ENHANCE_LOW = 1; + public static final byte IMG_ENHANCE_MED = 2; + public static final byte IMG_ENHANCE_HIGH = 3; + public static final byte IMG_ENHANCE_CUSTOM = 4; + + /** + * Valid values for ParamNum.ISBT_CONCAT_MODE + */ + public static final byte ISBT_CONCAT_NONE = 0; + public static final byte ISBT_CONCAT_ONLY = 1; + public static final byte ISBT_CONCAT_AUTOD = 2; + + /** + * Valid values for ParamNum.*_INVERSE + */ + public static final byte REGULAR_ONLY = 0; + public static final byte INVERSE_ONLY = 1; + public static final byte INVERSE_AUTOD = 2; + + /** + * Valid values for ParamNum.PDF_SECURITY_LEVEL + */ + public static final byte PDF_SECURITY_STRICT = 0; + public static final byte PDF_CWLEN_ZERO_OK = 1; + }; + + /** + * Property numbers used to get information from the scanner hardware. + */ + public static class PropertyNum { + /** + * Property number used to get the scanner model number string + */ + public static final int MODEL_NUMBER = 1; + /** + * Property number used to get the scanner serial number string + */ + public static final int SERIAL_NUM = 2; + /** + * Property number used to get the maximum buffer size required for a + * frame + */ + public static final int MAX_FRAME_BUFFER_SIZE = 3; + /** + * Property number used to get the scanner's horizontal resolution + */ + public static final int HORIZONTAL_RES = 4; + /** + * Property number used to get the scanner's vertical resolution + */ + public static final int VERTICAL_RES = 5; + /** + * Property number used to get the Image Kit version string + */ + public static final int IMGKIT_VER = 6; + /** + * Property number used to get the Scan Engine version string + */ + public static final int ENGINE_VER = 7; + } + + /** + * Creates a new BarCodeReader object to access a particular hardware + * reader. + * + *

+ * You must call {@link #release()} when you are done using the reader, + * otherwise it will remain locked and be unavailable to other applications. + * + *

+ * Your application should only have one BarCodeReader object active at a + * time for a particular hardware reader. + * + *

+ * Callbacks from other methods are delivered to the event loop of the + * thread which called open(). If this thread has no event loop, then + * callbacks are delivered to the main application event loop. If there is + * no main application event loop, callbacks are not delivered. + * + *

+ * Caution: On some devices, this method may take a long time to + * complete. It is best to call this method from a worker thread (possibly + * using {@link android.os.AsyncTask}) to avoid blocking the main + * application UI thread. + * + * @param readerId + * the hardware reader to access, between 0 and + * {@link #getNumberOfReaders()}-1. + * + * @return a new BarCodeReader object, connected, locked and ready for use. + * + * @throws RuntimeException + * if connection to the reader service fails (for example, if + * the reader is in use by another process). + */ + public static BarCodeReader open(int readerId) { + Log.i("info", "enter open"); + return (new BarCodeReader(readerId)); + } + + /** + * Creates a new BarCodeReader object to access the first back-facing reader + * on the device. If the device does not have a back-facing reader, this + * returns null + * + * @see #open(int) + */ + public static BarCodeReader open() { + ReaderInfo readerInfo; + + int iIdx; + int iNumReaders; + + iNumReaders = getNumberOfReaders(); + readerInfo = new ReaderInfo(); + for (iIdx = 0; iIdx < iNumReaders; ++iIdx) { + BarCodeReader.getReaderInfo(iIdx, readerInfo); + if (readerInfo.facing == ReaderInfo.BCRDR_FACING_BACK) { + return (new BarCodeReader(iIdx)); + } + } + return (null); + } + + BarCodeReader(int readerId) { + Looper aLooper; + + mEventHandler = null; + mAutoFocusCallback = null; + mDecodeCallback = null; + mErrorCallback = null; + mPreviewCallback = null; + mSnapshotCallback = null; + mVideoCallback = null; + mZoomListener = null; + + aLooper = Looper.myLooper(); + if (null == aLooper) + aLooper = Looper.getMainLooper(); + if (aLooper != null) { + mEventHandler = new EventHandler(this, aLooper); + } + Log.i("info","-----before native_setup---"); + native_setup(new WeakReference(this), readerId); + Log.i("info","-----after native_setup---"); + } + + protected void finalize() { + native_release(); + } + + /** + * Disconnects and releases the BarCodeReader object resources. + * + *

+ * You must call this as soon as you're done with the BarCodeReader object. + *

+ */ + public final void release() { + native_release(); + } + + /** + * Sets the {@link Surface} to be used for live preview. A surface is + * necessary for preview, and preview is necessary to take pictures. The + * same surface can be re-set without harm. + * + *

+ * The {@link SurfaceHolder} must already contain a surface when this method + * is called. If you are using {@link android.view.SurfaceView}, you will + * need to register a {@link SurfaceHolder.Callback} with + * {@link SurfaceHolder#addCallback(SurfaceHolder.Callback)} and wait for + * {@link SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)} before + * calling setPreviewDisplay() or starting preview. + * + *

+ * This method must be called before {@link #startPreview()}. The one + * exception is that if the preview surface is not set (or set to null) + * before startPreview() is called, then this method may be called once with + * a non-null parameter to set the preview surface. (This allows reader + * setup and surface creation to happen in parallel, saving time.) The + * preview surface may not otherwise change while preview is running. + * + * @param holder + * containing the Surface on which to place the preview, or null + * to remove the preview surface + * @throws IOException + * if the method fails (for example, if the surface is + * unavailable or unsuitable). + */ + public final void setPreviewDisplay(SurfaceHolder holder) + throws IOException { + if (holder != null) { + setPreviewDisplay(holder.getSurface()); + } else { + setPreviewDisplay((Surface) null); + } + } + + /** + * Callback interface used to notify on completion of reader auto focus. + * + *

+ * Devices that do not support auto-focus will receive a "fake" callback to + * this interface. If your application needs auto-focus and should not be + * installed on devices without auto-focus, you must declare that + * your app uses the + * {@code android.hardware.camera.autofocus} feature, in the + * <uses-feature> + * manifest element. + *

+ * + * @see #autoFocus(AutoFocusCallback) + */ + public interface AutoFocusCallback { + /** + * Called when the reader auto focus completes. If the reader does not + * support auto-focus and autoFocus is called, onAutoFocus will be + * called immediately with a fake value of success set to + * true. + * + * @param success + * true if focus was successful, false if otherwise + * @param reader + * the BarCodeReader service object + */ + void onAutoFocus(boolean success, BarCodeReader reader); + }; + + /** + * Starts reader auto-focus and registers a callback function to run when + * the reader is focused. This method is only valid when frame acquisition + * is active. + * + *

+ * Callers should check + * {@link Parameters#getFocusMode()} + * to determine if this method should be called. If the reader does not + * support auto-focus, it is a no-op and + * {@link AutoFocusCallback#onAutoFocus(boolean, BarCodeReader)} callback + * will be called immediately. + * + *

+ * If your application should not be installed on devices without + * auto-focus, you must declare that your application uses auto-focus with + * the <uses-feature> + * manifest element. + *

+ * + *

+ * If the current flash mode is not + * {@link Parameters#FLASH_MODE_OFF} + * , flash may be fired during auto-focus, depending on the driver and + * reader hardware. + *

+ * + * @param cb + * the callback to run + * @see #cancelAutoFocus() + */ + public final void autoFocus(AutoFocusCallback cb) { + mAutoFocusCallback = cb; + native_autoFocus(); + } + + /** + * Cancels any auto-focus function in progress. Whether or not auto-focus is + * currently in progress, this function will return the focus position to + * the default. If the reader does not support auto-focus, this is a no-op. + * + * @see #autoFocus(AutoFocusCallback) + */ + public final void cancelAutoFocus() { + mAutoFocusCallback = null; + native_cancelAutoFocus(); + } + + /** + * Callback interface used to deliver decode results. + * + * @see #setDecodeCallback(DecodeCallback) + * @see #startDecode() + */ + public interface DecodeCallback { + /** + * Called when a decode operation has completed, either due to a + * timeout, a successful decode or canceled by the user. This callback + * is invoked on the event thread {@link #open(int)} was called from. + * + * @param symbology + * the symbology of decoded bar code if any + * @param status + * if positive, indicates the length of the bar code data, + * otherwise, DECODE_STATUS_TIMEOUT if the request timed out + * or DECODE_STATUS_CANCELED if stopDecode() is called before + * a successful decode or timeout. + * @param data + * the contents of the decoded bar code + * @param reader + * the BarCodeReader service object. + */ + void onDecodeComplete(int symbology, int length, byte[] data, + BarCodeReader reader); + + /** + * Called to indicate that the decoder detected an event such as MOTION + * DECTECTED. This callback is invoked on the event thread + * {@link #open(int)} was called from. + * + * @param event + * the type of event that has occurred + * @param info + * additional event information, if any, else zero + * @param data + * data associated with the event, if any, else null + * @param reader + * the BarCodeReader service object. + */ + void onEvent(int event, int info, byte[] data, BarCodeReader reader); + }; + + /** + * Specifies whether or not automatic auto-focus should be performed during + * decode operations and if so, how many frames to initially wait before + * issuing the the first auto-focus request and how many frames to wait + * after receiving an auto-focus complete notification before issuing + * another request. An application should call + * {@link #Parameters.setFocusMode(String)} and + * {@link #setParameters(Parameters)} to set the focus mode to + * {@link #BarCodeReader.Parameters.FOCUS_MODE_AUTO}. + * + * When this function is used to enable automatic auto-focus requests, + * auto-focus callbacks are disabled. If an application needs to receive + * auto-focus callbacks, it should issue its own + * {@link #autoFocus(AutoFocusCallback)} requests and should not call this + * function. + * + * @param initialDelay + * the number of frames to process when a decode session is + * started before issuing the first auto-focus request. If this + * parameter is less than one and secondaryDelay is greater than + * zero, an auto-focus request will be issued as soon as the + * decode session is started. If both initialDelay and + * secondaryDelay are both less than one, no auto-focus requests + * will be issued. + * @param secondaryDelay + * the number of frames to process after receiving an auto-focus + * complete notification before issuing another auto-focus + * request. If this parameter is less than one, only the initial + * auto-focus request, if any, will be performed. + */ + public native final void setAutoFocusDelay(int initialDelay, + int secondaryDelay); + + /** + * Installs callbacks to be invoked when a decode request completes or a + * decoder event occurs. This method can be called at any time, even while a + * decode request is active. Any other decode callbacks are overridden. + * + * @param cb + * a callback object that receives a notification of a completed, + * decode request or null to stop receiving decode callbacks. + */ + public final void setDecodeCallback(DecodeCallback cb) { + mDecodeCallback = cb; + } + + /** + * Callback interface used to supply image data from a photo capture. + * + * @see #takePicture(PictureCallback) + */ + public interface PictureCallback { + /** + * Called when image data is available after a picture is taken. The + * format of the data depends on the current value of the + * IMG_FILE_FORMAT and IMG_VIDEOSUB parameters. + * + * @param format + * format of the image (IMG_FORMAT_JPEG, IMG_FORMAT_BMP, or + * IMG_FORMAT_TIFF) + * @param with + * horizontal resolution of the image + * @param height + * vertical resolution of the image + * @param data + * a byte array of the picture data + * @param reader + * the BarCodeReader service object + */ + void onPictureTaken(int format, int width, int height, byte[] data, + BarCodeReader reader); + }; + + /** + * Triggers an asynchronous image capture. The picture taken callback occurs + * when a scaled, fully processed image is available + * + *

+ * This method is only valid when the decoder is idle or view finder mode is + * active (after calling {@link #startViewFinder()}). Image capture will be + * stopped after the picture taken callback is called. Callers must call + * {@link #startViewFiner()} and/or takePicture() again if they want to + * re-start the view finder or take more pictures. + * + *

+ * After calling this method, you must not call {@link #startPreview()}, + * {@link #startViewFinder()} or take another picture until the picture + * taken callback has returned. + * + * @param cb + * the callback for processed image data + */ + public final void takePicture(PictureCallback cb) { + mSnapshotCallback = cb; + try { + native_takePicture(); + } catch (Throwable thrw) { + // TODO: Call error callback? + } + } + + /** + * Callback interface used to supply image data in video capture mode. + * + * @see #startVideoCapture(VideoCallback) + */ + public interface VideoCallback { + /** + * Called when image data is available during video capture mode. The + * format of the data depends on the current value of the + * IMG_FILE_FORMAT and IMG_VIDEOSUB parameters. + * + * @param format + * format of the image (IMG_FORMAT_JPEG, IMG_FORMAT_BMP, or + * IMG_FORMAT_TIFF) + * @param with + * horizontal resolution of the image + * @param height + * vertical resolution of the image + * @param data + * a byte array of the video frame + * @param reader + * the BarCodeReader service object + */ + void onVideoFrame(int format, int width, int height, byte[] data, + BarCodeReader reader); + }; + + /** + * Callback interface used to deliver copies of preview frames as they are + * displayed. + * + * @see #setOneShotPreviewCallback(PreviewCallback) + * @see #setPreviewCallbackWithBuffer(PreviewCallback) + * @see #startPreview() + */ + public interface PreviewCallback { + /** + * Called as preview frames are displayed. This callback is invoked on + * the event thread {@link #open(int)} was called from. + * + * @param data + * the contents of the preview frame in the format defined by + * {@link ImageFormat}, which can be queried + * with + * {@link Parameters#getPreviewFormat()} + * . If + * {@link Parameters#setPreviewFormat(int)} + * is never called, the default will be the YCbCr_420_SP + * (NV21) format. + * @param reader + * the BarCodeReader service object. + */ + void onPreviewFrame(byte[] data, BarCodeReader reader); + }; + + /** + * Installs a callback to be invoked for the next preview frame in addition + * to displaying it on the screen. After one invocation, the callback is + * cleared. This method can be called any time, even when preview is live. + * Any other preview callbacks are overridden. + * + * @param cb + * a callback object that receives a copy of the next preview + * frame, or null to stop receiving callbacks. + */ + public final void setOneShotPreviewCallback(PreviewCallback cb) { + mPreviewCallback = cb; + mOneShot = true; + mWithBuffer = false; + setHasPreviewCallback(cb != null, false); + } + + /** + * Installs a callback to be invoked for every preview frame, using buffers + * supplied with {@link #addCallbackBuffer(byte[])}, in addition to + * displaying them on the screen. The callback will be repeatedly called for + * as long as preview is active and buffers are available. Any other preview + * callbacks are overridden. + * + *

+ * The purpose of this method is to improve preview efficiency and frame + * rate by allowing preview frame memory reuse. You must call + * {@link #addCallbackBuffer(byte[])} at some point -- before or after + * calling this method -- or no callbacks will received. + * + * The buffer queue will be cleared if this method is called with a null + * callback or if + * {@link #setOneShotPreviewCallback(PreviewCallback)} is + * called. + * + * @param cb + * a callback object that receives a copy of the preview frame, + * or null to stop receiving callbacks and clear the buffer + * queue. + * @see #addCallbackBuffer(byte[]) + */ + public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { + mPreviewCallback = cb; + mOneShot = false; + mWithBuffer = true; + setHasPreviewCallback(cb != null, true); + } + + private class EventHandler extends Handler { + private BarCodeReader mReader; + + public EventHandler(BarCodeReader rdr, Looper looper) { + super(looper); + mReader = rdr; + } + + @Override + public void handleMessage(Message msg) { + Log.v(TAG, String.format("Event message: %X, arg1=%d, arg2=%d", + msg.what, msg.arg1, msg.arg2)); + switch (msg.what) { + case BCRDR_MSG_DECODE_COMPLETE: + if (mDecodeCallback != null) { + mDecodeCallback.onDecodeComplete(msg.arg1, msg.arg2, + (byte[]) msg.obj, mReader); + } + return; + + case BCRDR_MSG_DECODE_TIMEOUT: + if (mDecodeCallback != null) { + mDecodeCallback.onDecodeComplete(0, 0, (byte[]) msg.obj, + mReader); + } + return; + + case BCRDR_MSG_DECODE_CANCELED: + if (mDecodeCallback != null) { + mDecodeCallback.onDecodeComplete(0, DECODE_STATUS_CANCELED, + (byte[]) msg.obj, mReader); + } + return; + + case BCRDR_MSG_FRAME_ERROR: + // TODO: + case BCRDR_MSG_DECODE_ERROR: + if (mDecodeCallback != null) { + mDecodeCallback.onDecodeComplete(0, DECODE_STATUS_ERROR, + (byte[]) msg.obj, mReader); + } + return; + + case BCRDR_MSG_DECODE_EVENT: + if (mDecodeCallback != null) { + mDecodeCallback.onEvent(msg.arg1, msg.arg2, + (byte[]) msg.obj, mReader); + } + return; + + case BCRDR_MSG_SHUTTER: + // We do not support the shutter callback + return; + + case BCRDR_MSG_COMPRESSED_IMAGE: + if (mSnapshotCallback != null) { + int iCX; + int iCY; + + iCX = (msg.arg1 >> 0) & 0xFFFF; + iCY = (msg.arg1 >> 16) & 0xFFFF; + mSnapshotCallback.onPictureTaken(msg.arg2, iCX, iCY, + (byte[]) msg.obj, mReader); + } else { + Log.e(TAG, + "BCRDR_MSG_COMPRESSED_IMAGE event with no snapshot callback"); + } + return; + + case BCRDR_MSG_VIDEO_FRAME: + if (mVideoCallback != null) { + int iCX; + int iCY; + + iCX = (msg.arg1 >> 0) & 0xFFFF; + iCY = (msg.arg1 >> 16) & 0xFFFF; + mVideoCallback.onVideoFrame(msg.arg2, iCX, iCY, + (byte[]) msg.obj, mReader); + } else { + Log.e(TAG, + "BCRDR_MSG_VIDEO_FRAME event with no video callback"); + } + return; + + case BCRDR_MSG_PREVIEW_FRAME: + if (mPreviewCallback != null) { + PreviewCallback cb = mPreviewCallback; + if (mOneShot) { + // Clear the callback variable before the callback + // in case the app calls setOneShotPreviewCallback from + // the callback function + mPreviewCallback = null; + } else if (!mWithBuffer) { + // We're faking the reader preview mode to prevent + // the app from being flooded with preview frames. + // Set to one-shot mode again. + setHasPreviewCallback(true, false); + } + cb.onPreviewFrame((byte[]) msg.obj, mReader); + } + return; + + case BCRDR_MSG_FOCUS: + if (mAutoFocusCallback != null) { + mAutoFocusCallback.onAutoFocus( + msg.arg1 == 0 ? false : true, mReader); + } + return; + + case BCRDR_MSG_ZOOM: + if (mZoomListener != null) { + mZoomListener + .onZoomChange(msg.arg1, msg.arg2 != 0, mReader); + } + return; + + case BCRDR_MSG_ERROR: + Log.e(TAG, "Error " + msg.arg1); + if (mErrorCallback != null) { + mErrorCallback.onError(msg.arg1, mReader); + } + return; + + default: + Log.e(TAG, "Unknown message type " + msg.what); + return; + } + } + }; + + private static void postEventFromNative(Object reader_ref, int what, + int arg1, int arg2, Object obj) { + @SuppressWarnings("unchecked") + BarCodeReader c = (BarCodeReader) ((WeakReference) reader_ref) + .get(); + if ((c != null) && (c.mEventHandler != null)) { + Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); + c.mEventHandler.sendMessage(m); + } + } + + /** + * Callback interface for zoom changes during a smooth zoom operation. + * + * @see #setZoomChangeListener(OnZoomChangeListener) + * @see #startSmoothZoom(int) + */ + public interface OnZoomChangeListener { + /** + * Called when the zoom value has changed during a smooth zoom. + * + * @param zoomValue + * the current zoom value. In smooth zoom mode, reader calls + * this for every new zoom value. + * @param stopped + * whether smooth zoom is stopped. If the value is true, this + * is the last zoom update for the application. + * @param reader + * the BarCodeReader service object + */ + void onZoomChange(int zoomValue, boolean stopped, BarCodeReader reader); + }; + + /** + * Registers a listener to be notified when the zoom value is updated by the + * reader driver during smooth zoom. + * + * @param listener + * the listener to notify + * @see #startSmoothZoom(int) + */ + public final void setZoomChangeListener(OnZoomChangeListener listener) { + mZoomListener = listener; + } + + /** + * Callback interface for reader error notification. + * + * @see #setErrorCallback(ErrorCallback) + */ + public interface ErrorCallback { + /** + * Callback for reader errors. + * + * @param error + * error code: + *

    + *
  • {@link #BCRDR_ERROR_UNKNOWN} + *
  • {@link #BCRDR_ERROR_SERVER_DIED} + *
+ * @param reader + * the BarCodeReader service object + */ + void onError(int error, BarCodeReader reader); + }; + + /** + * Registers a callback to be invoked when an error occurs. + * + * @param cb + * The callback to run + */ + public final void setErrorCallback(ErrorCallback cb) { + mErrorCallback = cb; + } + + /** + * Changes the settings for this BarCodeReader service. + * + * @param params + * the Parameters to use for this BarCodeReader service + * @throws RuntimeException + * if any parameter is invalid or not supported. + * @see #getParameters() + */ + public void setParameters(Parameters params) { + native_setParameters(params.flatten()); + } + + /** + * Returns the current settings for this BarCodeReader service. If + * modifications are made to the returned Parameters, they must be passed to + * {@link #setParameters(Parameters)} to take effect. + * + * @see #setParameters(Parameters) + */ + public Parameters getParameters() { + Parameters p = new Parameters(); + String s = native_getParameters(); + p.unflatten(s); + return (p); + } + + /** + * Image size (width and height dimensions). + */ + public class Size { + /** + * Sets the dimensions for snapshots. + * + * @param w + * the image width (pixels) + * @param h + * the image height (pixels) + */ + public Size(int w, int h) { + width = w; + height = h; + } + + /** + * Compares {@code obj} to this size. + * + * @param obj + * the object to compare this size with. + * @return {@code true} if the width and height of {@code obj} is the + * same as those of this size. {@code false} otherwise. + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Size)) { + return (false); + } + Size s = (Size) obj; + return ((width == s.width) && (height == s.height)); + } + + @Override + public int hashCode() { + return ((width * 32713) + height); + } + + // width of the image + public int width; + // height of the image + public int height; + }; + + /** + * BarCodeReader service settings. + * + *

+ * To make reader parameters take effect, applications have to call + * {@link BarCodeReader#setParameters(Parameters)}. For + * example, after {@link Parameters#setWhiteBalance} is + * called, white balance is not actually changed until + * {@link BarCodeReader#setParameters(Parameters)} is called + * with the changed parameters object. + * + *

+ * Different devices may have different reader capabilities, such as picture + * size or flash modes. The application should query the reader capabilities + * before setting parameters. For example, the application should call + * {@link Parameters#getSupportedColorEffects()} before + * calling {@link Parameters#setColorEffect(String)}. If the + * reader does not support color effects, + * {@link Parameters#getSupportedColorEffects()} will return + * null. + */ + public class Parameters { + // Parameter keys to communicate with the reader driver. + private static final String KEY_PREVIEW_SIZE = "preview-size"; + private static final String KEY_PREVIEW_FORMAT = "preview-format"; + private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; + private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; + private static final String KEY_PICTURE_SIZE = "picture-size"; + private static final String KEY_PICTURE_FORMAT = "picture-format"; + private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; + private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; + private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; + private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; + private static final String KEY_JPEG_QUALITY = "jpeg-quality"; + private static final String KEY_ROTATION = "rotation"; + private static final String KEY_GPS_LATITUDE = "gps-latitude"; + private static final String KEY_GPS_LONGITUDE = "gps-longitude"; + private static final String KEY_GPS_ALTITUDE = "gps-altitude"; + private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; + private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; + private static final String KEY_WHITE_BALANCE = "whitebalance"; + private static final String KEY_EFFECT = "effect"; + private static final String KEY_ANTIBANDING = "antibanding"; + private static final String KEY_SCENE_MODE = "scene-mode"; + private static final String KEY_FLASH_MODE = "flash-mode"; + private static final String KEY_FOCUS_MODE = "focus-mode"; + private static final String KEY_FOCAL_LENGTH = "focal-length"; + private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; + private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; + private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; + private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; + private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; + private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; + private static final String KEY_ZOOM = "zoom"; + private static final String KEY_MAX_ZOOM = "max-zoom"; + private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; + private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; + private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; + private static final String KEY_FOCUS_DISTANCES = "focus-distances"; + + // Parameter key suffix for supported values. + private static final String SUPPORTED_VALUES_SUFFIX = "-values"; + + private static final String TRUE = "true"; + + // Values for white balance settings. + public static final String WHITE_BALANCE_AUTO = "auto"; + public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; + public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; + public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; + public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; + public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; + public static final String WHITE_BALANCE_TWILIGHT = "twilight"; + public static final String WHITE_BALANCE_SHADE = "shade"; + + // Values for color effect settings. + public static final String EFFECT_NONE = "none"; + public static final String EFFECT_MONO = "mono"; + public static final String EFFECT_NEGATIVE = "negative"; + public static final String EFFECT_SOLARIZE = "solarize"; + public static final String EFFECT_SEPIA = "sepia"; + public static final String EFFECT_POSTERIZE = "posterize"; + public static final String EFFECT_WHITEBOARD = "whiteboard"; + public static final String EFFECT_BLACKBOARD = "blackboard"; + public static final String EFFECT_AQUA = "aqua"; + + // Values for antibanding settings. + public static final String ANTIBANDING_AUTO = "auto"; + public static final String ANTIBANDING_50HZ = "50hz"; + public static final String ANTIBANDING_60HZ = "60hz"; + public static final String ANTIBANDING_OFF = "off"; + + // Values for flash mode settings. + /** + * Flash will not be fired. + */ + public static final String FLASH_MODE_OFF = "off"; + + /** + * Flash will be fired automatically when required. The flash may be + * fired during preview, auto-focus, or snapshot depending on the + * driver. + */ + public static final String FLASH_MODE_AUTO = "auto"; + + /** + * Flash will always be fired during snapshot. The flash may also be + * fired during preview or auto-focus depending on the driver. + */ + public static final String FLASH_MODE_ON = "on"; + + /** + * Flash will be fired in red-eye reduction mode. + */ + public static final String FLASH_MODE_RED_EYE = "red-eye"; + + /** + * Constant emission of light during preview, auto-focus and snapshot. + * This can also be used for video recording. + */ + public static final String FLASH_MODE_TORCH = "torch"; + + /** + * Scene mode is off. + */ + public static final String SCENE_MODE_AUTO = "auto"; + + /** + * Take photos of fast moving objects. Same as + * {@link #SCENE_MODE_SPORTS}. + */ + public static final String SCENE_MODE_ACTION = "action"; + + /** + * Take people pictures. + */ + public static final String SCENE_MODE_PORTRAIT = "portrait"; + + /** + * Take pictures on distant objects. + */ + public static final String SCENE_MODE_LANDSCAPE = "landscape"; + + /** + * Take photos at night. + */ + public static final String SCENE_MODE_NIGHT = "night"; + + /** + * Take people pictures at night. + */ + public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; + + /** + * Take photos in a theater. Flash light is off. + */ + public static final String SCENE_MODE_THEATRE = "theatre"; + + /** + * Take pictures on the beach. + */ + public static final String SCENE_MODE_BEACH = "beach"; + + /** + * Take pictures on the snow. + */ + public static final String SCENE_MODE_SNOW = "snow"; + + /** + * Take sunset photos. + */ + public static final String SCENE_MODE_SUNSET = "sunset"; + + /** + * Avoid blurry pictures (for example, due to hand shake). + */ + public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; + + /** + * For shooting firework displays. + */ + public static final String SCENE_MODE_FIREWORKS = "fireworks"; + + /** + * Take photos of fast moving objects. Same as + * {@link #SCENE_MODE_ACTION}. + */ + public static final String SCENE_MODE_SPORTS = "sports"; + + /** + * Take indoor low-light shot. + */ + public static final String SCENE_MODE_PARTY = "party"; + + /** + * Capture the naturally warm color of scenes lit by candles. + */ + public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; + + /** + * Applications are looking for a barcode. BarCodeReader driver will be + * optimized for barcode reading. + */ + public static final String SCENE_MODE_BARCODE = "barcode"; + + /** + * Auto-focus mode. Applications should call + * {@link #autoFocus(AutoFocusCallback)} to start the focus in this + * mode. + */ + public static final String FOCUS_MODE_AUTO = "auto"; + + /** + * Focus is set at infinity. Applications should not call + * {@link #autoFocus(AutoFocusCallback)} in this mode. + */ + public static final String FOCUS_MODE_INFINITY = "infinity"; + + /** + * Macro (close-up) focus mode. Applications should call + * {@link #autoFocus(AutoFocusCallback)} to start the focus in this + * mode. + */ + public static final String FOCUS_MODE_MACRO = "macro"; + + /** + * Focus is fixed. The reader is always in this mode if the focus is not + * adjustable. If the reader has auto-focus, this mode can fix the + * focus, which is usually at hyperfocal distance. Applications should + * not call {@link #autoFocus(AutoFocusCallback)} in this mode. + */ + public static final String FOCUS_MODE_FIXED = "fixed"; + + /** + * Extended depth of field (EDOF). Focusing is done digitally and + * continuously. Applications should not call + * {@link #autoFocus(AutoFocusCallback)} in this mode. + */ + public static final String FOCUS_MODE_EDOF = "edof"; + + /** + * Continuous auto focus mode intended for video recording. The reader + * continuously tries to focus. This is ideal for shooting video. Auto + * focus starts when the parameter is set. Applications should not call + * {@link #autoFocus(AutoFocusCallback)} in this mode. To stop + * continuous focus, applications should change the focus mode to other + * modes. + */ + public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; + + // Indices for focus distance array. + /** + * The array index of near focus distance for use with + * {@link #getFocusDistances(float[])}. + */ + public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; + + /** + * The array index of optimal focus distance for use with + * {@link #getFocusDistances(float[])}. + */ + public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; + + /** + * The array index of far focus distance for use with + * {@link #getFocusDistances(float[])}. + */ + public static final int FOCUS_DISTANCE_FAR_INDEX = 2; + + /** + * The array index of minimum preview fps for use with + * {@link #getPreviewFpsRange(int[])} or + * {@link #getSupportedPreviewFpsRange()}. + */ + public static final int PREVIEW_FPS_MIN_INDEX = 0; + + /** + * The array index of maximum preview fps for use with + * {@link #getPreviewFpsRange(int[])} or + * {@link #getSupportedPreviewFpsRange()}. + */ + public static final int PREVIEW_FPS_MAX_INDEX = 1; + + // Formats for setPreviewFormat and setPictureFormat. + private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; + private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; + private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; + private static final String PIXEL_FORMAT_RGB565 = "rgb565"; + private static final String PIXEL_FORMAT_JPEG = "jpeg"; + + private HashMap mMap; + + private Parameters() { + mMap = new HashMap(); + } + + /** + * Writes the current Parameters to the log. + * + * @hide + * @deprecated + */ + public void dump() { + Log.e(TAG, "dump: size=" + mMap.size()); + for (String k : mMap.keySet()) { + Log.e(TAG, "dump: " + k + "=" + mMap.get(k)); + } + } + + /** + * Creates a single string with all the parameters set in this + * Parameters object. + *

+ * The {@link #unflatten(String)} method does the reverse. + *

+ * + * @return a String with all values from this Parameters object, in + * semi-colon delimited key-value pairs + */ + public String flatten() { + StringBuilder flattened = new StringBuilder(); + for (String k : mMap.keySet()) { + flattened.append(k); + flattened.append("="); + flattened.append(mMap.get(k)); + flattened.append(";"); + } + // chop off the extra semicolon at the end + flattened.deleteCharAt(flattened.length() - 1); + return (flattened.toString()); + } + + /** + * Takes a flattened string of parameters and adds each one to this + * Parameters object. + *

+ * The {@link #flatten()} method does the reverse. + *

+ * + * @param flattened + * a String of parameters (key-value paired) that are + * semi-colon delimited + */ + public void unflatten(String flattened) { + StringTokenizer tokenizer; + + int iPos; + String strKV; + + mMap.clear(); + + tokenizer = new StringTokenizer(flattened, ";"); + while (tokenizer.hasMoreElements()) { + strKV = tokenizer.nextToken(); + iPos = strKV.indexOf('='); + if (iPos == -1) { + continue; + } + mMap.put(strKV.substring(0, iPos), strKV.substring(iPos + 1)); + } + } + + public void remove(String key) { + mMap.remove(key); + } + + /** + * Sets a String parameter. + * + * @param key + * the key name for the parameter + * @param value + * the String value of the parameter + */ + public void set(String key, String value) { + if ((key.indexOf('=') != -1) || (key.indexOf(';') != -1)) { + Log.e(TAG, "Key \"" + key + + "\" contains invalid character (= or ;)"); + return; + } + if ((value.indexOf('=') != -1) || (value.indexOf(';') != -1)) { + Log.e(TAG, "Value \"" + value + + "\" contains invalid character (= or ;)"); + return; + } + + mMap.put(key, value); + } + + /** + * Sets an integer parameter. + * + * @param key + * the key name for the parameter + * @param value + * the int value of the parameter + */ + public void set(String key, int value) { + if ((key.indexOf('=') != -1) || (key.indexOf(';') != -1)) { + Log.e(TAG, "Key \"" + key + + "\" contains invalid character (= or ;)"); + return; + } + mMap.put(key, Integer.toString(value)); + } + + /** + * Returns the value of a String parameter. + * + * @param key + * the key name for the parameter + * @return the String value of the parameter + */ + public String get(String key) { + return (mMap.get(key)); + } + + /** + * Returns the value of an integer parameter. + * + * @param key + * the key name for the parameter + * @return the int value of the parameter + */ + public int getInt(String key) { + return (getInt(key, -1)); + } + + /** + * Sets the dimensions for preview pictures. + * + * The sides of width and height are based on reader orientation. That + * is, the preview size is the size before it is rotated by display + * orientation. So applications need to consider the display orientation + * while setting preview size. For example, suppose the reader supports + * both 480x320 and 320x480 preview sizes. The application wants a 3:2 + * preview ratio. If the display orientation is set to 0 or 180, preview + * size should be set to 480x320. If the display orientation is set to + * 90 or 270, preview size should be set to 320x480. The display + * orientation should also be considered while setting picture size and + * thumbnail size. + * + * @param width + * the width of the pictures, in pixels + * @param height + * the height of the pictures, in pixels + * @see #setDisplayOrientation(int) + * @see #getReaderInfo(int, ReaderInfo) + * @see #setPictureSize(int, int) + * @see #setJpegThumbnailSize(int, int) + */ + public void setPreviewSize(int width, int height) { + String v = Integer.toString(width) + "x" + Integer.toString(height); + set(KEY_PREVIEW_SIZE, v); + } + + /** + * Returns the dimensions setting for preview pictures. + * + * @return a Size object with the height and width setting for the + * preview picture + */ + public Size getPreviewSize() { + String pair = get(KEY_PREVIEW_SIZE); + return (strToSize(pair)); + } + + /** + * Gets the supported preview sizes. + * + * @return a list of Size object. This method will always return a list + * with at least one element. + */ + public List getSupportedPreviewSizes() { + String str = get(KEY_PREVIEW_SIZE + SUPPORTED_VALUES_SUFFIX); + return (splitSize(str)); + } + + /** + * Sets the dimensions for EXIF thumbnail in Jpeg picture. If + * applications set both width and height to 0, EXIF will not contain + * thumbnail. + * + * Applications need to consider the display orientation. See + * {@link #setPreviewSize(int,int)} for reference. + * + * @param width + * the width of the thumbnail, in pixels + * @param height + * the height of the thumbnail, in pixels + * @see #setPreviewSize(int,int) + */ + public void setJpegThumbnailSize(int width, int height) { + set(KEY_JPEG_THUMBNAIL_WIDTH, width); + set(KEY_JPEG_THUMBNAIL_HEIGHT, height); + } + + /** + * Returns the dimensions for EXIF thumbnail in Jpeg picture. + * + * @return a Size object with the height and width setting for the EXIF + * thumbnails + */ + public Size getJpegThumbnailSize() { + return (new Size(getInt(KEY_JPEG_THUMBNAIL_WIDTH), + getInt(KEY_JPEG_THUMBNAIL_HEIGHT))); + } + + /** + * Gets the supported jpeg thumbnail sizes. + * + * @return a list of Size object. This method will always return a list + * with at least two elements. Size 0,0 (no thumbnail) is always + * supported. + */ + public List getSupportedJpegThumbnailSizes() { + String str = get(KEY_JPEG_THUMBNAIL_SIZE + SUPPORTED_VALUES_SUFFIX); + return (splitSize(str)); + } + + /** + * Sets the quality of the EXIF thumbnail in Jpeg picture. + * + * @param quality + * the JPEG quality of the EXIF thumbnail. The range is 1 to + * 100, with 100 being the best. + */ + public void setJpegThumbnailQuality(int quality) { + set(KEY_JPEG_THUMBNAIL_QUALITY, quality); + } + + /** + * Returns the quality setting for the EXIF thumbnail in Jpeg picture. + * + * @return the JPEG quality setting of the EXIF thumbnail. + */ + public int getJpegThumbnailQuality() { + return (getInt(KEY_JPEG_THUMBNAIL_QUALITY)); + } + + /** + * Sets Jpeg quality of captured picture. + * + * @param quality + * the JPEG quality of captured picture. The range is 1 to + * 100, with 100 being the best. + */ + public void setJpegQuality(int quality) { + set(KEY_JPEG_QUALITY, quality); + } + + /** + * Returns the quality setting for the JPEG picture. + * + * @return the JPEG picture quality setting. + */ + public int getJpegQuality() { + return (getInt(KEY_JPEG_QUALITY)); + } + + /** + * Sets the rate at which preview frames are received. This is the + * target frame rate. The actual frame rate depends on the driver. + * + * @param fps + * the frame rate (frames per second) + * @deprecated replaced by {@link #setPreviewFpsRange(int,int)} + */ + @Deprecated + public void setPreviewFrameRate(int fps) { + set(KEY_PREVIEW_FRAME_RATE, fps); + } + + /** + * Returns the setting for the rate at which preview frames are + * received. This is the target frame rate. The actual frame rate + * depends on the driver. + * + * @return the frame rate setting (frames per second) + * @deprecated replaced by {@link #getPreviewFpsRange(int[])} + */ + @Deprecated + public int getPreviewFrameRate() { + return (getInt(KEY_PREVIEW_FRAME_RATE)); + } + + /** + * Gets the supported preview frame rates. + * + * @return a list of supported preview frame rates. null if preview + * frame rate setting is not supported. + * @deprecated replaced by {@link #getSupportedPreviewFpsRange()} + */ + @Deprecated + public List getSupportedPreviewFrameRates() { + String str = get(KEY_PREVIEW_FRAME_RATE + SUPPORTED_VALUES_SUFFIX); + return (splitInt(str)); + } + + /** + * Sets the maximum and maximum preview fps. This controls the rate of + * preview frames received in {@link PreviewCallback}. The minimum and + * maximum preview fps must be one of the elements from + * {@link #getSupportedPreviewFpsRange}. + * + * @param min + * the minimum preview fps (scaled by 1000). + * @param max + * the maximum preview fps (scaled by 1000). + * @throws RuntimeException + * if fps range is invalid. + * @see #setPreviewCallbackWithBuffer(PreviewCallback) + * @see #getSupportedPreviewFpsRange() + */ + public void setPreviewFpsRange(int min, int max) { + set(KEY_PREVIEW_FPS_RANGE, "" + min + "," + max); + } + + /** + * Returns the current minimum and maximum preview fps. The values are + * one of the elements returned by {@link #getSupportedPreviewFpsRange}. + * + * @return range the minimum and maximum preview fps (scaled by 1000). + * @see #PREVIEW_FPS_MIN_INDEX + * @see #PREVIEW_FPS_MAX_INDEX + * @see #getSupportedPreviewFpsRange() + */ + public void getPreviewFpsRange(int[] range) { + if ((range == null) || (range.length != 2)) { + throw new IllegalArgumentException( + "range must be an array with two elements."); + } + splitInt(get(KEY_PREVIEW_FPS_RANGE), range); + } + + /** + * Gets the supported preview fps (frame-per-second) ranges. Each range + * contains a minimum fps and maximum fps. If minimum fps equals to + * maximum fps, the reader outputs frames in fixed frame rate. If not, + * the reader outputs frames in auto frame rate. The actual frame rate + * fluctuates between the minimum and the maximum. The values are + * multiplied by 1000 and represented in integers. For example, if frame + * rate is 26.623 frames per second, the value is 26623. + * + * @return a list of supported preview fps ranges. This method returns a + * list with at least one element. Every element is an int array + * of two values - minimum fps and maximum fps. The list is + * sorted from small to large (first by maximum fps and then + * minimum fps). + * @see #PREVIEW_FPS_MIN_INDEX + * @see #PREVIEW_FPS_MAX_INDEX + */ + public List getSupportedPreviewFpsRange() { + String str = get(KEY_PREVIEW_FPS_RANGE + SUPPORTED_VALUES_SUFFIX); + return (splitRange(str)); + } + + /** + * Sets the image format for preview pictures. + *

+ * If this is never called, the default format will be + * {@link ImageFormat#NV21}, which uses the NV21 + * encoding format. + *

+ * + * @param pixel_format + * the desired preview picture format, defined by one of the + * {@link ImageFormat} constants. (E.g., + * ImageFormat.NV21 (default), + * ImageFormat.RGB_565, or + * ImageFormat.JPEG) + * @see ImageFormat + */ + public void setPreviewFormat(int pixel_format) { + String s = readerFormatForPixelFormat(pixel_format); + if (s == null) { + throw new IllegalArgumentException("Invalid pixel_format=" + + pixel_format); + } + + set(KEY_PREVIEW_FORMAT, s); + } + + /** + * Returns the image format for preview frames got from + * {@link PreviewCallback}. + * + * @return the preview format. + * @see ImageFormat + */ + public int getPreviewFormat() { + return (pixelFormatForReaderFormat(get(KEY_PREVIEW_FORMAT))); + } + + /** + * Gets the supported preview formats. + * + * @return a list of supported preview formats. This method will always + * return a list with at least one element. + * @see ImageFormat + */ + public List getSupportedPreviewFormats() { + String str = get(KEY_PREVIEW_FORMAT + SUPPORTED_VALUES_SUFFIX); + ArrayList formats = new ArrayList(); + for (String s : split(str)) { + int f = pixelFormatForReaderFormat(s); + if (f == ImageFormat.UNKNOWN) + continue; + formats.add(f); + } + return (formats); + } + + /** + * Sets the dimensions for pictures. + * + * Applications need to consider the display orientation. See + * {@link #setPreviewSize(int,int)} for reference. + * + * @param width + * the width for pictures, in pixels + * @param height + * the height for pictures, in pixels + * @see #setPreviewSize(int,int) + * + */ + public void setPictureSize(int width, int height) { + String v = Integer.toString(width) + "x" + Integer.toString(height); + set(KEY_PICTURE_SIZE, v); + } + + /** + * Returns the dimension setting for pictures. + * + * @return a Size object with the height and width setting for pictures + */ + public Size getPictureSize() { + String pair = get(KEY_PICTURE_SIZE); + return (strToSize(pair)); + } + + /** + * Gets the supported picture sizes. + * + * @return a list of supported picture sizes. This method will always + * return a list with at least one element. + */ + public List getSupportedPictureSizes() { + String str = get(KEY_PICTURE_SIZE + SUPPORTED_VALUES_SUFFIX); + return (splitSize(str)); + } + + /** + * Sets the image format for pictures. + * + * @param pixel_format + * the desired picture format (ImageFormat.NV21, + * ImageFormat.RGB_565, or + * ImageFormat.JPEG) + * @see ImageFormat + */ + public void setPictureFormat(int pixel_format) { + String s = readerFormatForPixelFormat(pixel_format); + if (s == null) { + throw new IllegalArgumentException("Invalid pixel_format=" + + pixel_format); + } + + set(KEY_PICTURE_FORMAT, s); + } + + /** + * Returns the image format for pictures. + * + * @return the picture format + * @see ImageFormat + */ + public int getPictureFormat() { + return (pixelFormatForReaderFormat(get(KEY_PICTURE_FORMAT))); + } + + /** + * Gets the supported picture formats. + * + * @return supported picture formats. This method will always return a + * list with at least one element. + * @see ImageFormat + */ + public List getSupportedPictureFormats() { + String str = get(KEY_PICTURE_FORMAT + SUPPORTED_VALUES_SUFFIX); + ArrayList formats = new ArrayList(); + for (String s : split(str)) { + int f = pixelFormatForReaderFormat(s); + if (f == ImageFormat.UNKNOWN) + continue; + formats.add(f); + } + return (formats); + } + + private String readerFormatForPixelFormat(int pixel_format) { + switch (pixel_format) { + case ImageFormat.NV16: + return (PIXEL_FORMAT_YUV422SP); + case ImageFormat.NV21: + return (PIXEL_FORMAT_YUV420SP); + case ImageFormat.YUY2: + return (PIXEL_FORMAT_YUV422I); + case ImageFormat.RGB_565: + return (PIXEL_FORMAT_RGB565); + case ImageFormat.JPEG: + return (PIXEL_FORMAT_JPEG); + default: + break; + } + return (null); + } + + private int pixelFormatForReaderFormat(String format) { + if (format == null) + return (ImageFormat.UNKNOWN); + + if (format.equals(PIXEL_FORMAT_YUV422SP)) + return (ImageFormat.NV16); + + if (format.equals(PIXEL_FORMAT_YUV420SP)) + return (ImageFormat.NV21); + + if (format.equals(PIXEL_FORMAT_YUV422I)) + return (ImageFormat.YUY2); + + if (format.equals(PIXEL_FORMAT_RGB565)) + return (ImageFormat.RGB_565); + + if (format.equals(PIXEL_FORMAT_JPEG)) + return (ImageFormat.JPEG); + + return (ImageFormat.UNKNOWN); + } + + /** + * Sets the rotation angle in degrees relative to the orientation of the + * reader. This affects the pictures returned from JPEG + * {@link PictureCallback}. The reader driver may set orientation in the + * EXIF header without rotating the picture. Or the driver may rotate + * the picture and the EXIF thumbnail. If the Jpeg picture is rotated, + * the orientation in the EXIF header will be missing or 1 (row #0 is + * top and column #0 is left side). + * + *

+ * If applications want to rotate the picture to match the orientation + * of what users see, apps should use + * {@link android.view.OrientationEventListener} and {@link ReaderInfo}. + * The value from OrientationEventListener is relative to the natural + * orientation of the device. ReaderInfo.orientation is the angle + * between reader orientation and natural device orientation. The sum of + * the two is the rotation angle for back-facing reader. The difference + * of the two is the rotation angle for front-facing reader. Note that + * the JPEG pictures of front-facing readers are not mirrored as in + * preview display. + * + *

+ * For example, suppose the natural orientation of the device is + * portrait. The device is rotated 270 degrees clockwise, so the device + * orientation is 270. Suppose a back-facing reader sensor is mounted in + * landscape and the top side of the reader sensor is aligned with the + * right edge of the display in natural orientation. So the reader + * orientation is 90. The rotation should be set to 0 (270 + 90). + * + *

+ * The reference code is as follows. + * + *

+		 * #import com.motorolasolutions.adc.decoder;
+		 * 
+		 * public void public void onOrientationChanged(int orientation)
+		 * {
+		 * 	int rotation = 0;
+		 * 
+		 * 	if ( orientation == ORIENTATION_UNKNOWN )
+		 * 		return;
+		 * 
+		 * 	BarCodeReader.ReaderInfo info = new BarCodeReader.ReaderInfo();
+		 * 	BarCodeReader.getReaderInfo(readerId, info);
+		 * 	orientation = (orientation + 45) / 90 * 90;
+		 * 	if ( info.facing == BarCodeReader.ReaderInfo.BCRDR_FACING_FRONT )
+		 * 	{
+		 * 		rotation = (info.orientation - orientation + 360) % 360;
+		 * 	}
+		 * 	else
+		 * 	{
+		 * 		// back-facing reader
+		 * 		rotation = (info.orientation + orientation) % 360;
+		 * 	}
+		 * 	mParameters.setRotation(rotation);
+		 * }
+		 * 
+ * + * @param rotation + * The rotation angle in degrees relative to the orientation + * of the reader. Rotation can only be 0, 90, 180 or 270. + * @throws IllegalArgumentException + * if rotation value is invalid. + * @see android.view.OrientationEventListener + * @see #getReaderInfo(int, ReaderInfo) + */ + public void setRotation(int rotation) { + if ((rotation == 0) || (rotation == 90) || (rotation == 180) + || (rotation == 270)) { + set(KEY_ROTATION, Integer.toString(rotation)); + } else { + throw new IllegalArgumentException("Invalid rotation=" + + rotation); + } + } + + /** + * Sets GPS latitude coordinate. This will be stored in JPEG EXIF + * header. + * + * @param latitude + * GPS latitude coordinate. + */ + public void setGpsLatitude(double latitude) { + set(KEY_GPS_LATITUDE, Double.toString(latitude)); + } + + /** + * Sets GPS longitude coordinate. This will be stored in JPEG EXIF + * header. + * + * @param longitude + * GPS longitude coordinate. + */ + public void setGpsLongitude(double longitude) { + set(KEY_GPS_LONGITUDE, Double.toString(longitude)); + } + + /** + * Sets GPS altitude. This will be stored in JPEG EXIF header. + * + * @param altitude + * GPS altitude in meters. + */ + public void setGpsAltitude(double altitude) { + set(KEY_GPS_ALTITUDE, Double.toString(altitude)); + } + + /** + * Sets GPS timestamp. This will be stored in JPEG EXIF header. + * + * @param timestamp + * GPS timestamp (UTC in seconds since January 1, 1970). + */ + public void setGpsTimestamp(long timestamp) { + set(KEY_GPS_TIMESTAMP, Long.toString(timestamp)); + } + + /** + * Sets GPS processing method. It will store up to 32 characters in JPEG + * EXIF header. + * + * @param processing_method + * The processing method to get this location. + */ + public void setGpsProcessingMethod(String processing_method) { + set(KEY_GPS_PROCESSING_METHOD, processing_method); + } + + /** + * Removes GPS latitude, longitude, altitude, and timestamp from the + * parameters. + */ + public void removeGpsData() { + remove(KEY_GPS_LATITUDE); + remove(KEY_GPS_LONGITUDE); + remove(KEY_GPS_ALTITUDE); + remove(KEY_GPS_TIMESTAMP); + remove(KEY_GPS_PROCESSING_METHOD); + } + + /** + * Gets the current white balance setting. + * + * @return current white balance. null if white balance setting is not + * supported. + * @see #WHITE_BALANCE_AUTO + * @see #WHITE_BALANCE_INCANDESCENT + * @see #WHITE_BALANCE_FLUORESCENT + * @see #WHITE_BALANCE_WARM_FLUORESCENT + * @see #WHITE_BALANCE_DAYLIGHT + * @see #WHITE_BALANCE_CLOUDY_DAYLIGHT + * @see #WHITE_BALANCE_TWILIGHT + * @see #WHITE_BALANCE_SHADE + * + */ + public String getWhiteBalance() { + return (get(KEY_WHITE_BALANCE)); + } + + /** + * Sets the white balance. + * + * @param value + * new white balance. + * @see #getWhiteBalance() + */ + public void setWhiteBalance(String value) { + set(KEY_WHITE_BALANCE, value); + } + + /** + * Gets the supported white balance. + * + * @return a list of supported white balance. null if white balance + * setting is not supported. + * @see #getWhiteBalance() + */ + public List getSupportedWhiteBalance() { + String str = get(KEY_WHITE_BALANCE + SUPPORTED_VALUES_SUFFIX); + return (split(str)); + } + + /** + * Gets the current color effect setting. + * + * @return current color effect. null if color effect setting is not + * supported. + * @see #EFFECT_NONE + * @see #EFFECT_MONO + * @see #EFFECT_NEGATIVE + * @see #EFFECT_SOLARIZE + * @see #EFFECT_SEPIA + * @see #EFFECT_POSTERIZE + * @see #EFFECT_WHITEBOARD + * @see #EFFECT_BLACKBOARD + * @see #EFFECT_AQUA + */ + public String getColorEffect() { + return (get(KEY_EFFECT)); + } + + /** + * Sets the current color effect setting. + * + * @param value + * new color effect. + * @see #getColorEffect() + */ + public void setColorEffect(String value) { + set(KEY_EFFECT, value); + } + + /** + * Gets the supported color effects. + * + * @return a list of supported color effects. null if color effect + * setting is not supported. + * @see #getColorEffect() + */ + public List getSupportedColorEffects() { + String str = get(KEY_EFFECT + SUPPORTED_VALUES_SUFFIX); + return (split(str)); + } + + /** + * Gets the current antibanding setting. + * + * @return current antibanding. null if antibanding setting is not + * supported. + * @see #ANTIBANDING_AUTO + * @see #ANTIBANDING_50HZ + * @see #ANTIBANDING_60HZ + * @see #ANTIBANDING_OFF + */ + public String getAntibanding() { + return (get(KEY_ANTIBANDING)); + } + + /** + * Sets the antibanding. + * + * @param antibanding + * new antibanding value. + * @see #getAntibanding() + */ + public void setAntibanding(String antibanding) { + set(KEY_ANTIBANDING, antibanding); + } + + /** + * Gets the supported antibanding values. + * + * @return a list of supported antibanding values. null if antibanding + * setting is not supported. + * @see #getAntibanding() + */ + public List getSupportedAntibanding() { + String str = get(KEY_ANTIBANDING + SUPPORTED_VALUES_SUFFIX); + return (split(str)); + } + + /** + * Gets the current scene mode setting. + * + * @return one of SCENE_MODE_XXX string constant. null if scene mode + * setting is not supported. + * @see #SCENE_MODE_AUTO + * @see #SCENE_MODE_ACTION + * @see #SCENE_MODE_PORTRAIT + * @see #SCENE_MODE_LANDSCAPE + * @see #SCENE_MODE_NIGHT + * @see #SCENE_MODE_NIGHT_PORTRAIT + * @see #SCENE_MODE_THEATRE + * @see #SCENE_MODE_BEACH + * @see #SCENE_MODE_SNOW + * @see #SCENE_MODE_SUNSET + * @see #SCENE_MODE_STEADYPHOTO + * @see #SCENE_MODE_FIREWORKS + * @see #SCENE_MODE_SPORTS + * @see #SCENE_MODE_PARTY + * @see #SCENE_MODE_CANDLELIGHT + */ + public String getSceneMode() { + return (get(KEY_SCENE_MODE)); + } + + /** + * Sets the scene mode. Changing scene mode may override other + * parameters (such as flash mode, focus mode, white balance). For + * example, suppose originally flash mode is on and supported flash + * modes are on/off. In night scene mode, both flash mode and supported + * flash mode may be changed to off. After setting scene mode, + * applications should call getParameters to know if some parameters are + * changed. + * + * @param value + * scene mode. + * @see #getSceneMode() + */ + public void setSceneMode(String value) { + set(KEY_SCENE_MODE, value); + } + + /** + * Gets the supported scene modes. + * + * @return a list of supported scene modes. null if scene mode setting + * is not supported. + * @see #getSceneMode() + */ + public List getSupportedSceneModes() { + String str = get(KEY_SCENE_MODE + SUPPORTED_VALUES_SUFFIX); + return (split(str)); + } + + /** + * Gets the current flash mode setting. + * + * @return current flash mode. null if flash mode setting is not + * supported. + * @see #FLASH_MODE_OFF + * @see #FLASH_MODE_AUTO + * @see #FLASH_MODE_ON + * @see #FLASH_MODE_RED_EYE + * @see #FLASH_MODE_TORCH + */ + public String getFlashMode() { + return (get(KEY_FLASH_MODE)); + } + + /** + * Sets the flash mode. + * + * @param value + * flash mode. + * @see #getFlashMode() + */ + public void setFlashMode(String value) { + set(KEY_FLASH_MODE, value); + } + + /** + * Gets the supported flash modes. + * + * @return a list of supported flash modes. null if flash mode setting + * is not supported. + * @see #getFlashMode() + */ + public List getSupportedFlashModes() { + String str = get(KEY_FLASH_MODE + SUPPORTED_VALUES_SUFFIX); + return (split(str)); + } + + /** + * Gets the current focus mode setting. + * + * @return current focus mode. This method will always return a non-null + * value. Applications should call + * {@link #autoFocus(AutoFocusCallback)} to start the focus if + * focus mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO. + * @see #FOCUS_MODE_AUTO + * @see #FOCUS_MODE_INFINITY + * @see #FOCUS_MODE_MACRO + * @see #FOCUS_MODE_FIXED + * @see #FOCUS_MODE_EDOF + * @see #FOCUS_MODE_CONTINUOUS_VIDEO + */ + public String getFocusMode() { + return (get(KEY_FOCUS_MODE)); + } + + /** + * Sets the focus mode. + * + * @param value + * focus mode. + * @see #getFocusMode() + */ + public void setFocusMode(String value) { + set(KEY_FOCUS_MODE, value); + } + + /** + * Gets the supported focus modes. + * + * @return a list of supported focus modes. This method will always + * return a list with at least one element. + * @see #getFocusMode() + */ + public List getSupportedFocusModes() { + String str = get(KEY_FOCUS_MODE + SUPPORTED_VALUES_SUFFIX); + return (split(str)); + } + + /** + * Gets the focal length (in millimeter) of the reader. + * + * @return the focal length. This method will always return a valid + * value. + */ + public float getFocalLength() { + return (Float.parseFloat(get(KEY_FOCAL_LENGTH))); + } + + /** + * Gets the horizontal angle of view in degrees. + * + * @return horizontal angle of view. This method will always return a + * valid value. + */ + public float getHorizontalViewAngle() { + return (Float.parseFloat(get(KEY_HORIZONTAL_VIEW_ANGLE))); + } + + /** + * Gets the vertical angle of view in degrees. + * + * @return vertical angle of view. This method will always return a + * valid value. + */ + public float getVerticalViewAngle() { + return (Float.parseFloat(get(KEY_VERTICAL_VIEW_ANGLE))); + } + + /** + * Gets the current exposure compensation index. + * + * @return current exposure compensation index. The range is + * {@link #getMinExposureCompensation} to + * {@link #getMaxExposureCompensation}. 0 means exposure is not + * adjusted. + */ + public int getExposureCompensation() { + return (getInt(KEY_EXPOSURE_COMPENSATION, 0)); + } + + /** + * Sets the exposure compensation index. + * + * @param value + * exposure compensation index. The valid value range is from + * {@link #getMinExposureCompensation} (inclusive) to + * {@link #getMaxExposureCompensation} (inclusive). 0 means + * exposure is not adjusted. Application should call + * getMinExposureCompensation and getMaxExposureCompensation + * to know if exposure compensation is supported. + */ + public void setExposureCompensation(int value) { + set(KEY_EXPOSURE_COMPENSATION, value); + } + + /** + * Gets the maximum exposure compensation index. + * + * @return maximum exposure compensation index (>=0). If both this + * method and {@link #getMinExposureCompensation} return 0, + * exposure compensation is not supported. + */ + public int getMaxExposureCompensation() { + return (getInt(KEY_MAX_EXPOSURE_COMPENSATION, 0)); + } + + /** + * Gets the minimum exposure compensation index. + * + * @return minimum exposure compensation index (<=0). If both this + * method and {@link #getMaxExposureCompensation} return 0, + * exposure compensation is not supported. + */ + public int getMinExposureCompensation() { + return (getInt(KEY_MIN_EXPOSURE_COMPENSATION, 0)); + } + + /** + * Gets the exposure compensation step. + * + * @return exposure compensation step. Applications can get EV by + * multiplying the exposure compensation index and step. Ex: if + * exposure compensation index is -6 and step is 0.333333333, EV + * is -2. + */ + public float getExposureCompensationStep() { + return (getFloat(KEY_EXPOSURE_COMPENSATION_STEP, 0)); + } + + /** + * Gets current zoom value. This also works when smooth zoom is in + * progress. Applications should check {@link #isZoomSupported} before + * using this method. + * + * @return the current zoom value. The range is 0 to {@link #getMaxZoom} + * . 0 means the reader is not zoomed. + */ + public int getZoom() { + return (getInt(KEY_ZOOM, 0)); + } + + /** + * Sets current zoom value. If the reader is zoomed (value > 0), the + * actual picture size may be smaller than picture size setting. + * Applications can check the actual picture size after picture is + * returned from {@link PictureCallback}. The preview size remains the + * same in zoom. Applications should check {@link #isZoomSupported} + * before using this method. + * + * @param value + * zoom value. The valid range is 0 to {@link #getMaxZoom}. + */ + public void setZoom(int value) { + set(KEY_ZOOM, value); + } + + /** + * Returns true if zoom is supported. Applications should call this + * before using other zoom methods. + * + * @return true if zoom is supported. + */ + public boolean isZoomSupported() { + String str = get(KEY_ZOOM_SUPPORTED); + return (TRUE.equals(str)); + } + + /** + * Gets the maximum zoom value allowed for snapshot. This is the maximum + * value that applications can set to {@link #setZoom(int)}. + * Applications should call {@link #isZoomSupported} before using this + * method. This value may change in different preview size. Applications + * should call this again after setting preview size. + * + * @return the maximum zoom value supported by the reader. + */ + public int getMaxZoom() { + return (getInt(KEY_MAX_ZOOM, 0)); + } + + /** + * Gets the zoom ratios of all zoom values. Applications should check + * {@link #isZoomSupported} before using this method. + * + * @return the zoom ratios in 1/100 increments. Ex: a zoom of 3.2x is + * returned as 320. The number of elements is + * {@link #getMaxZoom} + 1. The list is sorted from small to + * large. The first element is always 100. The last element is + * the zoom ratio of the maximum zoom value. + */ + public List getZoomRatios() { + return (splitInt(get(KEY_ZOOM_RATIOS))); + } + + /** + * Returns true if smooth zoom is supported. Applications should call + * this before using other smooth zoom methods. + * + * @return true if smooth zoom is supported. + */ + public boolean isSmoothZoomSupported() { + String str = get(KEY_SMOOTH_ZOOM_SUPPORTED); + return (TRUE.equals(str)); + } + + /** + * Gets the distances from the reader to where an object appears to be + * in focus. The object is sharpest at the optimal focus distance. The + * depth of field is the far focus distance minus near focus distance. + * + * Focus distances may change after calling + * {@link #autoFocus(AutoFocusCallback)}, {@link #cancelAutoFocus}, or + * {@link #startPreview()}. Applications can call + * {@link #getParameters()} and this method anytime to get the latest + * focus distances. If the focus mode is FOCUS_MODE_CONTINUOUS_VIDEO, + * focus distances may change from time to time. + * + * This method is intended to estimate the distance between the reader + * and the subject. After autofocus, the subject distance may be within + * near and far focus distance. However, the precision depends on the + * reader hardware, autofocus algorithm, the focus area, and the scene. + * The error can be large and it should be only used as a reference. + * + * Far focus distance >= optimal focus distance >= near focus distance. + * If the focus distance is infinity, the value will be + * Float.POSITIVE_INFINITY. + * + * @param output + * focus distances in meters. output must be a float array + * with three elements. Near focus distance, optimal focus + * distance, and far focus distance will be filled in the + * array. + * @see #FOCUS_DISTANCE_NEAR_INDEX + * @see #FOCUS_DISTANCE_OPTIMAL_INDEX + * @see #FOCUS_DISTANCE_FAR_INDEX + */ + public void getFocusDistances(float[] output) { + if ((output == null) || (output.length != 3)) { + throw new IllegalArgumentException( + "output must be an float array with three elements."); + } + splitFloat(get(KEY_FOCUS_DISTANCES), output); + } + + // Splits a comma delimited string to an ArrayList of String. + // Return null if the passing string is null or the size is 0. + private ArrayList split(String str) { + if (str == null) + return (null); + + // Use StringTokenizer because it is faster than split. + StringTokenizer tokenizer = new StringTokenizer(str, ","); + ArrayList substrings = new ArrayList(); + while (tokenizer.hasMoreElements()) { + substrings.add(tokenizer.nextToken()); + } + return (substrings); + } + + // Splits a comma delimited string to an ArrayList of Integer. + // Return null if the passing string is null or the size is 0. + private ArrayList splitInt(String str) { + if (str == null) + return (null); + + StringTokenizer tokenizer = new StringTokenizer(str, ","); + ArrayList substrings = new ArrayList(); + while (tokenizer.hasMoreElements()) { + String token = tokenizer.nextToken(); + substrings.add(Integer.parseInt(token)); + } + if (substrings.size() == 0) + return (null); + + return (substrings); + } + + private void splitInt(String str, int[] output) { + if (str == null) + return; + + StringTokenizer tokenizer = new StringTokenizer(str, ","); + int index = 0; + while (tokenizer.hasMoreElements()) { + String token = tokenizer.nextToken(); + output[index++] = Integer.parseInt(token); + } + } + + // Splits a comma delimited string to an ArrayList of Float. + private void splitFloat(String str, float[] output) { + if (str == null) + return; + + StringTokenizer tokenizer = new StringTokenizer(str, ","); + int index = 0; + while (tokenizer.hasMoreElements()) { + String token = tokenizer.nextToken(); + output[index++] = Float.parseFloat(token); + } + } + + // Returns the value of a float parameter. + private float getFloat(String key, float defaultValue) { + float flRetVal; + + try { + flRetVal = Float.parseFloat(mMap.get(key)); + return (flRetVal); + } catch (Throwable thrw) { + } + return (defaultValue); + } + + // Returns the value of a integer parameter. + private int getInt(String key, int defaultValue) { + int iRetVal; + + try { + iRetVal = Integer.parseInt(mMap.get(key)); + return (iRetVal); + } catch (Throwable thrw) { + } + return (defaultValue); + } + + // Splits a comma delimited string to an ArrayList of Size. + // Return null if the passing string is null or the size is 0. + private ArrayList splitSize(String str) { + if (str == null) + return (null); + + StringTokenizer tokenizer = new StringTokenizer(str, ","); + ArrayList sizeList = new ArrayList(); + while (tokenizer.hasMoreElements()) { + Size size = strToSize(tokenizer.nextToken()); + if (size != null) + sizeList.add(size); + } + if (sizeList.size() == 0) + return (null); + + return (sizeList); + } + + // Parses a string (ex: "480x320") to Size object. + // Return null if the passing string is null. + private Size strToSize(String str) { + if (str == null) + return (null); + + int pos = str.indexOf('x'); + if (pos != -1) { + String width = str.substring(0, pos); + String height = str.substring(pos + 1); + return (new Size(Integer.parseInt(width), + Integer.parseInt(height))); + } + Log.e(TAG, "Invalid size parameter string=" + str); + return (null); + } + + // Splits a comma delimited string to an ArrayList of int array. + // Example string: "(10000,26623),(10000,30000)". Return null if the + // passing string is null or the size is 0. + private ArrayList splitRange(String str) { + if ((str == null) || (str.charAt(0) != '(') + || (str.charAt(str.length() - 1) != ')')) { + Log.e(TAG, "Invalid range list string=" + str); + return (null); + } + + ArrayList rangeList = new ArrayList(); + int endIndex, fromIndex = 1; + do { + int[] range = new int[2]; + endIndex = str.indexOf("),(", fromIndex); + if (endIndex == -1) + endIndex = str.length() - 1; + splitInt(str.substring(fromIndex, endIndex), range); + rangeList.add(range); + fromIndex = endIndex + 3; + } while (endIndex != (str.length() - 1)); + + if (rangeList.size() == 0) + return (null); + + return (rangeList); + } + }; +} diff --git a/app/src/main/java/com/seuic/scan/SeuicScanKeyEventRunnable.java b/app/src/main/java/com/seuic/scan/SeuicScanKeyEventRunnable.java new file mode 100644 index 0000000..109195e --- /dev/null +++ b/app/src/main/java/com/seuic/scan/SeuicScanKeyEventRunnable.java @@ -0,0 +1,44 @@ +package com.seuic.scan; + +import com.seuic.scanner.Scanner; +import com.seuic.scanner.ScannerKey; + +public class SeuicScanKeyEventRunnable implements Runnable { + private Scanner mScanner; + public boolean isrun = true; + + // 需要调用ScannerKey去实现扫描按键控制扫描灯的亮和灭(需要在子线程中执行) + public SeuicScanKeyEventRunnable(Scanner mScanner) { + this.mScanner = mScanner; + } + + public void run() { + int ret1 = ScannerKey.open(); + if (ret1 > -1) { + while (isrun) { + int ret = ScannerKey.getKeyEvent(); + if (ret > -1) { + // while (isrun) { + // try { + // mScanner.startScan(); + // Thread.sleep(300); + // mScanner.stopScan(); + // Thread.sleep(300); + // } catch (InterruptedException e) { + // + // } + // } + switch (ret) { + case ScannerKey.KEY_DOWN: + mScanner.startScan(); + break; + case ScannerKey.KEY_UP: + mScanner.stopScan(); + break; + } + } + } + } + } + +} diff --git a/app/src/main/java/com/seuic/scanner/DecodeCallback.java b/app/src/main/java/com/seuic/scanner/DecodeCallback.java new file mode 100644 index 0000000..f06771a --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/DecodeCallback.java @@ -0,0 +1,11 @@ +package com.seuic.scanner; + +public interface DecodeCallback { + void onDecodeComplete(String paramString); +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\DecodeCallback.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/DecodeInfo.java b/app/src/main/java/com/seuic/scanner/DecodeInfo.java new file mode 100644 index 0000000..4de8d5b --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/DecodeInfo.java @@ -0,0 +1,15 @@ +package com.seuic.scanner; + +public class DecodeInfo { + public String barcode; + + public String codetype; + + public int length; +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\DecodeInfo.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/DecodeInfoCallBack.java b/app/src/main/java/com/seuic/scanner/DecodeInfoCallBack.java new file mode 100644 index 0000000..90b589e --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/DecodeInfoCallBack.java @@ -0,0 +1,11 @@ +package com.seuic.scanner; + +public interface DecodeInfoCallBack { + void onDecodeComplete(DecodeInfo paramDecodeInfo); +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\DecodeInfoCallBack.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/Devices.java b/app/src/main/java/com/seuic/scanner/Devices.java new file mode 100644 index 0000000..aa49270 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/Devices.java @@ -0,0 +1,15 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ class Devices +/* */ { +/* */ enum DeviceModels { +/* 6 */ AUTOID6, +/* 7 */ AUTOID9; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\Devices.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/FileUtil.java b/app/src/main/java/com/seuic/scanner/FileUtil.java new file mode 100644 index 0000000..3ff2e6e --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/FileUtil.java @@ -0,0 +1,71 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.os.Environment; +/* */ import android.util.Log; +/* */ import java.io.File; +/* */ import java.io.IOException; +/* */ +/* */ +/* */ +/* */ +/* */ public class FileUtil +/* */ { +/* */ private static final String LOG_TAG = "FileUtil"; +/* 14 */ public static final String APP_TEMP_DIRECTORY = Environment.getExternalStorageDirectory() + "/PDATest"; +/* */ +/* */ public static boolean fileExists(String file) { +/* 17 */ File _file = new File(file); +/* 18 */ return _file.exists(); +/* */ } +/* */ +/* */ public static boolean createDirectory(String directory) { +/* */ try { +/* 23 */ File file = new File(directory); +/* 24 */ if (!file.exists() && !file.isDirectory()) { +/* 25 */ file.mkdir(); +/* */ } +/* 27 */ return true; +/* 28 */ } catch (Exception ex) { +/* 29 */ return false; +/* */ } +/* */ } +/* */ +/* */ public static void createFile(String filename) { +/* 34 */ File file = new File(filename); +/* */ try { +/* 36 */ file.createNewFile(); +/* 37 */ } catch (IOException e) { +/* 38 */ Log.e("FileUtil", "createFile : " + e.getMessage()); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static void clear(String folder) { +/* 48 */ File filefolder = new File(folder); +/* 49 */ if (filefolder != null) { +/* 50 */ if (filefolder.isDirectory()) { +/* 51 */ File[] filelist = filefolder.listFiles(); byte b; int i; File[] arrayOfFile1; +/* 52 */ for (i = (arrayOfFile1 = filelist).length, b = 0; b < i; ) { File file = arrayOfFile1[b]; +/* 53 */ clear(file.getPath()); b++; } +/* */ +/* */ } +/* 56 */ filefolder.delete(); +/* */ } +/* */ } +/* */ +/* */ public static void delete(String filename) { +/* 61 */ File file = new File(filename); +/* 62 */ if (file.exists()) +/* 63 */ file.delete(); +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\FileUtil.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/HHPObject.java b/app/src/main/java/com/seuic/scanner/HHPObject.java new file mode 100644 index 0000000..c94129d --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/HHPObject.java @@ -0,0 +1,19 @@ +package com.seuic.scanner; + +public class HHPObject { + String msg; + + byte codeID; + + byte symLetter; + + byte symModifier; + + int length; +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\HHPObject.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/HHPScanner.java b/app/src/main/java/com/seuic/scanner/HHPScanner.java new file mode 100644 index 0000000..bae0ac2 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/HHPScanner.java @@ -0,0 +1,319 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ import android.os.Handler; +/* */ import android.os.Message; +/* */ import android.text.TextUtils; +/* */ import android.util.Log; +/* */ import android.util.SparseIntArray; +/* */ +/* */ public class HHPScanner +/* */ extends Scanner +/* */ { +/* 13 */ final String LOG_TAG = "HHPScanner"; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 25 */ private final int DEFAULT_PARAMETER = 849; +/* */ +/* */ private Thread mThread; +/* */ private boolean isEnabled = true; +/* */ private static DecodeCallback callback; +/* 30 */ private Handler mHandler = new DecodeHandler(); +/* 31 */ private Runnable runnable = new DecodeRunnable(); +/* */ boolean scanFinished; static { System.loadLibrary("HHPScanner_jni"); paramArray.put(257, 1); paramArray.put(258, 17); paramArray.put(259, 33); paramArray.put(260, 49); paramArray.put(261, 65); paramArray.put(263, 2); paramArray.put(264, 18); paramArray.put(265, 34); paramArray.put(266, 3); paramArray.put(267, 19); paramArray.put(265, 35); paramArray.put(273, 20); paramArray.put(289, 113); paramArray.put(290, 114); paramArray.put(291, 115); paramArray.put(292, 145); paramArray.put(305, 209); paramArray.put(307, 212); paramArray.put(310, 210); paramArray.put(311, 211); paramArray.put(321, 241); paramArray.put(322, 242); paramArray.put(323, 243); paramArray.put(337, 257); paramArray.put(338, 258); paramArray.put(339, 259); paramArray.put(341, 260); paramArray.put(353, 273); paramArray.put(354, 274); paramArray.put(355, 275); paramArray.put(401, 289); paramArray.put(402, 290); paramArray.put(403, 291); paramArray.put(513, 305); paramArray.put(514, 306); paramArray.put(515, 307); paramArray.put(577, 321); paramArray.put(578, 322); paramArray.put(579, 323); paramArray.put(593, 337); paramArray.put(594, 338); paramArray.put(595, 339); paramArray.put(609, 369); paramArray.put(617, 370); paramArray.put(610, 385); paramArray.put(618, 386); paramArray.put(611, 401); paramArray.put(612, 417); paramArray.put(613, 433); paramArray.put(689, 561); paramArray.put(690, 562); paramArray.put(691, 563); paramArray.put(836, 564); paramArray.put(529, 497); paramArray.put(705, 577); paramArray.put(706, 578); paramArray.put(707, 579); paramArray.put(721, 593); paramArray.put(722, 594); paramArray.put(723, 595); paramArray.put(561, 609); paramArray.put(562, 610); paramArray.put(563, 611); paramArray.put(737, 625); paramArray.put(739, 626); paramArray.put(739, 627); paramArray.put(545, 641); paramArray.put(546, 642); paramArray.put(547, 643); paramArray.put(753, 657); paramArray.put(754, 658); paramArray.put(755, 659); paramArray.put(769, 705); paramArray.put(770, 706); paramArray.put(771, 707); paramArray.put(785, 753); paramArray.put(786, 754); paramArray.put(787, 755); paramArray.put(788, 756); +/* */ paramArray.put(817, 785); +/* */ paramArray.put(818, 786); +/* 35 */ paramArray.put(7, 850); } HHPScanner(Context context) { super(context); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 187 */ this.scanFinished = true; } +/* */ void decode() { HHPObject object = new HHPObject(); if (JNIGetDecode(object, 5000) > 0) { ScanLed.setLed(1); Message msg = this.mHandler.obtainMessage(); msg.obj = object; this.mHandler.sendMessage(msg); } +/* 189 */ this.scanFinished = true; } void scan() { synchronized (this.runnable) { +/* 190 */ if (this.isEnabled) +/* 191 */ if (this.scanFinished) { +/* 192 */ this.runnable.notify(); +/* */ } else { +/* 194 */ this.scanFinished = true; +/* */ } +/* */ } } public boolean open() { if (JNIOpen() > -1) { +/* */ this.mThread = new Thread(this.runnable); this.mThread.start(); return true; +/* */ } +/* */ return false; } +/* */ public void close() { JNIClose(); } +/* */ public void startScan() { scan(); } +/* 202 */ public void stopScan() { JNIStopDecode(); } +/* */ +/* */ +/* */ +/* */ public int getParams(int num) { +/* 207 */ if (paramArray.get(num, -1) == -1 && num != 801) { +/* 208 */ return -1; +/* */ } +/* */ +/* 211 */ ScanParam param = new ScanParam(); +/* 212 */ param.id = paramArray.get(num); +/* 213 */ JNIGetParameter(param); +/* */ +/* */ +/* 216 */ if (num == 7) { +/* 217 */ Log.i("HHPScanner", "12345"); +/* */ } +/* */ +/* 220 */ return param.value; +/* */ } +/* */ +/* */ +/* */ public void enable() { +/* 225 */ JNIEnable(); +/* */ } +/* */ +/* */ +/* */ public void disable() { +/* 230 */ JNIDisable(); +/* */ } +/* */ +/* */ +/* */ +/* */ public boolean setParams(int num, int value) { +/* 236 */ if (paramArray.get(num, -1) == -1 && num != 801) { +/* 237 */ return false; +/* */ } +/* */ +/* 240 */ ScanParam param = new ScanParam(); +/* 241 */ if (num != 801) { +/* 242 */ param.id = paramArray.get(num); +/* */ } else { +/* */ +/* 245 */ param.id = 849; +/* */ } +/* 247 */ param.value = value; +/* */ +/* 249 */ if (JNISetParameter(param) == 1) { +/* 250 */ return true; +/* */ } +/* 252 */ return false; +/* */ } +/* */ +/* */ public void setOCRTemplate(String template) { +/* 256 */ JNISetOCRTemplate(template); +/* */ } +/* */ +/* */ +/* */ public SparseIntArray getAllParams() { +/* 261 */ return paramArray; +/* */ } +/* */ +/* */ static class DecodeHandler extends Handler { +/* */ public void handleMessage(Message msg) { +/* 266 */ HHPObject object = (HHPObject)msg.obj; +/* 267 */ if (HHPScanner.callback != null && !TextUtils.isEmpty(object.msg)) +/* 268 */ HHPScanner.callback.onDecodeComplete(object.msg); +/* */ } +/* */ } +/* */ +/* */ class DecodeRunnable +/* */ implements Runnable +/* */ { +/* */ public void run() { +/* */ while (true) { +/* 277 */ synchronized (HHPScanner.this.runnable) { +/* */ try { +/* 279 */ HHPScanner.this.runnable.wait(); +/* 280 */ } catch (InterruptedException e) { +/* 281 */ Log.e("HHPScanner", "DecodeRunnable:" + e.getMessage()); +/* */ } +/* 283 */ HHPScanner.this.decode(); +/* */ } +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ public void setDecodeCallBack(DecodeCallback decodeCallback) { +/* 291 */ callback = decodeCallback; +/* */ } +/* */ +/* */ public void setDecodeInfoCallBack(DecodeInfoCallBack callback) {} +/* */ +/* */ final native int JNIOpen(); +/* */ +/* */ final native int JNIClose(); +/* */ +/* */ final native int JNIEnable(); +/* */ +/* */ final native int JNIDisable(); +/* */ +/* */ final native int JNISetOCRTemplate(String paramString); +/* */ +/* */ final native int JNIStopDecode(); +/* */ +/* */ final native int JNIGetDecode(HHPObject paramHHPObject, int paramInt); +/* */ +/* */ final native int JNISetParameter(ScanParam paramScanParam); +/* */ +/* */ final native int JNIGetParameter(ScanParam paramScanParam); +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\HHPScanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/IScanner.java b/app/src/main/java/com/seuic/scanner/IScanner.java new file mode 100644 index 0000000..7c11d10 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/IScanner.java @@ -0,0 +1,279 @@ +package com.seuic.scanner; + +public interface IScanner { + boolean open(); + + void close(); + + void startScan(); + + void stopScan(); + + void enable(); + + void disable(); + + boolean setParams(int paramInt1, int paramInt2); + + int getParams(int paramInt); + + void setDecodeCallBack(DecodeCallback paramDecodeCallback); + + void setDecodeInfoCallBack(DecodeInfoCallBack paramDecodeInfoCallBack); + + public static class ParamCode { + public static final int LASTER_ONTIME = 1; + + public static final int SCAN_ANGLE = 2; + + public static final int TIMEOUT_SAMESYMBOL = 3; + + public static final int SECURITY_LEVEL = 4; + + public static final int BIDIRECTIONAL = 6; + + public static final int LIGHTS = 7; + + public static final int LCD_DISPLAY = 8; + + public static final int ILLUMINATION_LEVEL = 9; + + public static final int UPCA = 257; + + public static final int UPCE = 258; + + public static final int UPCE1 = 259; + + public static final int EAN8 = 260; + + public static final int EAN13 = 261; + + public static final int BOOKLAND = 262; + + public static final int UPCA_CHK = 263; + + public static final int UPCE_CHK = 264; + + public static final int UPCE1_CHK = 265; + + public static final int UPCA_PREAM = 266; + + public static final int UPCE_PREAM = 267; + + public static final int UPCE1_PREAM = 268; + + public static final int UPCE_TO_A = 269; + + public static final int UPCE1_TO_A = 270; + + public static final int EAN8_TO_13 = 271; + + public static final int COUPON = 272; + + public static final int UPCE_EXPANDED = 273; + + public static final int CODE128 = 289; + + public static final int CODE128_LEN_MIN = 290; + + public static final int CODE128_LEN_MAX = 291; + + public static final int ISBT128 = 292; + + public static final int GS1128 = 293; + + public static final int CODE39 = 305; + + public static final int TRIC39 = 306; + + public static final int CODE39_FULL_ASCII = 307; + + public static final int CODE39_TO_CODE32 = 308; + + public static final int CODE32_PREFIX = 309; + + public static final int CODE39_LEN_MIN = 310; + + public static final int CODE39_LEN_MAX = 311; + + public static final int CODE39_CHK = 312; + + public static final int CODE39_VER = 313; + + public static final int CODE93 = 321; + + public static final int CODE93_LEN_MIN = 322; + + public static final int CODE93_LEN_MAX = 323; + + public static final int CODE11 = 337; + + public static final int CODE11_LEN_MIN = 338; + + public static final int CODE11_LEN_MAX = 339; + + public static final int CODE11_CHK_VER = 340; + + public static final int CODE11_CHK = 341; + + public static final int I25 = 353; + + public static final int I25_LEN_MIN = 354; + + public static final int I25_LEN_MAX = 355; + + public static final int D25 = 369; + + public static final int D25_LEN_MIN = 370; + + public static final int D25_LEN_MAX = 371; + + public static final int C25 = 385; + + public static final int C25_LEN_MIN = 386; + + public static final int C25_LEN_MAX = 387; + + public static final int CODEBAR = 401; + + public static final int CODEBAR_LEN_MIN = 402; + + public static final int CODEBAR_LEN_MAX = 403; + + public static final int MSI = 513; + + public static final int MSI_LEN_MIN = 514; + + public static final int MSI_LEN_MAX = 515; + + public static final int RSS14 = 529; + + public static final int RSS_LIMIT = 530; + + public static final int RSS_EXPANDED = 531; + + public static final int RSS_TO_UPCEAN = 532; + + public static final int QRCODE = 545; + + public static final int QRCODE_LEN_MIN = 546; + + public static final int QRCODE_LEN_MAX = 547; + + public static final int QRINVERSE = 548; + + public static final int MICROQR = 549; + + public static final int DM = 561; + + public static final int DM_LEN_MIN = 562; + + public static final int DM_LEN_MAX = 563; + + public static final int DMINVERSE = 564; + + public static final int DMI = 565; + + public static final int CHINAPOST = 577; + + public static final int CHINAPOST_LEN_MIN = 578; + + public static final int CHINAPOST_LEN_MAX = 579; + + public static final int M25 = 593; + + public static final int M25_LEN_MIN = 594; + + public static final int M25_LEN_MAX = 595; + + public static final int POSTNET = 609; + + public static final int PLANET = 610; + + public static final int BRITISHPOST = 611; + + public static final int JAPPOST = 612; + + public static final int AUSPOST = 613; + + public static final int UPU_FICS_POSTAL = 614; + + public static final int USPS_4CB = 615; + + public static final int NETHERLANDS_KIX_CODE = 616; + + public static final int POSTNET_CHK = 617; + + public static final int PLANET_CHK = 618; + + public static final int K35 = 625; + + public static final int COMPOSITE = 689; + + public static final int COMPOSITE_LEN_MIN = 690; + + public static final int COMPOSITE_LEN_MAX = 691; + + public static final int PDF417 = 705; + + public static final int PDF417_LEN_MIN = 706; + + public static final int PDF417_LEN_MAX = 707; + + public static final int MICROPDF417 = 721; + + public static final int MICROPDF417_LEN_MIN = 722; + + public static final int MICROPDF417_LEN_MAX = 723; + + public static final int MAXICODE = 737; + + public static final int MAXICODE_LEN_MIN = 738; + + public static final int MAXICODE_LEN_MAX = 739; + + public static final int AZTECCODE = 753; + + public static final int AZTECCODE_LEN_MIN = 754; + + public static final int AZTECCODE_LEN_MAX = 755; + + public static final int AZTECCODE_INVERSE = 756; + + public static final int CODEBLOCKF = 769; + + public static final int CODEBLOCKF_LEN_MIN = 770; + + public static final int CODEBLOCKF_LEN_MAX = 771; + + public static final int TELEPEN = 785; + + public static final int TELEPEN_LEN_MIN = 786; + + public static final int TELEPEN_LEN_MAX = 787; + + public static final int TELEPEN_OLDSTYLE = 788; + + public static final int FACTORY_DEFAULT = 801; + + public static final int OCR = 817; + + public static final int OCR_TEMPLATE = 818; + + public static final int COMPOSITE_CC_C = 833; + + public static final int COMPOSITE_CC_AB = 834; + + public static final int COMPOSITE_TLC_39 = 835; + + public static final int COMPOSITE_UPCEAN = 836; + + public static final int XMIT_CODE_ID = 849; + } +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\IScanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/N4313Scanner.java b/app/src/main/java/com/seuic/scanner/N4313Scanner.java new file mode 100644 index 0000000..44c5fbe --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/N4313Scanner.java @@ -0,0 +1,84 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ import android.util.SparseIntArray; +/* */ +/* */ public class N4313Scanner extends Scanner1D { +/* */ static { +/* 8 */ paramArray.clear(); +/* 9 */ paramArray.put(1, 1); +/* 10 */ paramArray.put(2, 2); +/* 11 */ paramArray.put(3, 3); +/* */ +/* */ +/* 14 */ paramArray.put(257, 145); +/* 15 */ paramArray.put(258, 146); +/* 16 */ paramArray.put(260, 148); +/* 17 */ paramArray.put(261, 149); +/* 18 */ paramArray.put(263, 151); +/* 19 */ paramArray.put(264, 152); +/* */ +/* 21 */ paramArray.put(289, 273); +/* 22 */ paramArray.put(292, 275); +/* 23 */ paramArray.put(293, 274); +/* */ +/* 25 */ paramArray.put(305, 289); +/* 26 */ paramArray.put(307, 291); +/* 27 */ paramArray.put(309, 293); +/* 28 */ paramArray.put(310, 294); +/* 29 */ paramArray.put(311, 295); +/* 30 */ paramArray.put(312, 296); +/* */ +/* 32 */ paramArray.put(321, 305); +/* 33 */ paramArray.put(322, 306); +/* 34 */ paramArray.put(323, 307); +/* */ +/* 36 */ paramArray.put(337, 321); +/* 37 */ paramArray.put(338, 322); +/* 38 */ paramArray.put(339, 323); +/* */ +/* */ +/* 41 */ paramArray.put(353, 337); +/* 42 */ paramArray.put(354, 338); +/* 43 */ paramArray.put(355, 339); +/* */ +/* 45 */ paramArray.put(513, 353); +/* 46 */ paramArray.put(514, 354); +/* 47 */ paramArray.put(515, 355); +/* */ +/* 49 */ paramArray.put(401, 369); +/* 50 */ paramArray.put(402, 370); +/* 51 */ paramArray.put(403, 371); +/* */ +/* 53 */ paramArray.put(369, 385); +/* 54 */ paramArray.put(370, 386); +/* 55 */ paramArray.put(371, 387); +/* */ +/* 57 */ paramArray.put(385, 401); +/* 58 */ paramArray.put(386, 402); +/* 59 */ paramArray.put(387, 403); +/* */ } +/* */ +/* */ N4313Scanner(Context context) { +/* 63 */ super(context); +/* */ } +/* */ +/* */ +/* */ protected int getLaserTime() { +/* 68 */ int laserTime = getParams(1); +/* 69 */ if (laserTime > 0) { +/* 70 */ return laserTime; +/* */ } +/* 72 */ return 5000; +/* */ } +/* */ +/* */ protected void setLaserTime(int time) { +/* 76 */ this.laser_time = time; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\N4313Scanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/Param1D.java b/app/src/main/java/com/seuic/scanner/Param1D.java new file mode 100644 index 0000000..3afde38 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/Param1D.java @@ -0,0 +1,13 @@ +package com.seuic.scanner; + +public class Param1D { + public int id; + + public int value; +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\Param1D.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/SE4500Scanner.java b/app/src/main/java/com/seuic/scanner/SE4500Scanner.java new file mode 100644 index 0000000..4eebb98 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/SE4500Scanner.java @@ -0,0 +1,438 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ import android.os.Build; +/* */ import android.text.TextUtils; +/* */ import android.util.Log; +/* */ import android.util.SparseIntArray; +/* */ import com.zebra.adc.decoder.compatible.BarCodeReader; +/* */ import java.io.UnsupportedEncodingException; +/* */ import java.util.HashMap; +/* */ import java.util.Map; +/* */ +/* */ +/* */ +/* */ +/* */ public class SE4500Scanner +/* */ extends Scanner +/* */ implements BarCodeReader.DecodeCallback +/* */ { +/* 20 */ private final String TYPE_NOT_FOUND = "Unknown Type"; +/* 21 */ private final int[] TYPE_LENGTH = new int[] { 1, 3 }; +/* */ +/* */ +/* */ static { +/* 25 */ System.loadLibrary("IAL"); +/* 26 */ System.loadLibrary("SDL"); +/* */ +/* 28 */ if (Build.VERSION.SDK_INT >= 19) { +/* 29 */ System.loadLibrary("barcodereader44"); +/* */ } +/* 31 */ else if (Build.VERSION.SDK_INT >= 18) { +/* 32 */ System.loadLibrary("barcodereader43"); +/* */ } else { +/* 34 */ System.loadLibrary("barcodereader"); +/* */ } +/* */ +/* */ +/* 38 */ paramArray.put(257, 1); +/* 39 */ paramArray.put(258, 2); +/* 40 */ paramArray.put(259, 12); +/* 41 */ paramArray.put(260, 4); +/* 42 */ paramArray.put(261, 3); +/* 43 */ paramArray.put(262, 83); +/* 44 */ paramArray.put(263, 40); +/* 45 */ paramArray.put(264, 41); +/* 46 */ paramArray.put(265, 42); +/* 47 */ paramArray.put(266, 34); +/* 48 */ paramArray.put(267, 35); +/* 49 */ paramArray.put(268, 36); +/* 50 */ paramArray.put(269, 37); +/* 51 */ paramArray.put(270, 38); +/* 52 */ paramArray.put(271, 39); +/* 53 */ paramArray.put(272, 85); +/* */ +/* */ +/* 56 */ paramArray.put(289, 8); +/* 57 */ paramArray.put(290, 209); +/* 58 */ paramArray.put(291, 210); +/* 59 */ paramArray.put(292, 84); +/* 60 */ paramArray.put(293, 14); +/* */ +/* */ +/* 63 */ paramArray.put(305, 0); +/* 64 */ paramArray.put(306, 13); +/* 65 */ paramArray.put(307, 17); +/* 66 */ paramArray.put(308, 86); +/* 67 */ paramArray.put(309, 231); +/* 68 */ paramArray.put(310, 18); +/* 69 */ paramArray.put(311, 19); +/* 70 */ paramArray.put(312, 43); +/* 71 */ paramArray.put(313, 48); +/* */ +/* */ +/* 74 */ paramArray.put(321, 9); +/* 75 */ paramArray.put(322, 26); +/* 76 */ paramArray.put(323, 27); +/* */ +/* */ +/* 79 */ paramArray.put(337, 10); +/* 80 */ paramArray.put(338, 28); +/* 81 */ paramArray.put(339, 29); +/* 82 */ paramArray.put(340, 52); +/* 83 */ paramArray.put(341, 47); +/* */ +/* */ +/* 86 */ paramArray.put(353, 6); +/* 87 */ paramArray.put(354, 22); +/* 88 */ paramArray.put(355, 23); +/* */ +/* */ +/* 91 */ paramArray.put(369, 5); +/* 92 */ paramArray.put(370, 20); +/* 93 */ paramArray.put(371, 21); +/* */ +/* */ +/* 96 */ paramArray.put(401, 7); +/* 97 */ paramArray.put(402, 24); +/* 98 */ paramArray.put(403, 25); +/* */ +/* */ +/* 101 */ paramArray.put(513, 11); +/* 102 */ paramArray.put(514, 30); +/* 103 */ paramArray.put(515, 31); +/* */ +/* */ +/* 106 */ paramArray.put(385, 408); +/* */ +/* */ +/* 109 */ paramArray.put(593, 618); +/* 110 */ paramArray.put(594, 619); +/* 111 */ paramArray.put(595, 620); +/* */ +/* */ +/* 114 */ paramArray.put(609, 89); +/* 115 */ paramArray.put(610, 90); +/* 116 */ paramArray.put(617, 95); +/* 117 */ paramArray.put(618, 95); +/* 118 */ paramArray.put(611, 91); +/* 119 */ paramArray.put(612, 290); +/* 120 */ paramArray.put(613, 291); +/* 121 */ paramArray.put(616, 326); +/* 122 */ paramArray.put(615, 592); +/* 123 */ paramArray.put(614, 611); +/* */ +/* */ +/* 126 */ paramArray.put(625, 581); +/* */ +/* */ +/* 129 */ paramArray.put(833, 341); +/* 130 */ paramArray.put(834, 342); +/* 131 */ paramArray.put(835, 371); +/* */ +/* */ +/* 134 */ paramArray.put(705, 15); +/* */ +/* */ +/* 137 */ paramArray.put(721, 227); +/* */ +/* */ +/* 140 */ paramArray.put(737, 294); +/* */ +/* */ +/* 143 */ paramArray.put(753, 574); +/* 144 */ paramArray.put(756, 589); +/* */ +/* */ +/* 147 */ paramArray.put(545, 293); +/* 148 */ paramArray.put(548, 587); +/* 149 */ paramArray.put(549, 573); +/* */ +/* */ +/* 152 */ paramArray.put(561, 292); +/* 153 */ paramArray.put(564, 588); +/* 154 */ paramArray.put(565, 537); +/* */ +/* 156 */ paramArray.put(8, 716); +/* 157 */ paramArray.put(849, 45); +/* */ +/* 159 */ paramArray.put(9, 764); +/* */ } +/* 161 */ private static Map mMapType = new HashMap(); static { +/* 162 */ mMapType.put("A", "UPC-A/UPC-E/UPC-E1/EAN-8/EAN-13"); +/* 163 */ mMapType.put("B", "Code 39/Code 32"); +/* 164 */ mMapType.put("C", "Codabar"); +/* 165 */ mMapType.put("D", "Code 128/ISBT 128/ISBT 128 Concatenated"); +/* 166 */ mMapType.put("E", "Code 93"); +/* 167 */ mMapType.put("F", "Interleaved 2 of 5"); +/* 168 */ mMapType.put("G", "Discrete 2 of 5/Discrete 2 of 5 IATA"); +/* 169 */ mMapType.put("H", "Code 11"); +/* 170 */ mMapType.put("J", "MSI"); +/* 171 */ mMapType.put("K", "GS1-128"); +/* 172 */ mMapType.put("L", "Bookland EAN"); +/* 173 */ mMapType.put("M", "Trioptic Code 39"); +/* 174 */ mMapType.put("N", "Coupon Code"); +/* 175 */ mMapType.put("R", "GS1 DataBar Family"); +/* 176 */ mMapType.put("S", "Matrix 2 of 5"); +/* 177 */ mMapType.put("T", "UCC Composite/TLC 39"); +/* 178 */ mMapType.put("U", "Chinese 2 of 5"); +/* 179 */ mMapType.put("V", "Korean 3 of 5"); +/* 180 */ mMapType.put("X", "ISSN EAN/PDF417/Macro PDF417/Micro PDF417"); +/* 181 */ mMapType.put("z", "Aztec/Aztec Rune"); +/* 182 */ mMapType.put("P00", "Data Matrix"); +/* 183 */ mMapType.put("P01", "QR Code/MicroQR"); +/* 184 */ mMapType.put("P02", "Maxicode"); +/* 185 */ mMapType.put("P03", "US Postnet"); +/* 186 */ mMapType.put("P04", "US Planet"); +/* 187 */ mMapType.put("P05", "Japan Postal"); +/* 188 */ mMapType.put("P06", "UK Postal"); +/* 189 */ mMapType.put("P08", "Netherlands KIX Code"); +/* 190 */ mMapType.put("P09", "Australia Post"); +/* 191 */ mMapType.put("P0A", "USPS 4CB/One Code/Intelligent Mail"); +/* 192 */ mMapType.put("P0B", "UPU FICS Postal"); +/* 193 */ mMapType.put("P0X", "Signature Capture"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 202 */ private Boolean released = new Boolean(true); +/* 203 */ private static int decCount = 0; private DecodeCallback mDecodeCallBack; +/* */ +/* */ public SE4500Scanner(Context context) { +/* 206 */ super(context); +/* */ } +/* */ private DecodeInfoCallBack mInfoCallBack; private BarCodeReader mBcr; +/* */ +/* */ public boolean open() { +/* 211 */ synchronized (this.released) { +/* 212 */ if (!this.released.booleanValue()) { +/* 213 */ return true; +/* */ } +/* */ +/* 216 */ if (Build.VERSION.SDK_INT >= 18) { +/* 217 */ this.mBcr = BarCodeReader.open(this.mContext.getApplicationContext()); +/* */ } else { +/* 219 */ this.mBcr = BarCodeReader.open(); +/* */ } +/* */ +/* 222 */ if (this.mBcr == null) { +/* 223 */ return false; +/* */ } +/* */ +/* 226 */ this.mBcr.setDecodeCallback(this); +/* 227 */ this.mBcr.setParameter(45, 2); +/* 228 */ this.released = Boolean.valueOf(false); +/* */ } +/* 230 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ public void close() { +/* 236 */ synchronized (this.released) { +/* */ +/* 238 */ if (this.released.booleanValue()) { +/* */ return; +/* */ } +/* */ +/* 242 */ if (this.mBcr != null) { +/* 243 */ this.mBcr.stopDecode(); +/* 244 */ if (!this.released.booleanValue()) +/* 245 */ this.mBcr.release(); +/* 246 */ this.released = Boolean.valueOf(true); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ public void startScan() { +/* 253 */ synchronized (this) { +/* 254 */ if (this.mBcr.scanFinished.booleanValue()) { +/* 255 */ Log.i("SE4500", "Start scan finished " + this.mBcr.scanFinished); +/* 256 */ this.mBcr.scanFinished = Boolean.valueOf(false); +/* 257 */ this.mBcr.startDecode(); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ public void stopScan() { +/* 264 */ this.mBcr.stopDecode(); +/* 265 */ Log.i("SE4500", "Stop scan finished "); +/* */ try { +/* 267 */ Thread.sleep(50L); +/* 268 */ } catch (InterruptedException e) { +/* 269 */ e.printStackTrace(); +/* */ } +/* */ } +/* */ +/* */ +/* */ public boolean setParams(int num, int value) { +/* 275 */ if (paramArray.get(num, -1) == -1 && num != 801) { +/* 276 */ return false; +/* */ } +/* */ +/* */ +/* 280 */ if (num == 801) { +/* 281 */ setDefault(); +/* 282 */ return true; +/* */ } +/* */ +/* 285 */ if (this.mBcr.setParameter(paramArray.get(num), value) == 0) { +/* 286 */ return true; +/* */ } +/* */ +/* 289 */ return false; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void setDefault() { +/* 297 */ close(); +/* */ +/* 299 */ open(); +/* */ } +/* */ +/* */ +/* */ public int getParams(int num) { +/* 304 */ if (paramArray.get(num, -1) == -1) { +/* 305 */ return -1; +/* */ } +/* */ +/* 308 */ return this.mBcr.getNumParameter(paramArray.get(num)); +/* */ } +/* */ +/* */ +/* */ +/* */ public void onDecodeComplete(int symbology, int length, byte[] data, BarCodeReader reader) { +/* 314 */ synchronized (this) { +/* */ +/* 316 */ if (length == -3) { +/* 317 */ decCount = symbology; +/* */ } else { +/* 319 */ this.mBcr.scanFinished = Boolean.valueOf(true); +/* */ } +/* 321 */ Log.i("SE4500", "Decode complete finished " + this.mBcr.scanFinished); +/* 322 */ if (length > 0) { +/* 323 */ synchronized (this.released) { +/* 324 */ if (!this.released.booleanValue()) { +/* 325 */ this.mBcr.stopDecode(); +/* */ } +/* */ } +/* */ +/* 329 */ ScanLed.setLed(1); +/* 330 */ if (symbology == 153) { +/* */ +/* 332 */ symbology = data[0]; +/* 333 */ int n = data[1]; +/* 334 */ int s = 2; +/* 335 */ int d = 0; +/* 336 */ int len = 0; +/* 337 */ byte[] d99 = new byte[data.length]; +/* 338 */ for (int i = 0; i < n; i++) { +/* 339 */ s += 2; +/* 340 */ len = data[s++]; +/* 341 */ System.arraycopy(data, s, d99, d, len); +/* 342 */ s += len; +/* 343 */ d += len; +/* */ } +/* 345 */ d99[d] = 0; +/* 346 */ data = d99; +/* */ } +/* */ +/* 349 */ String barcode = null; +/* */ try { +/* 351 */ barcode = (new String(data, StringUtils.guessEncoding(data))).trim(); +/* 352 */ } catch (UnsupportedEncodingException e1) { +/* 353 */ e1.printStackTrace(); +/* */ } +/* */ +/* 356 */ DecodeInfo info = getDecodeInfo(barcode); +/* 357 */ if (this.mDecodeCallBack != null) { +/* 358 */ this.mDecodeCallBack.onDecodeComplete(info.barcode); +/* */ } +/* */ +/* 361 */ if (this.mInfoCallBack != null) { +/* 362 */ this.mInfoCallBack.onDecodeComplete(info); +/* */ } +/* */ } +/* */ else { +/* */ +/* 367 */ switch (length) { +/* */ +/* */ } +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private DecodeInfo getDecodeInfo(String barcode) { +/* 379 */ DecodeInfo info = new DecodeInfo(); +/* 380 */ String type = null; +/* 381 */ int typelength = 0; +/* 382 */ if (barcode.length() > this.TYPE_LENGTH[0] && !TextUtils.isEmpty(type = mMapType.get(barcode.substring(0, this.TYPE_LENGTH[0])))) { +/* 383 */ info.codetype = type; +/* 384 */ typelength = this.TYPE_LENGTH[0]; +/* */ } +/* 386 */ else if (barcode.length() > this.TYPE_LENGTH[1] && !TextUtils.isEmpty(type = mMapType.get(barcode.substring(0, this.TYPE_LENGTH[1])))) { +/* 387 */ info.codetype = type; +/* 388 */ typelength = this.TYPE_LENGTH[1]; +/* */ } else { +/* 390 */ info.codetype = "Unknown Type"; +/* */ } +/* */ +/* 393 */ info.barcode = barcode.substring(typelength); +/* 394 */ info.length = info.barcode.length(); +/* 395 */ return info; +/* */ } +/* */ +/* */ +/* */ public void onEvent(int event, int info, byte[] data, BarCodeReader reader) { +/* 400 */ Log.i("SE4500", "onEvent " + event); +/* 401 */ switch (event) { +/* */ +/* */ case 7: +/* */ +/* */ try { +/* */ +/* */ +/* 408 */ Thread.sleep(50L); +/* 409 */ } catch (InterruptedException e) { +/* 410 */ e.printStackTrace(); +/* */ } +/* */ break; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ public void setDecodeCallBack(DecodeCallback callBack) { +/* 420 */ this.mDecodeCallBack = callBack; +/* */ } +/* */ +/* */ +/* */ public SparseIntArray getAllParams() { +/* 425 */ return paramArray; +/* */ } +/* */ +/* */ +/* */ public void setDecodeInfoCallBack(DecodeInfoCallBack callback) { +/* 430 */ this.mInfoCallBack = callback; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\SE4500Scanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/SE955Scanner.java b/app/src/main/java/com/seuic/scanner/SE955Scanner.java new file mode 100644 index 0000000..1ec9b3b --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/SE955Scanner.java @@ -0,0 +1,38 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ import android.util.SparseIntArray; +/* */ +/* */ public class SE955Scanner +/* */ extends Scanner1D { +/* */ static { +/* 9 */ paramArray.put(2, 2); +/* 10 */ paramArray.put(529, 417); +/* 11 */ paramArray.put(530, 418); +/* 12 */ paramArray.put(531, 419); +/* 13 */ paramArray.put(532, 420); +/* */ } +/* */ +/* */ SE955Scanner(Context context) { +/* 17 */ super(context); +/* */ } +/* */ +/* */ +/* */ protected int getLaserTime() { +/* 22 */ int laserTime = getParams(1); +/* 23 */ if (laserTime > 0) { +/* 24 */ return laserTime * 100; +/* */ } +/* 26 */ return 3000; +/* */ } +/* */ +/* */ protected void setLaserTime(int time) { +/* 30 */ this.laser_time = time * 100; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\SE955Scanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/ScanLed.java b/app/src/main/java/com/seuic/scanner/ScanLed.java new file mode 100644 index 0000000..9741f9e --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/ScanLed.java @@ -0,0 +1,20 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ class ScanLed +/* */ { +/* */ static { +/* 6 */ System.loadLibrary("Scannerled"); +/* */ } +/* */ +/* */ static final native int JNISetScanled(int paramInt); +/* */ +/* */ static int setLed(int brightness) { +/* 12 */ return JNISetScanled(brightness); +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\ScanLed.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/ScanParam.java b/app/src/main/java/com/seuic/scanner/ScanParam.java new file mode 100644 index 0000000..e3f4a1d --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/ScanParam.java @@ -0,0 +1,13 @@ +package com.seuic.scanner; + +public class ScanParam { + public int id; + + public int value; +} + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\ScanParam.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/Scanner.java b/app/src/main/java/com/seuic/scanner/Scanner.java new file mode 100644 index 0000000..82328c3 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/Scanner.java @@ -0,0 +1,72 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.app.ActivityManager; +/* */ import android.content.Context; +/* */ import android.content.Intent; +/* */ import android.util.SparseIntArray; +/* */ import java.util.List; +/* */ +/* */ +/* */ +/* */ +/* */ public abstract class Scanner +/* */ implements IScanner +/* */ { +/* */ public static final String ACTION_SEND_BARCODE = "com.android.server.scannerservice.broadcast"; +/* */ public static final String ACTION_SEND_KEY = "scannerdata"; +/* */ public static final String ACTION_SEND_KEY_CODE_TYPE = "codetype"; +/* */ private static final String ACTION_SCANNER_SERVICE_TERMINATE = "com.android.scanner.TERMINATE"; +/* */ private static final String SERVICE_NAME = "com.seuic.scanner.service.ScanService"; +/* */ private static final String ACTION_START_SCAN_SERVICE = "com.seuic.action.START_SCANSERVICE"; +/* */ protected boolean isEnabled = true; +/* 22 */ protected static SparseIntArray paramArray = new SparseIntArray(); +/* */ +/* */ Context mContext; +/* */ +/* */ Scanner(Context context) { +/* 27 */ this.mContext = context; +/* */ } +/* */ public abstract SparseIntArray getAllParams(); +/* */ +/* */ public static void stopScanService(Context context) { +/* 32 */ while (isRunning(context, "com.seuic.scanner.service.ScanService")) { +/* 33 */ context.sendBroadcast(new Intent("com.android.scanner.TERMINATE")); +/* */ } +/* */ try { +/* 36 */ Thread.sleep(150L); +/* 37 */ } catch (InterruptedException e) { +/* 38 */ e.printStackTrace(); +/* */ } +/* */ } +/* */ +/* */ public static void startScanService(Context context) { +/* 43 */ context.sendBroadcast(new Intent("com.seuic.action.START_SCANSERVICE")); +/* */ } +/* */ +/* */ private static boolean isRunning(Context context, String serviceName) { +/* 47 */ ActivityManager am = (ActivityManager)context.getSystemService("activity"); +/* 48 */ List infos = am.getRunningServices(100); +/* 49 */ for (ActivityManager.RunningServiceInfo serviceInfo : infos) { +/* 50 */ if (serviceInfo.service.getClassName().equals(serviceName)) { +/* 51 */ return true; +/* */ } +/* */ } +/* 54 */ return false; +/* */ } +/* */ +/* */ +/* */ public void enable() { +/* 59 */ this.isEnabled = true; +/* */ } +/* */ +/* */ +/* */ public void disable() { +/* 64 */ this.isEnabled = false; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\Scanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/Scanner1D.java b/app/src/main/java/com/seuic/scanner/Scanner1D.java new file mode 100644 index 0000000..f6c24d3 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/Scanner1D.java @@ -0,0 +1,327 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ import android.os.Handler; +/* */ import android.os.Message; +/* */ import android.util.Log; +/* */ import android.util.SparseIntArray; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ class Scanner1D +/* */ extends Scanner +/* */ { +/* */ private static final String LOG_TAG = "Scanner1D"; +/* */ private static DecodeCallback callback; +/* */ private static DecodeInfoCallBack infoCallBack; +/* */ private Thread mThread; +/* */ public boolean isOpened = false; +/* */ protected int laser_time; +/* */ +/* */ static { +/* 45 */ System.loadLibrary("Scanner1D"); +/* */ +/* 47 */ paramArray.put(1, 1); +/* 48 */ paramArray.put(3, 3); +/* 49 */ paramArray.put(4, 4); +/* 50 */ paramArray.put(6, 5); +/* */ +/* 52 */ paramArray.put(257, 145); +/* 53 */ paramArray.put(258, 146); +/* 54 */ paramArray.put(259, 147); +/* 55 */ paramArray.put(260, 148); +/* 56 */ paramArray.put(261, 149); +/* 57 */ paramArray.put(262, 150); +/* 58 */ paramArray.put(263, 151); +/* 59 */ paramArray.put(264, 152); +/* 60 */ paramArray.put(265, 153); +/* 61 */ paramArray.put(266, 154); +/* 62 */ paramArray.put(267, 155); +/* 63 */ paramArray.put(268, 156); +/* 64 */ paramArray.put(269, 157); +/* 65 */ paramArray.put(270, 158); +/* 66 */ paramArray.put(272, 159); +/* */ +/* 68 */ paramArray.put(289, 273); +/* 69 */ paramArray.put(292, 275); +/* 70 */ paramArray.put(293, 274); +/* */ +/* 72 */ paramArray.put(305, 289); +/* 73 */ paramArray.put(306, 290); +/* 74 */ paramArray.put(307, 291); +/* 75 */ paramArray.put(308, 292); +/* 76 */ paramArray.put(309, 293); +/* 77 */ paramArray.put(310, 294); +/* 78 */ paramArray.put(311, 295); +/* 79 */ paramArray.put(312, 296); +/* 80 */ paramArray.put(313, 297); +/* */ +/* 82 */ paramArray.put(321, 305); +/* 83 */ paramArray.put(322, 306); +/* 84 */ paramArray.put(323, 307); +/* */ +/* 86 */ paramArray.put(337, 321); +/* 87 */ paramArray.put(338, 322); +/* 88 */ paramArray.put(339, 323); +/* 89 */ paramArray.put(340, 324); +/* 90 */ paramArray.put(341, 325); +/* */ +/* 92 */ paramArray.put(353, 337); +/* 93 */ paramArray.put(354, 338); +/* 94 */ paramArray.put(355, 339); +/* */ +/* 96 */ paramArray.put(513, 353); +/* 97 */ paramArray.put(514, 354); +/* 98 */ paramArray.put(515, 355); +/* */ +/* 100 */ paramArray.put(401, 369); +/* 101 */ paramArray.put(402, 370); +/* 102 */ paramArray.put(403, 371); +/* */ +/* 104 */ paramArray.put(369, 385); +/* 105 */ paramArray.put(370, 386); +/* 106 */ paramArray.put(371, 387); +/* */ +/* 108 */ paramArray.put(385, 401); +/* 109 */ paramArray.put(386, 402); +/* 110 */ paramArray.put(387, 403); +/* */ } +/* */ +/* */ public SparseIntArray getAllParams() { +/* 114 */ return paramArray; +/* */ } +/* */ +/* 117 */ private Runnable runnable = new Runnable() +/* */ { +/* */ public void run() +/* */ { +/* */ while (true) { +/* 122 */ synchronized (Scanner1D.this.runnable) { +/* */ try { +/* 124 */ Scanner1D.this.runnable.wait(); +/* 125 */ } catch (InterruptedException e) { +/* 126 */ Log.i("Scanner1D", "Error:" + e.getMessage()); +/* */ } +/* 128 */ Scanner1D.this.decode(); +/* */ } +/* */ } +/* */ } +/* */ }; +/* */ +/* 134 */ private Handler mHandler = new DecodeHandler(); +/* */ +/* */ Scanner1D(Context context) { +/* 137 */ super(context); +/* */ } +/* */ +/* */ +/* */ public boolean open() { +/* 142 */ if (this.isOpened) { +/* 143 */ return true; +/* */ } +/* */ +/* 146 */ if (JNIOpen()) { +/* 147 */ this.isOpened = true; +/* 148 */ this.laser_time = getLaserTime(); +/* 149 */ this.mThread = new Thread(this.runnable); +/* 150 */ this.mThread.start(); +/* 151 */ return true; +/* */ } +/* 153 */ return false; +/* */ } +/* */ +/* */ public void close() { +/* 157 */ JNIClose(); +/* 158 */ this.isOpened = false; +/* */ } +/* */ +/* */ +/* */ public void startScan() { +/* 163 */ scan(); +/* */ } +/* */ +/* */ void scan() { +/* 167 */ if (!scanFinished.booleanValue()) { +/* */ return; +/* */ } +/* */ +/* 171 */ synchronized (this.runnable) { +/* 172 */ this.runnable.notify(); +/* */ } +/* */ } +/* */ +/* */ +/* 177 */ static Boolean scanFinished = Boolean.valueOf(true); +/* */ private void decode() { +/* 179 */ synchronized (this) { +/* 180 */ scanFinished = Boolean.valueOf(false); +/* 181 */ BarcodeInfo barcodeInfo = new BarcodeInfo(); +/* */ +/* 183 */ if (this.isEnabled && +/* 184 */ JNIGetBarcode(barcodeInfo, this.laser_time)) { +/* */ +/* 186 */ ScanLed.setLed(1); +/* 187 */ Message msg = this.mHandler.obtainMessage(); +/* 188 */ msg.obj = barcodeInfo; +/* 189 */ this.mHandler.sendMessage(msg); +/* */ } +/* */ +/* 192 */ scanFinished = Boolean.valueOf(true); +/* */ } +/* */ } +/* */ +/* */ +/* */ public void stopScan() { +/* 198 */ JNIStopScan(); +/* */ } +/* */ +/* */ +/* */ public void enable() { +/* 203 */ JNIEnableScan(); +/* 204 */ this.isEnabled = true; +/* */ } +/* */ +/* */ +/* */ public void disable() { +/* 209 */ JNIDisableScan(); +/* 210 */ this.isEnabled = false; +/* */ } +/* */ +/* */ +/* */ public boolean setParams(int id, int value) { +/* 215 */ if (paramArray.get(id, -1) == -1 && id != 801) { +/* 216 */ return false; +/* */ } +/* */ +/* 219 */ boolean ret = false; +/* */ +/* 221 */ if (id == 801) { +/* 222 */ ret = JNIFactoryDefault(); +/* 223 */ if (ret) { +/* */ +/* */ try { +/* 226 */ Thread.sleep(500L); +/* 227 */ this.laser_time = getLaserTime(); +/* 228 */ } catch (Exception exception) {} +/* */ } +/* */ +/* */ +/* 232 */ return ret; +/* */ } +/* */ +/* 235 */ ScanParam param = new ScanParam(); +/* 236 */ param.id = paramArray.get(id); +/* 237 */ param.value = value; +/* 238 */ ret = JNISetParam(param); +/* 239 */ if (ret && id == 1) { +/* 240 */ setLaserTime(value); +/* */ } +/* 242 */ return ret; +/* */ } +/* */ +/* */ +/* */ +/* */ public int getParams(int id) { +/* 248 */ if (paramArray.get(id, -1) == -1) { +/* 249 */ return -1; +/* */ } +/* */ +/* 252 */ ScanParam param = new ScanParam(); +/* 253 */ param.id = paramArray.get(id); +/* 254 */ boolean ret = JNIGetParam(param); +/* */ +/* 256 */ if (ret) { +/* 257 */ return param.value; +/* */ } +/* 259 */ return -1; +/* */ } +/* */ +/* */ private class BarcodeInfo { +/* */ public String data; +/* */ public int length; +/* */ public String type; +/* */ +/* */ private BarcodeInfo() {} } +/* */ +/* */ public void setDecodeCallBack(DecodeCallback decodeCallback) { +/* 270 */ callback = decodeCallback; +/* */ } +/* */ +/* */ static class DecodeHandler extends Handler { +/* */ public void handleMessage(Message msg) { +/* 275 */ BarcodeInfo barcodeInfo = (BarcodeInfo)msg.obj; +/* 276 */ if (Scanner1D.callback != null && !"".equals(barcodeInfo.data)) { +/* 277 */ Scanner1D.callback.onDecodeComplete(barcodeInfo.data); +/* */ } +/* */ +/* 280 */ if (Scanner1D.infoCallBack != null && !"".equals(barcodeInfo.data)) { +/* 281 */ DecodeInfo info = new DecodeInfo(); +/* 282 */ info.barcode = barcodeInfo.data; +/* 283 */ info.codetype = barcodeInfo.type; +/* 284 */ info.length = barcodeInfo.length; +/* 285 */ Scanner1D.infoCallBack.onDecodeComplete(info); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ public void setDecodeInfoCallBack(DecodeInfoCallBack callback) { +/* 293 */ infoCallBack = callback; +/* */ } +/* */ +/* */ protected int getLaserTime() { +/* 297 */ return -1; +/* */ } +/* */ +/* */ protected void setLaserTime(int time) { +/* 301 */ this.laser_time = time; +/* */ } +/* */ +/* */ public final native boolean JNIOpen(); +/* */ +/* */ public final native void JNIClose(); +/* */ +/* */ public final native boolean JNIGetBarcode(BarcodeInfo paramBarcodeInfo, int paramInt); +/* */ +/* */ public final native boolean JNIStopScan(); +/* */ +/* */ public final native boolean JNISetParam(ScanParam paramScanParam); +/* */ +/* */ public final native boolean JNIGetParam(ScanParam paramScanParam); +/* */ +/* */ public final native void JNIEnableScan(); +/* */ +/* */ public final native void JNIDisableScan(); +/* */ +/* */ private final native boolean JNIFactoryDefault(); +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\Scanner1D.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/ScannerFactory.java b/app/src/main/java/com/seuic/scanner/ScannerFactory.java new file mode 100644 index 0000000..217a6b7 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/ScannerFactory.java @@ -0,0 +1,60 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ +/* */ +/* */ +/* */ public class ScannerFactory +/* */ { +/* */ static final String SCN_SE4500 = "se4500"; +/* */ static final String SCN_N5600 = "N5600"; +/* */ static final String SCN_SE955 = "SE955"; +/* */ static final String SCN_SE965 = "SE965"; +/* */ static final String SCN_N4313 = "N4313"; +/* */ static final String SCN_UE966 = "UE966"; +/* */ static final String SCN_SE655 = "SE655"; +/* */ static final String SCN_SE4710 = "SE4710"; +/* */ private static Scanner scanner; +/* */ private static scanid mScanid; +/* */ +/* */ public static Scanner getScanner(Context context) { +/* 21 */ Scanner.stopScanService(context); +/* */ +/* 23 */ return getScannerNoStopService(context); +/* */ } +/* */ +/* */ +/* */ private static Scanner getScannerNoStopService(Context context) { +/* 28 */ if (scanner == null) { +/* */ +/* 30 */ mScanid = new scanid(); +/* 31 */ String deviceName = mScanid.readScanner(); +/* 32 */ if (deviceName != null) { +/* 33 */ if (deviceName.equals("N4313")) { +/* 34 */ scanner = new N4313Scanner(context); +/* 35 */ } else if (deviceName.equals("SE955") || +/* 36 */ deviceName.equals("SE965") || +/* 37 */ deviceName.equals("SE655")) { +/* 38 */ scanner = new SE955Scanner(context); +/* 39 */ } else if (deviceName.endsWith("UE966")) { +/* 40 */ scanner = new UE966Scanner(context); +/* 41 */ } else if (deviceName.equals("N5600")) { +/* 42 */ scanner = new HHPScanner(context); +/* 43 */ } else if (deviceName.equals("se4500") || +/* 44 */ deviceName.equals("SE4710")) { +/* 45 */ scanner = new SE4500Scanner(context); +/* */ } +/* */ } else { +/* 48 */ scanner = new HHPScanner(context); +/* */ } +/* */ } +/* */ +/* 52 */ return scanner; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\ScannerFactory.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/ScannerKey.java b/app/src/main/java/com/seuic/scanner/ScannerKey.java new file mode 100644 index 0000000..8d88443 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/ScannerKey.java @@ -0,0 +1,31 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class ScannerKey +/* */ { +/* 11 */ static scankey mScankey = new scankey(); +/* */ public static final int KEY_DOWN = 1; +/* */ +/* */ public static int open() { +/* 15 */ return mScankey.openScanKey(); +/* */ } +/* */ public static final int KEY_UP = 0; +/* */ public static int getKeyEvent() { +/* 19 */ return mScankey.waitScanKey(); +/* */ } +/* */ +/* */ public static void close() { +/* 23 */ mScankey.closeScanKey(); +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\ScannerKey.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/StringUtils.java b/app/src/main/java/com/seuic/scanner/StringUtils.java new file mode 100644 index 0000000..dea0064 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/StringUtils.java @@ -0,0 +1,191 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final class StringUtils +/* */ { +/* 12 */ private static final String PLATFORM_DEFAULT_ENCODING = System.getProperty("file.encoding"); +/* */ +/* */ public static final String SHIFT_JIS = "SJIS"; +/* */ private static final String EUC_JP = "EUC_JP"; +/* */ private static final String UTF8 = "UTF8"; +/* */ private static final String GB2312 = "GB2312"; +/* */ private static final String ISO88591 = "ISO8859_1"; +/* 19 */ private static final boolean ASSUME_SHIFT_JIS = !(!"SJIS".equalsIgnoreCase(PLATFORM_DEFAULT_ENCODING) && +/* 20 */ !"EUC_JP".equalsIgnoreCase(PLATFORM_DEFAULT_ENCODING)); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static String guessEncoding(byte[] bytes) { +/* 33 */ if (bytes.length > 3 && +/* 34 */ bytes[0] == -17 && +/* 35 */ bytes[1] == -69 && +/* 36 */ bytes[2] == -65) { +/* 37 */ return "UTF8"; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 46 */ int length = bytes.length; +/* 47 */ boolean canBeISO88591 = true; +/* 48 */ boolean canBeShiftJIS = true; +/* 49 */ boolean canBeUTF8 = true; +/* */ +/* 51 */ boolean canBeGB2312 = true; +/* */ +/* 53 */ int utf8BytesLeft = 0; +/* 54 */ int maybeDoubleByteCount = 0; +/* 55 */ int maybeSingleByteKatakanaCount = 0; +/* 56 */ boolean sawLatin1Supplement = false; +/* 57 */ boolean sawUTF8Start = false; +/* 58 */ boolean lastWasPossibleDoubleByteStart = false; +/* */ +/* 60 */ for (int i = 0; i < length && (canBeISO88591 || canBeShiftJIS || canBeUTF8); i++) { +/* */ +/* 62 */ int value = bytes[i] & 0xFF; +/* */ +/* */ +/* 65 */ if (value >= 128 && value <= 191) { +/* 66 */ if (utf8BytesLeft > 0) { +/* 67 */ utf8BytesLeft--; +/* */ } +/* */ } else { +/* 70 */ if (utf8BytesLeft > 0) { +/* 71 */ canBeUTF8 = false; +/* */ } +/* 73 */ if (value >= 192 && value <= 253) { +/* 74 */ sawUTF8Start = true; +/* 75 */ int valueCopy = value; +/* 76 */ while ((valueCopy & 0x40) != 0) { +/* 77 */ utf8BytesLeft++; +/* 78 */ valueCopy <<= 1; +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* 84 */ if (!canBeUTF8 && canBeGB2312 && +/* 85 */ value > 127 && +/* 86 */ value > 176 && value < 247) { +/* 87 */ int value2 = bytes[i + 1] & 0xFF; +/* 88 */ if (value2 > 160 && value2 <= 247) { +/* 89 */ canBeGB2312 = true; +/* */ +/* */ +/* */ +/* */ break; +/* */ } +/* */ } +/* */ +/* */ +/* 98 */ if ((value == 194 || value == 195) && i < length - 1) { +/* */ +/* */ +/* */ +/* 102 */ int nextValue = bytes[i + 1] & 0xFF; +/* 103 */ if (nextValue <= 191 && (( +/* 104 */ value == 194 && nextValue >= 160) || (value == 195 && nextValue >= 128))) { +/* 105 */ sawLatin1Supplement = true; +/* */ } +/* */ } +/* 108 */ if (value >= 127 && value <= 159) { +/* 109 */ canBeISO88591 = false; +/* */ } +/* */ +/* */ +/* */ +/* 114 */ if (value >= 161 && value <= 223) +/* */ { +/* 116 */ if (!lastWasPossibleDoubleByteStart) { +/* 117 */ maybeSingleByteKatakanaCount++; +/* */ } +/* */ } +/* 120 */ if (!lastWasPossibleDoubleByteStart && (( +/* 121 */ value >= 240 && value <= 255) || value == 128 || value == 160)) { +/* 122 */ canBeShiftJIS = false; +/* */ } +/* 124 */ if ((value >= 129 && value <= 159) || (value >= 224 && value <= 239)) { +/* */ +/* */ +/* 127 */ if (lastWasPossibleDoubleByteStart) { +/* */ +/* */ +/* */ +/* */ +/* 132 */ lastWasPossibleDoubleByteStart = false; +/* */ } +/* */ else { +/* */ +/* 136 */ lastWasPossibleDoubleByteStart = true; +/* 137 */ if (i >= bytes.length - 1) { +/* 138 */ canBeShiftJIS = false; +/* */ } else { +/* 140 */ int nextValue = bytes[i + 1] & 0xFF; +/* 141 */ if (nextValue < 64 || nextValue > 252) { +/* 142 */ canBeShiftJIS = false; +/* */ } else { +/* 144 */ maybeDoubleByteCount++; +/* */ } +/* */ +/* */ } +/* */ } +/* */ } else { +/* */ +/* 151 */ lastWasPossibleDoubleByteStart = false; +/* */ } +/* */ } +/* 154 */ if (utf8BytesLeft > 0) { +/* 155 */ canBeUTF8 = false; +/* */ } +/* */ +/* */ +/* 159 */ if (canBeShiftJIS && ASSUME_SHIFT_JIS) { +/* 160 */ return "SJIS"; +/* */ } +/* 162 */ if (canBeUTF8 && sawUTF8Start) { +/* 163 */ return "UTF8"; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* 170 */ if (canBeShiftJIS && (maybeDoubleByteCount >= 3 || 20 * maybeSingleByteKatakanaCount > length)) { +/* 171 */ return "SJIS"; +/* */ } +/* */ +/* */ +/* 175 */ if (canBeGB2312) { +/* 176 */ return "GB2312"; +/* */ } +/* */ +/* 179 */ if (!sawLatin1Supplement && canBeISO88591) { +/* 180 */ return "ISO8859_1"; +/* */ } +/* */ +/* 183 */ return PLATFORM_DEFAULT_ENCODING; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\StringUtils.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/UE966Scanner.java b/app/src/main/java/com/seuic/scanner/UE966Scanner.java new file mode 100644 index 0000000..57cba7c --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/UE966Scanner.java @@ -0,0 +1,30 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ import android.content.Context; +/* */ import android.util.SparseIntArray; +/* */ +/* */ public class UE966Scanner +/* */ extends Scanner1D { +/* */ UE966Scanner(Context context) { +/* 9 */ super(context); +/* */ } +/* */ +/* */ +/* */ protected int getLaserTime() { +/* 14 */ int laserTime = getParams(1); +/* 15 */ if (laserTime > 0) { +/* 16 */ return laserTime * 100; +/* */ } +/* 18 */ return 3000; +/* */ } +/* */ +/* */ protected void setLaserTime(int time) { +/* 22 */ this.laser_time = time * 100; +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\UE966Scanner.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/scanid.java b/app/src/main/java/com/seuic/scanner/scanid.java new file mode 100644 index 0000000..0270770 --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/scanid.java @@ -0,0 +1,18 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ public class scanid { +/* */ static { +/* 5 */ System.loadLibrary("ScannerId"); +/* */ } +/* */ public String readScanner() { +/* 8 */ return JNIReadScanId(); +/* */ } +/* */ +/* */ public final native String JNIReadScanId(); +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\scanid.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/seuic/scanner/scankey.java b/app/src/main/java/com/seuic/scanner/scankey.java new file mode 100644 index 0000000..9bef6ea --- /dev/null +++ b/app/src/main/java/com/seuic/scanner/scankey.java @@ -0,0 +1,31 @@ +/* */ package com.seuic.scanner; +/* */ +/* */ class scankey { +/* */ static { +/* 5 */ System.loadLibrary("ScannerKey"); +/* */ } +/* */ +/* */ public int openScanKey() { +/* 9 */ return JNIOpenScanKey(); +/* */ } +/* */ +/* */ public int waitScanKey() { +/* 13 */ return JNIWaitScanKey(); +/* */ } +/* */ +/* */ public void closeScanKey() { +/* 17 */ JNICloseScanKey(); +/* */ } +/* */ +/* */ private native int JNIOpenScanKey(); +/* */ +/* */ private native int JNIWaitScanKey(); +/* */ +/* */ private native void JNICloseScanKey(); +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\seuic\scanner\scankey.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/com/sys/SysData.java b/app/src/main/java/com/sys/SysData.java new file mode 100644 index 0000000..2e73ab1 --- /dev/null +++ b/app/src/main/java/com/sys/SysData.java @@ -0,0 +1,16 @@ +package com.sys; + +public class SysData { + public static String url; + public static String jigid; + public static String userid; + public static String lgnname; + public static String clientid; + public static float scale;//屏幕密度 + public static float t_scale=1f; //与200dpi的相对放大比例 + public static int timeout=30000;//超时设置120000 + public static boolean is_lx=false; + public static String isreg="N"; + public static int exectime=60; + public static String no; +} diff --git a/app/src/main/java/com/util/BitMapUtil.java b/app/src/main/java/com/util/BitMapUtil.java new file mode 100644 index 0000000..cbcfaa2 --- /dev/null +++ b/app/src/main/java/com/util/BitMapUtil.java @@ -0,0 +1,37 @@ +package com.util; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +public class BitMapUtil { + public static Bitmap generateBitMap(String url) throws IOException { + URL myFileUrl = null; + Bitmap bitmap = null; + myFileUrl = new URL(url); + HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); + conn.setDoInput(true); + conn.connect(); + InputStream is = conn.getInputStream(); + bitmap = BitmapFactory.decodeStream(is); + is.close(); + conn.disconnect(); + return bitmap; + } + public static Bitmap byteToBitmap(byte[] b){ + if(b==null){ + return null; + } + int len=b.length; + if(len!=0){ + return BitmapFactory.decodeByteArray(b, 0,len); + }else{ + return null; + } + } +} diff --git a/app/src/main/java/com/util/DateUtil.java b/app/src/main/java/com/util/DateUtil.java new file mode 100644 index 0000000..51f9b10 --- /dev/null +++ b/app/src/main/java/com/util/DateUtil.java @@ -0,0 +1,61 @@ +package com.util; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +public class DateUtil { + /* + * 得到当前日期 + */ + public static String getDate() { + Date now = new Date(); +// Calendar cal = Calendar.getInstance(); +// DateFormat d1 = DateFormat.getDateInstance(); //默认语言(汉语)下的默认风格(MEDIUM风格,比如:2008-6-16 20:54:53) + SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss"); + return dateFormat.format(now); + } + public static Date getDate(String s) throws ParseException { + SimpleDateFormat dateformat2=new SimpleDateFormat("yyyy-MM-dd"); + return dateformat2.parse(s); + } + /* + * 得到当前日期 + */ + public static String getDate1() { + Date now = new Date(); + SimpleDateFormat dateformat2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return dateformat2.format(now); + } + /* + * 得到当前时间 + */ + public static String getTime() { + Date now = new Date(); + Calendar cal = Calendar.getInstance(); + DateFormat d3 = DateFormat.getTimeInstance(); + return d3.format(now); + } + /* + * 得到当前日期和时间 + */ + public static String getDateAndTime() { + Date now = new Date(); + Calendar cal = Calendar.getInstance(); + DateFormat d1 = DateFormat.getDateTimeInstance(); //默认语言(汉语)下的默认风格(MEDIUM风格,比如:2008-6-16 20:54:53) + return d1.format(now); + } + // 天数相加减 + public static Date getDate(Date date, int amount) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.DATE, amount); + return calendar.getTime(); + } + public static void main(String[] args) { + System.out.println(DateUtil.getDateAndTime()+"---"+DateUtil.getTime()); + } +} diff --git a/app/src/main/java/com/util/DialogUtil.java b/app/src/main/java/com/util/DialogUtil.java new file mode 100644 index 0000000..3a32a75 --- /dev/null +++ b/app/src/main/java/com/util/DialogUtil.java @@ -0,0 +1,84 @@ +package com.util; + +import com.chaoran.entiry.SelfEditText; +import com.example.chaoran.DjActivity; +import com.example.chaoran.MainActivity; + +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.style.AbsoluteSizeSpan; +import android.util.Log; +import android.widget.ListView; +import android.widget.RelativeLayout; + +public class DialogUtil { + // 错误消息对话框 + public static void builder(final Context context, String title, String message, + int fontSize) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + SpannableStringBuilder ssBuilser = new SpannableStringBuilder(message); + builder.setTitle(title); + if (fontSize > 0) { + AbsoluteSizeSpan span = new AbsoluteSizeSpan(fontSize); + ssBuilser.setSpan(span, 0, message.length(), + Spannable.SPAN_INCLUSIVE_INCLUSIVE); + builder.setMessage(ssBuilser); + } else { + builder.setMessage(message); + } + builder.setPositiveButton("确定", new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + // TODO Auto-generated method stub + if (DjActivity.cr5wScanControl != null && "DjActivity".equals(context.getClass().getSimpleName())) { + DjActivity.cr5wScanControl.setIsOpen(true); + DjActivity.cr5wScanControl.start(context); + } else if (DjActivity.nr510ScanControl != null && "DjActivity".equals(context.getClass().getSimpleName())) { + DjActivity.nr510ScanControl.start(context); + } else if (DjActivity.barcodeReader != null && "DjActivity".equals(context.getClass().getSimpleName())) { + try { + // DjActivity.triggerState = true; + DjActivity.barcodeReader.light(true); //turn on/off backlight + DjActivity.barcodeReader.aim(true); //开关瞄准线 + DjActivity.barcodeReader.decode(true); //开关解码功能 + } catch (Exception ex) { + ex.printStackTrace(); + } + } + if (DjActivity.m_view != null) { + if (DjActivity.m_view instanceof SelfEditText) { + ((SelfEditText)DjActivity.m_view).selectAll(); + } + DjActivity.m_view = null; + } + } + }); + builder.create(); + builder.show(); + if (DjActivity.cr5wScanControl != null && "DjActivity".equals(context.getClass().getSimpleName())) + DjActivity.cr5wScanControl.setIsOpen(false); + } + + public static void builderCancel(Context context, String title, + String message, OnClickListener okListener) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(title); + builder.setMessage(message); + builder.setPositiveButton("确定", okListener); + builder.setNegativeButton("取消", null); + builder.create(); + builder.show(); + } + + public static void setDialog(ProgressDialog pd, String title, String message) { + pd.setTitle(title); + pd.setMessage(message); + pd.show(); + } +} diff --git a/app/src/main/java/com/util/DjMenuFun.java b/app/src/main/java/com/util/DjMenuFun.java new file mode 100644 index 0000000..b756599 --- /dev/null +++ b/app/src/main/java/com/util/DjMenuFun.java @@ -0,0 +1,185 @@ +package com.util; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Map; +import java.text.DateFormat; + +import map.baidu.com.BDMapActivity; + +import org.kobjects.base64.Base64; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.view.View; + +import com.chaoran.imp.InputInterface; +import com.example.chaoran.DjActivity; +import com.example.chaoran.ExitThread; +import com.example.chaoran.MipcaActivityCapture; +import com.example.chaoran.NetWorkSet; +import com.example.chaoran.RunYmupThread; +import com.sys.SysData; + +public class DjMenuFun { + public void Msave_dj(final DjActivity djActivity) throws Exception { +// if(djActivity.pd.isShowing()){ +// return; +// } + new AlertDialog.Builder(djActivity).setTitle("确定取消框") + .setMessage("确定保存单据") + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Map map = new HashMap(); + Object ob=DjUtil.saveOrganizationHzData(djActivity.hzTab,djActivity.pageMap.get("GZID")); + Map hzData=null; + if(ob instanceof Map){ + hzData=(Map)ob; + }else{ + View view=(View)ob; + if(view.isEnabled()){ + ((View)ob).requestFocus(); + } + DialogUtil.builder(djActivity, "错误信息", ((InputInterface)ob).getLabel().concat("不能为空"),0); + djActivity.pd.dismiss(); + return; + } +// Map hzData = DjUtil.organizationHzData(djActivity.layout); + ((HashMap)hzData.get("hzData")).putAll(djActivity.pageMap); + map.put("hzData", hzData); +// if (djActivity.mxData.size() > 0) { +// map.put("mxSql", djActivity.mxSql); +// map.put("mxData", DjUtil.organizationMxData(djActivity.mxData, +// djActivity.pageMap.get("GZID"))); +// } else { +// map.put("mxSql", ""); +// map.put("mxData", null); +// } + map.put("gzid", djActivity.pageMap.get("GZID")); + map.put("mxTempTable", djActivity.mxTempTable); + map.put("djlx", djActivity.pageMap.get("DJLX")); + map.put("djbs", djActivity.pageMap.get("DJBS")); + byte[] b; + try { + b = IoUtil.getbyte(map); + String paramString = Base64.encode(b); + DialogUtil.setDialog(djActivity.pd, "消息提示", "单据保存……"); + new RunYmupThread(paramString, djActivity.runHandler, "saveDj",0).start(); + } catch (Exception e) { + DialogUtil.setDialog(djActivity.pd, "消息提示", "参数转换成流失败……"); + } + } + }) + .setNegativeButton("取消", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }).show(); + + } + + public void Mdj_over(final DjActivity djActivity) { + new AlertDialog.Builder(djActivity).setTitle("确定取消框").setMessage("确定退出") + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + exitDj(djActivity); + }}) + .setNegativeButton("取消", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }).show(); + } + public void exitDj(DjActivity djActivity){ + DialogUtil.setDialog(djActivity.pd, "消息提示", "单据退出……"); + new ExitThread(djActivity.pageMap.get("GZID"), djActivity.mxTempTable, + djActivity.runHandler,"exitDj").start(); + } + public String getusername(DjActivity djActivity) { + return SysData.lgnname; + } + + public String getjigid(DjActivity djActivity) { + return SysData.jigid; + } + public String getclientid(DjActivity djActivity) { + return SysData.clientid.replaceAll(":", ""); + } + public String getdate(DjActivity djActivity) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd"); + Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ")); +// java.text.DateFormat d3 = DateFormat.getDateInstance(); + return dateFormat.format(date1); + } + + public String getdatetime(DjActivity djActivity) { + return djActivity.pageMap.get("RQ"); + } + + /* + * -取得当前月份 + */ + public int getmonth(DjActivity djActivity) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd kk:mm:ss"); + Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ")); + Calendar calendar = GregorianCalendar.getInstance(); + calendar.setTime(date1); + return calendar.get(Calendar.MONTH) + 1; + } + + /* + * -取得当前年份 + */ + public int getyear(DjActivity djActivity) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd kk:mm:ss"); + Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ")); + Calendar calendar = GregorianCalendar.getInstance(); + calendar.setTime(date1); + return calendar.get(Calendar.YEAR); + } + + /* + * -取得当前天数 + */ + public int getday(DjActivity djActivity) throws ParseException { + SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd kk:mm:ss"); + Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ")); + Calendar calendar = GregorianCalendar.getInstance(); + calendar.setTime(date1); + return calendar.get(Calendar.DATE); + } + /* + * 定位当前位置 + */ + public void Mlocation(DjActivity djActivity){ + Intent intent = new Intent(); + intent.setClass(djActivity,BDMapActivity.class); + djActivity.startActivityForResult(intent,3); + } + /* + * 调用摄像头扫描条码 + */ + public void scan(DjActivity djActivity,String funName){ + String uiId=funName.substring(5, funName.length()-1); + Intent intent = new Intent(); + intent.setClass(djActivity,MipcaActivityCapture.class); + intent.putExtra("uiId", uiId); + djActivity.startActivityForResult(intent,4); + } + public static void main(String[] args) { + String funName="scan(ckname)"; + String uiId=funName.substring(5, funName.length()-6); + System.out.println(funName+"----"+uiId); + } +} diff --git a/app/src/main/java/com/util/DjUtil.java b/app/src/main/java/com/util/DjUtil.java new file mode 100644 index 0000000..076ba48 --- /dev/null +++ b/app/src/main/java/com/util/DjUtil.java @@ -0,0 +1,391 @@ +package com.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.chaoran.entiry.PhotographUi; +import com.chaoran.entiry.SelfCheckBox; +import com.chaoran.entiry.SelfEditText; +import com.chaoran.entiry.SelfImage; +import com.chaoran.entiry.SelfTextBut; +import com.chaoran.imp.InputInterface; +import com.chaoran.thread.ImageUrl; + +import android.graphics.Bitmap; +import android.graphics.Bitmap.CompressFormat; +import android.os.Handler; +import android.view.View; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TabHost; +import android.widget.TextView; + +/* + * 单据工具类 + */ +public class DjUtil { + public static void setUiValue(TabHost layout, Map map, Map pageMap, + Handler imgHandler) { + Set set = map.keySet(); + View view = null; + String name = null; + Object value = null; + int fcolor = -1; + int bcolor = -1; + if (map.containsKey("__FCOLOR")) { + String __fcolor = map.get("__FCOLOR").toString().trim(); + if (__fcolor.length() > 0) { + fcolor = Integer.decode(__fcolor); + } + } + if (map.containsKey("__BCOLOR")) { + String __bcolor = map.get("__BCOLOR").toString().trim(); + if (__bcolor.length() > 0) { + bcolor = Integer.decode(__bcolor); + } + } + for (String s : set) { + name = s.toUpperCase().trim(); + value = map.get(s).toString().trim(); + view = layout.findViewWithTag(name); + if (view != null) { + setText(view, value, imgHandler, fcolor, bcolor); + } else if (pageMap.containsKey(name)) { + if (!pageMap.get(name).equals(value)) { + pageMap.put(name, value); + } + } + } + } + + private static void setText(View view, Object value, Handler imgHandler, + int fcolor, int bcolor) { + // if (view instanceof SelfEditText) { + // System.out.println(value+"============="); + // ((EditText) view).setText(value); + // }else if(view instanceof CheckBox){ + // boolean b=false; + // if(value.trim().equals("是")){ + // b=true; + // } + // ((CheckBox) view).setChecked(b); + // }else if(view instanceof SelfTextBut){ + // ((SelfTextBut) view).setText(value); + // } + // System.out.println(view.toString()+"---"+value); + if (view instanceof InputInterface) { + InputInterface iiView = (InputInterface) view; + if (fcolor > -1) { + iiView.setTextColor(SysUtil.toColor(fcolor)); + } + if (bcolor > -1) { + iiView.setBackgroundDrawable(SysUtil.GradientDrawable(SysUtil + .toColor(bcolor))); + } + if(value==null){ + value=""; + } + iiView.setText(value.toString()); + if (iiView.getIsTextChange()) { + iiView.setIsTextChange(false); + } + } else if (view instanceof CheckBox) { + boolean b = false; + if (value.equals("是")) { + b = true; + } + ((CheckBox) view).setChecked(b); + } else if (view instanceof ImageView) { + // Bitmap bmp =(Bitmap)view.getDrawingCache(); + SelfImage img = (SelfImage) view; + if (img.getBitmap() != null) { + img.getBitmap().recycle(); + } + img.setBitmap(null); + String val=value.toString(); + if (val.length() > 0) { + + new Thread(new ImageUrl(img, val, imgHandler)).start(); + } + }else if(view instanceof PhotographUi){ + PhotographUi photo=(PhotographUi)view; + photo.setImageBitmap(BitMapUtil.byteToBitmap((byte[])value)); + } + } + + public static void setUiValue(TabHost layout, List list, Map pageMap, + Handler imgHandler) { + int len = list.size(); + Map map = null; + String name = null; + Object value = null; + View view = null; +// Object ob = null; + int fcolor = -1; + int bcolor = -1; + for (int i = 0; i < len; i++) { + map = (Map) list.get(i); + name = map.get("fieldname").toString().trim(); + value = map.get("fieldValue"); + view = layout.findViewWithTag(name); + if (view != null) { + if (view instanceof InputInterface) { + if (map.containsKey("__FCOLOR")) { + String __fcolor = map.get("__FCOLOR").toString().trim(); + if (__fcolor.length() > 0) { + fcolor = Integer.decode(__fcolor); + } + } + if (map.containsKey("__BCOLOR")) { + String __bcolor = map.get("__BCOLOR").toString().trim(); + if (__bcolor.length() > 0) { + bcolor = Integer.decode(__bcolor); + } + } + } + setText(view, value, imgHandler, fcolor, bcolor); + } else if (pageMap.containsKey(name)) { + if (!pageMap.get(name).equals(value)) { + pageMap.put(name, value); + } + } + } + } + + public static void setUiValue2(TabHost layout, Map map, Handler imgHandler) { + Set set = map.keySet(); + View view = null; + ArrayList list = new ArrayList(); + for (String s : set) { + view = layout.findViewWithTag(s); + if (view != null) { + // if (view instanceof SelfEditText) { + // ((SelfEditText) view).setText(map.get(s).toString().trim()); + // } else if (view instanceof TextView) { + // ((TextView) view).setText(map.get(s).toString().trim()); + // } + setText(view, map.get(s).toString().trim(), imgHandler, -1, -1); + list.add(s); + } + } + for (int i = 0; i < list.size(); i++) { + map.remove(list.get(i)); + } + } + + public static Map organizationHzData(TabHost hzhost, String gzid) { + FrameLayout fl = hzhost.getTabContentView(); + int count = fl.getChildCount(); + MxTabHostContent layout = null; + // System.out.println(count + "------------------------总量"); + Map hzData = new HashMap(); + ArrayList pzImgList = null; + for (int i = 0; i < count; i++) { + layout = (MxTabHostContent) fl.getChildAt(i); + // System.out.println(layout+"========="); + int len = layout.getChildCount(); + View view = null; + String value = null; + // System.out.println(len+"---------"); + for (int j = 0; j < len; j++) { + view = layout.getChildAt(j); + if (view.getTag() == null) { + continue; + } + if (view instanceof PhotographUi) { + if (pzImgList == null) { + pzImgList = new ArrayList(); + } + PhotographUi pu = (PhotographUi) view; + if (pu.getImageBitmap() != null) { + HashMap imgMap = new HashMap(); + imgMap.put("photo",SysUtil.bitmapToByte(pu.getImageBitmap())); + imgMap.put("fieldname", pu.getTag().toString()); + imgMap.put("gzid", gzid); + pzImgList.add(imgMap); + } + } else { + if (view instanceof InputInterface) { + InputInterface et = (InputInterface) view; + value = et.getText().toString(); + if (value == null) { + value = ""; + } + hzData.put(et.getTag().toString(), value.trim()); + } else if (view instanceof SelfCheckBox) { + SelfCheckBox sfb = (SelfCheckBox) view; + boolean b = sfb.isChecked(); + if (b) { + hzData.put(sfb.getTag().toString(), "是"); + } else { + hzData.put(sfb.getTag().toString(), "否"); + } + } + } + } + } + HashMap map = new HashMap(); + map.put("hzData", hzData); + if (pzImgList != null) { + map.put("pzImgList", pzImgList); + } + return map; + } + + /* 保存方案组织汇总数据 */ + public static Object saveOrganizationHzData(TabHost hzhost,String gzid) { + FrameLayout fl = hzhost.getTabContentView(); + int count = fl.getChildCount(); + MxTabHostContent layout = null; + ArrayList pzImgList = null; + // System.out.println(count + "------------------------总量"); + Map hzData = new HashMap(); + for (int i = 0; i < count; i++) { + layout = (MxTabHostContent) fl.getChildAt(i); + int len = layout.getChildCount(); + View view = null; + String value = null; + for (int j = 0; j < len; j++) { + view = layout.getChildAt(j); + if (view.getTag() == null) { + continue; + } + if (view instanceof PhotographUi) { + PhotographUi pu = (PhotographUi) view; + if (pu.getImageBitmap() != null) { + + HashMap imgMap = new HashMap(); + imgMap.put("photo",SysUtil.bitmapToByte(pu.getImageBitmap())); + imgMap.put("fieldname", pu.getTag().toString()); + imgMap.put("gzid", gzid); + if (pzImgList == null) { + pzImgList = new ArrayList(); + } + pzImgList.add(imgMap); + } + } else { + if (view instanceof InputInterface) { + InputInterface et = (InputInterface) view; + value = et.getText().toString(); + if (et.getIsNull()) { + if (value == null || value.length() < 1) { + return et; + } + } + if (value == null) { + value = ""; + } + hzData.put(et.getTag().toString(), value.trim()); + } else if (view instanceof SelfCheckBox) { + SelfCheckBox sfb = (SelfCheckBox) view; + boolean b = sfb.isChecked(); + if (b) { + hzData.put(sfb.getTag().toString(), "是"); + } else { + hzData.put(sfb.getTag().toString(), "否"); + } + } + } + } + } + HashMap map = new HashMap(); + map.put("hzData", hzData); + if (pzImgList != null) { + map.put("pzImgList", pzImgList); + } + return map; + } + + /* 组织明细数据插入sql */ + public static String createMxSql(ArrayList mxFieldList, String mxTempTable) { + int len = mxFieldList.size(); + if (len < 1) { + return null; + } + StringBuilder mxInsertSql = new StringBuilder(); + StringBuilder fieldName = new StringBuilder("gzid,dj_sn,dj_sort");// 列名 + StringBuilder paramName = new StringBuilder(":gzid,:dj_sn,:dj_sort");// 参数名 + String fdname = null; + Map column = null; + for (int i = 0; i < len; i++) { + column = (Map) mxFieldList.get(i); + if (!fieldName.equals("")) { + fieldName.append(","); + paramName.append(","); + } + fdname = column.get("fdname").toString().trim(); + fieldName.append(fdname); + paramName.append(":").append(fdname); + } + mxInsertSql.append("insert ").append(mxTempTable).append("(") + .append(fieldName).append(")").append("values(") + .append(paramName).append(")"); + return mxInsertSql.toString(); + } + + /* 组织明细数据查询sql */ + public static String createMxQuerySql(ArrayList mxFieldList, + String mxTempTable) { + int len = mxFieldList.size(); + if (len < 1) { + return null; + } + StringBuilder mxInsertSql = new StringBuilder(); + StringBuilder fieldName = new StringBuilder("gzid,dj_sn,dj_sort");// 列名 + String fdname = null; + Map column = null; + for (int i = 0; i < len; i++) { + column = (Map) mxFieldList.get(i); + if (!fieldName.equals("")) { + fieldName.append(","); + } + fdname = column.get("fdname").toString().trim(); + fieldName.append(fdname); + } + mxInsertSql.append("select ").append(fieldName).append(" from ") + .append(mxTempTable); + return mxInsertSql.toString(); + } + + /* 组织明细数据 */ + public static ArrayList organizationMxData(List list, String gzid) { + ArrayList mxData = new ArrayList(); + int len = list.size(); + Map map = null; + for (int i = 0; i < len; i++) { + map = (Map) list.get(i); + map.put("gzid", gzid); + map.put("dj_sn", i + 1); + map.put("dj_sort", i + 1); + mxData.add(map); + } + return mxData; + } + + public static void setFocus(TabHost layout, String focus) { + View view = layout.findViewWithTag(focus.toUpperCase().trim()); + if (view != null) { + view.requestFocus(); + } + } + + public static void assembleFangA(HashMap map, ArrayList list) { + // if (list != null) { + int len = list.size(); + HashMap tempObMap = null; + for (int i = 0; i < len; i++) { + tempObMap = (HashMap) list.get(i); + map.put(tempObMap.get("funName"), tempObMap); + } + // } + } + +} diff --git a/app/src/main/java/com/util/Dom4jUtil.java b/app/src/main/java/com/util/Dom4jUtil.java new file mode 100644 index 0000000..d213195 --- /dev/null +++ b/app/src/main/java/com/util/Dom4jUtil.java @@ -0,0 +1,591 @@ +package com.util; + +import java.io.InputStream; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import com.chaoran.component.AntLine; +import com.chaoran.component.SelfHRule; +import com.chaoran.entiry.PhotographUi; +import com.chaoran.entiry.SelfButton; +import com.chaoran.entiry.SelfCheckBox; +import com.chaoran.entiry.SelfDateField; +import com.chaoran.entiry.SelfEditText; +import com.chaoran.entiry.SelfImage; +import com.chaoran.entiry.SelfTextBut; +import com.chaoran.entiry.UpdataInfo; +import com.chaoran.imp.InputInterface; +import com.chaoran.thread.ImageUrl; +import com.example.chaoran.DjActivity; +import com.sys.SysData; + +import com.example.chaoran.R; +import android.app.Activity; +import android.graphics.Color; +import android.os.Build.VERSION; +import android.text.InputType; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +public class Dom4jUtil { + public static void testParseXMLData(InputStream in, DjActivity aa) + throws DocumentException { + // 产生一个解析器对象 + SAXReader reader = new SAXReader(); + // 将xml文档转换为Document的对象 + Document document = reader.read(in); + // 获取文档的根元素 + Element root = document.getRootElement(); + Iterator i_pe = root.elementIterator(); + MxTabHostContent layout; + int i = 0; + String title = null; + while (i_pe.hasNext()) { + Element e_pe = (Element) i_pe.next(); + Iterator i_pe1 = e_pe.elementIterator(); + if (!i_pe1.hasNext()) { + continue; + } + layout = new MxTabHostContent(aa); + layout.setFocusable(true); + layout.setFocusableInTouchMode(true); + if (e_pe.attributeValue("title") != null) { + title = e_pe.attributeValue("title").trim(); + } else { + title = "汇总"; + } + if (title.equals("")) { + title = "汇总"; + } + aa.hzTab.addTab(aa.hzTab.newTabSpec("hzchild" + i) + .setIndicator(title).setContent(layout)); + aa.hzTab.setCurrentTab(i); + i++; + while (i_pe1.hasNext()) { + Element e_pe1 = (Element) i_pe1.next(); + String name = e_pe1.attributeValue("name"); + name = name.substring(name.indexOf("::") + 2, name.length()); + int w = (int) (Double.parseDouble(e_pe1 + .elementText("width_attribute"))); + int h = (int) (Double.parseDouble(e_pe1 + .elementText("height_attribute"))); + int x = (int) (Double.parseDouble(e_pe1 + .elementText("x_attribute"))); + int y = (int) (Double.parseDouble(e_pe1 + .elementText("y_attribute"))); + w = (int) (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, w, aa.getResources() + .getDisplayMetrics()) * SysData.t_scale); + h = (int) (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, h, aa.getResources() + .getDisplayMetrics()) * SysData.t_scale); + x = (int) (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, x, aa.getResources() + .getDisplayMetrics()) * SysData.t_scale); + y = (int) (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, y, aa.getResources() + .getDisplayMetrics()) * SysData.t_scale); + // int w = UnitConversionUtil.convertDIP2PX(Double + // .parseDouble(e_pe1.elementText("width_attribute"))); + // int h = UnitConversionUtil.convertDIP2PX(Double + // .parseDouble(e_pe1.elementText("height_attribute"))); + // int x = UnitConversionUtil.convertDIP2PX(Double + // .parseDouble(e_pe1.elementText("x_attribute"))); + // int y = UnitConversionUtil.convertDIP2PX(Double + // .parseDouble(e_pe1.elementText("y_attribute"))); + // System.out.println(h+"================"+name); + RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( + w, h); + layoutParams.topMargin = y; + layoutParams.leftMargin = x; + if (name.equals("SelfButton")) { + if (isVisible(e_pe1)) { + continue; + } + SelfButton but = new SelfButton(aa); + if (SysData.t_scale < 1) { + but.setPadding((int) (but.getPaddingLeft() * SysData.t_scale * 0.2f), (int) (but.getPaddingTop() * SysData.t_scale * 0.2f), + (int) (but.getPaddingRight() * SysData.t_scale * 0.2f), (int) (but.getPaddingBottom() * SysData.t_scale * 0.2f)); + } + // but.setFocusableInTouchMode(true); + but.setText(e_pe1.elementText("label_attribute")); + if (e_pe1.element("click_function") != null) { + but.setOnClickListener(aa.clickEvent); + but.clickFun = e_pe1.elementText("click_function") + .toString(); + } + if (e_pe1.element("enterKey_attribute") != null) { + but.nextFocus = e_pe1.elementText("enterKey_attribute") + .toString().toUpperCase(); + } + if (e_pe1.element("fontSize_style") != null) { + but.setTextSize(Float.parseFloat(e_pe1.elementText( + "fontSize_style").toString()) * SysData.t_scale); + } + if (e_pe1.element("key_value") != null) { + but.setTag(e_pe1.elementText("key_value").toString() + .trim().toUpperCase()); + } + // but.setLayoutParams(new + // AbsoluteLayout.LayoutParams(w,h,x,y)); + layout.addView(but, layoutParams); + } else if (name.equals("SelfLabel")) { + if (isVisible(e_pe1)) { + continue; + } + TextView tv = new TextView(aa); + // tv.setBackgroundColor(Color.GRAY); + tv.setGravity(Gravity.CENTER_VERTICAL); + if (e_pe1.element("fontSize_style") != null) { + tv.setTextSize(Float.parseFloat(e_pe1.elementText( + "fontSize_style").toString()) * SysData.t_scale); + } + tv.setText(e_pe1.elementText("text_attribute")); + // tv.setLayoutParams(new + // AbsoluteLayout.LayoutParams(w,h,x,y)); + layout.addView(tv, layoutParams); + } else if (name.equals("SelfTextInput")) { + if (!isVisible_attribute(e_pe1, aa)) { + continue; + } + if (e_pe1.attributeValue("isDouble").equals("yes")) { + SelfTextBut stb = new SelfTextBut(aa); + if (e_pe1.element("doubleClick_function") != null) { + stb.setOnClickListener(aa.clickEvent); + stb.setClickFun(e_pe1 + .elementText("doubleClick_function") + .toString().toUpperCase()); + } + // setTextButAtt(stb, e_pe1, aa); + setTextButAtt((InputInterface) stb, e_pe1, aa); + layout.addView(stb, layoutParams); + } else { + SelfEditText et = new SelfEditText(aa); + if (e_pe1.element("borderStyle_style") != null) { + et.showBorder = e_pe1.elementText( + "borderStyle_style").toString(); + } + et.setSingleLine(true); + setTextButAtt((InputInterface) et, e_pe1, aa); + layout.addView(et, layoutParams); + } + } else if (name.equals("SelfTextArea")) { + if (!isVisible_attribute(e_pe1, aa)) { + continue; + } + SelfEditText area = new SelfEditText(aa); + if (e_pe1.element("borderStyle_style") != null) { + area.showBorder = e_pe1 + .elementText("borderStyle_style").toString(); + } + // setEditTextAtt(area, e_pe1, aa); + setTextButAtt((InputInterface) area, e_pe1, aa); + area.setSingleLine(false); + // if(e_pe1.element("backgroundColor_style") != + // null){//backgroundColor_style + // area.setBackgroundColor(SysUtil.toHex(e_pe1.elementText("backgroundColor_style") + // .toString())); + // } + // if(e_pe1.element("color_style") != + // null){//backgroundColor_style + // area.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style") + // .toString())); + // } + layout.addView(area, layoutParams); + } else if (name.equals("SelfCheckBox")) { + // if (isVisible(e_pe1)) { + // continue; + // } + if (!isVisible_attribute(e_pe1, aa)) { + continue; + } + SelfCheckBox box = new SelfCheckBox(aa); + if (SysData.t_scale < 1) { + box.setPadding((int)(box.getPaddingLeft() * SysData.t_scale * 0.2f), box.getPaddingTop(), box.getPaddingRight(), box.getPaddingBottom()); + } + if (e_pe1.element("name_attribute") != null) { + box.setTag(e_pe1.elementText("name_attribute") + .toString().trim().toUpperCase()); + } + if (e_pe1.element("label_attribute") != null) { + box.setText(e_pe1.elementText("label_attribute") + .toString()); + } + if (e_pe1.element("fontSize_style") != null) { + box.setTextSize(Float.parseFloat(e_pe1.elementText( + "fontSize_style").toString()) * SysData.t_scale); //checkbox + 5会变大 + } + if (e_pe1.element("enabled_attribute") != null) { + String enabled = e_pe1.elementText("enabled_attribute") + .toString(); + box.setEnabled(Boolean.parseBoolean(enabled)); + } + if (e_pe1.element("text_attribute") != null) { + String funName = e_pe1.elementText("text_attribute") + .toString().trim().toLowerCase(); + if (dyhs(funName, aa).equals("是")) { + box.setChecked(true); + } + } + + layout.addView(box, layoutParams); + } else if (name.equals("SelfImage")) { + if (isVisible(e_pe1)) { + continue; + } + SelfImage imageView = new SelfImage(aa); + if (e_pe1.element("source_attribute") != null) { + String url = e_pe1.elementText("source_attribute") + .toString().trim(); + if (url.substring(0, 7).equals("http://")) { + new Thread(new ImageUrl(imageView, url, + aa.imgHandler)).start(); + } else if (url.indexOf(".") > 0) { + new Thread(new ImageUrl(imageView, SysData.url + .substring(0, SysData.url.lastIndexOf("/")) + .concat("/").concat(url), aa.imgHandler)) + .start(); + } else if (url.length() > 0) { + imageView.setTag(url.toUpperCase()); + } + } + imageView.setOnClickListener(aa.imgClickEvent); + layout.addView(imageView, layoutParams); + } else if (name.equals("SelfHRule") || name.equals("SelfVRule")) { + if (isVisible(e_pe1)) { + continue; + } + SelfHRule hrule = new SelfHRule(aa); + if (e_pe1.element("strokeColor_style") != null) { + // System.out.println(); + hrule.setColor(SysUtil.toHex(e_pe1.elementText( + "strokeColor_style").toString())); + } + layout.addView(hrule, layoutParams); + } else if (name.equals("AntLine")) { + if (isVisible(e_pe1)) { + continue; + } + AntLine al = new AntLine(aa); + if (e_pe1.element("lineColor_attribute") != null) { + al.setColor(SysUtil.toHex(e_pe1.elementText( + "lineColor_attribute").toString())); + } + if (e_pe1.element("lineThickness_attribute") != null) { + al.setSize(Integer.parseInt(e_pe1 + .elementText("lineThickness_attribute")) * 2); + } + layout.addView(al, layoutParams); + } else if (name.equals("SelfDateField")) { + SelfDateField df = new SelfDateField(aa); + if (e_pe1.element("formatString_attribute") != null) { + df.formatString = e_pe1 + .elementText("formatString_attribute") + .toString().trim().toLowerCase(); + if (df.formatString.length() < 1) { + df.formatString = "yyyy-mm-dd"; + } + df.formatString = df.formatString.replace("mm", "MM"); + } + setTextButAtt((InputInterface) df, e_pe1, aa); + layout.addView(df, layoutParams); + } else if (name.equals("PhotographUi")) { + if (isVisible(e_pe1)) { + continue; + } + int hh = (int) (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, 36, aa.getResources() + .getDisplayMetrics()) * SysData.t_scale); + PhotographUi pu = new PhotographUi(aa, h - hh); + layout.addView(pu, layoutParams); + pu.setOnClickListener(aa.pzClickEvent); + pu.setImageOnClickListener(aa.imgClickEvent); + if (e_pe1.element("name_attribute") != null) { + pu.setTag(e_pe1.elementText("name_attribute") + .toString().trim().toUpperCase()); + } + } + } + aa.setTabwidgetAtt(aa.hzTab.getTabWidget()); + aa.hzTab.setCurrentTab(0); + // break; + } + } + + // /* 设置属性 */ + // public static void setEditTextAtt(SelfEditText et, Element e_pe1, + // DjActivity djActivity) { + // et.setPadding(0, 0, 0, 0); + // et.setGravity(Gravity.CENTER_VERTICAL); + // if (e_pe1.element("name_attribute") != null) { + // et.setTag(e_pe1.elementText("name_attribute").toString().trim() + // .toUpperCase()); + // } + // if (e_pe1.element("enterKey") != null) { + // et.nextFocus = e_pe1.elementText("enterKey").toString() + // .toUpperCase(); + // } + // if (e_pe1.element("fontSize_style") != null) { + // et.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style") + // .toString()) + 5); + // } + // // et.setText(e_pe1.elementText("text_attribute")); + // boolean b = false;// 判断是否需要加焦点事件 + // if (e_pe1.element("focusOut_function") != null) { + // et.focusOutFun = e_pe1.elementText("focusOut_function").toString(); + // if (!b) { + // b = true; + // } + // } + // if (e_pe1.element("focusIn_function") != null) { + // et.focusInFun = e_pe1.elementText("focusIn_function").toString(); + // if (!b) { + // b = true; + // } + // } + // if (b) { + // et.setOnFocusChangeListener(djActivity.focusEvent); + // } + // if (e_pe1.element("enabled_attribute") != null) { + // Boolean enabled = Boolean.parseBoolean(e_pe1.elementText( + // "enabled_attribute").toString()); + // et.setEnabled(enabled); + // if (!enabled) { + // if (e_pe1.element("backgroundColor_style") != null) {// + // backgroundColor_style + // et.setBackgroundDrawable(SysUtil.GradientDrawable(e_pe1 + // .elementText("backgroundColor_style").toString())); + // } + // } + // } + // if (e_pe1.element("text_attribute") != null) { + // String funName = e_pe1.elementText("text_attribute").toString() + // .trim(); + // DjMenuFun menufun = new DjMenuFun(); + // Class cla = menufun.getClass(); + // try { + // Method method = cla.getDeclaredMethod(funName); + // if (method != null) { + // et.setText(method.invoke(menufun).toString()); + // } + // } catch (Exception e) { + // et.setText(funName); + // } + // } + // } + public static boolean isVisible(Element e_pe1) { + boolean b = false; + if (e_pe1.element("visible_attribute") != null) { + if (e_pe1.elementText("visible_attribute").toString().trim() + .equals("false")) { + b = true; + } else { + b = false; + } + } + return b; + } + + /* 设置属性 */ + public static void setTextButAtt(InputInterface et, Element e_pe1, + DjActivity djActivity) { + et.setPadding(0, 0, 0, 0); + et.setGravity(Gravity.CENTER_VERTICAL); + if (e_pe1.element("name_attribute") != null) { + et.setTag(e_pe1.elementText("name_attribute").toString().trim() + .toUpperCase()); + } + if (e_pe1.element("enterKey") != null) { + et.setNextFocus(e_pe1.elementText("enterKey").toString() + .toUpperCase()); + } + if (e_pe1.element("fontSize_style") != null) { + et.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style") + .toString()) * SysData.t_scale + 5); + } + if (e_pe1.element("closeKeyBoard") != null) { + boolean closeKeyBoard = Boolean.parseBoolean(e_pe1 + .elementText("closeKeyBoard")); + et.setCloseKeyBoard(closeKeyBoard); + if (closeKeyBoard) { + et.setInputType(InputType.TYPE_NULL); + } + } + // if(e_pe1.element("doubleClick_function") != null){ + // et.setOnClickListener(djActivity.clickEvent); + // et.setClickFun(e_pe1.elementText("doubleClick_function").toString().toUpperCase()); + // } + // et.setText(e_pe1.elementText("text_attribute")); + // boolean b = false;// 判断是否需要加焦点事件 + if (e_pe1.element("focusOut_function") != null) { + et.setFocusOutFun(e_pe1.elementText("focusOut_function").toString()); + // if (!b) { + // b = true; + // } + } + if (e_pe1.element("focusIn_function") != null) { + et.setFocusInFun(e_pe1.elementText("focusIn_function").toString()); + // if (!b) { + // b = true; + // } + } + // if (b) { + et.setOnFocusChangeListener(djActivity.focusEvent); + // } + if (e_pe1.element("enabled_attribute") != null) { + Boolean enabled = Boolean.parseBoolean(e_pe1.elementText( + "enabled_attribute").toString()); + et.setEnabled(enabled); + // if (!enabled) { + // } + } + if (e_pe1.element("backgroundColor_style") != null) {// backgroundColor_style + et.setBackgroundDrawable(SysUtil.GradientDrawable(e_pe1 + .elementText("backgroundColor_style").toString())); + } else { + et.setBackgroundDrawable(SysUtil.GradientDrawable()); + } + if (e_pe1.element("text_attribute") != null) { + String funName = e_pe1.elementText("text_attribute").toString() + .trim().toLowerCase(); + et.setText(dyhs(funName, djActivity)); + } + if (e_pe1.element("isValue_attribute") != null) { + et.setIsNull(Boolean.parseBoolean(e_pe1 + .elementText("isValue_attribute"))); + } + if (e_pe1.element("label_attribute") != null) { + et.setLabel(e_pe1.elementText("label_attribute").toString().trim()); + } + if (e_pe1.element("label_attribute") != null) { + et.setLabel(e_pe1.elementText("label_attribute").toString().trim()); + } + if (e_pe1.element("color_style") != null) { + et.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style") + .toString().trim())); + } + // if (e_pe1.element("fdtype")!= null) { + // String fdtype=e_pe1.elementText("fdtype").toString().trim(); + // if(fdtype.equals("整数")){ + // et.setDefaultValue("0"); + // }else if(fdtype.equals("实数")||fdtype.equals("浮点")){ + // et.setDefaultValue("0.00"); + // } + // } + } + + public static String dyhs(String funName, DjActivity activity) { + String val = ""; + DjMenuFun menufun = new DjMenuFun(); + Class cla = menufun.getClass(); + try { + Method method = cla.getDeclaredMethod(funName, DjActivity.class); + if (method != null) { + // if(method.getGenericParameterTypes().length>0){ + val = method.invoke(menufun, new Object[] { activity }) + .toString(); + // }else{ + // val = method.invoke(menufun).toString(); + // } + } else { + val = funName; + } + } catch (Exception e) { + // e.printStackTrace(); + val = funName; + } + return val; + } + + /* 解析更新xml */ + public static UpdataInfo parserXml(InputStream in, String version) + throws DocumentException { + version = version.substring(0, 1).toUpperCase(); + // 产生一个解析器对象 + SAXReader reader = new SAXReader(); + reader.setEncoding("UTF-8"); + // 将xml文档转换为Document的对象 + Document document = reader.read(in); + // 获取文档的根元素 + Element root = document.getRootElement(); + UpdataInfo info = null; + List list = root.elements(); + if (list != null) { + for (int i = 0; i < list.size(); i++) { + root = list.get(i); + if (root.getName().toUpperCase().equals("PDA")) { + Iterator i_pe = root.elementIterator(); + if (root.attributeValue("model").toUpperCase() + .equals(version)) { + info = gerUpdataInfo(i_pe); + break; + } + } + } + } + return info; + } + + public static UpdataInfo gerUpdataInfo(Iterator i_pe) { + String name = null; + UpdataInfo info = new UpdataInfo();// 实体 + while (i_pe.hasNext()) { + Element e_pe = (Element) i_pe.next(); + name = e_pe.getName(); + if ("version".equals(name)) { + info.setVersion(e_pe.getText()); // 获取版本号 + } else if ("url".equals(name)) { + info.setUrl(e_pe.getText()); // 获取要升级的APK文件 + } else if ("description".equals(name)) { + info.setDescription(e_pe.getText()); // 获取该文件的信息 + } + } + return info; + } + + public static boolean isVisible_attribute(Element e_pe11, + DjActivity djActivity) { + boolean isVisible = true; + if (e_pe11.element("visible_attribute") != null) { + if (e_pe11.elementText("visible_attribute").toString().trim() + .equals("false")) { + isVisible = false; + String val = ""; + if (e_pe11.element("text_attribute") != null) { + String funName = e_pe11.elementText("text_attribute") + .toString().trim(); + val = dyhs(funName, djActivity); + } + // if(val==null||val.length()==0){ + // if (e_pe11.element("fdtype")!= null) { + // String fdtype=e_pe11.elementText("fdtype").toString().trim(); + // if(fdtype.equals("整数")){ + // val="0"; + // }else if(fdtype.equals("实数")||fdtype.equals("浮点")){ + // val="0.00"; + // }else{ + // val=""; + // } + // } + // } + if (e_pe11.element("name_attribute") != null) { + djActivity.pageMap.put(e_pe11.elementText("name_attribute") + .toString().trim().toUpperCase(), val); + } + } + } + return isVisible; + } +} diff --git a/app/src/main/java/com/util/DownloadManager.java b/app/src/main/java/com/util/DownloadManager.java new file mode 100644 index 0000000..bbacc3c --- /dev/null +++ b/app/src/main/java/com/util/DownloadManager.java @@ -0,0 +1,48 @@ +package com.util; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +import android.app.ProgressDialog; +import android.content.Context; + +public class DownloadManager { + public static File getFileFromServer(String path, ProgressDialog pd,Context context) + throws Exception { + // 如果相等的话表示当前的sdcard挂载在手机上并且是可用的 +// if (Environment.getExternalStorageState().equals( +// Environment.MEDIA_MOUNTED)) { + URL url = new URL(path); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(5000); + // 获取到文件的大小 + pd.setMax(conn.getContentLength()/1000); + InputStream is = conn.getInputStream(); +// File file = new File(Environment.getExternalStorageDirectory(), +// "updata.apk");//得到sd卡的目录 + File file = new File(context.getCacheDir().getParentFile(), + "updata.apk"); //放到当前应用程序所在的目录下 + FileOutputStream fos = new FileOutputStream(file); + BufferedInputStream bis = new BufferedInputStream(is); + byte[] buffer = new byte[1024]; + int len; + int total = 0; + while ((len = bis.read(buffer)) != -1) { + fos.write(buffer, 0, len); + total += len; + // 获取当前下载量 + pd.setProgress(total/1000); + } + fos.close(); + bis.close(); + is.close(); + return file; +// } else { +// return null; +// } + } +} diff --git a/app/src/main/java/com/util/InstallUtil.java b/app/src/main/java/com/util/InstallUtil.java new file mode 100644 index 0000000..51b01a2 --- /dev/null +++ b/app/src/main/java/com/util/InstallUtil.java @@ -0,0 +1,33 @@ +package com.util; + +import java.io.File; +import java.io.IOException; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; + +public class InstallUtil { + // 安装apk + public void installApk(File file,Activity activity) { + chmod("777", file.getPath()); + Intent intent = new Intent(); + // 执行动作 + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setAction(Intent.ACTION_VIEW); + // 执行的数据类型 + intent.setDataAndType(Uri.fromFile(file), + "application/vnd.android.package-archive"); + activity.startActivity(intent); + } + // 修改apk权限 + public static void chmod(String permission, String path) { + try { + String command = "chmod " + permission + " " + path; + Runtime runtime = Runtime.getRuntime(); + runtime.exec(command); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/app/src/main/java/com/util/IoUtil.java b/app/src/main/java/com/util/IoUtil.java new file mode 100644 index 0000000..9f02d7d --- /dev/null +++ b/app/src/main/java/com/util/IoUtil.java @@ -0,0 +1,102 @@ +package com.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.StreamCorruptedException; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import org.kobjects.base64.Base64; + +public class IoUtil { + /*zip解压缩*/ + public static Object byte_obj(byte[] b) throws StreamCorruptedException, + IOException, ClassNotFoundException { + ByteArrayInputStream bin = null; + GZIPInputStream gzip = null; + ObjectInputStream oin = null; + try { + bin = new ByteArrayInputStream(b); + gzip = new GZIPInputStream(bin); + oin = new ObjectInputStream(gzip); + return oin.readObject(); + } finally { + if (oin != null) { + oin.close(); + } + if (gzip != null) { + gzip.close(); + } + if (bin != null) { + bin.close(); + } + System.out.println("留关闭---"); + } + } + + public static Object byte_obj2(byte[] b) throws StreamCorruptedException, + IOException, ClassNotFoundException { + ByteArrayInputStream bin = null; + ObjectInputStream oin = null; + try { + bin = new ByteArrayInputStream(b); + oin = new ObjectInputStream(bin); + return oin.readObject(); + } finally { + if (oin != null) { + oin.close(); + } + if (bin != null) { + bin.close(); + } + System.out.println("留关闭"); + } + } + /*gzip压缩*/ + public static byte[] getbyte(Object ob) throws Exception { + ByteArrayOutputStream byteOut = null; + GZIPOutputStream gziOut = null; + ObjectOutputStream objectOut = null; + try { + byteOut = new ByteArrayOutputStream(); + gziOut = new GZIPOutputStream(byteOut); + objectOut = new ObjectOutputStream(gziOut); + objectOut.writeObject(ob); + objectOut.flush(); + objectOut.close(); + gziOut.close(); + byteOut.close(); + return byteOut.toByteArray(); + } finally { +// if(objectOut!=null){ +// objectOut.close(); +// } +// if(gziOut!=null){ +//// gziOut.finish(); +// gziOut.close(); +// } +// if(byteOut!=null){ +// byteOut.close(); +// } + } + } + + public static String ob_base64(Object ob) throws IOException { + ByteArrayOutputStream bOut = null; + ObjectOutputStream objOut = null; + try { + bOut = new ByteArrayOutputStream(); + objOut = new ObjectOutputStream(bOut); + objOut.writeObject(ob); + return Base64.encode(bOut.toByteArray()); + } finally { + objOut.flush(); + objOut.close(); + bOut.flush(); + bOut.close(); + } + } +} diff --git a/app/src/main/java/com/util/LxParamPageCreate.java b/app/src/main/java/com/util/LxParamPageCreate.java new file mode 100644 index 0000000..77d36a2 --- /dev/null +++ b/app/src/main/java/com/util/LxParamPageCreate.java @@ -0,0 +1,265 @@ +package com.util; + +import java.io.InputStream; +import java.util.Iterator; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import android.app.Activity; +import android.text.InputType; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.chaoran.component.AntLine; +import com.chaoran.component.SelfHRule; +import com.chaoran.entiry.PhotographUi; +import com.chaoran.entiry.SelfButton; +import com.chaoran.entiry.SelfCheckBox; +import com.chaoran.entiry.SelfDateField; +import com.chaoran.entiry.SelfEditText; +import com.chaoran.entiry.SelfImage; +import com.chaoran.entiry.SelfTextBut; +import com.chaoran.imp.InputInterface; +import com.chaoran.thread.ImageUrl; +import com.example.chaoran.DjActivity; +import com.sys.SysData; + +public class LxParamPageCreate { + public static void lxParamPageCreate(InputStream in, Activity activity, RelativeLayout layout) throws DocumentException { + SAXReader reader = new SAXReader(); + // 将xml文档转换为Document的对象 + Document document = reader.read(in); + // 获取文档的根元素 + Element root = document.getRootElement(); + Iterator i_pe = root.elementIterator(); + while (i_pe.hasNext()) { + Element e_pe = (Element) i_pe.next(); + Iterator i_pe1 = e_pe.elementIterator(); + if (!i_pe1.hasNext()) { + continue; + } + while (i_pe1.hasNext()) { + Element e_pe1 = (Element) i_pe1.next(); + String name = e_pe1.attributeValue("name"); + name = name.substring(name.indexOf("::") + 2, name.length()); + int w = (int) (Double.parseDouble(e_pe1.elementText("width_attribute"))); + int h = (int) (Double.parseDouble(e_pe1.elementText("height_attribute"))); + int x = (int) (Double.parseDouble(e_pe1.elementText("x_attribute"))); + int y = (int) (Double.parseDouble(e_pe1.elementText("y_attribute"))); + w = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, activity.getResources().getDisplayMetrics()) * SysData.t_scale); + h = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, activity.getResources().getDisplayMetrics()) * SysData.t_scale); + x = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, activity.getResources().getDisplayMetrics()) * SysData.t_scale); + y = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, y, activity.getResources().getDisplayMetrics()) * SysData.t_scale); + RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(w, h); + layoutParams.topMargin = y; + layoutParams.leftMargin = x; + if (name.equals("SelfButton")) { + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + SelfButton but = new SelfButton(activity); + if (SysData.t_scale < 1) { + but.setPadding((int) (but.getPaddingLeft() * SysData.t_scale * 0.2f), (int) (but.getPaddingTop() * SysData.t_scale * 0.2f), + (int) (but.getPaddingRight() * SysData.t_scale * 0.2f), (int) (but.getPaddingBottom() * SysData.t_scale * 0.2f)); + } + // but.setFocusableInTouchMode(true); + but.setText(e_pe1.elementText("label_attribute")); + if (e_pe1.element("click_function") != null) { + but.clickFun = e_pe1.elementText("click_function").toString(); + } + if (e_pe1.element("enterKey_attribute") != null) { + but.nextFocus = e_pe1.elementText("enterKey_attribute").toString().toUpperCase(); + } + if (e_pe1.element("fontSize_style") != null) { + but.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale); + } + if (e_pe1.element("key_value") != null) { + but.setTag(e_pe1.elementText("key_value").toString().trim().toUpperCase()); + } + // but.setLayoutParams(new + // AbsoluteLayout.LayoutParams(w,h,x,y)); + layout.addView(but, layoutParams); + } else if (name.equals("SelfLabel")) { + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + TextView tv = new TextView(activity); + tv.setGravity(Gravity.CENTER_VERTICAL); + if (e_pe1.element("fontSize_style") != null) { + tv.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale); + } + tv.setText(e_pe1.elementText("text_attribute")); + layout.addView(tv, layoutParams); + } else if (name.equals("SelfTextInput")) { + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + if (e_pe1.attributeValue("isDouble").equals("yes")) { + SelfTextBut stb = new SelfTextBut(activity); + if (e_pe1.element("doubleClick_function") != null) { + stb.setClickFun(e_pe1.elementText("doubleClick_function").toString().toUpperCase()); + } + // setTextButAtt(stb, e_pe1, aa); + setTextButAtt((InputInterface) stb, e_pe1); + layout.addView(stb, layoutParams); + } else { + SelfEditText et = new SelfEditText(activity); + if (e_pe1.element("borderStyle_style") != null) { + et.showBorder = e_pe1.elementText("borderStyle_style").toString(); + } + et.setSingleLine(true); + setTextButAtt((InputInterface) et, e_pe1); + layout.addView(et, layoutParams); + } + } else if (name.equals("SelfTextArea")) { + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + SelfEditText area = new SelfEditText(activity); + if (e_pe1.element("borderStyle_style") != null) { + area.showBorder = e_pe1.elementText("borderStyle_style").toString(); + } + // setEditTextAtt(area, e_pe1, aa); + setTextButAtt((InputInterface) area, e_pe1); + area.setSingleLine(false); + // if(e_pe1.element("backgroundColor_style") != + // null){//backgroundColor_style + // area.setBackgroundColor(SysUtil.toHex(e_pe1.elementText("backgroundColor_style") + // .toString())); + // } + // if(e_pe1.element("color_style") != + // null){//backgroundColor_style + // area.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style") + // .toString())); + // } + layout.addView(area, layoutParams); + } else if (name.equals("SelfCheckBox")) { + // if (isVisible(e_pe1)) { + // continue; + // } + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + SelfCheckBox box = new SelfCheckBox(activity); + if (SysData.t_scale < 1) { + box.setPadding((int) (box.getPaddingLeft() * SysData.t_scale * 0.2f), box.getPaddingTop(), box.getPaddingRight(), box.getPaddingBottom()); + } + if (e_pe1.element("name_attribute") != null) { + box.setTag(e_pe1.elementText("name_attribute").toString().trim().toUpperCase()); + } + if (e_pe1.element("label_attribute") != null) { + box.setText(e_pe1.elementText("label_attribute").toString()); + } + if (e_pe1.element("fontSize_style") != null) { + box.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale); // checkbox + // + + // 5会变大 + } + if (e_pe1.element("enabled_attribute") != null) { + String enabled = e_pe1.elementText("enabled_attribute").toString(); + box.setEnabled(Boolean.parseBoolean(enabled)); + } + if (e_pe1.element("text_attribute") != null) { + String funName = e_pe1.elementText("text_attribute").toString().trim().toLowerCase(); + if (funName.equals("是")) { + box.setChecked(true); + } + } + layout.addView(box, layoutParams); + } else if (name.equals("SelfHRule") || name.equals("SelfVRule")) { + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + SelfHRule hrule = new SelfHRule(activity); + if (e_pe1.element("strokeColor_style") != null) { + // System.out.println(); + hrule.setColor(SysUtil.toHex(e_pe1.elementText("strokeColor_style").toString())); + } + layout.addView(hrule, layoutParams); + } else if (name.equals("AntLine")) { + if (Dom4jUtil.isVisible(e_pe1)) { + continue; + } + AntLine al = new AntLine(activity); + if (e_pe1.element("lineColor_attribute") != null) { + al.setColor(SysUtil.toHex(e_pe1.elementText("lineColor_attribute").toString())); + } + if (e_pe1.element("lineThickness_attribute") != null) { + al.setSize(Integer.parseInt(e_pe1.elementText("lineThickness_attribute")) * 2); + } + layout.addView(al, layoutParams); + } else if (name.equals("SelfDateField")) { + SelfDateField df = new SelfDateField(activity); + if (e_pe1.element("formatString_attribute") != null) { + df.formatString = e_pe1.elementText("formatString_attribute").toString().trim().toLowerCase(); + if (df.formatString.length() < 1) { + df.formatString = "yyyy-mm-dd"; + } + df.formatString = df.formatString.replace("mm", "MM"); + } + setTextButAtt((InputInterface) df, e_pe1); + layout.addView(df, layoutParams); + } + } + break; + } + } + + /* 设置属性 */ + public static void setTextButAtt(InputInterface et, Element e_pe1) { + et.setPadding(0, 0, 0, 0); + et.setGravity(Gravity.CENTER_VERTICAL); + if (e_pe1.element("name_attribute") != null) { + et.setTag(e_pe1.elementText("name_attribute").toString().trim().toUpperCase()); + } + if (e_pe1.element("enterKey") != null) { + et.setNextFocus(e_pe1.elementText("enterKey").toString().toUpperCase()); + } + if (e_pe1.element("fontSize_style") != null) { + et.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale + 5); + } + if (e_pe1.element("closeKeyBoard") != null) { + boolean closeKeyBoard = Boolean.parseBoolean(e_pe1.elementText("closeKeyBoard")); + et.setCloseKeyBoard(closeKeyBoard); + if (closeKeyBoard) { + et.setInputType(InputType.TYPE_NULL); + } + } + if (e_pe1.element("focusOut_function") != null) { + et.setFocusOutFun(e_pe1.elementText("focusOut_function").toString()); + } + if (e_pe1.element("focusIn_function") != null) { + et.setFocusInFun(e_pe1.elementText("focusIn_function").toString()); + } + if (e_pe1.element("enabled_attribute") != null) { + Boolean enabled = Boolean.parseBoolean(e_pe1.elementText("enabled_attribute").toString()); + et.setEnabled(enabled); + } + if (e_pe1.element("backgroundColor_style") != null) {// backgroundColor_style + et.setBackgroundDrawable(SysUtil.GradientDrawable(e_pe1.elementText("backgroundColor_style").toString())); + } else { + et.setBackgroundDrawable(SysUtil.GradientDrawable()); + } + if (e_pe1.element("text_attribute") != null) { + String funName = e_pe1.elementText("text_attribute").toString().trim().toLowerCase(); + et.setText(funName); + } + if (e_pe1.element("isValue_attribute") != null) { + et.setIsNull(Boolean.parseBoolean(e_pe1.elementText("isValue_attribute"))); + } + if (e_pe1.element("label_attribute") != null) { + et.setLabel(e_pe1.elementText("label_attribute").toString().trim()); + } + if (e_pe1.element("label_attribute") != null) { + et.setLabel(e_pe1.elementText("label_attribute").toString().trim()); + } + if (e_pe1.element("color_style") != null) { + et.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style").toString().trim())); + } + } +} diff --git a/app/src/main/java/com/util/MxTabHostContent.java b/app/src/main/java/com/util/MxTabHostContent.java new file mode 100644 index 0000000..da2a208 --- /dev/null +++ b/app/src/main/java/com/util/MxTabHostContent.java @@ -0,0 +1,24 @@ +package com.util; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.TabHost.TabContentFactory; + +public class MxTabHostContent extends RelativeLayout implements TabContentFactory{ + + public MxTabHostContent(Context context) { + super(context); + } + public MxTabHostContent(Context context, AttributeSet attrs) { + super(context, attrs); + } + @Override + public View createTabContent(String tag) { + // TODO Auto-generated method stub + return this; + } + + +} diff --git a/app/src/main/java/com/util/SqlUtil.java b/app/src/main/java/com/util/SqlUtil.java new file mode 100644 index 0000000..e482d83 --- /dev/null +++ b/app/src/main/java/com/util/SqlUtil.java @@ -0,0 +1,213 @@ +package com.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.chaoran.entiry.SelfCheckBox; +import com.chaoran.entiry.SelfEditText; +import com.chaoran.entiry.SelfTextBut; +import com.chaoran.imp.InputInterface; + +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.TabHost; +import android.widget.TextView; + +public class SqlUtil { + public static HashMap regSql(String sql, TabHost layout, Map pageMap) { + System.out.println("------------------==============================="); +// System.out.println(sql); + // String regEx=":[\\w|.]*[\\s]{0}"; + String regEx = "[:|\\&]([\\w\\.]+)"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(sql); + String paramName = null; + String oldParam = null; + HashMap paramMap = new HashMap(); + String paramValue = null; + String sqlCopy = sql; + String paramType = null; + while (m.find()) { + oldParam = m.group(); + System.out.println(oldParam+"--------------------"); + paramType = oldParam.substring(0, 1); + paramName = oldParam.toUpperCase(); + if (paramName.indexOf("MX.") > -1) { + paramName = paramName.substring(4, paramName.length()); + } else if (paramName.indexOf("HZ.") > -1) { + paramName = paramName.substring(4, paramName.length()); + } else { + paramName = paramName.substring(1, paramName.length()); + } + sqlCopy = sqlCopy.replaceFirst(oldParam, + paramType.concat(paramName)); + View view = layout.findViewWithTag(paramName); + if (view != null) { + // if (view instanceof SelfEditText) { + // paramValue = ((SelfEditText) view).getText().toString() + // .trim(); + // } else if (view instanceof SelfCheckBox) { + // SelfCheckBox sfb = (SelfCheckBox) view; + // boolean b = sfb.isChecked(); + // if (b) { + // paramValue = "是"; + // } else { + // paramValue = "否"; + // } + // } else if (view instanceof TextView) { + // paramValue = ((TextView) view).getText().toString().trim(); + // }else if(view instanceof SelfTextBut){ + // paramValue = ((SelfTextBut) + // view).getText().toString().trim(); + // } + if (view instanceof InputInterface) { + InputInterface inView = (InputInterface) view; + paramValue = inView.getText().toString(); + } else if (view instanceof SelfCheckBox) { + SelfCheckBox sfb = (SelfCheckBox) view; + boolean b = sfb.isChecked(); + if (b) { + paramValue = "是"; + } else { + paramValue = "否"; + } + } else if (view instanceof TextView) { + paramValue = ((TextView) view).getText().toString(); + } + } else if (pageMap.containsKey(paramName)) { + paramValue = pageMap.get(paramName).toString(); + } + if (paramValue == null) { + paramValue = ""; + } else { + paramValue = paramValue.trim(); + } + if (paramType.equals(":")) { + paramMap.put(paramName, paramValue); + } else { + paramValue = paramValue.replace("$", "\\$"); + sqlCopy = sqlCopy.replaceFirst(paramType.concat(paramName), + paramValue); + } + if (paramValue != null) { + paramValue = null; + } + } + HashMap map = new HashMap(); + System.out.println("============="+sqlCopy+"------------------------sqlCopy"); + map.put("sql", sqlCopy); + map.put("param", paramMap); + return map; + } + + public static HashMap regSql(String sql, Map item) { + // String regEx=":[\\w|.]*[\\s]{0}"; + String regEx = "[:|\\&]([\\w\\.]+)"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(sql); + String paramName = null; + String oldParam = null; + HashMap paramMap = new HashMap(); + String paramValue = ""; + String sqlCopy = sql; + String paramType = null; + while (m.find()) { + oldParam = m.group(); + System.out.println(oldParam + "--------------------"); + paramType = oldParam.substring(0, 1); + paramName = oldParam.toUpperCase(); + if (paramName.indexOf("MX.") > -1) { + paramName = paramName.substring(4, paramName.length()); + } else if (paramName.indexOf("HZ.") > -1) { + paramName = paramName.substring(4, paramName.length()); + } else { + paramName = paramName.substring(1, paramName.length()); + } + sqlCopy = sqlCopy.replaceFirst(oldParam, + paramType.concat(paramName)); + if (item.containsKey(paramName)) { + paramValue = item.get(paramName).toString(); + } + if (paramType.equals(":")) { + paramMap.put(paramName, paramValue); + } else { + paramValue = paramValue.replace("$", "\\$"); + sqlCopy = sqlCopy.replaceFirst(paramType.concat(paramName), + paramValue); + } + if (!paramValue.equals("")) { + paramValue = ""; + } + } + HashMap map = new HashMap(); + map.put("sql", sqlCopy); + map.put("param", paramMap); + return map; + } + + public static HashMap regSql(String sql, RelativeLayout layout) { + System.out.println(sql); + String regEx = "[:|\\&]([\\w\\.]+)"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(sql); + String paramName = null; + String oldParam = null; + HashMap paramMap = new HashMap(); + String paramValue = null; + String sqlCopy = sql; + String paramType = null; + while (m.find()) { + oldParam = m.group(); + paramType = oldParam.substring(0, 1); + paramName = oldParam.toUpperCase(); + if (paramName.indexOf("MX.") > -1) { + paramName = paramName.substring(4, paramName.length()); + } else if (paramName.indexOf("HZ.") > -1) { + paramName = paramName.substring(4, paramName.length()); + } else { + paramName = paramName.substring(1, paramName.length()); + } + sqlCopy = sqlCopy.replaceFirst(oldParam, + paramType.concat(paramName)); + View view = layout.findViewWithTag(paramName); + if (view != null) { + if (view instanceof InputInterface) { + InputInterface inView = (InputInterface) view; + paramValue = inView.getText().toString(); + } else if (view instanceof SelfCheckBox) { + SelfCheckBox sfb = (SelfCheckBox) view; + boolean b = sfb.isChecked(); + if (b) { + paramValue = "是"; + } else { + paramValue = "否"; + } + } else if (view instanceof TextView) { + paramValue = ((TextView) view).getText().toString(); + } + } + if (paramValue == null) { + paramValue = ""; + } else { + paramValue = paramValue.trim(); + } + if (paramType.equals(":")) { + paramMap.put(paramName, paramValue); + } else { + paramValue = paramValue.replace("$", "\\$"); + sqlCopy = sqlCopy.replaceFirst(paramType.concat(paramName), + paramValue); + } + if (paramValue != null) { + paramValue = null; + } + } + HashMap map = new HashMap(); + map.put("sql", sqlCopy); + map.put("param", paramMap); + return map; + } + +} diff --git a/app/src/main/java/com/util/SysUtil.java b/app/src/main/java/com/util/SysUtil.java new file mode 100644 index 0000000..801fb0f --- /dev/null +++ b/app/src/main/java/com/util/SysUtil.java @@ -0,0 +1,329 @@ +package com.util; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.lang.reflect.Method; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.ActivityManager; +import android.app.ActivityManager.RunningTaskInfo; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.Bitmap.CompressFormat; +import android.graphics.drawable.GradientDrawable; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Environment; + +public class SysUtil { + + private static String mac = ""; + + /* 把数字转换成颜色 */ + public static int toHex(String value) { + int color = (int) Long.parseLong("ff" + Integer.toHexString(Integer.parseInt(value)), 16); + if (color == 4080) + color = Color.BLACK; + return color; + } + + /* 把6位颜色直(0xff0000) 转换成颜色 */ + public static int toColor(int color) { + int red = (color & 0xff0000) >> 16; + int green = (color & 0x00ff00) >> 8; + int blue = (color & 0x0000ff); + return Color.rgb(red, green, blue); + } + + public static GradientDrawable GradientDrawable(String color) { + GradientDrawable gd = new GradientDrawable(); + gd.setCornerRadius(3); + gd.setColor(toHex(color));// 设置颜色 + // gd.setStroke(3, toHex("14079443")); + return gd; + } + + public static GradientDrawable GradientDrawable(int color) { + GradientDrawable gd = new GradientDrawable(); + gd.setCornerRadius(3); + gd.setColor(color);// 设置颜色 + // gd.setStroke(3, toHex("14079443")); + return gd; + } + + public static GradientDrawable GradientDrawable() { + GradientDrawable gd = new GradientDrawable(); + gd.setCornerRadius(3); + gd.setColor(Color.WHITE);// 设置颜色 + // gd.setStroke(3, toHex("14079443")); + return gd; + } + + public static boolean isTopApp(Context context) { + ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); + List tasks = activityManager.getRunningTasks(1); + if (tasks == null || tasks.isEmpty()) { + return false; + } + RunningTaskInfo task = tasks.get(0); + String className = task.topActivity.getClassName(); + System.out.println(className + "-----------------------------"); + return className.equals(((Activity) context).getComponentName().getClassName()); + } + + // public static String getMac() { + // String macSerial = null; + // String str = ""; + // try { + // Process pp = Runtime.getRuntime().exec( + // "cat /sys/class/net/wlan0/address "); + // InputStreamReader ir = new InputStreamReader(pp.getInputStream()); + // LineNumberReader input = new LineNumberReader(ir); + // + // for (; null != str;) { + // str = input.readLine(); + // if (str != null) { + // macSerial = str.trim();// 去空格 + // break; + // } + // } + // } catch (IOException ex) { + // // 赋予默认值 + // ex.printStackTrace(); + // } + // return macSerial; + // + // } + public static boolean isNetworkConnected(Context context) { + if (context != null) { + ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); + if (mNetworkInfo != null) { + return mNetworkInfo.isAvailable(); + } + } + return false; + } + +/* *//** + * 获取移动设备本地IP + * + * @return + *//* + private static InetAddress getLocalInetAddress() { + InetAddress ip = null; + try { + // 列举 + Enumeration en_netInterface = NetworkInterface + .getNetworkInterfaces(); + while (en_netInterface.hasMoreElements()) {// 是否还有元素 + NetworkInterface ni = (NetworkInterface) en_netInterface + .nextElement();// 得到下一个元素 + Enumeration en_ip = ni.getInetAddresses();// 得到一个ip地址的列举 + while (en_ip.hasMoreElements()) { + ip = en_ip.nextElement(); + if (!ip.isLoopbackAddress() + && ip.getHostAddress().indexOf(":") == -1) + break; + else + ip = null; + } + + if (ip != null) { + break; + } + } + } catch (SocketException e) { + + e.printStackTrace(); + } + return ip; + }*/ + public static String getLocalMacAddress(Activity activity) { + WifiManager wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); + WifiInfo info = wifi.getConnectionInfo(); + mac = info.getMacAddress(); + + if (mac == null || mac.length() < 1 || mac.startsWith("02:00:00:00:00:")) + mac = getMacAddress(); + + mac = mac.toUpperCase(); + + return mac; + } + + @SuppressLint("NewApi") + public static String getMacAddress() { + /* + * 获取mac地址有一点需要注意的就是android + * 6.0版本后,以下注释方法不再适用,不管任何手机都会返回"02:00:00:00:00:00" + * 这个默认的mac地址,这是googel官方为了加强权限管理而禁用了getSYstemService + * (Context.WIFI_SERVICE)方法来获得mac地址。 + */ + // String macAddress= ""; + // WifiManager wifiManager = (WifiManager) + // MyApp.getContext().getSystemService(Context.WIFI_SERVICE); + // WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + // macAddress = wifiInfo.getMacAddress(); + // return macAddress; + + String macAddress = null; + StringBuffer buf = new StringBuffer(); + NetworkInterface networkInterface = null; + try { + networkInterface = NetworkInterface.getByName("eth1"); + if (networkInterface == null) { + networkInterface = NetworkInterface.getByName("wlan0"); + } + if (networkInterface == null) { + return "02:00:00:00:00:02"; + } + byte[] addr = networkInterface.getHardwareAddress(); + for (byte b : addr) { + buf.append(String.format("%02X:", b)); + } + if (buf.length() > 0) { + buf.deleteCharAt(buf.length() - 1); + } + macAddress = buf.toString(); + } catch (SocketException e) { + e.printStackTrace(); + return "02:00:00:00:00:02"; + } + return macAddress; + } + + public static String mapFirst(List list) { + String filedName = null; + Set set = ((HashMap) list.get(0)).keySet(); + for (String s : set) { + filedName = s; + break; + } + return filedName; + } + + @SuppressLint({ "NewApi", "NewApi" }) + public static String getSerialNum() { + // String serialNum = null; + // try { + // Class classZ = Class.forName("android.os.SystemProperties"); + // Method get = classZ.getMethod("get", String.class); + // serialNum = (String) get.invoke(classZ, "ro.serialno"); + // } catch (Exception e) { + // } + String serialNum = android.os.Build.SERIAL; + return serialNum; + } + + /* 东集pda专用获取SN */ + public static String getSn() { + //return mac.toLowerCase().replace(":", ""); + + String sn = getSn0("data/data/sn"); + if (sn == null || sn.trim().length() < 1) + sn = getSn1(); + if (sn.length() >= 15) { + sn = getSn0("/sys/class/net/wlan0/address"); + sn = sn.replace(":", ""); + } + + if (sn != null && sn.trim().length() > 0) + return sn; + else + return mac.toLowerCase().replace(":", ""); + } + + public static String getSn0(String fileName) { + String SN_FILE = fileName; + InputStreamReader isr = null; + FileInputStream inputStream = null; + byte[] buffer = new byte[64]; + File file = new File(SN_FILE); + int code = 0; + try { + inputStream = new FileInputStream(file); + inputStream.read(buffer, 0, buffer.length); + + String str = new String(buffer).toString(); + + return str.trim().length() > 0 ? str.trim() : ""; + } catch (IOException e) { + return ""; + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + + public static String getSn1() { + try { + Method systemProperties_get = Class.forName("android.os.SystemProperties").getMethod("get", String.class); + // String []propertys = {"ro.boot.serialno", "ro.serialno"}; + String rtn = (String) systemProperties_get.invoke(null, "ro.boot.serialno"); + if (rtn == null || rtn.trim().length() < 1) + rtn = (String) systemProperties_get.invoke(null, "ro.serialno"); + return rtn == null ? "" : rtn; + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + + } + + /* + * 检查存储卡是否插入 + * + * @return + */ + public static boolean isHasSdcard() { + String status = Environment.getExternalStorageState(); + if (status.equals(Environment.MEDIA_MOUNTED)) { + return true; + } else { + return false; + } + } + + /* + * 拍照图片文件名 + */ + private static String getPhotoFileName() { + Date date = new Date(System.currentTimeMillis()); + SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG'_yyyyMMdd_HHmmss"); + return dateFormat.format(date) + ".jpg"; + } + + public static byte[] bitmapToByte(Bitmap bitmap) { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + bitmap.compress(CompressFormat.JPEG, 60, output); + byte[] result = output.toByteArray(); + try { + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/app/src/main/java/com/util/UnitConversionUtil.java b/app/src/main/java/com/util/UnitConversionUtil.java new file mode 100644 index 0000000..d9e48e8 --- /dev/null +++ b/app/src/main/java/com/util/UnitConversionUtil.java @@ -0,0 +1,19 @@ +package com.util; + +import com.sys.SysData; + +import android.content.Context; + +public class UnitConversionUtil { + //转换dip为px + public static int convertDIP2PX(Double dip) { + return (int)(dip*SysData.scale + 0.5f*(dip>=0?1:-1)); + } + + //转换px为dip + public static int convertPX2DIP(int px) { + return (int)(px/SysData.scale + 0.5f*(px>=0?1:-1)); + } + + +} diff --git a/app/src/main/java/com/util/WakeLockUtil.java b/app/src/main/java/com/util/WakeLockUtil.java new file mode 100644 index 0000000..be9a266 --- /dev/null +++ b/app/src/main/java/com/util/WakeLockUtil.java @@ -0,0 +1,51 @@ +package com.util; + +import android.app.Activity; +import android.content.Context; +import android.net.wifi.WifiManager; +import android.net.wifi.WifiManager.WifiLock; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; + +public class WakeLockUtil { + private static WifiLock wifiLock; + + public static void acquireWakeLock(Activity activity, WakeLock wakeLock) { + if (wakeLock == null) { + PowerManager pm = (PowerManager) activity + .getSystemService(Context.POWER_SERVICE); + wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK + | PowerManager.ACQUIRE_CAUSES_WAKEUP, "crtech"); + } + if (wifiLock == null) { + WifiManager manager = (WifiManager) activity + .getSystemService(Context.WIFI_SERVICE); + wifiLock = manager.createWifiLock("SwiFTP"); + wifiLock.setReferenceCounted(false); + } + if (wakeLock != null) { + System.out.println(wakeLock+"------------------锁定"); + wakeLock.acquire(); + System.out.println(wakeLock+"----------==--------锁定"); + } + if (wifiLock != null) { + System.out.println("------------------wifi锁定"); + wifiLock.acquire(); + } + } + + // 释放设备电源锁 + public static void releaseWakeLock(WakeLock wakeLock) { + System.out.println("------------------解除锁定====================="); + if (wakeLock != null) { + wakeLock.release(); + System.out.println("------------------解除锁定"); + wakeLock = null; + } + if (wifiLock != null) { + wifiLock.release(); + wifiLock = null; + } + } + +} diff --git a/app/src/main/java/com/zebra/adc/decoder/compatible/BarCodeReader.java b/app/src/main/java/com/zebra/adc/decoder/compatible/BarCodeReader.java new file mode 100644 index 0000000..4bb6125 --- /dev/null +++ b/app/src/main/java/com/zebra/adc/decoder/compatible/BarCodeReader.java @@ -0,0 +1,3443 @@ +/* */ package com.zebra.adc.decoder.compatible; +/* */ +/* */ import android.content.Context; +/* */ import android.os.Handler; +/* */ import android.os.Looper; +/* */ import android.os.Message; +/* */ import android.util.Log; +/* */ import android.view.Surface; +/* */ import android.view.SurfaceHolder; +/* */ import java.io.IOException; +/* */ import java.lang.ref.WeakReference; +/* */ import java.util.ArrayList; +/* */ import java.util.HashMap; +/* */ import java.util.List; +/* */ import java.util.StringTokenizer; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class BarCodeReader +/* */ { +/* */ private static final String TAG = "BarCodeReader"; +/* */ private static final int BCRDR_MSG_ERROR = 1; +/* */ private static final int BCRDR_MSG_SHUTTER = 2; +/* */ private static final int BCRDR_MSG_FOCUS = 4; +/* */ private static final int BCRDR_MSG_ZOOM = 8; +/* */ private static final int BCRDR_MSG_PREVIEW_FRAME = 16; +/* */ private static final int BCRDR_MSG_VIDEO_FRAME = 32; +/* */ private static final int BCRDR_MSG_POSTVIEW_FRAME = 64; +/* */ private static final int BCRDR_MSG_RAW_IMAGE = 128; +/* */ private static final int BCRDR_MSG_COMPRESSED_IMAGE = 256; +/* */ private static final int BCRDR_MSG_LAST_DEC_IMAGE = 512; +/* */ private static final int BCRDR_MSG_DEC_COUNT = 1024; +/* */ private static final int BCRDR_MSG_DECODE_COMPLETE = 65536; +/* */ private static final int BCRDR_MSG_DECODE_TIMEOUT = 131072; +/* */ private static final int BCRDR_MSG_DECODE_CANCELED = 262144; +/* */ private static final int BCRDR_MSG_DECODE_ERROR = 524288; +/* */ private static final int BCRDR_MSG_DECODE_EVENT = 1048576; +/* */ private static final int BCRDR_MSG_FRAME_ERROR = 2097152; +/* */ private static final int BCRDR_MSG_ALL_MSGS = 4129791; +/* */ private static final int DECODE_MODE_PREVIEW = 1; +/* */ private static final int DECODE_MODE_VIEWFINDER = 2; +/* */ private static final int DECODE_MODE_VIDEO = 3; +/* */ private int mNativeContext; +/* */ private EventHandler mEventHandler; +/* */ private AutoFocusCallback mAutoFocusCallback; +/* */ private DecodeCallback mDecodeCallback; +/* */ private ErrorCallback mErrorCallback; +/* */ private VideoCallback mVideoCallback; +/* */ private PictureCallback mSnapshotCallback; +/* */ private PreviewCallback mPreviewCallback; +/* */ private OnZoomChangeListener mZoomListener; +/* */ private boolean mOneShot; +/* */ private boolean mWithBuffer; +/* */ public static final int BCR_SUCCESS = 0; +/* */ public static final int BCR_ERROR = -1; +/* */ public static final int DECODE_STATUS_TIMEOUT = 0; +/* */ public static final int DECODE_STATUS_CANCELED = -1; +/* */ public static final int DECODE_STATUS_ERROR = -2; +/* */ public static final int DECODE_STATUS_MULTI_DEC_COUNT = -3; +/* */ public static final int BCRDR_EVENT_SCAN_MODE_CHANGED = 5; +/* */ public static final int BCRDR_EVENT_MOTION_DETECTED = 6; +/* */ public static final int BCRDR_EVENT_SCANNER_RESET = 7; +/* */ public static final int BCRDR_ERROR_UNKNOWN = 1; +/* */ public static final int BCRDR_ERROR_SERVER_DIED = 100; +/* */ String LOG_TAG; +/* */ public Boolean scanFinished; +/* */ +/* */ public final int setParameter(int paramNum, int paramVal) { +/* 218 */ return setNumParameter(paramNum, paramVal); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final int setParameter(int paramNum, String paramVal) { +/* 232 */ return setStrParameter(paramNum, paramVal); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final void startVideoCapture(VideoCallback cb) { +/* 287 */ this.mVideoCallback = cb; +/* 288 */ native_startPreview(3); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final void startViewFinder() { +/* 298 */ native_startPreview(2); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final void startPreview() { +/* 319 */ native_startPreview(1); +/* */ } +/* */ +/* */ +/* */ +/* */ public static class ReaderInfo +/* */ { +/* */ public static final int BCRDR_FACING_BACK = 0; +/* */ +/* */ +/* */ public static final int BCRDR_FACING_FRONT = 1; +/* */ +/* */ +/* */ public int facing; +/* */ +/* */ +/* */ public int orientation; +/* */ } +/* */ +/* */ +/* */ +/* */ public static class ParamNum +/* */ { +/* */ public static final short CODE39 = 0; +/* */ +/* */ +/* */ public static final short UPCA = 1; +/* */ +/* */ +/* */ public static final short UPCE = 2; +/* */ +/* */ +/* */ public static final short EAN13 = 3; +/* */ +/* */ +/* */ public static final short EAN8 = 4; +/* */ +/* */ +/* */ public static final short D25 = 5; +/* */ +/* */ +/* */ public static final short I25 = 6; +/* */ +/* */ +/* */ public static final short CODABAR = 7; +/* */ +/* */ +/* */ public static final short CODE128 = 8; +/* */ +/* */ +/* */ public static final short CODE93 = 9; +/* */ +/* */ +/* */ public static final short CODE11 = 10; +/* */ +/* */ +/* */ public static final short MSI = 11; +/* */ +/* */ +/* */ public static final short UPCE1 = 12; +/* */ +/* */ +/* */ public static final short TRIOPTIC = 13; +/* */ +/* */ +/* */ public static final short EAN128 = 14; +/* */ +/* */ +/* */ public static final short PDF = 15; +/* */ +/* */ +/* */ public static final short SUPPS = 16; +/* */ +/* */ +/* */ public static final short C39_FULL_ASCII = 17; +/* */ +/* */ +/* */ public static final short C39_LEN1 = 18; +/* */ +/* */ +/* */ public static final short C39_LEN2 = 19; +/* */ +/* */ +/* */ public static final short D25_LEN1 = 20; +/* */ +/* */ +/* */ public static final short D25_LEN2 = 21; +/* */ +/* */ +/* */ public static final short I25_LEN1 = 22; +/* */ +/* */ +/* */ public static final short I25_LEN2 = 23; +/* */ +/* */ +/* */ public static final short CBR_LEN1 = 24; +/* */ +/* */ +/* */ public static final short CBR_LEN2 = 25; +/* */ +/* */ +/* */ public static final short C93_LEN1 = 26; +/* */ +/* */ +/* */ public static final short C93_LEN2 = 27; +/* */ +/* */ +/* */ public static final short C11_LEN1 = 28; +/* */ +/* */ +/* */ public static final short C11_LEN2 = 29; +/* */ +/* */ +/* */ public static final short MSI_LEN1 = 30; +/* */ +/* */ +/* */ public static final short MSI_LEN2 = 31; +/* */ +/* */ +/* */ public static final short UPCA_PREAM = 34; +/* */ +/* */ +/* */ public static final short UPCE_PREAM = 35; +/* */ +/* */ +/* */ public static final short UPCE1_PREAM = 36; +/* */ +/* */ +/* */ public static final short UPCE_TO_A = 37; +/* */ +/* */ +/* */ public static final short UPCE1_TO_A = 38; +/* */ +/* */ +/* */ public static final short EAN8_TO_13 = 39; +/* */ +/* */ +/* */ public static final short UPCA_CHK = 40; +/* */ +/* */ +/* */ public static final short UPCE_CHK = 41; +/* */ +/* */ +/* */ public static final short UPCE1_CHK = 42; +/* */ +/* */ +/* */ public static final short XMIT_C39_CHK = 43; +/* */ +/* */ +/* */ public static final short XMIT_I25_CHK = 44; +/* */ +/* */ +/* */ public static final short XMIT_CODE_ID = 45; +/* */ +/* */ +/* */ public static final short XMIT_MSI_CHK = 46; +/* */ +/* */ +/* */ public static final short XMIT_C11_CHK = 47; +/* */ +/* */ +/* */ public static final short C39_CHK_EN = 48; +/* */ +/* */ +/* */ public static final short I25_CHK_TYPE = 49; +/* */ +/* */ +/* */ public static final short MSI_CHK_1_2 = 50; +/* */ +/* */ +/* */ public static final short MSI_CHK_SCHEME = 51; +/* */ +/* */ +/* */ public static final short C11_CHK_TYPE = 52; +/* */ +/* */ +/* */ public static final short CLSI = 54; +/* */ +/* */ +/* */ public static final short NOTIS = 55; +/* */ +/* */ +/* */ public static final short UPC_SEC_LEV = 77; +/* */ +/* */ +/* */ public static final short LIN_SEC_LEV = 78; +/* */ +/* */ +/* */ public static final short SUPP_REDUN = 80; +/* */ +/* */ +/* */ public static final short I25_TO_EAN13 = 82; +/* */ +/* */ +/* */ public static final short BOOKLAND = 83; +/* */ +/* */ +/* */ public static final short ISBT_128 = 84; +/* */ +/* */ +/* */ public static final short COUPON = 85; +/* */ +/* */ +/* */ public static final short CODE32 = 86; +/* */ +/* */ +/* */ public static final short POST_US1 = 89; +/* */ +/* */ +/* */ public static final short POST_US2 = 90; +/* */ +/* */ +/* */ public static final short POST_UK = 91; +/* */ +/* */ +/* */ public static final short SIGNATURE = 93; +/* */ +/* */ +/* */ public static final short XMIT_NO_READ = 94; +/* */ +/* */ +/* */ public static final short POST_US_PARITY = 95; +/* */ +/* */ +/* */ public static final short POST_UK_PARITY = 96; +/* */ +/* */ +/* */ public static final short EMUL_EAN128 = 123; +/* */ +/* */ +/* */ public static final short LASER_ON_PRIM = 136; +/* */ +/* */ +/* */ public static final short LASER_OFF_PRIM = 137; +/* */ +/* */ +/* */ public static final short PRIM_TRIG_MODE = 138; +/* */ +/* */ +/* */ public static final short C128_LEN1 = 209; +/* */ +/* */ +/* */ public static final short C128_LEN2 = 210; +/* */ +/* */ +/* */ public static final short ISBT_MAX_TRY = 223; +/* */ +/* */ +/* */ public static final short UPDF = 227; +/* */ +/* */ +/* */ public static final short C32_PREFIX = 231; +/* */ +/* */ +/* */ public static final short POSTAL_JAP = 290; +/* */ +/* */ +/* */ public static final short POSTAL_AUS = 291; +/* */ +/* */ +/* */ public static final short DATAMATRIX = 292; +/* */ +/* */ +/* */ public static final short QRCODE = 293; +/* */ +/* */ +/* */ public static final short MAXICODE = 294; +/* */ +/* */ +/* */ public static final short IMG_ILLUM = 298; +/* */ +/* */ +/* */ public static final short IMG_AIM_SNAPSHOT = 300; +/* */ +/* */ +/* */ public static final short IMG_CROP = 301; +/* */ +/* */ +/* */ public static final short IMG_SUBSAMPLE = 302; +/* */ +/* */ +/* */ public static final short IMG_BPP = 303; +/* */ +/* */ +/* */ public static final short IMG_FILE_FORMAT = 304; +/* */ +/* */ +/* */ public static final short IMG_JPEG_QUAL = 305; +/* */ +/* */ +/* */ public static final short IMG_AIM_MODE = 306; +/* */ +/* */ +/* */ public static final short IMG_SIG_FMT = 313; +/* */ +/* */ +/* */ public static final short IMG_SIG_BPP = 314; +/* */ +/* */ +/* */ public static final short IMG_CROP_TOP = 315; +/* */ +/* */ +/* */ public static final short IMG_CROP_LEFT = 316; +/* */ +/* */ +/* */ public static final short IMG_CROP_BOT = 317; +/* */ +/* */ +/* */ public static final short IMG_CROP_RIGHT = 318; +/* */ +/* */ +/* */ public static final short IMG_SNAPTIMEOUT = 323; +/* */ +/* */ +/* */ public static final short IMG_VIDEOVF = 324; +/* */ +/* */ +/* */ public static final short POSTAL_DUTCH = 326; +/* */ +/* */ +/* */ public static final short RSS_14 = 338; +/* */ +/* */ +/* */ public static final short RSS_LIM = 339; +/* */ +/* */ +/* */ public static final short RSS_EXP = 340; +/* */ +/* */ +/* */ public static final short CCC_ENABLE = 341; +/* */ +/* */ +/* */ public static final short CCAB_ENABLE = 342; +/* */ +/* */ +/* */ public static final short UPC_COMPOSITE = 344; +/* */ +/* */ +/* */ public static final short IMG_IMAGE_ILLUM = 361; +/* */ +/* */ +/* */ public static final short SIGCAP_WIDTH = 366; +/* */ +/* */ +/* */ public static final short SIGCAP_HEIGHT = 367; +/* */ +/* */ +/* */ public static final short TCIF = 371; +/* */ +/* */ +/* */ public static final short MARGIN_RATIO = 381; +/* */ +/* */ +/* */ public static final short DEMOTE_RSS = 397; +/* */ +/* */ +/* */ public static final short PICKLIST_MODE = 402; +/* */ +/* */ +/* */ public static final short C25 = 408; +/* */ +/* */ +/* */ public static final short IMAGE_SIG_JPEG_QUALITY = 421; +/* */ +/* */ +/* */ public static final short EMUL_UCCEAN128 = 427; +/* */ +/* */ +/* */ public static final short MIRROR_IMAGE = 537; +/* */ +/* */ +/* */ public static final short IMG_ENHANCEMENT = 564; +/* */ +/* */ +/* */ public static final short UQR_EN = 573; +/* */ +/* */ +/* */ public static final short AZTEC = 574; +/* */ +/* */ +/* */ public static final short BOOKLAND_FORMAT = 576; +/* */ +/* */ +/* */ public static final short ISBT_CONCAT_MODE = 577; +/* */ +/* */ +/* */ public static final short CHECK_ISBT_TABLE = 578; +/* */ +/* */ +/* */ public static final short SUPP_USER_1 = 579; +/* */ +/* */ +/* */ public static final short SUPP_USER_2 = 580; +/* */ +/* */ +/* */ public static final short K35 = 581; +/* */ +/* */ +/* */ public static final short ONE_D_INVERSE = 586; +/* */ +/* */ +/* */ public static final short QR_INVERSE = 587; +/* */ +/* */ +/* */ public static final short DATAMATRIX_INVERSE = 588; +/* */ +/* */ +/* */ public static final short AZTEC_INVERSE = 589; +/* */ +/* */ +/* */ public static final short AIMMODEHANDSFREE = 590; +/* */ +/* */ +/* */ public static final short POST_US3 = 592; +/* */ +/* */ +/* */ public static final short POST_US4 = 611; +/* */ +/* */ +/* */ public static final short ISSN_EAN_EN = 617; +/* */ +/* */ +/* */ public static final short MATRIX_25_EN = 618; +/* */ +/* */ +/* */ public static final short MATRIX_25_LEN1 = 619; +/* */ +/* */ +/* */ public static final short MATRIX_25_LEN2 = 620; +/* */ +/* */ +/* */ public static final short MATRIX_25_REDUN = 621; +/* */ +/* */ +/* */ public static final short MATRIX_25_CHK_EN = 622; +/* */ +/* */ +/* */ public static final short MATRIX_25_XMIT_CHK = 623; +/* */ +/* */ +/* */ public static final short AIMID_SUPP_FORMAT = 672; +/* */ +/* */ +/* */ public static final short CELL_DISPLAY_MODE = 716; +/* */ +/* */ +/* */ public static final short POST_AUS_FMT = 718; +/* */ +/* */ +/* */ public static final short DATABAR_LIM_SEC_LEV = 728; +/* */ +/* */ +/* */ public static final short COUPON_REPORT = 730; +/* */ +/* */ +/* */ public static final short VIDEO_SUBSMAPLE = 761; +/* */ +/* */ +/* */ public static final short IMG_MOTIONILLUM = 762; +/* */ +/* */ +/* */ public static final short ILLUMINATION_POWER_LEVEL = 764; +/* */ +/* */ +/* */ public static final short MULTI_DECODE = 900; +/* */ +/* */ +/* */ public static final short FULL_READ_MODE = 901; +/* */ +/* */ public static final short NUM_BR_TO_READ = 902; +/* */ +/* */ public static final short RETRIEVE_LAST_DECODE = 905; +/* */ +/* */ public static final short SECURITY_LEVEL = 1121; +/* */ +/* */ public static final short ENABLE_HANXIN = 1167; +/* */ +/* */ public static final short HANXIN_INVERSE = 1168; +/* */ } +/* */ +/* */ +/* */ public static class ParamVal +/* */ { +/* */ public static final byte SUPP_NONE = 0; +/* */ +/* */ public static final byte SUPP_ONLY = 1; +/* */ +/* */ public static final byte SUPP_AUTOD = 2; +/* */ +/* */ public static final byte SUPP_SMART = 3; +/* */ +/* */ public static final byte SUPP_378_379 = 4; +/* */ +/* */ public static final byte SUPP_978_979 = 5; +/* */ +/* */ public static final byte SUPP_414_419_434_439 = 6; +/* */ +/* */ public static final byte SUPP_977 = 7; +/* */ +/* */ public static final byte SUPP_491 = 8; +/* */ +/* */ public static final byte SUPP_PROG_1 = 9; +/* */ +/* */ public static final byte SUPP_PROG_1_AND_2 = 10; +/* */ +/* */ public static final byte SUPP_SMART_PLUS_1 = 11; +/* */ +/* */ public static final byte SUPP_SMART_PLUS_1_2 = 12; +/* */ +/* */ public static final byte LEVEL = 0; +/* */ +/* */ public static final byte HANDSFREE = 7; +/* */ +/* */ public static final byte AUTO_AIM = 9; +/* */ +/* */ public static final byte IMG_BPP_1 = 0; +/* */ +/* */ public static final byte IMG_BPP_4 = 1; +/* */ +/* */ public static final byte IMG_BPP_8 = 2; +/* */ +/* */ public static final byte IMG_FORMAT_JPEG = 1; +/* */ +/* */ public static final byte IMG_FORMAT_BMP = 3; +/* */ +/* */ public static final byte IMG_FORMAT_TIFF = 4; +/* */ +/* */ public static final byte IMG_SUBSAMPLE_FACTOR_1 = 0; +/* */ +/* */ public static final byte IMG_SUBSAMPLE_FACTOR_2 = 1; +/* */ +/* */ public static final byte IMG_SUBSAMPLE_FACTOR_3 = 2; +/* */ +/* */ public static final byte IMG_SUBSAMPLE_FACTOR_4 = 3; +/* */ +/* */ public static final byte AIM_OFF = 0; +/* */ +/* */ public static final byte AIM_ON = 1; +/* */ +/* */ public static final byte AIM_ON_ALWAYS = 2; +/* */ +/* */ public static final byte UPC_NEVER = 0; +/* */ +/* */ public static final byte UPC_ALWAYS = 1; +/* */ +/* */ public static final byte UPC_AUTOD = 2; +/* */ +/* */ public static final byte PICKLIST_NEVER = 0; +/* */ +/* */ public static final byte PICKLIST_OUT_OF_SCANSTAND = 1; +/* */ +/* */ public static final byte PICKLIST_ALWAYS = 1; +/* */ +/* */ public static final byte MIRROR_NEVER = 0; +/* */ +/* */ public static final byte MIRROR_ALWAYS = 1; +/* */ +/* */ public static final byte MIRROR_AUTO = 2; +/* */ +/* */ public static final byte IMG_ENHANCE_OFF = 0; +/* */ +/* */ public static final byte IMG_ENHANCE_LOW = 1; +/* */ +/* */ public static final byte IMG_ENHANCE_MED = 2; +/* */ +/* */ public static final byte IMG_ENHANCE_HIGH = 3; +/* */ +/* */ public static final byte IMG_ENHANCE_CUSTOM = 4; +/* */ +/* */ public static final byte ISBT_CONCAT_NONE = 0; +/* */ +/* */ public static final byte ISBT_CONCAT_ONLY = 1; +/* */ +/* */ public static final byte ISBT_CONCAT_AUTOD = 2; +/* */ +/* */ public static final byte REGULAR_ONLY = 0; +/* */ +/* */ public static final byte INVERSE_ONLY = 1; +/* */ +/* */ public static final byte INVERSE_AUTOD = 2; +/* */ +/* */ public static final byte PDF_SECURITY_STRICT = 0; +/* */ +/* */ public static final byte PDF_CWLEN_ZERO_OK = 1; +/* */ } +/* */ +/* */ +/* */ public static class PropertyNum +/* */ { +/* */ public static final int MODEL_NUMBER = 1; +/* */ +/* */ public static final int SERIAL_NUM = 2; +/* */ +/* */ public static final int MAX_FRAME_BUFFER_SIZE = 3; +/* */ +/* */ public static final int HORIZONTAL_RES = 4; +/* */ +/* */ public static final int VERTICAL_RES = 5; +/* */ +/* */ public static final int IMGKIT_VER = 6; +/* */ +/* */ public static final int ENGINE_VER = 7; +/* */ +/* */ public static final int BTLD_FW_VER = 11; +/* */ +/* */ public static final int SDL_VER = 99; +/* */ } +/* */ +/* */ +/* */ public static BarCodeReader open(int readerId) { +/* 929 */ return new BarCodeReader(readerId); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static BarCodeReader open() { +/* 945 */ int iNumReaders = getNumberOfReaders(); +/* 946 */ ReaderInfo readerInfo = new ReaderInfo(); +/* 947 */ for (int iIdx = 0; iIdx < iNumReaders; iIdx++) { +/* */ +/* 949 */ getReaderInfo(iIdx, readerInfo); +/* 950 */ if (readerInfo.facing == 1) +/* */ { +/* 952 */ return new BarCodeReader(iIdx); +/* */ } +/* */ } +/* 955 */ return null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static BarCodeReader open(int readerId, Context context) { +/* 988 */ return new BarCodeReader(readerId, context); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static BarCodeReader open(Context context) { +/* 1004 */ int iNumReaders = getNumberOfReaders(); +/* 1005 */ ReaderInfo readerInfo = new ReaderInfo(); +/* */ +/* */ +/* 1008 */ if (iNumReaders == 3) { +/* 1009 */ return new BarCodeReader(2, context); +/* */ } +/* */ +/* 1012 */ for (int iIdx = 0; iIdx < iNumReaders; iIdx++) { +/* */ +/* 1014 */ getReaderInfo(iIdx, readerInfo); +/* 1015 */ if (readerInfo.facing == 1) +/* */ { +/* 1017 */ return new BarCodeReader(iIdx, context); +/* */ } +/* */ } +/* 1020 */ return null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ BarCodeReader(int readerId) +/* */ { +/* 1046 */ this.LOG_TAG = "BarCode"; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* 1411 */ this.scanFinished = Boolean.valueOf(true); this.mEventHandler = null; this.mAutoFocusCallback = null; this.mDecodeCallback = null; this.mErrorCallback = null; this.mPreviewCallback = null; this.mSnapshotCallback = null; this.mVideoCallback = null; this.mZoomListener = null; Looper aLooper = Looper.myLooper(); if (aLooper == null) aLooper = Looper.getMainLooper(); if (aLooper != null) this.mEventHandler = new EventHandler(this, aLooper); native_setup(new WeakReference(this), readerId); } BarCodeReader(int readerId, Context context) { this.LOG_TAG = "BarCode"; this.scanFinished = Boolean.valueOf(true); this.mEventHandler = null; this.mAutoFocusCallback = null; this.mDecodeCallback = null; this.mErrorCallback = null; this.mPreviewCallback = null; this.mSnapshotCallback = null; this.mVideoCallback = null; this.mZoomListener = null; Looper aLooper = Looper.myLooper(); if (aLooper == null) aLooper = Looper.getMainLooper(); if (aLooper != null) this.mEventHandler = new EventHandler(this, aLooper); native_setup(new WeakReference(this), readerId, context); } +/* */ protected void finalize() { native_release(); } +/* */ public final void release() { native_release(); } +/* 1414 */ public final void setPreviewDisplay(SurfaceHolder holder) throws IOException { if (holder != null) { setPreviewDisplay(holder.getSurface()); } else { setPreviewDisplay((Surface)null); } } public final void autoFocus(AutoFocusCallback cb) { this.mAutoFocusCallback = cb; native_autoFocus(); } public boolean isScanFinished() { return this.scanFinished.booleanValue(); } +/* */ public final void cancelAutoFocus() { this.mAutoFocusCallback = null; native_cancelAutoFocus(); } +/* */ public final void setDecodeCallback(DecodeCallback cb) { this.mDecodeCallback = cb; } +/* */ public final void takePicture(PictureCallback cb) { this.mSnapshotCallback = cb; try { native_takePicture(); } catch (Throwable throwable) {} } +/* 1418 */ public final void setOneShotPreviewCallback(PreviewCallback cb) { this.mPreviewCallback = cb; this.mOneShot = true; this.mWithBuffer = false; setHasPreviewCallback((cb != null), false); } public final void setPreviewCallbackWithBuffer(PreviewCallback cb) { this.mPreviewCallback = cb; this.mOneShot = false; this.mWithBuffer = true; setHasPreviewCallback((cb != null), true); } public void setScanFinished(boolean finished) { this.scanFinished = Boolean.valueOf(finished); } +/* */ +/* */ +/* */ private class EventHandler +/* */ extends Handler +/* */ { +/* */ private BarCodeReader mReader; +/* */ +/* */ public EventHandler(BarCodeReader rdr, Looper looper) { +/* 1427 */ super(looper); +/* 1428 */ this.mReader = rdr; +/* */ } +/* */ +/* */ +/* */ +/* */ public void handleMessage(Message msg) { +/* 1434 */ Log.i("BarCodeReader", String.format("Event message: %X, arg1=%d, arg2=%d", new Object[] { Integer.valueOf(msg.what), Integer.valueOf(msg.arg1), Integer.valueOf(msg.arg2) })); +/* 1435 */ switch (msg.what) { +/* */ +/* */ case 65536: +/* 1438 */ if (BarCodeReader.this.mDecodeCallback != null) +/* */ { +/* 1440 */ BarCodeReader.this.mDecodeCallback.onDecodeComplete(msg.arg1, msg.arg2, (byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 131072: +/* 1445 */ if (BarCodeReader.this.mDecodeCallback != null) +/* */ { +/* 1447 */ BarCodeReader.this.mDecodeCallback.onDecodeComplete(0, 0, (byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 262144: +/* 1452 */ if (BarCodeReader.this.mDecodeCallback != null) +/* */ { +/* 1454 */ BarCodeReader.this.mDecodeCallback.onDecodeComplete(0, -1, (byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ +/* */ case 524288: +/* */ case 2097152: +/* 1461 */ if (BarCodeReader.this.mDecodeCallback != null) +/* */ { +/* 1463 */ BarCodeReader.this.mDecodeCallback.onDecodeComplete(0, -2, (byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 1048576: +/* 1468 */ if (BarCodeReader.this.mDecodeCallback != null) +/* */ { +/* 1470 */ BarCodeReader.this.mDecodeCallback.onEvent(msg.arg1, msg.arg2, (byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ +/* */ case 2: +/* */ return; +/* */ +/* */ case 256: +/* 1479 */ if (BarCodeReader.this.mSnapshotCallback != null) { +/* */ +/* */ +/* */ +/* */ +/* 1484 */ int iCX = msg.arg1 >> 0 & 0xFFFF; +/* 1485 */ int iCY = msg.arg1 >> 16 & 0xFFFF; +/* 1486 */ BarCodeReader.this.mSnapshotCallback.onPictureTaken(msg.arg2, iCX, iCY, (byte[])msg.obj, this.mReader); +/* */ } +/* */ else { +/* */ +/* 1490 */ Log.e("BarCodeReader", "BCRDR_MSG_COMPRESSED_IMAGE event with no snapshot callback"); +/* */ } +/* */ return; +/* */ +/* */ case 32: +/* 1495 */ if (BarCodeReader.this.mVideoCallback != null) { +/* */ +/* */ +/* */ +/* */ +/* 1500 */ int iCX = msg.arg1 >> 0 & 0xFFFF; +/* 1501 */ int iCY = msg.arg1 >> 16 & 0xFFFF; +/* 1502 */ BarCodeReader.this.mVideoCallback.onVideoFrame(msg.arg2, iCX, iCY, (byte[])msg.obj, this.mReader); +/* */ } +/* */ else { +/* */ +/* 1506 */ Log.e("BarCodeReader", "BCRDR_MSG_VIDEO_FRAME event with no video callback"); +/* */ } +/* */ return; +/* */ +/* */ case 16: +/* 1511 */ if (BarCodeReader.this.mPreviewCallback != null) { +/* */ +/* 1513 */ PreviewCallback cb = BarCodeReader.this.mPreviewCallback; +/* 1514 */ if (BarCodeReader.this.mOneShot) { +/* */ +/* */ +/* */ +/* */ +/* 1519 */ BarCodeReader.this.mPreviewCallback = null; +/* */ } +/* 1521 */ else if (!BarCodeReader.this.mWithBuffer) { +/* */ +/* */ +/* */ +/* */ +/* 1526 */ BarCodeReader.this.setHasPreviewCallback(true, false); +/* */ } +/* 1528 */ cb.onPreviewFrame((byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 4: +/* 1533 */ if (BarCodeReader.this.mAutoFocusCallback != null) +/* */ { +/* 1535 */ BarCodeReader.this.mAutoFocusCallback.onAutoFocus(!(msg.arg1 == 0), this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 8: +/* 1540 */ if (BarCodeReader.this.mZoomListener != null) +/* */ { +/* 1542 */ BarCodeReader.this.mZoomListener.onZoomChange(msg.arg1, (msg.arg2 != 0), this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 1: +/* 1547 */ Log.e("BarCodeReader", "Error " + msg.arg1); +/* 1548 */ if (BarCodeReader.this.mErrorCallback != null) +/* */ { +/* 1550 */ BarCodeReader.this.mErrorCallback.onError(msg.arg1, this.mReader); +/* */ } +/* */ return; +/* */ +/* */ case 1024: +/* 1555 */ if (BarCodeReader.this.mDecodeCallback != null) +/* */ { +/* 1557 */ BarCodeReader.this.mDecodeCallback.onDecodeComplete(msg.arg1, -3, (byte[])msg.obj, this.mReader); +/* */ } +/* */ return; +/* */ } +/* */ +/* 1562 */ Log.e("BarCodeReader", "Unknown message type " + msg.what); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private static void postEventFromNative(Object reader_ref, int what, int arg1, int arg2, Object obj) { +/* 1571 */ BarCodeReader c = ((WeakReference)reader_ref).get(); +/* 1572 */ if (c != null && c.mEventHandler != null) { +/* */ +/* 1574 */ Message m = c.mEventHandler.obtainMessage(what, arg1, arg2, obj); +/* 1575 */ c.mEventHandler.sendMessage(m); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final void setZoomChangeListener(OnZoomChangeListener listener) { +/* 1608 */ this.mZoomListener = listener; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public final void setErrorCallback(ErrorCallback cb) { +/* 1636 */ this.mErrorCallback = cb; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setParameters(Parameters params) { +/* 1648 */ native_setParameters(params.flatten()); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Parameters getParameters() { +/* 1660 */ Parameters p = new Parameters(); +/* 1661 */ String s = native_getParameters(); +/* 1662 */ p.unflatten(s); +/* 1663 */ return p; +/* */ } private final native void native_autoFocus(); private final native void native_cancelAutoFocus(); private final native String native_getParameters(); private final native void native_release(); private final native int setNumParameter(int paramInt1, int paramInt2); private final native int setStrParameter(int paramInt, String paramString); private final native void native_setParameters(String paramString); private final native void native_setup(Object paramObject, int paramInt); private final native void native_setup(Object paramObject1, int paramInt, Object paramObject2); private final native void native_startPreview(int paramInt); private final native void native_takePicture(); private final native void setHasPreviewCallback(boolean paramBoolean1, boolean paramBoolean2); private final native void setPreviewDisplay(Surface paramSurface); public static native int getNumberOfReaders(); public static native void getReaderInfo(int paramInt, ReaderInfo paramReaderInfo); public final native void lock(); public final native void unlock(); public final native void reconnect() throws IOException; public final native int getNumProperty(int paramInt); public final native String getStrProperty(int paramInt); public final native int getNumParameter(int paramInt); public final native String getStrParameter(int paramInt); public final native void setDefaultParameters(); public final native void addCallbackBuffer(byte[] paramArrayOfbyte); public final native int FWUpdate(String paramString, boolean paramBoolean1, boolean paramBoolean2); +/* */ public final native void stopPreview(); +/* */ public final native void startDecode(); +/* */ public final native int startHandsFreeDecode(int paramInt); +/* */ public final native void stopDecode(); +/* */ public final native boolean previewEnabled(); +/* */ public final native void startSmoothZoom(int paramInt); +/* */ public final native void stopSmoothZoom(); +/* */ public final native void setDisplayOrientation(int paramInt); +/* */ public final native int getDecodeCount(); +/* */ public final native void enableAllCodeTypes(); +/* */ public final native void disableAllCodeTypes(); +/* */ public final native byte[] getLastDecImage(); +/* */ public final native void setAutoFocusDelay(int paramInt1, int paramInt2); +/* */ public class Size { public Size(int w, int h) { +/* 1679 */ this.width = w; +/* 1680 */ this.height = h; +/* */ } +/* */ +/* */ +/* */ +/* */ public int width; +/* */ +/* */ +/* */ public int height; +/* */ +/* */ +/* */ public boolean equals(Object obj) { +/* 1692 */ if (!(obj instanceof Size)) +/* */ { +/* 1694 */ return false; +/* */ } +/* 1696 */ Size s = (Size)obj; +/* 1697 */ return (this.width == s.width && this.height == s.height); +/* */ } +/* */ +/* */ +/* */ public int hashCode() { +/* 1702 */ return this.width * 32713 + this.height; +/* */ } } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class Parameters +/* */ { +/* */ private static final String KEY_PREVIEW_SIZE = "preview-size"; +/* */ +/* */ +/* */ private static final String KEY_PREVIEW_FORMAT = "preview-format"; +/* */ +/* */ +/* */ private static final String KEY_PREVIEW_FRAME_RATE = "preview-frame-rate"; +/* */ +/* */ +/* */ private static final String KEY_PREVIEW_FPS_RANGE = "preview-fps-range"; +/* */ +/* */ +/* */ private static final String KEY_PICTURE_SIZE = "picture-size"; +/* */ +/* */ +/* */ private static final String KEY_PICTURE_FORMAT = "picture-format"; +/* */ +/* */ +/* */ private static final String KEY_JPEG_THUMBNAIL_SIZE = "jpeg-thumbnail-size"; +/* */ +/* */ +/* */ private static final String KEY_JPEG_THUMBNAIL_WIDTH = "jpeg-thumbnail-width"; +/* */ +/* */ +/* */ private static final String KEY_JPEG_THUMBNAIL_HEIGHT = "jpeg-thumbnail-height"; +/* */ +/* */ +/* */ private static final String KEY_JPEG_THUMBNAIL_QUALITY = "jpeg-thumbnail-quality"; +/* */ +/* */ +/* */ private static final String KEY_JPEG_QUALITY = "jpeg-quality"; +/* */ +/* */ +/* */ private static final String KEY_ROTATION = "rotation"; +/* */ +/* */ +/* */ private static final String KEY_GPS_LATITUDE = "gps-latitude"; +/* */ +/* */ +/* */ private static final String KEY_GPS_LONGITUDE = "gps-longitude"; +/* */ +/* */ +/* */ private static final String KEY_GPS_ALTITUDE = "gps-altitude"; +/* */ +/* */ +/* */ private static final String KEY_GPS_TIMESTAMP = "gps-timestamp"; +/* */ +/* */ +/* */ private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; +/* */ +/* */ +/* */ private static final String KEY_WHITE_BALANCE = "whitebalance"; +/* */ +/* */ +/* */ private static final String KEY_EFFECT = "effect"; +/* */ +/* */ +/* */ private static final String KEY_ANTIBANDING = "antibanding"; +/* */ +/* */ +/* */ private static final String KEY_SCENE_MODE = "scene-mode"; +/* */ +/* */ +/* */ private static final String KEY_FLASH_MODE = "flash-mode"; +/* */ +/* */ +/* */ private static final String KEY_FOCUS_MODE = "focus-mode"; +/* */ +/* */ +/* */ private static final String KEY_FOCAL_LENGTH = "focal-length"; +/* */ +/* */ +/* */ private static final String KEY_HORIZONTAL_VIEW_ANGLE = "horizontal-view-angle"; +/* */ +/* */ +/* */ private static final String KEY_VERTICAL_VIEW_ANGLE = "vertical-view-angle"; +/* */ +/* */ +/* */ private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; +/* */ +/* */ +/* */ private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; +/* */ +/* */ +/* */ private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; +/* */ +/* */ +/* */ private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; +/* */ +/* */ +/* */ private static final String KEY_ZOOM = "zoom"; +/* */ +/* */ +/* */ private static final String KEY_MAX_ZOOM = "max-zoom"; +/* */ +/* */ +/* */ private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; +/* */ +/* */ +/* */ private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; +/* */ +/* */ +/* */ private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; +/* */ +/* */ +/* */ private static final String KEY_FOCUS_DISTANCES = "focus-distances"; +/* */ +/* */ +/* */ private static final String SUPPORTED_VALUES_SUFFIX = "-values"; +/* */ +/* */ +/* */ private static final String TRUE = "true"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_AUTO = "auto"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_INCANDESCENT = "incandescent"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_FLUORESCENT = "fluorescent"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_WARM_FLUORESCENT = "warm-fluorescent"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_DAYLIGHT = "daylight"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_CLOUDY_DAYLIGHT = "cloudy-daylight"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_TWILIGHT = "twilight"; +/* */ +/* */ +/* */ public static final String WHITE_BALANCE_SHADE = "shade"; +/* */ +/* */ +/* */ public static final String EFFECT_NONE = "none"; +/* */ +/* */ +/* */ public static final String EFFECT_MONO = "mono"; +/* */ +/* */ +/* */ public static final String EFFECT_NEGATIVE = "negative"; +/* */ +/* */ +/* */ public static final String EFFECT_SOLARIZE = "solarize"; +/* */ +/* */ +/* */ public static final String EFFECT_SEPIA = "sepia"; +/* */ +/* */ +/* */ public static final String EFFECT_POSTERIZE = "posterize"; +/* */ +/* */ +/* */ public static final String EFFECT_WHITEBOARD = "whiteboard"; +/* */ +/* */ +/* */ public static final String EFFECT_BLACKBOARD = "blackboard"; +/* */ +/* */ +/* */ public static final String EFFECT_AQUA = "aqua"; +/* */ +/* */ +/* */ public static final String ANTIBANDING_AUTO = "auto"; +/* */ +/* */ +/* */ public static final String ANTIBANDING_50HZ = "50hz"; +/* */ +/* */ +/* */ public static final String ANTIBANDING_60HZ = "60hz"; +/* */ +/* */ +/* */ public static final String ANTIBANDING_OFF = "off"; +/* */ +/* */ +/* */ public static final String FLASH_MODE_OFF = "off"; +/* */ +/* */ +/* */ public static final String FLASH_MODE_AUTO = "auto"; +/* */ +/* */ +/* */ public static final String FLASH_MODE_ON = "on"; +/* */ +/* */ +/* */ public static final String FLASH_MODE_RED_EYE = "red-eye"; +/* */ +/* */ +/* */ public static final String FLASH_MODE_TORCH = "torch"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_AUTO = "auto"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_ACTION = "action"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_PORTRAIT = "portrait"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_LANDSCAPE = "landscape"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_NIGHT = "night"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_NIGHT_PORTRAIT = "night-portrait"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_THEATRE = "theatre"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_BEACH = "beach"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_SNOW = "snow"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_SUNSET = "sunset"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_STEADYPHOTO = "steadyphoto"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_FIREWORKS = "fireworks"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_SPORTS = "sports"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_PARTY = "party"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_CANDLELIGHT = "candlelight"; +/* */ +/* */ +/* */ public static final String SCENE_MODE_BARCODE = "barcode"; +/* */ +/* */ +/* */ public static final String FOCUS_MODE_AUTO = "auto"; +/* */ +/* */ +/* */ public static final String FOCUS_MODE_INFINITY = "infinity"; +/* */ +/* */ +/* */ public static final String FOCUS_MODE_MACRO = "macro"; +/* */ +/* */ +/* */ public static final String FOCUS_MODE_FIXED = "fixed"; +/* */ +/* */ +/* */ public static final String FOCUS_MODE_EDOF = "edof"; +/* */ +/* */ +/* */ public static final String FOCUS_MODE_CONTINUOUS_VIDEO = "continuous-video"; +/* */ +/* */ +/* */ public static final int FOCUS_DISTANCE_NEAR_INDEX = 0; +/* */ +/* */ +/* */ public static final int FOCUS_DISTANCE_OPTIMAL_INDEX = 1; +/* */ +/* */ +/* */ public static final int FOCUS_DISTANCE_FAR_INDEX = 2; +/* */ +/* */ +/* */ public static final int PREVIEW_FPS_MIN_INDEX = 0; +/* */ +/* */ +/* */ public static final int PREVIEW_FPS_MAX_INDEX = 1; +/* */ +/* */ +/* */ private static final String PIXEL_FORMAT_YUV422SP = "yuv422sp"; +/* */ +/* */ +/* */ private static final String PIXEL_FORMAT_YUV420SP = "yuv420sp"; +/* */ +/* */ +/* */ private static final String PIXEL_FORMAT_YUV422I = "yuv422i-yuyv"; +/* */ +/* */ +/* */ private static final String PIXEL_FORMAT_RGB565 = "rgb565"; +/* */ +/* */ +/* */ private static final String PIXEL_FORMAT_JPEG = "jpeg"; +/* */ +/* */ +/* 1999 */ private HashMap mMap = new HashMap(); +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void dump() { +/* 2009 */ Log.e("BarCodeReader", "dump: size=" + this.mMap.size()); +/* 2010 */ for (String k : this.mMap.keySet()) +/* */ { +/* 2012 */ Log.e("BarCodeReader", "dump: " + k + "=" + (String)this.mMap.get(k)); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String flatten() { +/* 2026 */ StringBuilder flattened = new StringBuilder(); +/* 2027 */ for (String k : this.mMap.keySet()) { +/* */ +/* 2029 */ flattened.append(k); +/* 2030 */ flattened.append("="); +/* 2031 */ flattened.append(this.mMap.get(k)); +/* 2032 */ flattened.append(";"); +/* */ } +/* */ +/* 2035 */ flattened.deleteCharAt(flattened.length() - 1); +/* 2036 */ return flattened.toString(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void unflatten(String flattened) { +/* 2054 */ this.mMap.clear(); +/* */ +/* 2056 */ StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); +/* 2057 */ while (tokenizer.hasMoreElements()) { +/* */ +/* 2059 */ String strKV = tokenizer.nextToken(); +/* 2060 */ int iPos = strKV.indexOf('='); +/* 2061 */ if (iPos == -1) { +/* */ continue; +/* */ } +/* */ +/* 2065 */ this.mMap.put(strKV.substring(0, iPos), strKV.substring(iPos + 1)); +/* */ } +/* */ } +/* */ +/* */ +/* */ public void remove(String key) { +/* 2071 */ this.mMap.remove(key); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void set(String key, String value) { +/* 2082 */ if (key.indexOf('=') != -1 || key.indexOf(';') != -1) { +/* */ +/* 2084 */ Log.e("BarCodeReader", "Key \"" + key + "\" contains invalid character (= or ;)"); +/* */ return; +/* */ } +/* 2087 */ if (value.indexOf('=') != -1 || value.indexOf(';') != -1) { +/* */ +/* 2089 */ Log.e("BarCodeReader", "Value \"" + value + "\" contains invalid character (= or ;)"); +/* */ +/* */ return; +/* */ } +/* 2093 */ this.mMap.put(key, value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void set(String key, int value) { +/* 2104 */ if (key.indexOf('=') != -1 || key.indexOf(';') != -1) { +/* */ +/* 2106 */ Log.e("BarCodeReader", "Key \"" + key + "\" contains invalid character (= or ;)"); +/* */ return; +/* */ } +/* 2109 */ this.mMap.put(key, Integer.toString(value)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String get(String key) { +/* 2120 */ return this.mMap.get(key); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getInt(String key) { +/* 2131 */ return getInt(key, -1); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setPreviewSize(int width, int height) { +/* 2158 */ String v = String.valueOf(Integer.toString(width)) + "x" + Integer.toString(height); +/* 2159 */ set("preview-size", v); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Size getPreviewSize() { +/* 2170 */ String pair = get("preview-size"); +/* 2171 */ return strToSize(pair); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedPreviewSizes() { +/* 2182 */ String str = get("preview-size-values"); +/* 2183 */ return splitSize(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setJpegThumbnailSize(int width, int height) { +/* 2250 */ set("jpeg-thumbnail-width", width); +/* 2251 */ set("jpeg-thumbnail-height", height); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Size getJpegThumbnailSize() { +/* 2262 */ return new Size(getInt("jpeg-thumbnail-width"), getInt("jpeg-thumbnail-height")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedJpegThumbnailSizes() { +/* 2274 */ String str = get("jpeg-thumbnail-size-values"); +/* 2275 */ return splitSize(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setJpegThumbnailQuality(int quality) { +/* 2286 */ set("jpeg-thumbnail-quality", quality); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getJpegThumbnailQuality() { +/* 2296 */ return getInt("jpeg-thumbnail-quality"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setJpegQuality(int quality) { +/* 2307 */ set("jpeg-quality", quality); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getJpegQuality() { +/* 2317 */ return getInt("jpeg-quality"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ @Deprecated +/* */ public void setPreviewFrameRate(int fps) { +/* 2330 */ set("preview-frame-rate", fps); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ @Deprecated +/* */ public int getPreviewFrameRate() { +/* 2344 */ return getInt("preview-frame-rate"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ @Deprecated +/* */ public List getSupportedPreviewFrameRates() { +/* 2357 */ String str = get("preview-frame-rate-values"); +/* 2358 */ return splitInt(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setPreviewFpsRange(int min, int max) { +/* 2375 */ set("preview-fps-range", min + "," + max); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void getPreviewFpsRange(int[] range) { +/* 2389 */ if (range == null || range.length != 2) +/* */ { +/* 2391 */ throw new IllegalArgumentException("range must be an array with two elements."); +/* */ } +/* 2393 */ splitInt(get("preview-fps-range"), range); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedPreviewFpsRange() { +/* 2415 */ String str = get("preview-fps-range-values"); +/* 2416 */ return (List)splitRange(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setPreviewFormat(int pixel_format) { +/* 2434 */ String s = readerFormatForPixelFormat(pixel_format); +/* 2435 */ if (s == null) +/* */ { +/* 2437 */ throw new IllegalArgumentException("Invalid pixel_format=" + pixel_format); +/* */ } +/* */ +/* 2440 */ set("preview-format", s); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getPreviewFormat() { +/* 2452 */ return pixelFormatForReaderFormat(get("preview-format")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedPreviewFormats() { +/* 2464 */ String str = get("preview-format-values"); +/* 2465 */ ArrayList formats = new ArrayList(); +/* 2466 */ for (String s : split(str)) { +/* */ +/* 2468 */ int f = pixelFormatForReaderFormat(s); +/* 2469 */ if (f == 0) +/* */ continue; +/* 2471 */ formats.add(Integer.valueOf(f)); +/* */ } +/* 2473 */ return formats; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setPictureSize(int width, int height) { +/* 2489 */ String v = String.valueOf(Integer.toString(width)) + "x" + Integer.toString(height); +/* 2490 */ set("picture-size", v); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public Size getPictureSize() { +/* 2501 */ String pair = get("picture-size"); +/* 2502 */ return strToSize(pair); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedPictureSizes() { +/* 2513 */ String str = get("picture-size-values"); +/* 2514 */ return splitSize(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setPictureFormat(int pixel_format) { +/* 2528 */ String s = readerFormatForPixelFormat(pixel_format); +/* 2529 */ if (s == null) +/* */ { +/* 2531 */ throw new IllegalArgumentException("Invalid pixel_format=" + pixel_format); +/* */ } +/* */ +/* 2534 */ set("picture-format", s); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getPictureFormat() { +/* 2545 */ return pixelFormatForReaderFormat(get("picture-format")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedPictureFormats() { +/* 2557 */ String str = get("picture-format-values"); +/* 2558 */ ArrayList formats = new ArrayList(); +/* 2559 */ for (String s : split(str)) { +/* */ +/* 2561 */ int f = pixelFormatForReaderFormat(s); +/* 2562 */ if (f == 0) +/* */ continue; +/* 2564 */ formats.add(Integer.valueOf(f)); +/* */ } +/* 2566 */ return formats; +/* */ } +/* */ +/* */ +/* */ private String readerFormatForPixelFormat(int pixel_format) { +/* 2571 */ switch (pixel_format) { +/* */ +/* */ case 16: +/* 2574 */ return "yuv422sp"; +/* */ case 17: +/* 2576 */ return "yuv420sp"; +/* */ case 20: +/* 2578 */ return "yuv422i-yuyv"; +/* */ case 4: +/* 2580 */ return "rgb565"; +/* */ case 256: +/* 2582 */ return "jpeg"; +/* */ } +/* */ +/* */ +/* 2586 */ return null; +/* */ } +/* */ +/* */ +/* */ private int pixelFormatForReaderFormat(String format) { +/* 2591 */ if (format == null) { +/* 2592 */ return 0; +/* */ } +/* 2594 */ if (format.equals("yuv422sp")) { +/* 2595 */ return 16; +/* */ } +/* 2597 */ if (format.equals("yuv420sp")) { +/* 2598 */ return 17; +/* */ } +/* 2600 */ if (format.equals("yuv422i-yuyv")) { +/* 2601 */ return 20; +/* */ } +/* 2603 */ if (format.equals("rgb565")) { +/* 2604 */ return 4; +/* */ } +/* 2606 */ if (format.equals("jpeg")) { +/* 2607 */ return 256; +/* */ } +/* 2609 */ return 0; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setRotation(int rotation) { +/* 2676 */ if (rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270) { +/* */ +/* 2678 */ set("rotation", Integer.toString(rotation)); +/* */ } +/* */ else { +/* */ +/* 2682 */ throw new IllegalArgumentException("Invalid rotation=" + rotation); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setGpsLatitude(double latitude) { +/* 2694 */ set("gps-latitude", Double.toString(latitude)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setGpsLongitude(double longitude) { +/* 2705 */ set("gps-longitude", Double.toString(longitude)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setGpsAltitude(double altitude) { +/* 2715 */ set("gps-altitude", Double.toString(altitude)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setGpsTimestamp(long timestamp) { +/* 2726 */ set("gps-timestamp", Long.toString(timestamp)); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setGpsProcessingMethod(String processing_method) { +/* 2737 */ set("gps-processing-method", processing_method); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void removeGpsData() { +/* 2746 */ remove("gps-latitude"); +/* 2747 */ remove("gps-longitude"); +/* 2748 */ remove("gps-altitude"); +/* 2749 */ remove("gps-timestamp"); +/* 2750 */ remove("gps-processing-method"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getWhiteBalance() { +/* 2770 */ return get("whitebalance"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setWhiteBalance(String value) { +/* 2781 */ set("whitebalance", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedWhiteBalance() { +/* 2793 */ String str = get("whitebalance-values"); +/* 2794 */ return split(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getColorEffect() { +/* 2814 */ return get("effect"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setColorEffect(String value) { +/* 2825 */ set("effect", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedColorEffects() { +/* 2837 */ String str = get("effect-values"); +/* 2838 */ return split(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getAntibanding() { +/* 2854 */ return get("antibanding"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setAntibanding(String antibanding) { +/* 2865 */ set("antibanding", antibanding); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedAntibanding() { +/* 2877 */ String str = get("antibanding-values"); +/* 2878 */ return split(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getSceneMode() { +/* 2904 */ return get("scene-mode"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setSceneMode(String value) { +/* 2921 */ set("scene-mode", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedSceneModes() { +/* 2933 */ String str = get("scene-mode-values"); +/* 2934 */ return split(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getFlashMode() { +/* 2950 */ return get("flash-mode"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setFlashMode(String value) { +/* 2961 */ set("flash-mode", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedFlashModes() { +/* 2973 */ String str = get("flash-mode-values"); +/* 2974 */ return split(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public String getFocusMode() { +/* 2993 */ return get("focus-mode"); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setFocusMode(String value) { +/* 3004 */ set("focus-mode", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getSupportedFocusModes() { +/* 3016 */ String str = get("focus-mode-values"); +/* 3017 */ return split(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public float getFocalLength() { +/* 3028 */ return Float.parseFloat(get("focal-length")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public float getHorizontalViewAngle() { +/* 3039 */ return Float.parseFloat(get("horizontal-view-angle")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public float getVerticalViewAngle() { +/* 3050 */ return Float.parseFloat(get("vertical-view-angle")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getExposureCompensation() { +/* 3063 */ return getInt("exposure-compensation", 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setExposureCompensation(int value) { +/* 3078 */ set("exposure-compensation", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getMaxExposureCompensation() { +/* 3090 */ return getInt("max-exposure-compensation", 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getMinExposureCompensation() { +/* 3102 */ return getInt("min-exposure-compensation", 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public float getExposureCompensationStep() { +/* 3115 */ return getFloat("exposure-compensation-step", 0.0F); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getZoom() { +/* 3128 */ return getInt("zoom", 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void setZoom(int value) { +/* 3143 */ set("zoom", value); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean isZoomSupported() { +/* 3154 */ String str = get("zoom-supported"); +/* 3155 */ return "true".equals(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getMaxZoom() { +/* 3169 */ return getInt("max-zoom", 0); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public List getZoomRatios() { +/* 3184 */ return splitInt(get("zoom-ratios")); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public boolean isSmoothZoomSupported() { +/* 3195 */ String str = get("smooth-zoom-supported"); +/* 3196 */ return "true".equals(str); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void getFocusDistances(float[] output) { +/* 3230 */ if (output == null || output.length != 3) +/* */ { +/* 3232 */ throw new IllegalArgumentException("output must be an float array with three elements."); +/* */ } +/* 3234 */ splitFloat(get("focus-distances"), output); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private ArrayList split(String str) { +/* 3241 */ if (str == null) { +/* 3242 */ return null; +/* */ } +/* */ +/* 3245 */ StringTokenizer tokenizer = new StringTokenizer(str, ","); +/* 3246 */ ArrayList substrings = new ArrayList(); +/* 3247 */ while (tokenizer.hasMoreElements()) +/* */ { +/* 3249 */ substrings.add(tokenizer.nextToken()); +/* */ } +/* 3251 */ return substrings; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private ArrayList splitInt(String str) { +/* 3258 */ if (str == null) { +/* 3259 */ return null; +/* */ } +/* 3261 */ StringTokenizer tokenizer = new StringTokenizer(str, ","); +/* 3262 */ ArrayList substrings = new ArrayList(); +/* 3263 */ while (tokenizer.hasMoreElements()) { +/* */ +/* 3265 */ String token = tokenizer.nextToken(); +/* 3266 */ substrings.add(Integer.valueOf(Integer.parseInt(token))); +/* */ } +/* 3268 */ if (substrings.size() == 0) { +/* 3269 */ return null; +/* */ } +/* 3271 */ return substrings; +/* */ } +/* */ +/* */ +/* */ private void splitInt(String str, int[] output) { +/* 3276 */ if (str == null) { +/* */ return; +/* */ } +/* 3279 */ StringTokenizer tokenizer = new StringTokenizer(str, ","); +/* 3280 */ int index = 0; +/* 3281 */ while (tokenizer.hasMoreElements()) { +/* */ +/* 3283 */ String token = tokenizer.nextToken(); +/* 3284 */ output[index++] = Integer.parseInt(token); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ private void splitFloat(String str, float[] output) { +/* 3291 */ if (str == null) { +/* */ return; +/* */ } +/* 3294 */ StringTokenizer tokenizer = new StringTokenizer(str, ","); +/* 3295 */ int index = 0; +/* 3296 */ while (tokenizer.hasMoreElements()) { +/* */ +/* 3298 */ String token = tokenizer.nextToken(); +/* 3299 */ output[index++] = Float.parseFloat(token); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private float getFloat(String key, float defaultValue) { +/* */ try { +/* 3310 */ float flRetVal = Float.parseFloat(this.mMap.get(key)); +/* 3311 */ return flRetVal; +/* */ } +/* 3313 */ catch (Throwable throwable) { +/* */ +/* */ +/* 3316 */ return defaultValue; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private int getInt(String key, int defaultValue) { +/* */ try { +/* 3326 */ int iRetVal = Integer.parseInt(this.mMap.get(key)); +/* 3327 */ return iRetVal; +/* */ } +/* 3329 */ catch (Throwable throwable) { +/* */ +/* */ +/* 3332 */ return defaultValue; +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ private ArrayList splitSize(String str) { +/* 3339 */ if (str == null) { +/* 3340 */ return null; +/* */ } +/* 3342 */ StringTokenizer tokenizer = new StringTokenizer(str, ","); +/* 3343 */ ArrayList sizeList = new ArrayList(); +/* 3344 */ while (tokenizer.hasMoreElements()) { +/* */ +/* 3346 */ Size size = strToSize(tokenizer.nextToken()); +/* 3347 */ if (size != null) +/* 3348 */ sizeList.add(size); +/* */ } +/* 3350 */ if (sizeList.size() == 0) { +/* 3351 */ return null; +/* */ } +/* 3353 */ return sizeList; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private Size strToSize(String str) { +/* 3360 */ if (str == null) { +/* 3361 */ return null; +/* */ } +/* 3363 */ int pos = str.indexOf('x'); +/* 3364 */ if (pos != -1) { +/* */ +/* 3366 */ String width = str.substring(0, pos); +/* 3367 */ String height = str.substring(pos + 1); +/* 3368 */ return new Size(Integer.parseInt(width), Integer.parseInt(height)); +/* */ } +/* 3370 */ Log.e("BarCodeReader", "Invalid size parameter string=" + str); +/* 3371 */ return null; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ private ArrayList splitRange(String str) { +/* */ int endIndex; +/* 3379 */ if (str == null || str.charAt(0) != '(' || str.charAt(str.length() - 1) != ')') { +/* */ +/* 3381 */ Log.e("BarCodeReader", "Invalid range list string=" + str); +/* 3382 */ return null; +/* */ } +/* */ +/* 3385 */ ArrayList rangeList = (ArrayList)new ArrayList<>(); +/* 3386 */ int fromIndex = 1; +/* */ +/* */ do { +/* 3389 */ int[] range = new int[2]; +/* 3390 */ endIndex = str.indexOf("),(", fromIndex); +/* 3391 */ if (endIndex == -1) +/* 3392 */ endIndex = str.length() - 1; +/* 3393 */ splitInt(str.substring(fromIndex, endIndex), range); +/* 3394 */ rangeList.add(range); +/* 3395 */ fromIndex = endIndex + 3; +/* */ } +/* 3397 */ while (endIndex != str.length() - 1); +/* */ +/* 3399 */ if (rangeList.size() == 0) { +/* 3400 */ return null; +/* */ } +/* 3402 */ return rangeList; +/* */ } +/* */ +/* */ private Parameters() {} +/* */ } +/* */ +/* */ public static interface AutoFocusCallback { +/* */ void onAutoFocus(boolean param1Boolean, BarCodeReader param1BarCodeReader); +/* */ } +/* */ +/* */ public static interface DecodeCallback { +/* */ void onDecodeComplete(int param1Int1, int param1Int2, byte[] param1ArrayOfbyte, BarCodeReader param1BarCodeReader); +/* */ +/* */ void onEvent(int param1Int1, int param1Int2, byte[] param1ArrayOfbyte, BarCodeReader param1BarCodeReader); +/* */ } +/* */ +/* */ public static interface ErrorCallback { +/* */ void onError(int param1Int, BarCodeReader param1BarCodeReader); +/* */ } +/* */ +/* */ public static interface OnZoomChangeListener { +/* */ void onZoomChange(int param1Int, boolean param1Boolean, BarCodeReader param1BarCodeReader); +/* */ } +/* */ +/* */ public static interface PictureCallback { +/* */ void onPictureTaken(int param1Int1, int param1Int2, int param1Int3, byte[] param1ArrayOfbyte, BarCodeReader param1BarCodeReader); +/* */ } +/* */ +/* */ public static interface PreviewCallback { +/* */ void onPreviewFrame(byte[] param1ArrayOfbyte, BarCodeReader param1BarCodeReader); +/* */ } +/* */ +/* */ public static interface VideoCallback { +/* */ void onVideoFrame(int param1Int1, int param1Int2, int param1Int3, byte[] param1ArrayOfbyte, BarCodeReader param1BarCodeReader); +/* */ } +/* */ } + + +/* Location: E:\Demo\ChaoRan_A9L\libs\ScannerAPI.jar!\com\zebra\adc\decoder\BarCodeReader.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 1.1.3 + */ \ No newline at end of file diff --git a/app/src/main/java/map/baidu/com/BDMapActivity.java b/app/src/main/java/map/baidu/com/BDMapActivity.java new file mode 100644 index 0000000..e3f3dbb --- /dev/null +++ b/app/src/main/java/map/baidu/com/BDMapActivity.java @@ -0,0 +1,141 @@ +package map.baidu.com; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.ZoomControls; +import com.baidu.location.BDLocation; +import com.baidu.location.BDLocationListener; +import com.baidu.mapapi.*; +import com.example.chaoran.R; +import com.util.DialogUtil; + +import java.util.HashMap; + +public class BDMapActivity extends MapActivity { + private MapView mMapView = null; // 地图View + private MapController mMapController; + private LBSLocationClientController mLocationClientController; + private BMapManagerUtil app; + private BDLocation bdLocation; + + @Override + protected boolean isRouteDisplayed() { + // TODO Auto-generated method stub + return false; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_bdmap); + this.setTitle("正在定位......"); + app = (BMapManagerUtil) this.getApplication(); + if (app.mBMapMan == null) { + app.mBMapMan = new BMapManager(getApplication()); + app.mBMapMan.init(app.mStrKey, + new BMapManagerUtil.MyGeneralListener()); + } + super.initMapActivity(app.mBMapMan); + mMapView = (MapView) findViewById(R.id.bmapView); + mMapView.setBuiltInZoomControls(true); + mMapController = mMapView.getController(); + mMapController.setZoom(24); + mLocationClientController = new LBSLocationClientController(this, + new MyBDLocationListener()); + mLocationClientController.initializeLocationClientOption(); // 初始化定位选项(可调节) + MyLocationOverlay myLocation = new MyLocationOverlay(this, mMapView); + // 注册GPS位置更新的事件,让地图能实时显示当前位置 + myLocation.enableMyLocation(); + // 开启磁场感应传感器 + myLocation.enableCompass(); + mMapView.getOverlays().add(myLocation); + ZoomControls zoomControls = (ZoomControls) mMapView.getChildAt(2); + // mapView.removeViewAt(2); + // 调整缩放控件的位置 + zoomControls.setPadding(0, 0, 0, 100); + // 获取mapview中的百度地图图标 + ImageView iv = (ImageView) mMapView.getChildAt(1); + // mapView.removeViewAt(1); + // 调整百度地图图标的位置 + iv.setPadding(0, 0, 0, 100); + } + + @Override + protected void onPause() { + mLocationClientController.stopLocationClient(); + app.mBMapMan.stop(); + super.onPause(); + } + + @Override + protected void onResume() { + mLocationClientController.startLocationClient(); + app.mBMapMan.start(); + super.onResume(); + } + + @Override + protected void onDestroy() { + // TODO Auto-generated method stub + super.onDestroy(); + app.onTerminate(); + bdLocation = null; + app = null; + mLocationClientController = null; + mMapController = null; + mMapView = null; + } + + public void onSub(View v) { + if (bdLocation != null) { + HashMap map = new HashMap(); + map.put("latitude", bdLocation.getLatitude()); + map.put("longitude", bdLocation.getLongitude()); + map.put("gpsAddress", bdLocation.getAddrStr()); + Intent intent = getIntent(); + intent.putExtra("param", map); + setResult(3, intent); + finish(); + }else{ + DialogUtil.builder(BDMapActivity.this, "提示信息", + "正在定位",0); + } + } + + public void onCurrentLocal(View v) { + this.setTitle("正在定位......"); + mLocationClientController.requestLocationInformation(); + } + + // @Override + // public boolean onCreateOptionsMenu(Menu menu) { + // // TODO Auto-generated method stub + // super.onCreateOptionsMenu(menu); + // menu.add(0, 1, Menu.NONE, "放大"); + // menu.add(0, 2, Menu.NONE, "缩小"); + // return true; + // } + private class MyBDLocationListener implements BDLocationListener { + @Override + public void onReceiveLocation(BDLocation location) { + Log.i("onReceiveLocation", "onReceiveLocation"); + if (location == null) + return; + bdLocation = location; + mMapController.setCenter(new GeoPoint( + (int) (location.getLatitude() * 1E6), (int) (location + .getLongitude() * 1E6))); + BDMapActivity.this.setTitle("定位成功 _" + location.getAddrStr()); + } + + @Override + public void onReceivePoi(BDLocation poiLocation) { + if (poiLocation == null) + return; + } + } + +} diff --git a/app/src/main/java/map/baidu/com/BMapManagerUtil.java b/app/src/main/java/map/baidu/com/BMapManagerUtil.java new file mode 100644 index 0000000..9b0af7c --- /dev/null +++ b/app/src/main/java/map/baidu/com/BMapManagerUtil.java @@ -0,0 +1,61 @@ +package map.baidu.com; + +import android.app.Application; +import android.widget.Toast; +import com.baidu.mapapi.BMapManager; +import com.baidu.mapapi.MKEvent; +import com.baidu.mapapi.MKGeneralListener; + +public class BMapManagerUtil extends Application { + private static BMapManagerUtil bMapManagerUtil; + // 百度MapAPI的管理类 + public BMapManager mBMapMan = null; + + // 授权Key + // TODO: 请输入您的Key, + // 申请地址:http://dev.baidu.com/wiki/static/imap/key/ + public String mStrKey = "F49D31823069482466999FADEE70C34C80055379"; + private boolean m_bKeyRight = true; // 授权Key正确,验证通过 + + // 常用事件监听,用来处理通常的网络错误,授权验证错误等 + static class MyGeneralListener implements MKGeneralListener { + @Override + public void onGetNetworkState(int iError) { + Toast.makeText(bMapManagerUtil.getApplicationContext(), "您的网络出错啦!", + Toast.LENGTH_LONG).show(); + } + + @Override + public void onGetPermissionState(int iError) { + if (iError == MKEvent.ERROR_PERMISSION_DENIED) { + // 授权Key错误: + Toast.makeText(bMapManagerUtil.getApplicationContext(), + "请在BMapApiDemoApp.java文件输入正确的授权Key!", Toast.LENGTH_LONG) + .show(); + bMapManagerUtil.m_bKeyRight = false; + + } + } + + } + + @Override + public void onCreate() { + bMapManagerUtil = this; + mBMapMan = new BMapManager(this); + mBMapMan.init(this.mStrKey, new MyGeneralListener()); + super.onCreate(); + } + + @Override + // 建议在您app的退出之前调用mapadpi的destroy()函数,避免重复初始化带来的时间消耗 + public void onTerminate() { + // TODO Auto-generated method stub + if (mBMapMan != null) { + mBMapMan.destroy(); + mBMapMan = null; + } + super.onTerminate(); + } + +} diff --git a/app/src/main/java/map/baidu/com/LBSLocationClientController.java b/app/src/main/java/map/baidu/com/LBSLocationClientController.java new file mode 100644 index 0000000..732885f --- /dev/null +++ b/app/src/main/java/map/baidu/com/LBSLocationClientController.java @@ -0,0 +1,126 @@ +package map.baidu.com; + +import android.content.Context; +import android.util.Log; +import com.baidu.location.BDLocation; +import com.baidu.location.BDLocationListener; +import com.baidu.location.LocationClient; +import com.baidu.location.LocationClientOption; + +public class LBSLocationClientController { + + private LocationClient mLocationClient; + + public LBSLocationClientController(Context context, + BDLocationListener listener) { + initializeLocationClient(context, listener); + } + + private void initializeLocationClient(Context context, + BDLocationListener listener) { + + mLocationClient = new LocationClient(context); + mLocationClient.registerLocationListener(listener); + } + + private boolean isLocationClientPrepared() { + return mLocationClient != null && mLocationClient.isStarted(); + } + + public void setLocationOption(LocationClientOption option) { + mLocationClient.setLocOption(option); + } + + public void startLocationClient() { + if (mLocationClient != null) { + System.out.println("------------------------------------------启动"); + mLocationClient.start(); + } + } + + public void stopLocationClient() { + if (mLocationClient != null) { + mLocationClient.stop(); + } + } + + public void requestPIOInformation() { + if (isLocationClientPrepared()) { + Log.i("requestPoi", "requestPoi"); + mLocationClient.requestPoi(); + } + } + + public void requestLocationInformation() { + if (isLocationClientPrepared()) { + Log.i("requestLocation", "requestLocation"); + mLocationClient.requestLocation(); + } + } + + public StringBuffer buildLocationStringBuffer(BDLocation location) { + StringBuffer sb = new StringBuffer(256); + sb.append("time : "); + sb.append(location.getTime()); + sb.append("\nerror code : "); + sb.append(location.getLocType()); + sb.append("\nlatitude : "); + sb.append(location.getLatitude()); + sb.append("\nlontitude : "); + sb.append(location.getLongitude()); + sb.append("\nradius : "); + sb.append(location.getRadius()); + if (location.getLocType() == BDLocation.TypeGpsLocation) { + sb.append("\nspeed : "); + sb.append(location.getSpeed()); + sb.append("\nsatellite : "); + sb.append(location.getSatelliteNumber()); + } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) { + sb.append("\naddr : "); + sb.append(location.getAddrStr()); + } + return sb; + } + + public StringBuffer buildPIOStringBuffer(BDLocation poiLocation) { + StringBuffer sb = new StringBuffer(256); + sb.append("Poi time : "); + sb.append(poiLocation.getTime()); + sb.append("\nerror code : "); + sb.append(poiLocation.getLocType()); + sb.append("\nlatitude : "); + sb.append(poiLocation.getLatitude()); + sb.append("\nlontitude : "); + sb.append(poiLocation.getLongitude()); + sb.append("\nradius : "); + sb.append(poiLocation.getRadius()); + if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation) { + sb.append("\naddr : "); + sb.append(poiLocation.getAddrStr()); + } + if (poiLocation.hasPoi()) { + sb.append("\nPoi:"); + sb.append(poiLocation.getPoi()); + } else { + sb.append("noPoi information"); + } + return sb; + } + + public void initializeLocationClientOption() { + LocationClientOption option = new LocationClientOption(); + option.setOpenGps(true);// 开启GPS +// option.setAddrType("detail"); + option.setCoorType("bd09ll");// gcj02 +// option.setScanSpan(800); + option.setServiceName("crtech"); + option.setProdName("crtech"); + option.setAddrType("all"); + option.disableCache(true);// 禁止启用缓存定位 + option.setPoiNumber(5); // 最多返回POI个数 + option.setPoiDistance(500); // poi查询距离 + option.setPoiExtraInfo(true); // 是否需要POI的电话和地址等详细信息 + setLocationOption(option); + } + +} diff --git a/app/src/main/res/drawable-hdpi/calendar.png b/app/src/main/res/drawable-hdpi/calendar.png new file mode 100644 index 0000000..ef1038b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/calendar.png differ diff --git a/app/src/main/res/drawable-hdpi/checkbox_empty.png b/app/src/main/res/drawable-hdpi/checkbox_empty.png new file mode 100644 index 0000000..b50cbfa Binary files /dev/null and b/app/src/main/res/drawable-hdpi/checkbox_empty.png differ diff --git a/app/src/main/res/drawable-hdpi/checkbox_full.png b/app/src/main/res/drawable-hdpi/checkbox_full.png new file mode 100644 index 0000000..9c25249 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/checkbox_full.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_action_search.png b/app/src/main/res/drawable-hdpi/ic_action_search.png new file mode 100644 index 0000000..67de12d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..4fd7458 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-hdpi/logo.png b/app/src/main/res/drawable-hdpi/logo.png new file mode 100644 index 0000000..4fd7458 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/logo.png differ diff --git a/app/src/main/res/drawable-hdpi/mm_title_back_focused.png b/app/src/main/res/drawable-hdpi/mm_title_back_focused.png new file mode 100644 index 0000000..e979613 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/mm_title_back_focused.png differ diff --git a/app/src/main/res/drawable-hdpi/mm_title_back_normal.png b/app/src/main/res/drawable-hdpi/mm_title_back_normal.png new file mode 100644 index 0000000..f57da3d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/mm_title_back_normal.png differ diff --git a/app/src/main/res/drawable-hdpi/mm_title_back_pressed.png b/app/src/main/res/drawable-hdpi/mm_title_back_pressed.png new file mode 100644 index 0000000..8cb91f6 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/mm_title_back_pressed.png differ diff --git a/app/src/main/res/drawable-hdpi/mmtitle_bg_alpha.png b/app/src/main/res/drawable-hdpi/mmtitle_bg_alpha.png new file mode 100644 index 0000000..99528cc Binary files /dev/null and b/app/src/main/res/drawable-hdpi/mmtitle_bg_alpha.png differ diff --git a/app/src/main/res/drawable-ldpi/ic_launcher.png b/app/src/main/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000..2206095 Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_search.png b/app/src/main/res/drawable-mdpi/ic_action_search.png new file mode 100644 index 0000000..134d549 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..59ebb8e Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_search.png b/app/src/main/res/drawable-xhdpi/ic_action_search.png new file mode 100644 index 0000000..d699c6b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_search.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..8a0e38d Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable/mm_title_back_btn.xml b/app/src/main/res/drawable/mm_title_back_btn.xml new file mode 100644 index 0000000..a2d1086 --- /dev/null +++ b/app/src/main/res/drawable/mm_title_back_btn.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_bdmap.xml b/app/src/main/res/layout/activity_bdmap.xml new file mode 100644 index 0000000..566b7ed --- /dev/null +++ b/app/src/main/res/layout/activity_bdmap.xml @@ -0,0 +1,43 @@ + + + + + + +