This commit is contained in:
Alexey Kulish 2016-03-03 18:56:44 +03:00
parent a349213141
commit 425e772f20
8 changed files with 376 additions and 144 deletions

View file

@ -1,118 +1,219 @@
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg" android:background="?attr/bottom_menu_view_bg"
tools:context="net.osmand.plus.download.ui.DataStoragePlaceDialogFragment"> android:orientation="horizontal"
tools:context="net.osmand.plus.download.ui.DataStoragePlaceDialogFragment">
<ImageView <LinearLayout
android:id="@+id/folderIconImageView" android:layout_width="wrap_content"
android:layout_width="56dp" android:layout_height="match_parent">
android:layout_height="56dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_row="0"
android:scaleType="center"
tools:background="@color/color_warning"
tools:src="@drawable/ic_action_folder"/>
<TextView <ImageView
android:id="@+id/folderIconImageView"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_row="0"
android:scaleType="center"
tools:background="@color/color_warning"
tools:src="@drawable/ic_action_folder"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_columnSpan="2" android:layout_weight="1"
android:layout_gravity="fill_horizontal" android:orientation="vertical">
android:layout_marginTop="22dp"
android:layout_row="0"
android:text="@string/application_dir"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="@dimen/dialog_header_text_size"/>
<ImageButton <LinearLayout
android:id="@+id/closeImageButton" android:layout_width="match_parent"
style="@style/Widget.AppCompat.Button.Borderless" android:layout_height="wrap_content"
android:layout_width="44dp" android:orientation="horizontal">
android:layout_height="44dp"
android:src="@drawable/ic_action_remove_dark"
tools:background="@color/color_warning"/>
<TextView <TextView
android:layout_width="0dp" android:id="@+id/title"
android:layout_column="1" android:layout_width="0dp"
android:layout_columnSpan="2" android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal" android:layout_gravity="fill_horizontal"
android:layout_marginBottom="24dp" android:layout_weight="1"
android:layout_row="1" android:paddingTop="22dp"
android:text="@string/application_dir_description" android:text="@string/application_dir"
android:textSize="16sp"/> android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="@dimen/dialog_header_text_size"/>
<ImageView <ImageButton
android:id="@+id/deviceMemoryImageView" android:id="@+id/closeImageButton"
android:layout_width="wrap_content" style="@style/Widget.AppCompat.Button.Borderless"
android:layout_height="56dp" android:layout_width="44dp"
android:layout_column="1" android:layout_height="44dp"
android:layout_row="2" android:src="@drawable/ic_action_remove_dark"
android:layout_rowSpan="2" tools:background="@color/color_warning"/>
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/ic_sdcard"
tools:background="@color/color_warning"/>
<TextView </LinearLayout>
android:id="@+id/deviceMemoryTitle"
android:layout_width="0dp"
android:layout_column="2"
android:layout_gravity="fill_horizontal"
android:layout_marginTop="8dp"
android:layout_row="2"
android:gravity="center_vertical"
android:text="@string/storage_directory_default"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView <TextView
android:id="@+id/deviceMemoryDescription" android:id="@+id/description"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_column="2" android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal" android:layout_gravity="fill_horizontal"
android:layout_row="3" android:layout_marginBottom="24dp"
tools:text="Free: 568 Mb"/> android:layout_marginTop="4dp"
android:text="@string/application_dir_description"
android:textSize="16sp"/>
<View <ScrollView
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="match_parent">
android:layout_column="1"
android:layout_columnSpan="3"
android:layout_gravity="fill_horizontal"
android:layout_row="4"
android:background="@color/divider_color"/>
<ImageView <LinearLayout
android:id="@+id/memoryStickImageView" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="56dp" android:orientation="vertical">
android:layout_column="1"
android:layout_row="5"
android:layout_rowSpan="2"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/ic_sdcard"
tools:background="@color/color_warning"/>
<TextView <LinearLayout
android:id="@+id/memoryStickTitle" android:id="@+id/deviceMemoryRow"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_column="2" android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal" android:background="?attr/selectableItemBackground"
android:layout_marginTop="8dp" android:orientation="horizontal">
android:layout_row="5"
android:text="@string/storage_directory_external"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView <ImageView
android:id="@+id/memoryStickDescription" android:id="@+id/deviceMemoryImageView"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_column="2" android:layout_height="56dp"
android:layout_gravity="fill_horizontal" android:paddingRight="16dp"
android:layout_row="6" android:scaleType="center"
tools:text="Free: 9 Gb"/> android:src="@drawable/ic_sdcard"
</GridLayout> tools:background="@color/color_warning"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/deviceMemoryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:gravity="center_vertical"
android:text="@string/storage_directory_default"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/deviceMemoryDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
tools:text="Free: 568 Mb"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="fill_horizontal"
android:background="@color/divider_color"/>
<LinearLayout
android:id="@+id/sharedMemoryRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:id="@+id/sharedMemoryImageView"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/ic_sdcard"
tools:background="@color/color_warning"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/sharedMemoryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:text="@string/storage_directory_shared"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/sharedMemoryDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
tools:text="Free: 9 Gb"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="fill_horizontal"
android:background="@color/divider_color"/>
<LinearLayout
android:id="@+id/memoryStickRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:id="@+id/memoryStickImageView"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/ic_sdcard"
tools:background="@color/color_warning"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/memoryStickTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:text="@string/storage_directory_external"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/memoryStickDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
tools:text="Free: 9 Gb"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="storage_directory_readonly_desc">Currently selected Data storage folder is readonly. The storage folder was temporarily switched to Internal memory. Please choose valid storage directory.</string>
<string name="storage_directory_shared">Shared memory</string>
<string name="shared_string_topbar">Topbar</string> <string name="shared_string_topbar">Topbar</string>
<string name="recalculate_route">Recalculate route</string> <string name="recalculate_route">Recalculate route</string>
<string name="donations">Donations</string> <string name="donations">Donations</string>

