Search in sources :

Example 61 with OsmandSettings

use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.

the class WakeLockHelper method onVoiceMessage.

@Override
public void onVoiceMessage() {
    OsmandSettings settings = app.getSettings();
    final Integer screenPowerSave = settings.WAKE_ON_VOICE_INT.get();
    if (screenPowerSave > 0) {
        uiHandler.removeCallbacks(releaseWakeLocksRunnable);
        if (!active && wakeLock == null) {
            PowerManager pm = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
            wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "OsmAndOnVoiceWakeupTag");
            wakeLock.acquire();
        }
        uiHandler.postDelayed(releaseWakeLocksRunnable, screenPowerSave * 1000L);
    }
}
Also used : PowerManager(android.os.PowerManager) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 62 with OsmandSettings

use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.

the class LiveUpdatesAlarmReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String fileName = intent.getAction();
    String localIndexInfoFile = intent.getStringExtra(LiveUpdatesHelper.LOCAL_INDEX_INFO);
    if (localIndexInfoFile == null) {
        LOG.error("Unexpected: localIndexInfoFile is null");
        return;
    }
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    final OsmandApplication application = (OsmandApplication) context.getApplicationContext();
    final OsmandSettings settings = application.getSettings();
    if (!preferenceDownloadViaWiFi(localIndexInfoFile, settings).get() || wifi.isWifiEnabled()) {
        new PerformLiveUpdateAsyncTask(context, localIndexInfoFile, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, fileName);
    } else {
        PerformLiveUpdateAsyncTask.tryRescheduleDownload(context, settings, localIndexInfoFile);
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) OsmandApplication(net.osmand.plus.OsmandApplication) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 63 with OsmandSettings

use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    helper = app.getRoutingHelper();
    view = inflater.inflate(R.layout.route_info_layout, container, false);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationContentDescription(R.string.shared_string_close);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    ((ImageView) view.findViewById(R.id.distance_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_route_distance));
    ((ImageView) view.findViewById(R.id.time_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_time_span));
    buildMenuButtons();
    listView = (ListView) view.findViewById(android.R.id.list);
    listView.setBackgroundColor(getResources().getColor(app.getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light : R.color.ctx_menu_info_view_bg_dark));
    View topShadowView = inflater.inflate(R.layout.list_shadow_header, listView, false);
    listView.addHeaderView(topShadowView, null, false);
    View bottomShadowView = inflater.inflate(R.layout.list_shadow_footer, listView, false);
    listView.addFooterView(bottomShadowView, null, false);
    adapter = new RouteInfoAdapter(helper.getRouteDirections());
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position < 2) {
                return;
            }
            RouteDirectionInfo item = adapter.getItem(position - 2);
            Location loc = helper.getLocationFromRouteDirection(item);
            if (loc != null) {
                MapRouteInfoMenu.directionInfo = position - 2;
                OsmandSettings settings = getMyApplication().getSettings();
                settings.setMapLocationToShow(loc.getLatitude(), loc.getLongitude(), Math.max(13, settings.getLastKnownMapZoom()), new PointDescription(PointDescription.POINT_TYPE_MARKER, item.getDescriptionRoutePart() + " " + getTimeDescription(item)), false, null);
                MapActivity.launchMapActivityMoveToTop(getActivity());
                dismiss();
            }
        }
    });
    int dist = helper.getLeftDistance();
    int time = helper.getLeftTime();
    int hours = time / (60 * 60);
    int minutes = (time / 60) % 60;
    ((TextView) view.findViewById(R.id.distance)).setText(OsmAndFormatter.getFormattedDistance(dist, app));
    StringBuilder timeStr = new StringBuilder();
    if (hours > 0) {
        timeStr.append(hours).append(" ").append(getString(R.string.osmand_parking_hour)).append(" ");
    }
    if (minutes > 0) {
        timeStr.append(minutes).append(" ").append(getString(R.string.osmand_parking_minute));
    }
    ((TextView) view.findViewById(R.id.time)).setText(timeStr);
    view.findViewById(R.id.go_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity activity = (MapActivity) getActivity();
            if (activity != null) {
                activity.getMapLayers().getMapControlsLayer().startNavigation();
                dismiss();
            }
        }
    });
    makeGpx();
    if (hasHeights) {
        View headerView = inflater.inflate(R.layout.route_info_header, null);
        buildHeader(headerView);
        listView.addHeaderView(headerView);
    }
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandSettings(net.osmand.plus.OsmandSettings) PointDescription(net.osmand.data.PointDescription) RouteDirectionInfo(net.osmand.plus.routing.RouteDirectionInfo) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Toolbar(android.support.v7.widget.Toolbar) Location(net.osmand.Location)

