DataStoragePlaceDialogFragment implemented

This commit is contained in:
GaidamakUA 2015-10-23 15:57:58 +03:00
parent d60e3170e1
commit 9fc6d79adb
6 changed files with 146 additions and 33 deletions

View file

@ -3,7 +3,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
tools:background="@color/color_warning"
tools:context="net.osmand.plus.download.ui.DataStoragePlaceDialogFragment">
<ImageView
@ -12,26 +11,29 @@
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
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_columnSpan="2"
android:layout_columnWeight="1"
android:layout_gravity="fill_horizontal"
android:layout_marginTop="22dp"
android:text="Data storage folder"
android:layout_row="0"
android:text="@string/application_dir"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="@dimen/dialog_header_text_size"/>
<ImageButton
android:id="@+id/crossIconImageView"
android:id="@+id/closeImageButton"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="44dp"
android:layout_height="44dp"
android:src="@drawable/ic_action_remove_dark"/>
android:src="@drawable/ic_action_remove_dark"
tools:background="@color/color_warning"/>
<TextView
android:layout_width="0dp"
@ -40,7 +42,7 @@
android:layout_gravity="fill_horizontal"
android:layout_marginBottom="24dp"
android:layout_row="1"
android:text="Choose where you want to save map files."
android:text="@string/application_dir_description"
android:textSize="16sp"/>
<ImageView
@ -52,7 +54,8 @@
android:layout_rowSpan="2"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/ic_sdcard"/>
android:src="@drawable/ic_sdcard"
tools:background="@color/color_warning"/>
<TextView
android:id="@+id/deviceMemoryTitle"
@ -62,7 +65,7 @@
android:layout_marginTop="8dp"
android:layout_row="2"
android:gravity="center_vertical"
android:text="Device memory"
android:text="@string/storage_directory_default"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
@ -71,7 +74,7 @@
android:layout_column="2"
android:layout_gravity="fill_horizontal"
android:layout_row="3"
android:text="Free: 568 Mb"/>
tools:text="Free: 568 Mb"/>
<View
android:layout_width="0dp"
@ -80,7 +83,7 @@
android:layout_columnSpan="3"
android:layout_gravity="fill_horizontal"
android:layout_row="4"
android:background="#FFF"/>
android:background="@color/divider_color"/>
<ImageView
android:id="@+id/memoryStickImageView"
@ -91,7 +94,8 @@
android:layout_rowSpan="2"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/ic_sdcard"/>
android:src="@drawable/ic_sdcard"
tools:background="@color/color_warning"/>
<TextView
android:id="@+id/memoryStickTitle"
@ -100,14 +104,14 @@
android:layout_gravity="fill_horizontal"
android:layout_marginTop="8dp"
android:layout_row="5"
android:text="Memory stick"
android:text="@string/storage_directory_external"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/memoryStickDescription"
android:layout_width="0dp"
android:layout_column="2"
android:layout_gravity="fill_horizontal"
android:layout_row="6"
android:text="Free: 9 Gb"
android:id="@+id/memoryStickDescription"/>
tools:text="Free: 9 Gb"/>
</GridLayout>

View file

@ -2027,4 +2027,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="application_dir_description">Choose where you want to save map files.</string>
</resources>

View file

@ -294,14 +294,13 @@
<item name="android:textColor">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowBackground">@color/color_white</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimAmount">0.3</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:textColorPrimary">#DD000000</item>
<item name="android:textColorSecondary">#8A000000</item>
<item name="android:textColorHint">#42000000</item>
<item name="android:textColorPrimary">@color/dashboard_black</item>
<item name="android:textColorSecondary">@color/icon_color</item>
</style>
</resources>

View file

