use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class SettingsAudioVideoActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
((OsmandApplication) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState);
getToolbar().setTitle(R.string.av_settings);
PreferenceScreen grp = getPreferenceScreen();
AudioVideoNotesPlugin p = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
if (p != null) {
String[] entries;
Integer[] intValues;
entries = new String[] { getString(R.string.av_def_action_choose), getString(R.string.av_def_action_audio), getString(R.string.av_def_action_video), getString(R.string.av_def_action_picture) };
intValues = new Integer[] { AV_DEFAULT_ACTION_CHOOSE, AV_DEFAULT_ACTION_AUDIO, AV_DEFAULT_ACTION_VIDEO, AV_DEFAULT_ACTION_TAKEPICTURE };
ListPreference defAct = createListPreference(p.AV_DEFAULT_ACTION, entries, intValues, R.string.av_widget_action, R.string.av_widget_action_descr);
grp.addPreference(defAct);
PreferenceCategory photo = new PreferenceCategory(this);
photo.setTitle(R.string.shared_string_photo);
grp.addPreference(photo);
final Camera cam = openCamera();
if (cam != null) {
// camera type settings
photo.addPreference(createCheckBoxPreference(p.AV_EXTERNAL_PHOTO_CAM, R.string.av_use_external_camera, R.string.av_use_external_camera_descr));
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 (// 100 K
px > 102400) {
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);
photo.addPreference(camSizes);
}
// focus mode settings
// show in menu only suppoted modes
List<String> sfm = parameters.getSupportedFocusModes();
List<String> items = new ArrayList<String>();
List<Integer> itemsValues = new ArrayList<Integer>();
// filtering known types for translate and set index
for (int index = 0; index < sfm.size(); index++) {
if (sfm.get(index).equals("auto")) {
items.add(getString(R.string.av_camera_focus_auto));
itemsValues.add(AV_CAMERA_FOCUS_AUTO);
} else if (sfm.get(index).equals("fixed")) {
items.add(getString(R.string.av_camera_focus_hiperfocal));
itemsValues.add(AV_CAMERA_FOCUS_HIPERFOCAL);
} else if (sfm.get(index).equals("edof")) {
items.add(getString(R.string.av_camera_focus_edof));
itemsValues.add(AV_CAMERA_FOCUS_EDOF);
} else if (sfm.get(index).equals("infinity")) {
items.add(getString(R.string.av_camera_focus_infinity));
itemsValues.add(AV_CAMERA_FOCUS_INFINITY);
} else if (sfm.get(index).equals("macro")) {
items.add(getString(R.string.av_camera_focus_macro));
itemsValues.add(AV_CAMERA_FOCUS_MACRO);
} else if (sfm.get(index).equals("continuous-picture")) {
items.add(getString(R.string.av_camera_focus_continuous));
itemsValues.add(AV_CAMERA_FOCUS_CONTINUOUS);
}
}
entries = items.toArray(new String[items.size()]);
intValues = itemsValues.toArray(new Integer[itemsValues.size()]);
if (entries.length > 0) {
ListPreference camFocus = createListPreference(p.AV_CAMERA_FOCUS_TYPE, entries, intValues, R.string.av_camera_focus, R.string.av_camera_focus_descr);
photo.addPreference(camFocus);
}
// play sound on success photo
photo.addPreference(createCheckBoxPreference(p.AV_PHOTO_PLAY_SOUND, R.string.av_photo_play_sound, R.string.av_photo_play_sound_descr));
cam.release();
}
// video settings
PreferenceCategory video = new PreferenceCategory(this);
video.setTitle(R.string.shared_string_video);
grp.addPreference(video);
video.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,
// R.string.av_video_format_descr);
// video.addPreference(lp);
List<String> qNames = new ArrayList<>();
List<Integer> qValues = new ArrayList<>();
if (Build.VERSION.SDK_INT < 11 || CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_LOW)) {
qNames.add(getString(R.string.av_video_quality_low));
qValues.add(CamcorderProfile.QUALITY_LOW);
}
if (Build.VERSION.SDK_INT >= 11 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
qNames.add("720 x 480 (480p)");
qValues.add(CamcorderProfile.QUALITY_480P);
}
if (Build.VERSION.SDK_INT >= 11 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
qNames.add("1280 x 720 (720p)");
qValues.add(CamcorderProfile.QUALITY_720P);
}
if (Build.VERSION.SDK_INT >= 11 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) {
qNames.add("1920 x 1080 (1080p)");
qValues.add(CamcorderProfile.QUALITY_1080P);
}
if (Build.VERSION.SDK_INT >= 21 && CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_2160P)) {
qNames.add("3840x2160 (2160p)");
qValues.add(CamcorderProfile.QUALITY_2160P);
}
if (Build.VERSION.SDK_INT < 11 || CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_HIGH)) {
qNames.add(getString(R.string.av_video_quality_high));
qValues.add(CamcorderProfile.QUALITY_HIGH);
}
ListPreference lp = createListPreference(p.AV_VIDEO_QUALITY, qNames.toArray(new String[qNames.size()]), qValues.toArray(new Integer[qValues.size()]), R.string.av_video_quality, R.string.av_video_quality_descr);
video.addPreference(lp);
// Recorder Split settings
PreferenceCategory recSplit = new PreferenceCategory(this);
recSplit.setTitle(R.string.rec_split);
grp.addPreference(recSplit);
recSplit.addPreference(createCheckBoxPreference(p.AV_RECORDER_SPLIT, R.string.rec_split_title, R.string.rec_split_desc));
intValues = new Integer[] { 1, 2, 3, 4, 5, 7, 10, 15, 20, 25, 30 };
entries = new String[intValues.length];
int i = 0;
String minStr = getString(R.string.int_min);
for (int v : intValues) {
entries[i++] = String.valueOf(v) + " " + minStr;
}
lp = createListPreference(p.AV_RS_CLIP_LENGTH, entries, intValues, R.string.rec_split_clip_length, R.string.rec_split_clip_length_desc);
recSplit.addPreference(lp);
File dir = getMyApplication().getAppPath("").getParentFile();
long size = 0;
if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath());
size = ((long) fs.getBlockSize() * (long) fs.getBlockCount()) / (1 << 30);
}
if (size > 0) {
int value = 1;
ArrayList<Integer> gbList = new ArrayList<>();
while (value < size) {
gbList.add(value);
if (value < 5) {
value++;
} else {
value += 5;
}
}
if (value != size) {
gbList.add((int) size);
}
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
entries = new String[gbList.size()];
intValues = new Integer[gbList.size()];
i = 0;
for (int v : gbList) {
intValues[i] = v;
entries[i] = formatGb.format(new Object[] { (float) v });
i++;
}
lp = createListPreference(p.AV_RS_STORAGE_SIZE, entries, intValues, R.string.rec_split_storage_size, R.string.rec_split_storage_size_desc);
recSplit.addPreference(lp);
}
// audio settings
PreferenceCategory audio = new PreferenceCategory(this);
audio.setTitle(R.string.shared_string_audio);
grp.addPreference(audio);
entries = new String[] { "Default", "AAC" };
intValues = new Integer[] { MediaRecorder.AudioEncoder.DEFAULT, MediaRecorder.AudioEncoder.AAC };
lp = createListPreference(p.AV_AUDIO_FORMAT, entries, intValues, R.string.av_audio_format, R.string.av_audio_format_descr);
audio.addPreference(lp);
entries = new String[] { "Default", "16 kbps", "32 kbps", "48 kbps", "64 kbps", "96 kbps", "128 kbps" };
intValues = new Integer[] { AUDIO_BITRATE_DEFAULT, 16 * 1024, 32 * 1024, 48 * 1024, 64 * 1024, 96 * 1024, 128 * 1024 };
lp = createListPreference(p.AV_AUDIO_BITRATE, entries, intValues, R.string.av_audio_bitrate, R.string.av_audio_bitrate_descr);
audio.addPreference(lp);
}
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class DownloadResourceGroupFragment method doSubscribe.
private void doSubscribe(final String email) {
new AsyncTask<Void, Void, String>() {
ProgressDialog dlg;
@Override
protected void onPreExecute() {
dlg = new ProgressDialog(getActivity());
dlg.setTitle("");
dlg.setMessage(getString(R.string.wait_current_task_finished));
dlg.setCancelable(false);
dlg.show();
}
@Override
protected String doInBackground(Void... params) {
try {
Map<String, String> parameters = new HashMap<>();
parameters.put("aid", Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID));
parameters.put("email", email);
return AndroidNetworkUtils.sendRequest(getMyApplication(), "http://download.osmand.net/subscription/register_email.php", parameters, "Subscribing email...", true, true);
} catch (Exception e) {
return null;
}
}
@Override
protected void onPostExecute(String response) {
if (dlg != null) {
dlg.dismiss();
dlg = null;
}
OsmandApplication app = getMyApplication();
if (response == null) {
app.showShortToastMessage(activity.getString(R.string.shared_string_unexpected_error));
} else {
try {
JSONObject obj = new JSONObject(response);
String responseEmail = obj.getString("email");
if (!email.equalsIgnoreCase(responseEmail)) {
app.showShortToastMessage(activity.getString(R.string.shared_string_unexpected_error));
} else {
int newDownloads = app.getSettings().NUMBER_OF_FREE_DOWNLOADS.get().intValue() - 3;
if (newDownloads < 0) {
newDownloads = 0;
} else if (newDownloads > DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - 3) {
newDownloads = DownloadValidationManager.MAXIMUM_AVAILABLE_FREE_DOWNLOADS - 3;
}
app.getSettings().NUMBER_OF_FREE_DOWNLOADS.set(newDownloads);
app.getSettings().EMAIL_SUBSCRIBED.set(true);
hideSubscribeEmailView();
activity.updateBanner();
}
} catch (JSONException e) {
String message = "JSON parsing error: " + (e.getMessage() == null ? "unknown" : e.getMessage());
app.showShortToastMessage(MessageFormat.format(activity.getString(R.string.error_message_pattern), message));
}
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class TestVoiceActivity method addButton.
public void addButton(ViewGroup layout, final String description, final CommandBuilder builder) {
final Button button = new Button(this);
button.setGravity(Gravity.LEFT);
// or else button text is all upper case
button.setTransformationMethod(null);
button.setText(description);
button.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
if (!description.startsWith("\u25BA (")) {
// Section headline buttons
button.setPadding(10, 20, 10, 5);
} else {
button.setPadding(40, 5, 10, 5);
}
if (description.startsWith("\u25BA (11.1)")) {
infoButton = button;
}
layout.addView(button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
builder.play();
if (description.startsWith("\u25BA (11.1)")) {
infoButton.setText("\u25BA (11.1) (Tap to refresh)\n" + getVoiceSystemInfo());
Toast.makeText(TestVoiceActivity.this, "Info refreshed.", Toast.LENGTH_LONG).show();
}
if (description.startsWith("\u25BA (11.2)")) {
if (((OsmandApplication) getApplication()).getSettings().AUDIO_STREAM_GUIDANCE.get() == 0) {
if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1000) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1500);
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1500) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2000);
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2000) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2500);
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2500) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(3000);
} else {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1000);
}
infoButton.setText("\u25BA (11.1) (Tap to refresh)\n" + getVoiceSystemInfo());
Toast.makeText(TestVoiceActivity.this, "BT SCO init delay changed to " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + "\u00A0ms.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(TestVoiceActivity.this, "Setting only available when using 'Phone call audio'.", Toast.LENGTH_LONG).show();
}
}
}
});
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class TestVoiceActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
((OsmandApplication) getApplication()).applyTheme(this);
super.onCreate(icicle);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
}
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
final OsmandApplication app = ((OsmandApplication) getApplication());
LinearLayout gl = new LinearLayout(this);
gl.setOrientation(LinearLayout.VERTICAL);
gl.setPadding(3, 3, 3, 3);
TextView tv = new TextView(this);
tv.setText("Tap a button and listen to the corresponding voice prompt to identify missing or faulty propmts.");
tv.setPadding(0, 5, 0, 7);
ScrollView sv = new ScrollView(this);
gl.addView(sv, new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT));
final LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
sv.addView(ll, new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT));
// add buttons
setContentView(gl);
getSupportActionBar().setTitle(R.string.test_voice_prompts);
selectVoice(ll);
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class RasterMapMenu method createLayersItems.
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
final OsmandSettings.CommonPreference<String> mapTypePreference;
final OsmandSettings.CommonPreference<String> exMapTypePreference;
final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
@StringRes final int mapTypeString;
@StringRes final int mapTypeStringTransparency;
if (type == RasterMapType.OVERLAY) {
mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
mapTypePreference = settings.MAP_OVERLAY;
exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
mapTypeString = R.string.map_overlay;
mapTypeStringTransparency = R.string.overlay_transparency;
} else if (type == RasterMapType.UNDERLAY) {
mapTransparencyPreference = settings.MAP_TRANSPARENCY;
mapTypePreference = settings.MAP_UNDERLAY;
exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
mapTypeString = R.string.map_underlay;
mapTypeStringTransparency = R.string.map_transparency;
} else {
throw new RuntimeException("Unexpected raster map type");
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
String mapTypeDescr = mapTypePreference.get();
final boolean selected = mapTypeDescr != null;
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
if (type == RasterMapType.UNDERLAY && !canceled && !selected) {
hidePolygonsPref.set(true);
refreshMapComplete(mapActivity);
} else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) {
hidePolygonsPref.set(false);
refreshMapComplete(mapActivity);
}
mapActivity.getDashboard().refreshContent(true);
}
};
final MapActivityLayers mapLayers = mapActivity.getMapLayers();
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == mapTypeString) {
if (selected) {
plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
}
return false;
}
return super.onRowItemClick(adapter, view, itemId, pos);
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
if (itemId == toggleActionStringId) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
refreshMapComplete(mapActivity);
}
});
} else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked);
refreshMapComplete(mapActivity);
} else if (itemId == R.string.show_transparency_seekbar) {
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF);
if (isChecked) {
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
} else {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
}
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked);
}
return false;
}
};
mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(selected).createItem());
if (selected) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {
@Override
public boolean onIntegerValueChangedListener(int newValue) {
mapTransparencyPreference.set(newValue);
mapActivity.getMapView().refreshMap();
return false;
}
};
// android:max="255" in layout is expected
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
if (type == RasterMapType.UNDERLAY) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_polygons, mapActivity).hideDivider(true).setListener(l).setSelected(!hidePolygonsPref.get()).createItem());
}
Boolean transparencySwitchState = isSeekbarVisible(app, type);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
}
}
Aggregations