Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-03-26 18:56:27 +02:00
commit cdc4980c49
12 changed files with 309 additions and 98 deletions

View file

@ -13,6 +13,7 @@
android:src="@drawable/bg_shadow_list_bottom"/>
<View
android:id="@+id/bottomMarginView"
android:layout_width="match_parent"
android:layout_height="16dp"/>

View file

@ -17,16 +17,23 @@
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<net.osmand.plus.activities.search.toolbar.SplitToolbar
android:id="@+id/bottomControls"
android:background="?attr/bottomToolBarColor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<net.osmand.plus.activities.search.toolbar.SplitToolbar
android:id="@+id/bottomControls"
android:background="?attr/bottomToolBarColor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</FrameLayout>
</LinearLayout>

View file

@ -93,7 +93,7 @@
<color name="actionbar_dark_color">#39464d</color>
<color name="tool_bar_color_dark">#CC080B0D</color>
<color name="actionbar_light_color">#ff8f00</color>
<color name="tool_bar_color_light">#b4ff8f00</color>
<color name="tool_bar_color_light">#CC080B0D</color>
<color name="download_pressed_light">#8cff8f00</color>
<color name="download_pressed_dark">#be39464d</color>

View file

@ -3,9 +3,13 @@ package net.osmand.plus.activities;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.myplaces.FavoritesActivity;
public class ActionBarProgressActivity extends OsmandActionBarActivity {
@ -46,4 +50,24 @@ public class ActionBarProgressActivity extends OsmandActionBarActivity {
toolbar.setVisibility(visible ? View.VISIBLE : View.GONE);
}
}
public boolean isToolbarVisible() {
View toolbar = findViewById(R.id.bottomControls);
return toolbar != null && toolbar.getVisibility() == View.VISIBLE;
}
public void updateListViewFooter(View footerView) {
if (footerView != null) {
View bottomMarginView = footerView.findViewById(R.id.bottomMarginView);
if (bottomMarginView != null) {
if (isToolbarVisible()) {
bottomMarginView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(this, 72f)));
} else {
bottomMarginView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(this, 16f)));
}
}
}
}
}

View file