@ -140,7 +140,12 @@ public class DownloadActivity extends ActionBarProgressActivity implements Downl
filter = intent.getExtras().getString(FILTER_KEY);
filterCat = intent.getExtras().getString(FILTER_CAT);
}
// new DataStoragePlaceDialogFragment().show(getFragmentManager(), null);
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(null);
final boolean externalExists =
DataStoragePlaceDialogFragment.getExternalStorageDirectory(this) != null;
if (firstTime && externalExists) {
new DataStoragePlaceDialogFragment().show(getFragmentManager(), null);
}
}
public DownloadIndexesThread getDownloadThread() {

View file

@ -4,11 +4,8 @@ import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.app.Fragment;
import android.support.annotation.AnyRes;
import android.support.annotation.ColorInt;
import android.os.StatFs;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.view.Gravity;
@ -17,46 +14,154 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.DownloadActivity;
import java.io.File;
public class DataStoragePlaceDialogFragment extends DialogFragment {
public DataStoragePlaceDialogFragment() {
// Required empty public constructor
}
private File internalStorage;
private File externalStorage;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity(), R.style.BottomSheet_Dialog);
Window window = dialog.getWindow();
window.setGravity(Gravity.CENTER);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onStart() {
super.onStart();
final Window window = getDialog().getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.BOTTOM;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
window.setAttributes(params);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
internalStorage = getInternalStorageDirectory(getActivity());
externalStorage = getExternalStorageDirectory(getActivity());
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
false);
((ImageView) view.findViewById(R.id.folderIconImageView))
.setImageDrawable(getIcon(R.drawable.ic_action_folder, R.color.map_widget_blue));
ImageView internalStorageImageView = (ImageView) view.findViewById(R.id.deviceMemoryImageView);
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);
internalStorageDescription.setOnClickListener(internalMemoryOnClickListener);
internalStorageDescription.setText(getFreeSpace(internalStorage));
ImageView externalStorageImageView = ((ImageView) view.findViewById(R.id.memoryStickImageView));
externalStorageImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
externalStorageImageView.setOnClickListener(externalMemoryOnClickListener);
View externalStorageTitle = view.findViewById(R.id.memoryStickTitle);
externalStorageTitle.setOnClickListener(externalMemoryOnClickListener);
TextView externalStorageDescription = (TextView) view.findViewById(R.id.memoryStickDescription);
externalStorageDescription.setOnClickListener(externalMemoryOnClickListener);
externalStorageDescription.setText(getFreeSpace(externalStorage));
final ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
closeImageButton.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark));
closeImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return view;
}
public OsmandApplication getMyApplication() {
public static File getExternalStorageDirectory(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings()
.getExternalStorageDirectory();
}
public static File getInternalStorageDirectory(Activity activity) {
return ((OsmandApplication) activity.getApplication()).getSettings()
.getDefaultInternalStorage();
}
private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
public Drawable getContentIcon(@DrawableRes int drawableRes) {
private Drawable getContentIcon(@DrawableRes int drawableRes) {
return getMyApplication().getIconsCache().getContentIcon(drawableRes);
}
public Drawable getIcon(@DrawableRes int drawableRes, @ColorRes int color) {
private Drawable getIcon(@DrawableRes int drawableRes, @ColorRes int color) {
return getMyApplication().getIconsCache().getIcon(drawableRes, color);
}
private String getFreeSpace(File dir) {
String sz = "";
if (dir.canRead()) {
StatFs fs = new StatFs(dir.getAbsolutePath());
int size = fs.getAvailableBlocks() * fs.getBlockSize();
if (size > 0) {
if (size > 1 << 20) {
sz = DownloadActivity.formatGb.format(new Object[]{(float) size / (1 << 20)});
} else {
sz = DownloadActivity.formatMb.format(new Object[]{(float) size / (1 << 10)});
}
}
}
return sz;
}
private View.OnClickListener internalMemoryOnClickListener =
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT,
internalStorage, getActivity());
dismiss();
}
};
private View.OnClickListener externalMemoryOnClickListener =
new View.OnClickListener() {
@Override
public void onClick(View v) {
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE,
externalStorage, getActivity());
dismiss();
}
};
public static void saveFilesLocation(int type, File selectedFile, Activity context) {
boolean wr = OsmandSettings.isWritable(selectedFile);
if (wr) {
((OsmandApplication) context.getApplication())
.setExternalStorageDirectory(type, selectedFile.getAbsolutePath());
} else {
AccessibleToast.makeText(context, R.string.specified_directiory_not_writeable,
Toast.LENGTH_LONG).show();
}
}
}

View file

@ -956,7 +956,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
} else {
sz = DownloadActivity.formatMb.format(new Object[]{(float) size / (1 << 10)});
}
}
sizeView.setText(sz);
sizeView.setVisibility(View.VISIBLE);