Skip to content

Commit

Permalink
Merge pull request #24 from bojanv55/ael_lock
Browse files Browse the repository at this point in the history
added bracketing 3 images, max diff
  • Loading branch information
jonasjuffinger authored Jul 16, 2019
2 parents 8176a49 + db253b3 commit c0b6512
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 9 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/jonasjuffinger/timelapse/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Intent;
import android.content.SharedPreferences;

import java.util.concurrent.atomic.AtomicInteger;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;

/**
Expand All @@ -16,13 +18,15 @@ class Settings {
private static final String EXTRA_DISPLAYOFF = "com.jonasjuffinger.timelapse.DISPLAYOFF";
private static final String EXTRA_SILENTSHUTTER = "com.jonasjuffinger.timelapse.SILENTSHUTTER";
private static final String EXTRA_AEL = "com.jonasjuffinger.timelapse.AEL";
private static final String EXTRA_BRS = "com.jonasjuffinger.timelapse.BRS";

int interval, rawInterval;
int shotCount, rawShotCount;
boolean displayOff;
boolean silentShutter;
boolean ael;
int fps; // index
boolean brs;

Settings() {
interval = 1;
Expand All @@ -33,14 +37,16 @@ class Settings {
silentShutter = true;
ael = true;
fps = 0;
brs = true;
}

public Settings(int interval, int shotCount, boolean displayOff, boolean silentShutter, boolean ael) {
public Settings(int interval, int shotCount, boolean displayOff, boolean silentShutter, boolean ael, boolean brs) {
this.interval = interval;
this.shotCount = shotCount;
this.displayOff = displayOff;
this.silentShutter = silentShutter;
this.ael = ael;
this.brs = brs;
}

void putInIntent(Intent intent) {
Expand All @@ -49,6 +55,7 @@ void putInIntent(Intent intent) {
intent.putExtra(EXTRA_DISPLAYOFF, displayOff);
intent.putExtra(EXTRA_SILENTSHUTTER, silentShutter);
intent.putExtra(EXTRA_AEL, ael);
intent.putExtra(EXTRA_BRS, brs);
}

static Settings getFromIntent(Intent intent) {
Expand All @@ -57,7 +64,8 @@ static Settings getFromIntent(Intent intent) {
intent.getIntExtra(EXTRA_SHOTCOUNT, 1),
intent.getBooleanExtra(EXTRA_DISPLAYOFF, false),
intent.getBooleanExtra(EXTRA_SILENTSHUTTER, false),
intent.getBooleanExtra(EXTRA_AEL, false)
intent.getBooleanExtra(EXTRA_AEL, false),
intent.getBooleanExtra(EXTRA_BRS, false)
);
}

Expand All @@ -70,6 +78,7 @@ void save(Context context)
editor.putBoolean("silentShutter", silentShutter);
editor.putBoolean("ael", ael);
editor.putInt("fps", fps);
editor.putBoolean("brs", brs);
editor.apply();
}

Expand All @@ -81,5 +90,6 @@ void load(Context context)
silentShutter = sharedPref.getBoolean("silentShutter", silentShutter);
ael = sharedPref.getBoolean("ael", ael);
fps = sharedPref.getInt("fps", fps);
brs = sharedPref.getBoolean("brs", brs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SettingsActivity extends BaseActivity

private CheckBox cbSilentShutter;
private CheckBox cbAEL;
private CheckBox cbBRS;

@Override
protected void onCreate(Bundle savedInstanceState)
Expand Down Expand Up @@ -72,8 +73,10 @@ protected void onCreate(Bundle savedInstanceState)
tvShotsValue = (TextView) findViewById(R.id.tvShotsValue);
sbShots = (AdvancedSeekBar) findViewById(R.id.sbShots);
spnFps = (Spinner) findViewById(R.id.spnFps);

cbSilentShutter = (CheckBox) findViewById(R.id.cbSilentShutter);
cbAEL = (CheckBox) findViewById(R.id.cbAEL);
cbBRS = (CheckBox) findViewById(R.id.cbBRC);

sbInterval.setMax(83);
sbInterval.setOnSeekBarChangeListener(sbIntervalOnSeekBarChangeListener);
Expand All @@ -93,6 +96,9 @@ protected void onCreate(Bundle savedInstanceState)
cbAEL.setChecked(settings.ael);
cbAEL.setOnCheckedChangeListener(cbAELOnCheckListener);

cbBRS.setChecked(settings.brs);
cbBRS.setOnCheckedChangeListener(cbBRSOnCheckListener);

//try {
//CameraEx cameraEx = CameraEx.open(0, null);
//final CameraEx.ParametersModifier modifier = cameraEx.createParametersModifier(cameraEx.getNormalCamera().getParameters());
Expand Down Expand Up @@ -226,6 +232,13 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
};

CheckBox.OnCheckedChangeListener cbBRSOnCheckListener = new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
settings.brs = b;
}
};

void updateTimes() {
if(settings.shotCount == Integer.MAX_VALUE)
{
Expand Down
50 changes: 43 additions & 7 deletions app/src/main/java/com/jonasjuffinger/timelapse/ShootActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class ShootActivity extends BaseActivity implements SurfaceHolder.Callback, CameraEx.ShutterListener
{
Expand All @@ -42,6 +43,13 @@ public class ShootActivity extends BaseActivity implements SurfaceHolder.Callbac

private Display display;

int getcnt(){
if(settings.brs){
return 3;
}
return 1;
}

private Handler shootRunnableHandler = new Handler();
private final Runnable shootRunnable = new Runnable()
{
Expand All @@ -55,12 +63,16 @@ public void run()
//display.off();
}

if(shotCount < settings.shotCount) {
if(shotCount < settings.shotCount * getcnt()) {
long remainingTime = shootTime + settings.interval * 1000 - System.currentTimeMillis();
if(brck.get()>0){
remainingTime = -1;
}

log(" Remaining Time: " + Long.toString(remainingTime));

if (remainingTime <= 150) { // 300ms is vaguely the time this postDelayed is to slow
brck.getAndDecrement();
shoot();
if(!settings.displayOff) {
log(Boolean.toString(settings.displayOff));
Expand Down Expand Up @@ -142,6 +154,19 @@ protected void onResume() {
//do nothing
}

if(settings.brs){
try{
modifier.setDriveMode(CameraEx.ParametersModifier.DRIVE_MODE_BRACKET);
modifier.setBracketMode(CameraEx.ParametersModifier.BRACKET_MODE_EXPOSURE);
modifier.setExposureBracketMode(CameraEx.ParametersModifier.EXPOSURE_BRACKET_MODE_SINGLE);
modifier.setExposureBracketPeriod(30);
modifier.setNumOfBracketPicture(3);
}
catch (Exception e){
//do nothing
}
}

cameraEx.getNormalCamera().setParameters(params);

pictureReviewTime = autoReviewControl.getPictureReviewTime();
Expand All @@ -157,8 +182,8 @@ protected void onResume() {

setAutoPowerOffMode(false);

tvCount.setText(Integer.toString(shotCount)+"/"+Integer.toString(settings.shotCount));
tvRemaining.setText("" + Integer.toString((settings.shotCount - shotCount) * settings.interval / 60) + "min");
tvCount.setText(Integer.toString(shotCount)+"/"+Integer.toString(settings.shotCount * getcnt()));
tvRemaining.setText("" + Integer.toString((settings.shotCount * getcnt() - shotCount) * settings.interval / 60) + "min");
tvBattery.setText(getBatteryPercentage());
}

Expand Down Expand Up @@ -215,7 +240,6 @@ public void surfaceCreated(SurfaceHolder holder) {
catch (IOException e) {}
}


private void shoot() {
if(takingPicture)
return;
Expand All @@ -229,24 +253,36 @@ private void shoot() {
runOnUiThread(new Runnable() {
@Override
public void run() {
tvCount.setText(Integer.toString(shotCount)+"/"+Integer.toString(settings.shotCount));
tvRemaining.setText("" + Integer.toString((settings.shotCount - shotCount) * settings.interval / 60) + "min");
tvCount.setText(Integer.toString(shotCount)+"/"+Integer.toString(settings.shotCount * getcnt()));
tvRemaining.setText("" + Integer.toString((settings.shotCount * getcnt() - shotCount) * settings.interval / 60) + "min");
tvBattery.setText(getBatteryPercentage());
}
});
}

private AtomicInteger brck = new AtomicInteger(0);

@Override
public void onShutter(int i, CameraEx cameraEx) {

if(brck.get()<0){
brck = new AtomicInteger(0);
if(getcnt()>1) {
brck = new AtomicInteger(2);
}
}

this.cameraEx.cancelTakePicture();

camera.startPreview();

if(shotCount < settings.shotCount) {
if(shotCount < settings.shotCount * getcnt()) {

// remaining time to the next shot
long remainingTime = shootTime + settings.interval * 1000 - System.currentTimeMillis();
if(brck.get()>0){
remainingTime = -1;
}

log("Remaining Time: " + Long.toString(remainingTime));

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@
android:checked="true"
android:layout_toRightOf="@id/cbSilentShutter"
android:text="AEL" />

<CheckBox
android:id="@+id/cbBRC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:checked="true"
android:layout_toRightOf="@id/cbAEL"
android:text="BRC3" />
</RelativeLayout>
</LinearLayout>

Expand Down

0 comments on commit c0b6512

Please sign in to comment.