Commit 983f62438473fc4ea5390f4b9768f7f13a40972b

Authored by FatBaz
1 parent 9ac2b332

Add MapMarker and buttons

app/src/main/java/fr/utbm/lo53/p2017/positionningapp/Calibration.java
... ... @@ -10,9 +10,10 @@ import android.view.MotionEvent;
10 10 import android.view.View;
11 11 import android.view.Menu;
12 12 import android.view.MenuItem;
  13 +import android.widget.Button;
13 14 import android.widget.ImageView;
14 15  
15   -public class Calibration extends BaseActivity {
  16 +public class Calibration extends AppCompatActivity {
16 17  
17 18 @Override
18 19 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -33,31 +34,78 @@ public class Calibration extends BaseActivity {
33 34  
34 35 final ImageView Map = (ImageView) findViewById(R.id.Map);
35 36 final ImageView MapMarker = (ImageView) findViewById(R.id.MapMarker);
  37 + final Button setPointButton = (Button) findViewById(R.id.setPointButton);
  38 + final Button cancelButton = (Button) findViewById(R.id.cancelButton);
  39 + final Button measureButton = (Button) findViewById(R.id.measureButton);
36 40  
37 41 MapMarker.setVisibility(MapMarker.INVISIBLE);
  42 + cancelButton.setVisibility(cancelButton.INVISIBLE);
  43 + cancelButton.setX(50);
  44 + measureButton.setVisibility(measureButton.INVISIBLE);
  45 + measureButton.setX(300);
38 46  
39 47 Map.setOnTouchListener(new View.OnTouchListener() {
40 48 @Override
41 49 public boolean onTouch(View view, MotionEvent motionEvent) {
42   - if(motionEvent.getAction()==motionEvent.ACTION_MOVE || motionEvent.getAction()==motionEvent.ACTION_UP) {
  50 + /*motionEvent.getAction()==motionEvent.ACTION_MOVE &&*/
  51 + if( setPointButton.getVisibility() == setPointButton.INVISIBLE && motionEvent.getX() <= Map.getWidth() && motionEvent.getY() <= Map.getHeight() && motionEvent.getX() >= 0 && motionEvent.getY() >= 0) {
43 52 MapMarker.setVisibility(MapMarker.VISIBLE);
44 53 Snackbar.make(view, " X : " + motionEvent.getX() + " Y : " + motionEvent.getY(), Snackbar.LENGTH_LONG)
45 54 .setAction("Action", null).show();
46 55 MapMarker.setX(motionEvent.getX()-(MapMarker.getWidth()/4));
47   - MapMarker.setY(motionEvent.getY()-(MapMarker.getHeight()/4));
  56 + MapMarker.setY(motionEvent.getY());
48 57 }
49 58 return true;
50 59 }
51 60  
52 61 });
  62 + setPointButton.setOnClickListener(new View.OnClickListener() {
  63 + @Override
  64 + public void onClick(View v) {
  65 + setPointButton.setVisibility(setPointButton.INVISIBLE);
  66 + cancelButton.setVisibility(cancelButton.VISIBLE);
  67 + measureButton.setVisibility(measureButton.VISIBLE);
  68 + }
  69 + });
  70 + measureButton.setOnClickListener(new View.OnClickListener() {
  71 + @Override
  72 + public void onClick(View v) {
  73 + if(MapMarker.getVisibility()==MapMarker.INVISIBLE) {
  74 + Snackbar.make(v, "You need to set a point before measurement.", Snackbar.LENGTH_LONG)
  75 + .setAction("Action", null).show();
  76 + }
  77 + }
  78 + });
  79 + cancelButton.setOnClickListener(new View.OnClickListener() {
  80 + @Override
  81 + public void onClick(View v) {
  82 + setPointButton.setVisibility(setPointButton.VISIBLE);
  83 + cancelButton.setVisibility(cancelButton.INVISIBLE);
  84 + measureButton.setVisibility(measureButton.INVISIBLE);
  85 + MapMarker.setVisibility(MapMarker.INVISIBLE);
  86 + }
  87 + });
53 88 }
54 89  
55 90 @Override
56 91 public boolean onCreateOptionsMenu(Menu menu) {
57   - super.onCreateOptionsMenu(menu);
58   - MenuItem item = menu.findItem(R.id.open_locate_activity);
59   - item.setVisible(true);
  92 + // Inflate the menu; this adds items to the action bar if it is present.
  93 + getMenuInflater().inflate(R.menu.menu_calibration, menu);
60 94 return true;
61 95 }
62 96  
  97 + @Override
  98 + public boolean onOptionsItemSelected(MenuItem item) {
  99 + // Handle action bar item clicks here. The action bar will
  100 + // automatically handle clicks on the Home/Up button, so long
  101 + // as you specify a parent activity in AndroidManifest.xml.
  102 + int id = item.getItemId();
  103 +
  104 + //noinspection SimplifiableIfStatement
  105 + if (id == R.id.action_settings) {
  106 + return true;
  107 + }
  108 +
  109 + return super.onOptionsItemSelected(item);
  110 + }
63 111 }
... ...
app/src/main/res/layout/content_calibration.xml
... ... @@ -14,7 +14,7 @@
14 14 android:layout_height="wrap_content"
15 15 android:layout_marginLeft="8dp"
16 16 android:layout_marginRight="8dp"
17   - android:layout_marginTop="30dp"
  17 + android:layout_marginTop="50dp"
18 18 android:paddingLeft="0dp"
19 19 android:paddingTop="0dp"
20 20 android:scaleType="fitXY"
... ... @@ -22,7 +22,9 @@
22 22 app:layout_constraintLeft_toLeftOf="parent"
23 23 app:layout_constraintRight_toRightOf="parent"
24 24 app:layout_constraintTop_toTopOf="parent"
25   - app:srcCompat="@drawable/map" />
  25 + app:srcCompat="@drawable/map"
  26 + android:layout_marginStart="8dp"
  27 + android:layout_marginEnd="8dp" />
26 28  
27 29 <ImageView
28 30 android:id="@+id/MapMarker"
... ... @@ -36,6 +38,52 @@
36 38 app:layout_constraintTop_toTopOf="@+id/Map"
37 39 android:layout_marginTop="8dp"
38 40 app:layout_constraintBottom_toBottomOf="@+id/Map"
39   - android:layout_marginBottom="8dp" />
  41 + android:layout_marginBottom="8dp"
  42 + android:layout_marginStart="8dp"
  43 + android:layout_marginEnd="8dp" />
  44 +
  45 + <Button
  46 + android:id="@+id/setPointButton"
  47 + style="@style/Widget.AppCompat.Button"
  48 + android:layout_width="0dp"
  49 + android:layout_height="wrap_content"
  50 + android:layout_marginTop="50dp"
  51 + android:text="Set Point"
  52 + app:layout_constraintTop_toBottomOf="@+id/Map"
  53 + android:layout_marginStart="8dp"
  54 + android:layout_marginEnd="8dp"
  55 + android:layout_marginLeft="8dp"
  56 + app:layout_constraintLeft_toLeftOf="parent"
  57 + android:layout_marginRight="8dp"
  58 + app:layout_constraintRight_toRightOf="parent"
  59 + app:layout_constraintHorizontal_bias="0.0" />
  60 +
  61 + <Button
  62 + android:id="@+id/cancelButton"
  63 + android:layout_width="368dp"
  64 + android:layout_height="wrap_content"
  65 + android:layout_marginTop="8dp"
  66 + android:text="Cancel"
  67 + app:layout_constraintTop_toBottomOf="@+id/measureButton"
  68 + android:layout_marginLeft="8dp"
  69 + app:layout_constraintLeft_toLeftOf="parent"
  70 + android:layout_marginStart="8dp"
  71 + android:layout_marginEnd="8dp"
  72 + android:layout_marginRight="8dp"
  73 + app:layout_constraintRight_toRightOf="parent" />
  74 +
  75 + <Button
  76 + android:id="@+id/measureButton"
  77 + android:layout_width="0dp"
  78 + android:layout_height="wrap_content"
  79 + android:layout_marginTop="50dp"
  80 + android:text="Measure"
  81 + app:layout_constraintTop_toBottomOf="@+id/Map"
  82 + android:layout_marginStart="8dp"
  83 + android:layout_marginEnd="8dp"
  84 + android:layout_marginRight="8dp"
  85 + app:layout_constraintRight_toRightOf="parent"
  86 + android:layout_marginLeft="8dp"
  87 + app:layout_constraintLeft_toLeftOf="parent" />
40 88  
41 89 </android.support.constraint.ConstraintLayout>
... ...