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
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView

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,45 +3,42 @@
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:descendantFocusability="blocksDescendants"
android:paddingTop="4dp">
<LinearLayout
<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
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"
@ -49,19 +46,31 @@
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_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>

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

@ -3,17 +3,14 @@
*/
package net.osmand.plus.activities;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
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;

View file

@ -1,8 +1,6 @@
package net.osmand.plus.activities;
import android.app.Dialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode;
@ -12,8 +10,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;
@ -28,21 +24,17 @@ 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;

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

@ -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;
@ -172,25 +176,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){
@ -205,6 +191,28 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
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 +930,12 @@ 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);
}
});
viewName.setText(getNameToDisplay(child));
if (child.isNotSupported()) {
viewName.setTextColor(warningColor);
@ -980,6 +994,47 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
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) {
String mapDescr = getMapDescription(child.getFileName());
String mapName = FileNameTranslationHelper.getFileName(ctx,

View file

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