alertdialog für device auswahl für plot
This commit is contained in:
parent
55f4998f78
commit
63e1518882
@ -1,30 +1,23 @@
|
|||||||
package com.example.aped.ui.plots;
|
package com.example.aped.ui.plots;
|
||||||
|
|
||||||
import android.net.sip.SipSession;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.Toast;
|
||||||
import com.example.aped.MainActivity;
|
import com.example.aped.MainActivity;
|
||||||
import com.example.aped.R;
|
import com.example.aped.R;
|
||||||
import com.example.aped.communication.Communicator;
|
import com.example.aped.communication.Communicator;
|
||||||
import com.example.aped.utils.IXML;
|
import com.example.aped.utils.IXML;
|
||||||
import com.example.aped.utils.XMLHandler;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Dictionary;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lecho.lib.hellocharts.model.AxisValue;
|
|
||||||
import lecho.lib.hellocharts.model.Line;
|
|
||||||
import lecho.lib.hellocharts.model.LineChartData;
|
|
||||||
import lecho.lib.hellocharts.model.PointValue;
|
|
||||||
import lecho.lib.hellocharts.view.LineChartView;
|
import lecho.lib.hellocharts.view.LineChartView;
|
||||||
|
|
||||||
public class PlotFragment extends Fragment {
|
public class PlotFragment extends Fragment {
|
||||||
@ -35,6 +28,8 @@ public class PlotFragment extends Fragment {
|
|||||||
private List<String> bufferedDevices;
|
private List<String> bufferedDevices;
|
||||||
/** Line Chart View that is displayed **/
|
/** Line Chart View that is displayed **/
|
||||||
private LineChartView lineChartView;
|
private LineChartView lineChartView;
|
||||||
|
/** List of all the devices with buffers. **/
|
||||||
|
private List<String> bufferedDevicesSelected;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* paul
|
* paul
|
||||||
@ -56,12 +51,46 @@ public class PlotFragment extends Fragment {
|
|||||||
|
|
||||||
getBufferedValues(mainActivity.getDelivery(), mainActivity.getXml());
|
getBufferedValues(mainActivity.getDelivery(), mainActivity.getXml());
|
||||||
mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots);
|
mainActivity.getConfigurationHandler().setCurrentView(R.id.nav_plots);
|
||||||
|
|
||||||
|
Button buttonChoseDevice = view.findViewById(R.id.button_alert);
|
||||||
|
buttonChoseDevice.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(final View v) {
|
||||||
|
bufferedDevicesSelected = new ArrayList<>();
|
||||||
|
MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(mainActivity);
|
||||||
|
alertDialogBuilder.setTitle("Choose your devices");
|
||||||
|
alertDialogBuilder.setMultiChoiceItems(bufferedDevices.toArray(new String[bufferedDevices.size()]), null, new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final DialogInterface dialog, final int which, final boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
bufferedDevicesSelected.add(bufferedDevices.get(which));
|
||||||
|
} else if (bufferedDevices.contains(bufferedDevices.get(which))) {
|
||||||
|
bufferedDevicesSelected.remove(bufferedDevices.get(which));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertDialogBuilder.setPositiveButton("display", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final DialogInterface dialog, final int which) {
|
||||||
|
String data = "";
|
||||||
|
for (String item:bufferedDevicesSelected) {
|
||||||
|
data = data + " " + item;
|
||||||
|
}
|
||||||
|
Toast.makeText(mainActivity, data, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
alertDialogBuilder.create();
|
||||||
|
alertDialogBuilder.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getBufferedDevices(IXML xml){
|
private List<String> getBufferedDevices(final IXML xml) {
|
||||||
List<String> returnList = new ArrayList<>();
|
List<String> returnList = new ArrayList<>();
|
||||||
for (String deviceName : xml.getDeviceNames()){
|
for (String deviceName : xml.getDeviceNames()) {
|
||||||
if (xml.getBufferSize(deviceName) > 0) {
|
if (xml.getBufferSize(deviceName) > 0) {
|
||||||
returnList.add(deviceName);
|
returnList.add(deviceName);
|
||||||
}
|
}
|
||||||
@ -69,22 +98,22 @@ public class PlotFragment extends Fragment {
|
|||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getBufferedValues(Communicator communicator, IXML xml){
|
private void getBufferedValues(final Communicator communicator, final IXML xml) {
|
||||||
for (String deviceName : this.bufferedDevices){
|
for (String deviceName : this.bufferedDevices) {
|
||||||
communicator.readBuffer(deviceName,response -> {
|
communicator.readBuffer(deviceName, response -> {
|
||||||
try {
|
try {
|
||||||
JSONObject buffer = response.getJSONObject("buffer");
|
JSONObject buffer = response.getJSONObject("buffer");
|
||||||
for(String pin : (List<String>) (xml.getPort(deviceName)).get("pins")) {
|
for (String pin : (List<String>) (xml.getPort(deviceName)).get("pins")) {
|
||||||
String valueString = buffer.getString(pin);
|
String valueString = buffer.getString(pin);
|
||||||
valueString = valueString.substring(2,valueString.length()-2);
|
valueString = valueString.substring(2, valueString.length() - 2);
|
||||||
String[] valueStringArray = valueString.split("', '");
|
String[] valueStringArray = valueString.split("', '");
|
||||||
int[] values = new int[valueString.length()];
|
int[] values = new int[valueString.length()];
|
||||||
for (int i = 0; i < valueStringArray.length; i++){
|
for (int i = 0; i < valueStringArray.length; i++) {
|
||||||
values[i] = Integer.parseInt(valueStringArray[i]);
|
values[i] = Integer.parseInt(valueStringArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//display data
|
//display data
|
||||||
List yAxisValues = new ArrayList();
|
/*List yAxisValues = new ArrayList();
|
||||||
for (int i = 0; i < values.length; i++){
|
for (int i = 0; i < values.length; i++){
|
||||||
yAxisValues.add(values[i]);
|
yAxisValues.add(values[i]);
|
||||||
}
|
}
|
||||||
@ -93,7 +122,7 @@ public class PlotFragment extends Fragment {
|
|||||||
lines.add(line);
|
lines.add(line);
|
||||||
LineChartData lineChartData = new LineChartData();
|
LineChartData lineChartData = new LineChartData();
|
||||||
lineChartData.setLines(lines);
|
lineChartData.setLines(lines);
|
||||||
this.lineChartView.setLineChartData(lineChartData);
|
this.lineChartView.setLineChartData(lineChartData);*/
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Log.e("PlotFragment", "error while parsing JSON on READ BUFFER: " + e.getMessage());
|
Log.e("PlotFragment", "error while parsing JSON on READ BUFFER: " + e.getMessage());
|
||||||
|
@ -9,4 +9,10 @@
|
|||||||
android:id="@+id/test_plot"
|
android:id="@+id/test_plot"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_alert"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="chose devices" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
x
Reference in New Issue
Block a user