package cn.edu.tsinghua.hpc.gsmtest;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.TabHost;
import cn.edu.tsinghua.hpc.gsmtest.service.MessageReportHandlerService;
public class GSMTesterActivity extends TabActivity {
private static final String TAG = "GSMTesterActivity";
public static MessageReportHandlerService messageService;
private NotificationManager mNM;
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
messageService = ((MessageReportHandlerService.ServiceBinder) service)
.getService();
}
@Override
public void onServiceDisconnected(ComponentName name) {
messageService = null;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(
getString(R.string.state)).setContent(
new Intent(this, PhoneState.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator(
getString(R.string.phone)).setContent(
new Intent(this, CallTester.class)));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator(
getString(R.string.message)).setContent(
new Intent(this, MsgTester.class)));
tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator(
getString(R.string.station)).setContent(
new Intent(this, StationInfo.class)));
Preferences.init(this);
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
startService(new Intent(GSMTesterActivity.this,
MessageReportHandlerService.class));
bindService(new Intent(GSMTesterActivity.this,
MessageReportHandlerService.class), serviceConnection,
Context.BIND_AUTO_CREATE);
showNotification();
}
@Override
protected void onDestroy() {
//mNM.cancel(0);
//unbindService(serviceConnection);
super.onDestroy();
}
/**
* Show a notification while this activity is running.
*/
private void showNotification() {
String text = getString(R.string.gsmtest_started);
Notification notification = new Notification(
android.R.drawable.ic_menu_mylocation, text, System
.currentTimeMillis());
notification.flags = Notification.FLAG_NO_CLEAR
| Notification.FLAG_SHOW_LIGHTS
| Notification.FLAG_ONLY_ALERT_ONCE
| Notification.FLAG_ONGOING_EVENT;
notification.defaults |= Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS;
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, GSMTesterActivity.class), 0);
notification.setLatestEventInfo(this,
getText(R.string.gsmtest_started), text, contentIntent);
mNM.notify(0, notification);
}
}
|