This commit is contained in:
Nazar 2019-10-04 16:38:20 +03:00
parent df350e43ba
commit 17d0fcf062
10 changed files with 164 additions and 314 deletions

View file

@ -6,12 +6,17 @@
android:layout_height="wrap_content"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/button_container"
android:layout_width="match_parent"
<FrameLayout
android:id="@+id/secondary_btn_container"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_half"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/button_container"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:orientation="horizontal">
@ -22,8 +27,8 @@
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:visibility="visible"
android:src="@drawable/ic_action_folder" />
android:src="@drawable/ic_action_folder"
android:visibility="visible" />
<FrameLayout
android:layout_width="match_parent"
@ -48,3 +53,5 @@
</LinearLayout>
</FrameLayout>
</FrameLayout>

View file

@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_weight="1">
android:layout_weight="1"
android:orientation="vertical">
<FrameLayout
android:id="@+id/secondary_btn_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/button_container"
@ -17,13 +22,15 @@
android:id="@+id/button_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:gravity="center"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Button" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/edit_text_otfb"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
app:labelText="@string/enter_path_to_folder"
app:primaryColor="?android:textColorPrimary"
app:secondaryColor="?android:textColorSecondary">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:maxLines="1"
tools:text="Some text"/>
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
</FrameLayout>

View file

@ -11,7 +11,8 @@
Thx - Hardy
-->
<string name="shared_string_used">Used</string>
<string name="description_used_gb">Used %1$s GB</string>
<string name="used_and_total_space_description">%1$s / %2$s GB</string>
<string name="shared_string_by_default">By default</string>
<string name="enter_path_to_folder">Enter path to the folder</string>
<string name="shared_string_select_folder">Select folder</string>

View file

