Skip to content

Commit

Permalink
Merge pull request #61 from MuhamadJawdat/master
Browse files Browse the repository at this point in the history
Portrait, capture properties fix
  • Loading branch information
hansemannn authored Nov 21, 2017
2 parents cd1fa01 + ff4c30d commit 004894b
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 116 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ xcuserdata
.idea/
libs/
/android/java-sources.txt

.project
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode7.3
osx_image: xcode9
env:
global:
- "MODULE_NAME=ti.barcode"
Expand Down
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 3.1.0
version: 3.1.1
apiversion: 3
architectures: armeabi-v7a x86
description: Lets you process 1D/2D barcodes.
Expand Down
159 changes: 94 additions & 65 deletions android/src/com/google/zxing/client/android/CaptureActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private String characterSet;
private InactivityTimer inactivityTimer;
private BeepManager beepManager;

private boolean allowMenu;
private boolean keepOpen;
private boolean showRectangle;

private AmbientLightManager ambientLightManager;

private boolean showInfoText = false;

private static final int SHARE_ID = Menu.FIRST;
private static final int HISTORY_ID = Menu.FIRST + 1;
private static final int SETTINGS_ID = Menu.FIRST + 2;
Expand All @@ -122,6 +128,10 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
private FrameLayout _layout;
private static CaptureActivity _instance;

public boolean doKeepOpen() {
return keepOpen;
}

public static CaptureActivity getInstance() {
return _instance;
}
Expand Down Expand Up @@ -161,15 +171,15 @@ public void onCreate(Bundle icicle) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
_instance = this;
_layout = (FrameLayout) View.inflate(this, RHelper.getLayout("capture"), null);

setContentView(_layout);

if (Intents.Scan.overlayProxy != null) {
View overlayView = Intents.Scan.overlayProxy.getOrCreateView().getNativeView();
_layout.addView(overlayView);
overlayView.bringToFront();
}

hasSurface = false;
inactivityTimer = new InactivityTimer(this);
beepManager = new BeepManager(this);
Expand Down Expand Up @@ -197,6 +207,15 @@ private void resume(){
resultView = findViewById(RHelper.getId("result_view"));
statusView = (TextView) findViewById(RHelper.getId("status_view"));

Intent intent = getIntent();
boolean showInfoText = intent.getBooleanExtra(Intents.Scan.SHOW_INFO_TEXT, false);

if (showInfoText) {
statusView.setVisibility(View.VISIBLE);
} else {
statusView.setVisibility(View.GONE);
}

handler = null;
lastResult = null;

Expand All @@ -205,7 +224,7 @@ private void resume(){
if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
setRequestedOrientation(getCurrentOrientation());
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}

resetStatusView();
Expand All @@ -216,7 +235,6 @@ private void resume(){

inactivityTimer.onResume();

Intent intent = getIntent();

copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
&& (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));
Expand Down Expand Up @@ -247,13 +265,22 @@ private void resume(){
}
}

showRectangle = intent.getBooleanExtra(Intents.Scan.SHOW_RECTANGLE, true);
viewfinderView.setShowRectangle(showRectangle);
allowMenu = intent.getBooleanExtra(Intents.Scan.ALLOW_MENU, true);
if (intent.getBooleanExtra(Intents.Scan.ALLOW_INSTRUCTIONS, true)) {
//showHelpOnFirstLaunch();
}

keepOpen = intent.getBooleanExtra(Intents.Scan.KEEP_OPEN, false);

if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
if (cameraId >= 0) {
cameraManager.setManualCameraId(cameraId);
}
}

String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
if (customPromptMessage != null) {
statusView.setText(customPromptMessage);
Expand Down Expand Up @@ -318,7 +345,7 @@ private int getCurrentOrientation() {
}
}
}

