Wear add menu icons and animation

This commit is contained in:
Andries Smit 2021-11-30 21:02:49 +01:00
parent dc7a27b018
commit 5ae7346123
12 changed files with 165 additions and 48 deletions

View file

@ -6,15 +6,12 @@ import android.os.Bundle;
import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter;
import android.support.wearable.view.GridViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService;

View file

@ -5,6 +5,8 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import info.nightscout.androidaps.R;
@ -32,29 +34,30 @@ public class MainMenuActivity extends MenuListActivity {
}
@Override
protected String[] getElements() {
protected List<MenuElement> getElements() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
List<MenuElement> menuitems = new ArrayList<>();
if (!sharedPreferences.getBoolean("wearcontrol", false)) {
return new String[]{
getString(R.string.menu_settings),
getString(R.string.menu_resync)};
menuitems.add(new MenuElement(R.drawable.ic_settings, getString(R.string.menu_settings)));
menuitems.add(new MenuElement(R.drawable.ic_sync, getString(R.string.menu_resync)));
return menuitems;
}
boolean showPrimeFill = sp.getBoolean("primefill", false);
boolean showWizard = sp.getBoolean("showWizard", true);
Vector<String> menuitems = new Vector<String>();
menuitems.add(getString(R.string.menu_tempt));
if (showWizard) menuitems.add(getString(R.string.menu_wizard));
menuitems.add(getString(R.string.menu_ecarb));
menuitems.add(getString(R.string.menu_bolus));
menuitems.add(getString(R.string.menu_settings));
menuitems.add(getString(R.string.menu_status));
if (showPrimeFill) menuitems.add(getString(R.string.menu_prime_fill));
menuitems.add(new MenuElement(R.drawable.ic_temptarget, getString(R.string.menu_tempt)));
if (showWizard) menuitems.add(new MenuElement(R.drawable.ic_cob_iob, getString(R.string.menu_wizard)));
menuitems.add(new MenuElement(R.drawable.ic_carbs, getString(R.string.menu_ecarb)));
menuitems.add(new MenuElement(R.drawable.ic_ins, getString(R.string.menu_bolus)));
menuitems.add(new MenuElement(R.drawable.ic_settings, getString(R.string.menu_settings)));
menuitems.add(new MenuElement(R.drawable.ic_status, getString(R.string.menu_status)));
if (showPrimeFill) menuitems.add(new MenuElement(R.drawable.ic_canula, getString(R.string.menu_prime_fill)));
return menuitems.toArray(new String[menuitems.size()]);
return menuitems;
}
@Override

View file

