mirror of
https://bitbucket.org/HeshamTB/barcodescanner2.git
synced 2024-11-22 00:32:16 +01:00
new activity
This commit is contained in:
parent
096a05cb1d
commit
570cba2ca6
Binary file not shown.
@ -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"
|
||||
@ -19,11 +27,13 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".infoActivity">
|
||||
<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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
9
app/src/main/res/layout/activity_info.xml
Normal file
9
app/src/main/res/layout/activity_info.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?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">
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -41,4 +41,24 @@
|
||||
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,7 @@
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="scan">Scan</string>
|
||||
<string name="TextViewLabel">KAU.IE201.TEAM3</string>
|
||||
<string name="version">0.2</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user