private static boolean isZXingURL(String dataString) {
if (dataString == null) {
return false;
Expand Down Expand Up @@ -396,6 +423,9 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!allowMenu) {
return false;
}
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(RHelper.getLayout("capture"), menu);
return super.onCreateOptionsMenu(menu);
Expand Down Expand Up @@ -529,10 +559,10 @@ private void drawResultPoints(Bitmap barcode, float scaleFactor, Result rawResul

private static void drawLine(Canvas canvas, Paint paint, ResultPoint a, ResultPoint b, float scaleFactor) {
if (a != null && b != null) {
canvas.drawLine(scaleFactor * a.getX(),
scaleFactor * a.getY(),
scaleFactor * b.getX(),
scaleFactor * b.getY(),
canvas.drawLine(scaleFactor * a.getX(),
scaleFactor * a.getY(),
scaleFactor * b.getX(),
scaleFactor * b.getY(),
paint);
}
}
Expand Down Expand Up @@ -561,52 +591,47 @@ private void handleDecodeInternally(Result rawResult, ResultHandler resultHandle
barcodeImageView.setImageBitmap(barcode);
}

TextView formatTextView = (TextView) findViewById(RHelper.getId("format_text_view"));
formatTextView.setText(rawResult.getBarcodeFormat().toString());

TextView typeTextView = (TextView) findViewById(RHelper.getId("type_text_view"));
typeTextView.setText(resultHandler.getType().toString());

DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
TextView timeTextView = (TextView) findViewById(RHelper.getId("time_text_view"));
timeTextView.setText(formatter.format(rawResult.getTimestamp()));


TextView metaTextView = (TextView) findViewById(RHelper.getId("meta_text_view"));
View metaTextViewLabel = findViewById(RHelper.getId("meta_text_view_label"));
metaTextView.setVisibility(View.GONE);
metaTextViewLabel.setVisibility(View.GONE);
Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
if (metadata != null) {
StringBuilder metadataText = new StringBuilder(20);
for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
metadataText.append(entry.getValue()).append('\n');
if (showInfoText) {
TextView formatTextView = (TextView) findViewById(RHelper.getId("format_text_view"));
formatTextView.setText(rawResult.getBarcodeFormat().toString());

TextView typeTextView = (TextView) findViewById(RHelper.getId("type_text_view"));
typeTextView.setText(resultHandler.getType().toString());

DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
TextView timeTextView = (TextView) findViewById(RHelper.getId("time_text_view"));
timeTextView.setText(formatter.format(rawResult.getTimestamp()));

TextView metaTextView = (TextView) findViewById(RHelper.getId("meta_text_view"));
View metaTextViewLabel = findViewById(RHelper.getId("meta_text_view_label"));
metaTextView.setVisibility(View.GONE);
metaTextViewLabel.setVisibility(View.GONE);
Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
if (metadata != null) {
StringBuilder metadataText = new StringBuilder(20);
for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
metadataText.append(entry.getValue()).append('\n');
}
}
if (metadataText.length() > 0) {
metadataText.setLength(metadataText.length() - 1);
metaTextView.setText(metadataText);
metaTextView.setVisibility(View.VISIBLE);
metaTextViewLabel.setVisibility(View.VISIBLE);
}
}
}
if (metadataText.length() > 0) {
metadataText.setLength(metadataText.length() - 1);
metaTextView.setText(metadataText);
metaTextView.setVisibility(View.VISIBLE);
metaTextViewLabel.setVisibility(View.VISIBLE);
}
}

CharSequence displayContents = resultHandler.getDisplayContents();
TextView contentsTextView = (TextView) findViewById(RHelper.getId("contents_text_view"));
contentsTextView.setText(displayContents);
int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);
CharSequence displayContents = resultHandler.getDisplayContents();
TextView contentsTextView = (TextView) findViewById(RHelper.getId("contents_text_view"));
contentsTextView.setText(displayContents);
int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

TextView supplementTextView = (TextView) findViewById(RHelper.getId("contents_supplement_text_view"));
supplementTextView.setText("");
supplementTextView.setOnClickListener(null);
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
// SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
// resultHandler.getResult(),
// historyManager,
// this);
TextView supplementTextView = (TextView) findViewById(RHelper.getId("contents_supplement_text_view"));
supplementTextView.setText("");
supplementTextView.setOnClickListener(null);
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
PreferencesActivity.KEY_SUPPLEMENTAL, true)) {}
}

int buttonCount = resultHandler.getButtonCount();
Expand Down Expand Up @@ -645,13 +670,15 @@ private void handleDecodeExternally(Result rawResult, ResultHandler resultHandle
if (rawResultString.length() > 32) {
rawResultString = rawResultString.substring(0, 32) + " ...";
}
statusView.setText(getString(resultHandler.getDisplayTitle()) + " : " + rawResultString);
if (showInfoText) {
statusView.setText(getString(resultHandler.getDisplayTitle()) + " : " + rawResultString);
}
}

