Android ++
This commit is contained in:
3
DEV-4.5/TP05/Reticule/.idea/.gitignore
generated
vendored
3
DEV-4.5/TP05/Reticule/.idea/.gitignore
generated
vendored
@@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
1
DEV-4.5/TP05/Reticule/.idea/gradle.xml
generated
1
DEV-4.5/TP05/Reticule/.idea/gradle.xml
generated
@@ -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>
|
||||
|
8
DEV-4.5/TP05/Reticule/.idea/misc.xml
generated
8
DEV-4.5/TP05/Reticule/.idea/misc.xml
generated
@@ -1,5 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="../../../../../../../../layout/custom_preview.xml" value="0.22871376811594202" />
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.33" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
|
@@ -7,8 +7,8 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.reticule"
|
||||
minSdk 19
|
||||
targetSdk 32
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
|
@@ -11,4 +11,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
ReticuleView rv = (ReticuleView) findViewById(R.id.mimemamomou);
|
||||
rv.setOnTouchListener(new ReticuleMovementListener());
|
||||
}
|
||||
}
|
@@ -1,2 +1,37 @@
|
||||
package com.example.reticule;public class ReticuleMovementListener {
|
||||
package com.example.reticule;
|
||||
|
||||
import android.view.DragEvent;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class ReticuleMovementListener implements View.OnTouchListener {
|
||||
|
||||
private MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords();
|
||||
private float cx, cy;
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
ReticuleView v = (ReticuleView) view;
|
||||
|
||||
switch (motionEvent.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
motionEvent.getPointerCoords(motionEvent.getActionIndex(), pc);
|
||||
cx = v.getCx();
|
||||
cy = v.getCy();
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
MotionEvent.PointerCoords npc = new MotionEvent.PointerCoords();
|
||||
motionEvent.getPointerCoords(motionEvent.getActionIndex(), npc);
|
||||
|
||||
float dx = npc.x - pc.x;
|
||||
float dy = npc.y - pc.y;
|
||||
v.setCx(cx + dx);
|
||||
v.setCy(cy + dy);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,2 +1,62 @@
|
||||
package com.example.reticule;public class ReticuleView {
|
||||
package com.example.reticule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ReticuleView extends View {
|
||||
|
||||
private float cx, cy;
|
||||
private final int radius = 15;
|
||||
private Paint backgroundPaint, crosshairPaint;
|
||||
|
||||
public ReticuleView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
cx = getWidth() / 2;
|
||||
cy = getHeight() / 2;
|
||||
|
||||
crosshairPaint = new Paint();
|
||||
crosshairPaint.setStyle(Paint.Style.STROKE);
|
||||
crosshairPaint.setColor(0xFFFF9900);
|
||||
|
||||
backgroundPaint = new Paint();
|
||||
backgroundPaint.setStyle(Paint.Style.FILL);
|
||||
backgroundPaint.setColor(0xFF888888);
|
||||
}
|
||||
|
||||
private double distance(float x, float y) {
|
||||
return Math.sqrt(Math.pow(x - cx, 2) + Math.pow(y - cy, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundPaint);
|
||||
canvas.drawCircle(cx, cy, 15, crosshairPaint);
|
||||
canvas.drawLine(cx - 20, cy, cx + 20, cy, crosshairPaint);
|
||||
canvas.drawLine(cx, cy - 20, cx, cy + 20, crosshairPaint);
|
||||
}
|
||||
|
||||
public void setCx(float cx) {
|
||||
this.cx = cx;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setCy(float cy) {
|
||||
this.cy = cy;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public float getCx() {
|
||||
return cx;
|
||||
}
|
||||
|
||||
public float getCy() {
|
||||
return cy;
|
||||
}
|
||||
}
|
||||
|
@@ -6,13 +6,9 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<com.example.reticule.ReticuleView
|
||||
android:id="@+id/mimemamomou"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -1,4 +1,4 @@
|
||||
#Fri Mar 10 09:59:35 CET 2023
|
||||
#Fri Mar 10 10:05:22 CET 2023
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
|
Reference in New Issue
Block a user