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

Changement de la couleur de fond du bouton camera via le JS.

This commit is contained in:
Thomas BOY 2015-01-14 12:27:44 +01:00
parent 80c135419a
commit d0ea0d5950
45 changed files with 156 additions and 19 deletions

View File

@ -52,6 +52,8 @@ public class CameraLauncher extends CordovaPlugin {
} }
intent.putExtra("miniature", args.getBoolean(1)); intent.putExtra("miniature", args.getBoolean(1));
intent.putExtra("cameraBackgroundColor", args.getString(2));
intent.putExtra("cameraBackgroundColorPressed", args.getString(3));
cordova.startActivityForResult((CordovaPlugin) this, intent, CameraLauncher.REQUEST_CODE); cordova.startActivityForResult((CordovaPlugin) this, intent, CameraLauncher.REQUEST_CODE);

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="35dp" android:color="@android:color/transparent" />
</shape>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="35dp" android:color="@android:color/transparent" />
</shape>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="35dp" android:color="@android:color/transparent" />
</shape>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="35dp" android:color="@android:color/transparent" />
</shape>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="35dp" android:color="@android:color/transparent" />
</shape>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ffffffff"
android:centerColor="#ffdddddd"
android:centerY="0.50"
android:endColor="#ffffffff"
android:angle="270" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#FBFCFA"
android:endColor="#FBFCFA"
android:angle="90" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#777777"
android:endColor="#777777"
android:angle="90" />
</shape>
</clip>
</item>
</layer-list>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="35dp" android:color="@android:color/transparent" />
</shape>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<gradient
android:angle="270"
android:endColor="#e26760"
android:startColor="#e26760"
/>
<size
android:height="40dp"
android:width="40dp" />
</shape>

View File

@ -39,13 +39,12 @@
android:onClick="buttonMiniature" android:onClick="buttonMiniature"
android:text="@string/miniature" /> android:text="@string/miniature" />
<Button <ImageButton
android:id="@+id/capture" android:id="@+id/capture"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:background="@drawable/round_button"
android:onClick="takePhoto" android:src="@drawable/capture2" />
android:text="@string/capture" />
<org.geneanet.customcamera.VerticalSeekBar <org.geneanet.customcamera.VerticalSeekBar
android:id="@+id/switchOpacity" android:id="@+id/switchOpacity"
@ -78,21 +77,24 @@
android:background="@color/black" android:background="@color/black"
android:visibility="invisible" > android:visibility="invisible" >
<Button <ImageButton
android:id="@+id/accept" android:id="@+id/accept"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:onClick="acceptPhoto" android:onClick="acceptPhoto"
android:text="@string/acceptePicture" /> android:src="@drawable/accept"
android:background="@android:color/transparent" />
<Button <ImageButton
android:id="@+id/decline" android:id="@+id/decline"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:onClick="declinePhoto" android:onClick="declinePhoto"
android:text="@string/declinePicture" /> android:src="@drawable/delete"
android:background="@android:color/transparent" />
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">TestCustomCamera</string> <string name="app_name">TestCustomCamera</string>
<string name="hello_world">Hello world!</string> <string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
@ -11,7 +10,7 @@
<string name="miniature">Miniature</string> <string name="miniature">Miniature</string>
<string name="capture">Photo</string> <string name="capture">Photo</string>
<string name="BoutonMiniature">Ceci est le bouton permettant d\'afficher une miniature</string> <string name="BoutonMiniature">Ceci est le bouton permettant d\'afficher une miniature</string>
<string name="descImage">Il s\'agit de l\'image de fond de l\'appareil photo</string> <string name="descImage">Il s\'agit de l\'image de fond de l\'appareil photo</string>
<string name="acceptePicture">Accepter Photo</string> <string name="acceptePicture">Accepter Photo</string>
<string name="declinePicture">Refuser Photo</string> <string name="declinePicture">Refuser Photo</string>
</resources> </resources>

View File

