Refactor preview activities

pull/53/head
Mattia Iavarone 8 years ago
parent 9bc42de78f
commit 0667d87fae
  1. 50
      demo/src/main/java/com/otaliastudios/cameraview/demo/MessageView.java
  2. 31
      demo/src/main/java/com/otaliastudios/cameraview/demo/PicturePreviewActivity.java
  3. 8
      demo/src/main/java/com/otaliastudios/cameraview/demo/VideoPreviewActivity.java
  4. 2
      demo/src/main/res/drawable/background.xml
  5. 183
      demo/src/main/res/layout/activity_picture_preview.xml
  6. 51
      demo/src/main/res/layout/activity_video_preview.xml
  7. 2
      demo/src/main/res/layout/control_view.xml
  8. 2
      demo/src/main/res/values/colors.xml

@ -0,0 +1,50 @@
package com.otaliastudios.cameraview.demo;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import com.otaliastudios.cameraview.CameraView;
import java.util.ArrayList;
public class MessageView extends LinearLayout {
private TextView message;
private TextView title;
public MessageView(Context context) {
this(context, null);
}
public MessageView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public MessageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOrientation(VERTICAL);
inflate(context, R.layout.control_view, this);
ViewGroup content = findViewById(R.id.content);
inflate(context, R.layout.spinner_text, content);
title = findViewById(R.id.title);
message = (TextView) content.getChildAt(0);
}
public void setTitle(String title) {
this.title.setText(title);
}
public void setMessage(String message) {
this.message.setText(message);
}
}

@ -15,12 +15,6 @@ import java.lang.ref.WeakReference;
public class PicturePreviewActivity extends Activity {
ImageView imageView;
TextView nativeCaptureResolution;
TextView actualResolution;
TextView approxUncompressedSize;
TextView captureLatency;
private static WeakReference<byte[]> image;
public static void setImage(@Nullable byte[] im) {
@ -31,11 +25,11 @@ public class PicturePreviewActivity extends Activity {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picture_preview);
imageView = findViewById(R.id.image);
nativeCaptureResolution = findViewById(R.id.nativeCaptureResolution);
actualResolution = findViewById(R.id.actualResolution);
approxUncompressedSize = findViewById(R.id.approxUncompressedSize);
captureLatency = findViewById(R.id.captureLatency);
final ImageView imageView = findViewById(R.id.image);
final MessageView nativeCaptureResolution = findViewById(R.id.nativeCaptureResolution);
final MessageView actualResolution = findViewById(R.id.actualResolution);
final MessageView approxUncompressedSize = findViewById(R.id.approxUncompressedSize);
final MessageView captureLatency = findViewById(R.id.captureLatency);
final long delay = getIntent().getLongExtra("delay", 0);
final int nativeWidth = getIntent().getIntExtra("nativeWidth", 0);
@ -50,14 +44,21 @@ public class PicturePreviewActivity extends Activity {
@Override
public void onBitmapReady(Bitmap bitmap) {
imageView.setImageBitmap(bitmap);
approxUncompressedSize.setText(getApproximateFileMegabytes(bitmap) + "MB");
captureLatency.setText(delay + " milliseconds");
approxUncompressedSize.setTitle("Approx. uncompressed size");
approxUncompressedSize.setMessage(getApproximateFileMegabytes(bitmap) + "MB");
captureLatency.setTitle("Capture latency");
captureLatency.setMessage(delay + " milliseconds");
// ncr and ar might be different when cropOutput is true.
AspectRatio nativeRatio = AspectRatio.of(nativeWidth, nativeHeight);
AspectRatio finalRatio = AspectRatio.of(bitmap.getWidth(), bitmap.getHeight());
nativeCaptureResolution.setText(nativeWidth + "x" + nativeHeight + " (" + nativeRatio + ")");
actualResolution.setText(bitmap.getWidth() + "x" + bitmap.getHeight() + " (" + finalRatio + ")");
nativeCaptureResolution.setTitle("Native capture resolution");
nativeCaptureResolution.setMessage(nativeWidth + "x" + nativeHeight + " (" + nativeRatio + ")");
actualResolution.setTitle("Actual resolution");
actualResolution.setMessage(bitmap.getWidth() + "x" + bitmap.getHeight() + " (" + finalRatio + ")");
}
});

@ -14,8 +14,7 @@ import android.widget.VideoView;
public class VideoPreviewActivity extends Activity {
VideoView videoView;
TextView actualResolution;
private VideoView videoView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -28,7 +27,7 @@ public class VideoPreviewActivity extends Activity {
playVideo();
}
});
actualResolution = findViewById(R.id.actualResolution);
final MessageView actualResolution = findViewById(R.id.actualResolution);
Uri videoUri = getIntent().getParcelableExtra("video");
MediaController controller = new MediaController(this);
@ -40,7 +39,8 @@ public class VideoPreviewActivity extends Activity {
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
actualResolution.setText(mp.getVideoWidth() + " x " + mp.getVideoHeight());
actualResolution.setTitle("Actual resolution");
actualResolution.setMessage(mp.getVideoWidth() + " x " + mp.getVideoHeight());
ViewGroup.LayoutParams lp = videoView.getLayoutParams();
float videoWidth = mp.getVideoWidth();
float videoHeight = mp.getVideoHeight();

@ -2,5 +2,5 @@
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorPrimary"/>
<solid android:color="@color/colorAccent"/>
</shape>

@ -3,180 +3,37 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true" />
</FrameLayout>
<LinearLayout
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="NATIVE CAPTURE RESOLUTION"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/nativeCaptureResolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textColor="@android:color/black"
android:textSize="14.5sp" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="ACTUAL RESOLUTION"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/actualResolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textColor="@android:color/black"
android:textSize="14.5sp" />
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="APPROX. UNCOMPRESSED SIZE"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/approxUncompressedSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textColor="@android:color/black"
android:textSize="14.5dp" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="CAPTURE LATENCY"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/captureLatency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textColor="@android:color/black"
android:textSize="14.5sp" />
<com.otaliastudios.cameraview.demo.MessageView
android:id="@+id/nativeCaptureResolution"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<com.otaliastudios.cameraview.demo.MessageView
android:id="@+id/actualResolution"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
<com.otaliastudios.cameraview.demo.MessageView
android:id="@+id/approxUncompressedSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<com.otaliastudios.cameraview.demo.MessageView
android:id="@+id/captureLatency"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -14,45 +14,10 @@
android:layout_width="match_parent"
android:layout_height="200dp"/>
<LinearLayout
<com.otaliastudios.cameraview.demo.MessageView
android:id="@+id/actualResolution"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<!-- Resolution -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">
<View
android:layout_width="2.5dp"
android:layout_height="match_parent"
android:background="@color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:text="ACTUAL RESOLUTION"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/actualResolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:textColor="@android:color/black"
android:textSize="14.5sp" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>

@ -5,7 +5,7 @@
<TextView
style="@style/TextAppearance.AppCompat.Subhead"
android:id="@+id/title"
android:layout_marginTop="8dp"
android:layout_marginTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textStyle="bold"

@ -2,5 +2,5 @@
<resources>
<color name="colorPrimary">#009966</color>
<color name="colorPrimaryDark">#00734d</color>
<color name="colorAccent">#65FF2D</color>
<color name="colorAccent">#57db27</color>
</resources>

Loading…
Cancel
Save