StatusItem ui elements

This commit is contained in:
Jamorham 2018-01-26 16:12:37 +00:00
parent 8fa0de19c2
commit 31b0ce21e5
No known key found for this signature in database
GPG key ID: 0BC5C3E0AAD64DF9
2 changed files with 144 additions and 0 deletions

View file

@ -0,0 +1,64 @@
package info.nightscout.androidaps.plugins.PumpInsight.utils;
/**
* Created by jamorham on 26/01/2018.
*
* For representing row status items
*/
public class StatusItem {
public enum Highlight {
NORMAL,
GOOD,
BAD,
NOTICE,
CRITICAL
}
public String name;
public String value;
public Highlight highlight;
public String button_name;
public Runnable runnable;
public StatusItem(String name, String value) {
this(name, value, Highlight.NORMAL);
}
public StatusItem() {
this("line-break", "", Highlight.NORMAL);
}
public StatusItem(String name, Highlight highlight) {
this("heading-break", name, highlight);
}
public StatusItem(String name, Runnable runnable) {
this("button-break", "", Highlight.NORMAL, name, runnable);
}
public StatusItem(String name, String value, Highlight highlight) {
this(name, value, highlight, null, null);
}
public StatusItem(String name, String value, Highlight highlight, String button_name, Runnable runnable) {
this.name = name;
this.value = value;
this.highlight = highlight;
this.button_name = button_name;
this.runnable = runnable;
}
public StatusItem(String name, Integer value) {
this(name, value, Highlight.NORMAL);
}
public StatusItem(String name, Integer value, Highlight highlight) {
this.name = name;
this.value = Integer.toString(value);
this.highlight = highlight;
}
}

View file

@ -0,0 +1,80 @@
package info.nightscout.androidaps.plugins.PumpInsight.utils.ui;
import android.app.Activity;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem;
/**
* Created by jamorham on 26/01/2018.
*
* Convert StatusItem to View
*/
public class StatusItemViewAdapter {
private final Activity activity;
private final ViewGroup holder;
public StatusItemViewAdapter(Activity activity, ViewGroup holder) {
this.activity = activity;
this.holder = holder;
}
public View inflateStatus(StatusItem statusItem) {
if (activity == null) return null;
final View child = activity.getLayoutInflater().inflate(R.layout.insightpump_statuselements, null);
final TextView name = child.findViewById(R.id.insightstatuslabel);
final TextView value = child.findViewById(R.id.insightstatusvalue);
final TextView spacer = child.findViewById(R.id.insightstatusspacer);
final LinearLayout layout = child.findViewById(R.id.insightstatuslayout);
if (statusItem.name.equals("line-break")) {
spacer.setVisibility(View.GONE);
name.setVisibility(View.GONE);
value.setVisibility(View.GONE);
layout.setPadding(10, 10, 10, 10);
} else if (statusItem.name.equals("heading-break")) {
value.setVisibility(View.GONE);
spacer.setVisibility(View.GONE);
name.setText(statusItem.value);
name.setGravity(Gravity.CENTER_HORIZONTAL);
name.setTextColor(Color.parseColor("#fff9c4"));
} else {
name.setText(statusItem.name);
value.setText(statusItem.value);
}
final int this_color = getHighlightColor(statusItem);
name.setBackgroundColor(this_color);
value.setBackgroundColor(this_color);
spacer.setBackgroundColor(this_color);
if (holder != null) {
holder.addView(child);
}
return child;
}
private static int getHighlightColor(StatusItem row) {
switch (row.highlight) {
case BAD:
return Color.parseColor("#480000");
case NOTICE:
return Color.parseColor("#403000");
case GOOD:
return Color.parseColor("#003000");
case CRITICAL:
return Color.parseColor("#770000");
default:
return Color.TRANSPARENT;
}
}
}