use of org.mapsforge.map.layer.cache.TileCache in project satstat by mvglasow.
the class SettingsActivity method onPreferenceClick.
/**
* @author k9mail, mvglasow
*/
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference == prefMapPath) {
boolean success = false;
int i = 0;
do {
String intentAction = PICK_DIRECTORY_INTENTS[i][0];
String uriPrefix = PICK_DIRECTORY_INTENTS[i][1];
Intent intent = new Intent(intentAction);
if (uriPrefix != null)
intent.setData(Uri.parse(uriPrefix + prefMapPathValue));
try {
startActivityForResult(intent, REQUEST_CODE_PICK_MAP_PATH);
Log.i("SettingsActivity", String.format("Sending intent: %s", intentAction));
success = true;
} catch (ActivityNotFoundException e) {
// Try the next intent in the list
i++;
}
} while (!success && (i < PICK_DIRECTORY_INTENTS.length));
if (!success) {
// No app for folder browsing is installed, show a fallback dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.pref_map_path));
LayoutInflater inflater = LayoutInflater.from(this);
final View alertView = inflater.inflate(R.layout.alert_map_path, null);
final EditText editPath = (EditText) alertView.findViewById(R.id.editPath);
editPath.setText(prefMapPathValue);
final ImageButton btnOiFilemanager = (ImageButton) alertView.findViewById(R.id.btn_oi_filemanager);
btnOiFilemanager.setTag(Uri.parse("market://details?id=org.openintents.filemanager"));
final ImageButton btnCmFilemanager = (ImageButton) alertView.findViewById(R.id.btn_cm_filemanager);
btnCmFilemanager.setTag(Uri.parse("market://details?id=com.cyanogenmod.filemanager.ics"));
final View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getTag() instanceof Uri)
startActivity(new Intent(Intent.ACTION_VIEW, (Uri) v.getTag()));
}
};
builder.setView(alertView);
btnOiFilemanager.setOnClickListener(clickListener);
btnCmFilemanager.setOnClickListener(clickListener);
builder.setPositiveButton(getString(R.string.action_ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setMapPath(editPath.getText().toString());
}
});
builder.setNegativeButton(getString(R.string.action_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// NOP
}
});
builder.show();
success = true;
}
return success;
} else if (preference == prefMapDownload) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
startActivity(new Intent(this, MapDownloadActivity.class));
else
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, Const.PERM_REQUEST_MAP_DOWNLOAD);
return true;
} else if (preference == prefMapPurge) {
TileCache mapRendererTileCache = AndroidUtil.createExternalStorageTileCache(this, Const.TILE_CACHE_INTERNAL_RENDER_THEME, 0, 256, true);
TileCache mapDownloadTileCache = AndroidUtil.createExternalStorageTileCache(this, Const.TILE_CACHE_OSM, 0, 256, true);
mapRendererTileCache.purge();
mapDownloadTileCache.purge();
mapRendererTileCache.destroy();
mapDownloadTileCache.destroy();
/*
* This is a hack to have the map view (if it is active) redraw the map:
* Setting the preference to true causes the listener in MainView to fire.
* The listener will, in turn, determine if a map view is active and, if so,
* cause it to reload all tile layers, then reset the preference to false.
*/
SharedPreferences.Editor spEditor = mSharedPreferences.edit();
spEditor.putBoolean(Const.KEY_PREF_MAP_PURGE, true);
spEditor.commit();
String message = getString(R.string.status_map_purged);
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
return true;
} else
return false;
}
Aggregations