TimeListEdit initial work

This commit is contained in:
Milos Kozak 2016-12-30 16:43:43 +01:00
parent 2f52091b67
commit e1c2e4c492
9 changed files with 258 additions and 8 deletions

View file

@ -107,7 +107,7 @@ android {
dependencies { dependencies {
wearWearApp project(path: ':wear', configuration: 'fullRelease') wearWearApp project(path: ':wear', configuration: 'fullRelease')
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') { compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
transitive = true; transitive = true;
} }
@ -127,6 +127,7 @@ dependencies {
compile 'com.jjoe64:graphview:4.0.1' compile 'com.jjoe64:graphview:4.0.1'
compile 'com.eclipsesource.j2v8:j2v8:3.1.6@aar' compile 'com.eclipsesource.j2v8:j2v8:3.1.6@aar'
compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1' compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.1.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services-wearable:7.5.0' compile 'com.google.android.gms:play-services-wearable:7.5.0'
compile 'junit:junit:4.12'
testCompile 'org.json:json:20140107'
} }

View file

@ -0,0 +1,154 @@
package info.nightscout.utils;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import info.nightscout.androidaps.R;
/**
* Created by mike on 29.12.2016.
*/
public class TimeListEdit {
LinearLayout layout;
Context context;
View view;
int resLayoutId;
JSONArray data;
boolean per30min = false;
String array1;
String array2;
public TimeListEdit(Context context, View view, int resLayoutId, JSONArray data, String array1, String array2, boolean per30min) {
this.context = context;
this.view = view;
this.resLayoutId = resLayoutId;
this.data = data;
this.array1 = array1;
this.array2 = array2;
this.per30min = per30min;
buildView();
}
private void buildView() {
/*
LayoutInflater inflater = LayoutInflater.from(context);
layout = (LinearLayout) view.findViewById(resLayoutId);
final EditText[] editTexts = new EditText[24];
for (int i = 0; i < 24; i++) {
View childview = inflater.inflate(R.layout.timelistedit_element, layout, false);
((TextView) childview.findViewById(R.id.basal_time_elem)).setText((i < 10 ? "0" : "") + i + ":00: ");
ImageView copyprevbutton = (ImageView) childview.findViewById(R.id.basal_copyprev_elem);
if (i == 0) {
copyprevbutton.setVisibility(View.INVISIBLE);
;
} else {
final int j = i; //needs to be final to be passed to inner class.
copyprevbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editTexts[j].setText(editTexts[j - 1].getText());
}
});
}
editTexts[i] = ((EditText) childview.findViewById(R.id.basal_edittext_elem));
//editTexts[i].setText(DecimalFormatter.to2Decimal(values[i]));
layout.addView(childview);
}
*/
}
public int itemsCount() {
return data.length();
}
public int secondFromMidnight(int index) {
try {
JSONObject item = (JSONObject) data.get(index);
if (item.has("timeAsSeconds")) {
return item.getInt("timeAsSeconds");
}
} catch (JSONException e) {
e.printStackTrace();
}
return 0;
}
public double value1(int index) {
try {
JSONObject item = (JSONObject) data.get(index);
if (item.has(array1)) {
return item.getDouble(array1);
}
} catch (JSONException e) {
e.printStackTrace();
}
return 0d;
}
public double value2(int index) {
try {
JSONObject item = (JSONObject) data.get(index);
if (item.has(array2)) {
return item.getDouble(array2);
}
} catch (JSONException e) {
e.printStackTrace();
}
return 0d;
}
public void editItem(int index, int timeAsSeconds, double value1, double value2) {
try {
JSONObject newObject = new JSONObject();
newObject.put("timeAsSeconds", timeAsSeconds);
newObject.put(array1, value1);
if (array2 != null)
newObject.put(array2, value2);
data.put(index, newObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
public void addItem(int index, int timeAsSeconds, double value1, double value2) {
try {
// shift data
for (int i = data.length(); i > index; i--) {
data.put(i, data.get(i - 1));
}
// add new object
JSONObject newObject = new JSONObject();
newObject.put("timeAsSeconds", timeAsSeconds);
newObject.put(array1, value1);
if (array2 != null)
newObject.put(array2, value2);
data.put(index, newObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
public void removeItem(int index) {
data.remove(index);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

View file

@ -0,0 +1,46 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/cardColorBackground"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall">
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timelistedit_time"
/>
<EditText
android:id="@+id/timelistedit_edit1"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal"/>
<EditText
android:id="@+id/timelistedit_edit2"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:inputType="numberDecimal"/>
<ImageView
android:id="@+id/timelistedit_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
tools:src="@drawable/add" />
<ImageView
android:id="@+id/timelistedit_remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
tools:src="@drawable/remove" />
</LinearLayout>

View file

@ -16,12 +16,12 @@
<string name="careportal_announcement">Известие</string> <string name="careportal_announcement">Известие</string>
<string name="careportal_bgcheck">Проверка на КЗ</string> <string name="careportal_bgcheck">Проверка на КЗ</string>
<string name="careportal_carbscorrection">Корекция с въглехидр.</string> <string name="careportal_carbscorrection">Корекция с въглехидр.</string>
<string name="careportal_cgmsensorinsert">Замяна сензор</string> <string name="careportal_cgmsensorinsert">Смяна на сензор</string>
<string name="careportal_cgmsensorstart">Рестарт на сензор</string> <string name="careportal_cgmsensorstart">Рестарт на сензор</string>
<string name="careportal_combobolus">Комбиниран болус</string> <string name="careportal_combobolus">Комбиниран болус</string>
<string name="careportal_correctionbolus">Болус за корекция</string> <string name="careportal_correctionbolus">Болус за корекция</string>
<string name="careportal_exercise">Физ. активност</string> <string name="careportal_exercise">Физ. активност</string>
<string name="careportal_insulincartridgechange">Замяна резервоар</string> <string name="careportal_insulincartridgechange">Смяна на резервоар</string>
<string name="careportal_mealbolus">Болус за осн. хранене</string> <string name="careportal_mealbolus">Болус за осн. хранене</string>
<string name="careportal_newnstreatment_absolute_label">Абсолютна</string> <string name="careportal_newnstreatment_absolute_label">Абсолютна</string>
<string name="careportal_newnstreatment_carbs_label">ВХ</string> <string name="careportal_newnstreatment_carbs_label">ВХ</string>
@ -41,7 +41,7 @@
<string name="careportal_note">Бележка</string> <string name="careportal_note">Бележка</string>
<string name="careportal_openapsoffline">OpenAPS оффлайн</string> <string name="careportal_openapsoffline">OpenAPS оффлайн</string>
<string name="careportal_profileswitch">Смяна на профил</string> <string name="careportal_profileswitch">Смяна на профил</string>
<string name="careportal_pumpsitechange">Замяна сет</string> <string name="careportal_pumpsitechange">Смяна на сет</string>
<string name="careportal_question">Въпрос</string> <string name="careportal_question">Въпрос</string>
<string name="careportal_snackbolus">Болус за закуска</string> <string name="careportal_snackbolus">Болус за закуска</string>
<string name="careportal_tempbasalend">Край на временен базал</string> <string name="careportal_tempbasalend">Край на временен базал</string>
@ -375,4 +375,5 @@
<string name="resend_all_data">Изпрати всички данни отново</string> <string name="resend_all_data">Изпрати всички данни отново</string>
<string name="wear">Wear</string> <string name="wear">Wear</string>
<string name="wrongpumpdriverselected">Избран е грешен тип помпа</string> <string name="wrongpumpdriverselected">Избран е грешен тип помпа</string>
<string name="minago">преди %d м.</string>
</resources> </resources>

View file

@ -6,20 +6,24 @@ import static org.junit.Assert.*;
public class RoundTest { public class RoundTest {
public RoundTest(){
super();
}
@Test @Test
public void roundTo() { public void roundToTest() throws Exception {
assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 0.55d, Round.roundTo(0.54d, 0.05d), 0.00000001d );
assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d ); assertEquals( 1d, Round.roundTo(1.49d, 1d), 0.00000001d );
} }
@Test @Test
public void floorTo() { public void floorToTest() throws Exception {
assertEquals( 0.5d, Round.floorTo(0.54d, 0.05d), 0.00000001d ); assertEquals( 0.5d, Round.floorTo(0.54d, 0.05d), 0.00000001d );
assertEquals( 1d, Round.floorTo(1.59d, 1d), 0.00000001d ); assertEquals( 1d, Round.floorTo(1.59d, 1d), 0.00000001d );
} }
@Test @Test
public void ceilTo() { public void ceilToTest() throws Exception {
assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d ); assertEquals( 0.6d, Round.ceilTo(0.54d, 0.1d), 0.00000001d );
assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d ); assertEquals( 2d, Round.ceilTo(1.49999d, 1d), 0.00000001d );
} }

View file

@ -0,0 +1,44 @@
package info.nightscout.utils;
import org.json.JSONArray;
import org.junit.Test;
import java.lang.reflect.Method;
import static org.junit.Assert.*;
/**
* Created by mike on 30.12.2016.
*/
public class TimeListEditTest {
JSONArray data = new JSONArray();
JSONArray data2 = new JSONArray();
TimeListEdit tle = new TimeListEdit(null, null, 0, data, "ic", null, false);
TimeListEdit tle2 = new TimeListEdit(null, null, 0, data2, "ic", "ic2", false);
@Test
public void doArrayTest() throws Exception {
tle.addItem(0, 0, 0.1, 0);
tle.addItem(1, 60 * 60, 0.2, 0);
assertEquals(2, tle.itemsCount());
tle.editItem(0, 2 * 60 * 60, 1, 0);
assertEquals(2, tle.itemsCount());
assertEquals(1d, tle.value1(0), 0.00001d);
assertEquals( 2 * 60 * 60, tle.secondFromMidnight(0));
tle.removeItem(0);
assertEquals(0.2d, tle.value1(0), 0.00001d);
assertEquals(0, tle.value2(0), 0.00001d);
assertEquals(60 * 60, tle.secondFromMidnight(0));
//System.out.print(tle2.toString());
assertEquals(0, tle2.itemsCount());
tle2.addItem(0, 0, 1, 2);
assertEquals(1, tle2.itemsCount());
assertEquals(0, tle2.secondFromMidnight(0));
assertEquals(1d, tle2.value1(0), 0.00001d);
assertEquals(2d, tle2.value2(0), 0.00001d);
}
}