mirror of
https://bitbucket.org/HeshamTB/barcodescanner2.git
synced 2024-11-05 11:02:14 +01:00
Merge branch 'test-branch'
This commit is contained in:
commit
dd3f8dfef9
Binary file not shown.
@ -7,7 +7,7 @@ android {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 16
|
||||
versionCode 1
|
||||
versionName '0.2'
|
||||
versionName '0.3'
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
@ -2,6 +2,14 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="team3.kau.ie201.barcodescanner2">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@ -16,14 +24,17 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".infoActivity">
|
||||
android:parentActivityName=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.FLASHLIGHT"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
</manifest>
|
@ -1,141 +0,0 @@
|
||||
package team3.kau.ie201.barcodescanner2;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.hardware.camera2.*;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Size;
|
||||
import android.view.Surface;
|
||||
import android.widget.Toast;
|
||||
import java.util.*;
|
||||
|
||||
@TargetApi(23)
|
||||
public class FlashLightUtilForL {
|
||||
private CameraCaptureSession mSession;
|
||||
private CaptureRequest.Builder mBuilder;
|
||||
private CameraDevice mCameraDevice;
|
||||
private CameraManager mCameraManager;
|
||||
|
||||
public FlashLightUtilForL(Context context) {
|
||||
try {
|
||||
mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
|
||||
//here to judge if flash is available
|
||||
CameraCharacteristics cameraCharacteristics = mCameraManager.getCameraCharacteristics("0");
|
||||
boolean flashAvailable = cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
|
||||
if (flashAvailable) {
|
||||
try {mCameraManager.openCamera("0", new MyCameraDeviceStateCallback(), null);}
|
||||
catch (SecurityException e){e.printStackTrace();}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
//todo: throw Exception
|
||||
}
|
||||
//mCameraManager.openCamera("0", new MyCameraDeviceStateCallback(), null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
class MyCameraDeviceStateCallback extends CameraDevice.StateCallback {
|
||||
|
||||
@Override
|
||||
public void onOpened(CameraDevice camera) {
|
||||
mCameraDevice = camera;
|
||||
//get builder
|
||||
try {
|
||||
mBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL);
|
||||
//flash on, default is on
|
||||
mBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
|
||||
mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
|
||||
List<Surface> list = new ArrayList<Surface>();
|
||||
SurfaceTexture mSurfaceTexture = new SurfaceTexture(1);
|
||||
Size size = getSmallestSize(mCameraDevice.getId());
|
||||
mSurfaceTexture.setDefaultBufferSize(size.getWidth(), size.getHeight());
|
||||
Surface mSurface = new Surface(mSurfaceTexture);
|
||||
list.add(mSurface);
|
||||
mBuilder.addTarget(mSurface);
|
||||
camera.createCaptureSession(list, new MyCameraCaptureSessionStateCallback(), null);
|
||||
} catch (CameraAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected(CameraDevice camera) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(CameraDevice camera, int error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Size getSmallestSize(String cameraId) throws CameraAccessException {
|
||||
Size[] outputSizes = mCameraManager.getCameraCharacteristics(cameraId)
|
||||
.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
|
||||
.getOutputSizes(SurfaceTexture.class);
|
||||
if (outputSizes == null || outputSizes.length == 0) {
|
||||
throw new IllegalStateException(
|
||||
"Camera " + cameraId + "doesn't support any outputSize.");
|
||||
}
|
||||
Size chosen = outputSizes[0];
|
||||
for (Size s : outputSizes) {
|
||||
if (chosen.getWidth() >= s.getWidth() && chosen.getHeight() >= s.getHeight()) {
|
||||
chosen = s;
|
||||
}
|
||||
}
|
||||
return chosen;
|
||||
}
|
||||
|
||||
/**
|
||||
* session callback
|
||||
*/
|
||||
class MyCameraCaptureSessionStateCallback extends CameraCaptureSession.StateCallback {
|
||||
|
||||
@Override
|
||||
public void onConfigured(CameraCaptureSession session) {
|
||||
mSession = session;
|
||||
try {
|
||||
mSession.setRepeatingRequest(mBuilder.build(), null, null);
|
||||
} catch (CameraAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigureFailed(CameraCaptureSession session) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void turnOnFlashLight() {
|
||||
try {
|
||||
mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
|
||||
mSession.setRepeatingRequest(mBuilder.build(), null, null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void turnOffFlashLight() {
|
||||
try {
|
||||
mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
|
||||
mSession.setRepeatingRequest(mBuilder.build(), null, null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void close() {
|
||||
if (mCameraDevice == null || mSession == null) {
|
||||
return;
|
||||
}
|
||||
mSession.close();
|
||||
mCameraDevice.close();
|
||||
mCameraDevice = null;
|
||||
mSession = null;
|
||||
}
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
//stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a
|
||||
|
||||
package team3.kau.ie201.barcodescanner2;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.DataSource;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.Security;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class GMailSender extends javax.mail.Authenticator {
|
||||
private String mailhost = "smtp.gmail.com";
|
||||
private String user;
|
||||
private String password;
|
||||
private Session session;
|
||||
|
||||
static {
|
||||
//Security.addProvider(new com.provider.JSSEProvider());//////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
public GMailSender(String user, String password) {
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("mail.transport.protocol", "smtp");
|
||||
props.setProperty("mail.host", mailhost);
|
||||
props.put("mail.smtp.auth", "true");
|
||||
props.put("mail.smtp.port", "465");
|
||||
props.put("mail.smtp.socketFactory.port", "465");
|
||||
props.put("mail.smtp.socketFactory.class",
|
||||
"javax.net.ssl.SSLSocketFactory");
|
||||
props.put("mail.smtp.socketFactory.fallback", "false");
|
||||
props.setProperty("mail.smtp.quitwait", "false");
|
||||
|
||||
session = Session.getDefaultInstance(props, this);
|
||||
}
|
||||
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(user, password);
|
||||
}
|
||||
|
||||
public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {
|
||||
try{
|
||||
MimeMessage message = new MimeMessage(session);
|
||||
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
|
||||
message.setSender(new InternetAddress(sender));
|
||||
message.setSubject(subject);
|
||||
message.setDataHandler(handler);
|
||||
if (recipients.indexOf(',') > 0)
|
||||
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));
|
||||
else
|
||||
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
|
||||
Transport.send(message);
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class ByteArrayDataSource implements DataSource {
|
||||
private byte[] data;
|
||||
private String type;
|
||||
|
||||
public ByteArrayDataSource(byte[] data, String type) {
|
||||
super();
|
||||
this.data = data;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ByteArrayDataSource(byte[] data) {
|
||||
super();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
if (type == null)
|
||||
return "application/octet-stream";
|
||||
else
|
||||
return type;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayInputStream(data);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "ByteArrayDataSource";
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
throw new IOException("Not Supported");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Alexander Y. Kleymenov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package team3.kau.ie201.barcodescanner2;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.Provider;
|
||||
|
||||
public class JSSEProvider extends Provider {
|
||||
|
||||
public JSSEProvider() {
|
||||
super("HarmonyJSSE", 1.0, "Harmony JSSE Provider");
|
||||
AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
put("SSLContext.TLS",
|
||||
"org.apache.harmony.xnet.provider.jsse.SSLContextImpl");
|
||||
put("Alg.Alias.SSLContext.TLSv1", "TLS");
|
||||
put("KeyManagerFactory.X509",
|
||||
"org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl");
|
||||
put("TrustManagerFactory.X509",
|
||||
"org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ import android.content.Context;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
|
||||
|
||||
import com.google.zxing.integration.android.IntentResult;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
|
||||
@ -33,6 +34,7 @@ import com.google.zxing.integration.android.IntentIntegrator;
|
||||
public class MainActivity extends AppCompatActivity implements OnClickListener {
|
||||
|
||||
private Button button;
|
||||
private Button infoButton;
|
||||
boolean passed1, passed2 = false;
|
||||
|
||||
|
||||
@ -54,6 +56,8 @@ public class MainActivity extends AppCompatActivity implements OnClickListener {
|
||||
});
|
||||
button = (Button)findViewById(R.id.button);//
|
||||
button.setOnClickListener(this);//
|
||||
infoButton = findViewById(R.id.infoButton);
|
||||
infoButton.setOnClickListener(this);
|
||||
|
||||
|
||||
}
|
||||
@ -87,7 +91,11 @@ public class MainActivity extends AppCompatActivity implements OnClickListener {
|
||||
//start barcode scan cam 1,2
|
||||
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
|
||||
scanIntegrator.initiateScan(0);
|
||||
}
|
||||
|
||||
if (v.getId() == R.id.infoButton){
|
||||
Intent intent = new Intent(this , infoActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
||||
@ -98,7 +106,6 @@ public class MainActivity extends AppCompatActivity implements OnClickListener {
|
||||
try {
|
||||
//get scan result
|
||||
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
|
||||
|
||||
// if not empty
|
||||
if (scanningResult != null) {
|
||||
String result = scanningResult.getContents();
|
||||
@ -113,7 +120,6 @@ public class MainActivity extends AppCompatActivity implements OnClickListener {
|
||||
Toast toast = Toast.makeText(getApplicationContext(), "Key 1 Accepted", Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
passed1 = true;
|
||||
|
||||
//take shot of barcode 2
|
||||
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
|
||||
scanIntegrator.initiateScan(0);
|
||||
@ -140,25 +146,23 @@ public class MainActivity extends AppCompatActivity implements OnClickListener {
|
||||
passed1 = false;
|
||||
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
|
||||
scanIntegrator.initiateScan(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
Toast toast = Toast.makeText(getApplicationContext(), "Key not accepted", Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
passed1 = false;
|
||||
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
|
||||
scanIntegrator.initiateScan(0);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
Toast toast = Toast.makeText(getApplicationContext(),
|
||||
"No scan data received!", Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e){
|
||||
|
@ -0,0 +1,13 @@
|
||||
package team3.kau.ie201.barcodescanner2;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class infoActivity extends AppCompatActivity {
|
||||
//TODO: make it work with button
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_info);
|
||||
}
|
||||
}
|
27
app/src/main/res/layout/activity_info.xml
Normal file
27
app/src/main/res/layout/activity_info.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".infoActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView3"
|
||||
android:layout_width="377dp"
|
||||
android:layout_height="212dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:fontFamily="monospace"
|
||||
android:gravity="center"
|
||||
android:text="@string/info"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -22,7 +22,25 @@
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||
app:layout_constraintVertical_bias="0.322" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/infoButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/infoButton"
|
||||
app:layout_constraintBottom_toTopOf="@+id/textView2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button"
|
||||
app:layout_constraintVertical_bias="0.151" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
@ -32,13 +50,35 @@
|
||||
android:layout_marginLeft="85dp"
|
||||
android:layout_marginRight="82dp"
|
||||
android:layout_marginStart="85dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:fontFamily="serif-monospace"
|
||||
android:text="@string/TextViewLabel"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textSize="24sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="28dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:autoText="false"
|
||||
android:text="@string/version"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat"
|
||||
android:textSize="18sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/button"
|
||||
app:layout_constraintVertical_bias="0.952" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -3,6 +3,9 @@
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="scan">Scan</string>
|
||||
<string name="TextViewLabel">KAU.IE201.TEAM3</string>
|
||||
<string name="version">0.3</string>
|
||||
<string name="infoButton">Info</string>
|
||||
<string name="info">Made by Hesham and IE200 Team 3\nInstructed by Dr. Nibras Subahi\n© 2018 KAU. All rights reserved. </string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user