@ -324,51 +324,25 @@ public class UiUtilities {
}
public static void setupDialogButton(boolean nightMode, View buttonView, DialogButtonType buttonType, CharSequence buttonText) {
Context ctx = buttonView.getContext();
TextViewEx buttonTextView = (TextViewEx) buttonView.findViewById(R.id.button_text);
boolean v21 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
View buttonContainer = buttonView.findViewById(R.id.button_container);
switch (buttonType) {
case PRIMARY:
if (v21) {
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark);
}
AndroidUtils.setBackground(ctx, buttonView, nightMode, R.drawable.dlg_btn_primary_light, R.drawable.dlg_btn_primary_dark);
buttonTextView.setTextColor(ContextCompat.getColorStateList(ctx, nightMode ? R.color.dlg_btn_primary_text_dark : R.color.dlg_btn_primary_text_light));
break;
case SECONDARY:
if (v21) {
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark);
}
AndroidUtils.setBackground(ctx, buttonView, nightMode, R.drawable.dlg_btn_secondary_light, R.drawable.dlg_btn_secondary_dark);
buttonTextView.setTextColor(ContextCompat.getColorStateList(ctx, nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light));
break;
case STROKED:
if (v21) {
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
}
AndroidUtils.setBackground(ctx, buttonView, nightMode, R.drawable.dlg_btn_stroked_light, R.drawable.dlg_btn_stroked_dark);
buttonTextView.setTextColor(ContextCompat.getColorStateList(ctx, nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light));
break;
}
buttonTextView.setText(buttonText);
buttonTextView.setEnabled(buttonView.isEnabled());
setupDialogButton(nightMode, buttonView, buttonType, buttonText, -1);
}
public void setupDialogButtonWithIcon(boolean nightMode, View buttonView, DialogButtonType buttonType, CharSequence buttonText, int iconResId) {
public static void setupDialogButton(boolean nightMode, View buttonView, DialogButtonType buttonType, CharSequence buttonText, int iconResId) {
Context ctx = buttonView.getContext();
TextViewEx buttonTextView = (TextViewEx) buttonView.findViewById(R.id.button_text);
ImageView img = buttonView.findViewById(R.id.button_icon);
int iconAndTextNormalColor = -1;
int iconAndTextPressedColor = -1;
boolean v21 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
View buttonContainer = buttonView.findViewById(R.id.button_container);
View secondaryBtnContainer = buttonView.findViewById(R.id.secondary_btn_container);
int iconAndTextNormalColor = -1;
int iconAndTextPressedColor = -1;
switch (buttonType) {
case PRIMARY:
if (v21) {
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark);
}
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.dlg_btn_primary_light, R.drawable.dlg_btn_primary_dark);
AndroidUtils.setBackground(ctx, secondaryBtnContainer, nightMode, R.drawable.dlg_btn_primary_light, R.drawable.dlg_btn_primary_dark);
iconAndTextNormalColor = nightMode ? R.color.dlg_btn_primary_text_dark : R.color.dlg_btn_primary_text_light;
iconAndTextPressedColor = iconAndTextNormalColor;
break;
@ -376,7 +350,7 @@ public class UiUtilities {
if (v21) {
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_solid_light, R.drawable.ripple_solid_dark);
}
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.dlg_btn_secondary_light, R.drawable.dlg_btn_secondary_dark);
AndroidUtils.setBackground(ctx, secondaryBtnContainer, nightMode, R.drawable.dlg_btn_secondary_light, R.drawable.dlg_btn_secondary_dark);
iconAndTextNormalColor = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light;
iconAndTextPressedColor = nightMode ? R.color.dlg_btn_primary_text_dark : R.color.dlg_btn_primary_text_light;
break;
@ -384,17 +358,20 @@ public class UiUtilities {
if (v21) {
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
}
AndroidUtils.setBackground(ctx, buttonContainer, nightMode, R.drawable.dlg_btn_stroked_light, R.drawable.dlg_btn_stroked_dark);
AndroidUtils.setBackground(ctx, secondaryBtnContainer, nightMode, R.drawable.dlg_btn_stroked_light, R.drawable.dlg_btn_stroked_dark);
iconAndTextNormalColor = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light;
iconAndTextPressedColor = nightMode ? R.color.dlg_btn_primary_text_dark : R.color.dlg_btn_primary_text_light;
break;
}
img.setImageDrawable(AndroidUtils.createPressedStateListDrawable(getDrawable(iconResId, iconAndTextNormalColor),
getDrawable(iconResId, iconAndTextPressedColor)));
buttonTextView.setText(buttonText);
buttonTextView.setTextColor(ContextCompat.getColorStateList(ctx, iconAndTextNormalColor));
buttonTextView.setEnabled(buttonView.isEnabled());
if (iconResId != -1) {
Drawable iconNormal = tintDrawable(ContextCompat.getDrawable(ctx, iconResId), ContextCompat.getColor(ctx, iconAndTextNormalColor));
Drawable iconPressed = tintDrawable(ContextCompat.getDrawable(ctx, iconResId), ContextCompat.getColor(ctx, iconAndTextPressedColor));
ImageView img = buttonView.findViewById(R.id.button_icon);
img.setImageDrawable(AndroidUtils.createPressedStateListDrawable(iconNormal, iconPressed));
}
}
public static Context getThemedContext(Context context, boolean nightMode) {

View file

@ -13,15 +13,12 @@ import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -31,7 +28,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.settings.bottomsheets.ChangeDataStorageBottomSheet;
import net.osmand.plus.settings.bottomsheets.SelectFolderBottomSheet;
@ -41,6 +38,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -65,7 +63,7 @@ public class DataStorageFragment extends BaseSettingsFragment {
private DataStorageItemsHolder itemsHolder;
private OsmandApplication app;
private Activity activity;
private OsmandActionBarActivity activity;
private OsmandSettings settings;
@Override
@ -254,7 +252,7 @@ public class DataStorageFragment extends BaseSettingsFragment {
File fromDirectory = new File(currentStorage.getDirectory());
File toDirectory = new File(newStorage.getDirectory());
@SuppressLint("StaticFieldLeak")
DashChooseAppDirFragment.MoveFilesToDifferentDirectory task = new DashChooseAppDirFragment.MoveFilesToDifferentDirectory(activity, fromDirectory, toDirectory) {
MoveFilesToDifferentDirectory task = new MoveFilesToDifferentDirectory(activity, fromDirectory, toDirectory) {
private MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
@ -273,26 +271,30 @@ public class DataStorageFragment extends BaseSettingsFragment {
private void showResultsDialog() {
StringBuilder sb = new StringBuilder();
Context ctx = activity.get();
if (ctx == null) {
return;
}
int moved = getMovedCount();
int copied = getCopiedCount();
int failed = getFailedCount();
sb.append(activity.getString(R.string.files_moved, moved, getFormattedSize(getMovedSize()))).append("\n");
sb.append(ctx.getString(R.string.files_moved, moved, getFormattedSize(getMovedSize()))).append("\n");
if (copied > 0) {
sb.append(activity.getString(R.string.files_copied, copied, getFormattedSize(getCopiedSize()))).append("\n");
sb.append(ctx.getString(R.string.files_copied, copied, getFormattedSize(getCopiedSize()))).append("\n");
}
if (failed > 0) {
sb.append(activity.getString(R.string.files_failed, failed, getFormattedSize(getFailedSize()))).append("\n");
sb.append(ctx.getString(R.string.files_failed, failed, getFormattedSize(getFailedSize()))).append("\n");
}
if (copied > 0 || failed > 0) {
int count = copied + failed;
sb.append(activity.getString(R.string.files_present, count, getFormattedSize(getCopiedSize() + getFailedSize()), newStorage.getDirectory()));
sb.append(ctx.getString(R.string.files_present, count, getFormattedSize(getCopiedSize() + getFailedSize()), newStorage.getDirectory()));
}
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
AlertDialog.Builder bld = new AlertDialog.Builder(ctx);
bld.setMessage(sb.toString());
bld.setPositiveButton(R.string.shared_string_restart, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
confirm(app, (AppCompatActivity) activity, newStorage, true);
confirm(app, activity.get(), newStorage, true);
}
});
bld.show();
@ -301,17 +303,22 @@ public class DataStorageFragment extends BaseSettingsFragment {
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
OsmandActionBarActivity a = this.activity.get();
if (a == null) {
return;
}
OsmandApplication app = a.getMyApplication();
if (result) {
app.getResourceManager().resetStoreDirectory();
// immediately proceed with change (to not loose where maps are currently located)
if (getCopiedCount() > 0 || getFailedCount() > 0) {
showResultsDialog();
} else {
confirm(app, (AppCompatActivity) activity, newStorage, false);
confirm(app, a, newStorage, false);
}
} else {
showResultsDialog();
Toast.makeText(activity, R.string.copying_osmand_file_failed,
Toast.makeText(a, R.string.copying_osmand_file_failed,
Toast.LENGTH_SHORT).show();
}
@ -362,12 +369,13 @@ public class DataStorageFragment extends BaseSettingsFragment {
}
protected void reloadData() {
new DashChooseAppDirFragment.ReloadData(activity, getMyApplication()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
new ReloadData(activity, getMyApplication()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
public static class MoveFilesToDifferentDirectory extends AsyncTask<Void, Void, Boolean> {
private Context ctx;
protected WeakReference<OsmandActionBarActivity> activity;
private WeakReference<Context> context;
private File from;
private File to;
protected ProgressImplementation progress;
@ -379,8 +387,9 @@ public class DataStorageFragment extends BaseSettingsFragment {
private int failedCount;
private long failedSize;
public MoveFilesToDifferentDirectory(Context ctx, File from, File to) {
this.ctx = ctx;
public MoveFilesToDifferentDirectory(OsmandActionBarActivity activity, File from, File to) {
this.activity = new WeakReference<>(activity);
this.context = new WeakReference<>((Context) activity);
this.from = from;
this.to = to;
}
@ -415,6 +424,10 @@ public class DataStorageFragment extends BaseSettingsFragment {
@Override
protected void onPreExecute() {
Context ctx = context.get();
if (context == null) {
return;
}
movedCount = 0;
copiedCount = 0;
failedCount = 0;
@ -427,6 +440,10 @@ public class DataStorageFragment extends BaseSettingsFragment {
@Override
protected void onPostExecute(Boolean result) {
if (result != null) {
Context ctx = context.get();
if (ctx == null) {
return;
}
if (result.booleanValue() && runOnSuccess != null) {
runOnSuccess.run();
} else if (!result.booleanValue()) {
@ -443,6 +460,10 @@ public class DataStorageFragment extends BaseSettingsFragment {
}
private void movingFiles(File f, File t, int depth) throws IOException {
Context ctx = context.get();
if (ctx == null) {
return;
}
if (depth <= 2) {
progress.startTask(ctx.getString(R.string.copying_osmand_one_file_descr, t.getName()), -1);
}
@ -506,19 +527,23 @@ public class DataStorageFragment extends BaseSettingsFragment {
}
public static class ReloadData extends AsyncTask<Void, Void, Boolean> {
private Context ctx;
private WeakReference<Context> ctx;
protected ProgressImplementation progress;
private OsmandApplication app;
public ReloadData(Context ctx, OsmandApplication app) {
this.ctx = ctx;
this.ctx = new WeakReference<>(ctx);
this.app = app;
}
@Override
protected void onPreExecute() {
progress = ProgressImplementation.createProgressDialog(ctx, ctx.getString(R.string.loading_data),
ctx.getString(R.string.loading_data), ProgressDialog.STYLE_HORIZONTAL);
Context c = ctx.get();
if (c == null) {
return;
}
progress = ProgressImplementation.createProgressDialog(c, c.getString(R.string.loading_data),
c.getString(R.string.loading_data), ProgressDialog.STYLE_HORIZONTAL);
}
@Override

View file

@ -61,6 +61,8 @@ public class DataStorageItemsHolder {
File dir;
int iconId;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//internal storage
path = settings.getInternalAppPath().getAbsolutePath();
dir = new File(path);
@ -90,7 +92,6 @@ public class DataStorageItemsHolder {
.build();
addItem(sharedStorageItem);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//external storage
File[] externals = app.getExternalFilesDirs(null);
if (externals != null) {

View file

@ -146,10 +146,8 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
DecimalFormat formatter = new DecimalFormat("#.##");
String summary = currentStorage.getTitle() +
" \u2022 " +
getString(R.string.shared_string_used) +
" " +
formatter.format(AndroidUtils.getUsedSpaceGb(dir)) +
" Gb";
String.format(getString(R.string.description_used_gb),
formatter.format(AndroidUtils.getUsedSpaceGb(dir)));
externalStorageDir.setSummary(summary);
}

View file

@ -95,7 +95,8 @@ public class ChangeDataStorageBottomSheet extends BasePreferenceBottomSheet {
//buttons
View btnDontMoveView = View.inflate(ctx, R.layout.bottom_sheet_big_dialog_button_with_icon, null);
requiredMyApplication().getUIUtilities().setupDialogButtonWithIcon(nightMode, btnDontMoveView, UiUtilities.DialogButtonType.SECONDARY, getString(R.string.dont_move_maps), currentDirectory.getIconResId());
UiUtilities.setupDialogButton(nightMode, btnDontMoveView, UiUtilities.DialogButtonType.SECONDARY,
getString(R.string.dont_move_maps), currentDirectory.getIconResId());
BaseBottomSheetItem btnDontMove = new BaseBottomSheetItem.Builder()
.setCustomView(btnDontMoveView)
.setOnClickListener(new View.OnClickListener() {
@ -108,7 +109,8 @@ public class ChangeDataStorageBottomSheet extends BasePreferenceBottomSheet {
items.add(btnDontMove);
View btnMoveView = View.inflate(ctx, R.layout.bottom_sheet_big_dialog_button_with_icon, null);
requiredMyApplication().getUIUtilities().setupDialogButtonWithIcon(nightMode, btnMoveView, UiUtilities.DialogButtonType.PRIMARY, getString(R.string.move_maps_to_new_destination), R.drawable.ic_action_folder_move);
UiUtilities.setupDialogButton(nightMode, btnMoveView, UiUtilities.DialogButtonType.PRIMARY,
getString(R.string.move_maps_to_new_destination), R.drawable.ic_action_folder_move);
BaseBottomSheetItem btnMove = new BaseBottomSheetItem.Builder()
.setCustomView(btnMoveView)
.setOnClickListener(new View.OnClickListener() {
@ -121,7 +123,8 @@ public class ChangeDataStorageBottomSheet extends BasePreferenceBottomSheet {
items.add(btnMove);
View btnCloseView = View.inflate(ctx, R.layout.bottom_sheet_big_dialog_button_with_icon, null);
requiredMyApplication().getUIUtilities().setupDialogButtonWithIcon(nightMode, btnCloseView, UiUtilities.DialogButtonType.SECONDARY, getString(R.string.shared_string_cancel), R.drawable.ic_action_undo_dark);
UiUtilities.setupDialogButton(nightMode, btnCloseView, UiUtilities.DialogButtonType.SECONDARY,
getString(R.string.shared_string_cancel), R.drawable.ic_action_undo_dark);
BaseBottomSheetItem btnClose = new BaseBottomSheetItem.Builder()
.setCustomView(btnCloseView)
.setOnClickListener(new View.OnClickListener() {

View file

@ -147,46 +147,6 @@ public class SelectFolderBottomSheet extends BasePreferenceBottomSheet {
}
}
/*@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void openDocumentTree() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
if (currentPath != null) {
Uri uri = Uri.fromFile(new File(currentPath));
}
startActivityForResult(intent, CHOOSE_FOLDER_REQUEST_CODE);
}*/
/*@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
Uri result = data.getData();
if (result == null) {
return;
}
if (requestCode == CHOOSE_FOLDER_REQUEST_CODE) {
DocumentFile documentFile = DocumentFile.fromTreeUri(getContext(), result);
File f = null;
try {
f = FileUtil.from(getContext(), documentFile.getUri());
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getMyApplication(), f.getAbsolutePath(), Toast.LENGTH_LONG).show();
for (DocumentFile file : documentFile.listFiles()) {
if (file.isDirectory()) {
Toast.makeText(getMyApplication(), file.getName(), Toast.LENGTH_SHORT).show();
etWasFocused = true;
editText.setText(file.getName());
break;
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}*/
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_close;
@ -241,104 +201,4 @@ public class SelectFolderBottomSheet extends BasePreferenceBottomSheet {
this.btnTitle = btnTitle;
}
/*private static class FileUtil {
private static final int EOF = -1;
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
private FileUtil() {
}
public static File from(Context context, Uri uri) throws IOException {
InputStream inputStream = context.getContentResolver().openInputStream(uri);
String fileName = getFileName(context, uri);
String[] splitName = splitFileName(fileName);
File tempFile = File.createTempFile(splitName[0], splitName[1]);
tempFile = rename(tempFile, fileName);
tempFile.deleteOnExit();
FileOutputStream out = null;
try {
out = new FileOutputStream(tempFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (inputStream != null) {
copy(inputStream, out);
inputStream.close();
}
if (out != null) {
out.close();
}
return tempFile;
}
private static String[] splitFileName(String fileName) {
String name = fileName;
String extension = "";
int i = fileName.lastIndexOf(".");
if (i != -1) {
name = fileName.substring(0, i);
extension = fileName.substring(i);
}
return new String[]{name, extension};
}
private static String getFileName(Context context, Uri uri) {
String result = null;
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
int cut = result.lastIndexOf(File.separator);
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}
private static File rename(File file, String newName) {
File newFile = new File(file.getParent(), newName);
if (!newFile.equals(file)) {
if (newFile.exists() && newFile.delete()) {
// Log.d("FileUtil", "Delete old " + newName + " file");
}
if (file.renameTo(newFile)) {
// Log.d("FileUtil", "Rename file to " + newName);
}
}
return newFile;
}
private static long copy(InputStream input, OutputStream output) throws IOException {
long count = 0;
int n;
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
}*/
}