Space left card on WorldItemsFragment
This commit is contained in:
parent
549ec0a4da
commit
f469467ace
8 changed files with 88 additions and 93 deletions
|
@ -27,7 +27,7 @@
|
|||
android:text="@string/device_memory"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/memory_size"
|
||||
android:id="@+id/sizeFreeTextView"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -36,7 +36,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/memory_progress"
|
||||
android:id="@+id/memoryLeftProgressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:progressDrawable="?attr/size_progress_bar"
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/ctx_menu_info_view_bg_dark"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/free_version_banner"/>
|
||||
|
||||
<LinearLayout
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?attr/bg_card"
|
||||
android:padding="10dp"
|
||||
android:id="@+id/downloadProgressLayout">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/leftTextView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
tools:text="@string/device_memory"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rightTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
tools:text="@string/free"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="20dp"
|
||||
android:progressDrawable="?attr/size_progress_bar"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="World regions"/>
|
||||
|
||||
</LinearLayout>
|
46
OsmAnd/res/layout/used_space_card.xml
Normal file
46
OsmAnd/res/layout/used_space_card.xml
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/downloadProgressLayout"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?attr/bg_card"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp"
|
||||
tools:showIn="@layout/local_index_fragment_header">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/device_memory"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sizeFreeTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
tools:text="@string/free"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/memoryLeftProgressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="20dp"
|
||||
android:progress="40"
|
||||
android:progressDrawable="?attr/size_progress_bar"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ public abstract class OsmandExpandableListFragment extends Fragment
|
|||
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication)getActivity().getApplication();
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,11 +8,13 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.StatFs;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.BaseAdapter;
|
||||
|
@ -22,7 +24,6 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -42,10 +43,12 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip;
|
|||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -66,6 +69,8 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
public static final String DOWNLOAD_TAB = "download";
|
||||
public static final String UPDATES_TAB = "updates";
|
||||
public static final String SINGLE_TAB = "SINGLE_TAB";
|
||||
public static final MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
|
||||
|
||||
private List<DownloadActivityType> downloadTypes = new ArrayList<DownloadActivityType>();
|
||||
private BannerAndDownloadFreeVersion visibleBanner;
|
||||
private ActiveDownloadsDialogFragment.DownloadEntryAdapter progressAdapter;
|
||||
|
@ -675,4 +680,28 @@ public class DownloadActivity extends BaseDownloadActivity implements DialogDism
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void updateDescriptionTextWithSize(View view){
|
||||
TextView descriptionText = (TextView) view.findViewById(R.id.sizeFreeTextView);
|
||||
ProgressBar sizeProgress = (ProgressBar) view.findViewById(R.id.memoryLeftProgressBar);
|
||||
|
||||
File dir = getMyApplication().getAppPath("").getParentFile();
|
||||
String size = formatGb.format(new Object[]{0});
|
||||
int percent = 0;
|
||||
if(dir.canRead()){
|
||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
|
||||
percent = 100 - (int) (fs.getAvailableBlocks() * 100 / fs.getBlockCount());
|
||||
}
|
||||
sizeProgress.setProgress(percent);
|
||||
String text = getString(R.string.free, size);
|
||||
int l = text.indexOf('.');
|
||||
if(l == -1) {
|
||||
l = text.length();
|
||||
}
|
||||
descriptionText.setText(text);
|
||||
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,13 +85,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
|||
protected static int RESTORE_OPERATION = 3;
|
||||
|
||||
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
||||
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
|
||||
private ContextMenuAdapter optionsMenuAdapter;
|
||||
private ActionMode actionMode;
|
||||
|
||||
private TextView descriptionText;
|
||||
private ProgressBar sizeProgress;
|
||||
|
||||
Drawable backup;
|
||||
Drawable sdcard;
|
||||
Drawable planet;
|
||||
|
@ -107,9 +103,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
|||
listView.setAdapter(listAdapter);
|
||||
expandAllGroups();
|
||||
setListView(listView);
|
||||
descriptionText = (TextView) view.findViewById(R.id.memory_size);
|
||||
sizeProgress = (ProgressBar) view.findViewById(R.id.memory_progress);
|
||||
updateDescriptionTextWithSize();
|
||||
((DownloadActivity) getActivity()).updateDescriptionTextWithSize(view);
|
||||
colorDrawables();
|
||||
return view;
|
||||
}
|
||||
|
@ -655,8 +649,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
selectionMode = false;
|
||||
descriptionText.setVisibility(View.VISIBLE);
|
||||
updateDescriptionTextWithSize();
|
||||
((DownloadActivity) getActivity()).updateDescriptionTextWithSize(getView());
|
||||
listAdapter.cancelFilter();
|
||||
expandAllGroups();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
@ -667,26 +660,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
|||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateDescriptionTextWithSize(){
|
||||
File dir = getMyApplication().getAppPath("").getParentFile();
|
||||
String size = formatGb.format(new Object[]{0});
|
||||
int percent = 0;
|
||||
if(dir.canRead()){
|
||||
StatFs fs = new StatFs(dir.getAbsolutePath());
|
||||
size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) });
|
||||
percent = 100 - (int) (fs.getAvailableBlocks() * 100 / fs.getBlockCount());
|
||||
}
|
||||
sizeProgress.setProgress(percent);
|
||||
String text = getString(R.string.free, size);
|
||||
int l = text.indexOf('.');
|
||||
if(l == -1) {
|
||||
l = text.length();
|
||||
}
|
||||
descriptionText.setText(text);
|
||||
descriptionText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public void localOptionsMenu(final int itemId) {
|
||||
if (itemId == R.string.local_index_mi_reload) {
|
||||
reloadIndexes();
|
||||
|
@ -1061,7 +1034,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
|
|||
String sz = "";
|
||||
if (size > 0) {
|
||||
if (size > 1 << 20) {
|
||||
sz = formatGb.format(new Object[] { (float) size / (1 << 20) });
|
||||
sz = DownloadActivity.formatGb.format(new Object[] { (float) size / (1 << 20) });
|
||||
} else {
|
||||
sz = formatMb.format(new Object[] { (float) size / (1 << 10) });
|
||||
}
|
||||
|
|
|
@ -71,7 +71,8 @@ public class UpdatesIndexFragment extends OsmAndListFragment {
|
|||
listAdapter.sort(new Comparator<IndexItem>() {
|
||||
@Override
|
||||
public int compare(IndexItem indexItem, IndexItem indexItem2) {
|
||||
return indexItem.getVisibleName(getMyApplication(), osmandRegions).compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions));
|
||||
return indexItem.getVisibleName(getMyApplication(), osmandRegions)
|
||||
.compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions));
|
||||
}
|
||||
});
|
||||
setListAdapter(listAdapter);
|
||||
|
|
|
@ -71,6 +71,10 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
|
|||
expandAllGroups();
|
||||
setListView(listView);
|
||||
|
||||
View usedSpaceCard = inflater.inflate(R.layout.used_space_card, listView, false);
|
||||
getMyActivity().updateDescriptionTextWithSize(usedSpaceCard);
|
||||
listView.addHeaderView(usedSpaceCard);
|
||||
|
||||
onCategorizationFinished();
|
||||
|
||||
return view;
|
||||
|
|
Loading…
Reference in a new issue