add osmand to notification bar during running

git-svn-id: https://osmand.googlecode.com/svn/trunk@45 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
frolovmo 2010-05-07 13:21:37 +00:00
parent 92a6ef78ba
commit 6a3308bc79

View file

@ -1,6 +1,9 @@
package com.osmand.activities; package com.osmand.activities;
import android.app.Activity; import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -17,6 +20,8 @@ public class MainMenuActivity extends Activity {
private Button showMap; private Button showMap;
private Button exitButton; private Button exitButton;
private Button settingsButton; private Button settingsButton;
private NotificationManager mNotificationManager;
private int APP_NOTIFICATION_ID;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -25,11 +30,23 @@ public class MainMenuActivity extends Activity {
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.menu); setContentView(R.layout.menu);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent mapIndent = new Intent(MainMenuActivity.this, MapActivity.class);
Notification notification = new Notification(R.drawable.icon, "Notify",
System.currentTimeMillis());
notification.setLatestEventInfo(MainMenuActivity.this, "OsmAnd",
"OsmAnd are running in background", PendingIntent.getActivity(
this.getBaseContext(), 0, mapIndent,
PendingIntent.FLAG_CANCEL_CURRENT));
mNotificationManager.notify(APP_NOTIFICATION_ID, notification);
showMap = (Button) findViewById(R.id.MapButton); showMap = (Button) findViewById(R.id.MapButton);
showMap.setOnClickListener(new OnClickListener() { showMap.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { 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); startActivityForResult(mapIndent, 0);
} }
@ -38,7 +55,8 @@ public class MainMenuActivity extends Activity {
settingsButton.setOnClickListener(new OnClickListener() { settingsButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { 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); startActivity(settings);
} }
}); });
@ -46,11 +64,15 @@ public class MainMenuActivity extends Activity {
exitButton.setOnClickListener(new OnClickListener() { exitButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mNotificationManager.cancel(APP_NOTIFICATION_ID);
MainMenuActivity.this.finish(); MainMenuActivity.this.finish();
} }
}); });
final ProgressDialog dlg = ProgressDialog.show(this, "Loading data", "Reading indices..."); // add notification
final ProgressDialog dlg = ProgressDialog.show(this, "Loading data",
"Reading indices...");
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
@ -65,5 +87,4 @@ public class MainMenuActivity extends Activity {
} }
} }