Styled local indexes

This commit is contained in:
Denis 2015-02-16 12:32:15 +02:00
parent 96c02d2ae9
commit cdd9e45e7f
10 changed files with 122 additions and 73 deletions

View file

@ -21,7 +21,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView

View file

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

View file

@ -3,45 +3,42 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height" android:minHeight="@dimen/list_item_height"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:paddingLeft="@dimen/list_content_padding" android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding" android:paddingRight="@dimen/list_content_padding"
android:background="?attr/expandable_list_item_background" android:descendantFocusability="blocksDescendants"
android:paddingTop="4dp"> android:paddingTop="4dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<CheckBox <CheckBox
android:id="@+id/check_local_index" android:id="@+id/check_local_index"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:focusable="false" android:focusable="false"
android:gravity="center_vertical"/> android:gravity="center_vertical"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView <TextView
android:id="@+id/local_index_name" android:id="@+id/local_index_name"
style="@style/ListText.Small" style="@style/ListText.Small"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" tools:text="@string/app_version"/>
tools:text="@string/lorem_ipsum"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView <TextView
android:id="@+id/local_index_size" android:id="@+id/local_index_size"
@ -49,8 +46,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="3dp" android:layout_marginLeft="3dp"
android:gravity="right"/> android:gravity="right"
</LinearLayout> tools:text="@string/app_version"/>
<TextView <TextView
android:id="@+id/local_index_descr" android:id="@+id/local_index_descr"
@ -58,10 +55,22 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_marginLeft="7dp"
android:maxLines="25" android:maxLines="25"
tools:text="@string/lorem_ipsum"/> tools:text="@string/app_mode_aircraft"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
<ImageButton
android:id="@+id/options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?attr/dashboardGeneralButtonStyle"
android:layout_marginTop="@dimen/list_header_settings_top_margin"
android:layout_marginRight="0dp"
android:layout_gravity="top"
android:focusable="false"
android:src="?attr/list_settings_icon"/>
</LinearLayout> </LinearLayout>

View file

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

View file

@ -3,17 +3,14 @@
*/ */
package net.osmand.plus.activities; package net.osmand.plus.activities;
import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.view.*; import android.view.*;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;

View file

@ -1,8 +1,6 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import android.app.Dialog;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
@ -12,8 +10,6 @@ import android.view.*;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
import java.io.File; import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -28,21 +24,17 @@ import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter; 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;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.helpers.ScreenOrientationHelper; import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -56,7 +48,6 @@ import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.CheckBox; import android.widget.CheckBox;

View file

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

View file

@ -157,7 +157,7 @@ public class DirectionsDialogs {
} }
} }
private static void setupPopUpMenuIcon(PopupMenu menu){ public static void setupPopUpMenuIcon(PopupMenu menu){
try { try {
Field[] fields = menu.getClass().getDeclaredFields(); Field[] fields = menu.getClass().getDeclaredFields();
for (Field field : fields) { 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.LocalIndexInfo;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment; import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import android.app.Activity; import android.app.Activity;
@ -34,13 +35,16 @@ import android.app.AlertDialog.Builder;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.StatFs; import android.os.StatFs;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -172,12 +176,28 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
OnContextMenuClick listener = new OnContextMenuClick() { OnContextMenuClick listener = new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
return performBasicOperation(resId, info);
}
};
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA){
if(!info.isBackupedData()){
adapter.item(R.string.local_index_mi_backup).listen(listener).position( 1).reg();
}
}
if(info.isBackupedData()){
adapter.item(R.string.local_index_mi_restore).listen(listener).position(2).reg();
}
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) { if (resId == R.string.local_index_mi_rename) {
renameFile(info); renameFile(info);
} else if (resId == R.string.local_index_mi_restore) { } else if (resId == R.string.local_index_mi_restore) {
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info); new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
} else if (resId == R.string.local_index_mi_delete) { } else if (resId == R.string.local_index_mi_delete) {
Builder confirm = new AlertDialog.Builder(getActivity()); Builder confirm = new Builder(getActivity());
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -192,18 +212,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
} }
return true; return true;
} }
};
if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA){
if(!info.isBackupedData()){
adapter.item(R.string.local_index_mi_backup).listen(listener).position( 1).reg();
}
}
if(info.isBackupedData()){
adapter.item(R.string.local_index_mi_restore).listen(listener).position(2).reg();
}
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 void renameFile(LocalIndexInfo info) { private void renameFile(LocalIndexInfo info) {
final File f = new File(info.getPathToData()); final File f = new File(info.getPathToData());
@ -922,6 +930,12 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false); v = inflater.inflate(net.osmand.plus.R.layout.local_index_list_item, parent, false);
} }
TextView viewName = ((TextView) v.findViewById(R.id.local_index_name)); 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);
}
});
viewName.setText(getNameToDisplay(child)); viewName.setText(getNameToDisplay(child));
if (child.isNotSupported()) { if (child.isNotSupported()) {
viewName.setTextColor(warningColor); viewName.setTextColor(warningColor);
@ -980,6 +994,47 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
return v; 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();
Drawable backup = getActivity().getResources().getDrawable(R.drawable.ic_type_archive);
backup.mutate();
if (light) {
backup.setColorFilter(0xff727272, PorterDuff.Mode.MULTIPLY);
}
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) { private String getNameToDisplay(LocalIndexInfo child) {
String mapDescr = getMapDescription(child.getFileName()); String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx, String mapName = FileNameTranslationHelper.getFileName(ctx,

View file

@ -1,7 +1,6 @@
package net.osmand.plus.render; package net.osmand.plus.render;
import net.osmand.core.android.MapRendererView; import net.osmand.core.android.MapRendererView;
import net.osmand.core.android.TileSourceProxyProvider;
import net.osmand.core.jni.MapLayerConfiguration; import net.osmand.core.jni.MapLayerConfiguration;
import net.osmand.core.jni.PointI; import net.osmand.core.jni.PointI;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;