Merge pull request #1075 from Bars107/master

Favorites and updates lists.
This commit is contained in:
vshcherb 2015-02-16 17:17:57 +01:00
commit 9ce7ada675
17 changed files with 381 additions and 267 deletions

View file

@ -43,8 +43,8 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:textSize="12sp"
tools:text="@string/lorem_ipsum"/>
android:textSize="@dimen/download_descr_text_size"
tools:text="@string/app_version"/>
<TextView
android:id="@+id/update_descr"
@ -52,7 +52,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_distance"
android:textSize="12sp"
android:textSize="@dimen/download_descr_text_size"
tools:text="@string/lorem_ipsum"
android:maxLines="1"/>
</LinearLayout>

View file

@ -19,18 +19,18 @@
android:visibility="gone"
tools:visibility="visible"/>
<ImageView
android:id="@+id/favourite_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/favourite_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/favorites_icon_right_margin"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"

View file

@ -51,6 +51,7 @@
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="true"
android:groupIndicator="@android:color/transparent"/>
</LinearLayout>

View file

@ -3,65 +3,80 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:background="?attr/expandable_list_item_background"
android:paddingTop="4dp">
android:paddingRight="@dimen/list_content_padding">
<LinearLayout
<CheckBox
android:id="@+id/check_local_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:visibility="gone"
android:layout_marginRight="@dimen/local_index_check_right_margin"
android:layout_gravity="center_vertical"/>
<ImageView
android:id="@+id/icon"
android:src="@drawable/ic_sdcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
android:focusable="false"
android:layout_gravity="center_vertical"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/local_index_name"
style="@style/ListText.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
tools:text="@string/app_version"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<CheckBox
android:id="@+id/check_local_index"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"/>
</LinearLayout>
<TextView
android:id="@+id/local_index_name"
style="@style/ListText.Small"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:maxLines="1"
tools:text="@string/lorem_ipsum"/>
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/local_index_size"
style="@style/ListText.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:gravity="right"/>
</LinearLayout>
android:gravity="right"
tools:text="@string/app_version"/>
<TextView
android:id="@+id/local_index_descr"
style="@style/ListText.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:maxLines="25"
tools:text="@string/lorem_ipsum"/>
<TextView
android:id="@+id/local_index_descr"
style="@style/ListText.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginLeft="7dp"
android:maxLines="25"
tools:text="@string/app_mode_aircraft"/>
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/dashboardGeneralButtonStyle"
android:layout_marginRight="0dp"
android:layout_gravity="center_vertical"
android:focusable="false"
android:src="?attr/list_settings_icon"/>
</LinearLayout>

View file

@ -1,37 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/list_item_height"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:orientation="horizontal">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingTop="5dp">
<TextView
android:id="@+id/label"
style="@style/ListText"
<TextView
android:id="@+id/label"
style="@style/ListText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:textColor="?android:textColorPrimary"
android:maxLines="1"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:ellipsize="end"
tools:text="@string/lorem_ipsum"
android:layout_weight="1" />
android:maxLines="1"
android:textColor="?android:textColorPrimary"
tools:text="@string/lorem_ipsum"/>
<ImageButton
android:id="@+id/remove"
android:contentDescription="@string/default_buttons_delete"
<ImageButton
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/reset_image"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="2dp" />
android:background="?attr/reset_image"
android:contentDescription="@string/default_buttons_delete"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="2dp"/>
</LinearLayout>

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_header_padding">
<CheckBox
android:id="@+id/select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/updates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_header_text_left_margin"
android:text="@string/download_tab_updates"/>
</LinearLayout>
<ListView
android:id="@android:id/list"
style="@style/OsmandListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:layout_weight="1"/>
</LinearLayout>

View file

@ -1,35 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height"
android:paddingBottom="1dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingTop="1dp">
<CheckBox
android:id="@+id/check_download_item"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:focusable="false" />
<CheckBox
android:id="@+id/check_download_item"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/download_item"
android:gravity="center_vertical"
android:maxLines="7"
android:layout_weight="1"
style="@style/ListText.Small" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/download_item"
style="@style/ListText.Small"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
tools:text="@string/app_version"
android:maxLines="7"/>
<TextView
android:id="@+id/download_descr"
style="@style/ListText.Small"
android:textSize="@dimen/download_descr_text_size"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:text="@string/app_version"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/download_descr"
android:layout_marginLeft="3dp"
android:gravity="right|center_vertical"
style="@style/ListText.Small" />
</LinearLayout>

