DanaR Stats beautify layout and add some listeners

This commit is contained in:
viktoria 2017-01-20 14:51:16 +01:00
parent d2acad1942
commit 722976f6b0
3 changed files with 140 additions and 104 deletions

View file

@ -13,10 +13,12 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
@ -70,6 +72,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout tl,ctl,etl;
String TBB;
double magicNumber;
DecimalFormat decimalFormat;
List<DanaRHistoryRecord> historyList = new ArrayList<>();
@ -128,30 +131,55 @@ public class DanaRStatsActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.danar_statsactivity);
statusView = (TextView) findViewById(R.id.danar_historystatus);
reloadButton = (Button) findViewById(R.id.danar_historyreload);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
reloadButton = (Button) findViewById(R.id.danar_statsreload);
llm = new LinearLayoutManager(this);
statusView.setVisibility(View.GONE);
statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
statsMessage.setVisibility(View.GONE);
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2);
decimalFormat = new DecimalFormat("0.000");
totalBaseBasal2.setEnabled(false);
totalBaseBasal2.setClickable(false);
totalBaseBasal2.setFocusable(false);
totalBaseBasal2.setInputType(0);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
TBB = preferences.getString("TBB", "10.00");
totalBaseBasal.setHint(TBB);
totalBaseBasal.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
totalBaseBasal.setText(TBB);
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfile();
if (pi instanceof CircadianPercentageProfilePlugin){
totalBaseBasal.setText(decimalFormat.format(((CircadianPercentageProfilePlugin)pi).baseBasalSum()));
}
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE){
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
totalBaseBasal.clearFocus();
}
return false;
}
});
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
totalBaseBasal.getText().clear();
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
// stats table
@ -306,29 +334,17 @@ public class DanaRStatsActivity extends Activity {
cleanTable(ctl);
cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM.");
DecimalFormat decimalFormat = new DecimalFormat("0.000");
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfile();
if (pi instanceof CircadianPercentageProfilePlugin){
magicNumber = ((CircadianPercentageProfilePlugin)pi).baseBasalSum();
totalBaseBasal.setHint(decimalFormat.format(magicNumber));
totalBaseBasal.setEnabled(false);
totalBaseBasal.setClickable(false);
totalBaseBasal.setFocusable(false);
totalBaseBasal.setInputType(0);
} else {
if(TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
}
else {
magicNumber = Double.parseDouble(TBB);
}
if(TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
}
else {
magicNumber = Double.parseDouble(TBB);
}
magicNumber *=2;
totalBaseBasal2.setHint(decimalFormat.format(magicNumber));
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
int i = 0;
double sum = 0d;

View file

@ -13,10 +13,12 @@ import android.os.HandlerThread;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
@ -70,6 +72,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout tl,ctl,etl;
String TBB;
double magicNumber;
DecimalFormat decimalFormat;
List<DanaRHistoryRecord> historyList = new ArrayList<>();
@ -128,30 +131,55 @@ public class DanaRStatsActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.danar_statsactivity);
statusView = (TextView) findViewById(R.id.danar_historystatus);
reloadButton = (Button) findViewById(R.id.danar_historyreload);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
reloadButton = (Button) findViewById(R.id.danar_statsreload);
llm = new LinearLayoutManager(this);
statusView.setVisibility(View.GONE);
statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
statsMessage.setVisibility(View.GONE);
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2);
decimalFormat = new DecimalFormat("0.000");
totalBaseBasal2.setEnabled(false);
totalBaseBasal2.setClickable(false);
totalBaseBasal2.setFocusable(false);
totalBaseBasal2.setInputType(0);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
TBB = preferences.getString("TBB", "10.00");
totalBaseBasal.setHint(TBB);
totalBaseBasal.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
totalBaseBasal.setText(TBB);
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfile();
if (pi instanceof CircadianPercentageProfilePlugin){
totalBaseBasal.setText(decimalFormat.format(((CircadianPercentageProfilePlugin)pi).baseBasalSum()));
}
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE){
SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString());
edit.commit();
TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
totalBaseBasal.clearFocus();
}
return false;
}
});
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
totalBaseBasal.getText().clear();
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
// stats table
@ -306,29 +334,17 @@ public class DanaRStatsActivity extends Activity {
cleanTable(ctl);
cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM.");
DecimalFormat decimalFormat = new DecimalFormat("0.000");
ProfileInterface pi = ConfigBuilderPlugin.getActiveProfile();
if (pi instanceof CircadianPercentageProfilePlugin){
magicNumber = ((CircadianPercentageProfilePlugin)pi).baseBasalSum();
totalBaseBasal.setHint(decimalFormat.format(magicNumber));
totalBaseBasal.setEnabled(false);
totalBaseBasal.setClickable(false);
totalBaseBasal.setFocusable(false);
totalBaseBasal.setInputType(0);
} else {
if(TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
}
else {
magicNumber = Double.parseDouble(TBB);
}
if(TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
}
else {
magicNumber = Double.parseDouble(TBB);
}
magicNumber *=2;
totalBaseBasal2.setHint(decimalFormat.format(magicNumber));
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
int i = 0;
double sum = 0d;

View file

@ -23,8 +23,6 @@
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/danar_historytop"
android:layout_above="@+id/danar_historybuttons"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
@ -35,9 +33,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/loopmodeborder"
android:gravity="center_horizontal"
android:textColor="@color/cardColorBackground"
android:textColor="@color/mdtp_white"
android:background="@drawable/pillborder"
android:text="@string/danar_stats" />
<TableLayout
@ -66,17 +64,16 @@
<TextView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="@drawable/loopmodeborder"
android:textColor="@color/mdtp_white"
android:background="@drawable/pillborder"
android:gravity="center_horizontal"
android:textColor="@color/cardColorBackground"
android:text="@string/danar_stats_cumulative_tdd" />
<TableLayout
android:stretchColumns="0,1,2"
android:id="@+id/cumulative_table"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_column="0"
android:layout_weight="1">
</TableLayout>
@ -97,17 +94,16 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/loopmodeborder"
android:gravity="center_horizontal"
android:textColor="@color/cardColorBackground"
android:textColor="@color/mdtp_white"
android:background="@drawable/pillborder"
android:text="@string/danar_stats_expweight" />
<TableLayout
android:stretchColumns="0,1,2"
android:id="@+id/expweight_table"
android:layout_height="match_parent"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_column="1"
android:layout_weight="1">
</TableLayout>
@ -123,18 +119,21 @@
<TextView
android:text="@string/danar_stats_tbb"
android:labelFor="@+id/danar_stats_editTotalBaseBasal"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/danar_stats_editTotalBaseBasal_label"
android:gravity="left"
android:layout_weight="1" />
<EditText
android:layout_width="79dp"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:textSize="50px"
android:gravity="center"
android:inputType="numberDecimal"
android:layout_marginRight="10dp"
android:gravity="center_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/mdtp_white"
android:background="@drawable/pillborder"
android:id="@+id/danar_stats_editTotalBaseBasal" />
</LinearLayout>
@ -146,18 +145,19 @@
<TextView
android:text="@string/danar_stats_tbb2"
android:labelFor="@+id/danar_stats_editTotalBaseBasal2"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/danar_stats_editTotalBaseBasal2_label"
android:gravity="left"
android:layout_weight="1" />
<TextView
android:layout_width="79dp"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:textSize="50px"
android:gravity="center"
android:inputType="numberDecimal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical|center_horizontal"
android:layout_marginRight="10dp"
android:textColor="@color/mdtp_white"
android:id="@+id/danar_stats_editTotalBaseBasal2" />
</LinearLayout>
@ -165,12 +165,6 @@
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/danar_historystatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
</LinearLayout>
</ScrollView>
@ -184,25 +178,35 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:layout_weight="1">
<TextView
android:id="@+id/danar_stats_connection_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/danar_stats_Message"
android:layout_width="match_parent"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="45px"
android:textSize="24sp"
android:textColor="#ff0000"
android:background="@drawable/pillborder"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/danar_stats_warning_Message" />
<Button
android:id="@+id/danar_historyreload"
android:layout_width="match_parent"
android:id="@+id/danar_statsreload"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/mdtp_white"
android:background="@drawable/pillborder"
android:text="@string/danar_historyreload" />
</LinearLayout>