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.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.view.KeyEvent;
import android.view.View; 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.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TableLayout; import android.widget.TableLayout;
@ -70,6 +72,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout tl,ctl,etl; TableLayout tl,ctl,etl;
String TBB; String TBB;
double magicNumber; double magicNumber;
DecimalFormat decimalFormat;
List<DanaRHistoryRecord> historyList = new ArrayList<>(); List<DanaRHistoryRecord> historyList = new ArrayList<>();
@ -128,30 +131,55 @@ public class DanaRStatsActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.danar_statsactivity); setContentView(R.layout.danar_statsactivity);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
statusView = (TextView) findViewById(R.id.danar_historystatus); statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
reloadButton = (Button) findViewById(R.id.danar_historyreload); reloadButton = (Button) findViewById(R.id.danar_statsreload);
llm = new LinearLayoutManager(this); llm = new LinearLayoutManager(this);
statusView.setVisibility(View.GONE); statusView.setVisibility(View.GONE);
statsMessage = (TextView) findViewById(R.id.danar_stats_Message); statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
statsMessage.setVisibility(View.GONE); statsMessage.setVisibility(View.GONE);
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal); totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2); 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); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
TBB = preferences.getString("TBB", "10.00"); TBB = preferences.getString("TBB", "10.00");
totalBaseBasal.setHint(TBB); totalBaseBasal.setText(TBB);
totalBaseBasal.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) { 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(); SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString()); edit.putString("TBB",totalBaseBasal.getText().toString());
edit.commit(); edit.commit();
TBB = preferences.getString("TBB", ""); TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY); 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 // stats table
@ -306,17 +334,6 @@ public class DanaRStatsActivity extends Activity {
cleanTable(ctl); cleanTable(ctl);
cleanTable(etl); cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM."); 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)) { if(TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal"); totalBaseBasal.setError("Please Enter Total Base Basal");
@ -326,9 +343,8 @@ public class DanaRStatsActivity extends Activity {
magicNumber = Double.parseDouble(TBB); magicNumber = Double.parseDouble(TBB);
} }
}
magicNumber *=2; magicNumber *=2;
totalBaseBasal2.setHint(decimalFormat.format(magicNumber)); totalBaseBasal2.setText(decimalFormat.format(magicNumber));
int i = 0; int i = 0;
double sum = 0d; double sum = 0d;

View file

@ -13,10 +13,12 @@ import android.os.HandlerThread;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.view.KeyEvent;
import android.view.View; 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.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TableLayout; import android.widget.TableLayout;
@ -70,6 +72,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout tl,ctl,etl; TableLayout tl,ctl,etl;
String TBB; String TBB;
double magicNumber; double magicNumber;
DecimalFormat decimalFormat;
List<DanaRHistoryRecord> historyList = new ArrayList<>(); List<DanaRHistoryRecord> historyList = new ArrayList<>();
@ -128,30 +131,55 @@ public class DanaRStatsActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.danar_statsactivity); setContentView(R.layout.danar_statsactivity);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
statusView = (TextView) findViewById(R.id.danar_historystatus); statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
reloadButton = (Button) findViewById(R.id.danar_historyreload); reloadButton = (Button) findViewById(R.id.danar_statsreload);
llm = new LinearLayoutManager(this); llm = new LinearLayoutManager(this);
statusView.setVisibility(View.GONE); statusView.setVisibility(View.GONE);
statsMessage = (TextView) findViewById(R.id.danar_stats_Message); statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
statsMessage.setVisibility(View.GONE); statsMessage.setVisibility(View.GONE);
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal); totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2); 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); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
TBB = preferences.getString("TBB", "10.00"); TBB = preferences.getString("TBB", "10.00");
totalBaseBasal.setHint(TBB); totalBaseBasal.setText(TBB);
totalBaseBasal.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) { 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(); SharedPreferences.Editor edit = preferences.edit();
edit.putString("TBB",totalBaseBasal.getText().toString()); edit.putString("TBB",totalBaseBasal.getText().toString());
edit.commit(); edit.commit();
TBB = preferences.getString("TBB", ""); TBB = preferences.getString("TBB", "");
loadDataFromDB(RecordTypes.RECORD_TYPE_DAILY); 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 // stats table
@ -306,17 +334,6 @@ public class DanaRStatsActivity extends Activity {
cleanTable(ctl); cleanTable(ctl);
cleanTable(etl); cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM."); 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)) { if(TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal"); totalBaseBasal.setError("Please Enter Total Base Basal");
@ -326,9 +343,8 @@ public class DanaRStatsActivity extends Activity {
magicNumber = Double.parseDouble(TBB); magicNumber = Double.parseDouble(TBB);
} }
}
magicNumber *=2; magicNumber *=2;
totalBaseBasal2.setHint(decimalFormat.format(magicNumber)); totalBaseBasal2.setText(decimalFormat.format(magicNumber));
int i = 0; int i = 0;
double sum = 0d; double sum = 0d;

View file

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