Skip to content

Commit

Permalink
Update scan text
Browse files Browse the repository at this point in the history
  • Loading branch information
YOOJIA.CHEN committed Sep 27, 2016
1 parent 0e91e93 commit f898962
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.yoojia.qrcode.camera.CaptureCallback;
import com.github.yoojia.qrcode.camera.CameraPreviewView;
import com.github.yoojia.qrcode.camera.CaptureCallback;
import com.github.yoojia.qrcode.camera.LiveCameraView;
import com.github.yoojia.qrcode.qrcode.QRCodeDecoder;
import com.github.yoojia.zxing.R;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
* @author : Yoojia.Chen (yoojia.chen@gmail.com)
* 扫描二维码
Expand All @@ -25,11 +33,27 @@ public class QRCodeScanActivity extends AppCompatActivity {
private LiveCameraView mLiveCameraView;

private ImageView mCaptureImage;
private TextView mContentView;

private final CaptureCallback mCaptureCallback = new CaptureCallback() {
@Override public void onCaptured(Bitmap bitmap) {
Log.i(TAG, "-> Got bitmap, show to capture view");
mCaptureImage.setImageBitmap(bitmap);
Observable.just(bitmap)
.map(new Func1<Bitmap, String>() {
private final QRCodeDecoder mDecoder = new QRCodeDecoder.Builder().build();
@Override
public String call(Bitmap bitmap) {
return mDecoder.decode(bitmap);
}
})
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<String>() {
@Override public void call(String content) {
mContentView.setText(content);
}
});
}
};

Expand All @@ -40,6 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_scan);
mCaptureImage = (ImageView) findViewById(R.id.capture_image);
mContentView = (TextView) findViewById(R.id.content);
mLiveCameraView = (LiveCameraView) findViewById(R.id.capture_preview_view);
mLiveCameraView.setPreviewReadyCallback(new CameraPreviewView.PreviewReadyCallback() {
@Override
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/layout/activity_scan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
android:layout_width="120dp"
android:layout_height="80dp"/>

<!--
<com.github.yoojia.qrcode.camera.LiveFocusView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>-->
<TextView
android:id="@+id/content"
android:gravity="center"
android:textColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>

0 comments on commit f898962

Please sign in to comment.