diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2022-03-15 03:37:28 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2022-03-15 03:40:59 +0300 |
commit | 7fb113a0e4506003defe44b68eb0e4f17a15497c (patch) | |
tree | 35f71e0fc634b12b41af4fc1ace8dabf8acaa243 | |
parent | 0dca222b183536e7f7a371526631028cbb028d83 (diff) |
Explanation, ConstraintLayout, fixes
-rw-r--r-- | app/src/main/AndroidManifest.xml | 5 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java | 27 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java | 7 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java | 15 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java | 55 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java | 18 | ||||
-rw-r--r-- | app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java | 11 | ||||
-rw-r--r-- | app/src/main/res/drawable-nodpi/explanation.png | bin | 0 -> 58746 bytes | |||
-rw-r--r-- | app/src/main/res/drawable-nodpi/preview_notround.png | bin | 67266 -> 39721 bytes | |||
-rw-r--r-- | app/src/main/res/layout/explanation.xml | 8 | ||||
-rw-r--r-- | app/src/main/res/layout/menu_item.xml | 126 |
11 files changed, 190 insertions, 82 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0612878..ad40590 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -69,6 +69,11 @@ android:label="Settings"
android:theme="@style/MyMaterialTheme">
</activity>
+ <activity
+ android:name=".ExplanationActivity"
+ android:label="Explanation"
+ android:theme="@style/MyMaterialTheme">
+ </activity>
<meta-data
android:name="com.google.android.gms.version"
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java new file mode 100644 index 0000000..e45ca2a --- /dev/null +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/ExplanationActivity.java @@ -0,0 +1,27 @@ +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 + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.explanation); + } +} diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java index 3dd6ef7..81b14bc 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/HexWatchFace.java @@ -45,7 +45,7 @@ public class HexWatchFace extends CanvasWatchFaceService { */ public static String TAG = "hex_watchface"; private static final long INTERACTIVE_UPDATE_RATE = TimeUnit.SECONDS.toMillis(1); - private static final long MAX_HEART_RATE_AGE = TimeUnit.SECONDS.toMillis(15); + private static final long MAX_HEART_RATE_AGE = TimeUnit.SECONDS.toMillis(300); private static final long TOUCH_TIME = TimeUnit.SECONDS.toMillis(3); private static final int NUMBER_WIDTH = 78; private static final int NUMBER_V_INTERVAL = 56; @@ -299,8 +299,8 @@ public class HexWatchFace extends CanvasWatchFaceService { dateEndianness = ENDIANNESS_LITTLE_ENDIAN; break; } - drawNumber(canvas, mCalendar.get(Calendar.DAY_OF_MONTH), dateEndianness, 1, HexNumbers.COLORS_CYAN, 2, -1); - drawNumber(canvas, mCalendar.get(Calendar.MONTH) + 1, dateEndianness, 1, HexNumbers.COLORS_CYAN, 2, 1); + drawNumber(canvas, mCalendar.get(Calendar.DAY_OF_MONTH), dateEndianness, 1, HexNumbers.COLORS_CYAN, 2, 1); + drawNumber(canvas, mCalendar.get(Calendar.MONTH) + 1, dateEndianness, 1, HexNumbers.COLORS_CYAN, 2, -1); drawNumber(canvas, mCalendar.get(Calendar.YEAR), dateEndianness, 1, HexNumbers.COLORS_CYAN, 1, -1); } @@ -365,7 +365,6 @@ public class HexWatchFace extends CanvasWatchFaceService { switch (stepsSystem) { default: case SettingsActivity.PREF_VALUE_COMMON_DEC: - Log.d(TAG, "Steps total: "+mStepCounter+", steps today: " + todaySteps +", today start: " + todayStepStart); drawNumber(canvas, todaySteps, ENDIANNESS_FAKE_HEX, 3, HexNumbers.COLORS_CYAN, -2, 1); break; case SettingsActivity.PREF_VALUE_COMMON_HEX: diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java index e0d5015..5687453 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsActivity.java @@ -126,11 +126,16 @@ public class SettingsActivity extends AppCompatActivity { }; WearableRecyclerView recyclerView = findViewById(R.id.settings_menu_view); - recyclerView.setEdgeItemsCenteringEnabled(true); - CustomScrollingLayoutCallback customScrollingLayoutCallback = - new CustomScrollingLayoutCallback(); - recyclerView.setLayoutManager( - new WearableLinearLayoutManager(this, customScrollingLayoutCallback)); + if (res.getBoolean(R.bool.is_round)) { + recyclerView.setEdgeItemsCenteringEnabled(true); + CustomScrollingLayoutCallback customScrollingLayoutCallback = + new CustomScrollingLayoutCallback(); + recyclerView.setLayoutManager( + new WearableLinearLayoutManager(this, customScrollingLayoutCallback)); + } else { + recyclerView.setLayoutManager( + new WearableLinearLayoutManager(this)); + } mSettingsMenuAdapter = new SettingsMenuAdapter(this, mSettings); recyclerView.setAdapter(mSettingsMenuAdapter); } diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java index 979cc16..f43c993 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsMenuAdapter.java @@ -1,21 +1,17 @@ package com.clusterrr.hexeditorwatchface;
-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;
import android.view.ViewGroup;
-import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapter.RecyclerViewHolder> {
@@ -26,22 +22,42 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte public SettingsMenuAdapter(AppCompatActivity context, Setting[] settings) {
this.mContext = context;
mSettings = settings;
- this.mHolders = new SettingsMenuAdapter.RecyclerViewHolder[settings.length];
+ this.mHolders = new SettingsMenuAdapter.RecyclerViewHolder[settings.length + 1];
}
public void updateHolder(int pos)
{
Resources res = mContext.getResources();
SettingsMenuAdapter.RecyclerViewHolder holder = mHolders[pos];
- holder.menuItemSettingKey.setText(mSettings[pos].getName());
- holder.menuItemSettingValue.setText(mSettings[pos].getValueName());
- holder.menuContainer.setOnClickListener(v -> {
- Intent intent = new Intent(mContext, SettingsSubActivity.class);
- intent.putExtra("setting", pos);
- intent.putExtra("values", mSettings[pos].getValueNames());
- intent.putExtra("selected", mSettings[pos].getValue());
- mContext.startActivityForResult(intent, 0);
- });
+ if (pos < mSettings.length) {
+ // Settings with values
+ holder.menuItemSettingKey.setText(mSettings[pos].getName());
+ holder.menuItemSettingValue.setText(mSettings[pos].getValueName());
+ holder.menuContainer.setOnClickListener(v -> {
+ Intent intent = new Intent(mContext, SettingsSubActivity.class);
+ intent.putExtra("setting", pos);
+ intent.putExtra("values", mSettings[pos].getValueNames());
+ intent.putExtra("selected", mSettings[pos].getValue());
+ mContext.startActivityForResult(intent, 0);
+ });
+ holder.menuItemSettingKey.setVisibility(View.VISIBLE);
+ holder.menuItemSettingValue.setVisibility(View.VISIBLE);
+ holder.menuItemSettingRadio.setVisibility(View.GONE);
+ holder.menuItemSettingExplanation.setVisibility(View.GONE);
+ } else {
+ // Show some explanation
+ holder.menuItemSettingKey.setText("Explanation");
+ holder.menuItemSettingValue.setText("");
+
+ holder.menuContainer.setOnClickListener(v -> {
+ Intent intent = new Intent(mContext, ExplanationActivity.class);
+ mContext.startActivity(intent);
+ });
+ holder.menuItemSettingKey.setVisibility(View.GONE);
+ holder.menuItemSettingValue.setVisibility(View.GONE);
+ holder.menuItemSettingRadio.setVisibility(View.GONE);
+ holder.menuItemSettingExplanation.setVisibility(View.VISIBLE);
+ }
// 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);
@@ -57,9 +73,10 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte public static class RecyclerViewHolder extends RecyclerView.ViewHolder {
private Context mContext;
- LinearLayout menuContainer;
+ ConstraintLayout menuContainer;
TextView menuItemSettingKey;
TextView menuItemSettingValue;
+ TextView menuItemSettingExplanation;
RadioButton menuItemSettingRadio;
public RecyclerViewHolder(AppCompatActivity context, View view) {
@@ -68,10 +85,8 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte menuContainer = view.findViewById(R.id.settingsContainer);
menuItemSettingKey = view.findViewById(R.id.textViewSettingKey);
menuItemSettingValue = view.findViewById(R.id.textViewSettingValue);
+ menuItemSettingExplanation = view.findViewById(R.id.textViewSettingExplanation);
menuItemSettingRadio = view.findViewById(R.id.radioButtonSettingValue);
- menuItemSettingValue.setVisibility(View.VISIBLE);
- menuItemSettingRadio.setVisibility(View.GONE);
- Log.i(TAG, "RecyclerViewHolder created");
}
}
@@ -84,6 +99,6 @@ public class SettingsMenuAdapter extends RecyclerView.Adapter<SettingsMenuAdapte @Override
public int getItemCount() {
- return mSettings.length;
+ return mSettings.length + 1;
}
}
diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java index ff76297..791dd34 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubActivity.java @@ -19,14 +19,16 @@ public class SettingsSubActivity extends AppCompatActivity { int selected = intent.getIntExtra("selected", 0); setContentView(R.layout.settings_activity); WearableRecyclerView recyclerView = findViewById(R.id.settings_menu_view); - recyclerView.setEdgeItemsCenteringEnabled(true); - CustomScrollingLayoutCallback customScrollingLayoutCallback = - new CustomScrollingLayoutCallback(); - recyclerView.setLayoutManager( - new WearableLinearLayoutManager(this, customScrollingLayoutCallback)); + if (getResources().getBoolean(R.bool.is_round)) { + recyclerView.setEdgeItemsCenteringEnabled(true); + CustomScrollingLayoutCallback customScrollingLayoutCallback = + new CustomScrollingLayoutCallback(); + recyclerView.setLayoutManager( + new WearableLinearLayoutManager(this, customScrollingLayoutCallback)); + } else { + recyclerView.setLayoutManager( + new WearableLinearLayoutManager(this)); + } recyclerView.setAdapter(new SettingsSubMenuAdapter(this, setting, values, selected)); - //Intent resultIntent = new Intent(); - //resultIntent.putExtra("selected", 0); - //setResult(Activity.RESULT_OK, 0); } } diff --git a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java index 203383c..1a52e4f 100644 --- a/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java +++ b/app/src/main/java/com/clusterrr/hexeditorwatchface/SettingsSubMenuAdapter.java @@ -13,6 +13,7 @@ import android.widget.TextView; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
public class SettingsSubMenuAdapter extends RecyclerView.Adapter<SettingsSubMenuAdapter.RecyclerViewHolder> {
@@ -39,9 +40,10 @@ public class SettingsSubMenuAdapter extends RecyclerView.Adapter<SettingsSubMenu public static class RecyclerViewHolder extends RecyclerView.ViewHolder {
private Context mContext;
- LinearLayout menuContainer;
+ ConstraintLayout menuContainer;
TextView menuItemSettingKey;
TextView menuItemSettingValue;
+ TextView menuItemSettingExplanation;
RadioButton menuItemSettingRadio;
public RecyclerViewHolder(Context context, View view) {
@@ -50,9 +52,8 @@ public class SettingsSubMenuAdapter extends RecyclerView.Adapter<SettingsSubMenu menuContainer = view.findViewById(R.id.settingsContainer);
menuItemSettingKey = view.findViewById(R.id.textViewSettingKey);
menuItemSettingValue = view.findViewById(R.id.textViewSettingValue);
+ menuItemSettingExplanation = view.findViewById(R.id.textViewSettingExplanation);
menuItemSettingRadio = view.findViewById(R.id.radioButtonSettingValue);
- menuItemSettingValue.setVisibility(View.GONE);
- menuItemSettingRadio.setVisibility(View.VISIBLE);
}
}
@@ -76,6 +77,10 @@ public class SettingsSubMenuAdapter extends RecyclerView.Adapter<SettingsSubMenu holder.menuItemSettingRadio.setChecked(false);
holder.menuItemSettingRadio.setChecked(true);
});
+ holder.menuItemSettingKey.setVisibility(View.VISIBLE);
+ holder.menuItemSettingValue.setVisibility(View.GONE);
+ holder.menuItemSettingRadio.setVisibility(View.VISIBLE);
+ holder.menuItemSettingExplanation.setVisibility(View.GONE);
}
@Override
diff --git a/app/src/main/res/drawable-nodpi/explanation.png b/app/src/main/res/drawable-nodpi/explanation.png Binary files differnew file mode 100644 index 0000000..2e04c19 --- /dev/null +++ b/app/src/main/res/drawable-nodpi/explanation.png diff --git a/app/src/main/res/drawable-nodpi/preview_notround.png b/app/src/main/res/drawable-nodpi/preview_notround.png Binary files differindex 537d84b..331ac41 100644 --- a/app/src/main/res/drawable-nodpi/preview_notround.png +++ b/app/src/main/res/drawable-nodpi/preview_notround.png diff --git a/app/src/main/res/layout/explanation.xml b/app/src/main/res/layout/explanation.xml new file mode 100644 index 0000000..e03a8cc --- /dev/null +++ b/app/src/main/res/layout/explanation.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<ImageView xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:scaleType="center" + app:srcCompat="@drawable/explanation"> +</ImageView> diff --git a/app/src/main/res/layout/menu_item.xml b/app/src/main/res/layout/menu_item.xml index 4f8b3c4..a03d0e1 100644 --- a/app/src/main/res/layout/menu_item.xml +++ b/app/src/main/res/layout/menu_item.xml @@ -1,59 +1,101 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:id="@+id/settingsContainer" android:layout_width="match_parent" android:layout_height="70dp" - android:orientation="horizontal" - android:layout_marginLeft="5dp" - android:layout_marginRight="5dp"> + android:orientation="horizontal"> <ImageView - android:id="@+id/imageView" + android:id="@+id/imageViewLeft" android:layout_width="20dp" - android:layout_height="match_parent" + android:layout_height="0dp" + android:layout_marginStart="5dp" android:scaleType="fitXY" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/menu_background_left" /> - <LinearLayout + <ImageView + android:id="@+id/imageViewCenter" android:layout_width="0dp" - android:layout_height="match_parent" - android:layout_weight="1" - android:orientation="horizontal" - android:background="@drawable/menu_background_center" - android:gravity="center"> - - <TextView - android:id="@+id/textViewSettingKey" - android:layout_width="0dp" - android:layout_height="wrap_content" - android:layout_weight="1" - android:text="key" - android:textSize="15dp"/> - - <TextView - android:id="@+id/textViewSettingValue" - android:layout_width="60dp" - android:layout_height="wrap_content" - android:gravity="center" - android:paddingLeft="8dp" - android:text="value" - android:textSize="12sp"/> - - <RadioButton - android:id="@+id/radioButtonSettingValue" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:enabled="true" - android:checked="false" - android:layout_marginLeft="10dp" - android:visibility="gone"/> - </LinearLayout> + android:layout_height="0dp" + android:scaleType="fitXY" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/imageViewRight" + app:layout_constraintStart_toEndOf="@+id/imageViewLeft" + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/menu_background_center" /> + + <TextView + android:id="@+id/textViewSettingKey" + android:layout_width="0dp" + android:layout_height="0dp" + android:layout_marginStart="16dp" + android:gravity="center_vertical|left" + android:text="key" + android:textSize="15dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/guideline" + app:layout_constraintStart_toStartOf="@+id/imageViewLeft" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/textViewSettingValue" + android:layout_width="60dp" + android:layout_height="0dp" + android:layout_marginEnd="8dp" + android:gravity="center" + android:paddingLeft="8dp" + android:text="value" + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/imageViewRight" + app:layout_constraintStart_toEndOf="@+id/guideline" + app:layout_constraintTop_toTopOf="parent" /> + + <RadioButton + android:id="@+id/radioButtonSettingValue" + android:layout_width="wrap_content" + android:layout_height="0dp" + android:checked="false" + android:enabled="true" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="@+id/imageViewCenter" + app:layout_constraintTop_toTopOf="parent" /> <ImageView - android:id="@+id/imageView2" + android:id="@+id/imageViewRight" android:layout_width="20dp" - android:layout_height="70dp" + android:layout_height="0dp" + android:layout_marginEnd="5dp" android:scaleType="fitXY" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/menu_background_right" /> -</LinearLayout> + + <androidx.constraintlayout.widget.Guideline + android:id="@+id/guideline" + android:layout_width="0dp" + android:layout_height="0dp" + android:orientation="vertical" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintGuide_percent="0.6" + app:layout_constraintStart_toStartOf="parent" /> + + <TextView + android:id="@+id/textViewSettingExplanation" + android:layout_width="0dp" + android:layout_height="0dp" + android:gravity="center" + android:text="Explanation" + android:textSize="25dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + android:visibility="visible"/> +</androidx.constraintlayout.widget.ConstraintLayout> |