Browse Source

App: Abzweigungsliste erstellt

master
Baran Yasar 1 year ago
parent
commit
ce8d424f95

+ 112
- 1
MobileApp/app/src/main/java/com/example/lfrmobileapp/ui/dashboard/DashboardFragment.java View File

@@ -1,21 +1,36 @@
package com.example.lfrmobileapp.ui.dashboard;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.example.lfrmobileapp.R;
import com.example.lfrmobileapp.databinding.FragmentAutomatikBinding;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;

import kotlin.collections.UArraySortingKt;

public class DashboardFragment extends Fragment {

private FragmentAutomatikBinding binding;

String listKey = "listkey";

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
DashboardViewModel dashboardViewModel =
@@ -26,6 +41,86 @@ public class DashboardFragment extends Fragment {

final TextView textView = binding.textDashboard;
dashboardViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();



ArrayList<String> autoList = stringToArraylist(sharedPref.getString(listKey, ""));

// on the below line we are initializing the adapter for our list view.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(root.getContext(), android.R.layout.simple_list_item_1, autoList){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view =super.getView(position, convertView, parent);

TextView textView=(TextView) view.findViewById(android.R.id.text1);

/*YOUR CHOICE OF COLOR*/
textView.setTextColor(Color.BLACK);

return view;
}

@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
editor.putString(listKey, listToString(autoList));
editor.apply();
}
};

// on below line we are setting adapter for our list view.
binding.automaticList.setAdapter(adapter);

// on below line we are adding click listener for our button.
binding.addLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// on below line we are getting text from edit text
String item = Integer.toString(autoList.size() + 1) + ": Links";

// on below line we are checking if item is not empty
if (!item.isEmpty()) {
// on below line we are adding item to our list.
autoList.add(item);
// on below line we are notifying adapter
// that data in list is updated to
// update our list view.
adapter.notifyDataSetChanged();
}

}
});

// on below line we are adding click listener for our button.
binding.addRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// on below line we are getting text from edit text
String item = Integer.toString(autoList.size() + 1) + ": Rechts";

// on below line we are checking if item is not empty
if (!item.isEmpty()) {
// on below line we are adding item to our list.
autoList.add(item);
// on below line we are notifying adapter
// that data in list is updated to
// update our list view.
adapter.notifyDataSetChanged();
}
}
});

binding.automaticList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
autoList.remove(position);
adapter.notifyDataSetChanged();
}
});

return root;
}

@@ -34,4 +129,20 @@ public class DashboardFragment extends Fragment {
super.onDestroyView();
binding = null;
}
}

public String listToString(ArrayList<String> list){
String result = "";
for (String s : list) {
result += s + ";";
}
return result;
}

public ArrayList<String> stringToArraylist(String str){
ArrayList<String> list = null;
String[] stringArray = str.split(";");
list = new ArrayList<String>(Arrays.asList(stringArray));
return list;
}
}


+ 37
- 15
MobileApp/app/src/main/res/layout/fragment_automatik.xml View File

@@ -11,15 +11,16 @@
android:layout_width="224dp"
android:layout_height="38dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:checked="false"
android:fontFamily="sans-serif-medium"
android:text="Roboter losfahren "
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.147"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></Switch>
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text_dashboard"
@@ -39,34 +40,55 @@

<TextView
android:id="@+id/textTurnLeftRight"
android:layout_width="128dp"
android:layout_height="22dp"
android:layout_width="137dp"
android:layout_height="39dp"
android:layout_marginStart="8dp"
android:layout_marginTop="68dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-medium"
android:text="Abbiegen nach "
android:text="Abzweigung hinzufügen:"
android:textColor="#000000"
android:textSize="16sp"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.322"
app:layout_constraintHorizontal_bias="0.089"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="95dp"
<Button
android:id="@+id/addLeft"
android:layout_width="105dp"
android:layout_height="40dp"
android:layout_marginTop="60dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="16dp"
android:fontFamily="sans-serif-medium"
android:text="ToggleButton"
android:textOff="Links"
android:textOn="Rechts"
android:text="Links"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.74"
app:layout_constraintHorizontal_bias="0.613"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/addRight"
android:layout_width="105dp"
android:layout_height="40dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="16dp"
android:fontFamily="sans-serif-medium"
android:text="Rechts"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ListView
android:id="@+id/automaticList"
android:layout_width="413dp"
android:layout_height="470dp"
android:layout_marginTop="124dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/startAutomatic" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save