use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class SubscriptionFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
InAppHelper helper = getInAppHelper();
if (helper != null) {
helper.addListener(this);
}
String userName = settings.BILLING_USER_NAME.get();
String email = settings.BILLING_USER_EMAIL.get();
String countryDownloadName = settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get();
boolean hideUserName = settings.BILLING_HIDE_USER_NAME.get();
donation = !countryDownloadName.equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER);
if (savedInstanceState != null) {
userName = savedInstanceState.getString(USER_NAME_ID);
email = savedInstanceState.getString(EMAIL_ID);
hideUserName = savedInstanceState.getBoolean(HIDE_USER_NAME_ID);
donation = savedInstanceState.getBoolean(DONATION_ID);
Object obj = savedInstanceState.getSerializable(COUNTRY_ITEM_ID);
if (obj instanceof CountryItem) {
selectedCountryItem = (CountryItem) obj;
countryDownloadName = selectedCountryItem.getDownloadName();
} else {
countryDownloadName = donation ? OsmandSettings.BILLING_USER_DONATION_WORLD_PARAMETER : OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER;
}
}
View view = inflater.inflate(R.layout.subscription_fragment, container, false);
ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
if (editMode) {
closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
} else {
closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_remove_dark));
}
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
TextView title = (TextView) view.findViewById(R.id.titleTextView);
if (editMode) {
title.setText(getString(R.string.osm_live_subscription_settings));
} else {
title.setText(getString(R.string.osm_live_subscription));
}
final View headerLayout = view.findViewById(R.id.headerLayout);
final View paramsLayout = view.findViewById(R.id.paramsLayout);
AppCompatCheckBox donationCheckbox = (AppCompatCheckBox) view.findViewById(R.id.donationCheckbox);
donationCheckbox.setChecked(donation);
donationCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
donation = isChecked;
paramsLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
}
});
headerLayout.setVisibility(View.VISIBLE);
paramsLayout.setVisibility(donation ? View.VISIBLE : View.GONE);
final EditText userNameEdit = (EditText) view.findViewById(R.id.userNameEdit);
if (!Algorithms.isEmpty(userName)) {
userNameEdit.setText(userName);
}
final EditText emailEdit = (EditText) view.findViewById(R.id.emailEdit);
if (!Algorithms.isEmpty(email)) {
emailEdit.setText(email);
}
countrySelectionFragment.initCountries(getMyApplication());
if (Algorithms.isEmpty(countryDownloadName) || countryDownloadName.equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER)) {
selectedCountryItem = countrySelectionFragment.getCountryItems().get(0);
} else {
selectedCountryItem = countrySelectionFragment.getCountryItem(countryDownloadName);
}
final EditText selectCountryEdit = (EditText) view.findViewById(R.id.selectCountryEdit);
if (selectedCountryItem != null) {
selectCountryEdit.setText(selectedCountryItem.getLocalName());
}
selectCountryEdit.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
CountrySelectionFragment countryCountrySelectionFragment = countrySelectionFragment;
countryCountrySelectionFragment.show(getChildFragmentManager(), "CountriesSearchSelectionFragment");
}
return false;
}
});
final CheckBox hideUserNameCheckbox = (CheckBox) view.findViewById(R.id.hideUserNameCheckbox);
hideUserNameCheckbox.setChecked(hideUserName);
View editModeBottomView = view.findViewById(R.id.editModeBottomView);
View purchaseCard = view.findViewById(R.id.purchaseCard);
if (editMode) {
editModeBottomView.setVisibility(View.VISIBLE);
purchaseCard.setVisibility(View.GONE);
Button saveChangesButton = (Button) view.findViewById(R.id.saveChangesButton);
saveChangesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InAppHelper helper = getInAppHelper();
if (helper != null && applySettings(userNameEdit.getText().toString().trim(), emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
final Map<String, String> parameters = new HashMap<>();
parameters.put("visibleName", settings.BILLING_HIDE_USER_NAME.get() ? "" : settings.BILLING_USER_NAME.get());
parameters.put("preferredCountry", settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get());
parameters.put("email", settings.BILLING_USER_EMAIL.get());
parameters.put("cemail", prevEmail);
parameters.put("userid", settings.BILLING_USER_ID.get());
parameters.put("token", helper.getToken());
showProgress();
AndroidNetworkUtils.sendRequestAsync(getMyApplication(), "http://download.osmand.net/subscription/update.php", parameters, "Sending data...", true, true, new AndroidNetworkUtils.OnRequestResultListener() {
@Override
public void onResult(String result) {
dismissProgress();
OsmandApplication app = getMyApplication();
if (result != null) {
try {
JSONObject obj = new JSONObject(result);
if (!obj.has("error")) {
String userId = obj.getString("userid");
app.getSettings().BILLING_USER_ID.set(userId);
String email = obj.getString("email");
app.getSettings().BILLING_USER_EMAIL.set(email);
String visibleName = obj.getString("visibleName");
if (!Algorithms.isEmpty(visibleName)) {
app.getSettings().BILLING_USER_NAME.set(visibleName);
app.getSettings().BILLING_HIDE_USER_NAME.set(false);
} else {
app.getSettings().BILLING_HIDE_USER_NAME.set(true);
}
String preferredCountry = obj.getString("preferredCountry");
app.getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.set(preferredCountry);
Fragment parent = getParentFragment();
if (parent != null && parent instanceof LiveUpdatesFragment) {
((LiveUpdatesFragment) parent).updateSubscriptionHeader();
}
dismiss();
} else {
app.showToastMessage("Error: " + obj.getString("error"));
}
} catch (JSONException e) {
app.showToastMessage(getString(R.string.shared_string_io_error));
}
} else {
app.showToastMessage(getString(R.string.shared_string_io_error));
}
}
});
}
}
});
} else {
editModeBottomView.setVisibility(View.GONE);
purchaseCard.setVisibility(View.VISIBLE);
updatePrice(view);
final Button subscribeButton = (Button) view.findViewById(R.id.subscribeButton);
subscribeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InAppHelper helper = getInAppHelper();
if (helper != null) {
if (applySettings(userNameEdit.getText().toString().trim(), emailEdit.getText().toString().trim(), hideUserNameCheckbox.isChecked())) {
helper.purchaseLiveUpdates(getActivity(), settings.BILLING_USER_EMAIL.get(), settings.BILLING_USER_NAME.get(), settings.BILLING_USER_COUNTRY_DOWNLOAD_NAME.get(), settings.BILLING_HIDE_USER_NAME.get());
}
}
}
});
}
setThemedDrawable((ImageView) view.findViewById(R.id.userNameIcon), R.drawable.ic_person);
setThemedDrawable((ImageView) view.findViewById(R.id.emailIcon), R.drawable.ic_action_message);
setThemedDrawable((ImageView) view.findViewById(R.id.countryIcon), R.drawable.ic_world_globe_dark);
selectCountryEdit.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
return view;
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class FirstUsageWizardFragment method onStart.
@Override
public void onStart() {
super.onStart();
final OsmandApplication app = getMyApplication();
switch(wizardType) {
case SEARCH_LOCATION:
if (searchLocationByIp) {
final Map<String, String> pms = new LinkedHashMap<>();
pms.put("version", Version.getFullVersion(app));
try {
pms.put("aid", Secure.getString(app.getContentResolver(), Secure.ANDROID_ID));
} catch (Exception e) {
e.printStackTrace();
}
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
return AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/geo-ip", pms, "Requesting location by IP...", false, false);
} catch (Exception e) {
logError("Requesting location by IP error: ", e);
return null;
}
}
@Override
protected void onPostExecute(String response) {
if (response != null) {
try {
JSONObject obj = new JSONObject(response);
double latitude = obj.getDouble("latitude");
double longitude = obj.getDouble("longitude");
if (latitude == 0 && longitude == 0) {
showNoLocationFragment(getActivity());
} else {
location = new Location("geo-ip");
location.setLatitude(latitude);
location.setLongitude(longitude);
showSearchMapFragment(getActivity());
}
} catch (Exception e) {
logError("JSON parsing error: ", e);
showNoLocationFragment(getActivity());
}
} else {
showNoLocationFragment(getActivity());
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
FragmentActivity activity = getActivity();
if (!OsmAndLocationProvider.isLocationPermissionAvailable(activity)) {
ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, FIRST_USAGE_LOCATION_PERMISSION);
} else {
app.getLocationProvider().addLocationListener(this);
locationSearchTimer = new Timer();
locationSearchTimer.schedule(new TimerTask() {
@Override
public void run() {
FragmentActivity a = getActivity();
if (a != null) {
showNoLocationFragment(a);
}
}
}, 1000 * 10);
}
}
break;
case NO_INTERNET:
break;
case NO_LOCATION:
break;
case SEARCH_MAP:
if (app.isApplicationInitializing()) {
app.getAppInitializer().addListener(this);
} else {
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
waitForIndexes = true;
downloadThread.runReloadIndexFilesSilent();
} else {
searchMap();
}
}
break;
case MAP_FOUND:
break;
case MAP_DOWNLOAD:
if (!startDownload(0)) {
startDownload(1);
}
if (localDownloadRegion != null) {
downloadThread.initSettingsFirstMap(localDownloadRegion);
}
break;
}
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class FirstUsageWizardFragment method onStop.
@Override
public void onStop() {
super.onStop();
OsmandApplication app = getMyApplication();
cancelLocationSearchTimer();
app.getLocationProvider().removeLocationListener(this);
app.getAppInitializer().removeListener(this);
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class MapDataMenuController method deleteItem.
public void deleteItem(final File fl) {
final OsmandApplication app = getMapActivity().getMyApplication();
if (fl.exists()) {
AlertDialog.Builder confirm = new AlertDialog.Builder(getMapActivity());
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
getMapActivity().getContextMenu().close();
}
@Override
protected Void doInBackground(Void... params) {
boolean successfull = Algorithms.removeAllFiles(fl.getAbsoluteFile());
if (successfull) {
app.getResourceManager().closeFile(fl.getName());
}
app.getDownloadThread().updateLoadedFiles();
return null;
}
protected void onPostExecute(Void result) {
getMapActivity().refreshMap();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
});
confirm.setNegativeButton(R.string.shared_string_no, null);
String fn;
if (indexItem != null) {
fn = FileNameTranslationHelper.getFileName(getMapActivity(), app.getRegions(), indexItem.getVisibleName(getMapActivity(), app.getRegions()));
} else {
fn = getPointDescription().getName();
}
confirm.setMessage(getMapActivity().getString(R.string.delete_confirmation_msg, fn));
confirm.show();
}
}
use of net.osmand.plus.OsmandApplication in project Osmand by osmandapp.
the class SettingsAccessibilityActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
((OsmandApplication) getApplication()).applyTheme(this);
super.onCreate(savedInstanceState);
getToolbar().setTitle(R.string.shared_string_accessibility);
PreferenceScreen grp = getPreferenceScreen();
String[] entries = new String[AccessibilityMode.values().length];
for (int i = 0; i < entries.length; i++) {
entries[i] = AccessibilityMode.values()[i].toHumanString(getMyApplication());
}
accessibilityModePreference = createListPreference(settings.ACCESSIBILITY_MODE, entries, AccessibilityMode.values(), R.string.accessibility_mode, R.string.accessibility_mode_descr);
accessibilityModePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
private final OnPreferenceChangeListener committer = accessibilityModePreference.getOnPreferenceChangeListener();
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (committer != null)
committer.onPreferenceChange(preference, newValue);
updateAllSettings();
return true;
}
});
addSpeechRateSetting(grp);
grp.addPreference(accessibilityModePreference);
PreferenceCategory cat = new PreferenceCategory(this);
cat.setKey("accessibility_options");
cat.setTitle(R.string.accessibility_options);
cat.setEnabled(getMyApplication().accessibilityEnabled());
grp.addPreference(cat);
entries = new String[RelativeDirectionStyle.values().length];
for (int i = 0; i < entries.length; i++) {
entries[i] = RelativeDirectionStyle.values()[i].toHumanString(getMyApplication());
}
directionStylePreference = createListPreference(settings.DIRECTION_STYLE, entries, RelativeDirectionStyle.values(), R.string.settings_direction_style, R.string.settings_direction_style_descr);
directionStylePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
private final OnPreferenceChangeListener committer = directionStylePreference.getOnPreferenceChangeListener();
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (committer != null)
committer.onPreferenceChange(preference, newValue);
updateAllSettings();
return true;
}
});
cat.addPreference(directionStylePreference);
cat.addPreference(createCheckBoxPreference(settings.ACCESSIBILITY_SMART_AUTOANNOUNCE, R.string.access_smart_autoannounce, R.string.access_smart_autoannounce_descr));
final int[] seconds = new int[] { 5, 10, 15, 20, 30, 45, 60, 90 };
final int[] minutes = new int[] { 2, 3, 5 };
autoannouncePeriodPreference = createTimeListPreference(settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD, seconds, minutes, 1000, R.string.access_autoannounce_period, R.string.access_autoannounce_period_descr);
autoannouncePeriodPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
private final OnPreferenceChangeListener committer = autoannouncePeriodPreference.getOnPreferenceChangeListener();
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (committer != null)
committer.onPreferenceChange(preference, newValue);
updateAllSettings();
return true;
}
});
cat.addPreference(autoannouncePeriodPreference);
cat.addPreference(createCheckBoxPreference(settings.DISABLE_OFFROUTE_RECALC, R.string.access_disable_offroute_recalc, R.string.access_disable_offroute_recalc_descr));
cat.addPreference(createCheckBoxPreference(settings.DISABLE_WRONG_DIRECTION_RECALC, R.string.access_disable_wrong_direction_recalc, R.string.access_disable_wrong_direction_recalc_descr));
cat.addPreference(createCheckBoxPreference(settings.DIRECTION_AUDIO_FEEDBACK, R.string.access_direction_audio_feedback, R.string.access_direction_audio_feedback_descr));
cat.addPreference(createCheckBoxPreference(settings.DIRECTION_HAPTIC_FEEDBACK, R.string.access_direction_haptic_feedback, R.string.access_direction_haptic_feedback_descr));
cat.addPreference(createCheckBoxPreference(settings.ZOOM_BY_TRACKBALL, R.string.zoom_by_trackball, R.string.zoom_by_trackball_descr));
}
Aggregations