View file

@ -33,6 +33,7 @@
<dimen name="list_header_bottom_margin">8dp</dimen>
<dimen name="bottom_tool_bar_size">48dp</dimen>
<dimen name="favorites_icon_right_margin">18dp</dimen>
<dimen name="local_index_check_right_margin">10dp</dimen>
<dimen name="favorites_icon_top_margin">13dp</dimen>
<dimen name="dialog_elements_vertical_margin">16dp</dimen>
<dimen name="dialog_content_margin">24dp</dimen>
@ -42,6 +43,7 @@
<!-- TextSizes -->
<dimen name="list_header_text_size">14sp</dimen>
<dimen name="showAllButtonTextSize">12sp</dimen>
<dimen name="download_descr_text_size">12sp</dimen>
<dimen name="subHeaderTextSize">14sp</dimen>
<dimen name="dashFavNameTextSize">16sp</dimen>
<dimen name="dashProgressTextSize">18sp</dimen>

View file

@ -1,7 +1,5 @@
package net.osmand.plus;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.*;
import gnu.trove.list.array.TIntArrayList;

View file

@ -45,7 +45,7 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip;
/**
*
*/
public class FavoritesActivity extends TabActivity implements OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener {
public class FavoritesActivity extends TabActivity {
private static final String FAVOURITES_INFO = "FAVOURITES_INFO";
private static final String TRACKS = "TRACKS";
@ -125,10 +125,6 @@ public class FavoritesActivity extends TabActivity implements OsmAndLocationProv
}
});
if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) {
getLocationProvider().addCompassListener(this);
getLocationProvider().registerOrUnregisterCompassListener(true);
}
}
public OsmandApplication getMyApplication() {
@ -143,9 +139,6 @@ public class FavoritesActivity extends TabActivity implements OsmAndLocationProv
protected void onPause() {
super.onPause();
((OsmandApplication) getApplication()).getSelectedGpxHelper().setUiListener(FavoritesActivity.class, null);
getLocationProvider().pauseAllUpdates();
getLocationProvider().removeLocationListener(this);
getLocationProvider().removeCompassListener(this);
}
public void updateSelectedTracks() {
@ -217,25 +210,5 @@ public class FavoritesActivity extends TabActivity implements OsmAndLocationProv
}
}
@Override
public void updateCompassValue(float value) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if (f instanceof FavoritesTreeFragment && !f.isDetached()) {
((FavoritesTreeFragment) f).updateCompassValue(value);
}
}
}
@Override
public void updateLocation(Location location) {
for (WeakReference<Fragment> ref : fragList) {
Fragment f = ref.get();
if (f instanceof FavoritesTreeFragment && !f.isDetached()) {
((FavoritesTreeFragment) f).updateLocation(location);
}
}
}
}

View file

