Skip to content

Commit 374cf30

Browse files
committed
从 APIJSON 主项目迁移 Demo 项目过来
1 parent 7727044 commit 374cf30

File tree

624 files changed

+65577
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

624 files changed

+65577
-0
lines changed

APIJSON-Android/APIJSONApp/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
.idea
5+
.DS_Store
6+
/build
7+
/captures
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion '29.0.0'
6+
defaultConfig {
7+
minSdkVersion 20
8+
targetSdkVersion 22
9+
versionCode 1
10+
versionName "1.0"
11+
}
12+
buildTypes {
13+
release {
14+
minifyEnabled false
15+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16+
}
17+
}
18+
productFlavors {
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
}
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/Tommy/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ericssonlabs;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.ericssonlabs"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk android:minSdkVersion="10" />
8+
9+
<!-- 复制粘贴到你的工程的AndroidManifest.xml内对应位置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
10+
11+
12+
<!-- 需要的权限和功能 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
13+
<uses-permission android:name="android.permission.VIBRATE" />
14+
<uses-permission android:name="android.permission.CAMERA" />
15+
<uses-permission android:name="android.permission.FLASHLIGHT" />
16+
17+
<uses-feature android:name="android.hardware.camera" />
18+
<uses-feature android:name="android.hardware.camera.autofocus" />
19+
<!-- 需要的权限和功能 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
20+
21+
<!-- 复制粘贴到你的工程的AndroidManifest.xml内对应位置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
22+
23+
</manifest>
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
package com.zxing.activity;
2+
3+
import java.io.IOException;
4+
import java.util.Vector;
5+
6+
import android.app.Activity;
7+
import android.content.Intent;
8+
import android.content.res.AssetFileDescriptor;
9+
import android.graphics.Bitmap;
10+
import android.media.AudioManager;
11+
import android.media.MediaPlayer;
12+
import android.media.MediaPlayer.OnCompletionListener;
13+
import android.os.Bundle;
14+
import android.os.Handler;
15+
import android.os.Vibrator;
16+
import android.view.SurfaceHolder;
17+
import android.view.SurfaceHolder.Callback;
18+
import android.view.SurfaceView;
19+
import android.view.Window;
20+
import android.widget.Toast;
21+
22+
import com.ericssonlabs.R;
23+
import com.google.zxing.BarcodeFormat;
24+
import com.google.zxing.Result;
25+
import com.zxing.camera.CameraManager;
26+
import com.zxing.decoding.CaptureActivityHandler;
27+
import com.zxing.decoding.CaptureActivityHandler.DecodeCallback;
28+
import com.zxing.decoding.InactivityTimer;
29+
import com.zxing.view.ViewfinderView;
30+
/**
31+
* Initial the camera
32+
* @author Ryan.Tang
33+
* @modifier Lemon
34+
* @use extends CaptureActivity并且在setContentView方法后调用init方法
35+
*/
36+
public abstract class CaptureActivity extends Activity implements Callback, DecodeCallback {
37+
// private static final String TAG = "CaptureActivity";
38+
39+
protected Activity context;
40+
protected SurfaceView surfaceView;
41+
protected ViewfinderView viewfinderView;
42+
/**初始化,必须在setContentView之后
43+
* @param context
44+
* @param viewfinderView
45+
*/
46+
protected void init(Activity context, SurfaceView surfaceView, ViewfinderView viewfinderView) {
47+
this.context = context;
48+
this.surfaceView = surfaceView;
49+
this.viewfinderView = viewfinderView;
50+
51+
CameraManager.init(getApplication());
52+
53+
hasSurface = false;
54+
inactivityTimer = new InactivityTimer(this);
55+
}
56+
57+
private boolean isOn = false;
58+
protected final boolean isOn() {
59+
return isOn;
60+
}
61+
/**打开或关闭闪关灯
62+
* @param open
63+
*/
64+
protected void switchLight(boolean on) {
65+
if (on == isOn()) {
66+
return;
67+
}
68+
isOn = CameraManager.get().switchLight(on);
69+
}
70+
71+
72+
73+
@Override
74+
protected void onCreate(Bundle savedInstanceState) {
75+
super.onCreate(savedInstanceState);
76+
requestWindowFeature(Window.FEATURE_NO_TITLE);
77+
}
78+
79+
80+
private CaptureActivityHandler handler;
81+
private boolean hasSurface;
82+
private Vector<BarcodeFormat> decodeFormats;
83+
private String characterSet;
84+
private InactivityTimer inactivityTimer;
85+
private MediaPlayer mediaPlayer;
86+
private boolean playBeep;
87+
private static final float BEEP_VOLUME = 0.10f;
88+
private boolean vibrate;
89+
90+
91+
@Override
92+
protected void onResume() {
93+
super.onResume();
94+
SurfaceHolder surfaceHolder = surfaceView.getHolder();
95+
if (hasSurface) {
96+
initCamera(surfaceHolder);
97+
} else {
98+
surfaceHolder.addCallback(this);
99+
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
100+
}
101+
decodeFormats = null;
102+
characterSet = null;
103+
104+
playBeep = true;
105+
AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
106+
if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
107+
playBeep = false;
108+
}
109+
initBeepSound();
110+
vibrate = true;
111+
}
112+
113+
@Override
114+
protected void onPause() {
115+
super.onPause();
116+
if (handler != null) {
117+
handler.quitSynchronously();
118+
handler = null;
119+
}
120+
isOn = false;
121+
CameraManager.get().closeDriver();
122+
}
123+
124+
125+
@Override
126+
protected void onDestroy() {
127+
inactivityTimer.shutdown();
128+
super.onDestroy();
129+
}
130+
131+
132+
public static final String RESULT_QRCODE_STRING = "RESULT_QRCODE_STRING";
133+
/**
134+
* Handler scan result
135+
* @param result
136+
* @param barcode
137+
*/
138+
public void handleDecode(Result result, Bitmap barcode) {
139+
inactivityTimer.onActivity();
140+
playBeepSoundAndVibrate();
141+
String resultString = result.getText();
142+
//FIXME
143+
if (resultString.equals("")) {
144+
Toast.makeText(CaptureActivity.this, "Scan failed!", Toast.LENGTH_SHORT).show();
145+
}
146+
147+
setResult(RESULT_OK, new Intent().putExtra(RESULT_QRCODE_STRING, resultString));
148+
finish();
149+
}
150+
151+
private void initCamera(SurfaceHolder surfaceHolder) {
152+
try {
153+
CameraManager.get().openDriver(surfaceHolder);
154+
} catch (IOException ioe) {
155+
return;
156+
} catch (RuntimeException e) {
157+
return;
158+
}
159+
if (handler == null) {
160+
handler = new CaptureActivityHandler(this, decodeFormats,
161+
characterSet, viewfinderView, this);
162+
}
163+
}
164+
165+
@Override
166+
public void drawViewfinder() {
167+
viewfinderView.drawViewfinder();
168+
}
169+
170+
171+
@Override
172+
public void surfaceChanged(SurfaceHolder holder, int format, int width,
173+
int height) {
174+
175+
}
176+
177+
@Override
178+
public void surfaceCreated(SurfaceHolder holder) {
179+
if (!hasSurface) {
180+
hasSurface = true;
181+
initCamera(holder);
182+
}
183+
184+
}
185+
186+
@Override
187+
public void surfaceDestroyed(SurfaceHolder holder) {
188+
hasSurface = false;
189+
190+
}
191+
192+
193+
public Handler getHandler() {
194+
return handler;
195+
}
196+
197+
198+
private void initBeepSound() {
199+
if (playBeep && mediaPlayer == null) {
200+
// The volume on STREAM_SYSTEM is not adjustable, and users found it
201+
// too loud,
202+
// so we now play on the music stream.
203+
setVolumeControlStream(AudioManager.STREAM_MUSIC);
204+
mediaPlayer = new MediaPlayer();
205+
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
206+
mediaPlayer.setOnCompletionListener(beepListener);
207+
208+
AssetFileDescriptor file = getResources().openRawResourceFd(
209+
R.raw.beep);
210+
try {
211+
mediaPlayer.setDataSource(file.getFileDescriptor(),
212+
file.getStartOffset(), file.getLength());
213+
file.close();
214+
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
215+
mediaPlayer.prepare();
216+
} catch (IOException e) {
217+
mediaPlayer = null;
218+
}
219+
}
220+
}
221+
222+
private static final long VIBRATE_DURATION = 200L;
223+
224+
private void playBeepSoundAndVibrate() {
225+
if (playBeep && mediaPlayer != null) {
226+
mediaPlayer.start();
227+
}
228+
if (vibrate) {
229+
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
230+
vibrator.vibrate(VIBRATE_DURATION);
231+
}
232+
}
233+
234+
/**
235+
* When the beep has finished playing, rewind to queue up another one.
236+
*/
237+
private final OnCompletionListener beepListener = new OnCompletionListener() {
238+
public void onCompletion(MediaPlayer mediaPlayer) {
239+
mediaPlayer.seekTo(0);
240+
}
241+
};
242+
243+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2010 ZXing authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.zxing.camera;
18+
19+
import android.hardware.Camera;
20+
import android.os.Handler;
21+
import android.os.Message;
22+
import android.util.Log;
23+
24+
final class AutoFocusCallback implements Camera.AutoFocusCallback {
25+
26+
private static final String TAG = AutoFocusCallback.class.getSimpleName();
27+
28+
private static final long AUTOFOCUS_INTERVAL_MS = 1500L;
29+
30+
private Handler autoFocusHandler;
31+
private int autoFocusMessage;
32+
33+
void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
34+
this.autoFocusHandler = autoFocusHandler;
35+
this.autoFocusMessage = autoFocusMessage;
36+
}
37+
38+
public void onAutoFocus(boolean success, Camera camera) {
39+
if (autoFocusHandler != null) {
40+
Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
41+
autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
42+
autoFocusHandler = null;
43+
} else {
44+
Log.d(TAG, "Got auto-focus callback, but no handler for it");
45+
}
46+
}
47+
48+
}

0 commit comments

Comments
 (0)