mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-18 12:20:36 +01:00
implement toggling between photo/video
This commit is contained in:
parent
321860b4a4
commit
fbc3d9b162
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.camera;
|
package com.simplemobiletools.camera;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.hardware.Sensor;
|
import android.hardware.Sensor;
|
||||||
import android.hardware.SensorEvent;
|
import android.hardware.SensorEvent;
|
||||||
@ -24,12 +25,15 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
@BindView(R.id.viewHolder) RelativeLayout viewHolder;
|
@BindView(R.id.viewHolder) RelativeLayout viewHolder;
|
||||||
@BindView(R.id.toggle_camera) ImageView toggleCameraBtn;
|
@BindView(R.id.toggle_camera) ImageView toggleCameraBtn;
|
||||||
@BindView(R.id.toggle_flash) ImageView toggleFlashBtn;
|
@BindView(R.id.toggle_flash) ImageView toggleFlashBtn;
|
||||||
|
@BindView(R.id.toggle_videocam) ImageView togglePhotoVideoBtn;
|
||||||
|
@BindView(R.id.shutter) ImageView shutterBtn;
|
||||||
|
|
||||||
public static int orientation;
|
public static int orientation;
|
||||||
private static SensorManager sensorManager;
|
private static SensorManager sensorManager;
|
||||||
private Preview preview;
|
private Preview preview;
|
||||||
private int currCamera;
|
private int currCamera;
|
||||||
private boolean isFlashEnabled;
|
private boolean isFlashEnabled;
|
||||||
|
private boolean isPhoto;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -44,6 +48,7 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
preview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
preview.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
viewHolder.addView(preview);
|
viewHolder.addView(preview);
|
||||||
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
|
isPhoto = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.toggle_camera)
|
@OnClick(R.id.toggle_camera)
|
||||||
@ -78,8 +83,12 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.shutter)
|
@OnClick(R.id.shutter)
|
||||||
public void takePicture() {
|
public void shutterPressed() {
|
||||||
preview.takePicture();
|
if (isPhoto) {
|
||||||
|
preview.takePicture();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.about)
|
@OnClick(R.id.about)
|
||||||
@ -88,9 +97,18 @@ public class MainActivity extends AppCompatActivity implements SensorEventListen
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.videocam)
|
@OnClick(R.id.toggle_videocam)
|
||||||
public void toggleVideo() {
|
public void toggleVideo() {
|
||||||
|
final Resources res = getResources();
|
||||||
|
isPhoto = !isPhoto;
|
||||||
|
|
||||||
|
if (isPhoto) {
|
||||||
|
togglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.videocam));
|
||||||
|
shutterBtn.setImageDrawable(res.getDrawable(R.mipmap.camera));
|
||||||
|
} else {
|
||||||
|
togglePhotoVideoBtn.setImageDrawable(res.getDrawable(R.mipmap.photo));
|
||||||
|
shutterBtn.setImageDrawable(res.getDrawable(R.mipmap.video_rec));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideNavigationBarIcons() {
|
private void hideNavigationBarIcons() {
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
android:src="@mipmap/about"/>
|
android:src="@mipmap/about"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/videocam"
|
android:id="@+id/toggle_videocam"
|
||||||
android:layout_width="@dimen/icon_size"
|
android:layout_width="@dimen/icon_size"
|
||||||
android:layout_height="@dimen/icon_size"
|
android:layout_height="@dimen/icon_size"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user