From 570cba2ca634c78477faca55add718d9d73faa34 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 1 Jul 2018 01:10:45 +0300 Subject: [PATCH] new activity --- .idea/caches/build_file_checksums.ser | Bin 538 -> 538 bytes app/src/main/AndroidManifest.xml | 20 ++- .../barcodescanner2/FlashLightUtilForL.java | 141 ------------------ .../ie201/barcodescanner2/GMailSender.java | 108 -------------- .../ie201/barcodescanner2/JSSEProvider.java | 46 ------ .../ie201/barcodescanner2/infoActivity.java | 13 ++ app/src/main/res/layout/activity_info.xml | 9 ++ app/src/main/res/layout/content_main.xml | 20 +++ app/src/main/res/values/strings.xml | 1 + 9 files changed, 58 insertions(+), 300 deletions(-) delete mode 100644 app/src/main/java/team3/kau/ie201/barcodescanner2/FlashLightUtilForL.java delete mode 100644 app/src/main/java/team3/kau/ie201/barcodescanner2/GMailSender.java delete mode 100644 app/src/main/java/team3/kau/ie201/barcodescanner2/JSSEProvider.java create mode 100644 app/src/main/java/team3/kau/ie201/barcodescanner2/infoActivity.java create mode 100644 app/src/main/res/layout/activity_info.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 30039a603540759a967ae179059f714541dcbf0f..2f8c48ed445fbeb53a7611aea806c5eaf0645c76 100644 GIT binary patch delta 36 scmbQmGK*!xbk>xhy?yT{&iN^DP}J5rOgSb0l!E_cE4BQ}$x9ha0UP-a@&Et; delta 36 ucmV+<0NekX1eyepmjz + + + + + + + + + + + + + + + - - - - - \ No newline at end of file diff --git a/app/src/main/java/team3/kau/ie201/barcodescanner2/FlashLightUtilForL.java b/app/src/main/java/team3/kau/ie201/barcodescanner2/FlashLightUtilForL.java deleted file mode 100644 index 8a2faa6..0000000 --- a/app/src/main/java/team3/kau/ie201/barcodescanner2/FlashLightUtilForL.java +++ /dev/null @@ -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 list = new ArrayList(); - 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; - } -} diff --git a/app/src/main/java/team3/kau/ie201/barcodescanner2/GMailSender.java b/app/src/main/java/team3/kau/ie201/barcodescanner2/GMailSender.java deleted file mode 100644 index e8d7ee7..0000000 --- a/app/src/main/java/team3/kau/ie201/barcodescanner2/GMailSender.java +++ /dev/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"); - } - } -} diff --git a/app/src/main/java/team3/kau/ie201/barcodescanner2/JSSEProvider.java b/app/src/main/java/team3/kau/ie201/barcodescanner2/JSSEProvider.java deleted file mode 100644 index a0f2089..0000000 --- a/app/src/main/java/team3/kau/ie201/barcodescanner2/JSSEProvider.java +++ /dev/null @@ -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() { - 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; - } - }); - } -} - - diff --git a/app/src/main/java/team3/kau/ie201/barcodescanner2/infoActivity.java b/app/src/main/java/team3/kau/ie201/barcodescanner2/infoActivity.java new file mode 100644 index 0000000..8927af4 --- /dev/null +++ b/app/src/main/java/team3/kau/ie201/barcodescanner2/infoActivity.java @@ -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); + } +} diff --git a/app/src/main/res/layout/activity_info.xml b/app/src/main/res/layout/activity_info.xml new file mode 100644 index 0000000..edfe8e0 --- /dev/null +++ b/app/src/main/res/layout/activity_info.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index abb32a7..3c7ca19 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -41,4 +41,24 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c50d41c..a87007e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,6 +3,7 @@ Settings Scan KAU.IE201.TEAM3 + 0.2