@ -1,5 +1,8 @@
package info.nightscout.androidaps.interaction.menus;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.interaction.utils.MenuListActivity;
@ -11,14 +14,14 @@ import info.nightscout.androidaps.interaction.utils.MenuListActivity;
public class StatusMenuActivity extends MenuListActivity {
@Override
protected String[] getElements() {
return new String[] {
getString(R.string.status_pump),
getString(R.string.status_loop),
getString(R.string.status_cpp),
getString(R.string.status_tdd)};
protected List<MenuElement> getElements() {
List<MenuElement> menuitems = new ArrayList<>();
menuitems.add(new MenuElement(R.drawable.ic_status, getString(R.string.status_pump)));
menuitems.add(new MenuElement(R.drawable.ic_loop_closed_white, getString(R.string.status_loop)));
menuitems.add(new MenuElement(R.drawable.ic_status, getString(R.string.status_cpp)));
menuitems.add(new MenuElement(R.drawable.ic_iob_detailed, getString(R.string.status_tdd)));
return menuitems;
}
@Override

View file

@ -7,8 +7,12 @@ import android.support.wearable.view.WearableListView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import info.nightscout.androidaps.R;
/**
@ -18,9 +22,9 @@ import info.nightscout.androidaps.R;
public abstract class MenuListActivity extends Activity
implements WearableListView.ClickListener {
String[] elements;
List<MenuElement> elements;
protected abstract String[] getElements();
protected abstract List<MenuElement> getElements();
protected abstract void doAction(String position);
@ -41,7 +45,7 @@ public abstract class MenuListActivity extends Activity
findViewById(R.id.wearable_list);
// Assign an adapter to the list
listView.setAdapter(new Adapter(this, elements));
listView.setAdapter(new MenuAdapter(this, elements));
// Set a click listener
listView.setClickListener(this);
@ -61,20 +65,20 @@ public abstract class MenuListActivity extends Activity
}
private static final class Adapter extends WearableListView.Adapter {
private final String[] mDataset;
private class MenuAdapter extends WearableListView.Adapter {
private final List<MenuElement> mDataset;
private final Context mContext;
private final LayoutInflater mInflater;
// Provide a suitable constructor (depends on the kind of dataset)
public Adapter(Context context, String[] dataset) {
public MenuAdapter(Context context, List<MenuElement> dataset) {
mContext = context;
mInflater = LayoutInflater.from(context);
mDataset = dataset;
}
// Provide a reference to the type of views you're using
public static class ItemViewHolder extends WearableListView.ViewHolder {
public class ItemViewHolder extends WearableListView.ViewHolder {
private final TextView textView;
public ItemViewHolder(View itemView) {
@ -90,7 +94,8 @@ public abstract class MenuListActivity extends Activity
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// Inflate our custom layout for list items
return new ItemViewHolder(mInflater.inflate(R.layout.list_item, null));
WearableListView.ViewHolder viewHolder = new WearableListView.ViewHolder(new MenuItemView(mContext));
return viewHolder;
}
// Replace the contents of a list item
@ -100,21 +105,68 @@ public abstract class MenuListActivity extends Activity
public void onBindViewHolder(WearableListView.ViewHolder holder,
int position) {
// retrieve the text view
ItemViewHolder itemHolder = (ItemViewHolder) holder;
TextView view = itemHolder.textView;
// replace text contents
view.setText(mDataset[position]);
MenuItemView menuItemView = (MenuItemView) holder.itemView;
final MenuElement item = mDataset.get(position);
TextView textView = menuItemView.findViewById(R.id.actionitem);
textView.setText(item.actionitem);
final ImageView imageView = menuItemView.findViewById(R.id.actionicon);
imageView.setImageResource(item.actionicon);
// replace list item's metadata
holder.itemView.setTag(mDataset[position]);
holder.itemView.setTag(item.actionitem);
}
// Return the size of your dataset
// (invoked by the WearableListView's layout manager)
@Override
public int getItemCount() {
return mDataset.length;
return mDataset.size();
}
}
public final class MenuItemView extends FrameLayout implements WearableListView.OnCenterProximityListener {
}
final ImageView image;
final TextView text;
final float scale = 0.8f;
final float alpha = 0.8f;
public MenuItemView(Context context) {
super(context);
View.inflate(context, R.layout.list_item, this);
image = findViewById(R.id.actionicon);
text = findViewById(R.id.actionitem);
image.setScaleX(scale);
image.setScaleX(scale);
image.setAlpha(alpha);
text.setScaleX(scale);
text.setScaleX(scale);
text.setAlpha(alpha);
}
@Override
public void onCenterPosition(boolean b) {
// Animation to be ran when the view becomes the centered one
image.animate().scaleX(1f).scaleY(1f).alpha(1);
text.animate().scaleX(1f).scaleY(1f).alpha(1);
}
@Override
public void onNonCenterPosition(boolean b) {
//Animation to be ran when the view is not the centered one anymore
image.animate().scaleX(scale).scaleY(scale).alpha(alpha);
text.animate().scaleX(scale).scaleY(scale).alpha(alpha);
}
}
protected class MenuElement {
public MenuElement(int actionicon, String actionitem) {
this.actionicon = actionicon;
this.actionitem = actionitem;
}
public int actionicon;
public String actionitem;
}
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M20.951,10.458h-1.99c-0.054,-0.733 -0.659,-1.313 -1.406,-1.313h-2.354c-0.747,0 -1.352,0.58 -1.406,1.313h-1.99c-0.388,0 -0.696,0.27 -0.771,0.622c-1.32,-0.021 -2.226,-0.555 -2.936,-0.999c-0.7,-0.437 -1.304,-0.814 -2.005,-0.434c-1.202,0.654 -0.843,2.024 -0.554,3.126c0.192,0.731 0.39,1.489 0.098,1.836c-0.603,0.718 -2.212,0.276 -2.781,0.045c-0.143,-0.057 -0.31,0.011 -0.369,0.156c-0.059,0.146 0.011,0.311 0.156,0.369c0.061,0.024 0.971,0.388 1.893,0.388c0.574,0 1.153,-0.142 1.534,-0.593c0.482,-0.571 0.256,-1.433 0.017,-2.345c-0.323,-1.234 -0.479,-2.074 0.276,-2.485c0.392,-0.213 0.762,-0.003 1.434,0.417c0.755,0.471 1.766,1.123 3.359,1.096C11.301,11.859 11.531,12 11.806,12h4.406v5.771l0.333,-0.854V12h4.406c0.443,0 0.802,-0.345 0.802,-0.771S21.394,10.458 20.951,10.458z"
android:fillColor="@android:color/white"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M24,9.343l-5.781,-3.968l-1.328,6.688l2.102,-1.757c0.014,0.056 0.03,0.111 0.043,0.168c0.116,0.512 0.183,1.042 0.183,1.589c0,3.952 -3.204,7.156 -7.156,7.156s-7.156,-3.204 -7.156,-7.156s3.204,-7.156 7.156,-7.156c1.072,0 2.085,0.242 2.998,0.665c0.325,0.151 0.639,0.321 0.936,0.517l0.002,-0.002l-0.352,-1.784l1.876,-0.538c-1.567,-1.033 -3.442,-1.639 -5.46,-1.639c-5.488,0 -9.938,4.449 -9.938,9.938S6.574,22 12.063,22S22,17.551 22,12.063c0,-0.759 -0.093,-1.496 -0.254,-2.206c-0.04,-0.176 -0.085,-0.35 -0.134,-0.523L24,9.343L24,9.343z"
android:fillColor="@android:color/white"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12.028,2.042c-5.523,0 -10,4.477 -10,10c0,5.523 4.477,10 10,10s10,-4.477 10,-10C22.028,6.519 17.551,2.042 12.028,2.042zM13.007,16.958h-1.958V11h1.958V16.958zM13.007,8.958h-1.958V7h1.958V8.958z"
android:fillColor="@color/white"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="m13 7.101.01.001a4.978 4.978 0 0 1 2.526 1.362 5.005 5.005 0 0 1 1.363 2.528 5.061 5.061 0 0 1-.001 2.016 4.976 4.976 0 0 1-1.363 2.527l1.414 1.414a7.014 7.014 0 0 0 1.908-3.54 6.98 6.98 0 0 0 0-2.819 6.957 6.957 0 0 0-1.907-3.539 6.97 6.97 0 0 0-2.223-1.5 6.921 6.921 0 0 0-1.315-.408c-.137-.028-.275-.043-.412-.063V2L9 6l4 4V7.101zm-7.45 7.623c.174.412.392.812.646 1.19.249.37.537.718.854 1.034a7.036 7.036 0 0 0 2.224 1.501c.425.18.868.317 1.315.408.167.034.338.056.508.078v2.944l4-4-4-4v3.03c-.035-.006-.072-.003-.107-.011a4.978 4.978 0 0 1-2.526-1.362 4.994 4.994 0 0 1 .001-7.071L7.051 7.05a7.01 7.01 0 0 0-1.5 2.224A6.974 6.974 0 0 0 5 12a6.997 6.997 0 0 0 .55 2.724z"/>
</vector>

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21.569,12.709h-4.772c-0.392,0 -0.709,-0.317 -0.709,-0.709V9.177H7.927l0,2.823c0,0.392 -0.317,0.709 -0.708,0.709H2.431c-0.392,0 -0.708,-0.317 -0.708,-0.709s0.317,-0.708 0.708,-0.708H6.51l0,-2.823c0,-0.392 0.317,-0.708 0.708,-0.708h9.578c0.392,0 0.709,0.317 0.709,0.708v2.823h4.063c0.392,0 0.709,0.317 0.709,0.708S21.961,12.709 21.569,12.709z"
android:fillColor="@android:color/white"/>
</vector>

View file

@ -3,21 +3,28 @@
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="80dp">
<ImageView
android:id="@+id/actionicon"
android:layout_height="20dp"
android:layout_margin="5dp"
android:layout_width="20dp"
android:src="@drawable/circle"/>
<TextView
android:id="@+id/actionitem"
android:gravity="center_vertical|center_horizontal"
android:layout_width="match_parent"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="0dp"
android:layout_height="match_parent"
android:fontFamily="sans-serif-condensed-light"
android:lineSpacingExtra="-4sp"
android:textColor="@color/dark_statusView"
android:textSize="32sp"
android:textSize="30sp"
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="32sp"
android:autoSizeStepGranularity="2sp"
android:text="list item"
/>
</info.nightscout.androidaps.interaction.utils.WearableListItemLayout>

View file

@ -3,22 +3,23 @@
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="80dp">
<!-- ImageView
android:id="@+id/circle"
<ImageView
android:id="@+id/actionicon"
android:layout_height="20dp"
android:layout_margin="16dp"
android:layout_margin="5dp"
android:layout_width="20dp"
android:src="@drawable/wl_circle"/-->
android:src="@drawable/circle"/>
<TextView
android:id="@+id/actionitem"
android:gravity="center_vertical|center_horizontal"
android:layout_width="match_parent"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="0dp"
android:layout_height="match_parent"
android:fontFamily="sans-serif-condensed-light"
android:lineSpacingExtra="-4sp"
android:textColor="@color/dark_statusView"
android:textSize="32sp"/>
android:textSize="30sp"
android:text="list item"/>
</info.nightscout.androidaps.interaction.utils.WearableListItemLayout>