changing layout

git-svn-id: https://osmand.googlecode.com/svn/trunk@41 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-06 20:46:06 +00:00
parent eb744a6e34
commit 92a6ef78ba
6 changed files with 61 additions and 115 deletions

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent" android:background="@color/menu_background">
<Button android:layout_height="85dp"
android:layout_gravity="center" android:id="@+id/MapButton"
android:text="@string/map_Button" android:layout_width="200dp" android:layout_marginTop="30dp"></Button>
<Button android:layout_height="85dp" android:id="@+id/SearchButton" android:text="@string/search_button"
android:layout_width="200dp" android:layout_gravity="center" android:layout_marginTop="20dp"></Button>
<Button android:layout_height="85dp"
android:layout_gravity="center" android:id="@+id/SettingsButton"
android:text="@string/settings_Button" android:layout_width="200dp" android:layout_marginTop="20dp"></Button>
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginBottom ="5dp"
android:layout_height="wrap_content" android:layout_gravity="bottom|left"
android:id="@+id/ExitButton" android:background="@drawable/exit"></Button>
</FrameLayout>
</LinearLayout>

View file

@ -3,21 +3,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:orientation="vertical"
android:layout_height="fill_parent" android:background="@color/menu_background">
<ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top|right" android:id="@+id/LoadProgressBar" ></ProgressBar>
<Button android:layout_height="wrap_content"
<Button android:layout_height="55dp"
android:layout_gravity="center" android:id="@+id/MapButton"
android:text="@string/map_Button" android:layout_width="200px" android:layout_marginTop="5px"></Button>
android:text="@string/map_Button" android:layout_width="300dp" android:layout_marginTop="10dp"></Button>
<Button android:layout_height="wrap_content"
<Button android:layout_height="55dp" android:id="@+id/SearchButton" android:text="@string/search_button"
android:layout_width="300dp" android:layout_gravity="center" android:layout_marginTop="20dp"></Button>
<Button android:layout_height="55dp"
android:layout_gravity="center" android:id="@+id/SettingsButton"
android:text="@string/settings_Button" android:layout_width="200px" android:layout_marginTop="15px"></Button>
<Button android:layout_height="wrap_content" android:id="@+id/SearchButton" android:text="@string/search_button" android:layout_width="200px" android:layout_gravity="center_horizontal" android:layout_marginTop="15px"></Button><FrameLayout android:id="@+id/FrameLayout01"
android:text="@string/settings_Button" android:layout_width="300dp" android:layout_marginTop="20dp"></Button>
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginBottom ="5dp"
android:layout_height="wrap_content" android:layout_gravity="bottom|left"
android:id="@+id/ExitButton" android:background="@drawable/exit"></Button>
</FrameLayout>

View file

@ -14,6 +14,7 @@ import org.apache.commons.logging.Log;
import org.apache.tools.bzip2.CBZip2InputStream;
import org.xml.sax.SAXException;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
@ -191,7 +192,7 @@ public class ResourceManager {
// POI INDEX //
public void indexingPoi(){
public void indexingPoi(ProgressDialog dlg){
if (poiIndex == null) {
File file = new File(Environment.getExternalStorageDirectory(), POI_PATH);
poiIndex = new DataTileManager<Amenity>();
@ -201,6 +202,9 @@ public class ResourceManager {
if (log.isDebugEnabled()) {
log.debug("Starting index POI " + f.getAbsolutePath());
}
if(dlg != null){
dlg.setMessage("Indexing poi " + f.getName());
}
boolean zipped = f.getName().endsWith(".bz2");
InputStream stream = null;
try {
@ -240,7 +244,7 @@ public class ResourceManager {
public DataTileManager<Amenity> getPoiIndex() {
if(poiIndex == null){
indexingPoi();
indexingPoi(null);
}
return poiIndex;
}

View file

@ -1,28 +1,22 @@
package com.osmand.activities;
import java.util.concurrent.Callable;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import com.osmand.R;
import com.osmand.ResourceManager;
import com.osmand.services.LongRunningActionCallback;
import com.osmand.services.LongRunningActionDispatcher;
public class MainMenuActivity extends Activity implements
LongRunningActionCallback {
public class MainMenuActivity extends Activity {
private Button showMap;
private Button exitButton;
private Button settingsButton;
private ProgressBar loadProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -31,14 +25,11 @@ public class MainMenuActivity extends Activity implements
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.menu);
showMap = (Button) findViewById(R.id.MapButton);
showMap.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent mapIndent = new Intent(MainMenuActivity.this,
MapActivity.class);
final Intent mapIndent = new Intent(MainMenuActivity.this, MapActivity.class);
startActivityForResult(mapIndent, 0);
}
@ -47,8 +38,7 @@ public class MainMenuActivity extends Activity implements
settingsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Intent settings = new Intent(MainMenuActivity.this,
SettingsActivity.class);
final Intent settings = new Intent(MainMenuActivity.this, SettingsActivity.class);
startActivity(settings);
}
});
@ -60,30 +50,20 @@ public class MainMenuActivity extends Activity implements
}
});
loadProgress = (ProgressBar) findViewById(R.id.LoadProgressBar);
loadProgress.setHorizontalScrollBarEnabled(true);
// startLongRunningOperation();
}
private LongRunningActionDispatcher dispatcher;
@SuppressWarnings("unchecked")
private void startLongRunningOperation() {
this.dispatcher = new LongRunningActionDispatcher(this, this);
dispatcher.startLongRunningAction(new Callable() {
public Void call() throws Exception {
ResourceManager.getResourceManager().indexingPoi();
return null;
final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices...");
new Thread(){
@Override
public void run() {
try {
dlg.setMessage("Indexing poi...");
ResourceManager.getResourceManager().indexingPoi(dlg);
} finally {
dlg.dismiss();
}
}
}, "Dialog Title", "Dialog message");
}
@Override
public void onLongRunningActionFinished(Exception error) {
// TODO Auto-generated method stub
}.start();
}
}

View file

@ -1,5 +0,0 @@
package com.osmand.services;
public interface LongRunningActionCallback {
void onLongRunningActionFinished(Exception error);
}

View file

@ -1,61 +0,0 @@
package com.osmand.services;
import java.util.concurrent.Callable;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
public class LongRunningActionDispatcher {
private Context context;
private LongRunningActionCallback callback;
private ProgressDialog progressDialog;
private Handler finishedHandler = new Handler();
public LongRunningActionDispatcher(Context context,
LongRunningActionCallback callback) {
this.context = context;
this.callback = callback;
}
@SuppressWarnings("unchecked")
public void startLongRunningAction(final Callable callable,
String progressDialogTitle, String progressDialogMessage) {
progressDialog = ProgressDialog.show(context, progressDialogTitle,
progressDialogMessage, true, false);
new Thread(new Runnable() {
public void run() {
Exception error = null;
try {
callable.call();
} catch (Exception e) {
error = e;
}
final Exception finalError = error;
finishedHandler.post(new Runnable() {
public void run() {
onLongRunningActionFinished(finalError);
}
});
}
}).start();
}
private void onLongRunningActionFinished(Exception error) {
progressDialog.dismiss();
callback.onLongRunningActionFinished(error);
}
}