1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-22 16:23:09 +02:00

added for graph and table fragment an option menu

This commit is contained in:
OliE
2018-02-12 12:01:59 +01:00
parent 8ec7eac288
commit 6a2b479969
13 changed files with 256 additions and 159 deletions

View File

@@ -27,11 +27,14 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.TextView;
import com.health.openscale.R;
@@ -80,7 +83,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
private FloatingActionButton diagramWaist;
private FloatingActionButton diagramHip;
private FloatingActionButton diagramBone;
private FloatingActionButton enableMonth;
private ImageView optionMenu;
private PopupMenu popup;
private SharedPreferences prefs;
private int textColor;
@@ -140,7 +144,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
diagramWaist = (FloatingActionButton) graphView.findViewById(R.id.diagramWaist);
diagramHip = (FloatingActionButton) graphView.findViewById(R.id.diagramHip);
diagramBone = (FloatingActionButton) graphView.findViewById(R.id.diagramBone);
enableMonth = (FloatingActionButton) graphView.findViewById(R.id.enableMonth);
optionMenu = (ImageView) graphView.findViewById(R.id.optionMenu);
diagramWeight.setOnClickListener(new onClickListenerDiagramLines());
diagramFat.setOnClickListener(new onClickListenerDiagramLines());
@@ -151,7 +155,12 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
diagramHip.setOnClickListener(new onClickListenerDiagramLines());
diagramBone.setOnClickListener(new onClickListenerDiagramLines());
enableMonth.setOnClickListener(new onClickListenerDiagramLines());
optionMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popup.show();
}
});
prefs = PreferenceManager.getDefaultSharedPreferences(graphView.getContext());
@@ -217,6 +226,34 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
}
});
popup = new PopupMenu(getContext(), optionMenu);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.enableMonth:
if (item.isChecked()) {
item.setChecked(false);
prefs.edit().putBoolean("showMonth", false).commit();
} else {
item.setChecked(true);
prefs.edit().putBoolean("showMonth", true).commit();
}
generateGraphs();
return true;
default:
return false;
}
}
});
popup.getMenuInflater().inflate(R.menu.graph_menu, popup.getMenu());
MenuItem enableMonth = popup.getMenu().findItem(R.id.enableMonth);
enableMonth.setChecked(prefs.getBoolean("showMonth", true));
openScale.registerFragment(this);
return graphView;
@@ -417,12 +454,6 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
diagramBone.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
}
if (prefs.getBoolean(String.valueOf(enableMonth.getId()), true)) {
enableMonth.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_BLUE));
} else {
enableMonth.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#d3d3d3")));
}
LineChartData lineData = new LineChartData(lines);
lineData.setAxisXBottom(new Axis(axisValues).
setHasLines(true).
@@ -548,7 +579,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
}
// show monthly diagram
if (prefs.getBoolean(String.valueOf(enableMonth.getId()), true)) {
if (prefs.getBoolean("showMonth", true)) {
chartTop.setVisibility(View.VISIBLE);
chartBottom.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 0.7f));

View File