maybeSetClipboard(resultHandler);

if (source == IntentSource.NATIVE_APP_INTENT) {

// Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
// the deprecated intent is retired.
Intent intent = new Intent(getIntent().getAction());
Expand Down Expand Up @@ -687,23 +714,23 @@ private void handleDecodeExternally(Result rawResult, ResultHandler resultHandle
}
}
sendReplyMessage(RHelper.getId("return_scan_result"), intent, resultDurationMS);

} else if (source == IntentSource.PRODUCT_SEARCH_LINK) {

// Reformulate the URL which triggered us into a query, so that the request goes to the same
// TLD as the scan URL.
int end = sourceUrl.lastIndexOf("/scan");
String replyURL = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents() + "&source=zxing";
String replyURL = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents() + "&source=zxing";
sendReplyMessage(RHelper.getId("launch_product_query"), replyURL, resultDurationMS);

} else if (source == IntentSource.ZXING_LINK) {

if (scanFromWebPageManager != null && scanFromWebPageManager.isScanFromWebPage()) {
String replyURL = scanFromWebPageManager.buildReplyURL(rawResult, resultHandler);
scanFromWebPageManager = null;
sendReplyMessage(RHelper.getId("launch_product_query"), replyURL, resultDurationMS);
}

}
}

Expand All @@ -712,7 +739,7 @@ private void maybeSetClipboard(ResultHandler resultHandler) {
ClipboardInterface.setText(resultHandler.getDisplayContents(), this);
}
}

private void sendReplyMessage(int id, Object arg, long delayMS) {
if (handler != null) {
Message message = Message.obtain(handler, id, arg);
Expand Down Expand Up @@ -768,8 +795,10 @@ public void restartPreviewAfterDelay(long delayMS) {

private void resetStatusView() {
resultView.setVisibility(View.GONE);
statusView.setText(RHelper.getString("msg_default_status"));
statusView.setVisibility(View.VISIBLE);
if (showInfoText) {
statusView.setText(RHelper.getString("msg_default_status"));
statusView.setVisibility(View.VISIBLE);
}
viewfinderView.setVisibility(View.VISIBLE);
lastResult = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.Collection;
import java.util.Map;
import ti.barcode.RHelper;
import ti.barcode.BarcodeModule;

/**
* This class handles all the messaging which comprises the state machine for capture.
Expand Down Expand Up @@ -92,18 +93,32 @@ public void handleMessage(Message message) {
// Mutable copy:
barcode = barcode.copy(Bitmap.Config.ARGB_8888, true);
}
scaleFactor = bundle.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
scaleFactor = bundle.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
}
activity.handleDecode((Result) message.obj, barcode, scaleFactor);

} else if(message.what==RHelper.getId("decode_failed")){
// We're decoding as fast as possible, so when one decode fails, start another.
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(), RHelper.getId("decode"));
} else if (message.what== RHelper.getId("return_scan_result")) {
activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
activity.finish();
} else if (message.what==RHelper.getId("launch_product_query")){
} else if (message.what == RHelper.getId("return_scan_result")) {
Log.d(TAG, "Got return scan result message");
Intent msgObj = (Intent) message.obj;
if (activity.doKeepOpen()) {
String scanResultFormat = msgObj.getStringExtra(Intents.Scan.RESULT_FORMAT);
String scanResult = msgObj.getStringExtra(Intents.Scan.RESULT);
BarcodeModule barcodeModule = BarcodeModule.getInstance();
if (barcodeModule != null) {
barcodeModule.processResult(scanResultFormat, scanResult, Activity.RESULT_OK);
} else {
Log.e(TAG, "Unable to find an instance of the barcode module!");
}
restartPreviewAndDecode();
} else {
activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
activity.finish();
}
} else if (message.what==RHelper.getId("launch_product_query")){
String url = (String) message.obj;

Intent intent = new Intent(Intent.ACTION_VIEW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public void handleMessage(Message message) {
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
if (width < height) {
// portrait
byte[] rotatedData = new byte[data.length];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++)
rotatedData[y * width + width - x - 1] = data[y + x * height];
}
data = rotatedData;
}
Result rawResult = null;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
if (source != null) {
Expand Down
Loading

0 comments on commit 004894b

Please sign in to comment.