9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2024-10-06 18:32:07 +08:00

Merge pull request #23 from ChristopheBoucaut/optimisation#1-Refonte-layout

Optimisation#1 refonte layout
This commit is contained in:
ChristopheBoucaut 2014-12-01 17:36:08 +01:00
commit f5b81138cc
2 changed files with 59 additions and 71 deletions

View File

@ -13,7 +13,9 @@
<FrameLayout <FrameLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" > android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView <ImageView
android:id="@+id/normal" android:id="@+id/normal"
@ -24,46 +26,35 @@
android:src="@drawable/normal" /> android:src="@drawable/normal" />
</FrameLayout> </FrameLayout>
<GridLayout <LinearLayout
android:id="@+id/beforePhoto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:columnCount="4" > android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
<LinearLayout android:gravity="bottom" >
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RelativeLayout
android:id="@+id/miniature_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<Button <Button
android:id="@+id/miniature" android:id="@+id/miniature"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_weight="0.2"
android:layout_gravity="bottom"
android:onClick="showMiniature" android:onClick="showMiniature"
android:text="@string/miniature" /> android:text="@string/miniature" />
</RelativeLayout>
<Button <Button
android:id="@+id/capture" android:id="@+id/capture"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_weight="1"
android:layout_weight="0.74" android:onClick="takePhoto"
android:text="@string/capture" android:text="@string/capture" />
android:onClick="takePhoto" />
<org.geneanet.customcamera.VerticalSeekBar <org.geneanet.customcamera.VerticalSeekBar
android:id="@+id/switchOpacity" android:id="@+id/switchOpacity"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="300dp" android:layout_height="300dp"
android:layout_gravity="center_vertical|right" android:layout_gravity="center_vertical"
android:layout_weight="0" android:layout_weight="0"
android:alpha="0.6" android:alpha="0.6"
android:max="7" android:max="7"
@ -72,21 +63,21 @@
android:progress="0" android:progress="0"
android:progressDrawable="@drawable/custom_opacity_bar" android:progressDrawable="@drawable/custom_opacity_bar"
android:secondaryProgress="7" android:secondaryProgress="7"
android:thumb="@drawable/thumb" /> android:thumb="@drawable/thumb"
android:thumbOffset="-0.9px" />
</LinearLayout> </LinearLayout>
</GridLayout>
<GridLayout <FrameLayout
android:id="@+id/afterPhoto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" >
android:columnCount="2" >
<LinearLayout <LinearLayout
android:id="@+id/keepPhoto" android:id="@+id/keepPhoto"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:alpha="0.6" android:alpha="0.8"
android:background="@color/black" android:background="@color/black"
android:visibility="invisible" > android:visibility="invisible" >
@ -104,6 +95,5 @@
android:layout_weight="1" android:layout_weight="1"
android:text="@string/declinePicture" /> android:text="@string/declinePicture" />
</LinearLayout> </LinearLayout>
</GridLayout> </FrameLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -27,7 +27,6 @@ import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.SeekBar.OnSeekBarChangeListener;
@ -184,13 +183,15 @@ public class CameraActivity extends Activity {
if (newDist > distanceBetweenFingers) { if (newDist > distanceBetweenFingers) {
//zoom in //zoom in
if (zoom < maxZoom/2) if (zoom < maxZoom/2) {
zoom+=2; zoom+=2;
}
} else if (newDist < distanceBetweenFingers) { } else if (newDist < distanceBetweenFingers) {
//zoom out //zoom out
if (zoom > 0) if (zoom > 0) {
zoom-=2; zoom-=2;
} }
}
distanceBetweenFingers = newDist; distanceBetweenFingers = newDist;
params.setZoom(zoom); params.setZoom(zoom);
mCamera.setParameters(params); mCamera.setParameters(params);
@ -203,6 +204,7 @@ public class CameraActivity extends Activity {
* @param Parameters params Camera's parameter. * @param Parameters params Camera's parameter.
*/ */
public void handleFocus(MotionEvent event, Camera.Parameters params) { public void handleFocus(MotionEvent event, Camera.Parameters params) {
if (photoTaken == false) {
List<String> supportedFocusModes = params.getSupportedFocusModes(); List<String> supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
mCamera.autoFocus(new Camera.AutoFocusCallback() { mCamera.autoFocus(new Camera.AutoFocusCallback() {
@ -211,6 +213,7 @@ public class CameraActivity extends Activity {
}); });
} }
} }
}
/** /**
* Determine the space between the first two fingers. * Determine the space between the first two fingers.
@ -253,8 +256,6 @@ public class CameraActivity extends Activity {
paramsReagrandissement.width = -1; paramsReagrandissement.width = -1;
paramsReagrandissement.height = -1; paramsReagrandissement.height = -1;
imageView.setLayoutParams(paramsReagrandissement); imageView.setLayoutParams(paramsReagrandissement);
// imageView.setAlpha(imageView.getAlpha());
miniature.setVisibility(View.VISIBLE); miniature.setVisibility(View.VISIBLE);
} }
}); });
@ -318,7 +319,6 @@ public class CameraActivity extends Activity {
*/ */
public void onPictureTaken(final byte[] data, Camera camera) { public void onPictureTaken(final byte[] data, Camera camera) {
// Show buttons to accept or decline the picture. // Show buttons to accept or decline the picture.
final LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto); final LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto);
keepPhoto.setVisibility(View.VISIBLE); keepPhoto.setVisibility(View.VISIBLE);
Button accept = (Button)findViewById(R.id.accept); Button accept = (Button)findViewById(R.id.accept);
@ -330,9 +330,8 @@ public class CameraActivity extends Activity {
// Put button miniature at the top of the page // Put button miniature at the top of the page
final Button miniature = (Button)findViewById(R.id.miniature); final Button miniature = (Button)findViewById(R.id.miniature);
final LayoutParams params = (RelativeLayout.LayoutParams)miniature.getLayoutParams(); final LayoutParams params = (LinearLayout.LayoutParams)miniature.getLayoutParams();
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); ((LinearLayout.LayoutParams) params).gravity = Gravity.TOP;
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
miniature.setLayoutParams(params); miniature.setLayoutParams(params);
photoTaken = true; photoTaken = true;
@ -375,8 +374,7 @@ public class CameraActivity extends Activity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
photoTaken = false; photoTaken = false;
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); ((LinearLayout.LayoutParams) params).gravity = Gravity.BOTTOM;
((RelativeLayout.LayoutParams) params).addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
miniature.setLayoutParams(params); miniature.setLayoutParams(params);
// If mode miniature and photo is declined, the miniature goes back to the bottom // If mode miniature and photo is declined, the miniature goes back to the bottom