Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.Camera;
import android.hardware.Camera.Face;
import android.hardware.Camera.Parameters;
Expand All @@ -46,7 +44,6 @@
import com.commonsware.cwac.camera.SimpleCameraHost;

import nl.changer.polypicker.model.Image;
import nl.changer.polypicker.utils.DebugLog;

public class CwacCameraFragment extends CameraFragment {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.Camera;
import android.hardware.Camera.Face;
import android.hardware.Camera.Parameters;
Expand All @@ -37,15 +35,17 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;

import com.commonsware.cwac.camera.CameraFragment;
import com.commonsware.cwac.camera.CameraUtils;
import com.commonsware.cwac.camera.PictureTransaction;
import com.commonsware.cwac.camera.SimpleCameraHost;

import java.util.List;

import nl.changer.polypicker.model.Image;
import nl.changer.polypicker.utils.DebugLog;

public class CwacCameraFragment extends CameraFragment {

Expand All @@ -55,7 +55,10 @@ public class CwacCameraFragment extends CameraFragment {

private MenuItem autoFocusItem = null;
private MenuItem recordItem = null;
String flashMode = null;
String flashMode = Parameters.FLASH_MODE_OFF;

Switch flashSwitch;
List<String> supportedFlashModes = null;

private View mTakePictureBtn;

Expand Down Expand Up @@ -88,6 +91,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mTakePictureBtn = view.findViewById(R.id.take_picture);
mTakePictureBtn.setOnClickListener(mOnTakePictureClicked);

flashSwitch = (Switch) view.findViewById( R.id.flash_switch );
flashSwitch.setChecked(false);
flashSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
if( supportedFlashModes != null ) {
if (supportedFlashModes.contains(Parameters.FLASH_MODE_TORCH)) {
flashMode = Parameters.FLASH_MODE_TORCH;
} else if (supportedFlashModes.contains(Parameters.FLASH_MODE_ON)) {
flashMode = Parameters.FLASH_MODE_ON;
}
}
} else {
flashMode = Parameters.FLASH_MODE_OFF;
}
}
});

if (mConfig != null) {
mTakePictureBtn.getBackground().setColorFilter(getResources().getColor(mConfig.getCameraButtonColor()), PorterDuff.Mode.DARKEN);
} // else default will be used.
Expand Down Expand Up @@ -243,10 +265,18 @@ public void onCameraFail(FailureReason reason) {

@Override
public Parameters adjustPreviewParameters(Parameters parameters) {
flashMode = CameraUtils.findBestFlashModeMatch(parameters,
Parameters.FLASH_MODE_RED_EYE,
Parameters.FLASH_MODE_AUTO,
Parameters.FLASH_MODE_ON);
// flashMode = CameraUtils.findBestFlashModeMatch(parameters,
// Parameters.FLASH_MODE_RED_EYE,
// Parameters.FLASH_MODE_AUTO,
// Parameters.FLASH_MODE_ON);

supportedFlashModes = parameters.getSupportedFlashModes();

if( supportedFlashModes != null ) {
flashSwitch.setVisibility( View.VISIBLE );
} else {
Log.d( TAG, "No Camera flash modes" );
}

if (parameters.getMaxNumDetectedFaces() > 0) {
supportsFaces = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
<FrameLayout
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent" >
</FrameLayout>

<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/flash"
android:id="@+id/flash_switch"
android:visibility="gone"
android:layout_marginStart="@dimen/flash_horizontal_margin"
android:layout_marginTop="@dimen/flash_vertical_margin"
android:layout_gravity="start|top" />

<nl.changer.polypicker.FloatingActionButton
android:id="@+id/take_picture"
Expand Down
14 changes: 13 additions & 1 deletion PolyPickerDemo/pp3/src/main/res/layout/fragment_camera_cwac.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
<FrameLayout
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent" >
</FrameLayout>

<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/flash"
android:id="@+id/flash_switch"
android:visibility="gone"
android:layout_marginStart="@dimen/flash_horizontal_margin"
android:layout_marginLeft="@dimen/flash_horizontal_margin"
android:layout_marginTop="@dimen/flash_vertical_margin"
android:layout_gravity="start|top" />

<ImageButton
android:id="@+id/take_picture"
Expand Down
3 changes: 3 additions & 0 deletions PolyPickerDemo/pp3/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<dimen name="fab_icon_size">30dp</dimen>
<dimen name="fab_press_translation_z">9dp</dimen>

<dimen name="flash_horizontal_margin">16dp</dimen>
<dimen name="flash_vertical_margin">16dp</dimen>

</resources>
3 changes: 3 additions & 0 deletions PolyPickerDemo/pp3/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<string name="imageview_capture_photo_content_description">Take photo using device camera</string>
<string name="n_images_selected">%1$s images selected already</string>

<string name="flash">Flash</string>


</resources>