@ -3,17 +3,16 @@
*/
package net.osmand.plus.activities;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v4.app.ListFragment;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.view.*;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -48,7 +47,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
private boolean selectFavoriteMode;
private OsmandSettings settings;
private LatLon location;
@Override
public void onAttach(Activity activity) {
@ -87,6 +86,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
}
}
locationUpdate(location);
}
@Override
@ -132,6 +132,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
private Activity activity;
private LatLon location;
private OsmandApplication app;
Drawable arrowImage;
public LatLon getLocation() {
return location;
@ -162,6 +163,14 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
super(activity, R.layout.favourites_list_item, list);
this.activity = activity;
this.app = ((OsmandApplication) activity.getApplication());
boolean light = app.getSettings().isLightContent();
arrowImage = activity.getResources().getDrawable(R.drawable.ic_destination_arrow_white);
arrowImage.mutate();
if (light) {
arrowImage.setColorFilter(activity.getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
} else {
arrowImage.setColorFilter(activity.getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
}
}
public String getName(FavouritePoint model){
@ -179,8 +188,12 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
row = inflater.inflate(R.layout.favourites_list_item, parent, false);
}
TextView label = (TextView) row.findViewById(R.id.favourite_label);
TextView name = (TextView) row.findViewById(R.id.favourite_label);
TextView distanceText = (TextView) row.findViewById(R.id.distance);
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
ImageView direction = (ImageView) row.findViewById(R.id.direction);
direction.setImageDrawable(arrowImage);
direction.setVisibility(View.VISIBLE);
final FavouritePoint model = getItem(position);
if (!model.getCategory().isEmpty()){
row.findViewById(R.id.group_image).setVisibility(View.VISIBLE);
@ -196,9 +209,8 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
.getLongitude()));
distance = OsmAndFormatter.getFormattedDistance(dist, app) + " " ;
}
label.setText(distance + getName(model), BufferType.SPANNABLE);
((Spannable) label.getText()).setSpan(new ForegroundColorSpan(activity.getResources().getColor(R.color.color_distance)), 0, distance.length(), 0);
distanceText.setText(distance);
name.setText(getName(model));
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
row.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE);
ch.setVisibility(View.GONE);
@ -207,5 +219,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
}
public OsmandApplication getMyApplication() {
return (OsmandApplication)getActivity().getApplication();
}
}

View file

