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;
}
}
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));
}
}
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);
}
}
}
}
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);
}
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;
}
Aggregations