Skip to content

Commit

Permalink
#544 minor ui updates for the sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
spyhunter99 committed Jan 27, 2017
1 parent 9871fac commit 4c113e2
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.osmdroid.R;
import org.osmdroid.debug.model.SqlTileWriterExt;
import org.osmdroid.debug.util.FileDateUtil;
import org.osmdroid.intro.StorageAdapter;
import org.osmdroid.tileprovider.util.StorageUtils;

/**
* A simple view for browsing the osmdroid tile cache database
Expand Down Expand Up @@ -39,7 +41,7 @@ public void onResume() {
lv.setAdapter(adapter);

((TextView) findViewById(R.id.rows)).setText(cache.getRowCount(null) + "");
((TextView) findViewById(R.id.size)).setText(FileDateUtil.readableFileSize(MainActivity.updateStoragePrefreneces(this)));
((TextView) findViewById(R.id.size)).setText(StorageAdapter.readableFileSize(MainActivity.updateStoragePrefreneces(this)));
((TextView) findViewById(R.id.date)).setText("Now " + FileDateUtil.getModifiedDate(System.currentTimeMillis()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@

public class FileDateUtil {

public static String readableFileSize(long size) {
if (size <= 0) return "0";
final String[] units = new String[]{"B", "kB", "MB", "GB", "TB"};
int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}

public static String getModifiedDate(long modified) {
public static String getModifiedDate(long modified) {
return getModifiedDate(Locale.getDefault(), modified);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
Expand All @@ -18,12 +19,15 @@

import org.osmdroid.R;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.modules.SqlTileWriter;
import org.osmdroid.tileprovider.util.StorageUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static org.osmdroid.intro.StorageAdapter.readableFileSize;

/**
* created on 1/5/2017.
*
Expand All @@ -33,7 +37,11 @@
public class StoragePreferenceFragment extends Fragment implements View.OnClickListener {
Button buttonSetCache,
buttonManualCacheEntry;
TextView textViewCacheDirectory;
TextView textViewCacheDirectory,
textViewCacheMaxSize,
textViewCacheFreeSpace,
textViewCacheCurrentSize,
textViewCacheTrimSize;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -52,9 +60,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
buttonManualCacheEntry = (Button) v.findViewById(R.id.buttonManualCacheEntry);
buttonSetCache.setOnClickListener(this);
buttonManualCacheEntry.setOnClickListener(this);


textViewCacheDirectory.setText(Configuration.getInstance().getOsmdroidTileCache().toString());
textViewCacheMaxSize = (TextView) v.findViewById(R.id.textViewCacheMaxSize);
textViewCacheFreeSpace = (TextView) v.findViewById(R.id.textViewCacheFreeSpace);
textViewCacheCurrentSize = (TextView) v.findViewById(R.id.textViewCacheCurrentSize);
textViewCacheTrimSize = (TextView) v.findViewById(R.id.textViewCacheTrimSize);
return v;
}

Expand All @@ -63,6 +73,19 @@ public void onResume() {
super.onResume();
updateStorage(getContext());
textViewCacheDirectory.setText(Configuration.getInstance().getOsmdroidTileCache().toString());

textViewCacheMaxSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheMaxBytes()));
textViewCacheTrimSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheTrimBytes()));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
textViewCacheFreeSpace.setText(readableFileSize(Configuration.getInstance().getOsmdroidTileCache().getFreeSpace()));
} else textViewCacheFreeSpace.setText("");
File dbFile = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + SqlTileWriter.DATABASE_FILENAME);
if (Build.VERSION.SDK_INT >= 9 && dbFile.exists()) {
textViewCacheCurrentSize.setText(readableFileSize(dbFile.length()));
} else textViewCacheCurrentSize.setText("");


}

public void updateStorage(Context ctx) {
Expand Down Expand Up @@ -106,7 +129,7 @@ private void showPickCacheFromList() {
try {
File f = new File("/data/data/" + getActivity().getPackageName() + "/osmdroid/");
f.mkdirs();
StorageUtils.StorageInfo privateStorage=new StorageUtils.StorageInfo(f.getAbsolutePath(), true, false, 0);
StorageUtils.StorageInfo privateStorage = new StorageUtils.StorageInfo(f.getAbsolutePath(), true, false, 0);
privateStorage.setDisplayName("Application Private Storage");
storageListFiltered.add(privateStorage);
} catch (Exception ex) {
Expand Down Expand Up @@ -153,6 +176,18 @@ public void onClick(DialogInterface dialog, int which) {
textViewCacheDirectory.setText(item.path + File.separator + "osmdroid" + File.separator + "tiles");
Configuration.getInstance().setOsmdroidTileCache(new File(textViewCacheDirectory.getText() + ""));
Configuration.getInstance().save(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext()));

textViewCacheMaxSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheMaxBytes()));
textViewCacheTrimSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheTrimBytes()));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
textViewCacheFreeSpace.setText(readableFileSize(Configuration.getInstance().getOsmdroidTileCache().getFreeSpace()));
} else textViewCacheFreeSpace.setText("");
File dbFile = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + SqlTileWriter.DATABASE_FILENAME);
if (Build.VERSION.SDK_INT >= 9 && dbFile.exists()) {
textViewCacheCurrentSize.setText(readableFileSize(dbFile.length()));
} else textViewCacheCurrentSize.setText("");

}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -210,6 +245,18 @@ public void afterTextChanged(Editable s) {
public void onClick(DialogInterface dialog, int which) {
if (input.getError() == null) {
textViewCacheDirectory.setText(input.getText().toString());

textViewCacheMaxSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheMaxBytes()));
textViewCacheTrimSize.setText(readableFileSize(Configuration.getInstance().getTileFileSystemCacheTrimBytes()));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
textViewCacheFreeSpace.setText(readableFileSize(Configuration.getInstance().getOsmdroidTileCache().getFreeSpace()));
} else textViewCacheFreeSpace.setText("");
File dbFile = new File(Configuration.getInstance().getOsmdroidTileCache().getAbsolutePath() + File.separator + SqlTileWriter.DATABASE_FILENAME);
if (Build.VERSION.SDK_INT >= 9 && dbFile.exists()) {
textViewCacheCurrentSize.setText(readableFileSize(dbFile.length()));
} else textViewCacheCurrentSize.setText("");

}
}
});
Expand Down
166 changes: 125 additions & 41 deletions OpenStreetMapViewer/src/main/res/layout/intro_storage.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,136 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="18dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
android:layout_height="match_parent">
android:orientation="vertical"
android:padding="18dp">

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cache_storage"
android:textSize="22dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/introalmostthere"
android:textSize="14dp"/>

<TextView
android:paddingTop="22dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/current_location"
/>
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cache_storage"
android:textSize="22dp"/>

android:id="@+id/textViewCacheDirectory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PLACEHOLDER"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/introalmostthere"
android:textSize="14dp"/>

<Button
android:layout_marginTop="22dp"
android:id="@+id/buttonSetCache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pick_cache_location"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:layout_marginTop="22dp"
android:id="@+id/buttonManualCacheEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enter_cache_location"/>
<TextView
android:paddingTop="22dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Current Cache Size"
/>

<TextView
android:paddingLeft="5dp"
android:id="@+id/textViewCacheCurrentSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PLACEHOLDER"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:text="Cache Trim Size"
/>

<TextView
android:paddingLeft="5dp"
android:id="@+id/textViewCacheTrimSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PLACEHOLDER"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cache Max Size"
/>

<TextView

android:id="@+id/textViewCacheMaxSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="PLACEHOLDER"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Storage Free Space"
/>

<TextView
android:paddingLeft="5dp"
android:id="@+id/textViewCacheFreeSpace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PLACEHOLDER"/>
</LinearLayout>


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="22dp"
android:text="@string/current_location"
/>

<TextView

android:id="@+id/textViewCacheDirectory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PLACEHOLDER"/>


<Button
android:id="@+id/buttonSetCache"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:text="@string/pick_cache_location"/>

<Button
android:id="@+id/buttonManualCacheEntry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:text="@string/enter_cache_location"/>
</LinearLayout>
</ScrollView>

0 comments on commit 4c113e2

Please sign in to comment.