add focus setup, play sound on photo

This commit is contained in:
progserega 2013-06-23 22:25:43 +11:00
parent 4e8196096a
commit 17320775cf
4 changed files with 154 additions and 8 deletions

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="srtm_plugin_description">Этот плагин позволяет загружать линии высот (Загрузка данных -&gt; Меню -&gt; "Другие карты") для использование в оффлайн режиме.</string>
<string name="srtm_paid_version_msg">Рассмотрите пожалуйста покупку плагина \"Линии высот\" на Market, чтобы поддержать последующую разработку.</string>
@ -1199,4 +1199,14 @@
<string name="context_menu_item_destination_point">Установить как пункт назначения</string>
<string name="please_select_address">Сначала выберите город или улицу</string>
<string name="destination_point">Пункт назначения %1$s</string>
<string name="av_camera_focus">Режим фокусировки камеры</string>
<string name="av_camera_focus_descr">Режим фокусировки для встроенного приложения фотографирования</string>
<string name="av_camera_focus_auto">Автоматический фокус</string>
<string name="av_camera_focus_hiperfocal">Гиперфокальное (если поддерживается)</string>
<string name="av_camera_focus_edof">Увеличенная глубина резкозти (EDOF)</string>
<string name="av_camera_focus_infinity">Фокус на бесконечность</string>
<string name="av_camera_focus_macro">Макро-режим</string>
<string name="av_camera_focus_continuous">Постоянная фокусировка</string>
<string name="av_photo_play_sound">Звук затвора</string>
<string name="av_photo_play_sound_descr">Проигрывать звук при фотографировании</string>
</resources>

View file

@ -1508,4 +1508,14 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="edit_filter_create_message">Filter {0} has been created</string>
<string name="default_buttons_selectall">Select All</string>
<string name="email">email</string>
<string name="av_camera_focus">Camera focus type</string>
<string name="av_camera_focus_descr">Select internal camera focus type</string>
<string name="av_camera_focus_auto">Auto focus</string>
<string name="av_camera_focus_hiperfocal">Hiperfocal focus</string>
<string name="av_camera_focus_edof">Extended depth of field (EDOF)</string>
<string name="av_camera_focus_infinity">Focus is set at infinity</string>
<string name="av_camera_focus_macro">Macro (close-up) focus mode</string>
<string name="av_camera_focus_continuous">The camera continuously tries to focus</string>
<string name="av_photo_play_sound">Play sound on photo shot</string>
<string name="av_photo_play_sound_descr">When shot photo play sound</string>
</resources>

View file

