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