mirror of
https://github.com/Team4388/RidgeScout.git
synced 2026-06-09 00:37:59 -06:00
Add better dropdown
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
@@ -28,11 +29,6 @@ import com.ridgebotics.ridgescout.types.data.dataType;
|
||||
import com.ridgebotics.ridgescout.types.data.intType;
|
||||
import com.ridgebotics.ridgescout.utility.BuiltByteParser;
|
||||
import com.ridgebotics.ridgescout.utility.ByteBuilder;
|
||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||
import com.skydoves.powerspinner.SpinnerGravity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import static com.google.android.material.internal.ContextUtils.getActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
@@ -13,6 +16,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.ridgebotics.ridgescout.types.data.dataType;
|
||||
import com.ridgebotics.ridgescout.types.data.intType;
|
||||
import com.ridgebotics.ridgescout.ui.CustomSpinnerView;
|
||||
import com.ridgebotics.ridgescout.utility.BuiltByteParser;
|
||||
import com.ridgebotics.ridgescout.utility.ByteBuilder;
|
||||
import com.github.mikephil.charting.charts.LineChart;
|
||||
@@ -24,13 +28,9 @@ import com.github.mikephil.charting.data.LineDataSet;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.data.PieEntry;
|
||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||
import com.skydoves.powerspinner.SpinnerGravity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -65,51 +65,19 @@ public class dropdownType extends inputType {
|
||||
text_options = (String[]) objects.get(2).get();
|
||||
}
|
||||
|
||||
public PowerSpinnerView dropdown = null;
|
||||
public CustomSpinnerView dropdown = null;
|
||||
|
||||
public View createView(Context context, Function<dataType, Integer> onUpdate){
|
||||
dropdown = new PowerSpinnerView(context);
|
||||
dropdown = new CustomSpinnerView(context);
|
||||
|
||||
List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
|
||||
for(int i = 0; i < text_options.length; i++){
|
||||
iconSpinnerItems.add(new IconSpinnerItem(text_options[i]));
|
||||
}
|
||||
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
|
||||
ArrayList<String> iconSpinnerItems = new ArrayList<>(Arrays.asList(text_options));
|
||||
|
||||
dropdown.setGravity(Gravity.CENTER);
|
||||
dropdown.setTitle(name);
|
||||
dropdown.setOptions(iconSpinnerItems);
|
||||
onUpdate.apply(getViewValue());
|
||||
|
||||
dropdown.setSpinnerAdapter(iconSpinnerAdapter);
|
||||
dropdown.setItems(iconSpinnerItems);
|
||||
dropdown.setOnClickListener((item, index) -> onUpdate.apply(getViewValue()));
|
||||
|
||||
dropdown.selectItemByIndex((int) default_value);
|
||||
|
||||
dropdown.setPadding(10,20,10,20);
|
||||
dropdown.setBackgroundColor(0xf0000000);
|
||||
dropdown.setTextColor(0xff00ff00);
|
||||
dropdown.setTextSize(14.5f);
|
||||
dropdown.setArrowGravity(SpinnerGravity.END);
|
||||
dropdown.setArrowPadding(8);
|
||||
// dropdown.setSpinnerItemHeight(46);
|
||||
dropdown.setSpinnerPopupElevation(14);
|
||||
|
||||
|
||||
|
||||
|
||||
dropdown.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<IconSpinnerItem>() {
|
||||
@Override
|
||||
public void onItemSelected(int oldIndex, @Nullable IconSpinnerItem oldItem, int newIndex,
|
||||
IconSpinnerItem newItem) {
|
||||
onUpdate.apply(getViewValue());
|
||||
}
|
||||
});
|
||||
|
||||
// dropdown.setLifecycleOwner(context.life);
|
||||
// slider.addOnChangeListener(new Slider.OnChangeListener() {
|
||||
// @Override
|
||||
// public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
|
||||
// onUpdate.apply(getViewValue());
|
||||
// }
|
||||
// });
|
||||
return dropdown;
|
||||
|
||||
}
|
||||
@@ -123,7 +91,7 @@ public class dropdownType extends inputType {
|
||||
isBlank = false;
|
||||
|
||||
dropdown.setVisibility(View.VISIBLE);
|
||||
dropdown.selectItemByIndex((int) value);
|
||||
dropdown.setOption((int) value);
|
||||
}
|
||||
public void nullify(){
|
||||
isBlank = true;
|
||||
@@ -132,7 +100,7 @@ public class dropdownType extends inputType {
|
||||
public dataType getViewValue(){
|
||||
if(dropdown == null) return null;
|
||||
if(dropdown.getVisibility() == View.GONE) return new intType(name, intType.nullval);
|
||||
return new intType(name, dropdown.getSelectedIndex());
|
||||
return new intType(name, dropdown.getIndex());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import static android.text.InputType.TYPE_CLASS_NUMBER;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.Editable;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import static android.text.InputType.TYPE_CLASS_NUMBER;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.Editable;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.view.Gravity;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ridgebotics.ridgescout.types.input;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.Editable;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.ridgebotics.ridgescout.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.MaterialToolbar;
|
||||
import com.ridgebotics.ridgescout.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomSpinner extends DialogFragment {
|
||||
private List<String> options;
|
||||
private OnOptionSelectedListener listener;
|
||||
private RecyclerView recyclerView;
|
||||
private CustomSpinnerOptionsAdapter adapter;
|
||||
|
||||
public interface OnOptionSelectedListener {
|
||||
void onOptionSelected(String option);
|
||||
}
|
||||
|
||||
public static CustomSpinner newInstance(ArrayList<String> options) {
|
||||
CustomSpinner dialog = new CustomSpinner();
|
||||
Bundle args = new Bundle();
|
||||
args.putStringArrayList("options", options);
|
||||
dialog.setArguments(args);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle);
|
||||
if (getArguments() != null) {
|
||||
options = getArguments().getStringArrayList("options");
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.view_custom_spinner, container, false);
|
||||
|
||||
// Setup toolbar
|
||||
MaterialToolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
toolbar.setNavigationOnClickListener(v -> dismiss());
|
||||
toolbar.setTitle("Select an Option");
|
||||
|
||||
// Setup RecyclerView
|
||||
recyclerView = view.findViewById(R.id.recyclerView);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapter = new CustomSpinnerOptionsAdapter(options, option -> {
|
||||
if (listener != null) {
|
||||
listener.onOptionSelected(option);
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setOnOptionSelectedListener(OnOptionSelectedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.ridgebotics.ridgescout.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TableLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.MaterialToolbar;
|
||||
import com.google.android.material.divider.MaterialDivider;
|
||||
import com.ridgebotics.ridgescout.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomSpinnerPopup extends TableLayout {
|
||||
private List<String> options;
|
||||
private OnOptionSelectedListener listener;
|
||||
private RecyclerView recyclerView;
|
||||
private CustomSpinnerOptionsAdapter adapter;
|
||||
|
||||
public CustomSpinnerPopup(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CustomSpinnerPopup(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public interface OnOptionSelectedListener {
|
||||
void onOptionSelected(String option);
|
||||
}
|
||||
|
||||
// private int selectedIndex = -1;
|
||||
// public void setValue()
|
||||
|
||||
|
||||
public CustomSpinnerPopup init(List<String> options, OnOptionSelectedListener onOptionSelectedListener){
|
||||
CheckBox[] checkBoxes = new CheckBox[options.size()];
|
||||
setPadding(16, 16, 16, 16);
|
||||
for(int i = 0; i < options.size(); i++){
|
||||
final CheckBox cb = new CheckBox(getContext());
|
||||
cb.setText(options.get(i));
|
||||
cb.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Headline5);
|
||||
|
||||
addView(new MaterialDivider(getContext()));
|
||||
// cb.margin
|
||||
|
||||
addView(cb);
|
||||
checkBoxes[i] = cb;
|
||||
|
||||
final int fi = i;
|
||||
cb.setOnClickListener(a -> {
|
||||
onOptionSelectedListener.onOptionSelected(options.get(fi));
|
||||
for (CheckBox checkBox : checkBoxes)
|
||||
checkBox.setChecked(false);
|
||||
cb.setChecked(true);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// public static CustomSpinnerPopup newInstance(ArrayList<String> options) {
|
||||
// CustomSpinnerPopup dialog = new CustomSpinnerPopup();
|
||||
// Bundle args = new Bundle();
|
||||
// args.putStringArrayList("options", options);
|
||||
//
|
||||
//
|
||||
//
|
||||
//// dialog.setArguments(args);
|
||||
// return dialog;
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// public void onCreate(Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
// setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle);
|
||||
// if (getArguments() != null) {
|
||||
// options = getArguments().getStringArrayList("options");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
// @Nullable Bundle savedInstanceState) {
|
||||
// View view = inflater.inflate(R.layout.view_custom_spinner_popup, container, false);
|
||||
//
|
||||
// // Setup toolbar
|
||||
// MaterialToolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
// toolbar.setNavigationOnClickListener(v -> dismiss());
|
||||
// toolbar.setTitle("Select an Option");
|
||||
//
|
||||
// // Setup RecyclerView
|
||||
// recyclerView = view.findViewById(R.id.recyclerView);
|
||||
// recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
// adapter = new CustomSpinnerOptionsAdapter(options, option -> {
|
||||
// if (listener != null) {
|
||||
// listener.onOptionSelected(option);
|
||||
// }
|
||||
// dismiss();
|
||||
// });
|
||||
// recyclerView.setAdapter(adapter);
|
||||
//
|
||||
// return view;
|
||||
// }
|
||||
//
|
||||
public void setOnOptionSelectedListener(OnOptionSelectedListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.ridgebotics.ridgescout.ui;
|
||||
|
||||
import static android.app.PendingIntent.getActivity;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.getEditor;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.ridgebotics.ridgescout.R;
|
||||
import com.ridgebotics.ridgescout.databinding.ViewCustomSpinnerBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomSpinnerView extends LinearLayout {
|
||||
|
||||
public interface onClickListener {
|
||||
void onClick(String item, int index);
|
||||
}
|
||||
|
||||
public CustomSpinnerView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public CustomSpinnerView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private ViewCustomSpinnerBinding binding;
|
||||
|
||||
private List<String> options;
|
||||
private CustomSpinnerPopup dialog;
|
||||
private onClickListener onClickListener;
|
||||
|
||||
private TextView title;
|
||||
private TextView item;
|
||||
|
||||
private int index = -1;
|
||||
|
||||
public void init(Context context) {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_custom_spinner, this, true);
|
||||
|
||||
title = findViewById(R.id.title);
|
||||
item = findViewById(R.id.item);
|
||||
}
|
||||
|
||||
public void setOnClickListener(onClickListener listener){
|
||||
this.onClickListener = listener;
|
||||
}
|
||||
|
||||
public void setOptions(List<String> options){
|
||||
this.options = options;
|
||||
// dialog = CustomSpinnerPopup.newInstance(options);
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setPositiveButton("OK", (dialog, which) -> {});
|
||||
CustomSpinnerPopup popup = new CustomSpinnerPopup(getContext()).init(options, option -> {
|
||||
// dialog.();
|
||||
if(!isEnabled()) return;
|
||||
item.setText(option);
|
||||
if(onClickListener != null) {
|
||||
onClickListener.onClick(option, options.indexOf(option));
|
||||
index = options.indexOf(option);
|
||||
}
|
||||
});
|
||||
popup.setLayoutDirection(0);
|
||||
builder.setView(popup);
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
|
||||
// popup.setOnOptionSelectedListener();
|
||||
|
||||
this.setOnClickListener(v -> {
|
||||
if(!isEnabled()) return;
|
||||
dialog.show();
|
||||
});
|
||||
}
|
||||
|
||||
public void setTitle(String text){
|
||||
title.setText(text);
|
||||
}
|
||||
|
||||
public void setOption(String option) {
|
||||
item.setText(option);
|
||||
}
|
||||
|
||||
public void setOption(int index) {
|
||||
setOption(options.get(index));
|
||||
}
|
||||
|
||||
public int getIndex(){
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,8 @@ import com.ridgebotics.ridgescout.types.input.numberType;
|
||||
import com.ridgebotics.ridgescout.types.input.sliderType;
|
||||
import com.ridgebotics.ridgescout.types.input.tallyType;
|
||||
import com.ridgebotics.ridgescout.types.input.textType;
|
||||
import com.ridgebotics.ridgescout.ui.CustomSpinnerView;
|
||||
import com.ridgebotics.ridgescout.utility.AlertManager;
|
||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||
import com.skydoves.powerspinner.SpinnerGravity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -401,53 +398,27 @@ public class FieldsFragment extends Fragment {
|
||||
|
||||
private void addField_Part_2(String title) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle("Title");
|
||||
builder.setTitle("Select Type");
|
||||
|
||||
final PowerSpinnerView dropdown = new PowerSpinnerView(getContext());
|
||||
final CustomSpinnerView dropdown = new CustomSpinnerView(getContext());
|
||||
List<String> options = new ArrayList<>();
|
||||
|
||||
List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
|
||||
options.add("Slider");
|
||||
options.add("Text");
|
||||
options.add("Dropdown");
|
||||
options.add("Tally");
|
||||
options.add("Number");
|
||||
options.add("Checkbox");
|
||||
options.add("Field Position");
|
||||
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Slider"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Text"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Dropdown"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Tally"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Number"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Checkbox"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Field Position"));
|
||||
|
||||
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
|
||||
|
||||
dropdown.setGravity(Gravity.CENTER);
|
||||
|
||||
dropdown.setSpinnerAdapter(iconSpinnerAdapter);
|
||||
dropdown.setItems(iconSpinnerItems);
|
||||
|
||||
dropdown.selectItemByIndex(0);
|
||||
|
||||
dropdown.setPadding(10,20,10,20);
|
||||
dropdown.setBackgroundColor(0xf0000000);
|
||||
dropdown.setTextColor(0xff00ff00);
|
||||
dropdown.setTextSize(14.5f);
|
||||
dropdown.setArrowGravity(SpinnerGravity.END);
|
||||
dropdown.setArrowPadding(8);
|
||||
// dropdown.setSpinnerItemHeight(46);
|
||||
dropdown.setSpinnerPopupElevation(14);
|
||||
dropdown.setOptions(options);
|
||||
dropdown.setTitle("Type");
|
||||
dropdown.setOption(0);
|
||||
|
||||
builder.setView(dropdown);
|
||||
|
||||
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
addField_Part_3(title, dropdown.getSelectedIndex());
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("Cancel", (dialog, which) -> dialog.cancel());
|
||||
builder.setPositiveButton("OK", (dialog, which) -> addField_Part_3(title, dropdown.getIndex()));
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@@ -31,11 +31,6 @@ import com.ridgebotics.ridgescout.types.frcTeam;
|
||||
import com.ridgebotics.ridgescout.utility.DataManager;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
import com.google.android.material.divider.MaterialDivider;
|
||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||
import com.skydoves.powerspinner.SpinnerGravity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -83,44 +78,44 @@ public class TeamsFragment extends Fragment {
|
||||
|
||||
|
||||
|
||||
PowerSpinnerView dropdown = new PowerSpinnerView(getContext());
|
||||
|
||||
List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
|
||||
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Individual"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("Compiled"));
|
||||
iconSpinnerItems.add(new IconSpinnerItem("History"));
|
||||
|
||||
IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
|
||||
dropdown.setSpinnerAdapter(iconSpinnerAdapter);
|
||||
dropdown.setItems(iconSpinnerItems);
|
||||
|
||||
dropdown.selectItemByIndex(0);
|
||||
|
||||
dropdown.setPadding(10,20,10,20);
|
||||
dropdown.setBackgroundColor(0xf0000000);
|
||||
dropdown.setTextColor(0xff00ff00);
|
||||
dropdown.setTextSize(15);
|
||||
dropdown.setArrowGravity(SpinnerGravity.END);
|
||||
dropdown.setArrowPadding(8);
|
||||
// dropdown.setSpinnerItemHeight(46);
|
||||
dropdown.setSpinnerPopupElevation(14);
|
||||
|
||||
|
||||
dropdown.selectItemByIndex(mode);
|
||||
|
||||
|
||||
dropdown.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<IconSpinnerItem>() {
|
||||
@Override
|
||||
public void onItemSelected(int oldIndex, @Nullable IconSpinnerItem oldItem, int newIndex,
|
||||
IconSpinnerItem newItem) {
|
||||
|
||||
settingsManager.setDataMode(newIndex);
|
||||
loadTeam(newIndex);
|
||||
}
|
||||
});
|
||||
|
||||
ll.addView(dropdown);
|
||||
// PowerSpinnerView dropdown = new PowerSpinnerView(getContext());
|
||||
//
|
||||
// List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
|
||||
//
|
||||
// iconSpinnerItems.add(new IconSpinnerItem("Individual"));
|
||||
// iconSpinnerItems.add(new IconSpinnerItem("Compiled"));
|
||||
// iconSpinnerItems.add(new IconSpinnerItem("History"));
|
||||
//
|
||||
// IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
|
||||
// dropdown.setSpinnerAdapter(iconSpinnerAdapter);
|
||||
// dropdown.setItems(iconSpinnerItems);
|
||||
//
|
||||
// dropdown.selectItemByIndex(0);
|
||||
//
|
||||
// dropdown.setPadding(10,20,10,20);
|
||||
// dropdown.setBackgroundColor(0xf0000000);
|
||||
// dropdown.setTextColor(0xff00ff00);
|
||||
// dropdown.setTextSize(15);
|
||||
// dropdown.setArrowGravity(SpinnerGravity.END);
|
||||
// dropdown.setArrowPadding(8);
|
||||
//// dropdown.setSpinnerItemHeight(46);
|
||||
// dropdown.setSpinnerPopupElevation(14);
|
||||
//
|
||||
//
|
||||
// dropdown.selectItemByIndex(mode);
|
||||
//
|
||||
//
|
||||
// dropdown.setOnSpinnerItemSelectedListener(new OnSpinnerItemSelectedListener<IconSpinnerItem>() {
|
||||
// @Override
|
||||
// public void onItemSelected(int oldIndex, @Nullable IconSpinnerItem oldItem, int newIndex,
|
||||
// IconSpinnerItem newItem) {
|
||||
//
|
||||
// settingsManager.setDataMode(newIndex);
|
||||
// loadTeam(newIndex);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// ll.addView(dropdown);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -198,14 +198,11 @@ public class MatchScoutingFragment extends Fragment {
|
||||
|
||||
default_text_color = tv.getCurrentTextColor();
|
||||
|
||||
final View v = DataManager.match_latest_values[i].createView(getContext(), new Function<dataType, Integer>() {
|
||||
@Override
|
||||
public Integer apply(dataType dataType) {
|
||||
final View v = DataManager.match_latest_values[i].createView(getContext(), dataType -> {
|
||||
// edited = true;
|
||||
if(asm.isRunning)
|
||||
update_asm();
|
||||
return 0;
|
||||
}
|
||||
if(asm.isRunning)
|
||||
update_asm();
|
||||
return 0;
|
||||
});
|
||||
|
||||
binding.MatchScoutArea.addView(tv);
|
||||
|
||||
@@ -1,316 +1,47 @@
|
||||
package com.ridgebotics.ridgescout.ui.settings;
|
||||
|
||||
import static android.text.InputType.TYPE_CLASS_NUMBER;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.AllyPosKey;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.FTPEnabled;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.FTPSendMetaFiles;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.FTPServer;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.SelEVCodeKey;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.UnameKey;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.WifiModeKey;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.YearNumKey;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.defaults;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.getEditor;
|
||||
import static com.ridgebotics.ridgescout.utility.settingsManager.prefs;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.health.connect.datatypes.units.Power;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.checkbox.MaterialCheckBox;
|
||||
import com.google.android.material.divider.MaterialDivider;
|
||||
import com.google.android.material.textfield.MaterialAutoCompleteTextView;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.ridgebotics.ridgescout.databinding.FragmentSettingsBinding;
|
||||
import com.ridgebotics.ridgescout.types.data.intType;
|
||||
import com.ridgebotics.ridgescout.ui.CustomSpinner;
|
||||
import com.ridgebotics.ridgescout.ui.CustomSpinnerPopup;
|
||||
import com.ridgebotics.ridgescout.ui.CustomSpinnerView;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
import com.ridgebotics.ridgescout.utility.settingsManager;
|
||||
|
||||
import com.skydoves.powerspinner.IconSpinnerAdapter;
|
||||
import com.skydoves.powerspinner.IconSpinnerItem;
|
||||
import com.skydoves.powerspinner.OnSpinnerItemSelectedListener;
|
||||
import com.skydoves.powerspinner.PowerSpinnerView;
|
||||
import com.skydoves.powerspinner.SpinnerGravity;
|
||||
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
public class settingsFragment extends Fragment {
|
||||
private FragmentSettingsBinding binding;
|
||||
private android.widget.ScrollView ScrollArea;
|
||||
private android.widget.TableLayout Table;
|
||||
|
||||
// private void setDropdownItems(Spinner dropdown, String[] items){
|
||||
// ArrayAdapter<String> adapter = new ArrayAdapter<>(requireActivity(), android.R.layout.simple_spinner_item, items);
|
||||
// dropdown.setAdapter(adapter);
|
||||
// }
|
||||
|
||||
private View[] concatArrays(View[] a, View[] b){
|
||||
return Stream.of(a, b).flatMap(Stream::of).toArray(View[]::new);
|
||||
}
|
||||
|
||||
|
||||
private View[] addViews(View[] a){
|
||||
for(int i = 0; i < a.length; i++){
|
||||
binding.SettingsTable.addView(a[i]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private int safeToInt(String num){
|
||||
if(num.isEmpty())
|
||||
return 0;
|
||||
try {
|
||||
return Integer.parseInt(num);
|
||||
}catch (NumberFormatException e){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private View[] createHeading(String name){
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
TableRow.LayoutParams params = new TableRow.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
params.topMargin = 100;
|
||||
tv.setLayoutParams(params);
|
||||
tv.setTextSize(20);
|
||||
tv.setText(name);
|
||||
|
||||
View divider = new MaterialDivider(getContext());
|
||||
|
||||
return new View[]{tv, divider};
|
||||
}
|
||||
|
||||
private View[] addStringEdit(String name, String key){
|
||||
View[] heading = createHeading(name);
|
||||
EditText et = new EditText(getContext());
|
||||
et.setText(prefs.getString(key, (String) defaults.get(key)));
|
||||
|
||||
et.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
getEditor().putString(key, s.toString()).apply();
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
});
|
||||
return concatArrays(heading, new View[]{et});
|
||||
}
|
||||
|
||||
private View[] addNumberEdit(String name, String key){
|
||||
View[] heading = createHeading(name);
|
||||
EditText et = new EditText(getContext());
|
||||
et.setText(String.valueOf(prefs.getInt(key, (Integer) defaults.get(key))));
|
||||
et.setInputType(TYPE_CLASS_NUMBER);
|
||||
|
||||
et.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
getEditor().putInt(key, safeToInt(s.toString())).apply();
|
||||
}
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
});
|
||||
return concatArrays(heading, new View[]{et});
|
||||
}
|
||||
|
||||
private TextInputLayout addDropdownEdit(String name, String[] options, String key){
|
||||
|
||||
int padding = (int) TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
16,
|
||||
getResources().getDisplayMetrics()
|
||||
);
|
||||
|
||||
// Create TextInputLayout
|
||||
TextInputLayout textInputLayout = new TextInputLayout(getContext(), null,
|
||||
com.google.android.material.R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox_ExposedDropdownMenu);
|
||||
LinearLayout.LayoutParams inputLayoutParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
textInputLayout.setLayoutParams(inputLayoutParams);
|
||||
textInputLayout.setHint("Select an item");
|
||||
|
||||
// Create MaterialAutoCompleteTextView
|
||||
MaterialAutoCompleteTextView dropdownText = new MaterialAutoCompleteTextView(getContext());
|
||||
TextInputLayout.LayoutParams dropdownParams = new TextInputLayout.LayoutParams(
|
||||
TextInputLayout.LayoutParams.MATCH_PARENT,
|
||||
TextInputLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
dropdownText.setLayoutParams(dropdownParams);
|
||||
dropdownText.setInputType(InputType.TYPE_NULL);
|
||||
|
||||
textInputLayout.addView(dropdownText);
|
||||
|
||||
|
||||
// Create item layout programmatically
|
||||
TextView itemView = new TextView(getContext());
|
||||
LinearLayout.LayoutParams itemParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
itemView.setLayoutParams(itemParams);
|
||||
itemView.setPadding(10, padding, padding, padding);
|
||||
itemView.setMaxLines(1);
|
||||
itemView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
itemView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1);
|
||||
|
||||
// Create and set adapter
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
|
||||
getContext(),
|
||||
android.R.layout.simple_dropdown_item_1line,
|
||||
options
|
||||
) {
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||
// Apply the same styling as our programmatic item layout
|
||||
textView.setPadding(padding, padding, padding, padding);
|
||||
textView.setMaxLines(1);
|
||||
textView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
textView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1);
|
||||
return textView;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// <com.google.android.material.textfield.TextInputLayout
|
||||
// android:layout_width="match_parent"
|
||||
// android:layout_height="wrap_content"
|
||||
// android:hint="Select an item"
|
||||
// style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
|
||||
//
|
||||
// <com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
// android:id="@+id/dropdown_text"
|
||||
// android:layout_width="match_parent"
|
||||
// android:layout_height="wrap_content"
|
||||
// android:inputType="none"/>
|
||||
//
|
||||
// </com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
// PowerSpinnerView dropdown = new PowerSpinnerView(getContext());
|
||||
//
|
||||
// List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
|
||||
// for(int i = 0; i < options.length; i++){
|
||||
// iconSpinnerItems.add(new IconSpinnerItem(options[i]));
|
||||
// }
|
||||
// IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
|
||||
//
|
||||
// dropdown.setGravity(Gravity.CENTER);
|
||||
//
|
||||
// dropdown.setSpinnerAdapter(iconSpinnerAdapter);
|
||||
// dropdown.setItems(iconSpinnerItems);
|
||||
// dropdown.setHint("Unselected");
|
||||
//
|
||||
// dropdown.setPadding(10,20,10,20);
|
||||
// dropdown.setBackgroundColor(0xf0000000);
|
||||
// dropdown.setTextColor(0xff00ff00);
|
||||
// dropdown.setTextSize(14.5f);
|
||||
// dropdown.setArrowGravity(SpinnerGravity.END);
|
||||
// dropdown.setArrowPadding(8);
|
||||
// dropdown.setSpinnerPopupElevation(14);
|
||||
|
||||
return textInputLayout;
|
||||
}
|
||||
|
||||
private View[] addDropdownByString(String name, String[] options, String key){
|
||||
View[] heading = createHeading(name);
|
||||
TextInputLayout dropdown = addDropdownEdit(name, options, key);
|
||||
int index = Arrays.asList(options).indexOf(prefs.getString(key, (String) defaults.get(key)));
|
||||
System.out.println(index);
|
||||
|
||||
|
||||
// dropdown.setOnSpinnerItemSelectedListener(
|
||||
// (OnSpinnerItemSelectedListener<IconSpinnerItem>)
|
||||
// (oldIndex, oldItem, newIndex, newItem) -> getEditor().putString(key, newItem.getText().toString()).apply()
|
||||
// );
|
||||
|
||||
return concatArrays(heading, new View[]{dropdown});
|
||||
}
|
||||
|
||||
private View[] addDropdownByIndex(String name, String[] options, String key){
|
||||
View[] heading = createHeading(name);
|
||||
TextInputLayout dropdown = addDropdownEdit(name, options, key);
|
||||
|
||||
int index = prefs.getInt(key, (Integer) defaults.get(key));
|
||||
|
||||
// if(dropdown.length() != 0 && index != -1){
|
||||
// dropdown.selectItemByIndex(index);
|
||||
// }
|
||||
//
|
||||
// dropdown.setOnSpinnerItemSelectedListener(
|
||||
// (OnSpinnerItemSelectedListener<IconSpinnerItem>)
|
||||
// (oldIndex, oldItem, newIndex, newItem) -> getEditor().putInt(key, newIndex).apply()
|
||||
// );
|
||||
|
||||
return concatArrays(heading, new View[]{dropdown});
|
||||
}
|
||||
|
||||
private View[] addCheckbox(String name, String key, View[] dependency){
|
||||
CheckBox cb = new CheckBox(getContext());
|
||||
cb.setText(name);
|
||||
cb.setTextSize(22);
|
||||
boolean checked = prefs.getBoolean(key, (Boolean) defaults.get(key));
|
||||
cb.setChecked(checked);
|
||||
|
||||
if(dependency != null && !checked){
|
||||
for(int i = 0; i < dependency.length; i++){
|
||||
dependency[i].setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
cb.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
getEditor().putBoolean(key, isChecked).apply();
|
||||
if(dependency != null){
|
||||
for(int i = 0; i < dependency.length; i++){
|
||||
dependency[i].setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
System.out.println(dependency[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return new View[]{new MaterialDivider(getContext()), cb};
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
@@ -323,33 +54,24 @@ public class settingsFragment extends Fragment {
|
||||
|
||||
SettingsManager manager = new SettingsManager(getContext());
|
||||
|
||||
manager.addItem(new StringSettingsItem(
|
||||
UnameKey,
|
||||
"Username",
|
||||
""
|
||||
));
|
||||
manager.addItem(new DropdownSettingsItem(SelEVCodeKey, "Event Code", "", fileEditor.getEventList().toArray(new String[0])));
|
||||
manager.addItem(new DropdownSettingsItem(AllyPosKey, "Alliance Pos", "", alliance_pos_list));
|
||||
|
||||
|
||||
StringSettingsItem FTPServer = new StringSettingsItem(settingsManager.FTPServer, "FTP Server");
|
||||
manager.addItem(FTPServer);
|
||||
CheckboxSettingsItem FTPSendMetaFiles = new CheckboxSettingsItem(settingsManager.FTPSendMetaFiles, "Send meta files");
|
||||
manager.addItem(FTPSendMetaFiles);
|
||||
CheckboxSettingsItem FTPEnabled = new CheckboxSettingsItem(settingsManager.FTPEnabled, "FTP Enabled", FTPServer, FTPSendMetaFiles);
|
||||
manager.addItem(FTPEnabled);
|
||||
|
||||
binding.SettingsTable.addView(manager.getSettingsView());
|
||||
manager.addItem(new CheckboxSettingsItem(WifiModeKey, "Wifi Mode", FTPEnabled));
|
||||
|
||||
// addViews(addStringEdit("Username", UnameKey));
|
||||
// addViews(addDropdownByString("Event Code", fileEditor.getEventList().toArray(new String[0]), SelEVCodeKey));
|
||||
// addViews(addDropdownByString("Alliance Position", alliance_pos_list, AllyPosKey));
|
||||
// addViews(addNumberEdit("Team Number", TeamNumKey));
|
||||
//
|
||||
// View[] FTPDependency = concatArrays(
|
||||
// addCheckbox("Send Meta Files", FTPSendMetaFiles, new View[]{}),
|
||||
// addStringEdit("FTP Server", FTPServer)
|
||||
// );
|
||||
//
|
||||
// View[] WifiDependency = addCheckbox("FTP Enabled", FTPEnabled, FTPDependency);
|
||||
// addViews(addCheckbox("Wifi Mode", WifiModeKey, concatArrays(FTPDependency, WifiDependency)));
|
||||
// addViews(WifiDependency);
|
||||
// addViews(FTPDependency);
|
||||
manager.addItem(new NumberSettingsItem(YearNumKey, "Year", 0, 9999));
|
||||
|
||||
manager.addItem(new DropdownSettingsItem(AllyPosKey, "Alliance Pos", alliance_pos_list));
|
||||
manager.addItem(new DropdownSettingsItem(SelEVCodeKey, "Event Code", fileEditor.getEventList().toArray(new String[0])));
|
||||
manager.addItem(new StringSettingsItem(UnameKey, "Username"));
|
||||
|
||||
manager.getView(binding.SettingsTable);
|
||||
|
||||
|
||||
return root;
|
||||
@@ -378,14 +100,11 @@ public class settingsFragment extends Fragment {
|
||||
public abstract class SettingsItem<T> {
|
||||
private String key;
|
||||
private String title;
|
||||
private String description;
|
||||
private T defaultValue;
|
||||
private boolean enabled = true;
|
||||
|
||||
public SettingsItem(String key, String title, String description, T defaultValue) {
|
||||
public SettingsItem(String key, String title, T defaultValue) {
|
||||
this.key = key;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
@@ -394,15 +113,20 @@ public class settingsFragment extends Fragment {
|
||||
|
||||
public String getKey() { return key; }
|
||||
public String getTitle() { return title; }
|
||||
public String getDescription() { return description; }
|
||||
public T getDefaultValue() { return defaultValue; }
|
||||
public void setEnabled(boolean enabled) { this.enabled = enabled; }
|
||||
public boolean isEnabled() { return enabled; }
|
||||
public abstract void setEnabled(boolean enabled);
|
||||
}
|
||||
|
||||
public class StringSettingsItem extends SettingsItem<String> {
|
||||
public StringSettingsItem(String key, String title, String description) {
|
||||
super(key, title, description, prefs.getString(key, (String) defaults.get(key)));
|
||||
public StringSettingsItem(String key, String title) {
|
||||
super(key, title, prefs.getString(key, (String) defaults.get(key)));
|
||||
}
|
||||
|
||||
TextInputEditText editText;
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled){
|
||||
editText.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,9 +137,8 @@ public class settingsFragment extends Fragment {
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
|
||||
TextInputEditText editText = new TextInputEditText(context);
|
||||
editText = new TextInputEditText(context);
|
||||
editText.setText(getValue());
|
||||
editText.setEnabled(isEnabled());
|
||||
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
@@ -444,20 +167,30 @@ public class settingsFragment extends Fragment {
|
||||
private int min;
|
||||
private int max;
|
||||
|
||||
public NumberSettingsItem(String key, String title, String description, int min, int max) {
|
||||
super(key, title, description, prefs.getInt(key, (int) defaults.get(key)));
|
||||
public NumberSettingsItem(String key, String title, int min, int max) {
|
||||
super(key, title, prefs.getInt(key, (int) defaults.get(key)));
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
TextInputEditText editText;
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled){
|
||||
editText.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(Context context) {
|
||||
TextView titleView = new TextView(context);
|
||||
titleView.setText(getTitle());
|
||||
titleView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1);
|
||||
|
||||
TextInputLayout textInputLayout = new TextInputLayout(context);
|
||||
TextInputEditText editText = new TextInputEditText(context);
|
||||
editText = new TextInputEditText(context);
|
||||
|
||||
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
editText.setText(getValue());
|
||||
editText.setEnabled(isEnabled());
|
||||
editText.setText(String.valueOf(getValue()));
|
||||
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
@@ -480,6 +213,7 @@ public class settingsFragment extends Fragment {
|
||||
});
|
||||
|
||||
textInputLayout.addView(editText);
|
||||
textInputLayout.addView(titleView);
|
||||
return textInputLayout;
|
||||
}
|
||||
|
||||
@@ -492,105 +226,38 @@ public class settingsFragment extends Fragment {
|
||||
public class DropdownSettingsItem extends SettingsItem<String> {
|
||||
private String[] options;
|
||||
|
||||
public DropdownSettingsItem(String key, String title, String description, String[] options) {
|
||||
super(key, title, description, prefs.getString(key, (String) defaults.get(key)));
|
||||
private boolean enabled = true;
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled){
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public DropdownSettingsItem(String key, String title, String[] options) {
|
||||
super(key, title, prefs.getString(key, (String) defaults.get(key)));
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(Context context) {
|
||||
TextInputLayout textInputLayout = new TextInputLayout(context);
|
||||
textInputLayout.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
CustomSpinnerView dropdown = new CustomSpinnerView(getContext());
|
||||
dropdown.setLayoutParams(new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
textInputLayout.setHint("Select " + getTitle());
|
||||
|
||||
|
||||
ArrayList<String> optionsList = new ArrayList<>(Arrays.asList(options));
|
||||
|
||||
TextView dropdown = new TextView(getContext());
|
||||
dropdown.setTitle(getTitle());
|
||||
dropdown.setOptions(optionsList);
|
||||
dropdown.setOption(getValue());
|
||||
|
||||
dropdown.setTextSize(24);
|
||||
dropdown.setText(getValue());
|
||||
|
||||
ArrayList optionsList = new ArrayList();
|
||||
for(int i = 0; i < options.length; i++)
|
||||
optionsList.add(options[i]);
|
||||
|
||||
CustomSpinner dialog = CustomSpinner.newInstance(optionsList);
|
||||
|
||||
dialog.setOnOptionSelectedListener(option -> {
|
||||
getEditor().putString(getKey(), option).apply();
|
||||
dropdown.setText(option);
|
||||
dropdown.setOnClickListener((item, index) -> {
|
||||
getEditor().putString(getKey(), item).apply();
|
||||
});
|
||||
|
||||
dropdown.setOnClickListener(v -> {
|
||||
dialog.show(getActivity().getSupportFragmentManager(), getTitle());
|
||||
});
|
||||
|
||||
// List<IconSpinnerItem> iconSpinnerItems = new ArrayList<>();
|
||||
// for(int i = 0; i < options.length; i++){
|
||||
// iconSpinnerItems.add(new IconSpinnerItem(options[i]));
|
||||
// }
|
||||
// IconSpinnerAdapter iconSpinnerAdapter = new IconSpinnerAdapter(dropdown);
|
||||
// dropdown.setSpinnerAdapter(iconSpinnerAdapter);
|
||||
//
|
||||
// dropdown.setEnabled(isEnabled());
|
||||
//
|
||||
// ArrayAdapter<String> adapter = new ArrayAdapter<>(
|
||||
// context,
|
||||
// android.R.layout.simple_spinner_dropdown_item,
|
||||
// options
|
||||
// );
|
||||
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
//
|
||||
// int index = Arrays.asList(options).indexOf(getValue());
|
||||
//
|
||||
// if(dropdown.length() != 0 && index != -1){
|
||||
// dropdown.selectItemByIndex(index);
|
||||
// }
|
||||
//
|
||||
// dropdown.setOnSpinnerItemSelectedListener(
|
||||
// (OnSpinnerItemSelectedListener<IconSpinnerItem>)
|
||||
// (oldIndex, oldItem, newIndex, newItem) -> getEditor().putString(getKey(), newItem.getText().toString()).apply());
|
||||
//
|
||||
// dropdown.setPadding(10,20,10,20);
|
||||
// dropdown.setBackgroundColor(0xf0000000);
|
||||
// dropdown.setTextColor(0xff00ff00);
|
||||
// dropdown.setTextSize(14.5f);
|
||||
// dropdown.setArrowGravity(SpinnerGravity.END);
|
||||
// dropdown.setArrowPadding(8);
|
||||
// dropdown.setSpinnerPopupElevation(14);
|
||||
|
||||
|
||||
// spinner.setAdapter(adapter);
|
||||
|
||||
// Set initial selection
|
||||
// String currentValue = getValue();
|
||||
// for (int i = 0; i < options.length; i++) {
|
||||
// if (options[i].equals(currentValue)) {
|
||||
// spinner.setSelection(i);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// spinner.setText(getValue());
|
||||
// spinner.setTextSize(24);
|
||||
|
||||
|
||||
// spinner.addOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
// @Override
|
||||
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
// settings.put(getKey(), options[position]);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNothingSelected(AdapterView<?> parent) {
|
||||
// settings.put(getKey(), getDefaultValue());
|
||||
// }
|
||||
// });
|
||||
|
||||
textInputLayout.addView(dropdown);
|
||||
return textInputLayout;
|
||||
return dropdown;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -602,17 +269,27 @@ public class settingsFragment extends Fragment {
|
||||
public class CheckboxSettingsItem extends SettingsItem<Boolean> {
|
||||
private List<SettingsItem<?>> controlledItems;
|
||||
|
||||
public CheckboxSettingsItem(String key, String title, String description, SettingsItem<?>... controlledItems) {
|
||||
super(key, title, description, prefs.getBoolean(key, (Boolean) defaults.get(key)));
|
||||
public CheckboxSettingsItem(String key, String title, SettingsItem<?>... controlledItems) {
|
||||
super(key, title, prefs.getBoolean(key, (Boolean) defaults.get(key)));
|
||||
this.controlledItems = Arrays.asList(controlledItems);
|
||||
}
|
||||
|
||||
MaterialCheckBox checkBox;
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled){
|
||||
checkBox.setEnabled(enabled);
|
||||
for (SettingsItem<?> item : controlledItems) {
|
||||
item.setEnabled(enabled && checkBox.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View createView(Context context) {
|
||||
MaterialCheckBox checkBox = new MaterialCheckBox(context);
|
||||
checkBox = new MaterialCheckBox(context);
|
||||
checkBox.setText(getTitle());
|
||||
checkBox.setChecked(getValue());
|
||||
|
||||
checkBox.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1);
|
||||
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
getEditor().putBoolean(getKey(), isChecked).apply();
|
||||
for (SettingsItem<?> item : controlledItems) {
|
||||
@@ -620,6 +297,10 @@ public class settingsFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
for (SettingsItem<?> item : controlledItems) {
|
||||
item.setEnabled(getValue());
|
||||
}
|
||||
|
||||
return checkBox;
|
||||
}
|
||||
|
||||
@@ -633,46 +314,34 @@ public class settingsFragment extends Fragment {
|
||||
private Context context;
|
||||
private HashMap<String, Object> settings;
|
||||
private List<SettingsItem<?>> items;
|
||||
private LinearLayout container;
|
||||
// private LinearLayout container;
|
||||
|
||||
public SettingsManager(Context context) {
|
||||
this.context = context;
|
||||
this.items = new ArrayList<>();
|
||||
this.container = new LinearLayout(context);
|
||||
this.container.setOrientation(LinearLayout.VERTICAL);
|
||||
this.container.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
// this.container = new LinearLayout(context);
|
||||
// this.container.setOrientation(LinearLayout.VERTICAL);
|
||||
// this.container.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
// LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
// LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
// ));
|
||||
}
|
||||
|
||||
private final List<View> views = new ArrayList<>();
|
||||
public void addItem(SettingsItem<?> item) {
|
||||
items.add(item);
|
||||
|
||||
MaterialCardView card = new MaterialCardView(context);
|
||||
LinearLayout itemContainer = new LinearLayout(context);
|
||||
itemContainer.setOrientation(LinearLayout.VERTICAL);
|
||||
itemContainer.setPadding(32, 16, 32, 16);
|
||||
itemContainer.setPadding(32, 0, 32, 8);
|
||||
|
||||
TextView titleView = new TextView(context);
|
||||
titleView.setText(item.getTitle());
|
||||
titleView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1);
|
||||
|
||||
TextView descriptionView = new TextView(context);
|
||||
descriptionView.setText(item.getDescription());
|
||||
descriptionView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Body2);
|
||||
|
||||
itemContainer.addView(titleView);
|
||||
itemContainer.addView(descriptionView);
|
||||
itemContainer.addView(item.createView(context));
|
||||
|
||||
card.addView(itemContainer);
|
||||
container.addView(card);
|
||||
views.add(itemContainer);
|
||||
}
|
||||
|
||||
public View getSettingsView() {
|
||||
return container;
|
||||
public void getView(LinearLayout layout) {
|
||||
for(int i = views.size()-1; i >= 0; i--)
|
||||
layout.addView(views.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.ridgebotics.ridgescout.types.frcMatch;
|
||||
import com.ridgebotics.ridgescout.types.frcTeam;
|
||||
import com.ridgebotics.ridgescout.utility.fileEditor;
|
||||
import com.ridgebotics.ridgescout.utility.JSONUtil;
|
||||
import com.ridgebotics.ridgescout.utility.settingsManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -41,7 +42,7 @@ public class TBAFragment extends Fragment {
|
||||
private android.widget.TableLayout Table;
|
||||
private FragmentTransferTbaBinding binding;
|
||||
|
||||
private static final int year = 2024;
|
||||
private static final int year = settingsManager.getYearNum();
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
Reference in New Issue
Block a user