Search in sources :

Example 96 with OsmandApplication

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

the class MapMarkersListAdapter method calculateStartAndFinishPos.

private void calculateStartAndFinishPos() {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean startCalculated = false;
    boolean finishCalculated = false;
    boolean firstSelectedMarkerCalculated = false;
    if (app.getMapMarkersHelper().isStartFromMyLocation() && showLocationItem) {
        startPos = 0;
        startCalculated = true;
        if (inRoundTrip && !inDragAndDrop) {
            finishPos = 1;
            finishCalculated = true;
        }
    }
    for (int i = 0; i < items.size(); i++) {
        Object item = items.get(i);
        if (item instanceof MapMarker) {
            MapMarker m = (MapMarker) item;
            if (m.selected) {
                if (!startCalculated) {
                    startPos = i;
                    startCalculated = true;
                }
                firstSelectedMarkerPos = i;
                firstSelectedMarkerCalculated = true;
                break;
            }
        }
    }
    for (int i = items.size() - 1; i >= 0; i--) {
        Object item = items.get(i);
        if (item instanceof MapMarker) {
            MapMarker m = (MapMarker) item;
            if (m.selected) {
                finishPos = i + (inRoundTrip && !inDragAndDrop ? 1 : 0);
                finishCalculated = true;
                break;
            }
        }
    }
    if (!startCalculated) {
        startPos = -1;
    }
    if (!finishCalculated) {
        finishPos = -1;
    }
    if (!firstSelectedMarkerCalculated) {
        firstSelectedMarkerPos = -1;
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker)

Example 97 with OsmandApplication

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

the class MapMarkersListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean night = app.getDaynightHelper().isNightModeForMapControls();
    IconsCache iconsCache = app.getIconsCache();
    boolean locationItem = showLocationItem && pos == 0;
    boolean firstMarkerItem = showLocationItem ? pos == 1 : pos == 0;
    boolean lastMarkerItem = pos == getItemCount() - 1;
    boolean start = pos == startPos;
    final boolean finish = pos == finishPos && startPos != finishPos;
    boolean firstSelectedMarker = pos == firstSelectedMarkerPos;
    boolean roundTripFinishItem = finish && showRoundTripItem;
    boolean useLocation = app.getMapMarkersHelper().isStartFromMyLocation() && showLocationItem;
    MapMarker marker = null;
    Location location = null;
    Object item = getItem(pos);
    if (item instanceof Location) {
        location = (Location) item;
    } else {
        marker = (MapMarker) item;
    }
    holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
    holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
    holder.title.setText(location != null ? mapActivity.getString(R.string.shared_string_my_location) : marker.getName(mapActivity));
    holder.iconDirection.setVisibility(View.GONE);
    holder.optionsBtn.setVisibility(roundTripFinishItem ? View.VISIBLE : View.GONE);
    if (roundTripFinishItem) {
        holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
        TypedValue outValue = new TypedValue();
        mapActivity.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        holder.optionsBtn.setBackgroundResource(outValue.resourceId);
        holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onDisableRoundTripClick();
            }
        });
    }
    holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
    holder.divider.setVisibility(lastMarkerItem ? View.GONE : View.VISIBLE);
    holder.checkBox.setVisibility(roundTripFinishItem ? View.GONE : View.VISIBLE);
    if (!roundTripFinishItem) {
        holder.checkBox.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onCheckBoxClick(holder.itemView);
            }
        });
        holder.checkBoxContainer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                holder.checkBox.performClick();
            }
        });
    }
    holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
    holder.iconReorder.setVisibility(View.VISIBLE);
    holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
    holder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
    holder.firstDescription.setVisibility((start || finish) ? View.VISIBLE : View.GONE);
    if (start) {
        holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + " • ");
    } else if (finish) {
        holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + " • ");
    }
    if (location != null) {
        holder.icon.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.map_pedestrian_location));
    } else {
        int res = start ? R.drawable.ic_action_point_start : (finish ? R.drawable.ic_action_point_destination : R.drawable.ic_action_flag_dark);
        holder.icon.setImageDrawable(iconsCache.getIcon(res, MapMarker.getColorId(marker.colorIndex)));
    }
    if (locationItem || roundTripFinishItem) {
        holder.iconReorder.setAlpha(.5f);
        holder.iconReorder.setOnTouchListener(null);
    }
    if (locationItem) {
        holder.topDivider.setVisibility(View.VISIBLE);
        holder.checkBox.setChecked(app.getMapMarkersHelper().isStartFromMyLocation());
        holder.distance.setVisibility(View.GONE);
        holder.description.setText(locDescription.getName());
    } else if (roundTripFinishItem) {
        holder.topDivider.setVisibility(View.GONE);
        holder.description.setText(mapActivity.getString(R.string.round_trip));
    } else {
        holder.topDivider.setVisibility((!showLocationItem && firstMarkerItem) ? View.VISIBLE : View.GONE);
        holder.checkBox.setChecked(marker.selected);
        holder.iconReorder.setAlpha(1f);
        holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent event) {
                if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                    inDragAndDrop = true;
                    if (showRoundTripItem) {
                        int roundTripItemPos = finishPos;
                        reloadData();
                        notifyItemRemoved(roundTripItemPos);
                    }
                    listener.onDragStarted(holder);
                }
                return false;
            }
        });
        String descr;
        if ((descr = marker.groupName) != null) {
            if (descr.equals("")) {
                descr = mapActivity.getString(R.string.shared_string_favorites);
            }
        } else {
            Date date = new Date(marker.creationDate);
            String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
            if (month.length() > 1) {
                month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
            }
            String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
            descr = month + " " + day;
        }
        holder.description.setText(descr);
    }
    boolean showDistance = !roundTripFinishItem && (locationItem ? useLocation : marker != null && marker.selected);
    int visibility = showDistance ? View.VISIBLE : View.GONE;
    holder.distance.setVisibility(visibility);
    holder.point.setVisibility(visibility);
    holder.leftPointSpace.setVisibility(visibility);
    holder.rightPointSpace.setVisibility(visibility);
    if (showDistance) {
        holder.distance.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_distance : R.color.color_myloc_distance));
        LatLon first = firstSelectedMarker && useLocation ? new LatLon(myLoc.getLatitude(), myLoc.getLongitude()) : getPreviousSelectedMarkerLatLon(pos);
        float dist = 0;
        if (first != null && marker != null) {
            WptPt pt1 = new WptPt();
            pt1.lat = first.getLatitude();
            pt1.lon = first.getLongitude();
            WptPt pt2 = new WptPt();
            pt2.lat = marker.getLatitude();
            pt2.lon = marker.getLongitude();
            List<WptPt> points = snappedToRoadPoints.get(new Pair<>(pt1, pt2));
            if (points != null) {
                for (int i = 0; i < points.size() - 1; i++) {
                    dist += (float) MapUtils.getDistance(points.get(i).lat, points.get(i).lon, points.get(i + 1).lat, points.get(i + 1).lon);
                }
            } else {
                dist = (float) MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
            }
        }
        holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Date(java.util.Date) MotionEvent(android.view.MotionEvent) LatLon(net.osmand.data.LatLon) IconsCache(net.osmand.plus.IconsCache) SimpleDateFormat(java.text.SimpleDateFormat) Location(net.osmand.Location) TypedValue(android.util.TypedValue)