@ -89,6 +89,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
private SearchView searchView;
Drawable arrowImage;
private HashMap<String, OsmandSettings.OsmandPreference<Boolean>> preferenceCache = new HashMap<>();
private View footerView;
@Override
public void onAttach(Context context) {
@ -141,7 +142,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
favouritesAdapter.synchronizeGroups();
if (!favouritesAdapter.isEmpty()) {
listView.addHeaderView(inflater.inflate(R.layout.list_shadow_header, null, false));
listView.addFooterView(inflater.inflate(R.layout.list_shadow_footer, null, false));
footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
listView.addFooterView(footerView);
}
listView.setAdapter(favouritesAdapter);
setListView(listView);
@ -275,6 +277,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
} else {
((FavoritesActivity) getActivity()).getClearToolbar(false);
}
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
if (!MenuItemCompat.isActionViewExpanded(mi)) {
@ -427,6 +430,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
this.selectionMode = selectionMode;
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode &&
AndroidUiHelper.isOrientationPortrait(getActivity()));
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
}
protected void openChangeGroupDialog(final FavoriteGroup group) {

View file

@ -23,6 +23,7 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@ -59,7 +60,8 @@ public class NotesFragment extends OsmAndListFragment {
AudioVideoNotesPlugin plugin;
List<AudioVideoNotesPlugin.Recording> items;
NotesAdapter listAdapter;
private View footerView;
private boolean selectionMode = false;
private final static int MODE_DELETE = 100;
@ -118,8 +120,16 @@ public class NotesFragment extends OsmAndListFragment {
public void onResume() {
super.onResume();
items = new ArrayList<>(plugin.getAllRecordings());
ListView listView = getListView();
if (items.size() > 0) {
//listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_header, null, false));
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false);
listView.addFooterView(footerView);
listView.setHeaderDividersEnabled(false);
listView.setFooterDividersEnabled(false);
}
listAdapter = new NotesAdapter(items);
getListView().setAdapter(listAdapter);
listView.setAdapter(listAdapter);
}
@Override
@ -130,6 +140,8 @@ public class NotesFragment extends OsmAndListFragment {
} else {
((ActionBarProgressActivity) getActivity()).getClearToolbar(false);
}
((ActionBarProgressActivity) getActivity()).updateListViewFooter(footerView);
MenuItem item = menu.add(R.string.shared_string_share).
setIcon(R.drawable.ic_action_export);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@ -172,6 +184,7 @@ public class NotesFragment extends OsmAndListFragment {
view.findViewById(R.id.select_all).setVisibility(selectionMode ? View.VISIBLE : View.GONE);
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode &&
AndroidUiHelper.isOrientationPortrait(getActivity()));
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.helpers;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
@ -42,16 +43,25 @@ public class GpxImportHelper {
public static final String KML_SUFFIX = ".kml";
public static final String GPX_SUFFIX = ".gpx";
private final MapActivity mapActivity;
private final OsmandApplication application;
private final Activity activity;
private final OsmandApplication app;
private final OsmandMapTileView mapView;
private OnGpxImportCompleteListener gpxImportCompleteListener;
public GpxImportHelper(final MapActivity mapActivity, final OsmandApplication application, final OsmandMapTileView mapView) {
this.mapActivity = mapActivity;
this.application = application;
public interface OnGpxImportCompleteListener {
void onComplete(boolean success);
}
public GpxImportHelper(final Activity activity, final OsmandApplication app, final OsmandMapTileView mapView) {
this.activity = activity;
this.app = app;
this.mapView = mapView;
}
public void setGpxImportCompleteListener(OnGpxImportCompleteListener gpxImportCompleteListener) {
this.gpxImportCompleteListener = gpxImportCompleteListener;
}
public void handleContentImport(final Uri contentUri, final boolean useImportDir) {
final String name = getNameFromContentUri(contentUri);
handleFileImport(contentUri, name, useImportDir);
@ -59,7 +69,7 @@ public class GpxImportHelper {
public boolean handleGpxImport(final Uri contentUri, final boolean useImportDir) {
final String name = getNameFromContentUri(contentUri);
final boolean isOsmandSubdir = isSubDirectory(application.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath()));
final boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath()));
if (!isOsmandSubdir && name.endsWith(GPX_SUFFIX)) {
handleGpxImport(contentUri, name, true, useImportDir);
return true;
@ -69,7 +79,7 @@ public class GpxImportHelper {
public void handleFileImport(final Uri intentUri, final String fileName, final boolean useImportDir) {
final boolean isFileIntent = "file".equals(intentUri.getScheme());
final boolean isOsmandSubdir = isSubDirectory(application.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
final boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
final boolean saveFile = !isFileIntent || !isOsmandSubdir;
@ -87,7 +97,7 @@ public class GpxImportHelper {
private String getNameFromContentUri(Uri contentUri) {
final String name;
final Cursor returnCursor = application.getContentResolver().query(contentUri, null, null, null, null);
final Cursor returnCursor = app.getContentResolver().query(contentUri, null, null, null, null);
if (returnCursor != null && returnCursor.moveToFirst()) {
name = returnCursor.getString(returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
} else {
@ -105,18 +115,18 @@ public class GpxImportHelper {
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(mapActivity, application.getString(R.string.loading_smth, ""), application.getString(R.string.loading_data));
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
@Override
protected GPXUtilities.GPXFile doInBackground(Void... nothing) {
InputStream is = null;
try {
final ParcelFileDescriptor pFD = application.getContentResolver().openFileDescriptor(gpxFile, "r");
final ParcelFileDescriptor pFD = app.getContentResolver().openFileDescriptor(gpxFile, "r");
if (pFD != null) {
is = new FileInputStream(pFD.getFileDescriptor());
return GPXUtilities.loadGPXFile(application, is);
return GPXUtilities.loadGPXFile(app, is);
}
} catch (FileNotFoundException e) {
//
@ -143,18 +153,18 @@ public class GpxImportHelper {
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(mapActivity, application.getString(R.string.loading_smth, ""), application.getString(R.string.loading_data));
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
@Override
protected GPXUtilities.GPXFile doInBackground(Void... nothing) {
InputStream is = null;
try {
final ParcelFileDescriptor pFD = application.getContentResolver().openFileDescriptor(gpxFile, "r");
final ParcelFileDescriptor pFD = app.getContentResolver().openFileDescriptor(gpxFile, "r");
if (pFD != null) {
is = new FileInputStream(pFD.getFileDescriptor());
return GPXUtilities.loadGPXFile(application, is);
return GPXUtilities.loadGPXFile(app, is);
}
} catch (FileNotFoundException e) {
//
@ -181,13 +191,13 @@ public class GpxImportHelper {
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(mapActivity, application.getString(R.string.loading_smth, ""), application.getString(R.string.loading_data));
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
@Override
protected GPXUtilities.GPXFile doInBackground(Void... nothing) {
final List<FavouritePoint> favourites = asFavourites(gpxFile.points);
final FavouritesDbHelper favoritesHelper = application.getFavorites();
final FavouritesDbHelper favoritesHelper = app.getFavorites();
for (final FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false);
favoritesHelper.addFavourite(favourite, false);
@ -200,9 +210,9 @@ public class GpxImportHelper {
@Override
protected void onPostExecute(GPXUtilities.GPXFile result) {
progress.dismiss();
Toast.makeText(mapActivity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
final Intent newIntent = new Intent(mapActivity, application.getAppCustomization().getFavoritesActivity());
mapActivity.startActivity(newIntent);
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
activity.startActivity(newIntent);
}
}.execute();
}
@ -213,20 +223,20 @@ public class GpxImportHelper {
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(mapActivity, application.getString(R.string.loading_smth, ""), application.getString(R.string.loading_data));
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
@Override
protected GPXUtilities.GPXFile doInBackground(Void... nothing) {
InputStream is = null;
try {
final ParcelFileDescriptor pFD = application.getContentResolver().openFileDescriptor(kmlFile, "r");
final ParcelFileDescriptor pFD = app.getContentResolver().openFileDescriptor(kmlFile, "r");
if (pFD != null) {
is = new FileInputStream(pFD.getFileDescriptor());
final String result = Kml2Gpx.toGpx(is);
if (result != null) {
try {
return GPXUtilities.loadGPXFile(application, new ByteArrayInputStream(result.getBytes("UTF-8")));
return GPXUtilities.loadGPXFile(app, new ByteArrayInputStream(result.getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
return null;
}
@ -254,16 +264,25 @@ public class GpxImportHelper {
private void handleResult(final GPXUtilities.GPXFile result, final String name, final boolean save, final boolean useImportDir) {
if (result != null) {
if (result.warning != null) {
Toast.makeText(mapActivity, result.warning, Toast.LENGTH_LONG).show();
Toast.makeText(activity, result.warning, Toast.LENGTH_LONG).show();
if (gpxImportCompleteListener != null) {
gpxImportCompleteListener.onComplete(false);
}
} else {
if (save) {
new SaveAsyncTask(result, name, useImportDir).execute();
} else {
showGpxOnMap(result);
}
if (gpxImportCompleteListener != null) {
gpxImportCompleteListener.onComplete(true);
}
}
} else {
Toast.makeText(mapActivity, R.string.error_reading_gpx, Toast.LENGTH_LONG).show();
Toast.makeText(activity, R.string.error_reading_gpx, Toast.LENGTH_LONG).show();
if (gpxImportCompleteListener != null) {
gpxImportCompleteListener.onComplete(false);
}
}
}
@ -271,25 +290,25 @@ public class GpxImportHelper {
final String warning;
if (gpxFile.isEmpty() || fileName == null) {
warning = application.getString(R.string.error_reading_gpx);
warning = app.getString(R.string.error_reading_gpx);
} else {
final File importDir;
if (useImportDir) {
importDir = application.getAppPath(IndexConstants.GPX_IMPORT_DIR);
importDir = app.getAppPath(IndexConstants.GPX_IMPORT_DIR);
} else {
importDir = application.getAppPath(IndexConstants.GPX_INDEX_DIR);
importDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
}
//noinspection ResultOfMethodCallIgnored
importDir.mkdirs();
if (importDir.exists() && importDir.isDirectory() && importDir.canWrite()) {
final GPXUtilities.WptPt pt = gpxFile.findPointToShow();
final File toWrite = getFileToSave(fileName, importDir, pt);
warning = GPXUtilities.writeGpxFile(toWrite, gpxFile, application);
warning = GPXUtilities.writeGpxFile(toWrite, gpxFile, app);
if (warning == null) {
gpxFile.path = toWrite.getAbsolutePath();
}
} else {
warning = application.getString(R.string.sd_dir_not_accessible);
warning = app.getString(R.string.sd_dir_not_accessible);
}
}
@ -327,23 +346,33 @@ public class GpxImportHelper {
@Override
protected void onPostExecute(final String warning) {
final String msg = warning == null ? MessageFormat.format(application.getString(R.string.gpx_saved_sucessfully), result.path) : warning;
Toast.makeText(mapActivity, msg, Toast.LENGTH_LONG).show();
final String msg = warning == null ? MessageFormat.format(app.getString(R.string.gpx_saved_sucessfully), result.path) : warning;
Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
showGpxOnMap(result);
}
}
private void showGpxOnMap(final GPXUtilities.GPXFile result) {
application.getSelectedGpxHelper().setGpxFileToDisplay(result);
final GPXUtilities.WptPt moveTo = result.findPointToShow();
if (moveTo != null) {
mapView.getAnimatedDraggingThread().startMoving(moveTo.lat, moveTo.lon, mapView.getZoom(), true);
private MapActivity getMapActivity() {
if (activity instanceof MapActivity) {
return (MapActivity) activity;
} else {
return null;
}
mapView.refreshMap();
if (mapActivity.getDashboard().isVisible()) {
mapActivity.getDashboard().refreshContent(true);
}
private void showGpxOnMap(final GPXUtilities.GPXFile result) {
if (mapView != null && getMapActivity() != null) {
app.getSelectedGpxHelper().setGpxFileToDisplay(result);
final GPXUtilities.WptPt moveTo = result.findPointToShow();
if (moveTo != null) {
mapView.getAnimatedDraggingThread().startMoving(moveTo.lat, moveTo.lon, mapView.getZoom(), true);
}
mapView.refreshMap();
if (getMapActivity().getDashboard().isVisible()) {
getMapActivity().getDashboard().refreshContent(true);
}
}
}
@ -366,7 +395,7 @@ public class GpxImportHelper {
}
};
new AlertDialog.Builder(mapActivity)
new AlertDialog.Builder(activity)
.setTitle(R.string.shared_string_import2osmand)
.setMessage(R.string.import_file_favourites)
.setPositiveButton(R.string.shared_string_import, importFavouritesListener)

View file

@ -8,6 +8,7 @@ import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
@ -110,6 +111,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private GpxInfo currentRecording;
private boolean showOnMapMode;
private View currentGpxView;
private View footerView;
private boolean importing = false;
@Override
public void onAttach(Context activity) {
@ -125,6 +128,21 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
setAdapter(allGpxAdapter);
}
public boolean isImporting() {
return importing;
}
public void startImport() {
this.importing = true;
}
public void finishImport(boolean success) {
if (success) {
reloadTracks();
}
this.importing = false;
}
private void startHandler() {
Handler updateCurrentRecordingTrack = new Handler();
updateCurrentRecordingTrack.postDelayed(new Runnable() {
@ -148,15 +166,18 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
public void onResume() {
super.onResume();
if (asyncLoader == null || asyncLoader.getResult() == null) {
asyncLoader = new LoadGpxTask();
asyncLoader.execute(getActivity());
} else {
allGpxAdapter.refreshSelected();
allGpxAdapter.notifyDataSetChanged();
if (!importing) {
if (asyncLoader == null || asyncLoader.getResult() == null) {
asyncLoader = new LoadGpxTask();
asyncLoader.execute(getActivity());
} else {
allGpxAdapter.refreshSelected();
allGpxAdapter.notifyDataSetChanged();
}
asyncProcessor = new ProcessGpxTask();
asyncProcessor.execute();
}
asyncProcessor = new ProcessGpxTask();
asyncProcessor.execute();
updateCurrentTrack();
updateEnable = true;
@ -293,7 +314,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
View headerView = inflater.inflate(R.layout.list_shadow_header, null, false);
listView.addHeaderView(headerView);
}
View footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
listView.addFooterView(footerView);
if (this.adapter != null) {
listView.setAdapter(this.adapter);
@ -330,6 +351,15 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
a.startActivity(newIntent);
}
public void reloadTracks() {
asyncLoader = new LoadGpxTask();
asyncLoader.execute(getActivity());
if (asyncProcessor == null) {
asyncProcessor = new ProcessGpxTask();
asyncProcessor.execute();
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
@ -376,6 +406,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} else {
((FavoritesActivity) getActivity()).getClearToolbar(false);
}
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
// TODO Rewrite without ContextMenuAdapter
optionsMenuAdapter = new ContextMenuAdapter();
@ -383,12 +414,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, final int itemId, int pos, boolean isChecked) {
if (itemId == R.string.local_index_mi_reload) {
asyncLoader = new LoadGpxTask();
asyncLoader.execute(getActivity());
if (asyncProcessor == null) {
asyncProcessor = new ProcessGpxTask();
asyncProcessor.execute();
}
reloadTracks();
} else if (itemId == R.string.shared_string_show_on_map) {
openShowOnMapMode();
} else if (itemId == R.string.shared_string_delete) {
@ -400,10 +426,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
doAction(itemId);
}
});
} else if (itemId == R.string.gpx_add_track) {
addTrack();
}
return true;
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.gpx_add_track, getActivity())
.setIcon(R.drawable.ic_action_plus)
.setListener(listener).createItem());
}
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity())
.setIcon(R.drawable.ic_show_on_map)
.setListener(listener).createItem());
@ -429,7 +462,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (contextMenuItem.getIcon() != -1) {
item.setIcon(contextMenuItem.getIcon());
}
}
}
@ -458,6 +490,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
return super.onOptionsItemSelected(item);
}
private void addTrack() {
((FavoritesActivity) getActivity()).addTrack();
}
public void showProgressBar() {
((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true);
}
@ -481,6 +517,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode &&
AndroidUiHelper.isOrientationPortrait(getActivity()));
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
}
}

View file

@ -3,8 +3,12 @@
*/
package net.osmand.plus.myplaces;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
@ -23,6 +27,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.FavoritesTreeFragment;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.helpers.GpxImportHelper;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import java.io.File;
@ -35,10 +40,13 @@ import java.util.List;
*/
public class FavoritesActivity extends TabActivity {
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006;
public static final int GPX_TAB = R.string.shared_string_my_tracks;
public static final int FAV_TAB = R.string.shared_string_my_favorites;
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
private int tabSize;
private GpxImportHelper gpxImportHelper;
@Override
public void onCreate(Bundle icicle) {
@ -48,6 +56,8 @@ public class FavoritesActivity extends TabActivity {
app.logEvent(this, "myplaces_open");
gpxImportHelper = new GpxImportHelper(this, getMyApplication(), null);
//noinspection ConstantConditions
getSupportActionBar().setTitle(R.string.shared_string_my_places);
getSupportActionBar().setElevation(0);
@ -59,6 +69,54 @@ public class FavoritesActivity extends TabActivity {
// setupHomeButton();
}
@TargetApi(Build.VERSION_CODES.KITKAT)
public void addTrack() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OPEN_GPX_DOCUMENT_REQUEST && resultCode == Activity.RESULT_OK) {
if (data != null) {
Uri uri = data.getData();
AvailableGPXFragment gpxFragment = getGpxFragment();
if (gpxFragment!= null) {
gpxFragment.startImport();
}
gpxImportHelper.setGpxImportCompleteListener(new GpxImportHelper.OnGpxImportCompleteListener() {
@Override
public void onComplete(boolean success) {
AvailableGPXFragment gpxFragment = getGpxFragment();
if (gpxFragment!= null) {
gpxFragment.finishImport(success);
}
gpxImportHelper.setGpxImportCompleteListener(null);
}
});
if (!gpxImportHelper.handleGpxImport(uri, false)) {
if (gpxFragment!= null) {
gpxFragment.finishImport(false);
}
}
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
private AvailableGPXFragment getGpxFragment() {
AvailableGPXFragment gpxFragment = null;
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
if (frag instanceof AvailableGPXFragment) {
gpxFragment = (AvailableGPXFragment) frag;
}
}
return gpxFragment;
}
private void setTabs(List<TabItem> mTabs) {
PagerSlidingTabStrip mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tabs);
OsmandSettings settings = ((OsmandApplication) getApplication()).getSettings();

View file

@ -25,6 +25,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@ -60,6 +61,7 @@ public class OsmEditsFragment extends OsmAndListFragment
OsmEditingPlugin plugin;
private OsmEditsAdapter listAdapter;
private View footerView;
private boolean selectionMode = false;
@ -124,6 +126,8 @@ public class OsmEditsFragment extends OsmAndListFragment
} else {
((ActionBarProgressActivity) getActivity()).getClearToolbar(false);
}
((ActionBarProgressActivity) getActivity()).updateListViewFooter(footerView);
MenuItem item = menu.add(R.string.local_openstreetmap_uploadall).
setIcon(R.drawable.ic_action_export);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@ -288,6 +292,7 @@ public class OsmEditsFragment extends OsmAndListFragment
getView().findViewById(R.id.select_all).setVisibility(selectionMode ? View.VISIBLE : View.GONE);
((FavoritesActivity) getActivity()).setToolbarVisibility(!selectionMode &&
AndroidUiHelper.isOrientationPortrait(getActivity()));
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
}
public OsmandActionBarActivity getActionBarActivity() {
@ -312,8 +317,16 @@ public class OsmEditsFragment extends OsmAndListFragment
dataPoints.addAll(l2);
if (listAdapter == null) {
listAdapter = new OsmEditsAdapter(dataPoints);
getListView().setAdapter(listAdapter);
getListView().setOnItemClickListener(new OnItemClickListener() {
ListView listView = getListView();
if (dataPoints.size() > 0) {
//listView.addHeaderView(getActivity().getLayoutInflater().inflate(R.layout.list_shadow_header, null, false));
footerView = getActivity().getLayoutInflater().inflate(R.layout.list_shadow_footer, null, false);
listView.addFooterView(footerView);
listView.setHeaderDividersEnabled(false);
listView.setFooterDividersEnabled(false);
}
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

View file

@ -55,7 +55,10 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
private static final String QUICK_SEARCH_COORDS_OLC_INFO_KEY = "quick_search_coords_olc_info_key";
private static final String QUICK_SEARCH_COORDS_FORMAT_KEY = "quick_search_coords_format_key";
private static final String QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY = "quick_search_coords_use_map_center_key";
private static final String QUICK_SEARCH_COORDS_TEXT_KEY = "quick_search_coords_text_key";
private static final String QUICK_SEARCH_COORDS_LATITUDE_KEY = "quick_search_coords_latitude_key";
private static final String QUICK_SEARCH_COORDS_LONGITUDE_KEY = "quick_search_coords_longitude_key";
private View view;
private View coordsView;
@ -117,9 +120,19 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
myLocation = app.getLocationProvider().getLastKnownLocation();
currentFormat = app.getSettings().COORDINATES_FORMAT.get();
latEdit = ((EditText) view.findViewById(R.id.latitudeEditText));
lonEdit = ((EditText) view.findViewById(R.id.longitudeEditText));
northingEdit = ((EditText) view.findViewById(R.id.northingEditText));
eastingEdit = ((EditText) view.findViewById(R.id.eastingEditText));
zoneEdit = ((EditText) view.findViewById(R.id.zoneEditText));
olcEdit = ((EditText) view.findViewById(R.id.olcEditText));
olcInfo = ((TextView) view.findViewById(R.id.olcInfoTextView));
formatEdit = ((EditText) view.findViewById(R.id.formatEditText));
String defaultLat = "";
String defaultZone = "";
String defaultOlc = "";
boolean coordinatesApplied = false;
if (getArguments() != null) {
String text = getArguments().getString(QUICK_SEARCH_COORDS_TEXT_KEY);
if (!Algorithms.isEmpty(text)) {
@ -130,6 +143,14 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
} else {
defaultLat = text.trim();
}
} else {
double latitude = getArguments().getDouble(QUICK_SEARCH_COORDS_LATITUDE_KEY, Double.NaN);
double longitude = getArguments().getDouble(QUICK_SEARCH_COORDS_LONGITUDE_KEY, Double.NaN);
if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
currentLatLon = new LatLon(latitude, longitude);
applyFormat(currentFormat, true);
coordinatesApplied = true;
}
}
}
@ -153,28 +174,21 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
else if (getArguments().containsKey(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY))
useMapCenter = getArguments().getBoolean(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY);
latEdit = ((EditText) view.findViewById(R.id.latitudeEditText));
lonEdit = ((EditText) view.findViewById(R.id.longitudeEditText));
northingEdit = ((EditText) view.findViewById(R.id.northingEditText));
eastingEdit = ((EditText) view.findViewById(R.id.eastingEditText));
zoneEdit = ((EditText) view.findViewById(R.id.zoneEditText));
olcEdit = ((EditText) view.findViewById(R.id.olcEditText));
olcInfo = ((TextView) view.findViewById(R.id.olcInfoTextView));
formatEdit = ((EditText) view.findViewById(R.id.formatEditText));
latEdit.setText(latStr);
latEdit.setSelection(latStr.length());
lonEdit.setText(lonStr);
lonEdit.setSelection(lonStr.length());
northingEdit.setText(northingStr);
northingEdit.setSelection(northingStr.length());
eastingEdit.setText(eastingStr);
eastingEdit.setSelection(eastingStr.length());
zoneEdit.setText(zoneStr);
zoneEdit.setSelection(zoneStr.length());
olcEdit.setText(olcStr);
olcEdit.setSelection(olcStr.length());
olcInfo.setText(olcInfoStr);
if (!coordinatesApplied) {
latEdit.setText(latStr);
latEdit.setSelection(latStr.length());
lonEdit.setText(lonStr);
lonEdit.setSelection(lonStr.length());
northingEdit.setText(northingStr);
northingEdit.setSelection(northingStr.length());
eastingEdit.setText(eastingStr);
eastingEdit.setSelection(eastingStr.length());
zoneEdit.setText(zoneStr);
zoneEdit.setSelection(zoneStr.length());
olcEdit.setText(olcStr);
olcEdit.setSelection(olcStr.length());
olcInfo.setText(olcInfoStr);
}
formatEdit.setText(PointDescription.formatToHumanString(app, currentFormat));
formatEdit.setOnClickListener(new View.OnClickListener() {
@ -489,8 +503,8 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
}
}
private boolean applyFormat(int format) {
if (currentFormat != format) {
private boolean applyFormat(int format, boolean forceApply) {
if (currentFormat != format || forceApply) {
int prevFormat = currentFormat;
currentFormat = format;
formatEdit.setText(PointDescription.formatToHumanString(getMyApplication(), currentFormat));
@ -639,6 +653,15 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
fragment.show(parentFragment.getChildFragmentManager(), TAG);
}
public static void showDialog(DialogFragment parentFragment, double latitude, double longitude) {
Bundle bundle = new Bundle();
bundle.putDouble(QUICK_SEARCH_COORDS_LATITUDE_KEY, latitude);
bundle.putDouble(QUICK_SEARCH_COORDS_LONGITUDE_KEY, longitude);
QuickSearchCoordinatesFragment fragment = new QuickSearchCoordinatesFragment();
fragment.setArguments(bundle);
fragment.show(parentFragment.getChildFragmentManager(), TAG);
}
public static class ChooseCoordsFormatDialogFragment extends DialogFragment {
@NonNull
@Override
@ -656,7 +679,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os
.setSingleChoiceItems(entries, parent.currentFormat, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
parent.applyFormat(which);
parent.applyFormat(which, false);
dialog.dismiss();
}
});

View file

@ -1122,7 +1122,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
app.getString(R.string.coords_search), new OnClickListener() {
@Override
public void onClick(View v) {
QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this, "");
LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this,
latLon.getLatitude(), latLon.getLongitude());
}
}));