@ -7,7 +7,9 @@ import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat; import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.drawable.GradientDrawable;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Camera.CameraInfo; import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.PictureCallback; import android.hardware.Camera.PictureCallback;
@ -26,6 +28,7 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@ -118,6 +121,51 @@ public class CameraActivity extends Activity {
Button miniature = (Button) findViewById(R.id.miniature); Button miniature = (Button) findViewById(R.id.miniature);
miniature.setVisibility(View.INVISIBLE); miniature.setVisibility(View.INVISIBLE);
} }
ImageButton imgIcon = (ImageButton)findViewById(R.id.capture);
final Activity currentActivity = this;
this.setCameraBackgroundColor(this.getIntent().getStringExtra("cameraBackgroundColor"));
imgIcon.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
((CameraActivity) currentActivity).setCameraBackgroundColor(
currentActivity.getIntent().getStringExtra("cameraBackgroundColorPressed"));
break;
case MotionEvent.ACTION_UP:
view.performClick();
((CameraActivity) currentActivity).setCameraBackgroundColor(
currentActivity.getIntent().getStringExtra("cameraBackgroundColor"));
((CameraActivity) currentActivity).takePhoto();
break;
default:
break;
}
return true;
}
});
}
/**
* Set the background color of the camera button.
* @param color The color of the background.
*/
protected void setCameraBackgroundColor(String color) {
ImageButton imgIcon = (ImageButton)findViewById(R.id.capture);
GradientDrawable backgroundGradient = (GradientDrawable)imgIcon.getBackground();
if (color.length() > 0) {
try {
int cameraBackgroundColor = Color.parseColor(color);
backgroundGradient.setColor(cameraBackgroundColor);
} catch (IllegalArgumentException e) {
backgroundGradient.setColor(Color.TRANSPARENT);
}
} else {
backgroundGradient.setColor(Color.TRANSPARENT);
}
} }
/** Method onStart. Handle the zoom level seekBar and the camera orientation. */ /** Method onStart. Handle the zoom level seekBar and the camera orientation. */
@ -415,7 +463,7 @@ public class CameraActivity extends Activity {
*/ */
public void displayAcceptDeclineButtons() { public void displayAcceptDeclineButtons() {
LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto); LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto);
Button photo = (Button) findViewById(R.id.capture); ImageButton photo = (ImageButton) findViewById(R.id.capture);
SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel);
Button miniature = (Button) findViewById(R.id.miniature); Button miniature = (Button) findViewById(R.id.miniature);
ImageView background = (ImageView) findViewById(R.id.background); ImageView background = (ImageView) findViewById(R.id.background);
@ -477,9 +525,8 @@ public class CameraActivity extends Activity {
/** /**
* Method to take picture. * Method to take picture.
* @param view Current view.
*/ */
public void takePhoto(View view) { public void takePhoto() {
// Handles the moment where picture is taken // Handles the moment where picture is taken
ShutterCallback shutterCallback = new ShutterCallback() { ShutterCallback shutterCallback = new ShutterCallback() {
public void onShutter() { public void onShutter() {
@ -504,7 +551,7 @@ public class CameraActivity extends Activity {
BitmapFactory.Options opt; BitmapFactory.Options opt;
opt = new BitmapFactory.Options(); opt = new BitmapFactory.Options();
// Temp storage to use for decoding // Temporarily storage to use for decoding
opt.inTempStorage = new byte[16 * 1024]; opt.inTempStorage = new byte[16 * 1024];
Camera.Parameters paramsCamera = customCamera.getParameters(); Camera.Parameters paramsCamera = customCamera.getParameters();
Size size = paramsCamera.getPictureSize(); Size size = paramsCamera.getPictureSize();

View File

@ -17,7 +17,10 @@ var customCameraExport = function() {
customCameraExport.prototype.startCamera = function(options, successFct, failFct) { customCameraExport.prototype.startCamera = function(options, successFct, failFct) {
var defaultOptions = { var defaultOptions = {
imgBackgroundBase64: null, // background picture in base64. imgBackgroundBase64: null, // background picture in base64.
miniature: true // active or disable the miniature function. miniature: true, // active or disable the miniature function.
cameraBackgroundColor: "#e26760", // color of the camera button.
cameraBackgroundColorPressed: "#dc453d" // color of the pressed camera button.
// To get supported color formats, go to see method parseColor : http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)
}; };
for (var nameOption in defaultOptions) { for (var nameOption in defaultOptions) {
@ -41,7 +44,9 @@ customCameraExport.prototype.startCamera = function(options, successFct, failFct
"startCamera", "startCamera",
[ [
options.imgBackgroundBase64, options.imgBackgroundBase64,
options.miniature options.miniature,
options.cameraBackgroundColor,
options.cameraBackgroundColorPressed
] ]
); );
}; };