You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AreaAdapter.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package com.example.meinwald.ui.area;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.graphics.Rect;
  6. import android.util.Log;
  7. import android.view.Gravity;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.BaseAdapter;
  12. import android.widget.ImageView;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15. import com.example.meinwald.BuildConfig;
  16. import com.example.meinwald.R;
  17. import com.example.meinwald.ui.task.OwnTask;
  18. import com.google.android.material.floatingactionbutton.FloatingActionButton;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import androidx.appcompat.widget.AlertDialogLayout;
  22. import androidx.appcompat.widget.LinearLayoutCompat;
  23. import androidx.constraintlayout.widget.ConstraintLayout;
  24. import static java.security.AccessController.getContext;
  25. public class AreaAdapter extends BaseAdapter
  26. {
  27. List<OwnArea> areaList;
  28. LayoutInflater inflater;
  29. Context context;
  30. public AreaAdapter(Context applicationContext, List<OwnArea> areaList)
  31. {
  32. this.areaList = new ArrayList<>();
  33. this.areaList = areaList;
  34. this.context = applicationContext;
  35. inflater = LayoutInflater.from(applicationContext);
  36. if (BuildConfig.DEBUG)
  37. {
  38. Log.d("AreaAdapter","size: " + areaList.size());
  39. }
  40. }
  41. @Override
  42. public View getView(final int i, View view, final ViewGroup viewGroup) {
  43. view = inflater.inflate(R.layout.area_element, null);
  44. final ConstraintLayout elementView = view.findViewById(R.id.areaElement);
  45. final ConstraintLayout infovView = view.findViewById(R.id.areaInfoView);
  46. final TextView title = (TextView) view.findViewById(R.id.areaInfoTitle);
  47. final TextView notice = (TextView) view.findViewById(R.id.areaInfoNotice);
  48. final ImageView icon = (ImageView) view.findViewById(R.id.areaIcon);
  49. final ImageView manageArea = (ImageView) view.findViewById(R.id.areaManageArea);
  50. context = view.getContext();
  51. if (BuildConfig.DEBUG)
  52. {
  53. Log.d("AreaAdapter",areaList.get(i).toString());
  54. Log.d("AreaAdapter",areaList.get(i).getTitle());
  55. Log.d("AreaAdapter",areaList.get(i).getNotice());
  56. }
  57. title.setText(areaList.get(i).getTitle());
  58. notice.setText(areaList.get(i).getNotice());
  59. icon.setImageBitmap(areaList.get(i).getImage());
  60. manageArea.setOnClickListener(new View.OnClickListener() {
  61. @Override
  62. public void onClick(View v)
  63. {
  64. final AlertDialog.Builder builder = new AlertDialog.Builder(v.getRootView().getContext());
  65. final View viewInflated = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.area_management, viewGroup, false);
  66. builder.setView(viewInflated);
  67. //get elements
  68. TextView title = viewInflated.findViewById(R.id.areaManageTitle);
  69. final TextView notice = viewInflated.findViewById(R.id.areaManageNotice);
  70. TextView gpscount = viewInflated.findViewById(R.id.areaManageGPSPoints);
  71. ImageView image = (ImageView) viewInflated.findViewById(R.id.areaManageImage);
  72. ImageView newNotice = (ImageView) viewInflated.findViewById(R.id.areaManageNewDescription);
  73. ImageView newGPS = (ImageView) viewInflated.findViewById(R.id.areaManageNewGPS);
  74. ImageView newImage = (ImageView) viewInflated.findViewById(R.id.areaManageNewImage);
  75. ImageView deleteArea = (ImageView) viewInflated.findViewById(R.id.areaManageDeleteArea);
  76. //set current vlues
  77. title.setText(areaList.get(i).getTitle());
  78. notice.setText(areaList.get(i).getNotice());
  79. gpscount.setText(String.valueOf(areaList.get(i).getLocations().size()));
  80. if (areaList.get(i).getImage() != null)
  81. {
  82. image.setImageBitmap(areaList.get(i).getImage());
  83. }
  84. newNotice.setOnClickListener(new View.OnClickListener() {
  85. @Override
  86. public void onClick(View v)
  87. {
  88. final AlertDialog.Builder newbuilder = new AlertDialog.Builder(v.getRootView().getContext());
  89. final View viewInflated = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.area_management_notice, viewGroup, false);
  90. newbuilder.setView(viewInflated);
  91. final TextView noticeView = viewInflated.findViewById(R.id.areaManagementNoticeUserInput);
  92. newbuilder.setPositiveButton("Bestätigen", new DialogInterface.OnClickListener() {
  93. @Override
  94. public void onClick(DialogInterface dialog, int which) {
  95. areaList.get(i).setNotice(noticeView.getText().toString());
  96. notice.setText(areaList.get(i).getNotice());
  97. dialog.dismiss();
  98. }
  99. });
  100. newbuilder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() {
  101. @Override
  102. public void onClick(DialogInterface dialog, int which) {
  103. dialog.cancel();
  104. }
  105. });
  106. newbuilder.show();
  107. }});
  108. builder.setPositiveButton("Bestätigen", new DialogInterface.OnClickListener() {
  109. @Override
  110. public void onClick(DialogInterface dialog, int which) {
  111. dialog.dismiss();
  112. }
  113. });
  114. builder.setNegativeButton("Abbrechen", new DialogInterface.OnClickListener() {
  115. @Override
  116. public void onClick(DialogInterface dialog, int which) {
  117. dialog.cancel();
  118. }
  119. });
  120. builder.show();
  121. }
  122. });
  123. icon.setOnClickListener(new View.OnClickListener() {
  124. @Override
  125. public void onClick(View v)
  126. {
  127. final AlertDialog.Builder builder = new AlertDialog.Builder(v.getRootView().getContext());
  128. final View viewInflated = LayoutInflater.from(v.getRootView().getContext()).inflate(R.layout.image_large, viewGroup, false);
  129. builder.setView(viewInflated);
  130. final ConstraintLayout imageViewLayout = viewInflated.findViewById(R.id.taskLargeImageLayout);
  131. final ImageView imageView = viewInflated.findViewById(R.id.taskLargeImage);
  132. imageView.setImageBitmap(areaList.get(i).getImage());
  133. builder.setNegativeButton("Zurück", new DialogInterface.OnClickListener() {
  134. @Override
  135. public void onClick(DialogInterface dialog, int which) {
  136. dialog.cancel();
  137. }
  138. });
  139. builder.show();
  140. }
  141. });
  142. elementView.setOnLongClickListener(new View.OnLongClickListener() {
  143. @Override
  144. public boolean onLongClick(View v) {
  145. Toast toast = Toast.makeText(context, "on long click!", Toast.LENGTH_SHORT);
  146. TextView tv = (TextView) toast.getView().findViewById(android.R.id.message);
  147. if( v != null)
  148. {
  149. //text align center
  150. tv.setGravity(Gravity.CENTER);
  151. }
  152. return true;
  153. }
  154. });
  155. return view;
  156. }
  157. @Override
  158. public int getCount() {
  159. return areaList.size();
  160. }
  161. @Override
  162. public Object getItem(int i) {
  163. return areaList.get(i);
  164. }
  165. @Override
  166. public long getItemId(int i) {
  167. return i;
  168. }
  169. }