@ -66,6 +66,8 @@ import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaRecorder;
import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.net.Uri;
import android.os.Build;
import android.preference.Preference;
@ -97,6 +99,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public final CommonPreference<Boolean> AV_EXTERNAL_RECORDER ;
public final CommonPreference<Boolean> AV_EXTERNAL_PHOTO_CAM ;
public final CommonPreference<Boolean> AV_PHOTO_PLAY_SOUND ;
public static final int VIDEO_OUTPUT_MP4 = 0;
public static final int VIDEO_OUTPUT_3GP = 1;
@ -106,6 +109,17 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public static final int AV_DEFAULT_ACTION_VIDEO = 1;
public static final int AV_DEFAULT_ACTION_TAKEPICTURE = 2;
public static final int AV_DEFAULT_ACTION_CHOOSE = -1;
// camera focus type
public static final int AV_CAMERA_FOCUS_AUTO = 0;
public static final int AV_CAMERA_FOCUS_HIPERFOCAL = 1;
public static final int AV_CAMERA_FOCUS_EDOF = 2;
public static final int AV_CAMERA_FOCUS_INFINITY = 3;
public static final int AV_CAMERA_FOCUS_MACRO = 4;
public static final int AV_CAMERA_FOCUS_CONTINUOUS = 5;
public final CommonPreference<Integer> AV_CAMERA_FOCUS_TYPE;
public final CommonPreference<Integer> AV_DEFAULT_ACTION;
public final OsmandPreference<Boolean> SHOW_RECORDINGS ;
@ -322,7 +336,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
AV_EXTERNAL_RECORDER = settings.registerBooleanPreference("av_external_recorder", false).makeGlobal();
AV_EXTERNAL_PHOTO_CAM = settings.registerBooleanPreference("av_external_cam", true).makeGlobal();
AV_VIDEO_FORMAT = settings.registerIntPreference("av_video_format", VIDEO_OUTPUT_MP4).makeGlobal();
AV_DEFAULT_ACTION = settings.registerIntPreference("av_default_action", AV_DEFAULT_ACTION_CHOOSE).makeGlobal();
AV_DEFAULT_ACTION = settings.registerIntPreference("av_default_action", AV_DEFAULT_ACTION_CHOOSE).makeGlobal();
// camera focus type:
AV_CAMERA_FOCUS_TYPE = settings.registerIntPreference("av_camera_focus_type",AV_CAMERA_FOCUS_AUTO).makeGlobal();
// camera sound:
AV_PHOTO_PLAY_SOUND = settings.registerBooleanPreference("av_photo_play_sound", true).makeGlobal();
SHOW_RECORDINGS = settings.registerBooleanPreference("show_recordings", true).makeGlobal();
}
@ -695,7 +714,44 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} else {
final Camera cam = openCamera();
if (cam != null) {
// load sound:
int shotId = 0;
SoundPool sp = new SoundPool(5, AudioManager.STREAM_NOTIFICATION, 0);
if (AV_PHOTO_PLAY_SOUND.get()) {
log.info("Play sound on photo");
shotId = sp.load("/mnt/sdcard/osmand/shot.ogg", 1);
log.error("loaded file sound ID: " + shotId);
}
// take photo:
takePhotoWithCamera(lat, lon, mapActivity, cam);
// play sound after photo - sound file must be loaded at this time:
if (AV_PHOTO_PLAY_SOUND.get()) {
boolean error_play=true;
for(int i=0;i<100;i++)
{
int ret=sp.play(shotId, 1, 1, 0, 0, 1);
if(0!=ret)
{
log.debug("play sound shot success!");
log.debug("sp.play()="+ret);
error_play=false;
break;
}
else
{
try{
Thread.sleep(10);
} catch (Exception e) {
logErr(e);
e.printStackTrace();
}
// log.debug("sp.play()="+ret+"\nwait sp.play...");
}
}
if(error_play)
log.error("error play sound!");
// sp.release();
}
} else {
takeIntentPhoto(lat, lon, mapActivity);
}
@ -752,16 +808,47 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public void surfaceCreated(SurfaceHolder holder) {
try {
Parameters parameters = cam.getParameters();
// camera focus type:
boolean autofocus = true;
// boolean autofocus = !Boolean.parseBoolean(parameters.get("auto-exposure-lock-supported"));
parameters.setGpsLatitude(lat);
parameters.setGpsLongitude(lon);
if(autofocus) {
switch( AV_CAMERA_FOCUS_TYPE.get() ) {
case AV_CAMERA_FOCUS_HIPERFOCAL:
parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
autofocus = false;
log.info("Osmand:AudioNotes set camera FOCUS_MODE_FIXED");
break;
case AV_CAMERA_FOCUS_EDOF:
parameters.setFocusMode(Parameters.FOCUS_MODE_EDOF);
autofocus = false;
log.info("Osmand:AudioNotes set camera FOCUS_MODE_EDOF");
break;
case AV_CAMERA_FOCUS_INFINITY:
parameters.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
autofocus = false;
log.info("Osmand:AudioNotes set camera FOCUS_MODE_INFINITY");
break;
case AV_CAMERA_FOCUS_MACRO:
parameters.setFocusMode(Parameters.FOCUS_MODE_MACRO);
log.info("Osmand:AudioNotes set camera FOCUS_MODE_MACRO");
break;
case AV_CAMERA_FOCUS_CONTINUOUS:
parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
log.info("Osmand:AudioNotes set camera FOCUS_MODE_CONTINUOUS_PICTURE");
break;
default:
parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
} else {
log.info("Osmand:AudioNotes set camera FOCUS_MODE_AUTO");
break;
}
// parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
// parameters.set("auto-exposure-lock", "true");
}
//}
parameters.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
@ -780,11 +867,13 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
});
}
} catch (Exception e) {
logErr(e);
cam.release();
e.printStackTrace();
}
}
private void printCamParams(Parameters parameters, boolean autoExposure) {
@ -798,6 +887,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
});
dlg.setContentView(view);
dlg.show();
} catch (RuntimeException e) {
logErr(e);
cam.release();

View file

@ -8,12 +8,21 @@ import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_DEFAULT_ACTION
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_DEFAULT_ACTION_VIDEO;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.VIDEO_OUTPUT_3GP;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.VIDEO_OUTPUT_MP4;
// support camera focus select:
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_AUTO;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_HIPERFOCAL;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_EDOF;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_INFINITY;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_MACRO;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_CONTINUOUS;
////
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceScreen;
import android.util.Log;
public class SettingsAudioVideoActivity extends SettingsBaseActivity {
@ -34,12 +43,39 @@ public class SettingsAudioVideoActivity extends SettingsBaseActivity {
ListPreference defAct = createListPreference(p.AV_DEFAULT_ACTION, entries, intValues, R.string.av_widget_action,
R.string.av_widget_action_descr);
grp.addPreference(defAct);
grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_RECORDER, R.string.av_use_external_recorder,
R.string.av_use_external_recorder_descr));
// camera type settings:
grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera,
R.string.av_use_external_camera_descr));
// focus mode settings:
entries = new String[] {
getString(R.string.av_camera_focus_auto),
getString(R.string.av_camera_focus_hiperfocal),
getString(R.string.av_camera_focus_edof),
getString(R.string.av_camera_focus_infinity),
getString(R.string.av_camera_focus_macro),
getString(R.string.av_camera_focus_continuous)
};
intValues = new Integer[] {
AV_CAMERA_FOCUS_AUTO,
AV_CAMERA_FOCUS_HIPERFOCAL,
AV_CAMERA_FOCUS_EDOF,
AV_CAMERA_FOCUS_INFINITY,
AV_CAMERA_FOCUS_MACRO,
AV_CAMERA_FOCUS_CONTINUOUS
};
ListPreference camFocus = createListPreference(p.AV_CAMERA_FOCUS_TYPE, entries, intValues, R.string.av_camera_focus,
R.string.av_camera_focus_descr);
grp.addPreference(camFocus);
// play sound on success photo:
grp.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound,
R.string.av_photo_play_sound_descr));
// video settings:
grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_RECORDER, R.string.av_use_external_recorder,
R.string.av_use_external_recorder_descr));
entries = new String[] { "3GP", "MP4" };
intValues = new Integer[] { VIDEO_OUTPUT_3GP, VIDEO_OUTPUT_MP4 };
ListPreference lp = createListPreference(p.AV_VIDEO_FORMAT, entries, intValues, R.string.av_video_format,