Browse Source

create new task

master
Felix Diemar 3 years ago
parent
commit
4d931b5ab0

+ 1
- 0
Code Android/meinWald/.idea/gradle.xml View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>

+ 1
- 0
Code Android/meinWald/.idea/vcs.xml View File

@@ -2,5 +2,6 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

+ 4
- 0
Code Android/meinWald/app/src/main/java/com/example/meinwald/ui/area/AreaFragment.java View File

@@ -13,6 +13,7 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.example.meinwald.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class AreaFragment extends Fragment {

@@ -30,6 +31,9 @@ public class AreaFragment extends Fragment {
textView.setText(s);
}
});

FloatingActionButton fab = root.findViewById(R.id.fab_areas);

return root;
}
}

+ 296
- 13
Code Android/meinWald/app/src/main/java/com/example/meinwald/ui/task/TasksFragment.java View File

@@ -1,47 +1,330 @@
package com.example.meinwald.ui.task;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.location.Location;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.example.meinwald.BuildConfig;
import com.example.meinwald.R;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import org.json.JSONException;
import org.json.JSONObject;

public class TasksFragment extends Fragment {

private static final String TAG = TasksFragment.class.getSimpleName();

/**
* ______________________________________________________________________________________________
* LOCATION
*/
private static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1;
private static final String KEY_LOCATION = "location";
/**
* The entry point to the Fused Location Provider.
*/
private FusedLocationProviderClient mFusedLocationProviderClient;
private boolean mLocationPermissionGranted;
/**
* The geographical location where the device is currently located.
* That is the last-known location retrieved by the Fused Location Provider.
*/
private Location mLastKnownLocation;

private NotificationsViewModel notificationsViewModel;

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
notificationsViewModel = ViewModelProviders.of(this).get(NotificationsViewModel.class);
public class OwnTask
{
private String title;
private String notice;
private Location location;
private Image image;

public OwnTask()
{
this.title = null;
this.notice = null;
this.location = null;
this.image = null;
}

public OwnTask(String title, String notice, Location location, Image image)
{
this.title = title;
this.notice = notice;
this.location = location;
this.image = image;
}

public String getTitle() {
return title;
}

public String getNotice() {
return notice;
}

public Location getLocation() {
return location;
}

public Image getImage() {
return image;
}

public void setTitle(String title) {
this.title = title;
}

public void setNotice(String notice) {
this.notice = notice;
}

public void setLocation(Location location) {
this.location = location;
}

public void setImage(Image image) {
this.image = image;
}

@Override
public String toString() {
return "OwnTask{" +
"title='" + title + '\'' +
", notice='" + notice + '\'' +
", location=" + location +
'}';
}
}

OwnTask newTask = new OwnTask();

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View root = inflater.inflate(R.layout.fragment_tasks, container, false);
final TextView textView = root.findViewById(R.id.text_tasks);
notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override
public void onChanged(@Nullable String s) {
textView.setText(s);
}
});

FloatingActionButton fab = root.findViewById(R.id.fab);
//instance add button
FloatingActionButton fab = root.findViewById(R.id.fab_tasks);

//construct a FusedLocationProviderClient.
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(getActivity());

//get location permission
getLocationPermission();

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

getDeviceLocation();

final View viewInflated = LayoutInflater.from(getContext()).inflate(R.layout.task_input, (ViewGroup) getView(), false);
builder.setView(viewInflated);

//set location
final Button buttonSetLocation = viewInflated.findViewById(R.id.taskSetLocation);
final TextView locationText = viewInflated.findViewById(R.id.taskLocation);

buttonSetLocation.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

getLocationPermission();
getDeviceLocation();

do {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//wait if there is no known location
}
}, 100);
}while (mLastKnownLocation == null);

//save and display location
newTask.setLocation(mLastKnownLocation);
locationText.setText("Lat: " +String.valueOf(mLastKnownLocation.getLatitude()) + " Lng: " + String.valueOf(mLastKnownLocation.getLongitude()));
}
});

//add picture
final Button buttonAddPicture = viewInflated.findViewById(R.id.taskAddPicture);

buttonAddPicture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});

builder.setPositiveButton("Bestätigen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

final TextView titleView = viewInflated.findViewById(R.id.taskTitleUserInput);
final TextView noticeView = viewInflated.findViewById(R.id.taskNoticeUserInput);

if (titleView.getText()!=null)
{
//save user input
newTask.setTitle(String.valueOf(titleView.getText()));
newTask.setNotice(String.valueOf(noticeView.getText()));

if (BuildConfig.DEBUG)
{
Log.d(TAG, "new Task: " + newTask.toString());
}

dialog.dismiss();

//confirm added task
Toast toast = Toast.makeText(getActivity(), "Aufgabe hinzugefügt!", Toast.LENGTH_SHORT);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
if( v != null)
{
//text align center
v.setGravity(Gravity.CENTER);
}
toast.show();
}
else
{
//title needed
Toast toast = Toast.makeText(getActivity(), "Aufgabentitel fehlt!", Toast.LENGTH_SHORT);
TextView v = (TextView) toast.getView().findViewById(android.R.id.message);
if( v != null)
{
//text align center
v.setGravity(Gravity.CENTER);
}
toast.show();
}
}
});

