Merge pull request #803 from progserega/master

добавил поддержку выбора размера изображения при фотографировании
This commit is contained in:
vshcherb 2014-08-02 17:52:22 +02:00
commit 231057f51c
4 changed files with 114 additions and 14 deletions

View file

@ -1322,6 +1322,8 @@
<string name="av_camera_focus_continuous">Постоянная фокусировка</string> <string name="av_camera_focus_continuous">Постоянная фокусировка</string>
<string name="av_photo_play_sound">Звук затвора</string> <string name="av_photo_play_sound">Звук затвора</string>
<string name="av_photo_play_sound_descr">Проигрывать звук при фотографировании</string> <string name="av_photo_play_sound_descr">Проигрывать звук при фотографировании</string>
<string name="av_camera_pic_size">Размер фото</string>
<string name="av_camera_pic_size_descr">Размер изображения для встроенного приложения фотографирования</string>
<string name="speak_speed_limit">Сообщать о превышении скорости</string> <string name="speak_speed_limit">Сообщать о превышении скорости</string>
<string name="speak_cameras">Сообщать о камерах</string> <string name="speak_cameras">Сообщать о камерах</string>

View file

@ -1938,6 +1938,8 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="av_camera_focus_continuous">The camera continuously tries to focus</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">Play sound on photo shot</string>
<string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string> <string name="av_photo_play_sound_descr">Choose whether to play a sound when shooting photos</string>
<string name="av_camera_pic_size">Camera Picture Size</string>
<string name="av_camera_pic_size_descr">Select internal camera Picture Size</string>
<string name="navigation_intent_invalid">Invalid format: %s</string> <string name="navigation_intent_invalid">Invalid format: %s</string>
<string name="hide_all_waypoints">Remove all</string> <string name="hide_all_waypoints">Remove all</string>
<string name="announce_nearby_favorites">Announce nearby favorites</string> <string name="announce_nearby_favorites">Announce nearby favorites</string>

View file

@ -113,6 +113,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public static final int AV_DEFAULT_ACTION_TAKEPICTURE = 2; public static final int AV_DEFAULT_ACTION_TAKEPICTURE = 2;
public static final int AV_DEFAULT_ACTION_CHOOSE = -1; public static final int AV_DEFAULT_ACTION_CHOOSE = -1;
// camera picture size:
public static final int AV_PHOTO_SIZE_DEFAULT = -1;
public static int cameraPictureSizeDefault = 0;
// camera focus type // camera focus type
public static final int AV_CAMERA_FOCUS_AUTO = 0; 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_HIPERFOCAL = 1;
@ -124,10 +128,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private static int shotId = 0; private static int shotId = 0;
private SoundPool sp = null; private SoundPool sp = null;
public final CommonPreference<Integer> AV_CAMERA_PICTURE_SIZE;
public final CommonPreference<Integer> AV_CAMERA_FOCUS_TYPE; public final CommonPreference<Integer> AV_CAMERA_FOCUS_TYPE;
public final CommonPreference<Integer> AV_DEFAULT_ACTION; public final CommonPreference<Integer> AV_DEFAULT_ACTION;
public final OsmandPreference<Boolean> SHOW_RECORDINGS; public final OsmandPreference<Boolean> SHOW_RECORDINGS;
private DataTileManager<Recording> recordings = new DataTileManager<AudioVideoNotesPlugin.Recording>(14); private DataTileManager<Recording> recordings = new DataTileManager<AudioVideoNotesPlugin.Recording>(14);
@ -341,6 +344,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
AV_EXTERNAL_PHOTO_CAM = settings.registerBooleanPreference("av_external_cam", true).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_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 picture size:
AV_CAMERA_PICTURE_SIZE = settings.registerIntPreference("av_camera_picture_size", AV_PHOTO_SIZE_DEFAULT).makeGlobal();
// camera focus type: // camera focus type:
AV_CAMERA_FOCUS_TYPE = settings.registerIntPreference("av_camera_focus_type", AV_CAMERA_FOCUS_AUTO).makeGlobal(); AV_CAMERA_FOCUS_TYPE = settings.registerIntPreference("av_camera_focus_type", AV_CAMERA_FOCUS_AUTO).makeGlobal();
// camera sound: // camera sound:
@ -758,8 +763,34 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
try { try {
// load sound befor shot:
if (AV_PHOTO_PLAY_SOUND.get()) {
if (sp == null)
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
log.info("Play sound on photo");
if (shotId == 0) {
shotId = sp.load(app.getAssets().openFd("sounds/camera_click.ogg"), 1);
log.debug("loaded file sound ID: " + shotId);
}
}
Parameters parameters = cam.getParameters(); Parameters parameters = cam.getParameters();
// camera picture size:
List<Camera.Size> psps = parameters.getSupportedPictureSizes();
int index = AV_CAMERA_PICTURE_SIZE.get();
log.debug("takePhotoWithCamera() index=" + index );
if(index == AV_PHOTO_SIZE_DEFAULT)
{
index = cameraPictureSizeDefault;
log.debug("takePhotoWithCamera() Default value of picture size. Set index to cameraPictureSizeDefault. Now index="
+ index );
}
Camera.Size selectedCamPicSize = psps.get(index);
parameters.setPictureSize(selectedCamPicSize.width, selectedCamPicSize.height);
log.debug("takePhotoWithCamera() set Picture size: width=" + selectedCamPicSize.width
+ " height=" + selectedCamPicSize.height );
// camera focus type: // camera focus type:
boolean autofocus = true; boolean autofocus = true;
// boolean autofocus = !Boolean.parseBoolean(parameters.get("auto-exposure-lock-supported")); // boolean autofocus = !Boolean.parseBoolean(parameters.get("auto-exposure-lock-supported"));
@ -797,16 +828,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
// parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); // parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
// parameters.set("auto-exposure-lock", "true"); // parameters.set("auto-exposure-lock", "true");
// } // }
// load sound befor shot:
if (AV_PHOTO_PLAY_SOUND.get()) {
if (sp == null)
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
log.info("Play sound on photo");
if (shotId == 0) {
shotId = sp.load(app.getAssets().openFd("sounds/camera_click.ogg"), 1);
log.debug("loaded file sound ID: " + shotId);
}
}
parameters.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO); parameters.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
parameters.setFlashMode(Parameters.FLASH_MODE_AUTO); parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);

View file

@ -6,6 +6,9 @@ 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.AV_DEFAULT_ACTION_VIDEO;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.VIDEO_OUTPUT_3GP; import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.VIDEO_OUTPUT_3GP;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.VIDEO_OUTPUT_MP4; import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.VIDEO_OUTPUT_MP4;
// camera picture size:
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.cameraPictureSizeDefault;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_PHOTO_SIZE_DEFAULT;
// support camera focus select: // 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_AUTO;
import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_HIPERFOCAL; import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.AV_CAMERA_FOCUS_HIPERFOCAL;
@ -52,10 +55,80 @@ public class SettingsAudioVideoActivity extends SettingsBaseActivity {
// camera type settings: // camera type settings:
grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera, grp.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera,
R.string.av_use_external_camera_descr)); R.string.av_use_external_camera_descr));
// focus mode settings:
// show in menu only suppoted modes:
Parameters parameters = cam.getParameters(); Parameters parameters = cam.getParameters();
// Photo picture size
// get supported sizes:
List<Camera.Size> psps = parameters.getSupportedPictureSizes();
// list of megapixels of each resolution:
List<Integer> mpix = new ArrayList<Integer>();
// list of index each resolution in list, returned by getSupportedPictureSizes():
List<Integer> picSizesValues = new ArrayList<Integer>();
// fill lists for sort:
for (int index = 0; index < psps.size(); index++) {
mpix.add( (psps.get(index)).width*(psps.get(index)).height );
picSizesValues.add(index);
}
// sort list for max resolution in begining of list:
for (int i=0; i < mpix.size(); i++ )
{
for (int j=0; j < mpix.size() - i - 1; j++ )
{
if ( mpix.get(j) < mpix.get( j + 1 ) )
{
// change elements:
int tmp=mpix.get( j + 1 );
mpix.set( j + 1, mpix.get( j ) );
mpix.set( j, tmp );
tmp=picSizesValues.get( j + 1 );
picSizesValues.set( j + 1, picSizesValues.get( j ) );
picSizesValues.set( j, tmp );
}
}
}
// set default photo size to max resolution (set index of element with max resolution in List, returned by getSupportedPictureSizes() ):
cameraPictureSizeDefault = picSizesValues.get(0);
log.debug("onCreate() set cameraPictureSizeDefault=" + cameraPictureSizeDefault);
List<String> itemsPicSizes = new ArrayList<String>();
String prefix;
for (int index = 0; index < psps.size(); index++) {
float px=(float)((psps.get( picSizesValues.get(index) )).width*(psps.get( picSizesValues.get(index) )).height);
if(px>102400) // 100 K
{
px=px/1048576;
prefix="Mpx";
}
else
{
px=px/1024;
prefix="Kpx";
}
itemsPicSizes.add( (psps.get( picSizesValues.get(index) )).width +
"x" +
(psps.get( picSizesValues.get(index) )).height +
" ( " +
String.format("%.2f", px ) +
" " +
prefix +
" )");
}
log.debug("onCreate() set default size: width=" + psps.get( cameraPictureSizeDefault ).width + " height="
+ psps.get( cameraPictureSizeDefault ).height + " index in ps=" + cameraPictureSizeDefault );
entries = itemsPicSizes.toArray(new String[itemsPicSizes.size()]);
intValues = picSizesValues.toArray(new Integer[picSizesValues.size()]);
if (entries.length > 0) {
ListPreference camSizes = createListPreference(p.AV_CAMERA_PICTURE_SIZE, entries, intValues, R.string.av_camera_pic_size,
R.string.av_camera_pic_size_descr);
grp.addPreference(camSizes);
}
// focus mode settings:
// show in menu only suppoted modes:
List<String> sfm = parameters.getSupportedFocusModes(); List<String> sfm = parameters.getSupportedFocusModes();
List<String> items = new ArrayList<String>(); List<String> items = new ArrayList<String>();
List<Integer> itemsValues = new ArrayList<Integer>(); List<Integer> itemsValues = new ArrayList<Integer>();
@ -88,9 +161,11 @@ public class SettingsAudioVideoActivity extends SettingsBaseActivity {
R.string.av_camera_focus_descr); R.string.av_camera_focus_descr);
grp.addPreference(camFocus); grp.addPreference(camFocus);
} }
// play sound on success photo: // play sound on success photo:
grp.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound, grp.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound,
R.string.av_photo_play_sound_descr)); R.string.av_photo_play_sound_descr));
cam.release(); cam.release();
} }
// video settings: // video settings: