diff options
author | Alexey 'Cluster' Avdyukhin <a.avdyukhin@norsi-trans.ru> | 2022-03-14 17:54:00 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <a.avdyukhin@norsi-trans.ru> | 2022-03-14 17:54:54 +0300 |
commit | 0b833acbb93d245ed19d1243b0b9d7db686868cf (patch) | |
tree | a4be7de26a50107bbe5fd4c23960bd0f244a6af5 | |
parent | b6829e4698908cb5ad655be4ba8e8c63229ef8ee (diff) |
Permissions
6 files changed, 79 insertions, 66 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c37f3aa..0612878 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,7 +7,6 @@ <uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Required for complications to receive complication data and open the provider chooser. -->
<uses-permission android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA" />
- <uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.type.watch" />
<uses-feature android:name="android.hardware.sensor.stepcounter" android:required="true" />
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java index 21c5616..6ff6197 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java @@ -45,9 +45,6 @@ public class HexWatchFace extends CanvasWatchFaceService { private static final int ENDIANNESS_BIG_ENDIAN = 1; private static final int ENDIANNESS_FAKE_HEX = 2; - private static final int PREF_TIME_FORMAT_12 = 0; - private static final int PREF_TIME_FORMAT_24 = 1; - /** * Handler message id for updating the time periodically in interactive mode. */ @@ -211,7 +208,8 @@ public class HexWatchFace extends CanvasWatchFaceService { drawNumber(canvas, todaySteps, ENDIANNESS_FAKE_HEX, 3, HexNumbers.COLORS_CYAN, -2, 1); drawNumber(canvas, mCalendar.get( - prefs.getInt(res.getString(R.string.pref_time_format),PREF_TIME_FORMAT_24) == PREF_TIME_FORMAT_12 + prefs.getInt(res.getString(R.string.pref_time_format), SettingsActivity.PREF_TIME_FORMAT_24) + == SettingsActivity.PREF_TIME_FORMAT_12 ? Calendar.HOUR : Calendar.HOUR_OF_DAY ), ENDIANNESS_FAKE_HEX, 1, HexNumbers.COLORS_WHITE, 0, 0); diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java index f5682e2..2932d6c 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java @@ -1,29 +1,62 @@ package com.clusterrr.hexeditorwatchface; +import static com.clusterrr.hexeditorwatchface.HexWatchFace.TAG; + import android.Manifest; import android.app.Activity; -import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.os.Bundle; import android.util.Log; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import androidx.annotation.NonNull; -import androidx.appcompat.app.ActionBar; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.ActivityCompat; -import androidx.preference.PreferenceFragmentCompat; -import androidx.recyclerview.widget.RecyclerView; +import androidx.core.content.ContextCompat; import androidx.wear.widget.WearableLinearLayoutManager; import androidx.wear.widget.WearableRecyclerView; public class SettingsActivity extends AppCompatActivity { + public static final int PREF_KEY_TIME_FORMAT = 0; + public static final int PREF_KEY_TIME_SYSTEM = 1; + public static final int PREF_KEY_DATE = 2; + public static final int PREF_KEY_DAY_OF_THE_WEEK = 3; + public static final int PREF_KEY_HEART_RATE= 4; + public static final int PREF_KEY_STEPS = 5; + public static final int PREF_KEY_BATTERY = 6; + public static final int PREF_KEY_ENDIANNESS = 7; + public static final int PREF_KEY_VIGNETTING = 8; + + public static final int PREF_VALUE_NOT_SHOW = 0; + + public static final int PREF_TIME_FORMAT_12 = 0; + public static final int PREF_TIME_FORMAT_24 = 1; + private Setting[] mSettings; - SettingsMenuAdapter settingsMenuAdapter; + SettingsMenuAdapter mSettingsMenuAdapter; + + private ActivityResultLauncher<String> requestPermissionLauncherBody + = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { + if (isGranted) { + Log.i(TAG, "BODY_SENSORS granted"); + } else { + // Rollback + Log.i(TAG, "BODY_SENSORS not granted"); + mSettings[PREF_KEY_HEART_RATE].setValue(PREF_VALUE_NOT_SHOW); + mSettingsMenuAdapter.updateHolder(PREF_KEY_HEART_RATE); + } + }); + private ActivityResultLauncher<String> requestPermissionActivity + = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { + if (isGranted) { + Log.d(TAG, "ACTIVITY_RECOGNITION granted"); + } else { + Log.d(TAG, "ACTIVITY_RECOGNITION not granted"); + mSettings[PREF_KEY_STEPS].setValue(PREF_VALUE_NOT_SHOW); + mSettingsMenuAdapter.updateHolder(PREF_KEY_STEPS); + } + }); @Override protected void onCreate(Bundle savedInstanceState) { @@ -51,8 +84,8 @@ public class SettingsActivity extends AppCompatActivity { new CustomScrollingLayoutCallback(); recyclerView.setLayoutManager( new WearableLinearLayoutManager(this, customScrollingLayoutCallback)); - settingsMenuAdapter = new SettingsMenuAdapter(this, mSettings); - recyclerView.setAdapter(settingsMenuAdapter); + mSettingsMenuAdapter = new SettingsMenuAdapter(this, mSettings); + recyclerView.setAdapter(mSettingsMenuAdapter); } @Override @@ -63,8 +96,30 @@ public class SettingsActivity extends AppCompatActivity { int setting = data.getIntExtra("setting", -1); int selected = data.getIntExtra("selected", -1); Log.d(HexWatchFace.TAG, "Setting " + setting + " set to " + selected); + + switch (setting) { + case PREF_KEY_HEART_RATE: + if (selected != PREF_VALUE_NOT_SHOW) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.BODY_SENSORS) + != PackageManager.PERMISSION_GRANTED) { + Log.d(TAG, "BODY_SENSORS request required"); + requestPermissionLauncherBody.launch(Manifest.permission.BODY_SENSORS); + } + } + break; + case PREF_KEY_STEPS: + if (selected != PREF_VALUE_NOT_SHOW) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) + != PackageManager.PERMISSION_GRANTED) { + Log.d(TAG, "ACTIVITY_RECOGNITION request required"); + requestPermissionLauncherBody.launch(Manifest.permission.ACTIVITY_RECOGNITION); + } + } + break; + } + mSettings[setting].setValue(selected); - settingsMenuAdapter.updateHolder(setting); + mSettingsMenuAdapter.updateHolder(setting); } } diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java index 9fbedfc..c113a54 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java @@ -5,6 +5,7 @@ import static com.clusterrr.hexeditorwatchface.HexWatchFace.TAG; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.Resources;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -13,8 +14,6 @@ import android.widget.LinearLayout; import android.widget.RadioButton;
import android.widget.TextView;
-import androidx.activity.result.ActivityResultLauncher;
-import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
@@ -22,10 +21,6 @@ import androidx.recyclerview.widget.RecyclerView; public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapter.RecyclerViewHolder> {
private Setting[] mSettings;
private AppCompatActivity mContext;
- private ActivityResultLauncher<String> requestPermissionLauncherLocation;
- private ActivityResultLauncher<String> requestPermissionLauncherBody;
- private ActivityResultLauncher<String> requestPermissionLauncherSteps;
- private View.OnClickListener onClickListener;
private SettingsMenuAdapter.RecyclerViewHolder[] mHolders;
public SettingsMenuAdapter(AppCompatActivity context, Setting[] settings) {
@@ -35,52 +30,12 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte // this.dataSource = dataArgs;
// this.callback = callback;
- requestPermissionLauncherLocation = context.registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
- if (isGranted) {
- // Permission is granted. Continue the action or workflow in your
- // app.
- Log.d(TAG, "ACCESS_BACKGROUND_LOCATION granted");
- } else {
- // Explain to the user that the feature is unavailable because the
- // features requires a permission that the user has denied. At the
- // same time, respect the user's decision. Don't link to system
- // settings in an effort to convince the user to change their
- // decision.
- Log.d(TAG, "ACCESS_BACKGROUND_LOCATION not granted");
- }
- });
- requestPermissionLauncherBody = context.registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
- if (isGranted) {
- // Permission is granted. Continue the action or workflow in your
- // app.
- Log.d(TAG, "BODY_SENSORS granted");
- } else {
- // Explain to the user that the feature is unavailable because the
- // features requires a permission that the user has denied. At the
- // same time, respect the user's decision. Don't link to system
- // settings in an effort to convince the user to change their
- // decision.
- Log.d(TAG, "BODY_SENSORS not granted");
- }
- });
- requestPermissionLauncherSteps = context.registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
- if (isGranted) {
- // Permission is granted. Continue the action or workflow in your
- // app.
- Log.d(TAG, "ACTIVITY_RECOGNITION granted");
- } else {
- // Explain to the user that the feature is unavailable because the
- // features requires a permission that the user has denied. At the
- // same time, respect the user's decision. Don't link to system
- // settings in an effort to convince the user to change their
- // decision.
- Log.d(TAG, "ACTIVITY_RECOGNITION not granted");
- }
- });
}
public void updateHolder(int pos)
{
+ SharedPreferences prefs = mContext.getSharedPreferences(mContext.getString(R.string.app_name), Context.MODE_PRIVATE);
+ Resources res = mContext.getResources();
SettingsMenuAdapter.RecyclerViewHolder holder = mHolders[pos];
holder.menuItemSettingKey.setText(mSettings[pos].getName());
holder.menuItemSettingValue.setText(mSettings[pos].getValueName());
@@ -91,6 +46,10 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte intent.putExtra("selected", mSettings[pos].getValue());
mContext.startActivityForResult(intent, 0);
});
+ // Disable vignetting for rectangular screens
+ holder.menuContainer.setEnabled(res.getBoolean(R.bool.is_round) || pos != SettingsActivity.PREF_KEY_VIGNETTING);
+ holder.menuItemSettingKey.setEnabled(res.getBoolean(R.bool.is_round) || pos != SettingsActivity.PREF_KEY_VIGNETTING);
+ holder.menuItemSettingValue.setEnabled(res.getBoolean(R.bool.is_round) || pos != SettingsActivity.PREF_KEY_VIGNETTING);
}
@NonNull
diff --git a/app/src/main/res/values-notround/values-notround.xml b/app/src/main/res/values-notround/values-notround.xml index 414e281..df0a9f1 100644 --- a/app/src/main/res/values-notround/values-notround.xml +++ b/app/src/main/res/values-notround/values-notround.xml @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + <bool name="is_round">false</bool> <integer name="default_vignetting">0</integer> </resources>
\ No newline at end of file diff --git a/app/src/main/res/values-round/values-round.xml b/app/src/main/res/values-round/values-round.xml index 4162b1d..a05ba28 100644 --- a/app/src/main/res/values-round/values-round.xml +++ b/app/src/main/res/values-round/values-round.xml @@ -1,4 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + <bool name="is_round">true</bool> <integer name="default_vignetting">1</integer> </resources>
\ No newline at end of file |