Settings fragment added and DashboardOnMap refactoring. Review needed.
This commit is contained in:
parent
cce3a39b42
commit
e009aa5972
11 changed files with 489 additions and 230 deletions
22
OsmAnd/res/layout/dashboard_settings_dialog_item.xml
Normal file
22
OsmAnd/res/layout/dashboard_settings_dialog_item.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/list_header_height"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/text"
|
||||
style="@style/DashboardSubHeader"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="@string/lorem_ipsum"/>
|
||||
|
||||
<include
|
||||
layout="@layout/check_item_rel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -2226,4 +2226,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
|
|||
<string name="successfully_uploaded_pattern">Successfully uploaded {0}/{1}</string>
|
||||
<string name="try_again">Try again</string>
|
||||
<string name="error_message_pattern">Error: {0}</string>
|
||||
<string name="dahboard_options_dialog_title">Dashboard options</string>
|
||||
</resources>
|
||||
|
|
|
@ -174,7 +174,9 @@ public abstract class DashBaseFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onDismiss() {
|
||||
dashboardOnMap.hideFragmentByTag(fragmentTag);
|
||||
dashboardOnMap.blacklistFragmentByTag(fragmentTag);
|
||||
ViewCompat.setTranslationX(fragmentView, 0);
|
||||
ViewCompat.setAlpha(fragmentView, 1);
|
||||
Snackbar.make(parentView, "Card was hidden", Snackbar.LENGTH_LONG)
|
||||
.setAction("UNDO", new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -66,14 +66,6 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
|
|||
public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return fragment.initView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
public static boolean isDashNeeded(OsmandSettings settings) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
return false;
|
||||
}
|
||||
return !settings.isExternalStorageDirectorySpecifiedV19();
|
||||
}
|
||||
|
||||
|
||||
public static class ChooseAppDirFragment {
|
||||
public static final int VERSION_DEFAULTLOCATION_CHANGED = 19;
|
||||
|
@ -121,8 +113,6 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
|
|||
locationPath.setText(R.string.storage_directory_multiuser);
|
||||
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
|
||||
locationPath.setText(R.string.storage_directory_manual);
|
||||
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) {
|
||||
locationPath.setText(R.string.storage_directory_manual);
|
||||
}
|
||||
locationDesc.setText(selectedFile.getAbsolutePath() + " \u2022 " + getFreeSpace(selectedFile));
|
||||
boolean copyFiles = !currentAppFile.getAbsolutePath().equals(selectedFile.getAbsolutePath()) && !mapsCopied;
|
||||
|
|
|
@ -14,19 +14,14 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.ShowRouteInfoActivity;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class DashNavigationFragment extends DashBaseFragment {
|
||||
public static final String TAG = "DASH_NAVIGATION_FRAGMENT";
|
||||
List<TargetPoint> points = new ArrayList<TargetPoint>();
|
||||
|
||||
@Override
|
||||
public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
|
@ -50,60 +51,62 @@ public class DashRateUsFragment extends DashBaseFragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
public static boolean shouldShow(OsmandSettings settings) {
|
||||
if(!settings.LAST_DISPLAY_TIME.isSet()) {
|
||||
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||
}
|
||||
DashRateUsFragment.settings = settings;
|
||||
long lastDisplayTimeInMillis = settings.LAST_DISPLAY_TIME.get();
|
||||
int numberOfApplicationRuns = settings.NUMBER_OF_APPLICATION_STARTS.get();
|
||||
RateUsState state = settings.RATE_US_STATE.get();
|
||||
public static boolean shouldShow(OsmandSettings settings) {
|
||||
if(!settings.LAST_DISPLAY_TIME.isSet()) {
|
||||
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||
}
|
||||
DashRateUsFragment.settings = settings;
|
||||
long lastDisplayTimeInMillis = settings.LAST_DISPLAY_TIME.get();
|
||||
int numberOfApplicationRuns = settings.NUMBER_OF_APPLICATION_STARTS.get();
|
||||
RateUsState state = settings.RATE_US_STATE.get();
|
||||
|
||||
Calendar modifiedTime = Calendar.getInstance();
|
||||
Calendar lastDisplayTime = Calendar.getInstance();
|
||||
lastDisplayTime.setTimeInMillis(lastDisplayTimeInMillis);
|
||||
Calendar modifiedTime = Calendar.getInstance();
|
||||
Calendar lastDisplayTime = Calendar.getInstance();
|
||||
lastDisplayTime.setTimeInMillis(lastDisplayTimeInMillis);
|
||||
|
||||
int bannerFreeRuns = 0;
|
||||
int bannerFreeRuns = 0;
|
||||
|
||||
Log.v(TAG, "state=" + state + "; lastDisplayTimeInMillis=" + lastDisplayTimeInMillis
|
||||
+ "; numberOfApplicationRuns=" + numberOfApplicationRuns);
|
||||
Log.v(TAG, "state=" + state + "; lastDisplayTimeInMillis=" + lastDisplayTimeInMillis
|
||||
+ "; numberOfApplicationRuns=" + numberOfApplicationRuns);
|
||||
|
||||
switch (state) {
|
||||
case LIKED:
|
||||
return false;
|
||||
case INITIAL_STATE:
|
||||
break;
|
||||
case IGNORED:
|
||||
modifiedTime.add(Calendar.WEEK_OF_YEAR, -1);
|
||||
bannerFreeRuns = 5;
|
||||
break;
|
||||
case DISLIKED_WITH_MESSAGE:
|
||||
modifiedTime.add(Calendar.MONTH, -3);
|
||||
bannerFreeRuns = 3;
|
||||
break;
|
||||
case DISLIKED_WITHOUT_MESSAGE:
|
||||
modifiedTime.add(Calendar.MONTH, -2);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected state:" + state);
|
||||
}
|
||||
boolean toReturn = false;
|
||||
|
||||
if (state != RateUsState.INITIAL_STATE) {
|
||||
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
||||
settings.RATE_US_STATE.set(RateUsState.INITIAL_STATE);
|
||||
modifiedTime = Calendar.getInstance();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Initial state now
|
||||
modifiedTime.add(Calendar.HOUR, -72);
|
||||
bannerFreeRuns = 3;
|
||||
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
switch (state) {
|
||||
case LIKED:
|
||||
return false;
|
||||
case INITIAL_STATE:
|
||||
break;
|
||||
case IGNORED:
|
||||
modifiedTime.add(Calendar.WEEK_OF_YEAR, -1);
|
||||
bannerFreeRuns = 5;
|
||||
break;
|
||||
case DISLIKED_WITH_MESSAGE:
|
||||
modifiedTime.add(Calendar.MONTH, -3);
|
||||
bannerFreeRuns = 3;
|
||||
break;
|
||||
case DISLIKED_WITHOUT_MESSAGE:
|
||||
modifiedTime.add(Calendar.MONTH, -2);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected state:" + state);
|
||||
}
|
||||
|
||||
if (state != RateUsState.INITIAL_STATE) {
|
||||
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
||||
settings.RATE_US_STATE.set(RateUsState.INITIAL_STATE);
|
||||
modifiedTime = Calendar.getInstance();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Initial state now
|
||||
modifiedTime.add(Calendar.HOUR, -72);
|
||||
bannerFreeRuns = 3;
|
||||
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
||||
toReturn = true;
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public class PositiveButtonListener implements View.OnClickListener {
|
||||
private TextView header;
|
||||
|
@ -211,4 +214,12 @@ public class DashRateUsFragment extends DashBaseFragment {
|
|||
DISLIKED_WITH_MESSAGE,
|
||||
DISLIKED_WITHOUT_MESSAGE
|
||||
}
|
||||
|
||||
public static class RateUsShouldShow extends DashboardOnMap.SettingsShouldShow {
|
||||
@Override
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
return DashRateUsFragment.shouldShow(settings)
|
||||
&& super.shouldShow(settings, activity, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package net.osmand.plus.dashboard;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -12,6 +10,7 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
|
@ -42,10 +41,14 @@ import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
|
|||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.IntermediatePointsDialog;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
|
||||
import net.osmand.plus.dashboard.tools.DashFragmentData;
|
||||
import net.osmand.plus.dashboard.tools.DashboardSettingsDialogFragment;
|
||||
import net.osmand.plus.dashboard.tools.TransactionBuilder;
|
||||
import net.osmand.plus.development.DashSimulateFragment;
|
||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
|
@ -71,17 +74,45 @@ import java.util.List;
|
|||
*/
|
||||
public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||
|
||||
private static final String TAG = "DashboardOnMap";
|
||||
public static boolean staticVisible = false;
|
||||
public static DashboardType staticVisibleType = DashboardType.DASHBOARD;
|
||||
|
||||
public static final String SHOULD_SHOW = "should_show";
|
||||
|
||||
private static final DashFragmentData.ShouldShowFunction rateUsShouldShow = new DashRateUsFragment.RateUsShouldShow();
|
||||
private static final DefaultShouldShow defaultShouldShow = new DefaultShouldShow();
|
||||
private static final DefaultShouldShow errorShouldShow = new ErrorShouldShow();
|
||||
private static final DefaultShouldShow firstTimeShouldShow = new FirstTimeShouldShow();
|
||||
private static final DefaultShouldShow simulateShouldShow = new SimulateShouldShow();
|
||||
private static final DashFragmentData.ShouldShowFunction chooseAppDirShouldShow = new ChooseAppDirShouldShow();
|
||||
|
||||
private static final DashFragmentData[] fragmentsData = new DashFragmentData[]{
|
||||
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us", rateUsShouldShow),
|
||||
new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time", firstTimeShouldShow),
|
||||
new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir", chooseAppDirShouldShow),
|
||||
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error", errorShouldShow),
|
||||
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class, "Navigation", defaultShouldShow),
|
||||
new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking", defaultShouldShow),
|
||||
new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class, "Waypoints", defaultShouldShow),
|
||||
new DashFragmentData(DashSearchFragment.TAG, DashSearchFragment.class, "Search", defaultShouldShow),
|
||||
new DashFragmentData(DashRecentsFragment.TAG, DashRecentsFragment.class, "Recent places", defaultShouldShow),
|
||||
new DashFragmentData(DashFavoritesFragment.TAG, DashFavoritesFragment.class, "Favourites", defaultShouldShow),
|
||||
new DashFragmentData(DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, "Notes", defaultShouldShow),
|
||||
new DashFragmentData(DashTrackFragment.TAG, DashTrackFragment.class, "Track", defaultShouldShow),
|
||||
new DashFragmentData(DashOsMoFragment.TAG, DashOsMoFragment.class, "OsMo", defaultShouldShow),
|
||||
new DashFragmentData(DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, "OsmEdits", defaultShouldShow),
|
||||
new DashFragmentData(DashPluginsFragment.TAG, DashPluginsFragment.class, "Plugins", defaultShouldShow),
|
||||
new DashFragmentData(DashSimulateFragment.TAG, DashSimulateFragment.class, "Simulate", simulateShouldShow),
|
||||
};
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private ImageView actionButton;
|
||||
private FrameLayout dashboardView;
|
||||
|
||||
|
||||
private ArrayAdapter<?> listAdapter;
|
||||
private OnItemClickListener listAdapterOnClickListener;
|
||||
|
||||
|
||||
|
||||
private boolean visible = false;
|
||||
private DashboardType visibleType;
|
||||
private DashboardType previousVisibleType;
|
||||
|
@ -102,12 +133,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
private boolean portrait;
|
||||
|
||||
int baseColor;
|
||||
|
||||
|
||||
private WaypointDialogHelper waypointDialogHelper;
|
||||
private final int[] running = new int[] { -1 };
|
||||
private final int[] running = new int[]{-1};
|
||||
private List<LocationPointWrapper> deletedPoints = new ArrayList<LocationPointWrapper>();
|
||||
private Drawable gradientToolbar;
|
||||
|
||||
|
||||
public enum DashboardType {
|
||||
WAYPOINTS,
|
||||
WAYPOINTS_FLAT,
|
||||
|
@ -115,7 +146,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
CONFIGURE_SCREEN,
|
||||
CONFIGURE_MAP,
|
||||
LIST_MENU,
|
||||
DASHBOARD
|
||||
DASHBOARD
|
||||
}
|
||||
|
||||
public DashboardOnMap(MapActivity ma) {
|
||||
|
@ -166,6 +197,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
|
||||
private void updateListBackgroundHeight() {
|
||||
|
||||
if (listBackgroundView == null || listBackgroundView.getHeight() > 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -185,17 +217,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateToolbarActions() {
|
||||
TextView tv = (TextView) dashboardView.findViewById(R.id.toolbar_text);
|
||||
tv.setText("");
|
||||
boolean waypointsVisible = visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT;
|
||||
boolean waypointsEdit = visibleType == DashboardType.WAYPOINTS_EDIT;
|
||||
if (waypointsVisible || waypointsEdit){
|
||||
if (waypointsVisible || waypointsEdit) {
|
||||
tv.setText(R.string.waypoints);
|
||||
} else if(visibleType == DashboardType.CONFIGURE_MAP){
|
||||
} else if (visibleType == DashboardType.CONFIGURE_MAP) {
|
||||
tv.setText(R.string.configure_map);
|
||||
} else if(visibleType == DashboardType.CONFIGURE_SCREEN){
|
||||
} else if (visibleType == DashboardType.CONFIGURE_SCREEN) {
|
||||
tv.setText(R.string.layer_map_appearance);
|
||||
}
|
||||
ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit);
|
||||
|
@ -206,8 +237,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
ok.setVisibility(View.GONE);
|
||||
ImageView flat = (ImageView) dashboardView.findViewById(R.id.toolbar_flat);
|
||||
flat.setVisibility(View.GONE);
|
||||
ImageView settings = (ImageView) dashboardView.findViewById(R.id.toolbar_settings);
|
||||
settings.setVisibility(View.GONE);
|
||||
ImageView settingsButton = (ImageView) dashboardView.findViewById(R.id.toolbar_settings);
|
||||
settingsButton.setVisibility(View.GONE);
|
||||
ImageView configureScreen = (ImageView) dashboardView.findViewById(R.id.toolbar_configure_screen);
|
||||
configureScreen.setVisibility(View.GONE);
|
||||
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
|
||||
|
@ -215,15 +246,15 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
lst.setVisibility(View.GONE);
|
||||
ImageView back = (ImageView) dashboardView.findViewById(R.id.toolbar_back);
|
||||
back.setImageDrawable(
|
||||
((OsmandApplication)getMyApplication()).getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
||||
((OsmandApplication) getMyApplication()).getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
backPressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (waypointsVisible && getMyApplication().getWaypointHelper().getAllPoints().size() > 0) {
|
||||
if (mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) {
|
||||
sort.setVisibility(View.VISIBLE);
|
||||
|
@ -241,7 +272,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT);
|
||||
setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT);
|
||||
}
|
||||
});
|
||||
if (getMyApplication().getWaypointHelper().isRouteCalculated()) {
|
||||
|
@ -258,8 +289,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if(waypointsEdit) {
|
||||
}
|
||||
if (waypointsEdit) {
|
||||
ok.setVisibility(View.VISIBLE);
|
||||
ok.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
|
@ -271,25 +302,22 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
});
|
||||
}
|
||||
if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) {
|
||||
configureScreen.setVisibility(View.VISIBLE);
|
||||
configureScreen.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
configureScreen.setVisibility(View.VISIBLE);
|
||||
configureScreen.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN);
|
||||
}
|
||||
});
|
||||
|
||||
settings.setVisibility(View.VISIBLE);
|
||||
settings.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
settingsButton.setVisibility(View.VISIBLE);
|
||||
settingsButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Class<? extends Activity> sta = mapActivity.getMyApplication().getAppCustomization()
|
||||
.getSettingsActivity();
|
||||
hideDashboard(false);
|
||||
mapActivity.startActivity(new Intent(mapActivity, sta));
|
||||
new DashboardSettingsDialogFragment().show(
|
||||
mapActivity.getSupportFragmentManager(), "dashboard_settings");
|
||||
}
|
||||
});
|
||||
lst.setVisibility(View.VISIBLE);
|
||||
|
@ -317,16 +345,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
int btnSize = (int) mapActivity.getResources().getDimension(R.dimen.map_button_size);
|
||||
int topPad = (int) mapActivity.getResources().getDimension(R.dimen.dashboard_map_top_padding);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
|
||||
btnSize,btnSize
|
||||
);
|
||||
btnSize, btnSize
|
||||
);
|
||||
int marginRight = btnSize / 4;
|
||||
params.setMargins(0, landscape ? 0 : topPad - 2 * btnSize,
|
||||
params.setMargins(0, landscape ? 0 : topPad - 2 * btnSize,
|
||||
marginRight, landscape ? marginRight : 0);
|
||||
params.gravity = landscape ? Gravity.BOTTOM | Gravity.RIGHT : Gravity.TOP | Gravity.RIGHT;
|
||||
actionButton.setLayoutParams(params);
|
||||
actionButton.setScaleType(ScaleType.CENTER);
|
||||
actionButton.setImageDrawable(mapActivity.getResources().getDrawable(R.drawable.map_my_location));
|
||||
|
||||
|
||||
actionButton.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.btn_circle_blue));
|
||||
hideActionButton();
|
||||
actionButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -341,50 +369,50 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void hideActionButton() {
|
||||
actionButton.setVisibility(View.GONE);
|
||||
actionButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
public static int convertPixelsToDp(float dp, Context context){
|
||||
public static int convertPixelsToDp(float dp, Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||
}
|
||||
|
||||
|
||||
public net.osmand.Location getMyLocation() {
|
||||
return myLocation;
|
||||
}
|
||||
|
||||
|
||||
public LatLon getMapViewLocation() {
|
||||
return mapViewLocation;
|
||||
}
|
||||
|
||||
|
||||
public float getHeading() {
|
||||
return heading;
|
||||
}
|
||||
|
||||
|
||||
public float getMapRotation() {
|
||||
return mapRotation;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMapLinkedToLocation() {
|
||||
return mapLinkedToLocation;
|
||||
}
|
||||
|
||||
|
||||
protected OsmandApplication getMyApplication() {
|
||||
return mapActivity.getMyApplication();
|
||||
}
|
||||
|
||||
|
||||
public ArrayAdapter<?> getListAdapter() {
|
||||
return listAdapter;
|
||||
}
|
||||
|
||||
|
||||
public OnItemClickListener getListAdapterOnClickListener() {
|
||||
return listAdapterOnClickListener;
|
||||
}
|
||||
|
||||
|
||||
public void hideDashboard() {
|
||||
setDashboardVisibility(false, visibleType);
|
||||
}
|
||||
|
@ -399,12 +427,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
setDashboardVisibility(visible, type, this.visible ? visibleType : null, animation);
|
||||
}
|
||||
|
||||
public void refreshDashboardFragments(){
|
||||
public void refreshDashboardFragments() {
|
||||
addOrUpdateDashboardFragments();
|
||||
}
|
||||
|
||||
public void setDashboardVisibility(boolean visible, DashboardType type, DashboardType prevItem, boolean animation) {
|
||||
if(visible == this.visible && type == visibleType) {
|
||||
if (visible == this.visible && type == visibleType) {
|
||||
return;
|
||||
}
|
||||
this.previousVisibleType = prevItem;
|
||||
|
@ -420,7 +448,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
mapActivity.getMapViewTrackingUtilities().setDashboard(this);
|
||||
dashboardView.setVisibility(View.VISIBLE);
|
||||
if(isActionButtonVisible()) {
|
||||
if (isActionButtonVisible()) {
|
||||
actionButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
hideActionButton();
|
||||
|
@ -428,7 +456,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
updateDownloadBtn();
|
||||
View listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout);
|
||||
ScrollView scrollView = (ScrollView) dashboardView.findViewById(R.id.main_scroll);
|
||||
if(visibleType == DashboardType.DASHBOARD) {
|
||||
if (visibleType == DashboardType.DASHBOARD) {
|
||||
addOrUpdateDashboardFragments();
|
||||
scrollView.setVisibility(View.VISIBLE);
|
||||
scrollView.scrollTo(0, 0);
|
||||
|
@ -440,7 +468,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
if (listView instanceof ObservableListView) {
|
||||
onScrollChanged(((ObservableListView) listView).getScrollY(), false, false);
|
||||
}
|
||||
if(refresh) {
|
||||
if (refresh) {
|
||||
refreshContent(false);
|
||||
} else {
|
||||
updateListAdapter();
|
||||
|
@ -449,7 +477,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
mapActivity.findViewById(R.id.toolbar_back).setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE);
|
||||
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE);
|
||||
|
||||
|
||||
updateToolbarActions();
|
||||
//fabButton.showFloatingActionButton();
|
||||
open(dashboardView.findViewById(R.id.animateContent), animation);
|
||||
|
@ -464,7 +492,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
df.get().onCloseDash();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -487,9 +515,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
} else {
|
||||
if (DashboardType.CONFIGURE_SCREEN == visibleType) {
|
||||
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
|
||||
} else if(DashboardType.CONFIGURE_MAP == visibleType) {
|
||||
} else if (DashboardType.CONFIGURE_MAP == visibleType) {
|
||||
cm = new ConfigureMapMenu().createListAdapter(mapActivity);
|
||||
} else if(DashboardType.LIST_MENU == visibleType) {
|
||||
} else if (DashboardType.LIST_MENU == visibleType) {
|
||||
cm = mapActivity.getMapActions().createMainOptionsMenu();
|
||||
}
|
||||
if (cm != null) {
|
||||
|
@ -497,16 +525,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateListAdapter(ContextMenuAdapter cm) {
|
||||
final ArrayAdapter<?> listAdapter = cm.createListAdapter(mapActivity, getMyApplication().getSettings()
|
||||
.isLightContent());
|
||||
OnItemClickListener listener = getOptionsMenuOnClickListener(cm, listAdapter);
|
||||
updateListAdapter(listAdapter, listener);
|
||||
updateListAdapter(listAdapter, listener);
|
||||
}
|
||||
|
||||
|
||||
public void refreshContent(boolean force) {
|
||||
if(visibleType == DashboardType.WAYPOINTS || force) {
|
||||
if (visibleType == DashboardType.WAYPOINTS || force) {
|
||||
updateListAdapter();
|
||||
} else {
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
@ -515,15 +543,15 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
|
||||
private OnItemClickListener getOptionsMenuOnClickListener(final ContextMenuAdapter cm,
|
||||
final ArrayAdapter<?> listAdapter) {
|
||||
final ArrayAdapter<?> listAdapter) {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int which, long id) {
|
||||
OnContextMenuClick click = cm.getClickAdapter(which);
|
||||
if(click instanceof OnRowItemClick) {
|
||||
if (click instanceof OnRowItemClick) {
|
||||
boolean cl = ((OnRowItemClick) click).onRowItemClick(listAdapter, view, cm.getElementId(which), which);
|
||||
if(cl) {
|
||||
if (cl) {
|
||||
hideDashboard();
|
||||
}
|
||||
} else if (click != null) {
|
||||
|
@ -595,7 +623,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
public void navigationAction() {
|
||||
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
|
||||
if(!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
|
||||
if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
|
||||
mapActivity.getMapActions().enterRoutePlanningMode(null, null, false);
|
||||
} else {
|
||||
mapActivity.getRoutingHelper().setRoutePlanningMode(true);
|
||||
|
@ -621,7 +649,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
|
||||
private void hide(View view, boolean animation) {
|
||||
if(!animation) {
|
||||
if (!animation) {
|
||||
dashboardView.setVisibility(View.GONE);
|
||||
} else {
|
||||
TranslateAnimation animate = new TranslateAnimation(0, -mapActivity.findViewById(R.id.MapHudButtonsOverlay)
|
||||
|
@ -649,69 +677,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addOrUpdateDashboardFragments() {
|
||||
boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(mapActivity);
|
||||
// boolean showCards = mapActivity.getMyApplication().getSettings().USE_DASHBOARD_INSTEAD_OF_DRAWER.get();
|
||||
boolean showCards = !firstTime;
|
||||
|
||||
FragmentManager manager = mapActivity.getSupportFragmentManager();
|
||||
FragmentTransaction fragmentTransaction = manager.beginTransaction();
|
||||
|
||||
showFragment(manager, fragmentTransaction, DashRateUsFragment.TAG, DashRateUsFragment.class,
|
||||
DashRateUsFragment.shouldShow(getMyApplication().getSettings()));
|
||||
showFragment(manager, fragmentTransaction, DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, firstTime);
|
||||
showFragment(manager, fragmentTransaction, DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class,
|
||||
DashChooseAppDirFragment.isDashNeeded(getMyApplication().getSettings()));
|
||||
|
||||
showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class,
|
||||
mapActivity.getMyApplication().getAppInitializer().checkPreviousRunsForExceptions(mapActivity) && showCards);
|
||||
showFragment(manager, fragmentTransaction, DashNavigationFragment.TAG, DashNavigationFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashParkingFragment.TAG, DashParkingFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashWaypointsFragment.TAG, DashWaypointsFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashSearchFragment.TAG, DashSearchFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashRecentsFragment.TAG, DashRecentsFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashFavoritesFragment.TAG, DashFavoritesFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashTrackFragment.TAG, DashTrackFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashOsMoFragment.TAG, DashOsMoFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, showCards);
|
||||
// showFragment(manager, fragmentTransaction, DashUpdatesFragment.TAG, DashUpdatesFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashPluginsFragment.TAG, DashPluginsFragment.class, showCards);
|
||||
showFragment(manager, fragmentTransaction, DashSimulateFragment.TAG, DashSimulateFragment.class,
|
||||
OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null && showCards);
|
||||
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private <T extends DashBaseFragment> void showFragment(final FragmentManager manager,
|
||||
final FragmentTransaction fragmentTransaction,
|
||||
final String tag,
|
||||
final Class<T> cl,
|
||||
final boolean condition) {
|
||||
try {
|
||||
Fragment frag = manager.findFragmentByTag(tag);
|
||||
if (manager.findFragmentByTag(tag) == null ) {
|
||||
if(condition) {
|
||||
T ni = cl.newInstance();
|
||||
fragmentTransaction.add(R.id.content, ni, tag);
|
||||
}
|
||||
} else {
|
||||
if(!condition) {
|
||||
fragmentTransaction.remove(manager.findFragmentByTag(tag));
|
||||
} else if(frag instanceof DashBaseFragment){
|
||||
if(frag.getView() != null) {
|
||||
((DashBaseFragment) frag).onOpenDash();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getMyApplication().showToastMessage("Error showing dashboard " + tag);
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.v(TAG, "addOrUpdateDashboardFragments(" + ")");
|
||||
OsmandSettings settings = getMyApplication().getSettings();
|
||||
TransactionBuilder builder =
|
||||
new TransactionBuilder(mapActivity.getSupportFragmentManager(), settings, mapActivity);
|
||||
builder.addFragmentsData(fragmentsData).getFragmentTransaction().commit();
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
|
@ -720,18 +693,18 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
public void onDetach(DashBaseFragment dashBaseFragment) {
|
||||
Iterator<WeakReference<DashBaseFragment>> it = fragList.iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
WeakReference<DashBaseFragment> wr = it.next();
|
||||
if(wr.get() == dashBaseFragment) {
|
||||
if (wr.get() == dashBaseFragment) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateLocation(final boolean centerChanged, final boolean locationChanged, final boolean compassChanged){
|
||||
if(inLocationUpdate) {
|
||||
return ;
|
||||
|
||||
|
||||
public void updateLocation(final boolean centerChanged, final boolean locationChanged, final boolean compassChanged) {
|
||||
if (inLocationUpdate) {
|
||||
return;
|
||||
}
|
||||
inLocationUpdate = true;
|
||||
mapActivity.runOnUiThread(new Runnable() {
|
||||
|
@ -740,28 +713,28 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
inLocationUpdate = false;
|
||||
for (WeakReference<DashBaseFragment> df : fragList) {
|
||||
if (df.get() instanceof DashLocationFragment) {
|
||||
((DashLocationFragment)df.get()).updateLocation(centerChanged, locationChanged, compassChanged);
|
||||
((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void updateMyLocation(net.osmand.Location location) {
|
||||
myLocation = location;
|
||||
updateLocation(false, true, false);
|
||||
}
|
||||
|
||||
|
||||
public void updateCompassValue(double heading) {
|
||||
this.heading = (float) heading;
|
||||
updateLocation(false, false, true);
|
||||
}
|
||||
|
||||
public void onAttach(DashBaseFragment dashBaseFragment) {
|
||||
fragList.add(new WeakReference<DashBaseFragment>(dashBaseFragment));
|
||||
fragList.add(new WeakReference<>(dashBaseFragment));
|
||||
}
|
||||
|
||||
|
||||
public void requestLayout() {
|
||||
dashboardView.requestLayout();
|
||||
}
|
||||
|
@ -786,7 +759,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
|
||||
private void backPressed() {
|
||||
if(previousVisibleType != visibleType && previousVisibleType != null) {
|
||||
if (previousVisibleType != visibleType && previousVisibleType != null) {
|
||||
visibleType = null;
|
||||
setDashboardVisibility(true, previousVisibleType);
|
||||
} else {
|
||||
|
@ -799,7 +772,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
|
||||
// Translate list background
|
||||
if (portrait) {
|
||||
if(listBackgroundView != null) {
|
||||
if (listBackgroundView != null) {
|
||||
setTranslationY(listBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight));
|
||||
}
|
||||
}
|
||||
|
@ -813,13 +786,13 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
private boolean isActionButtonVisible() {
|
||||
return visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU || visibleType == DashboardType.CONFIGURE_SCREEN;
|
||||
}
|
||||
|
||||
|
||||
private boolean isBackButtonVisible() {
|
||||
return !(visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU);
|
||||
}
|
||||
|
||||
private void updateTopButton(int scrollY) {
|
||||
|
||||
|
||||
if (actionButton != null && portrait && isActionButtonVisible()) {
|
||||
double scale = mapActivity.getResources().getDisplayMetrics().density;
|
||||
int originalPosition = mFlexibleSpaceImageHeight - (int) (80 * scale);
|
||||
|
@ -857,13 +830,13 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateListAdapter(ArrayAdapter<?> listAdapter, OnItemClickListener listener) {
|
||||
this.listAdapter = listAdapter;
|
||||
this.listAdapterOnClickListener = listener;
|
||||
if (this.listView != null) {
|
||||
listView.setAdapter(listAdapter);
|
||||
if(!portrait) {
|
||||
if (!portrait) {
|
||||
listView.setOnItemClickListener(this.listAdapterOnClickListener);
|
||||
} else if (this.listAdapterOnClickListener != null) {
|
||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
@ -884,23 +857,23 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
v.setTranslationY(y);
|
||||
} else {
|
||||
TranslateAnimation anim = new TranslateAnimation(0, 0, y, y);
|
||||
anim.setFillAfter(true);
|
||||
anim.setDuration(0);
|
||||
v.startAnimation(anim);
|
||||
TranslateAnimation anim = new TranslateAnimation(0, 0, y, y);
|
||||
anim.setFillAfter(true);
|
||||
anim.setDuration(0);
|
||||
v.startAnimation(anim);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void setAlpha(View v, int alpha, int clr) {
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
// v.setAlpha(alpha/255.f);
|
||||
// } else {
|
||||
int colr = (((int) alpha ) << 24) | clr;
|
||||
v.setBackgroundColor(colr);
|
||||
int colr = (((int) alpha) << 24) | clr;
|
||||
v.setBackgroundColor(colr);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDownMotionEvent() {
|
||||
}
|
||||
|
@ -922,20 +895,23 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
|
||||
|
||||
public <T extends DashBaseFragment> T getFragmentByClass(Class<T> class1) {
|
||||
for(WeakReference<DashBaseFragment> f: fragList) {
|
||||
for (WeakReference<DashBaseFragment> f : fragList) {
|
||||
DashBaseFragment b = f.get();
|
||||
if(b != null && !b.isDetached() && class1.isInstance(b)) {
|
||||
if (b != null && !b.isDetached() && class1.isInstance(b)) {
|
||||
return (T) b;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void hideFragmentByTag(String tag) {
|
||||
public void blacklistFragmentByTag(String tag) {
|
||||
FragmentManager manager = mapActivity.getSupportFragmentManager();
|
||||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
Fragment frag = manager.findFragmentByTag(tag);
|
||||
transaction.hide(frag).commit();
|
||||
|
||||
getMyApplication().getSettings().registerBooleanPreference(SHOULD_SHOW + tag, true)
|
||||
.makeGlobal().set(false);
|
||||
}
|
||||
|
||||
public void unblacklistFragmentClass(String tag) {
|
||||
|
@ -943,9 +919,67 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
FragmentTransaction transaction = manager.beginTransaction();
|
||||
Fragment frag = manager.findFragmentByTag(tag);
|
||||
transaction.show(frag).commit();
|
||||
|
||||
getMyApplication().getSettings().registerBooleanPreference(SHOULD_SHOW + tag, true)
|
||||
.makeGlobal().set(true);
|
||||
}
|
||||
|
||||
View getParentView() {
|
||||
return dashboardView;
|
||||
}
|
||||
|
||||
public DashFragmentData[] getFragmentsData() {
|
||||
return fragmentsData;
|
||||
}
|
||||
|
||||
public static class SettingsShouldShow implements DashFragmentData.ShouldShowFunction {
|
||||
@Override
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
Log.v(TAG, "shouldShow(" + "settings=" + settings + ", activity=" + activity + ", tag=" + tag + ")");
|
||||
boolean shouldShow = settings.registerBooleanPreference(SHOULD_SHOW + tag, true)
|
||||
.makeGlobal().get();
|
||||
Log.v(TAG, "shouldShow=" + shouldShow);
|
||||
return shouldShow;
|
||||
}
|
||||
}
|
||||
public static class DefaultShouldShow extends SettingsShouldShow {
|
||||
@Override
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
return !activity.getMyApplication().getAppInitializer().isFirstTime(activity)
|
||||
&& super.shouldShow(settings, activity, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ErrorShouldShow extends DefaultShouldShow {
|
||||
@Override
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
return super.shouldShow(settings, activity, tag) && activity.getMyApplication()
|
||||
.getAppInitializer().checkPreviousRunsForExceptions(activity);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FirstTimeShouldShow extends DefaultShouldShow {
|
||||
@Override
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
return !super.shouldShow(settings, activity, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimulateShouldShow extends DefaultShouldShow {
|
||||
@Override
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
return super.shouldShow(settings, activity, tag)
|
||||
&& OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChooseAppDirShouldShow extends SettingsShouldShow {
|
||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
return false;
|
||||
}
|
||||
return !settings.isExternalStorageDirectorySpecifiedV19()
|
||||
&& super.shouldShow(settings, activity, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package net.osmand.plus.dashboard.tools;
|
||||
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashBaseFragment;
|
||||
|
||||
public final class DashFragmentData {
|
||||
public final String tag;
|
||||
public final Class<? extends DashBaseFragment> fragmentClass;
|
||||
public final String title;
|
||||
public final ShouldShowFunction shouldShowFunction;
|
||||
|
||||
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
|
||||
String title, ShouldShowFunction shouldShowFunction) {
|
||||
this.tag = tag;
|
||||
this.fragmentClass = fragmentClass;
|
||||
this.title = title;
|
||||
this.shouldShowFunction = shouldShowFunction;
|
||||
}
|
||||
|
||||
public interface ShouldShowFunction {
|
||||
boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package net.osmand.plus.dashboard.tools;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||
|
||||
public class DashboardSettingsDialogFragment extends DialogFragment {
|
||||
private MapActivity mapActivity;
|
||||
private DashFragmentData[] fragmentsData;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mapActivity = (MapActivity) activity;
|
||||
fragmentsData = mapActivity.getDashboard().getFragmentsData();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
|
||||
final DashFragmentAdapter adapter =
|
||||
new DashFragmentAdapter(getActivity(), fragmentsData,
|
||||
settings);
|
||||
builder.setTitle(R.string.dahboard_options_dialog_title)
|
||||
.setAdapter(adapter, null)
|
||||
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int type) {
|
||||
boolean[] shouldShow = adapter.getCheckedItems();
|
||||
for (int i = 0; i < shouldShow.length; i++) {
|
||||
settings.registerBooleanPreference(
|
||||
DashboardOnMap.SHOULD_SHOW + fragmentsData[i].tag, true)
|
||||
.makeGlobal().set(shouldShow[i]);
|
||||
}
|
||||
mapActivity.getDashboard().refreshDashboardFragments();
|
||||
}
|
||||
});
|
||||
final AlertDialog dialog = builder.create();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private static class DashFragmentAdapter extends ArrayAdapter<DashFragmentData> {
|
||||
private final boolean[] checkedItems;
|
||||
|
||||
public DashFragmentAdapter(Context context, DashFragmentData[] objects, OsmandSettings settings) {
|
||||
super(context, 0, objects);
|
||||
checkedItems = new boolean[objects.length];
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
checkedItems[i] = settings.registerBooleanPreference(
|
||||
DashboardOnMap.SHOULD_SHOW + objects[i].tag, true).makeGlobal().get();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
DashFragmentData dashFragmentData = getItem(position);
|
||||
DashViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
viewHolder = new DashViewHolder();
|
||||
convertView = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.dashboard_settings_dialog_item, parent, false);
|
||||
viewHolder.textView = (TextView) convertView.findViewById(R.id.text);
|
||||
viewHolder.compoundButton = (CompoundButton) convertView.findViewById(R.id.check_item);
|
||||
viewHolder.compoundButton.setOnCheckedChangeListener(
|
||||
new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
Integer position = (Integer) compoundButton.getTag();
|
||||
checkedItems[position] = b;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
viewHolder = (DashViewHolder) convertView.getTag();
|
||||
}
|
||||
viewHolder.compoundButton.setTag(position);
|
||||
viewHolder.compoundButton.setChecked(checkedItems[position]);
|
||||
viewHolder.textView.setText(dashFragmentData.title);
|
||||
convertView.setTag(viewHolder);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public boolean[] getCheckedItems() {
|
||||
return checkedItems;
|
||||
}
|
||||
|
||||
private class DashViewHolder {
|
||||
TextView textView;
|
||||
CompoundButton compoundButton;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package net.osmand.plus.dashboard.tools;
|
||||
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashBaseFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by GaidamakUA on 8/6/15.
|
||||
*/
|
||||
public final class TransactionBuilder {
|
||||
private static final String TAG = "TransactionBuilder";
|
||||
private FragmentManager manager;
|
||||
private List<DashFragmentData> fragments = new ArrayList<>();
|
||||
private OsmandSettings settings;
|
||||
private MapActivity mapActivity;
|
||||
|
||||
public TransactionBuilder(FragmentManager manager, OsmandSettings settings,
|
||||
MapActivity mapActivity) {
|
||||
this.manager = manager;
|
||||
this.settings = settings;
|
||||
this.mapActivity = mapActivity;
|
||||
}
|
||||
|
||||
public TransactionBuilder addFragmentsData(DashFragmentData... dashFragmentsData) {
|
||||
fragments.addAll(Arrays.asList(dashFragmentsData));
|
||||
return this;
|
||||
}
|
||||
|
||||
public FragmentTransaction getFragmentTransaction() {
|
||||
Log.v(TAG, "getFragmentTransaction(" + ")");
|
||||
FragmentTransaction fragmentTransaction = manager.beginTransaction();
|
||||
for (DashFragmentData dashFragmentData : fragments) {
|
||||
DashBaseFragment fragment =
|
||||
(DashBaseFragment) manager.findFragmentByTag(dashFragmentData.tag);
|
||||
if (manager.findFragmentByTag(dashFragmentData.tag) == null) {
|
||||
if (dashFragmentData.shouldShowFunction.shouldShow(settings, mapActivity, dashFragmentData.tag)) {
|
||||
DashBaseFragment newInstance = null;
|
||||
try {
|
||||
newInstance = dashFragmentData.fragmentClass.newInstance();
|
||||
// XXX hardcoded value
|
||||
fragmentTransaction.add(R.id.content, newInstance, dashFragmentData.tag);
|
||||
} catch (InstantiationException e) {
|
||||
Log.v(TAG, "");
|
||||
mapActivity.getMyApplication()
|
||||
.showToastMessage("Error showing dashboard " + dashFragmentData.tag);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.v(TAG, "");
|
||||
mapActivity.getMyApplication()
|
||||
.showToastMessage("Error showing dashboard " + dashFragmentData.tag);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!dashFragmentData.shouldShowFunction.shouldShow(settings, mapActivity, dashFragmentData.tag)) {
|
||||
fragmentTransaction.remove(manager.findFragmentByTag(dashFragmentData.tag));
|
||||
} else if (fragment.getView() != null) {
|
||||
if (fragment.isHidden()) {
|
||||
fragmentTransaction.show(fragment);
|
||||
}
|
||||
fragment.onOpenDash();
|
||||
}
|
||||
}
|
||||
}
|
||||
return fragmentTransaction;
|
||||
}
|
||||
}
|
|
@ -16,8 +16,6 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashBaseFragment;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class DashSimulateFragment extends DashBaseFragment {
|
||||
|
||||
public static final String TAG = "DASH_SIMULATE_FRAGMENT";
|
||||
|
@ -61,5 +59,4 @@ public class DashSimulateFragment extends DashBaseFragment {
|
|||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue