Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add shutter sound toggle #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions mobile/src/main/java/net/dheera/wearcamera/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback {

private static int currentCamera = Camera.CameraInfo.CAMERA_FACING_BACK;
private static String currentFlashMode = Camera.Parameters.FLASH_MODE_OFF;
private static boolean currentSoundMode = true;

private MessageApi.MessageListener mMessageListener = new MessageApi.MessageListener() {
@Override
Expand All @@ -92,6 +93,10 @@ public void onMessageReceived (MessageEvent m){
int arg0 = 0;
if (s.hasNextInt()) arg0 = s.nextInt();
doFlash(arg0);
} else if(command.equals("sound")) {
int arg0 = 0;
if (s.hasNextInt()) arg0 = s.nextInt();
doSound(arg0);
} else if(command.equals("received")) {
long arg0 = 0;
if(s.hasNextLong()) arg0 = s.nextLong();
Expand Down Expand Up @@ -262,6 +267,14 @@ public void doSwitch(int arg0) {
}
}

public void doSound(int arg0) {
currentSoundMode = (arg0 == 0);

if(mCamera != null) {
mCamera.enableShutterSound(currentSoundMode);
}
}

public void doSnap(){
if(mCamera == null || !mPreviewRunning) {
if(D) Log.d(TAG, "tried to snap when camera was inactive");
Expand Down
11 changes: 11 additions & 0 deletions wear/src/main/java/net/dheera/wearcamera/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ protected void onResume() {
sendToPhone("start", null, null);
doSwitch(currentCamera);
doFlash(currentFlash);
doSound(currentSound);
} else {
findPhoneNode();
}
Expand Down Expand Up @@ -232,6 +233,12 @@ private void doTimer(int arg0) {
currentTimer = arg0;
}

private static int currentSound = 0;
private void doSound(int arg0) {
currentSound = arg0;
sendToPhone("sound " + String.valueOf(arg0), null, null);
}

private void takePicture() {
if(mPhoneNode!=null) { sendToPhone("snap", null, null); }
mMenuAdapter.mCameraFragment.cameraResult.animate().setDuration(500).translationX(mMenuAdapter.mCameraFragment.cameraResult.getWidth()).rotation(40).withEndAction(new Runnable() {
Expand Down Expand Up @@ -357,6 +364,10 @@ public void handleMessage(Message msg) {
Log.d(TAG, "MESSAGE_FLASH");
doFlash(msg.arg1);
break;
case MenuAdapter.MESSAGE_SOUND:
Log.d(TAG, "MESSAGE_SOUND");
doSound(msg.arg1);
break;
}
}
};
Expand Down
23 changes: 22 additions & 1 deletion wear/src/main/java/net/dheera/wearcamera/MenuAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MenuAdapter extends FragmentGridPagerAdapter {
public static final int MESSAGE_SWITCH = 2;
public static final int MESSAGE_TIMER = 3;
public static final int MESSAGE_FLASH = 4;
public static final int MESSAGE_SOUND = 5;

private static int currentFlash = 0;
int[] currentFlashText = { R.string.action_flash_0, R.string.action_flash_1, R.string.action_flash_2 };
Expand All @@ -30,6 +31,10 @@ public class MenuAdapter extends FragmentGridPagerAdapter {
int[] currentTimerText = { R.string.action_timer_0, R.string.action_timer_1, R.string.action_timer_2 };
int[] currentTimerIcon = { R.drawable.action_timer_0, R.drawable.action_timer_1, R.drawable.action_timer_2 };

private static int currentSound = 0;
int[] currentSoundText = { R.string.action_sound_0, R.string.action_sound_1 };
int[] currentSoundIcon = { R.drawable.action_sound_0, R.drawable.action_sound_1 };

public MenuAdapter(Context ctx, FragmentManager fm, Handler h) {
super(fm);
mContext = ctx;
Expand All @@ -46,7 +51,7 @@ public void onClick(View v) {

@Override
public int getColumnCount(int arg0) {
return 4;
return 5;
}

@Override
Expand Down Expand Up @@ -106,6 +111,22 @@ public void onClick(View v) {
});
return timerAction;
}

if(colNum == 4) {
final ActionFragment soundAction = ActionFragment.newInstance(currentSoundIcon[currentSound], currentSoundText[currentSound]);
soundAction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("blah", "clicked sound");
currentSound = ( currentSound + 1 ) % currentSoundText.length;
soundAction.setTextRes(currentSoundText[currentSound]);
soundAction.setIconRes(currentSoundIcon[currentSound]);
mHandler.obtainMessage(MESSAGE_SOUND, currentSound, -1).sendToTarget();
}
});
return soundAction;
}

return null;
}

Expand Down
Binary file added wear/src/main/res/drawable/action_sound_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wear/src/main/res/drawable/action_sound_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<string name="action_timer_0">Self-timer off</string>
<string name="action_timer_1">Self-timer 5s</string>
<string name="action_timer_2">Self-timer 10s</string>
<string name="action_sound_0">Shutter sound on</string>
<string name="action_sound_1">Shutter sound off</string>

</resources>