View file

@ -1,5 +1,6 @@
package net.osmand.plus; package net.osmand.plus;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -69,13 +70,14 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIn
*/ */
public class AppInitializer implements IProgress { public class AppInitializer implements IProgress {
// 22 - 2.2 // 22 - 2.2
private static final int VERSION_2_2 = 22; public static final int VERSION_2_2 = 22;
private static final int CURRENT_VERSION_FOR_UGPRADE = VERSION_2_2; // 23 - 2.3
public static final int VERSION_2_3 = 23;
public static final boolean TIPS_AND_TRICKS = false; public static final boolean TIPS_AND_TRICKS = false;
private static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$ public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
private static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$NON-NLS-1$ public static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$NON-NLS-1$
public static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$ public static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$
public static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$ public static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$
private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$ private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$
@ -93,6 +95,7 @@ public class AppInitializer implements IProgress {
private boolean firstTime; private boolean firstTime;
private boolean activityChangesShowed = false; private boolean activityChangesShowed = false;
private boolean appVersionChanged; private boolean appVersionChanged;
private int prevAppVersion;
private long startTime; private long startTime;
private long startBgTime; private long startBgTime;
private boolean appInitializing = true; private boolean appInitializing = true;
@ -130,11 +133,14 @@ public class AppInitializer implements IProgress {
} }
private void initUiVars(Activity activity) { @SuppressLint("CommitPrefEdits")
public void initVariables() {
if(initSettings) { if(initSettings) {
return; return;
} }
startPrefs = activity.getPreferences(Context.MODE_WORLD_WRITEABLE); startPrefs = app.getSharedPreferences(
getLocalClassName(app.getAppCustomization().getMapActivity().getName()),
Context.MODE_WORLD_WRITEABLE);
if(!startPrefs.contains(NUMBER_OF_STARTS)) { if(!startPrefs.contains(NUMBER_OF_STARTS)) {
startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit(); startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit();
} else { } else {
@ -147,14 +153,18 @@ public class AppInitializer implements IProgress {
firstTime = true; firstTime = true;
startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit(); startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit(); startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
} else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) { } else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) {
if(startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0) < VERSION_2_2) { prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
if(prevAppVersion < VERSION_2_2) {
app.getSettings().SHOW_DASHBOARD_ON_START.set(true); app.getSettings().SHOW_DASHBOARD_ON_START.set(true);
app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true); app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true); app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit(); startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit();
} }
if(prevAppVersion < VERSION_2_3) {
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
}
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true; appVersionChanged = true;
} }
@ -181,13 +191,21 @@ public class AppInitializer implements IProgress {
} }
} }
public boolean isFirstTime(Activity activity) { public boolean isFirstTime() {
initUiVars(activity); initVariables();
return firstTime; return firstTime;
} }
public boolean checkAppVersionChanged(Activity activity) { public boolean isAppVersionChanged() {
initUiVars(activity); return appVersionChanged;
}
public int getPrevAppVersion() {
return prevAppVersion;
}
public boolean checkAppVersionChanged() {
initVariables();
boolean showRecentChangesDialog = !firstTime && appVersionChanged; boolean showRecentChangesDialog = !firstTime && appVersionChanged;
// showRecentChangesDialog = true; // showRecentChangesDialog = true;
if (showRecentChangesDialog && !activityChangesShowed) { if (showRecentChangesDialog && !activityChangesShowed) {
@ -210,7 +228,7 @@ public class AppInitializer implements IProgress {
} }
public boolean checkPreviousRunsForExceptions(Activity activity, boolean writeFileSize) { public boolean checkPreviousRunsForExceptions(Activity activity, boolean writeFileSize) {
initUiVars(activity); initVariables();
long size = activity.getPreferences(Context.MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0); long size = activity.getPreferences(Context.MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0);
final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH); final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH);
if (file.exists() && file.length() > 0) { if (file.exists() && file.length() > 0) {
@ -729,5 +747,13 @@ public class AppInitializer implements IProgress {
this.listeners.remove(listener); this.listeners.remove(listener);
} }
private String getLocalClassName(String cls) {
final String pkg = app.getPackageName();
int packageLen = pkg.length();
if (!cls.startsWith(pkg) || cls.length() <= packageLen
|| cls.charAt(packageLen) != '.') {
return cls;
}
return cls.substring(packageLen+1);
}
} }

View file

@ -103,6 +103,7 @@ public class OsmandApplication extends MultiDexApplication {
private Locale preferredLocale = null; private Locale preferredLocale = null;
private Locale defaultLocale; private Locale defaultLocale;
private File externalStorageDirectory; private File externalStorageDirectory;
private boolean externalStorageDirectoryReadOnly;
private String firstSelectedVoiceProvider; private String firstSelectedVoiceProvider;
@ -126,7 +127,17 @@ public class OsmandApplication extends MultiDexApplication {
appCustomization = new OsmAndAppCustomization(); appCustomization = new OsmAndAppCustomization();
appCustomization.setup(this); appCustomization.setup(this);
osmandSettings = appCustomization.getOsmandSettings(); osmandSettings = appCustomization.getOsmandSettings();
appInitializer.initVariables();
if (appInitializer.isAppVersionChanged() && appInitializer.getPrevAppVersion() < AppInitializer.VERSION_2_3) {
osmandSettings.freezeExternalStorageDirectory();
} else if (appInitializer.isFirstTime()) {
osmandSettings.initExternalStorageDirectory();
}
externalStorageDirectory = osmandSettings.getExternalStorageDirectory(); externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
if (!OsmandSettings.isWritable(externalStorageDirectory)) {
externalStorageDirectoryReadOnly = true;
externalStorageDirectory = osmandSettings.getInternalAppPath();
}
checkPreferredLocale(); checkPreferredLocale();
appInitializer.onCreateApplication(); appInitializer.onCreateApplication();
@ -141,6 +152,10 @@ public class OsmandApplication extends MultiDexApplication {
System.out.println("Time to init plugins " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms"); System.out.println("Time to init plugins " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms");
} }
public boolean isExternalStorageDirectoryReadOnly() {
return externalStorageDirectoryReadOnly;
}
@Override @Override
protected void attachBaseContext(Context base) { protected void attachBaseContext(Context base) {
super.attachBaseContext(base); super.attachBaseContext(base);
@ -618,6 +633,7 @@ public class OsmandApplication extends MultiDexApplication {
public void setExternalStorageDirectory(int type, String directory){ public void setExternalStorageDirectory(int type, String directory){
osmandSettings.setExternalStorageDirectory(type, directory); osmandSettings.setExternalStorageDirectory(type, directory);
externalStorageDirectory = osmandSettings.getExternalStorageDirectory(); externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
externalStorageDirectoryReadOnly = false;
getResourceManager().resetStoreDirectory(); getResourceManager().resetStoreDirectory();
} }

View file

@ -1282,12 +1282,31 @@ public class OsmandSettings {
public static final int EXTERNAL_STORAGE_TYPE_SPECIFIED = 4; public static final int EXTERNAL_STORAGE_TYPE_SPECIFIED = 4;
public void freezeExternalStorageDirectory() {
if (Build.VERSION.SDK_INT >= 19) {
int type = settingsAPI.getInt(globalPreferences, EXTERNAL_STORAGE_DIR_TYPE_V19, -1);
if (type == -1) {
ValueHolder<Integer> vh = new ValueHolder<>();
File f = getExternalStorageDirectoryV19(vh);
setExternalStorageDirectoryV19(vh.value, f.getAbsolutePath());
}
}
}
public void initExternalStorageDirectory() {
if (Build.VERSION.SDK_INT < 19) {
setExternalStorageDirectoryPre19(getInternalAppPath().getAbsolutePath());
} else {
setExternalStorageDirectoryV19(EXTERNAL_STORAGE_TYPE_INTERNAL_FILE, getInternalAppPath().getAbsolutePath());
}
}
public File getExternalStorageDirectory() { public File getExternalStorageDirectory() {
return getExternalStorageDirectory(null); return getExternalStorageDirectory(null);
} }
public File getExternalStorageDirectory(ValueHolder<Integer> type) { public File getExternalStorageDirectory(ValueHolder<Integer> type) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT < 19) {
return getExternalStorageDirectoryPre19(); return getExternalStorageDirectoryPre19();
} else { } else {
return getExternalStorageDirectoryV19(type); return getExternalStorageDirectoryV19(type);
@ -1395,7 +1414,7 @@ public class OsmandSettings {
@SuppressLint("NewApi") @SuppressLint("NewApi")
@Nullable @Nullable
public File getSecondaryStorage() { public File getSecondaryStorage() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT < 19) {
return getExternalStorageDirectoryPre19(); return getExternalStorageDirectoryPre19();
} else { } else {
File[] externals = ctx.getExternalFilesDirs(null); File[] externals = ctx.getExternalFilesDirs(null);

View file

@ -72,6 +72,7 @@ import net.osmand.plus.dialogs.ErrorBottomSheetDialog;
import net.osmand.plus.dialogs.RateUsBottomSheetDialog; import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
import net.osmand.plus.dialogs.WhatsNewDialogFragment; import net.osmand.plus.dialogs.WhatsNewDialogFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxImportHelper; import net.osmand.plus.helpers.GpxImportHelper;
import net.osmand.plus.helpers.WakeLockHelper; import net.osmand.plus.helpers.WakeLockHelper;
@ -207,7 +208,7 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
int h = dm.heightPixels - statusBarHeight; int h = dm.heightPixels - statusBarHeight;
mapView = new OsmandMapTileView(this, w, h); mapView = new OsmandMapTileView(this, w, h);
if (app.getAppInitializer().checkAppVersionChanged(this) && WhatsNewDialogFragment.SHOW) { if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) {
WhatsNewDialogFragment.SHOW = false; WhatsNewDialogFragment.SHOW = false;
new WhatsNewDialogFragment().show(getSupportFragmentManager(), null); new WhatsNewDialogFragment().show(getSupportFragmentManager(), null);
} }
@ -276,7 +277,7 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
} }
mapView.refreshMap(true); mapView.refreshMap(true);
if (getMyApplication().getAppInitializer().isFirstTime(this) && FirstUsageFragment.SHOW) { if (getMyApplication().getAppInitializer().isFirstTime() && FirstUsageFragment.SHOW) {
FirstUsageFragment.SHOW = false; FirstUsageFragment.SHOW = false;
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, new FirstUsageFragment(), .add(R.id.fragmentContainer, new FirstUsageFragment(),
@ -580,6 +581,11 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
if (System.currentTimeMillis() - tm > 50) { if (System.currentTimeMillis() - tm > 50) {
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms"); System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
} }
if (app.isExternalStorageDirectoryReadOnly()
&& getSupportFragmentManager().findFragmentByTag(DataStoragePlaceDialogFragment.TAG) == null) {
DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), true);
}
} }
private void parseNavigationIntent(final Uri data) { private void parseNavigationIntent(final Uri data) {

View file

@ -599,7 +599,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
} }
private void showFirstTimeExternalStorage() { private void showFirstTimeExternalStorage() {
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this); final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime();
final boolean externalExists = final boolean externalExists =
getMyApplication().getSettings().getSecondaryStorage() != null; getMyApplication().getSettings().getSecondaryStorage() != null;
if (firstTime && (externalExists || !hasPermissionToWriteExternalStorage()) if (firstTime && (externalExists || !hasPermissionToWriteExternalStorage())
@ -617,7 +617,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
private void chooseDataStorage() { private void chooseDataStorage() {
if (getMyApplication().getSettings().getSecondaryStorage() != null) { if (getMyApplication().getSettings().getSecondaryStorage() != null) {
new DataStoragePlaceDialogFragment().show(getSupportFragmentManager(), null); DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), false);
} }
} }

View file

@ -3,6 +3,8 @@ package net.osmand.plus.download.ui;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.os.StatFs; import android.os.StatFs;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -19,15 +21,21 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import java.io.File; import java.io.File;
public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment { public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
public static final String TAG = "DataStoragePlaceDialogFragment";
private static final String STORAGE_READOLNY_KEY = "storage_readolny_key";
private File internalStorage; private File internalStorage;
private File sharedStorage;
private File externalStorage; private File externalStorage;
public static boolean isInterestedInFirstTime = true; public static boolean isInterestedInFirstTime = true;
boolean storageReadOnly;
@Override @Override
public void onStart() { public void onStart() {
@ -45,34 +53,50 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
internalStorage = getInternalStorageDirectory(getActivity()); internalStorage = getInternalStorageDirectory(getActivity());
sharedStorage = getSharedStorageDirectory(getActivity());
externalStorage = getMyApplication().getSettings().getSecondaryStorage(); externalStorage = getMyApplication().getSettings().getSecondaryStorage();
Bundle args = null;
if (savedInstanceState != null) {
args = savedInstanceState;
} else if (getArguments() != null) {
args = getArguments();
}
if (args != null) {
storageReadOnly = args.getBoolean(STORAGE_READOLNY_KEY);
}
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container, final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
false); false);
((ImageView) view.findViewById(R.id.folderIconImageView)) ((ImageView) view.findViewById(R.id.folderIconImageView))
.setImageDrawable(getIcon(R.drawable.ic_action_folder, R.color.map_widget_blue)); .setImageDrawable(getIcon(R.drawable.ic_action_folder, R.color.map_widget_blue));
if (storageReadOnly) {
((TextView) view.findViewById(R.id.description))
.setText(getString(R.string.storage_directory_readonly_desc));
}
View internalStorageRow = view.findViewById(R.id.deviceMemoryRow);
internalStorageRow.setOnClickListener(internalMemoryOnClickListener);
ImageView internalStorageImageView = (ImageView) view.findViewById(R.id.deviceMemoryImageView); ImageView internalStorageImageView = (ImageView) view.findViewById(R.id.deviceMemoryImageView);
internalStorageImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard)); internalStorageImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
internalStorageImageView.setOnClickListener(internalMemoryOnClickListener);
View internalStorageTitle = view.findViewById(R.id.deviceMemoryTitle);
internalStorageTitle.setOnClickListener(internalMemoryOnClickListener);
TextView internalStorageDescription = (TextView) view.findViewById(R.id.deviceMemoryDescription); TextView internalStorageDescription = (TextView) view.findViewById(R.id.deviceMemoryDescription);
internalStorageDescription.setOnClickListener(internalMemoryOnClickListener);
internalStorageDescription.setText(getFreeSpace(internalStorage)); internalStorageDescription.setText(getFreeSpace(internalStorage));
ImageView externalStorageImageView = ((ImageView) view.findViewById(R.id.memoryStickImageView)); View sharedMemoryRow = view.findViewById(R.id.sharedMemoryRow);
externalStorageImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard)); sharedMemoryRow.setOnClickListener(sharedMemoryOnClickListener);
externalStorageImageView.setOnClickListener(externalMemoryOnClickListener); ImageView sharedMemoryImageView = (ImageView) view.findViewById(R.id.sharedMemoryImageView);
sharedMemoryImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
TextView sharedMemoryDescription = (TextView) view.findViewById(R.id.sharedMemoryDescription);
sharedMemoryDescription.setText(getFreeSpace(sharedStorage));
View externalStorageTitle = view.findViewById(R.id.memoryStickTitle); View memoryStickRow = view.findViewById(R.id.memoryStickRow);
externalStorageTitle.setOnClickListener(externalMemoryOnClickListener); memoryStickRow.setOnClickListener(externalMemoryOnClickListener);
ImageView memoryStickImageView = (ImageView) view.findViewById(R.id.memoryStickImageView);
TextView externalStorageDescription = (TextView) view.findViewById(R.id.memoryStickDescription); memoryStickImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
externalStorageDescription.setOnClickListener(externalMemoryOnClickListener); TextView memoryStickDescription = (TextView) view.findViewById(R.id.memoryStickDescription);
externalStorageDescription.setText(getFreeSpace(externalStorage)); memoryStickDescription.setText(getFreeSpace(externalStorage));
final ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton); final ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
closeImageButton.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark)); closeImageButton.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark));
@ -86,7 +110,18 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
return view; return view;
} }
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STORAGE_READOLNY_KEY, storageReadOnly);
}
public static File getInternalStorageDirectory(Activity activity) { public static File getInternalStorageDirectory(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings()
.getInternalAppPath();
}
public static File getSharedStorageDirectory(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings() return ((OsmandApplication) activity.getApplication()).getSettings()
.getDefaultInternalStorage(); .getDefaultInternalStorage();
} }
@ -112,32 +147,59 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT, saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE,
internalStorage, getActivity()); internalStorage, getActivity());
isInterestedInFirstTime = false; isInterestedInFirstTime = false;
dismiss(); dismiss();
} }
}; };
private View.OnClickListener sharedMemoryOnClickListener =
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT,
sharedStorage, getActivity());
isInterestedInFirstTime = false;
dismiss();
}
};
private View.OnClickListener externalMemoryOnClickListener = private View.OnClickListener externalMemoryOnClickListener =
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE, boolean res = saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE,
externalStorage, getActivity()); externalStorage, getActivity());
isInterestedInFirstTime = false; isInterestedInFirstTime = false;
dismiss(); if (res) {
dismiss();
}
} }
}; };
public static void saveFilesLocation(int type, File selectedFile, Activity context) { public boolean saveFilesLocation(int type, File selectedFile, Activity context) {
boolean wr = OsmandSettings.isWritable(selectedFile); boolean wr = OsmandSettings.isWritable(selectedFile);
if (wr) { if (wr) {
((OsmandApplication) context.getApplication()) ((OsmandApplication) context.getApplication())
.setExternalStorageDirectory(type, selectedFile.getAbsolutePath()); .setExternalStorageDirectory(type, selectedFile.getAbsolutePath());
reloadData();
} else { } else {
AccessibleToast.makeText(context, R.string.specified_directiory_not_writeable, AccessibleToast.makeText(context, R.string.specified_directiory_not_writeable,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} }
return wr;
}
private void reloadData() {
new DashChooseAppDirFragment.ReloadData(getActivity(), getMyApplication()).execute((Void) null);
}
public static void showInstance(FragmentManager fragmentManager, boolean storageReadOnly) {
DataStoragePlaceDialogFragment f = new DataStoragePlaceDialogFragment();
Bundle args = new Bundle();
args.putBoolean(STORAGE_READOLNY_KEY, storageReadOnly);
f.setArguments(args);
f.show(fragmentManager, DataStoragePlaceDialogFragment.TAG);
} }
} }