@@ -34,6 +34,7 @@ import android.text.Spanned;
import android.text.SpannedString;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -43,6 +44,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
@@ -76,8 +78,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import lecho.lib.hellocharts.util.ChartUtils;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class TableFragment extends Fragment implements FragmentUpdateListener {
@@ -87,6 +87,9 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
private SharedPreferences prefs;
private LinearLayout subpageView;
private ImageView optionMenu;
private PopupMenu popup;
private ArrayList <MeasurementView> measurementsList;
private int selectedSubpageNr;
@@ -106,8 +109,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
tableDataView = (ListView) tableView.findViewById(R.id.tableDataView);
tableHeaderView = (LinearLayout) tableView.findViewById(R.id.tableHeaderView);
tableView.findViewById(R.id.btnImportData).setOnClickListener(new onClickListenerImport());
tableView.findViewById(R.id.btnExportData).setOnClickListener(new onClickListenerExport());
optionMenu = (ImageView) tableView.findViewById(R.id.optionMenu);
measurementsList = new ArrayList<>();
@@ -140,6 +142,42 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
selectedSubpageNr = savedInstanceState.getInt(SELECTED_SUBPAGE_NR_KEY);
}
optionMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popup.show();
}
});
popup = new PopupMenu(getContext(), optionMenu);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.importData:
if (PermissionHelper.requestReadPermission(getActivity())) {
importTable();
}
return true;
case R.id.exportData:
if (PermissionHelper.requestWritePermission(getActivity())) {
exportTable();
}
return true;
case R.id.shareData:
if (PermissionHelper.requestWritePermission(getActivity())) {
shareTable();
}
return true;
default:
return false;
}
}
});
popup.getMenuInflater().inflate(R.menu.table_menu, popup.getMenu());
OpenScale.getInstance(getContext()).registerFragment(this);
return tableView;
@@ -160,7 +198,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
return;
}
final int maxSize = 50;
final int maxSize = 25;
int subpageCount = (int)Math.ceil(scaleMeasurementList.size() / (double)maxSize);
@@ -182,6 +220,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
TextView subpageNrView = new TextView(tableView.getContext());
subpageNrView.setOnClickListener(new onClickListenerSubpageSelect());
subpageNrView.setText(Integer.toString(i+1));
subpageNrView.setTextColor(Color.GRAY);
subpageNrView.setPadding(10, 10, 20, 10);
subpageView.addView(subpageNrView);
@@ -190,7 +229,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
TextView selectedSubpageNrView = (TextView) subpageView.getChildAt(selectedSubpageNr + 1);
if (selectedSubpageNrView != null) {
selectedSubpageNrView.setTypeface(null, Typeface.BOLD);
selectedSubpageNrView.setTextColor(ChartUtils.COLOR_BLUE);
selectedSubpageNrView.setTextColor(Color.WHITE);
}
}
@@ -206,12 +245,6 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
moveSubpageRight.setEnabled(selectedSubpageNr + 1 < subpageCount);
subpageView.addView(moveSubpageRight);
if (subpageCount <= 1) {
subpageView.setVisibility(View.GONE);
} else {
subpageView.setVisibility(View.VISIBLE);
}
tableHeaderView.removeAllViews();
for (MeasurementView measurement : measurementsList) {
@@ -288,15 +321,6 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
startActivityForResult(intent, 1); }
}
private class onClickListenerImport implements View.OnClickListener {
@Override
public void onClick(View v) {
if (PermissionHelper.requestReadPermission(getActivity())) {
importTable();
}
}
}
private void importTable() {
int selectedUserId = OpenScale.getInstance(getContext()).getSelectedScaleUserId();
@@ -343,15 +367,6 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
}
}
private class onClickListenerExport implements View.OnClickListener {
@Override
public void onClick(View v) {
if (PermissionHelper.requestWritePermission(getActivity())) {
exportTable();
}
}
}
private void exportTable() {
AlertDialog.Builder filenameDialog = new AlertDialog.Builder(getActivity());
@@ -377,33 +392,40 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
}
});
filenameDialog.setNeutralButton(getResources().getString(R.string.label_share), new DialogInterface.OnClickListener() {
filenameDialog.setNegativeButton(getResources().getString(R.string.label_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String fullPath = Environment.getExternalStorageDirectory().getPath() + "/tmp/" + txtFilename.getText().toString();
if (!OpenScale.getInstance(getContext()).exportData(fullPath)) {
return;
}
Intent intentShareFile = new Intent(Intent.ACTION_SEND);
File shareFile = new File(fullPath);
if(shareFile.exists()) {
intentShareFile.setType("text/comma-separated-values");
intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fullPath));
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, "openScale export csv file");
intentShareFile.putExtra(Intent.EXTRA_TEXT, txtFilename.getText().toString());
startActivity(Intent.createChooser(intentShareFile, getResources().getString(R.string.label_share)));
}
dialog.dismiss();
}
});
filenameDialog.show();
}
private void shareTable() {
final ScaleUser selectedScaleUser = OpenScale.getInstance(getContext()).getSelectedScaleUser();
String exportFilename = prefs.getString("exportFilename" + selectedScaleUser.getId(), "openScale_data_" + selectedScaleUser.getUserName() + ".csv");
String fullPath = Environment.getExternalStorageDirectory().getPath() + "/tmp/" + exportFilename;
if (!OpenScale.getInstance(getContext()).exportData(fullPath)) {
return;
}
Intent intentShareFile = new Intent(Intent.ACTION_SEND);
File shareFile = new File(fullPath);
if(shareFile.exists()) {
intentShareFile.setType("text/comma-separated-values");
intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fullPath));
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, "openScale export csv file");
intentShareFile.putExtra(Intent.EXTRA_TEXT, exportFilename);
startActivity(Intent.createChooser(intentShareFile, getResources().getString(R.string.label_share)));
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

