Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/wear-os-hex-editor-watchface.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-03-15 11:14:23 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-03-15 11:14:23 +0300
commitd07926821c7ced91dcc4f0cb6efa472fffac4896 (patch)
treed88f0e35050f5e6d710dbd9cc9289c4e0b66cf42
parent9ffaddd85880a8bfa1ab087d30a5d23b99bae561 (diff)
Fixes and clean up
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/CustomScrollingLayoutCallback.java4
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java15
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/HexNumbers.java6
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java21
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/Setting.java12
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java10
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java18
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java1
-rw-r--r--app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java17
9 files changed, 37 insertions, 67 deletions
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/CustomScrollingLayoutCallback.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/CustomScrollingLayoutCallback.java
index 9ac0fce..48e7edf 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/CustomScrollingLayoutCallback.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/CustomScrollingLayoutCallback.java
@@ -11,8 +11,6 @@ public class CustomScrollingLayoutCallback extends WearableLinearLayoutManager.L
*/
private static final float MAX_ICON_PROGRESS = 0.65f;
- private float progressToCenter;
-
@Override
public void onLayoutFinished(View child, RecyclerView parent) {
@@ -21,7 +19,7 @@ public class CustomScrollingLayoutCallback extends WearableLinearLayoutManager.L
float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
// Normalize for center
- progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
+ float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
// Adjust to the maximum scale
progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS);
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java
index e45ca2a..39f986c 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java
@@ -1,22 +1,7 @@
package com.clusterrr.hexeditorwatchface;
-import static com.clusterrr.hexeditorwatchface.HexWatchFace.TAG;
-
-import android.Manifest;
-import android.app.Activity;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
import android.os.Bundle;
-import android.util.Log;
-
-import androidx.activity.result.ActivityResultLauncher;
-import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.content.ContextCompat;
-import androidx.wear.widget.WearableLinearLayoutManager;
-import androidx.wear.widget.WearableRecyclerView;
public class ExplanationActivity extends AppCompatActivity {
@Override
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexNumbers.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexNumbers.java
index cb92f7f..c2d434f 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexNumbers.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexNumbers.java
@@ -9,9 +9,9 @@ public class HexNumbers {
public static final byte COLORS_WHITE = 1;
public static final byte COLORS_DARK = 2;
- private Bitmap[] mDCyan;
- private Bitmap[] mDWhite;
- private Bitmap[] mDDark;
+ private final Bitmap[] mDCyan;
+ private final Bitmap[] mDWhite;
+ private final Bitmap[] mDDark;
public Bitmap GetNumber(int number, int numberColor) {
Bitmap[] digits;
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java
index 81b14bc..8a52516 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java
@@ -34,6 +34,7 @@ import android.view.SurfaceHolder;
import androidx.core.content.ContextCompat;
import java.lang.ref.WeakReference;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
@@ -67,6 +68,7 @@ public class HexWatchFace extends CanvasWatchFaceService {
private static class EngineHandler extends Handler {
private final WeakReference<HexWatchFace.Engine> mWeakReference;
+ @SuppressWarnings("deprecation")
public EngineHandler(HexWatchFace.Engine reference) {
mWeakReference = new WeakReference<>(reference);
}
@@ -168,9 +170,9 @@ public class HexWatchFace extends CanvasWatchFaceService {
}
}
+ @SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
public void onDraw(Canvas canvas, Rect bounds) {
- Context context = getApplicationContext();
SharedPreferences prefs = getApplicationContext().getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);
Resources res = getApplicationContext().getResources();
long now = System.currentTimeMillis();
@@ -192,7 +194,6 @@ public class HexWatchFace extends CanvasWatchFaceService {
}
}
- int todayStepStart = 0;
int todaySteps = 0;
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACTIVITY_RECOGNITION) == PackageManager.PERMISSION_GRANTED) {
if (mStepCountSensor == null) {
@@ -200,7 +201,7 @@ public class HexWatchFace extends CanvasWatchFaceService {
mSensorManager.registerListener(this, mStepCountSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
- todayStepStart = prefs.getInt(getString(R.string.pref_today_step_start), 0);
+ int todayStepStart = prefs.getInt(getString(R.string.pref_today_step_start), 0);
if (mStepCounter >= 0 && (
(mCalendar.get(Calendar.DAY_OF_MONTH) != prefs.getInt(getString(R.string.pref_steps_day), 0))
|| (mStepCounter < todayStepStart))
@@ -262,8 +263,7 @@ public class HexWatchFace extends CanvasWatchFaceService {
mBackground[i] = (int) (Math.random() * 256);
break;
case PREF_VALUE_BACKGROUND_ZEROS:
- for (int i = 0; i < mBackground.length; i++)
- mBackground[i] = 0;
+ Arrays.fill(mBackground, 0);
break;
}
prefs.edit().putBoolean(getString(R.string.pref_background_redraw), false).apply();
@@ -382,7 +382,7 @@ public class HexWatchFace extends CanvasWatchFaceService {
}
if (prefs.getInt(getString(R.string.pref_vignetting), res.getInteger(R.integer.default_vignetting))
- == SettingsActivity.PREF_VALUE_VINGETTING_ENABLED) {
+ == SettingsActivity.PREF_VALUE_VIGNETTING_ENABLED) {
canvas.drawBitmap(mVignettingBitmap,
new Rect(0, 0, mVignettingBitmap.getWidth(), mVignettingBitmap.getHeight()),
new Rect(0, 0, canvas.getWidth(), canvas.getHeight()),
@@ -404,22 +404,23 @@ public class HexWatchFace extends CanvasWatchFaceService {
switch (endianness)
{
case ENDIANNESS_BIG_ENDIAN:
- digit = (number >> i) & 0xFF;
+ digit = (number >> ((size - i - 1) * 8)) & 0xFF;
break;
case ENDIANNESS_LITTLE_ENDIAN:
- base = (int)Math.pow(256, (size - i - 1));
- digit = (number / base) % 256;
+ digit = (number >> i * 8) & 0xFF;
break;
default:
case ENDIANNESS_FAKE_HEX:
base = (int)Math.pow(100, (size - i - 1));
digit = (number / base) % 100;
digit = (digit % 10) | ((digit / 10) * 16);
+ break;
}
drawNumberAtPos(canvas, digit, numberColor, left + i, top);
}
}
+ @SuppressWarnings("IntegerDivisionInFloatingPointContext")
private void drawNumberAtPos(Canvas canvas, int number, int numberColor,
float left, float top)
{
@@ -512,7 +513,7 @@ public class HexWatchFace extends CanvasWatchFaceService {
break;
case Sensor.TYPE_STEP_COUNTER:
mStepCounter = (int)event.values[0];
- Log.d(TAG, "Steps: " + mStepCounter);
+ //Log.d(TAG, "Steps: " + mStepCounter);
break;
}
}
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/Setting.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/Setting.java
index fb3f88c..b49972a 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/Setting.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/Setting.java
@@ -3,11 +3,11 @@ package com.clusterrr.hexeditorwatchface;
import android.content.SharedPreferences;
public class Setting {
- private SharedPreferences mPrefs;
- private String mName;
- private String[] mValueNames;
- private String mKey;
- private int mDefaultValue;
+ private final SharedPreferences mPrefs;
+ private final String mName;
+ private final String[] mValueNames;
+ private final String mKey;
+ private final int mDefaultValue;
public Setting(SharedPreferences prefs, String name, String[] valueNames, String key, int defaultValue) {
mPrefs = prefs;
@@ -19,8 +19,6 @@ public class Setting {
public String getName() { return mName; }
public String[] getValueNames() { return mValueNames.clone(); }
- public String getValueName(int i) { return mValueNames[i]; }
- public int getValueCount() { return mValueNames.length; }
public String getValueName() {
try{
return mValueNames[mPrefs.getInt(mKey, mDefaultValue)];
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java
index 5687453..dee6b26 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java
@@ -62,7 +62,7 @@ public class SettingsActivity extends AppCompatActivity {
public static final int PREF_VALUE_BARS_SHOW = 1;
- public static final int PREF_VALUE_VINGETTING_ENABLED = 1;
+ public static final int PREF_VALUE_VIGNETTING_ENABLED = 1;
public static final int PREF_DEFAULT_TIME_FORMAT = PREF_TIME_FORMAT_24;
public static final int PREF_DEFAULT_TIME_SYSTEM = PREF_VALUE_TIME_DEC;
@@ -74,12 +74,12 @@ public class SettingsActivity extends AppCompatActivity {
public static final int PREF_DEFAULT_ENDIANNESS = PREF_VALUE_ENDIANNESS_LITTLE_ENDIAN;
public static final int PREF_DEFAULT_BACKGROUND = PREF_VALUE_BACKGROUND_ZEROS;
public static final int PREF_DEFAULT_BARS = PREF_VALUE_BARS_SHOW;
- //public static final int PREF_DEFAULT_VIGNETTING = PREF_VALUE_VINGETTING_ENABLED;
+ //public static final int PREF_DEFAULT_VIGNETTING = PREF_VALUE_VIGNETTING_ENABLED;
private Setting[] mSettings;
SettingsMenuAdapter mSettingsMenuAdapter;
- private ActivityResultLauncher<String> requestPermissionLauncherBody
+ private final ActivityResultLauncher<String> requestPermissionLauncherBody
= registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) {
Log.i(TAG, "BODY_SENSORS granted");
@@ -90,7 +90,7 @@ public class SettingsActivity extends AppCompatActivity {
mSettingsMenuAdapter.updateHolder(PREF_KEY_HEART_RATE);
}
});
- private ActivityResultLauncher<String> requestPermissionActivity
+ private final ActivityResultLauncher<String> requestPermissionActivity
= registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) {
Log.d(TAG, "ACTIVITY_RECOGNITION granted");
@@ -163,7 +163,7 @@ public class SettingsActivity extends AppCompatActivity {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION)
!= PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "ACTIVITY_RECOGNITION request required");
- requestPermissionLauncherBody.launch(Manifest.permission.ACTIVITY_RECOGNITION);
+ requestPermissionActivity.launch(Manifest.permission.ACTIVITY_RECOGNITION);
}
}
break;
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java
index f43c993..c953726 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java
@@ -1,6 +1,5 @@
package com.clusterrr.hexeditorwatchface;
-import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.view.LayoutInflater;
@@ -15,9 +14,9 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapter.RecyclerViewHolder> {
- private Setting[] mSettings;
- private AppCompatActivity mContext;
- private SettingsMenuAdapter.RecyclerViewHolder[] mHolders;
+ private final Setting[] mSettings;
+ private final AppCompatActivity mContext;
+ private final SettingsMenuAdapter.RecyclerViewHolder[] mHolders;
public SettingsMenuAdapter(AppCompatActivity context, Setting[] settings) {
this.mContext = context;
@@ -68,20 +67,18 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte
@Override
public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item, parent, false);
- return new RecyclerViewHolder(mContext, view);
+ return new RecyclerViewHolder(view);
}
public static class RecyclerViewHolder extends RecyclerView.ViewHolder {
- private Context mContext;
ConstraintLayout menuContainer;
TextView menuItemSettingKey;
TextView menuItemSettingValue;
TextView menuItemSettingExplanation;
RadioButton menuItemSettingRadio;
- public RecyclerViewHolder(AppCompatActivity context, View view) {
+ public RecyclerViewHolder(View view) {
super(view);
- this.mContext = context;
menuContainer = view.findViewById(R.id.settingsContainer);
menuItemSettingKey = view.findViewById(R.id.textViewSettingKey);
menuItemSettingValue = view.findViewById(R.id.textViewSettingValue);
@@ -92,9 +89,8 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte
@Override
public void onBindViewHolder(@NonNull SettingsMenuAdapter.RecyclerViewHolder holder, int position) {
- final int pos = position;
- mHolders[pos] = holder;
- updateHolder(pos);
+ mHolders[position] = holder;
+ updateHolder(position);
}
@Override
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java
index 791dd34..465fc05 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java
@@ -1,6 +1,5 @@
package com.clusterrr.hexeditorwatchface;
-import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java
index 1a52e4f..085a5a5 100644
--- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java
+++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java
@@ -1,13 +1,11 @@
package com.clusterrr.hexeditorwatchface;
import android.app.Activity;
-import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
@@ -17,38 +15,34 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
public class SettingsSubMenuAdapter extends RecyclerView.Adapter<SettingsSubMenuAdapter.RecyclerViewHolder> {
- private AppCompatActivity mContext;
+ private final AppCompatActivity mContext;
int mSetting;
- private String[] mValues;
- private int mSelected;
- private RecyclerViewHolder[] mHolders;
+ private final String[] mValues;
+ private final int mSelected;
public SettingsSubMenuAdapter(AppCompatActivity context, int setting, String[] values, int selected) {
this.mContext = context;
this.mSetting = setting;
this.mValues = values;
this.mSelected = selected;
- this.mHolders = new RecyclerViewHolder[values.length];
}
@NonNull
@Override
public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.menu_item, parent, false);
- return new RecyclerViewHolder(mContext, view);
+ return new RecyclerViewHolder(view);
}
public static class RecyclerViewHolder extends RecyclerView.ViewHolder {
- private Context mContext;
ConstraintLayout menuContainer;
TextView menuItemSettingKey;
TextView menuItemSettingValue;
TextView menuItemSettingExplanation;
RadioButton menuItemSettingRadio;
- public RecyclerViewHolder(Context context, View view) {
+ public RecyclerViewHolder(View view) {
super(view);
- this.mContext = context;
menuContainer = view.findViewById(R.id.settingsContainer);
menuItemSettingKey = view.findViewById(R.id.textViewSettingKey);
menuItemSettingValue = view.findViewById(R.id.textViewSettingValue);
@@ -60,7 +54,6 @@ public class SettingsSubMenuAdapter extends RecyclerView.Adapter<SettingsSubMenu
@Override
public void onBindViewHolder(@NonNull SettingsSubMenuAdapter.RecyclerViewHolder holder, int position) {
final int pos = position;
- this.mHolders[pos] = holder;
holder.menuItemSettingKey.setText(mValues[pos]);
holder.menuItemSettingRadio.setChecked(pos == mSelected);
holder.menuItemSettingRadio.setOnCheckedChangeListener((v, b) -> {