forked from littlemonkeyltd/QRScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request littlemonkeyltd#7 from littlemonkeyltd/combined_sc…
…anner Combined scanner
- Loading branch information
Showing
65 changed files
with
6,293 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
84 changes: 84 additions & 0 deletions
84
native/android/com/codename1/ext/codescan/NativeCodeScannerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.codename1.ext.codescan; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import com.codename1.impl.android.AndroidNativeUtil; | ||
import com.codename1.impl.android.CodenameOneActivity; | ||
import com.codename1.impl.android.IntentIntegrator; | ||
import com.codename1.impl.android.IntentResultListener; | ||
import com.codename1.ui.Display; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
public class NativeCodeScannerImpl implements IntentResultListener { | ||
|
||
public void scanQRCode() { | ||
Activity activity = AndroidNativeUtil.getActivity(); | ||
if (activity instanceof CodenameOneActivity) { | ||
((CodenameOneActivity) activity).setIntentResultListener(this); | ||
} | ||
//this.callback = callback; | ||
IntentIntegrator in = new IntentIntegrator(activity); | ||
if(!in.initiateScan(IntentIntegrator.QR_CODE_TYPES, "QR_CODE_MODE")){ | ||
CodeScanner.scanErrorCallback(-1, "no scan app"); | ||
|
||
if (activity instanceof CodenameOneActivity) { | ||
((CodenameOneActivity) activity).restoreIntentResultListener(); | ||
} | ||
} | ||
} | ||
|
||
public void scanBarCode() { | ||
Activity activity = AndroidNativeUtil.getActivity(); | ||
if (activity instanceof CodenameOneActivity) { | ||
((CodenameOneActivity) activity).setIntentResultListener(this); | ||
} | ||
IntentIntegrator in = new IntentIntegrator(activity); | ||
Collection<String> types = IntentIntegrator.PRODUCT_CODE_TYPES; | ||
if(Display.getInstance().getProperty("scanAllCodeTypes", "false").equals("true")) { | ||
types = IntentIntegrator.ALL_CODE_TYPES; | ||
} | ||
if(Display.getInstance().getProperty("android.scanTypes", null) != null) { | ||
String[] arr = Display.getInstance().getProperty("android.scanTypes", null).split(";"); | ||
types = Arrays.asList(arr); | ||
} | ||
|
||
if(!in.initiateScan(types, "ONE_D_MODE")){ | ||
// restore old activity handling | ||
CodeScanner.scanErrorCallback(-1, "no scan app"); | ||
if (activity instanceof CodenameOneActivity) { | ||
((CodenameOneActivity) activity).restoreIntentResultListener(); | ||
} | ||
} | ||
} | ||
|
||
public void onActivityResult(int requestCode, final int resultCode, Intent data) { | ||
Activity activity = AndroidNativeUtil.getActivity(); | ||
if (requestCode == IntentIntegrator.REQUEST_CODE) { | ||
|
||
if (resultCode == Activity.RESULT_OK) { | ||
final String contents = data.getStringExtra("SCAN_RESULT"); | ||
final String formatName = data.getStringExtra("SCAN_RESULT_FORMAT"); | ||
final byte[] rawBytes = data.getByteArrayExtra("SCAN_RESULT_BYTES"); | ||
CodeScanner.scanCompletedCallback(contents, formatName, rawBytes); | ||
|
||
} else if(resultCode == Activity.RESULT_CANCELED) { | ||
CodeScanner.scanCanceledCallback(); | ||
|
||
} else { | ||
CodeScanner.scanErrorCallback(resultCode, null); | ||
|
||
} | ||
} | ||
|
||
// restore old activity handling | ||
if (activity instanceof CodenameOneActivity) { | ||
((CodenameOneActivity) activity).restoreIntentResultListener(); | ||
} | ||
} | ||
|
||
public boolean isSupported() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+344 Bytes
native/internal_tmp/com/codename1/ext/codescan/NativeCodeScannerImpl.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <Foundation/Foundation.h> | ||
#if !TARGET_IPHONE_SIMULATOR | ||
#import "ZBarReaderViewController.h" | ||
|
||
@interface CVZBarReaderViewControllerExt : ZBarReaderViewController | ||
@end | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#import "CVZBarReaderViewControllerExt.h" | ||
#if !TARGET_IPHONE_SIMULATOR | ||
|
||
@implementation CVZBarReaderViewControllerExt | ||
- (void) loadView | ||
{ | ||
#ifdef CN1_USE_ARC | ||
self.view = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)]; | ||
#else | ||
self.view = [[[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)] autorelease]; | ||
#endif | ||
} | ||
@end | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
//------------------------------------------------------------------------ | ||
// Copyright 2007-2010 (c) Jeff Brown <[email protected]> | ||
// | ||
// This file is part of the ZBar Bar Code Reader. | ||
// | ||
// The ZBar Bar Code Reader is free software; you can redistribute it | ||
// and/or modify it under the terms of the GNU Lesser Public License as | ||
// published by the Free Software Foundation; either version 2.1 of | ||
// the License, or (at your option) any later version. | ||
// | ||
// The ZBar Bar Code Reader is distributed in the hope that it will be | ||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser Public License | ||
// along with the ZBar Bar Code Reader; if not, write to the Free | ||
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, | ||
// Boston, MA 02110-1301 USA | ||
// | ||
// http://sourceforge.net/projects/zbar | ||
//------------------------------------------------------------------------ | ||
#ifndef _ZBAR_DECODER_H_ | ||
#define _ZBAR_DECODER_H_ | ||
|
||
/// @file | ||
/// Decoder C++ wrapper | ||
|
||
#ifndef _ZBAR_H_ | ||
# error "include zbar.h in your application, **not** zbar/Decoder.h" | ||
#endif | ||
|
||
#include <string> | ||
|
||
namespace zbar { | ||
|
||
/// low-level bar width stream decoder interface. | ||
/// identifies symbols and extracts encoded data | ||
|
||
class Decoder { | ||
public: | ||
|
||
/// Decoder result handler. | ||
/// applications should subtype this and pass an instance to | ||
/// set_handler() to implement result processing | ||
class Handler { | ||
public: | ||
virtual ~Handler() { } | ||
|
||
/// invoked by the Decoder as decode results become available. | ||
virtual void decode_callback(Decoder &decoder) = 0; | ||
}; | ||
|
||
/// constructor. | ||
Decoder () | ||
: _handler(NULL) | ||
{ | ||
_decoder = zbar_decoder_create(); | ||
} | ||
|
||
~Decoder () | ||
{ | ||
zbar_decoder_destroy(_decoder); | ||
} | ||
|
||
/// clear all decoder state. | ||
/// see zbar_decoder_reset() | ||
void reset () | ||
{ | ||
zbar_decoder_reset(_decoder); | ||
} | ||
|
||
/// mark start of a new scan pass. | ||
/// see zbar_decoder_new_scan() | ||
void new_scan () | ||
{ | ||
zbar_decoder_new_scan(_decoder); | ||
} | ||
|
||
/// process next bar/space width from input stream. | ||
/// see zbar_decode_width() | ||
zbar_symbol_type_t decode_width (unsigned width) | ||
{ | ||
return(zbar_decode_width(_decoder, width)); | ||
} | ||
|
||
/// process next bar/space width from input stream. | ||
/// see zbar_decode_width() | ||
Decoder& operator<< (unsigned width) | ||
{ | ||
zbar_decode_width(_decoder, width); | ||
return(*this); | ||
} | ||
|
||
/// retrieve color of @em next element passed to Decoder. | ||
/// see zbar_decoder_get_color() | ||
zbar_color_t get_color () const | ||
{ | ||
return(zbar_decoder_get_color(_decoder)); | ||
} | ||
|
||
/// retrieve last decoded symbol type. | ||
/// see zbar_decoder_get_type() | ||
zbar_symbol_type_t get_type () const | ||
{ | ||
return(zbar_decoder_get_type(_decoder)); | ||
} | ||
|
||
/// retrieve string name of last decoded symbol type. | ||
/// see zbar_get_symbol_name() | ||
const char *get_symbol_name () const | ||
{ | ||
return(zbar_get_symbol_name(zbar_decoder_get_type(_decoder))); | ||
} | ||
|
||
/// retrieve string name for last decode addon. | ||
/// see zbar_get_addon_name() | ||
/// @deprecated in 0.11 | ||
const char *get_addon_name () const | ||
{ | ||
return(zbar_get_addon_name(zbar_decoder_get_type(_decoder))); | ||
} | ||
|
||
/// retrieve last decoded data in ASCII format as a char array. | ||
/// see zbar_decoder_get_data() | ||
const char *get_data_chars() const | ||
{ | ||
return(zbar_decoder_get_data(_decoder)); | ||
} | ||
|
||
/// retrieve last decoded data as a std::string. | ||
/// see zbar_decoder_get_data() | ||
const std::string get_data_string() const | ||
{ | ||
return(std::string(zbar_decoder_get_data(_decoder), | ||
zbar_decoder_get_data_length(_decoder))); | ||
} | ||
|
||
/// retrieve last decoded data as a std::string. | ||
/// see zbar_decoder_get_data() | ||
const std::string get_data() const | ||
{ | ||
return(get_data_string()); | ||
} | ||
|
||
/// retrieve length of decoded binary data. | ||
/// see zbar_decoder_get_data_length() | ||
int get_data_length() const | ||
{ | ||
return(zbar_decoder_get_data_length(_decoder)); | ||
} | ||
|
||
/// retrieve last decode direction. | ||
/// see zbar_decoder_get_direction() | ||
/// @since 0.11 | ||
int get_direction() const | ||
{ | ||
return(zbar_decoder_get_direction(_decoder)); | ||
} | ||
|
||
/// setup callback to handle result data. | ||
void set_handler (Handler &handler) | ||
{ | ||
_handler = &handler; | ||
zbar_decoder_set_handler(_decoder, _cb); | ||
zbar_decoder_set_userdata(_decoder, this); | ||
} | ||
|
||
/// set config for indicated symbology (0 for all) to specified value. | ||
/// @see zbar_decoder_set_config() | ||
/// @since 0.4 | ||
int set_config (zbar_symbol_type_t symbology, | ||
zbar_config_t config, | ||
int value) | ||
{ | ||
return(zbar_decoder_set_config(_decoder, symbology, config, value)); | ||
} | ||
|
||
/// set config parsed from configuration string. | ||
/// @see zbar_decoder_parse_config() | ||
/// @since 0.4 | ||
int set_config (std::string cfgstr) | ||
{ | ||
return(zbar_decoder_parse_config(_decoder, cfgstr.c_str())); | ||
} | ||
|
||
private: | ||
friend class Scanner; | ||
zbar_decoder_t *_decoder; | ||
Handler *_handler; | ||
|
||
static void _cb (zbar_decoder_t *cdcode) | ||
{ | ||
Decoder *dcode = (Decoder*)zbar_decoder_get_userdata(cdcode); | ||
if(dcode && dcode->_handler) | ||
dcode->_handler->decode_callback(*dcode); | ||
} | ||
}; | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.