From af53ba6c86804a5645f96afd362e6634682ec21e Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 23 Jan 2024 05:43:40 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=83=BC=E3=83=9F=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0,=20=E4=BD=BF=E3=81=88=E3=81=AA=E3=81=84?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E9=9D=9E=E8=A1=A8=E7=A4=BA=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/MainActivity.java | 17 ++++++++++++++ .../scanner/ScannerManagerActivity.java | 23 +++++++++++++++---- .../main/res/menu/scanner_result_toolbar.xml | 10 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/one/nem/lacerta/MainActivity.java b/app/src/main/java/one/nem/lacerta/MainActivity.java index f74b20a7..d7fac694 100644 --- a/app/src/main/java/one/nem/lacerta/MainActivity.java +++ b/app/src/main/java/one/nem/lacerta/MainActivity.java @@ -1,5 +1,6 @@ package one.nem.lacerta; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; @@ -11,6 +12,7 @@ import androidx.navigation.fragment.NavHostFragment; import androidx.navigation.ui.NavigationUI; import android.content.Intent; +import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Bundle; import android.util.Log; @@ -85,6 +87,21 @@ public class MainActivity extends AppCompatActivity implements FragmentNavigatio }); } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == 1) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show(); + Toast.makeText(this, "カメラの権限は必須です.", Toast.LENGTH_LONG).show(); + finish(); // Exit app + } + } + } + private void initializeApp() { Log.d("Init", "Initializing app"); // Set feature switch override to default value diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java index dcfc89fa..80cf6ae5 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java @@ -1,6 +1,8 @@ package one.nem.lacerta.component.scanner; +import android.Manifest; import android.app.ProgressDialog; +import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; @@ -11,6 +13,8 @@ import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; @@ -92,6 +96,14 @@ public class ScannerManagerActivity extends AppCompatActivity { return insets; }); + + + if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) + != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1); // TODO-rca: リクエストコードを定数にする + } + + MaterialToolbar toolbar = findViewById(R.id.top_toolbar); setSupportActionBar(toolbar); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); @@ -116,11 +128,12 @@ public class ScannerManagerActivity extends AppCompatActivity { Toast.makeText(this, "保存処理", Toast.LENGTH_SHORT).show(); saveNewDocument(); return true; - } else if (item.getItemId() == R.id.action_insert_exist) { - // 既存ドキュメントに挿入 - Toast.makeText(this, "Work in progress", Toast.LENGTH_SHORT).show(); - insertToExistDocument(); - return true; +// } +// else if (item.getItemId() == R.id.action_insert_exist) { +// // 既存ドキュメントに挿入 +// Toast.makeText(this, "Work in progress", Toast.LENGTH_SHORT).show(); +// insertToExistDocument(); +// return true; } else if (item.getItemId() == android.R.id.home) { finish(); return true; diff --git a/component/scanner/src/main/res/menu/scanner_result_toolbar.xml b/component/scanner/src/main/res/menu/scanner_result_toolbar.xml index 3321aadc..dc815d7b 100644 --- a/component/scanner/src/main/res/menu/scanner_result_toolbar.xml +++ b/component/scanner/src/main/res/menu/scanner_result_toolbar.xml @@ -6,9 +6,9 @@ android:icon="@drawable/save_24px" android:title="Save" app:showAsAction="ifRoom"/> - + + + + + \ No newline at end of file