mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-22 16:03:15 +00:00
パーミッションチェックを追加, 使えない機能を非表示に
This commit is contained in:
parent
64d7a53616
commit
af53ba6c86
|
@ -1,5 +1,6 @@
|
||||||
package one.nem.lacerta;
|
package one.nem.lacerta;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
@ -11,6 +12,7 @@ import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
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() {
|
private void initializeApp() {
|
||||||
Log.d("Init", "Initializing app");
|
Log.d("Init", "Initializing app");
|
||||||
// Set feature switch override to default value
|
// Set feature switch override to default value
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package one.nem.lacerta.component.scanner;
|
package one.nem.lacerta.component.scanner;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -11,6 +13,8 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.EdgeToEdge;
|
import androidx.activity.EdgeToEdge;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.graphics.Insets;
|
import androidx.core.graphics.Insets;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.core.view.WindowInsetsCompat;
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
@ -92,6 +96,14 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
return insets;
|
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);
|
MaterialToolbar toolbar = findViewById(R.id.top_toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||||
|
@ -116,11 +128,12 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
Toast.makeText(this, "保存処理", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "保存処理", Toast.LENGTH_SHORT).show();
|
||||||
saveNewDocument();
|
saveNewDocument();
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.action_insert_exist) {
|
// }
|
||||||
// 既存ドキュメントに挿入
|
// else if (item.getItemId() == R.id.action_insert_exist) {
|
||||||
Toast.makeText(this, "Work in progress", Toast.LENGTH_SHORT).show();
|
// // 既存ドキュメントに挿入
|
||||||
insertToExistDocument();
|
// Toast.makeText(this, "Work in progress", Toast.LENGTH_SHORT).show();
|
||||||
return true;
|
// insertToExistDocument();
|
||||||
|
// return true;
|
||||||
} else if (item.getItemId() == android.R.id.home) {
|
} else if (item.getItemId() == android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
android:icon="@drawable/save_24px"
|
android:icon="@drawable/save_24px"
|
||||||
android:title="Save"
|
android:title="Save"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom"/>
|
||||||
<item
|
<!-- <item-->
|
||||||
android:id="@+id/action_insert_exist"
|
<!-- android:id="@+id/action_insert_exist"-->
|
||||||
android:icon="@drawable/ic_baseline_add_24"
|
<!-- android:icon="@drawable/description_24px"-->
|
||||||
android:title="Save"
|
<!-- android:title="Insert"-->
|
||||||
app:showAsAction="ifRoom"/>
|
<!-- app:showAsAction="ifRoom"/>-->
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue
Block a user