Example 64 with OsmandSettings

use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method openDetails.

void openDetails() {
    if (gpxItem != null) {
        LatLon location = null;
        WptPt wpt = null;
        gpxItem.chartTypes = new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE };
        if (gpxItem.chartHighlightPos != -1) {
            TrkSegment segment = gpx.tracks.get(0).segments.get(0);
            if (segment != null) {
                float distance = gpxItem.chartHighlightPos * elevationDataSet.getDivX();
                for (WptPt p : segment.points) {
                    if (p.distance >= distance) {
                        wpt = p;
                        break;
                    }
                }
                if (wpt != null) {
                    location = new LatLon(wpt.lat, wpt.lon);
                }
            }
        }
        if (location == null) {
            location = new LatLon(gpxItem.locationStart.lat, gpxItem.locationStart.lon);
        }
        if (wpt != null) {
            gpxItem.locationOnMap = wpt;
        } else {
            gpxItem.locationOnMap = gpxItem.locationStart;
        }
        final MapActivity activity = (MapActivity) getActivity();
        if (activity != null) {
            dismiss();
            final OsmandSettings settings = activity.getMyApplication().getSettings();
            settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, gpxItem.name), false, gpxItem);
            final MapRouteInfoMenu mapRouteInfoMenu = activity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
            if (MapRouteInfoMenu.isVisible()) {
                // We arrived here by the route info menu.
                // First, we close it and then show the details.
                mapRouteInfoMenu.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        mapRouteInfoMenu.setOnDismissListener(null);
                        MapActivity.launchMapActivityMoveToTop(activity);
                    }
                });
                mapRouteInfoMenu.hide();
            } else {
                // We arrived here by the dashboard.
                MapActivity.launchMapActivityMoveToTop(activity);
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.plus.GPXUtilities.WptPt) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) DialogInterface(android.content.DialogInterface) PointDescription(net.osmand.data.PointDescription) OnDismissListener(android.content.DialogInterface.OnDismissListener) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 65 with OsmandSettings

use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.

the class AppModeDialog method prepareAppModeView.

public static View prepareAppModeView(Activity a, final Set<ApplicationMode> selected, boolean showDefault, ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener) {
    OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
    final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));
    if (!showDefault) {
        values.remove(ApplicationMode.DEFAULT);
    }
    if (showDefault || (settings.getApplicationMode() != ApplicationMode.DEFAULT && !singleSelection)) {
        selected.add(settings.getApplicationMode());
    }
    return prepareAppModeView(a, values, selected, parent, singleSelection, useListBg, useMapTheme, onClickListener);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) ApplicationMode(net.osmand.plus.ApplicationMode) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

OsmandSettings (net.osmand.plus.OsmandSettings)91 View (android.view.View)27 OsmandApplication (net.osmand.plus.OsmandApplication)25 ArrayList (java.util.ArrayList)20 LatLon (net.osmand.data.LatLon)17 DialogInterface (android.content.DialogInterface)14 ArrayAdapter (android.widget.ArrayAdapter)14 TextView (android.widget.TextView)14 AlertDialog (android.support.v7.app.AlertDialog)11 ImageView (android.widget.ImageView)11 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)8 ContextMenuItem (net.osmand.plus.ContextMenuItem)8 ApplicationMode (net.osmand.plus.ApplicationMode)7 Paint (android.graphics.Paint)6 Pair (android.support.v4.util.Pair)6 ListView (android.widget.ListView)6 SpannableString (android.text.SpannableString)5 CompoundButton (android.widget.CompoundButton)5