Commit b486aa46 authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Update camera button behavior

parent d1aaf3d0
......@@ -38,6 +38,7 @@ import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.ArrayList;
......@@ -81,7 +82,7 @@ public class MainActivity extends AppCompatActivity {
/**
* The main layout where all happens
*/
private LinearLayout m_mainLayout;
private RelativeLayout m_mainLayout;
@Override
......@@ -128,6 +129,7 @@ public class MainActivity extends AppCompatActivity {
public void onClick(View view) {
Snackbar.make(view, "Should open QR code reader", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
startDetection();
}
});
......@@ -192,7 +194,7 @@ public class MainActivity extends AppCompatActivity {
PackageManager manager = getPackageManager();
m_mainLayout = (LinearLayout) findViewById(R.id.main_layout);
m_mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
......@@ -301,6 +303,18 @@ public class MainActivity extends AppCompatActivity {
}
}
private void requestPhotoPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String requiredPermission = Manifest.permission.CAMERA;
// If the user previously denied this permission then show a message explaining why
// this permission is needed
if (checkCallingOrSelfPermission(requiredPermission) == PackageManager.PERMISSION_DENIED) {
requestPermissions(new String[]{requiredPermission}, 101);
}
}
}
/**
* Unregisters the MainActivity as a listener of the current QRFile if necessary
......@@ -317,6 +331,7 @@ public class MainActivity extends AppCompatActivity {
}
private void setUpDetector() {
requestPhotoPermission();
/*
The barcode detector
*/
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<RelativeLayout
android:id="@+id/main_layout"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
......@@ -9,6 +9,16 @@
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/button_layout"
android:orientation="vertical"
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=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
......@@ -58,13 +68,12 @@
app:rippleColor="#FFFFFF"
app:srcCompat="@android:drawable/ic_media_play" />
</LinearLayout>
<SurfaceView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_below="@+id/content_layout"
android:layout_weight=".25"
android:visibility="invisible" />
</LinearLayout>
\ No newline at end of file
</RelativeLayout>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment