- Removed openCV libs - Issues: Take more than one picture fails - TODO: Saving the picture not needed, just send it to the servermaster
@@ -25,7 +25,7 @@ | |||
</value> | |||
</option> | |||
</component> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||
<output url="file://$PROJECT_DIR$/build/classes" /> | |||
</component> | |||
<component name="ProjectType"> |
@@ -23,8 +23,6 @@ dependencies { | |||
implementation 'com.android.support:appcompat-v7:27.1.1' | |||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |||
implementation 'com.android.support:design:27.1.1' | |||
testImplementation 'junit:junit:4.12' | |||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | |||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |||
implementation project(':openCVLibrary343') | |||
} |
@@ -1,12 +1,24 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |||
package="project.schafkopfzaehler_2"> | |||
<uses-permission android:name="android.permission.CAMERA"/> | |||
<uses-feature android:name="android.hardware.camera" android:required="false"/> | |||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> | |||
<uses-feature android:name="android.hardware.camera.front" android:required="false"/> | |||
<uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/> | |||
<uses-permission android:name="android.permission.CAMERA" /> | |||
<uses-feature | |||
android:name="android.hardware.camera" | |||
android:required="true" /> | |||
<uses-feature | |||
android:name="android.hardware.camera.autofocus" | |||
android:required="true" /> | |||
<uses-feature | |||
android:name="android.hardware.camera.front" | |||
android:required="true" /> | |||
<uses-feature | |||
android:name="android.hardware.camera.front.autofocus" | |||
android:required="true" /> | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |||
<application | |||
android:allowBackup="true" | |||
android:icon="@mipmap/ic_launcher" | |||
@@ -29,14 +41,16 @@ | |||
android:name=".MainGameActivity" | |||
android:label="@string/title_activity_main_game" | |||
android:screenOrientation="portrait" | |||
android:theme="@style/AppTheme.NoActionBar" | |||
/> | |||
android:theme="@style/AppTheme.NoActionBar" /> | |||
<activity | |||
android:name=".ChooseGame" | |||
android:label="@string/title_choose_game" | |||
android:screenOrientation="portrait" | |||
android:theme="@style/AppTheme.NoActionBar" | |||
/> | |||
android:theme="@style/AppTheme.NoActionBar" /> | |||
<activity | |||
android:name=".CardCaptureActivity" | |||
android:screenOrientation="portrait" | |||
android:theme="@style/AppTheme.NoActionBar"/> | |||
</application> | |||
</manifest> |
@@ -0,0 +1,164 @@ | |||
package project.schafkopfzaehler_2; | |||
import android.hardware.Camera; | |||
import android.net.Uri; | |||
import android.os.Environment; | |||
import android.support.v7.app.AppCompatActivity; | |||
import android.os.Bundle; | |||
import android.util.Log; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.FrameLayout; | |||
import android.widget.TextView; | |||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
public class CardCaptureActivity extends AppCompatActivity { | |||
private Camera mCamera; | |||
private cameraPreview mPreview; | |||
Button capture; // Button init | |||
TextView captureLog; // TextView init | |||
public static final int MEDIA_TYPE_IMAGE = 1; | |||
// Add a listener to the Capture button | |||
private View.OnClickListener startCaptureListener = new View.OnClickListener() { | |||
@Override | |||
public void onClick (View v) { | |||
if (v == capture) { | |||
mCamera.takePicture(null, null, mPicture); | |||
} | |||
} | |||
}; | |||
@Override | |||
protected void onCreate(Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.cardcapture); | |||
// Create an instance of Camera | |||
mCamera = getCameraInstance(); | |||
// Create our Preview view and set it as the content of our activity. | |||
mPreview = new cameraPreview(this, mCamera); | |||
FrameLayout preview = findViewById(R.id.cameraPreview); | |||
preview.addView(mPreview); | |||
capture = findViewById(R.id.capture); | |||
capture.setOnClickListener(startCaptureListener); | |||
} | |||
/* Get an instance of the Camera object. */ | |||
public static Camera getCameraInstance(){ | |||
Camera c = null; | |||
try { | |||
c = Camera.open(); // attempt to get a Camera instance | |||
} | |||
catch (Exception e){ | |||
// Camera is not available (in use or does not exist) | |||
} | |||
return c; // returns null if camera is unavailable | |||
} | |||
@Override | |||
protected void onPause() { | |||
super.onPause(); | |||
releaseCamera(); | |||
} | |||
@Override | |||
protected void onResume() { | |||
super.onResume(); | |||
} | |||
@Override | |||
protected void onRestart() { | |||
super.onRestart(); | |||
} | |||
@Override | |||
protected void onStart() { | |||
super.onStart(); | |||
} | |||
private Camera.PictureCallback mPicture = new Camera.PictureCallback() { | |||
@Override | |||
public void onPictureTaken(byte[] data, Camera camera) { | |||
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE); | |||
if (pictureFile == null){ | |||
Log.d("CAMERA", "Error creating media file, check storage permissions"); | |||
return; | |||
} | |||
try { | |||
FileOutputStream fos = new FileOutputStream(pictureFile); | |||
fos.write(data); | |||
fos.close(); | |||
} catch (FileNotFoundException e) { | |||
Log.d("CAMERA", "File not found: " + e.getMessage()); | |||
} catch (IOException e) { | |||
Log.d("CAMERA", "Error accessing file: " + e.getMessage()); | |||
} | |||
captureLog = findViewById(R.id.capture_log); | |||
captureLog.setText("Karte scannen --> an Server senden"); | |||
} | |||
}; | |||
private void releaseCamera(){ | |||
if (mCamera != null){ | |||
mCamera.release(); // release the camera for other applications | |||
mCamera = null; | |||
} | |||
} | |||
/** Create a file Uri for saving an image or video */ | |||
private static Uri getOutputMediaFileUri(int type){ | |||
return Uri.fromFile(getOutputMediaFile(type)); | |||
} | |||
/** Create a File for saving the captured image */ | |||
private static File getOutputMediaFile(int type){ | |||
// To be safe, you should check that the SDCard is mounted | |||
// using Environment.getExternalStorageState() before doing this. | |||
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( | |||
Environment.DIRECTORY_PICTURES), "MyCameraApp"); | |||
// This location works best if you want the created images to be shared | |||
// between applications and persist after your app has been uninstalled. | |||
// Create the storage directory if it does not exist | |||
if (! mediaStorageDir.exists()){ | |||
if (! mediaStorageDir.mkdirs()){ | |||
Log.d("MyCameraApp", "failed to create directory"); | |||
return null; | |||
} | |||
} | |||
// Create a media file name | |||
Long tsLong = System.currentTimeMillis()/1000; | |||
String timeStamp = tsLong.toString(); | |||
File mediaFile; | |||
if (type == MEDIA_TYPE_IMAGE){ | |||
mediaFile = new File(mediaStorageDir.getPath() + File.separator + | |||
"IMG_"+ timeStamp + ".jpg"); | |||
} else { | |||
return null; | |||
} | |||
return mediaFile; | |||
} | |||
} | |||
@@ -1,6 +1,8 @@ | |||
package project.schafkopfzaehler_2; | |||
import android.content.Intent; | |||
import android.hardware.camera2.CameraMetadata; | |||
import android.net.Uri; | |||
import android.os.Bundle; | |||
import android.provider.MediaStore; | |||
import android.support.design.widget.FloatingActionButton; | |||
@@ -11,13 +13,14 @@ import android.util.Log; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.TextView; | |||
import android.widget.VideoView; | |||
public class MainGameActivity extends AppCompatActivity { | |||
private Button p1, p2, p3, p4, chooseGame; // Button init | |||
private TextView choice; | |||
private String playerNames[] = {"", "", "", ""}; // Player names init | |||
static final int REQUEST_VIDEO_CAPTURE = 1; | |||
static final int REQUEST_IMAGE_CAPTURE = 1; | |||
private View.OnClickListener startClickListener = new View.OnClickListener() { | |||
@@ -87,12 +90,9 @@ public class MainGameActivity extends AppCompatActivity { | |||
private void playerButtonClicked (View v) { | |||
Log.d("MainGame", v + " clicked..."); | |||
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); | |||
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { | |||
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE); | |||
} | |||
// Start card capture activity with the camera preview | |||
Intent cardCaptureIntent = new Intent(this, CardCaptureActivity.class); | |||
startActivity(cardCaptureIntent); | |||
} | |||
private void gameChoosing () { | |||
@@ -109,10 +109,6 @@ public class MainGameActivity extends AppCompatActivity { | |||
choice.setText(announcement); | |||
} | |||
} | |||
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) { | |||
// Do nothing... | |||
} | |||
} | |||
} |
@@ -0,0 +1,69 @@ | |||
package project.schafkopfzaehler_2; | |||
import android.content.Context; | |||
import android.hardware.Camera; | |||
import android.util.Log; | |||
import android.view.SurfaceHolder; | |||
import android.view.SurfaceView; | |||
import java.io.IOException; | |||
/** A basic Camera preview class */ | |||
public class cameraPreview extends SurfaceView implements SurfaceHolder.Callback { | |||
private SurfaceHolder mHolder; | |||
private Camera mCamera; | |||
public cameraPreview(Context context, Camera camera) { | |||
super(context); | |||
mCamera = camera; | |||
// Install a SurfaceHolder.Callback so we get notified when the | |||
// underlying surface is created and destroyed. | |||
mHolder = getHolder(); | |||
mHolder.addCallback(this); | |||
// deprecated setting, but required on Android versions prior to 3.0 | |||
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); | |||
} | |||
public void surfaceCreated(SurfaceHolder holder) { | |||
// The Surface has been created, now tell the camera where to draw the preview. | |||
try { | |||
mCamera.setPreviewDisplay(holder); | |||
mCamera.startPreview(); | |||
} catch (IOException e) { | |||
Log.d("CAMERA", "Error setting camera preview: " + e.getMessage()); | |||
} | |||
} | |||
public void surfaceDestroyed(SurfaceHolder holder) { | |||
// empty. Take care of releasing the Camera preview in your activity. | |||
} | |||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { | |||
// If your preview can change or rotate, take care of those events here. | |||
// Make sure to stop the preview before resizing or reformatting it. | |||
if (mHolder.getSurface() == null){ | |||
// preview surface does not exist | |||
return; | |||
} | |||
// stop preview before making changes | |||
try { | |||
mCamera.stopPreview(); | |||
} catch (Exception e){ | |||
// ignore: tried to stop a non-existent preview | |||
} | |||
mCamera.setDisplayOrientation(90); | |||
// start preview with new settings | |||
try { | |||
mCamera.setPreviewDisplay(mHolder); | |||
mCamera.startPreview(); | |||
} catch (Exception e){ | |||
Log.d("CAMERA", "Error starting camera preview: " + e.getMessage()); | |||
} | |||
} | |||
} |
@@ -1,36 +1,42 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:background="@drawable/woodentable"> | |||
android:layout_height="match_parent"> | |||
<FrameLayout | |||
android:id="@+id/camera_preview" | |||
android:id="@+id/cameraPreview" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_above="@+id/button_capture" | |||
android:layout_alignParentTop="true"> | |||
android:layout_height="match_parent"> | |||
</FrameLayout> | |||
<Button | |||
android:id="@+id/button_capture" | |||
style="?android:borderlessButtonStyle" | |||
<RelativeLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_centerHorizontal="true" | |||
android:background="@android:color/holo_green_dark" | |||
android:fontFamily="@font/germania_one" | |||
android:text="@string/announcement" | |||
android:textColor="@android:color/black" | |||
android:textSize="24sp" /> | |||
android:background="@drawable/woodentable" | |||
android:layout_alignParentBottom="true"> | |||
<TextView | |||
android:id="@+id/capture_log" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_alignParentBottom="true" | |||
android:layout_below="@+id/button_capture" | |||
android:text="TextView" /> | |||
<Button | |||
android:id="@+id/capture" | |||
style="?android:borderlessButtonStyle" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_alignParentBottom="true" | |||
android:layout_centerHorizontal="true" | |||
android:background="@android:color/holo_green_dark" | |||
android:fontFamily="@font/germania_one" | |||
android:text="@string/capture" | |||
android:textColor="@android:color/black" | |||
android:textSize="24sp" /> | |||
<TextView | |||
android:id="@+id/capture_log" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:text="@string/app_name" | |||
android:layout_alignParentBottom="false" | |||
android:layout_below="@+id/capture" /> | |||
</RelativeLayout> | |||
</RelativeLayout> |
@@ -19,7 +19,6 @@ | |||
android:layout_height="wrap_content" | |||
android:fontFamily="@font/germania_one" | |||
android:gravity="fill_horizontal" | |||
android:paddingStart="10dp" | |||
android:paddingTop="10dp" | |||
android:text="@string/announcementMade" | |||
android:textAlignment="center" |
@@ -21,6 +21,7 @@ | |||
<string name="soloCall">Was war die Trumpffarbe?</string> | |||
<string name="title_activity_main_game">ActivityMainGame</string> | |||
<string name="title_choose_game">ChooseGame</string> | |||
<string name="capture">Karte scannen</string> | |||
<string name="announcement">Neue Ansage</string> | |||
<string name="announcementMade">Angesagt\:</string> | |||
<string name="noChoice">Es wurde noch nichts angesagt...</string> |