@ -1,8 +1,8 @@
package net.osmand.plus.activities;
import android.app.Dialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode;
@ -12,8 +12,6 @@ import android.view.*;
import gnu.trove.list.array.TIntArrayList;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
@ -23,26 +21,20 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import net.osmand.Location;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.util.MapUtils;
@ -56,7 +48,6 @@ import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.CheckBox;
@ -89,9 +80,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
private Set<FavoriteGroup> groupsToDelete = new LinkedHashSet<FavoriteGroup>();
private ActionMode actionMode;
private SearchView searchView;
protected LatLon loc = null;
protected Float heading = null;
Drawable arrowImage;
@Override
public void onAttach(Activity activity) {
@ -101,6 +90,15 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
favouritesAdapter = new FavouritesAdapter();
favouritesAdapter.synchronizeGroups();
setAdapter(favouritesAdapter);
boolean light = getMyApplication().getSettings().isLightContent();
arrowImage = getResources().getDrawable(R.drawable.ic_destination_arrow_white);
arrowImage.mutate();
if (light) {
arrowImage.setColorFilter(getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
} else {
arrowImage.setColorFilter(getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
}
}
private void deleteFavorites() {
@ -135,8 +133,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
// final LatLon mapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
favouritesAdapter.synchronizeGroups();
loc = getMyApplication().getSettings().getLastKnownMapLocation();
if(favouritesAdapter.getGroupCount() > 0 &&
if(favouritesAdapter.getGroupCount() > 0 &&
"".equals(favouritesAdapter.getGroup(0).name)) {
getExpandableListView().expandGroup(0);
}
@ -787,12 +784,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
distanceText.setTextColor(getResources().getColor(R.color.color_distance));
row.findViewById(R.id.group_image).setVisibility(View.GONE);
if(loc != null){
ImageView direction = (ImageView) row.findViewById(R.id.direction);
direction.setVisibility(View.VISIBLE);
DashLocationFragment.updateArrow(getActivity(), loc, new LatLon(model.getLatitude(), model.getLongitude()), direction,
10, R.drawable.ic_destination_arrow, heading);
}
ImageView direction = (ImageView) row.findViewById(R.id.direction);
direction.setVisibility(View.VISIBLE);
direction.setImageDrawable(arrowImage);
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
if (selectionMode) {
@ -880,34 +874,4 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
}
}
}
public void updateLocation(Location location) {
//This is used as origin for both Fav-list and direction arrows
if (getMyApplication().getSettings().getLastKnownMapLocation() != null) {
loc = getMyApplication().getSettings().getLastKnownMapLocation();
} else {
loc = new LatLon(0f, 0f);
}
updateArrows();
}
public boolean updateCompassValue(float value) {
//heading = value;
//updateArrows();
//99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass devices
float lastHeading = heading != null ? heading : 99;
heading = value;
if (heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
updateArrows();
return true;
} else {
heading = lastHeading;
}
return false;
}
private void updateArrows(){
favouritesAdapter.notifyDataSetChanged();
}
}

View file

@ -14,7 +14,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;

View file

@ -295,9 +295,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
} else {
arrowImage.setColorFilter(getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
}
}
private void addFooterView() {

View file

@ -157,7 +157,7 @@ public class DirectionsDialogs {
}
}
private static void setupPopUpMenuIcon(PopupMenu menu){
public static void setupPopUpMenuIcon(PopupMenu menu){
try {
Field[] fields = menu.getClass().getDeclaredFields();
for (Field field : fields) {

View file

@ -26,6 +26,7 @@ import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
import android.app.Activity;
@ -34,13 +35,16 @@ import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StatFs;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.text.method.LinkMovementMethod;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@ -56,6 +60,7 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@ -83,6 +88,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
private TextView descriptionText;
private ProgressBar sizeProgress;
Drawable backup;
Drawable sdcard;
Drawable planet;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.local_index, container, false);
@ -98,6 +107,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
descriptionText = (TextView) view.findViewById(R.id.memory_size);
sizeProgress = (ProgressBar) view.findViewById(R.id.memory_progress);
updateDescriptionTextWithSize();
colorDrawables();
return view;
}
@ -119,7 +129,19 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
setHasOptionsMenu(true);
}
private void colorDrawables(){
boolean light = getMyApplication().getSettings().isLightContent();
backup = getActivity().getResources().getDrawable(R.drawable.ic_type_archive);
backup.mutate();
if (light) {
backup.setColorFilter(0xff727272, PorterDuff.Mode.MULTIPLY);
}
sdcard = getActivity().getResources().getDrawable(R.drawable.ic_sdcard);
sdcard.mutate();
sdcard.setColorFilter(getActivity().getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
}
@Override
public void onResume() {
super.onResume();
@ -172,25 +194,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
if (resId == R.string.local_index_mi_rename) {
renameFile(info);
} else if (resId == R.string.local_index_mi_restore) {
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
} else if (resId == R.string.local_index_mi_delete) {
Builder confirm = new AlertDialog.Builder(getActivity());
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new LocalIndexOperationTask(DELETE_OPERATION).execute(info);
}
});
confirm.setNegativeButton(R.string.default_buttons_no, null);
confirm.setMessage(getString(R.string.delete_confirmation_msg, info.getFileName()));
confirm.show();
} else if (resId == R.string.local_index_mi_backup) {
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
}
return true;
return performBasicOperation(resId, info);
}
};
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA){
@ -204,7 +208,29 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
adapter.item(R.string.local_index_mi_rename).listen(listener).position(3).reg();
adapter.item(R.string.local_index_mi_delete).listen(listener).position(4).reg();
}
private boolean performBasicOperation(int resId, final LocalIndexInfo info) {
if (resId == R.string.local_index_mi_rename) {
renameFile(info);
} else if (resId == R.string.local_index_mi_restore) {
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
} else if (resId == R.string.local_index_mi_delete) {
Builder confirm = new Builder(getActivity());
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new LocalIndexOperationTask(DELETE_OPERATION).execute(info);
}
});
confirm.setNegativeButton(R.string.default_buttons_no, null);
confirm.setMessage(getString(R.string.delete_confirmation_msg, info.getFileName()));
confirm.show();
} else if (resId == R.string.local_index_mi_backup) {
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
}
return true;
}
private void renameFile(LocalIndexInfo info) {
final File f = new File(info.getPathToData());
Builder b = new AlertDialog.Builder(getActivity());
@ -922,6 +948,21 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
}
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name));
v.findViewById(R.id.options).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPopUpMenu(v, child);
}
});
ImageView icon = (ImageView) v.findViewById(R.id.icon);
if (child.isBackupedData()) {
icon.setImageDrawable(backup);
} else {
icon.setImageDrawable(sdcard);
}
viewName.setText(getNameToDisplay(child));
if (child.isNotSupported()) {
viewName.setTextColor(warningColor);
@ -962,6 +1003,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
final CheckBox checkbox = (CheckBox) v.findViewById(R.id.check_local_index);
checkbox.setVisibility(selectionMode ? View.VISIBLE : View.GONE);
if (selectionMode) {
icon.setVisibility(View.GONE);
checkbox.setChecked(selectedItems.contains(child));
checkbox.setOnClickListener(new View.OnClickListener() {
@ -974,12 +1016,51 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
}
}
});
} else {
icon.setVisibility(View.VISIBLE);
}
return v;
}
private void openPopUpMenu(View v, final LocalIndexInfo info) {
boolean light = getMyApplication().getSettings().isLightContent();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
final boolean restore = info.isBackupedData();
MenuItem item = optionsMenu.getMenu().add(restore? R.string.local_index_mi_restore : R.string.local_index_mi_backup)
.setIcon(backup);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(restore ? R.string.local_index_mi_restore : R.string.local_index_mi_backup, info);
return true;
}
});
item = optionsMenu.getMenu().add(R.string.favourites_context_menu_edit)
.setIcon(light ? R.drawable.ic_action_edit_light : R.drawable.ic_action_edit_dark);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.local_index_mi_rename, info);
return true;
}
});
item = optionsMenu.getMenu().add(R.string.favourites_context_menu_delete)
.setIcon(light ? R.drawable.ic_action_delete_light : R.drawable.ic_action_delete_dark);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
performBasicOperation(R.string.local_index_mi_delete, info);
return true;
}
});
optionsMenu.show();
}
private String getNameToDisplay(LocalIndexInfo child) {
String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx,

View file

@ -9,6 +9,7 @@ import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.view.*;
import android.widget.*;
import net.osmand.access.AccessibleToast;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
@ -29,25 +30,62 @@ public class UpdatesIndexFragment extends ListFragment {
private OsmandRegions osmandRegions;
private java.text.DateFormat format;
private UpdateIndexAdapter listAdapter;
private int updateColor;
List<IndexItem> indexItems = new ArrayList<IndexItem>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.update_index, container, false);
CheckBox selectAll = (CheckBox) view.findViewById(R.id.select_all);
selectAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
for (IndexItem item : indexItems) {
if (isChecked) {
List<DownloadEntry> download = item.createDownloadEntry(getMyApplication(), item.getType(), new ArrayList<DownloadEntry>());
if (download.size() > 0) {
getDownloadActivity().getEntriesToDownload().put(item, download);
getDownloadActivity().updateDownloadButton(true);
}
} else {
getDownloadActivity().getEntriesToDownload().remove(item);
getDownloadActivity().updateDownloadButton(true);
}
}
}
});
return view;
}
private void setSelectAllVisibility(boolean visible) {
View view = getView();
if (view == null) {
return;
}
if (visible) {
view.findViewById(R.id.header).setVisibility(View.VISIBLE);
} else {
view.findViewById(R.id.header).setVisibility(View.GONE);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
format = getMyApplication().getResourceManager().getDateFormat();
updateColor = getResources().getColor(R.color.color_update);
osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
List<IndexItem> indexItems = new ArrayList<IndexItem>();
if (BaseDownloadActivity.downloadListIndexThread != null) {
indexItems = new ArrayList<IndexItem>(DownloadActivity.downloadListIndexThread.getItemsToUpdate());
indexItems = new ArrayList<IndexItem>(DownloadActivity.downloadListIndexThread.getItemsToUpdate());
}
createListView(indexItems);
createListView();
setHasOptionsMenu(true);
}
private void createListView(List<IndexItem> indexItems) {
private void createListView() {
updateHeader();
if (indexItems.size() == 0) {
indexItems.clear();
indexItems.add(new IndexItem(getString(R.string.everything_up_to_date), "", 0, "", 0, 0, null));
}
listAdapter = new UpdateIndexAdapter(getDownloadActivity(), R.layout.download_index_list_item, indexItems);
@ -60,17 +98,27 @@ public class UpdatesIndexFragment extends ListFragment {
setListAdapter(listAdapter);
}
private void updateHeader(){
View view = getView();
if (getView() == null) {
return;
}
String header = getActivity().getString(R.string.download_tab_updates) + " - " + indexItems.size();
((TextView) view.findViewById(R.id.updates)).
setText(header);
}
@Override
public void onResume() {
super.onResume();
}
public void updateItemsList(List<IndexItem> items) {
if(listAdapter == null){
if (listAdapter == null) {
return;
}
createListView(new ArrayList<IndexItem>(items));
indexItems = new ArrayList<IndexItem>(items);
createListView();
}
@Override
@ -79,7 +127,7 @@ public class UpdatesIndexFragment extends ListFragment {
onItemSelected(ch, position);
}
private void onItemSelected(CheckBox ch, int position){
private void onItemSelected(CheckBox ch, int position) {
final IndexItem e = (IndexItem) getListAdapter().getItem(position);
if (ch.isChecked()) {
ch.setChecked(!ch.isChecked());
@ -102,6 +150,7 @@ public class UpdatesIndexFragment extends ListFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
updateHeader();
ActionBar actionBar = getDownloadActivity().getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
@ -170,11 +219,11 @@ public class UpdatesIndexFragment extends ListFragment {
}
private void filterExisting() {
final Map<String, String> listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames();
final Map<String, String> listAlreadyDownloaded = DownloadActivity.downloadListIndexThread.getDownloadedIndexFileNames();
final List<IndexItem> filtered = new ArrayList<IndexItem>();
for (IndexItem fileItem : listAdapter.getIndexFiles()) {
if(fileItem.isAlreadyDownloaded(listAlreadyDownloaded)){
if (fileItem.isAlreadyDownloaded(listAlreadyDownloaded)) {
filtered.add(fileItem);
}
}
@ -207,18 +256,19 @@ public class UpdatesIndexFragment extends ListFragment {
TextView description = (TextView) v.findViewById(R.id.download_descr);
final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);
IndexItem e = items.get(position);
if (e.getFileName() == getString(R.string.everything_up_to_date)){
if (e.getFileName().equals(getString(R.string.everything_up_to_date))) {
name.setText(e.getFileName());
description.setText("");
ch.setVisibility(View.INVISIBLE);
setSelectAllVisibility(false);
return v;
} else {
ch.setVisibility(View.VISIBLE);
}
String eName = e.getVisibleName(getMyApplication(), osmandRegions);
name.setText(eName.trim()); //$NON-NLS-1$
String d = e.getDate(format) + "\n" + e.getSizeDescription(getMyApplication());
name.setText(eName.trim().replace('\n', ' ')); //$NON-NLS-1$
String d = e.getDate(format) + " " + e.getSizeDescription(getMyApplication());
description.setText(d);
ch.setChecked(getDownloadActivity().getEntriesToDownload().containsKey(e));
@ -230,42 +280,12 @@ public class UpdatesIndexFragment extends ListFragment {
}
});
if (e.getDate(format) != null) {
Map<String, String> indexActivatedFileNames = getDownloadActivity().getIndexActivatedFileNames();
Map<String, String> indexFileNames = getDownloadActivity().getIndexFileNames();
if (indexActivatedFileNames != null && indexFileNames != null){
String sfName = e.getTargetFileName();
final boolean updatableResource = indexActivatedFileNames.containsKey(sfName);
if (updatableResource && !DownloadActivity.downloadListIndexThread.checkIfItemOutdated(e)) {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
name.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else if (e.getDate(format).equals(indexFileNames.get(sfName))) {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
name.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
} else if (updatableResource) {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexActivatedFileNames.get(sfName));
name.setTextColor(updateColor); // LIGHT_BLUE
name.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} else {
name.setText(name.getText() + "\n" + getResources().getString(R.string.local_index_installed) + " : "
+ indexFileNames.get(sfName));
name.setTextColor(updateColor); // LIGHT_BLUE
name.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
}
}
}
return v;
}
public void setIndexFiles(List<IndexItem> filtered) {
clear();
for (IndexItem item : filtered){
for (IndexItem item : filtered) {
add(item);
}
sort(new Comparator<IndexItem>() {