diff --git a/OsmAnd/res/drawable/exit.png b/OsmAnd/res/drawable/exit.png new file mode 100644 index 0000000000..e0ae1d94ed Binary files /dev/null and b/OsmAnd/res/drawable/exit.png differ diff --git a/OsmAnd/res/layout/menu.xml b/OsmAnd/res/layout/menu.xml index ad2286ea74..c1cfcc719c 100644 --- a/OsmAnd/res/layout/menu.xml +++ b/OsmAnd/res/layout/menu.xml @@ -2,29 +2,27 @@ - - + android:layout_height="fill_parent" android:background="@color/menu_background"> + + - + android:text="@string/map_Button" android:layout_width="200px" android:layout_marginTop="5px"> + + android:text="@string/settings_Button" android:layout_width="200px" android:layout_marginTop="15px"> - + android:id="@+id/ExitButton" android:background="@drawable/exit"> + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a5a09e18fb..46c07b5858 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -17,4 +17,6 @@ Exit Map Settings +Search +#CFFACD diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index 453083d69a..7543f5fbe7 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -1,5 +1,7 @@ package com.osmand.activities; +import java.util.concurrent.Callable; + import android.app.Activity; import android.content.Intent; import android.os.Bundle; @@ -7,28 +9,36 @@ 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 { +public class MainMenuActivity extends Activity implements + LongRunningActionCallback { private Button showMap; private Button exitButton; private Button settingsButton; - + private ProgressBar loadProgress; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - requestWindowFeature(Window.FEATURE_NO_TITLE); + + 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); } @@ -37,7 +47,8 @@ public class MainMenuActivity extends Activity { 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); } }); @@ -48,12 +59,31 @@ public class MainMenuActivity extends Activity { MainMenuActivity.this.finish(); } }); - - ResourceManager.getResourceManager().indexingPoi(); + + 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; + } + }, "Dialog Title", "Dialog message"); + } + @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); + public void onLongRunningActionFinished(Exception error) { + // TODO Auto-generated method stub + } + } diff --git a/OsmAnd/src/com/osmand/services/LongRunningActionCallback.java b/OsmAnd/src/com/osmand/services/LongRunningActionCallback.java new file mode 100644 index 0000000000..71e5a38268 --- /dev/null +++ b/OsmAnd/src/com/osmand/services/LongRunningActionCallback.java @@ -0,0 +1,5 @@ +package com.osmand.services; + +public interface LongRunningActionCallback { + void onLongRunningActionFinished(Exception error); +} diff --git a/OsmAnd/src/com/osmand/services/LongRunningActionDispatcher.java b/OsmAnd/src/com/osmand/services/LongRunningActionDispatcher.java new file mode 100644 index 0000000000..c64790b878 --- /dev/null +++ b/OsmAnd/src/com/osmand/services/LongRunningActionDispatcher.java @@ -0,0 +1,61 @@ +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); + } + +}