From 17320775cf1d1a463e97514262178a416ac76115 Mon Sep 17 00:00:00 2001 From: progserega Date: Sun, 23 Jun 2013 22:25:43 +1100 Subject: [PATCH] add focus setup, play sound on photo --- OsmAnd/res/values-ru/strings.xml | 12 ++- OsmAnd/res/values/strings.xml | 10 ++ .../audionotes/AudioVideoNotesPlugin.java | 98 ++++++++++++++++++- .../SettingsAudioVideoActivity.java | 42 +++++++- 4 files changed, 154 insertions(+), 8 deletions(-) diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index b2b63a16e4..86966f0fea 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,4 +1,4 @@ - + Этот плагин позволяет загружать линии высот (Загрузка данных -> Меню -> "Другие карты") для использование в оффлайн режиме. Рассмотрите пожалуйста покупку плагина \"Линии высот\" на Market, чтобы поддержать последующую разработку. @@ -1199,4 +1199,14 @@ Установить как пункт назначения Сначала выберите город или улицу Пункт назначения %1$s + Режим фокусировки камеры + Режим фокусировки для встроенного приложения фотографирования + Автоматический фокус + Гиперфокальное (если поддерживается) + Увеличенная глубина резкозти (EDOF) + Фокус на бесконечность + Макро-режим + Постоянная фокусировка + Звук затвора + Проигрывать звук при фотографировании diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a21d440a48..0e8ccc4c86 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1508,4 +1508,14 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Filter {0} has been created Select All email + Camera focus type + Select internal camera focus type + Auto focus + Hiperfocal focus + Extended depth of field (EDOF) + Focus is set at infinity + Macro (close-up) focus mode + The camera continuously tries to focus + Play sound on photo shot + When shot photo play sound diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 86c971c955..8cad3239d0 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -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 AV_EXTERNAL_RECORDER ; public final CommonPreference AV_EXTERNAL_PHOTO_CAM ; + public final CommonPreference 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 AV_CAMERA_FOCUS_TYPE; + public final CommonPreference AV_DEFAULT_ACTION; public final OsmandPreference 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(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java b/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java index bf8d6b561c..ccb5a69cdc 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/SettingsAudioVideoActivity.java @@ -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,