builder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();
}
});

return root;
}

/**
* Request location permission, so that we can get the location of the device.
* The result of the permission request is handled by a callback,
* onRequestPermissionsResult.
*
*/
private void getLocationPermission() {
if (ContextCompat.checkSelfPermission(getActivity().getApplicationContext(),
android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mLocationPermissionGranted = true;
} else {
ActivityCompat.requestPermissions(getActivity(),
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
}
}

/**
* DOCU ME!
* TOOD: What are grant results etc for?
* @param requestCode
* @param permissions
* @param grantResults
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
{
mLocationPermissionGranted = false;
switch (requestCode) {
case PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
mLocationPermissionGranted = true;
}
}
}
}

/**
* Get the best and most recent location of the device, which may be null in rare
* cases when a location is not available.
*
*/
private void getDeviceLocation() {
try {
if (mLocationPermissionGranted) {
Task<Location> locationResult = mFusedLocationProviderClient.getLastLocation();
locationResult.addOnCompleteListener(getActivity(), new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
if (task.isSuccessful()) {
// Set the last known position to the current location of the device.
mLastKnownLocation = task.getResult();
if (BuildConfig.DEBUG) {

if (task.getResult() != null)
{
Log.d(TAG, "getDeviceLocation " + task.getResult().toString());
}
}
} else {
if (BuildConfig.DEBUG) {
Log.d(TAG, "Current location is null. Using defaults.");
Log.e(TAG, "Exception: %s", task.getException());
}

if (BuildConfig.DEBUG) {
Log.d(TAG, "getDeviceLocation: task not successful");
}
}
}
});
}
} catch (SecurityException e) {
if (BuildConfig.DEBUG) {
Log.e(TAG, "Exception occurred: ");
e.printStackTrace();
}
}
}
}

+ 7
- 2
Code Android/meinWald/app/src/main/res/layout/fragment_areas.xml View File

@@ -22,12 +22,17 @@
android:gravity="center_horizontal" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:id="@+id/fab_areas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:tint="#00009688"
app:backgroundTint="@color/colorPrimary"
app:fabSize="mini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_dialog_email" />

app:rippleColor="#00000000"
app:srcCompat="@android:drawable/ic_menu_add" />
</androidx.constraintlayout.widget.ConstraintLayout>

+ 7
- 2
Code Android/meinWald/app/src/main/res/layout/fragment_tasks.xml View File

@@ -22,12 +22,17 @@
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:id="@+id/fab_tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:tint="#00009688"
app:backgroundTint="@color/colorPrimary"
app:backgroundTintMode="src_in"
app:fabSize="mini"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_dialog_email" />
app:rippleColor="#00000000"
app:srcCompat="@android:drawable/ic_menu_add" />
</androidx.constraintlayout.widget.ConstraintLayout>

+ 73
- 0
Code Android/meinWald/app/src/main/res/layout/task_input.xml View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp" >

<TextView
android:id="@+id/taskTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aufgabe"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/taskTitleUserInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Titel eingeben!">

<requestFocus />

</EditText>

<TextView
android:id="@+id/taskNotice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notizen"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/taskNoticeUserInput"
android:layout_width="match_parent"
android:layout_height="149dp"
android:hint="Beschreibung eingeben!"
android:isScrollContainer="true">

<requestFocus />

</EditText>

<Button
android:id="@+id/taskSetLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Standort setzen!" />

<TextView
android:id="@+id/taskLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/taskAddPicture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bild hinzufügen!" />

<ImageView
android:id="@+id/taskImage"
android:layout_width="243dp"
android:layout_height="149dp"
android:layout_gravity="center"
android:baselineAlignBottom="true"
android:foregroundGravity="center_vertical|center_horizontal"
app:srcCompat="@android:drawable/ic_menu_camera" />

</LinearLayout>

+ 1
- 1
Code Android/meinWald/app/src/main/res/menu/bottom_nav_menu.xml View File

@@ -3,7 +3,7 @@

<item
android:id="@+id/navigation_map"
android:icon="@drawable/ic_home_black_24dp"
android:icon="@android:drawable/ic_dialog_map"
android:title="@string/title_map" />

<item

+ 1
- 1
Code Android/meinWald/app/src/main/res/values/colors.xml View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimary">#1B5E20</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>

Loading…
Cancel
Save