Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified example with cleaner functionality. Added flashlight button.… #65

Merged
merged 2 commits into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void setDisplayOrientation(int degrees) {
}

public void setAutofocusInterval(long autofocusIntervalInMs) {
this.autofocusIntervalInMs = autofocusIntervalInMs;
if (autoFocusManager != null) {
this.autofocusIntervalInMs = autofocusIntervalInMs;
autoFocusManager.setAutofocusInterval(autofocusIntervalInMs);
}
}
Expand Down
1 change: 0 additions & 1 deletion samples/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<activity
android:name="com.example.qr_readerexample.DecoderActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@
import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.dlazaro66.qrcodereaderview.QRCodeReaderView;
import com.dlazaro66.qrcodereaderview.QRCodeReaderView.OnQRCodeReadListener;

public class DecoderActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, OnQRCodeReadListener {
public class DecoderActivity extends AppCompatActivity
implements ActivityCompat.OnRequestPermissionsResultCallback, OnQRCodeReadListener {

private static final int MY_PERMISSION_REQUEST_CAMERA = 0;

private ViewGroup mainLayout;

@Nullable private TextView myTextView;
@Nullable private QRCodeReaderView myDecoderView;
private TextView resultTextView;
private QRCodeReaderView qrCodeReaderView;
private CheckBox flashlightCheckBox;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -46,16 +45,16 @@ public class DecoderActivity extends AppCompatActivity implements ActivityCompat
@Override protected void onResume() {
super.onResume();

if (myDecoderView != null) {
myDecoderView.startCamera();
if (qrCodeReaderView != null) {
qrCodeReaderView.startCamera();
}
}

@Override protected void onPause() {
super.onPause();

if (myDecoderView != null) {
myDecoderView.stopCamera();
if (qrCodeReaderView != null) {
qrCodeReaderView.stopCamera();
}
}

Expand All @@ -78,7 +77,7 @@ public class DecoderActivity extends AppCompatActivity implements ActivityCompat
// "text" : the text encoded in QR
// "points" : points where QR control points are placed
@Override public void onQRCodeRead(String text, PointF[] points) {
myTextView.setText(text);
resultTextView.setText(text);
}

private void requestCameraPermission() {
Expand All @@ -101,22 +100,17 @@ private void requestCameraPermission() {
private void initQRCodeReaderView() {
View content = getLayoutInflater().inflate(R.layout.content_decoder, mainLayout, true);

myDecoderView = (QRCodeReaderView) content.findViewById(R.id.qrdecoderview);
myDecoderView.setOnQRCodeReadListener(this);
myDecoderView.setAutofocusInterval(1000L);
myDecoderView.startCamera();

myTextView = (TextView) content.findViewById(R.id.exampleTextView);

ImageView lineImage = (ImageView) content.findViewById(R.id.red_line_image);

TranslateAnimation mAnimation =
new TranslateAnimation(TranslateAnimation.ABSOLUTE, 0f, TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.RELATIVE_TO_PARENT, 0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.5f);
mAnimation.setDuration(1000);
mAnimation.setRepeatCount(-1);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setInterpolator(new LinearInterpolator());
lineImage.setAnimation(mAnimation);
qrCodeReaderView = (QRCodeReaderView) content.findViewById(R.id.qrdecoderview);
resultTextView = (TextView) content.findViewById(R.id.result_text_view);
flashlightCheckBox = (CheckBox) content.findViewById(R.id.flashlight_checkbox);

qrCodeReaderView.setAutofocusInterval(2000L);
qrCodeReaderView.setOnQRCodeReadListener(this);
flashlightCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
qrCodeReaderView.setTorchEnabled(isChecked);
}
});
qrCodeReaderView.startCamera();
}
}
}
6 changes: 3 additions & 3 deletions samples/src/main/res/layout/activity_decoder.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DecoderActivity"
/>
>

</FrameLayout>
31 changes: 21 additions & 10 deletions samples/src/main/res/layout/content_decoder.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DecoderActivity"
>

<com.dlazaro66.qrcodereaderview.QRCodeReaderView
android:id="@+id/qrdecoderview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>

<TextView
android:id="@+id/exampleTextView"
android:layout_width="wrap_content"
android:background="#55000000"
android:id="@+id/result_text_view"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:padding="16dp"
android:textSize="14sp"
android:textColor="#ffffff"
/>

<ImageView
android:id="@+id/red_line_image"
<CheckBox
android:background="#99000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/exampleTextView"
android:src="@drawable/red_line"
android:text="flashlight"
android:layout_alignParentBottom="true"
android:textSize="14sp"
android:padding="16dp"
android:textColor="#ffffff"
android:id="@+id/flashlight_checkbox"
android:checked="false"
/>

</RelativeLayout>