View File

@@ -1,10 +1,83 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="left"
android:layout_weight="1"
android:orientation="horizontal">
</LinearLayout>
<Button
android:id="@+id/btnLeftYear"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="@drawable/flat_selector"
android:text="&lt;"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/txtYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0"
android:gravity="center"
android:text="year"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white"
android:textStyle="bold" />
<Button
android:id="@+id/btnRightYear"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_weight="0"
android:background="@drawable/flat_selector"
android:text=">"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/colorHack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="right"
android:layout_weight="0.9"
android:orientation="horizontal">
<ImageView
android:id="@+id/optionMenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:tint="@android:color/white"
app:srcCompat="@drawable/ic_options" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@@ -114,55 +187,6 @@
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="?attr/colorPrimary"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="@+id/btnLeftYear"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="@drawable/flat_selector"
android:text="&lt;"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/txtYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0"
android:gravity="center"
android:text="year"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/white"
android:textStyle="bold" />
<Button
android:id="@+id/btnRightYear"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_weight="0"
android:background="@drawable/flat_selector"
android:text=">"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/colorHack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
<lecho.lib.hellocharts.view.ColumnChartView
android:id="@+id/chart_top"
android:layout_width="match_parent"
@@ -178,16 +202,4 @@
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/enableMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_lastmonth"
app:backgroundTint="#33B5E5"
app:layout_anchor="@id/chart_bottom"
app:layout_anchorGravity="bottom|right|end"
app:rippleColor="#33B5E5" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>

View File

@@ -6,12 +6,48 @@
android:weightSum="1">
<LinearLayout
android:id="@+id/subpageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:background="?attr/colorPrimary"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="left"
android:layout_weight="1"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:id="@+id/subpageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="center"
android:layout_weight="0"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="right"
android:layout_weight="0.9"
android:orientation="horizontal">
<ImageView
android:id="@+id/optionMenu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:tint="@android:color/white"
app:srcCompat="@drawable/ic_options" />
</LinearLayout>
</LinearLayout>
<LinearLayout
@@ -20,7 +56,8 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"></LinearLayout>
android:paddingTop="5dp">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
@@ -35,36 +72,4 @@
android:layout_height="match_parent">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.1"
android:gravity="bottom"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="@+id/btnImportData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.5"
android:background="@drawable/flat_selector"
android:text="@string/label_import"
android:textColor="@android:color/white" />
<Button
android:id="@+id/btnExportData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0.5"
android:background="@drawable/flat_selector"
android:text="@string/label_export"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.openscale.MainActivity">
<item
android:id="@+id/enableMonth"
android:title="@string/label_month_view"
android:checkable="true"/>
</menu>

View File

@@ -0,0 +1,16 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.openscale.MainActivity">
<item
android:id="@+id/importData"
android:title="@string/label_import"/>
<item
android:id="@+id/exportData"
android:title="@string/label_export"/>
<item
android:id="@+id/shareData"
android:title="@string/label_share"/>
</menu>

View File

@@ -216,6 +216,8 @@
<string name="edit">Edit</string>
<string name="save">Save</string>
<string name="label_month_view">Month view</string>
<string name="permission_not_granted">Permission not granted</string>
<string name="permission_bluetooth_info">openScale requires permission to access the coarse location to search for Bluetooth devices</string>
<string name="permission_bluetooth_info_title">Information</string>