Example 98 with OsmandApplication

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

the class FavoritesActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    OsmandApplication app = (OsmandApplication) getApplication();
    app.applyTheme(this);
    super.onCreate(icicle);
    app.logEvent(this, "myplaces_open");
    importHelper = new ImportHelper(this, getMyApplication(), null);
    // noinspection ConstantConditions
    getSupportActionBar().setTitle(R.string.shared_string_my_places);
    getSupportActionBar().setElevation(0);
    setContentView(R.layout.tab_content);
    List<TabItem> mTabs = getTabItems();
    setTabs(mTabs);
    // setupHomeButton();
    ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
    if (icicle == null) {
        Intent intent = getIntent();
        if (intent != null) {
            if (intent.hasExtra(OPEN_FAVOURITES_TAB) && intent.getBooleanExtra(OPEN_FAVOURITES_TAB, false)) {
                if (intent.hasExtra(GROUP_NAME_TO_SHOW)) {
                    groupNameToShow = intent.getStringExtra(GROUP_NAME_TO_SHOW);
                }
                mViewPager.setCurrentItem(0, false);
            } else if (intent.hasExtra(OPEN_MY_PLACES_TAB) && intent.getBooleanExtra(OPEN_MY_PLACES_TAB, false)) {
                mViewPager.setCurrentItem(1, false);
            }
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Intent(android.content.Intent) ViewPager(android.support.v4.view.ViewPager) ImportHelper(net.osmand.plus.helpers.ImportHelper)

Example 99 with OsmandApplication

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

the class FavoritesActivity method setTabs.

private void setTabs(List<TabItem> mTabs) {
    PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
    OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();
    ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
    Integer tabId = settings.FAVORITES_TAB.get();
    int tab = 0;
    for (int i = 0; i < mTabs.size(); i++) {
        if (mTabs.get(i).resId == tabId) {
            tab = i;
        }
    }
    tabSize = mTabs.size();
    setViewPagerAdapter(mViewPager, mTabs);
    mSlidingTabLayout.setViewPager(mViewPager);
    mViewPager.setCurrentItem(tab);
}
Also used : PagerSlidingTabStrip(net.osmand.plus.views.controls.PagerSlidingTabStrip) OsmandApplication(net.osmand.plus.OsmandApplication) ViewPager(android.support.v4.view.ViewPager) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 100 with OsmandApplication

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

the class OsmandMonitoringPlugin method createIntervalChooseLayout.

public static LinearLayout createIntervalChooseLayout(final Context uiCtx, final String patternMsg, final int[] seconds, final int[] minutes, final ValueHolder<Boolean> choice, final ValueHolder<Integer> v, final boolean showTrackSelection, DisplayMetrics dm) {
    LinearLayout ll = new LinearLayout(uiCtx);
    final int dp24 = AndroidUtils.dpToPx(uiCtx, 24f);
    final int dp8 = AndroidUtils.dpToPx(uiCtx, 8f);
    final TextView tv = new TextView(uiCtx);
    tv.setPadding(dp24, dp8 * 2, dp24, dp8);
    tv.setText(String.format(patternMsg, uiCtx.getString(R.string.int_continuosly)));
    SeekBar sp = new SeekBar(uiCtx);
    sp.setPadding(dp24 + dp8, dp8, dp24 + dp8, dp8);
    final int secondsLength = seconds.length;
    final int minutesLength = minutes.length;
    sp.setMax(secondsLength + minutesLength - 1);
    sp.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            String s;
            if (progress == 0) {
                s = uiCtx.getString(R.string.int_continuosly);
                v.value = 0;
            } else {
                if (progress < secondsLength) {
                    s = seconds[progress] + " " + uiCtx.getString(R.string.int_seconds);
                    v.value = seconds[progress] * 1000;
                } else {
                    s = minutes[progress - secondsLength] + " " + uiCtx.getString(R.string.int_min);
                    v.value = minutes[progress - secondsLength] * 60 * 1000;
                }
            }
            tv.setText(String.format(patternMsg, s));
        }
    });
    for (int i = 0; i < secondsLength + minutesLength - 1; i++) {
        if (i < secondsLength) {
            if (v.value <= seconds[i] * 1000) {
                sp.setProgress(i);
                break;
            }
        } else {
            if (v.value <= minutes[i - secondsLength] * 1000 * 60) {
                sp.setProgress(i);
                break;
            }
        }
    }
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(tv);
    ll.addView(sp);
    if (choice != null) {
        final CheckBox cb = new CheckBox(uiCtx);
        cb.setText(R.string.shared_string_remember_my_choice);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        lp.setMargins(dp24, dp8, dp24, 0);
        cb.setLayoutParams(lp);
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                choice.value = isChecked;
            }
        });
        ll.addView(cb);
    }
    if (showTrackSelection) {
        final OsmandApplication app = (OsmandApplication) uiCtx.getApplicationContext();
        boolean light = app.getSettings().isLightContent();
        View divider = new View(uiCtx);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(uiCtx, 1f));
        lp.setMargins(0, dp8 * 2, 0, 0);
        divider.setLayoutParams(lp);
        divider.setBackgroundColor(uiCtx.getResources().getColor(light ? R.color.dashboard_divider_light : R.color.dashboard_divider_dark));
        ll.addView(divider);
        final CheckBox cb = new CheckBox(uiCtx);
        cb.setText(R.string.shared_string_show_on_map);
        lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        lp.setMargins(dp24, dp8 * 2, dp24, 0);
        cb.setLayoutParams(lp);
        cb.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null);
        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), isChecked, false);
            }
        });
        ll.addView(cb);
    }
    return ll;
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) OsmandApplication(net.osmand.plus.OsmandApplication) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) LayoutParams(android.widget.LinearLayout.LayoutParams) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Aggregations

OsmandApplication (net.osmand.plus.OsmandApplication)181 View (android.view.View)46 TextView (android.widget.TextView)39 ArrayList (java.util.ArrayList)33 AlertDialog (android.support.v7.app.AlertDialog)32 ImageView (android.widget.ImageView)31 DialogInterface (android.content.DialogInterface)27 OsmandSettings (net.osmand.plus.OsmandSettings)27 LatLon (net.osmand.data.LatLon)25 Intent (android.content.Intent)21 AdapterView (android.widget.AdapterView)19 File (java.io.File)17 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)15 Location (net.osmand.Location)13 EditText (android.widget.EditText)12 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)12 ArrayAdapter (android.widget.ArrayAdapter)11 ListView (android.widget.ListView)11 ContextMenuItem (net.osmand.plus.ContextMenuItem)11 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)11