package org.thinkname.ap.main; //import org.openintents.sensorsimulator.hardware.SensorManagerSimulator; import jade.android.ConnectionListener; import jade.android.JadeGateway; import jade.core.Profile; import jade.imtp.leap.JICP.JICPProtocol; import jade.util.leap.Properties; import java.io.IOException; import java.net.ConnectException; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.thinkname.ap.R; import org.thinkname.ap.contact.Contact; import org.thinkname.ap.contact.ContactListAdapter; import org.thinkname.ap.contact.ContactListChanges; import org.thinkname.ap.contact.ContactLocation; import org.thinkname.ap.contact.ContactManager; import org.thinkname.ap.contact.MultiSelectionListView; import org.thinkname.ap.dialog.HelpDialog; import org.thinkname.ap.dialog.SettingDialog; import org.thinkname.ap.guide.WhatsNewActivity; import org.thinkname.ap.help.HelpActivity; import org.thinkname.ap.menu.IconContextMenu; import org.thinkname.ap.menu.IconContextMenu.IconContextItemSelectedListener; import org.thinkname.ap.msn.MsnAgent; import org.thinkname.ap.msn.MsnEvent; import org.thinkname.ap.msn.MsnEventMgr; import org.thinkname.ap.msn.MsnSession; import org.thinkname.ap.msn.MsnSessionManager; import org.thinkname.ap.msn.MsnSessionMessage; import org.thinkname.ap.util.Anim; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.DialogInterface.OnDismissListener; import android.content.res.Resources; import android.graphics.Color; import android.graphics.Point; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable.Orientation; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.Settings; import android.telephony.TelephonyManager; import android.text.Html; import android.util.Log; import android.view.ContextMenu; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ContextMenu.ContextMenuInfo; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.LayoutAnimationController; import android.view.animation.RotateAnimation; import android.view.animation.TranslateAnimation; import android.webkit.WebView; import android.widget.AdapterView; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.TabHost; import android.widget.TabWidget; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.TabHost.TabSpec; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.Overlay; @SuppressWarnings("deprecation") public class MainActivity extends MapActivity implements ConnectionListener { //The Net State public static String CONNECTSTATE="CONNECT"; private static String SHARED_PREFERENCES_NAME= "properties"; public static final String JADE_DEFAULT_HOST="JADE_DEFAULT_HOST"; public static final String JADE_DEFAULT_PORT="JADE_DEFAULT_PORT"; public static String DIALOGDISMISSMODE="CLOSE"; /** * Id of the context menu item. */ private final int CONTEXT_MENU_ITEM_CHAT_LIST = Menu.FIRST ; private final int CONTEXT_MENU_ITEM_CALL_LIST = Menu.FIRST + 1; private final int CONTEXT_MENU_ITEM_SMS_LIST = Menu.FIRST + 2; private final int CONTEXT_MENU_ITEM_ROUTE_LIST = Menu.FIRST + 3; private final int CONTEXT_MENU_ITEM_LOCATION_LIST=Menu.FIRST+4; /** * Id of tab */ private final String CONTACTS_TAB_TAG = "ContTab"; private final String MAPVIEW_TAB_TAG = "MapViewTab"; /** * The main tab host. */ private TabHost mainTabHost; private TabWidget widget; /** * Value returned by the ChatActivity when closed. */ public static final int CHAT_ACTIVITY_CLOSED = 777; public static final String ID_ACTIVITY_PENDING_RESULT = "ID_ACTIVITY_PENDING_RESULT"; private JadeGateway gateway; /** * Alpha transformation performed when connecting to Jade */ private AlphaAnimation backDissolve; /** * UI-Contacts */ //定义为全局静态变量? public static MultiSelectionListView contactsListView; /** * UI-Map */ private Button switchButton; private MapView mapView; private ContactsPositionOverlay overlay; private Button btnMapMenu; private Button btnMoveSwitch; public static boolean mapMoveFlag=false; private Button btnRecordTrack; private RecordTrack rt_thread; private boolean recordState=false; private Button btnFocusPoint; private boolean focusState=false; private Button btnFullMap; private boolean fullMapState=false; private FocusPoint fp_thread; private Button btnZoomUp; private Button btnZoomDown; private Button switchMapBtn; private Button btnMenu; private TextView tvSender; private SettingDialog parameterDialog; private GuiEventHandler activityHandler; private static IconContextMenu cm; private IconContextMenu cm_refresh; private IconContextMenu icmMap; private boolean fullScreenState=false; public static boolean helpAuthor=false; public static String tel; private void initUI() { //Setup the main tabhost setContentView(R.layout.homepage); mainTabHost = (TabHost) findViewById(R.id.main_tabhost); /* remove the white line*/ mainTabHost.setPadding(mainTabHost.getPaddingLeft(), mainTabHost.getPaddingTop(), mainTabHost.getPaddingRight(), mainTabHost.getPaddingBottom() - 5); mainTabHost.setup(); //Fill the contacts tab TabSpec contactsTabSpecs = mainTabHost.newTabSpec(CONTACTS_TAB_TAG); TabSpec mapTabSpecs = mainTabHost.newTabSpec(MAPVIEW_TAB_TAG); contactsTabSpecs.setIndicator(getText(R.string.label_contacts_tab_indicator), getResources().getDrawable(R.drawable.contact)); contactsTabSpecs.setContent(R.id.contactstabview); mapTabSpecs.setIndicator(getText(R.string.mapview_tab_name), getResources().getDrawable(R.drawable.globemap)); mapTabSpecs.setContent(R.id.maptabview); mainTabHost.addTab(contactsTabSpecs); mainTabHost.addTab(mapTabSpecs); Resources res = getResources(); int[] colors = new int[] { res.getColor(R.color.white), res.getColor(R.color.BuleDark) }; GradientDrawable contentGradient = new GradientDrawable( Orientation.LEFT_RIGHT, colors); View homeTab = (View) findViewById(R.id.contactstabview); homeTab.setBackgroundResource(R.drawable.w08); View homeTab1 = (View) findViewById(R.id.maptabview); homeTab1.setBackgroundDrawable(contentGradient); //获得手机号 // TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); // tel = tm.getLine1Number(); // Log.i("Debug",MainActivity.tel); //init the map view mapView = (MapView) findViewById(R.id.myMapView); btnMapMenu=(Button)findViewById(R.id.net_content_btn); icmMap=new IconContextMenu(MainActivity.this,R.menu.map_menu); icmMap.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() { @Override public void onIconContextItemSelected(MenuItem item, Object info) { List selectedIds = overlay.getSelectedItems(); if(item.getItemId()==R.id.cmCompass) { startActivity(new Intent(MainActivity.this,CompassActivity.class)); return; } if(selectedIds.size()<1) { Toast.makeText(getApplicationContext(), getString(R.string.toast_choice_one), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),"菜单已经锁定", Toast.LENGTH_SHORT); return; } switch (item.getItemId()) { case R.id.cmChat:{ List participantIds = overlay.getSelectedItems(); launchChatSession(participantIds); } break; case R.id.cmRoute:{ if (selectedIds.size() == 1) { Map contactLocMap = ContactManager.getInstance().getAllContactLocations(); ContactLocation myCloc = ContactManager.getInstance().getMyContactLocation(); String phoneNum=selectedIds.get(0); double lat=contactLocMap.get(phoneNum).getLatitude(); double lng=contactLocMap.get(phoneNum).getLongitude(); if (lat!=Double.POSITIVE_INFINITY&&lng!=Double.POSITIVE_INFINITY) { Intent i = new Intent(Intent.ACTION_VIEW); Uri routerUri = Uri.parse("http://maps.google.com/maps?f=d&saddr=" + myCloc.getLatitude()+","+myCloc.getLongitude()+ "&daddr=" + contactLocMap.get(phoneNum).getLatitude()+","+ contactLocMap.get(phoneNum).getLongitude() + "&hl=en"); Toast.makeText(MainActivity.this,getString(R.string.toast_route_suceesgetloc), Toast.LENGTH_SHORT).show(); i.setData(routerUri); startActivity(i); }else { Toast.makeText(MainActivity.this,R.string.toast_route_failgetloc, Toast.LENGTH_SHORT).show(); } } } break; case R.id.cmLocation :{ if (selectedIds.size() == 1) { String phoneNum=selectedIds.get(0); Map contactLocMap = ContactManager.getInstance().getAllContactLocations(); double lat=contactLocMap.get(phoneNum).getLatitude(); double lng=contactLocMap.get(phoneNum).getLongitude(); if (lat!=Double.POSITIVE_INFINITY&&lng!=Double.POSITIVE_INFINITY) { String address=Location.getAddressByLatLng(lat, lng); Toast.makeText(MainActivity.this,phoneNum+"\nIn "+ address, Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.this,R.string.toast_location_noaddress, Toast.LENGTH_LONG).show(); } } } break; case R.id.cmSMS: { ArrayList participantIds = (ArrayList) overlay.getSelectedItems(); //SMSDialog smsDialog = new SMSDialog(this,participantIds); String smsContacts=""; int size=1; for(String s:participantIds) { if(participantIds.size()>size) { smsContacts=smsContacts+s+";"; }else if(participantIds.size()==size) { smsContacts=smsContacts+s; } size++; } System.out.println(smsContacts); Uri smsToUri = Uri.parse("smsto:"+smsContacts);// 联系人地址 Intent i = new Intent(android.content.Intent.ACTION_SENDTO,smsToUri); i.putExtra("内容:", " "); startActivity(i); } break; case R.id.cmCall:{ if (selectedIds.size() == 1) { callContact(selectedIds.get(0)); } else { Toast.makeText(getApplicationContext(), R.string.error_msg_multiple_phonecalls, 2000); } } break; case R.id.cmRequest:{ }break; default: break; } } }); btnMapMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //显示菜单 icmMap.show(); } }); btnMoveSwitch=(Button)findViewById(R.id.moveSwitch); btnMoveSwitch.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { if(!mapMoveFlag) { mapMoveFlag=true; Toast.makeText(MainActivity.this, R.string.moveSwith_lock, Toast.LENGTH_SHORT).show(); //btnMoveSwitch.setText(R.string.moveSwith_unlock_name); btnMoveSwitch.setBackgroundResource(R.drawable.map_lock); // mapView.setBuiltInZoomControls(false); } else if(mapMoveFlag) { mapMoveFlag=false; Toast.makeText(MainActivity.this, R.string.moveSwith_unlock, Toast.LENGTH_SHORT).show(); // btnMoveSwitch.setText(R.string.moveSwith_lock_name); btnMoveSwitch.setBackgroundResource(R.drawable.map_unlock); // mapView.setBuiltInZoomControls(true); } } }); mapView.setSatellite(false); //地图触摸事件 mapView.setOnTouchListener(new View.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { //User has touched the screen, no action just take the time if ( event.getAction() == MotionEvent.ACTION_DOWN ) { Log.i("Debug","MotionEvent.ACTION_DOWN"); int touchedX = (int) event.getX(); int touchedY = (int) event.getY(); overlay.checkClickedPosition(new Point(touchedX, touchedY)); } return false; } }); List overlayList = mapView.getOverlays(); overlay = new ContactsPositionOverlay(this, mapView, getResources()); overlayList.add(overlay); //Button for switching map mode switchButton = (Button) findViewById(R.id.switchMapBtn); switchButton.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { Button clickedBtn = (Button) arg0; if (mapView.isSatellite()) { //clickedBtn.setText(MainActivity.this.getText(R.string.label_toggle_satellite)); clickedBtn.setBackgroundResource(R.drawable.switch_map_btn); mapView.setSatellite(false); } else { //clickedBtn.setText(MainActivity.this.getText(R.string.label_toggle_map)); clickedBtn.setBackgroundResource(R.drawable.switch_map_btn1); mapView.setSatellite(true); } } }); btnRecordTrack=(Button) findViewById(R.id.recordTrack); btnRecordTrack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(!recordState) { List selectedIds = overlay.getSelectedItems();//取到选择的点 if (selectedIds.size() == 1) { recordState=true; Toast.makeText(MainActivity.this,"轨迹记录已经开始", Toast.LENGTH_SHORT).show(); String phoneNum=selectedIds.get(0); rt_thread=new RecordTrack(phoneNum); Log.i("btnRecordTrack","before rt.starTrack()"); rt_thread.starTrack(); btnRecordTrack.setBackgroundResource(R.drawable.map_stoprecord); }else { /* Toast.makeText(MainActivity.this,"该版本不支持同时跟踪记录多人", Toast.LENGTH_SHORT).show();*/ Toast.makeText(MainActivity.this,"请选择一个目标进行记录其移动轨迹", Toast.LENGTH_SHORT).show(); } }else { recordState=false; if(rt_thread!=null) rt_thread.stopTrack(); btnRecordTrack.setBackgroundResource(R.drawable.map_record); Toast.makeText(MainActivity.this,"轨迹记录停止", Toast.LENGTH_SHORT).show(); /*Toast.makeText(MainActivity.this,RecordTrack.track.toString(), Toast.LENGTH_LONG).show();*/ new AlertDialog.Builder(MainActivity.this).setTitle("目标移动轨迹") .setMessage(RecordTrack.track.toString()).setPositiveButton("短信", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // 确定按钮事件 Intent i = new Intent(Intent.ACTION_VIEW); i.putExtra("address", ""); i.setType("vnd.android-dir/mms-sms"); i.putExtra("sms_body",RecordTrack.track.toString()); startActivity(i); } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } } }); btnFocusPoint=(Button) findViewById(R.id.focusPoint); btnFocusPoint.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List selectedIds = overlay.getSelectedItems();//取到选择的点 if(!focusState) { if (selectedIds.size() == 1) { focusState=true; String phoneNum=selectedIds.get(0); //overlay.initializePositionsFocus(phoneNum);//开启跟踪--失败 // ContactLocation focusPoint // =ContactManager.getInstance().getAllContactLocations().get(phoneNum); //解除锁定自己模式 mapMoveFlag=true; //btnMoveSwitch.setText("自由模式"); btnMoveSwitch.setBackgroundResource(R.drawable.map_lock_disable); btnMoveSwitch.setEnabled(false); btnFocusPoint.setBackgroundResource(R.drawable.map_trace_stop); Toast.makeText(MainActivity.this, R.string.moveSwith_unlock, Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "开启跟踪模式", 2000).show(); //btnMoveSwitch.setText(R.string.moveSwith_unlock_name); //初始化跟踪线程 fp_thread=new FocusPoint(mapView, phoneNum); fp_thread.setFoucsState(true); fp_thread.startFocus(); //mapView.setBuiltInZoomControls(true); } else { Toast.makeText(MainActivity.this,"该版本不支持同时跟踪记录多人", Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this,"请选择一个目标", Toast.LENGTH_SHORT).show(); } } else { focusState=false; fp_thread.setFoucsState(false); fp_thread.stopFocus(); Toast.makeText(MainActivity.this, "解除跟踪模式", 2000).show(); btnMoveSwitch.setEnabled(true); btnMoveSwitch.setBackgroundResource(R.drawable.map_lock); btnFocusPoint.setBackgroundResource(R.drawable.map_trace); //mapView.setBuiltInZoomControls(false); } } }); btnFullMap=(Button) findViewById(R.id.fullMap); btnFullMap.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(!fullMapState) { fullMapState=true; switchMapBtn=(Button) findViewById(R.id.switchMapBtn); switchMapBtn.setVisibility(View.GONE); mainTabHost.getTabWidget().setVisibility(View.GONE); btnFullMap.setBackgroundResource(R.drawable.map_windows); } else { fullMapState=false; switchMapBtn=(Button) findViewById(R.id.switchMapBtn); switchMapBtn.setVisibility(View.VISIBLE); mainTabHost.getTabWidget().setVisibility(View.VISIBLE); btnFullMap.setBackgroundResource(R.drawable.map_max); } } }); //mapView.getZoomButtonsController().setZoomSpeed(1000); btnZoomUp=(Button) findViewById(R.id.zoomup); btnZoomUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mapView.getController().setZoom(mapView.getZoomLevel()+1); } }); btnZoomDown=(Button) findViewById(R.id.zoomdown); btnZoomDown.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mapView.getController().setZoom(mapView.getZoomLevel()-1); } }); //Create the updater array //Select default tab mainTabHost.setCurrentTabByTag(CONTACTS_TAB_TAG); contactsListView = (MultiSelectionListView) findViewById(R.id.contactsList); contactsListView.setCacheColorHint(Color.TRANSPARENT); contactsListView.setSelector(R.drawable.list_selector); contactsListView.setDivider(getResources().getDrawable(R.drawable.contact_line)); // int[] selectorColors = new int[] { res.getColor(R.color.white), // res.getColor(R.color.BuleDark) }; // GradientDrawable selectorDrawable = new GradientDrawable( // Orientation.TL_BR, selectorColors); // contactsListView.setSelector(selectorDrawable); registerForContextMenu(contactsListView); contactsListView .setOnItemClickListener(new AdapterView.OnItemClickListener() { @SuppressWarnings("unchecked") public void onItemClick(AdapterView parent, View v, int position, long id) { CheckBox cb = (CheckBox) v .findViewById(R.id.contact_check_box); cb.setChecked(!cb.isChecked()); } }); //TODO:读取手机联系人 ContactManager.getInstance().readPhoneContacts(this); contactsListView.setAdapter(ContactManager.getInstance().getAdapter()); contactsListView.setLayoutAnimation(Anim.ListViewAnim()); parameterDialog = new SettingDialog(this); //initializeContactList(); widget= mainTabHost.getTabWidget(); setWidget(); //TODO:设置标签卡切换监听 mainTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { for (int i = 0; i < widget.getChildCount(); i++) { View view = widget.getChildAt(i); if (mainTabHost.getCurrentTab() == i) { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg_pressed)); //隐藏 } else { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg)); } } } }); btnMenu=(Button)findViewById(R.id.MenuBtn); btnMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cm=new IconContextMenu(MainActivity.this, R.menu.contextmenu); cm.setTitle(R.string.menu_item_title); List checkedContacts = contactsListView.getAllSelectedItems(); if(checkedContacts.size()==0) { Toast.makeText(getApplicationContext(), getString(R.string.toast_choice_one) ,Toast.LENGTH_SHORT).show(); } if(checkedContacts.size() > 0){ //Let the menu appear if(checkedContacts.size() == 1){ //only one contact selected Contact cc = ContactManager.getInstance().getContact(checkedContacts.get(0)); //verify is he is online --> add Chat if(!cc.isOnline()){ //当为测试账号的时候,不进行移除选项 if(cc.getPhoneNumber()!="18754371111") { cm.getMenu().removeItem(R.id.cmChat); cm.getMenu().removeItem(R.id.cmRoute); cm.getMenu().removeItem(R.id.cmLocation); } } }else{ //more elements selected boolean allOnline = true; for(String contactId : checkedContacts){ Contact cc = ContactManager.getInstance().getContact(contactId); if(!cc.isOnline()){ allOnline = false; break; } } if(allOnline){ cm.getMenu().removeItem(R.id.cmCall); cm.getMenu().removeItem(R.id.cmRoute); cm.getMenu().removeItem(R.id.cmLocation); }else //otherwise only sms { cm.getMenu().removeItem(R.id.cmChat); cm.getMenu().removeItem(R.id.cmRoute); cm.getMenu().removeItem(R.id.cmCall); cm.getMenu().removeItem(R.id.cmLocation); } } // cm.setOnIconContextItemSelectedListener(new ContentMenuListener(MainActivity.this, contactsListView)); cm.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() { @Override public void onIconContextItemSelected(MenuItem item, Object info) { // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.cmChat: { System.out.println("cmChat"); List participantIds = contactsListView.getAllSelectedItems(); launchChatSession(participantIds); } break; case R.id.cmRoute: { System.out.println("cmRoute"); List selectedIds = contactsListView.getAllSelectedItems(); if(selectedIds.get(0).equals("18754371111")) { ContactLocation myCloc = ContactManager.getInstance().getMyContactLocation(); Intent i = new Intent(Intent.ACTION_VIEW); Uri routerUri = Uri.parse("http://maps.google.com/maps?f=d&saddr=" + myCloc.getLatitude()+","+myCloc.getLongitude()+ "&daddr=" + 37.383174+","+ 118.00357 + "&hl=en"); Toast.makeText(MainActivity.this,getString(R.string.toast_route_suceesgetloc), Toast.LENGTH_SHORT).show(); i.setData(routerUri); startActivity(i); }else if (selectedIds.size() == 1) { Map contactLocMap = ContactManager.getInstance().getAllContactLocations(); ContactLocation myCloc = ContactManager.getInstance().getMyContactLocation(); String phoneNum=selectedIds.get(0); double lat=contactLocMap.get(phoneNum).getLatitude(); double lng=contactLocMap.get(phoneNum).getLongitude(); if (lat!=Double.POSITIVE_INFINITY&&lng!=Double.POSITIVE_INFINITY) { Intent i = new Intent(Intent.ACTION_VIEW); Uri routerUri = Uri.parse("http://maps.google.com/maps?f=d&saddr=" + myCloc.getLatitude()+","+myCloc.getLongitude()+ "&daddr=" + contactLocMap.get(phoneNum).getLatitude()+","+ contactLocMap.get(phoneNum).getLongitude() + "&hl=en"); Toast.makeText(MainActivity.this,getString(R.string.toast_route_suceesgetloc), Toast.LENGTH_SHORT).show(); i.setData(routerUri); startActivity(i); }else { Toast.makeText(MainActivity.this,R.string.toast_route_failgetloc, Toast.LENGTH_SHORT).show(); } } } break; case R.id.cmLocation: { System.out.println("cmLocation"); List selectedIds = contactsListView.getAllSelectedItems(); if(selectedIds.get(0).equals("18754371111")) { Toast.makeText(MainActivity.this,"位置:滨州学院>\n滨州市滨城区黄河五路391号\n思想有多远名字有多长\nThinkName", Toast.LENGTH_LONG).show(); }else if (selectedIds.size() == 1) { String phoneNum=selectedIds.get(0); Map contactLocMap = ContactManager.getInstance().getAllContactLocations(); double lat=contactLocMap.get(phoneNum).getLatitude(); double lng=contactLocMap.get(phoneNum).getLongitude(); if (lat!=Double.POSITIVE_INFINITY&&lng!=Double.POSITIVE_INFINITY) { String address=Location.getAddressByLatLng(lat, lng); Toast.makeText(MainActivity.this,phoneNum+"\nIn "+ address, Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.this,R.string.toast_location_noaddress, Toast.LENGTH_LONG).show(); } }else { Toast.makeText(MainActivity.this, R.string.toast_choice_one, Toast.LENGTH_SHORT).show(); } } break; case R.id.cmCall : { System.out.println("cmCall"); List selectedIds = contactsListView.getAllSelectedItems(); if (selectedIds.size() == 1) { callContact(selectedIds.get(0)); } else { Toast.makeText(MainActivity.this, R.string.error_msg_multiple_phonecalls, Toast.LENGTH_LONG).show(); } } break; case R.id.cmSMS: { System.out.println("cmSMS"); ArrayList participantIds = (ArrayList) contactsListView .getAllSelectedItems(); String smsContacts=""; int size=1; for(String s:participantIds) { if(participantIds.size()>size) { smsContacts=smsContacts+s+";"; }else if(participantIds.size()==size) { smsContacts=smsContacts+s; } size++; } System.out.println(smsContacts); Uri smsToUri = Uri.parse("smsto:"+smsContacts);// 联系人地址 // Intent i = new Intent(android.content.Intent.ACTION_SENDTO,smsToUri); // i.putExtra("内容:", " "); // startActivity(i); Intent i = new Intent(Intent.ACTION_SENDTO, smsToUri); //Intent i = new Intent(Intent.ACTION_VIEW); //i.putExtra("sms_body", "yyyy"); //i.putExtra("address", smsContacts); //i.setType("vnd.android-dir/mms-sms"); i.putExtra("sms_body", ""); startActivity(i); //Intent i = new Intent(Intent.ACTION_VIEW); //i.putExtra("sms_body", "yyyy"); // i.putExtra("address", smsContacts); // i.setType("vnd.android-dir/mms-sms"); // i.putExtra("sms_body", "I am joe!"); // startActivity(i); } break; case R.id.cmRequest:{ System.out.println("cmRequest"); ArrayList participantIds = (ArrayList) contactsListView .getAllSelectedItems(); String smsContacts=""; int size=1; for(String s:participantIds) { if(participantIds.size()>size) { smsContacts=smsContacts+s+";"; }else if(participantIds.size()==size) { smsContacts=smsContacts+s; } size++; } System.out.println(smsContacts); // Intent i = new Intent(Intent.ACTION_VIEW); // i.putExtra("address", smsContacts); // i.setType("vnd.android-dir/mms-sms"); // String s="Hi,我已开启活点地图,还等什么?速来加入!这是我的配置参数IP:"+SettingDialog.myIP+",Port:"+SettingDialog.myPort; // i.putExtra("sms_body", s); // startActivity(i); Uri smsToUri = Uri.parse("smsto:"+smsContacts);// 联系人地址 Intent i = new Intent(Intent.ACTION_SENDTO, smsToUri); String s="Hi,我已开启活点地图,还等什么?速来加入!这是我的配置参数IP:"+SettingDialog.myIP+",Port:"+SettingDialog.myPort; i.putExtra("sms_body", s); startActivity(i); }break; } } }); cm.show(); } } }); cm_refresh =new IconContextMenu(MainActivity.this, R.menu.refresh_menu); tvSender=(TextView)findViewById(R.id.senderTxtView); tvSender.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cm_refresh.show(); } }); cm_refresh.setOnIconContextItemSelectedListener(new IconContextItemSelectedListener() { @Override public void onIconContextItemSelected(MenuItem item, Object info) { // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.ref_refresh: { ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); adapter.hideOffline(); contactsListView.setAdapter(adapter); //overlay.initializePositions(); } break; case R.id.ref_showAll: { ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); adapter.initialize2(); contactsListView.setAdapter(adapter); //overlay.initializePositions(); } break; case R.id.ref_hideOffline: { //TODO:去实现隐藏非在线联系人 ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); adapter.hideOffline();//自定义方法 contactsListView.setAdapter(adapter); //overlay.initializePositions(); } break; default: break; } } }); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // menu.setHeaderTitle(R.string.menu_item_title); // menu.setHeaderIcon(R.drawable.connect); if(v instanceof MultiSelectionListView){ Log.i("map click", "onCreateContextMenu:v instanceof MultiSelectionListView"); AdapterView.AdapterContextMenuInfo adaptMenuInfo = (AdapterContextMenuInfo) menuInfo; MultiSelectionListView myLv = (MultiSelectionListView) v; myLv.setSelection(adaptMenuInfo.position); List checkedContacts = myLv.getAllSelectedItems(); if(checkedContacts.size() > 0){ //Let the menu appear if(checkedContacts.size() == 1){ //only one contact selected Contact cc = ContactManager.getInstance().getContact(checkedContacts.get(0)); //verify is he is online --> add Chat if(cc.isOnline()){ menu.add(Menu.NONE, CONTEXT_MENU_ITEM_CHAT_LIST, Menu.NONE, R.string.menu_item_chat); menu.add(Menu.NONE, CONTEXT_MENU_ITEM_ROUTE_LIST, Menu.NONE, R.string.menu_item_route); menu.add(Menu.NONE,CONTEXT_MENU_ITEM_LOCATION_LIST,Menu.NONE,R.string.menu_item_location); } //add always sms and call menu.add(Menu.NONE, CONTEXT_MENU_ITEM_CALL_LIST, Menu.NONE, R.string.menu_item_call); menu.add(Menu.NONE, CONTEXT_MENU_ITEM_SMS_LIST, Menu.NONE, R.string.menu_item_sms); }else{ //more elements selected boolean allOnline = true; for(String contactId : checkedContacts){ Contact cc = ContactManager.getInstance().getContact(contactId); if(!cc.isOnline()){ allOnline = false; break; } } if(allOnline) menu.add(Menu.NONE, CONTEXT_MENU_ITEM_CHAT_LIST, Menu.NONE, R.string.menu_item_chat); //otherwise only sms menu.add(Menu.NONE, CONTEXT_MENU_ITEM_SMS_LIST, Menu.NONE, R.string.menu_item_sms); } } } } public void onCreate(Bundle icicle) { super.onCreate(icicle); // 启动后删除之前我们定义的通知 NotificationManager notificationManager = (NotificationManager) this .getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(0); //继续初始化UI ContactListAdapter cla = new ContactListAdapter(this); ContactManager.getInstance().addAdapter(cla); ChatSessionNotificationManager.create(this); initUI(); //register an event for this activity to handle refresh of the views in this activity activityHandler = new ContactListActivityUpdateHandler(); //register a generic disconnection handler MsnEventMgr.getInstance().registerEvent(MsnEvent.CONTACT_DISCONNECT_EVENT, new ContactDisconnectionHandler()); //Initialize the UI disableUI(); if(CONNECTSTATE.equals("CONNECT")) { parameterDialog.show(); } else if(CONNECTSTATE.equals("CLOSE")) { //setNetwork setNetwork(); } //listen parameterDialog ,when the dialog dismiss ,it be called parameterDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if(DIALOGDISMISSMODE.equals("CONNECT")) { showProDialog(MainActivity.this); ConnectToPlatform(); } else if(DIALOGDISMISSMODE.equals("CLOSE")) { MainActivity.this.finish(); }else { Toast.makeText(MainActivity.this,getString(R.string.toast_network_seterror) ,Toast.LENGTH_SHORT).show(); } } }); } private void setNetwork() { AlertDialog.Builder builder=new AlertDialog.Builder(this); builder.setIcon(R.drawable.settings); builder.setTitle(R.string.setNetwork_setitle); builder.setMessage(R.string.setNetwork_setMessage); builder.setPositiveButton(R.string.setNetwork_positiveBtn, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 如果没有网络连接,则进入网络设置界面 startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); } }); builder.setNegativeButton(R.string.setNetwork_negativeBtn, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,getString(R.string.toast_network_nonetwoek), Toast.LENGTH_LONG).show(); dialog.cancel(); } }); builder.create(); builder.show(); } /** * Registers handlers for both the views. */ protected void onResume() { super.onResume(); Log.i("debug","On Resume was called!!!: setting event handler in ContactListActivity"); MsnEventMgr.getInstance().registerEvent(MsnEvent.VIEW_REFRESH_EVENT, activityHandler); MsnEventMgr.getInstance().registerEvent(MsnEvent.INCOMING_MESSAGE_EVENT, activityHandler); this.overlay.uncheckAllContacts(); this.contactsListView.uncheckAllSelectedItems(); //No Listener // sm.registerListener(this, SensorManager.SENSOR_ORIENTATION // | SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_NORMAL); } @Override public void onStart() { super.onStart(); } @Override protected void onStop() { super.onStop(); } @Override public void onPause() { showNotification(); super.onPause(); } /** * Enables the main view after the application is connected to server */ private void enableUI () { Log.i("debug","执行enableUI()"); View mainView = findViewById(R.id.main_tabhost); backDissolve = new AlphaAnimation(0.0f,1.0f); backDissolve.setDuration(2200); mainView.setAnimation(backDissolve); mainView.setVisibility(View.VISIBLE); //TabWidget widget = mainTabHost.getTabWidget(); //widget.setEnabled(true); } /** * Disables the UI at the beginning */ private void disableUI() { //TODO:R.id.main_view widget.setEnabled(true); } private void setWidget() { for (int i = 0; i < widget.getChildCount(); i++) { /* 得到每个标签的视图 */ View view = widget.getChildAt(i); /* 设置每个标签的背景 */ if (mainTabHost.getCurrentTab() == i) { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg_pressed)); } else { view.setBackgroundDrawable(getResources().getDrawable( R.drawable.number_bg)); } /* 设置Tab间分割竖线的颜色 */ // tabWidget.setBackgroundColor(Color.WHITE); /* 设置Tab间分割竖线的背景图片 */ // tabWidget.setBackgroundResource(R.drawable.icon); /* 设置tab的高度 */ //mainTabHost.getChildAt(i).getLayoutParams().height = 50; TextView tv = (TextView) widget.getChildAt(i).findViewById( android.R.id.title); /* 设置tab内字体的颜色 */ tv.setTextColor(Color.rgb(255, 255, 255)); } } //Retrieve the JADE properties from Dialog or configuration file private Properties getJadeProperties() { //fill server connection properties Properties jadeProperties = new Properties(); JChatApplication app = (JChatApplication)getApplication(); jadeProperties.setProperty(Profile.MAIN_HOST, app.getProperty(JChatApplication.JADE_DEFAULT_HOST)); jadeProperties.setProperty(Profile.MAIN_PORT, app.getProperty(JChatApplication.JADE_DEFAULT_PORT)); jadeProperties.setProperty(JICPProtocol.MSISDN_KEY, app.getProperty(JChatApplication.PREFERENCE_PHONE_NUMBER)); return jadeProperties; } protected void onDestroy() { GeoNavigator.getInstance(this).stopLocationUpdate(); ChatSessionNotificationManager.getInstance().removeAllNotifications(); if (gateway != null) { try { gateway.shutdownJADE(); } catch (ConnectException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } gateway.disconnect(this); } MsnSessionManager.getInstance().shutdown(); ContactManager.getInstance().shutdown(); //Debug.stopMethodTracing(); // 删除之前我们定义的通知 NotificationManager notificationManager = (NotificationManager) this .getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(0); //删除Track MyTrack.myTrack=null; super.onDestroy(); // After this is called, your app process is no longer available in DDMS //android.os.Process.killProcess(android.os.Process.myPid()); } /** * .onConnected to the service */ public void onConnected(JadeGateway gw) { this.gateway = gw; enableUI(); //启动位置服务 //contactsListView //TODO: Contact c=new Contact(getString(R.string.testerName),getString(R.string.testerPhoneNum), true); ContactLocation myCloc = ContactManager.getInstance().getMyContactLocation(); //TODO:两个方法 getMyTrack(); try { this.gateway.execute(""); } catch (Exception e) { Log.i("debug","Exception in onConnected"); e.printStackTrace(); } Log.i("debug", "onConnected(): SUCCESS!"); } private void getMyTrack() { MyTrack track=new MyTrack(); track.starTrack(MainActivity.this); } public void onDisconnected() { } /** * Creates the application main menu */ public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // Inflate the currently selected menu XML resource. MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.title_icon, menu); return true; } public boolean onPrepareOptionsMenu(Menu menu) { MenuItem menuItemConnect = menu.findItem(R.id.connect); menuItemConnect.setVisible(gateway == null); MenuItem menuItemSettings = menu.findItem(R.id.settings); menuItemSettings.setVisible((gateway == null)); return super.onPrepareOptionsMenu(menu); } private ProgressDialog pgUpdateDialog; private Dialog updateDlg; private Dialog helpDlg; /** * Handles the selection on items in main menu */ public boolean onMenuItemSelected(int featureId, MenuItem item) { View viewAddEmployee; super.onMenuItemSelected(featureId, item); switch (item.getItemId()) { case R.id.exit: finish(); break; case R.id.About: startActivity(new Intent(MainActivity.this ,HelpActivity.class)); break; case R.id.settings: parameterDialog.show(); break; case R.id.Guide: startActivity(new Intent(MainActivity.this,WhatsNewActivity.class)); //ContactListActivity.this.finish(); break; case R.id.connect: showProDialog(MainActivity.this); ConnectToPlatform(); break; case R.id.feedback: Uri uri = Uri.parse("mailto:getbox@126.com"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); startActivity(it); // LayoutInflater layoutInflater = LayoutInflater.from(this); // viewAddEmployee = layoutInflater.inflate(R.layout.feedback, null); // // new AlertDialog.Builder(this).setTitle("反馈信息").setView( // viewAddEmployee).setPositiveButton("提交", // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // Toast.makeText(MainActivity.this, "提交成功!", // Toast.LENGTH_SHORT).show(); // } // }).setNegativeButton("取消", // new DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog, int which) { // // } // }).show(); break; case R.id.update: { pgUpdateDialog=new ProgressDialog(MainActivity.this); pgUpdateDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); //pgDialog.setIcon(R.drawable.icon); pgUpdateDialog.setMessage("正在检查更新..."); pgUpdateDialog.setIndeterminate(false); final Handler updateHandler=new Handler() { @Override public void handleMessage(Message msg) { if(msg.what==0) { Toast.makeText(MainActivity.this, R.string.UpdateApp, Toast.LENGTH_SHORT).show(); } } }; pgUpdateDialog.show(); //pgDialog.dismiss(); new Thread() { public void run() { try{ Thread.sleep(3000); }catch(InterruptedException e){ e.printStackTrace(); } pgUpdateDialog.dismiss(); updateHandler.sendEmptyMessage(0); }}.start(); } break; case R.id.refresh: { //TODO:去实现隐藏非在线联系人 ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); adapter.hideOffline();//自定义方法 contactsListView.setAdapter(adapter); break; } case R.id.fullScreen: { if(!fullScreenState) { switchMapBtn=(Button) findViewById(R.id.switchMapBtn); switchMapBtn.setVisibility(View.GONE); mainTabHost.getTabWidget().setVisibility(View.GONE); fullScreenState=true; } else { switchMapBtn=(Button) findViewById(R.id.switchMapBtn); switchMapBtn.setVisibility(View.VISIBLE); mainTabHost.getTabWidget().setVisibility(View.VISIBLE); fullScreenState=false; } break; } case R.id.allContacts: { ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); adapter.initialize2();//自定义方法 contactsListView.setAdapter(adapter); break; } case R.id.updateLog: { updateDlg=new UpdateLogDialog(MainActivity.this); updateDlg.show(); // new AlertDialog.Builder(this) // .setTitle("HTML Example") // .setMessage(Html.fromHtml("")) // //Html.fromHtml("Bold text and italics") // .setPositiveButton("Sweet") // .create() // .show(); break; } case R.id.Help: { helpDlg=new HelpDialog(this); helpDlg.show(); helpDlg.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if(helpAuthor) { // Uri uri=Uri.parse("mailto:getbox@126.com"); // Intent myMailIntent=new Intent(Intent.ACTION_SEND,uri); // startActivity(myMailIntent); // final Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND); // emailIntent.setType("plain/text"); // emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"getbox@126.com"}); // emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "ProjectX 使用求助"); // startActivity(Intent.createChooser(emailIntent, "选择")); Uri uri = Uri.parse("mailto:getbox@126.com"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); startActivity(it); } } }); break; } } return true; } private String connectMsg=""; public void ConnectToPlatform() { Thread t= new Thread(new Runnable() { @Override public void run() { try{ SharedPreferences prefs = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); String host = prefs.getString(JADE_DEFAULT_HOST, getString(R.string.jade_platform_host)); String port = prefs.getString(JADE_DEFAULT_PORT, getString(R.string.jade_platform_port)); Socket client=new Socket(); SocketAddress sa=new InetSocketAddress(host, Integer.parseInt(port)); client.connect(sa,3000); connectMsg=getString(R.string.connect_msg_readytopaltform); client.close(); connHandler.sendEmptyMessage(1); //处理 } catch(IOException e) { connectMsg=getString(R.string.connect_msg_errortopaltform); connHandler.sendEmptyMessage(0); } catch(Exception e) { connectMsg =getString(R.string.connect_msg_throw_exception); connHandler.sendEmptyMessage(0); } } }); t.start(); } Handler connHandler=new Handler(){ @Override public void handleMessage(Message msg) { switch(msg.what) { case 1: try{ Toast.makeText(MainActivity.this, connectMsg, Toast.LENGTH_LONG) .show(); JChatApplication app = (JChatApplication)getApplication(); ContactManager.getInstance().addMyContact(app.getProperty(JChatApplication.PREFERENCE_PHONE_NUMBER)); GeoNavigator.setLocationProviderName(app.getProperty(JChatApplication.LOCATION_PROVIDER)); GeoNavigator.getInstance(MainActivity.this).startLocationUpdate(); initializeContactList(); //fill Jade connection properties Properties jadeProperties = getJadeProperties(); //TODO:真机无法通过的地方 Log.i("debug","getJadeProperties();"); JadeGateway.connect(MsnAgent.class.getName(), new String[] { getText(R.string.contacts_update_time) .toString() }, jadeProperties, MainActivity.this, MainActivity.this); Log.i("debug","before dismiss();"); proDialog.dismiss(); Toast.makeText(MainActivity.this, R.string.connect_msg_success, Toast.LENGTH_SHORT) .show(); } catch (Exception e) { Toast.makeText(MainActivity.this, getString(R.string.error_msg_jadegw_connection), Toast.LENGTH_LONG) .show(); Log.i("debug","Error in Handler ConnectToPlatform+"+e.toString()); e.printStackTrace(); } break; case 0: proDialog.dismiss(); Toast.makeText(MainActivity.this, connectMsg, Toast.LENGTH_LONG) .show(); //离线状态也进行初始化 JChatApplication app = (JChatApplication)getApplication(); ContactManager.getInstance().addMyContact(app.getProperty(JChatApplication.PREFERENCE_PHONE_NUMBER)); GeoNavigator.setLocationProviderName(app.getProperty(JChatApplication.LOCATION_PROVIDER)); GeoNavigator.getInstance(MainActivity.this).startLocationUpdate(); initializeContactList(); break; } } }; /** * Handles the context menu selection both in map and in contact view * * @see Activity */ public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case CONTEXT_MENU_ITEM_CALL_LIST: { List selectedIds = contactsListView.getAllSelectedItems(); if (selectedIds.size() == 1) { callContact(selectedIds.get(0)); } else { Toast.makeText(this, R.string.error_msg_multiple_phonecalls, Toast.LENGTH_LONG).show(); } } break; case CONTEXT_MENU_ITEM_CHAT_LIST: { List participantIds = contactsListView .getAllSelectedItems(); launchChatSession(participantIds); } break; case CONTEXT_MENU_ITEM_ROUTE_LIST: { List selectedIds = contactsListView.getAllSelectedItems(); if (selectedIds.size() == 1) { Map contactLocMap = ContactManager.getInstance().getAllContactLocations(); ContactLocation myCloc = ContactManager.getInstance().getMyContactLocation(); String phoneNum=selectedIds.get(0); double lat=contactLocMap.get(phoneNum).getLatitude(); double lng=contactLocMap.get(phoneNum).getLongitude(); if (lat!=Double.POSITIVE_INFINITY&&lng!=Double.POSITIVE_INFINITY) { Intent i = new Intent(Intent.ACTION_VIEW); Uri routerUri = Uri.parse("http://maps.google.com/maps?f=d&saddr=" + myCloc.getLatitude()+","+myCloc.getLongitude()+ "&daddr=" + contactLocMap.get(phoneNum).getLatitude()+","+ contactLocMap.get(phoneNum).getLongitude() + "&hl=en"); Toast.makeText(this,R.string.toast_route_suceesgetloc, Toast.LENGTH_LONG).show(); i.setData(routerUri); startActivity(i); } else { Toast.makeText(this, R.string.toast_route_failgetloc, Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, R.string.toast_choice_one, Toast.LENGTH_SHORT).show(); } } break; case CONTEXT_MENU_ITEM_LOCATION_LIST: { List selectedIds = contactsListView.getAllSelectedItems(); if (selectedIds.size() == 1) { String phoneNum=selectedIds.get(0); Map contactLocMap = ContactManager.getInstance().getAllContactLocations(); double lat=contactLocMap.get(phoneNum).getLatitude(); double lng=contactLocMap.get(phoneNum).getLongitude(); if (lat!=Double.POSITIVE_INFINITY&&lng!=Double.POSITIVE_INFINITY) { String address=Location.getAddressByLatLng(lat, lng); Toast.makeText(this,phoneNum+"\nIn "+ address, Toast.LENGTH_LONG).show(); } else { Toast.makeText(this,R.string.toast_location_noaddress, Toast.LENGTH_LONG).show(); } }else { Toast.makeText(this, R.string.toast_choice_one, Toast.LENGTH_SHORT).show(); } } break; case CONTEXT_MENU_ITEM_SMS_LIST:{ ArrayList participantIds = (ArrayList) contactsListView .getAllSelectedItems(); String smsContacts=""; int size=1; for(String s:participantIds) { if(participantIds.size()>size) { smsContacts=smsContacts+s+";"; }else if(participantIds.size()==size) { smsContacts=smsContacts+s; } size++; } System.out.println(smsContacts); Uri smsToUri = Uri.parse("smsto:"+smsContacts);// 联系人地址 Intent i = new Intent(android.content.Intent.ACTION_SENDTO,smsToUri); i.putExtra("内容:", " "); startActivity(i); } break; default: break; } return false; } /** * Performs a phone call to a given contact. */ private void callContact(String selectedCPhoneNumber) { Intent i = new Intent(Intent.ACTION_CALL); Uri phoneUri = Uri.parse("tel:" + selectedCPhoneNumber); i.setData(phoneUri); startActivity(i); } /** * Start a new chat session with the given participants. */ private void launchChatSession(List participantIds) { //start a new session or retrieve it If the session already exists. its Id is retrieved String sessionId = MsnSessionManager.getInstance().startMsnSession( participantIds); //retrieve a copy of the session MsnSession session = MsnSessionManager.getInstance().retrieveSession( sessionId); //Add a notification for the new session ChatSessionNotificationManager.getInstance().addNewSessionNotification(sessionId); //packet an intent. We'll try to add the session ID in the intent data in URI form //We use intent resolution here, cause the ChatActivity should be selected matching ACTION and CATEGORY Intent it = new Intent(Intent.ACTION_MAIN); //set the data as an URI (content://sessionId#) it.setData(session.getSessionIdAsUri()); it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); it.setClass(this, ChatActivity.class); startActivity(it); } /** * Updates the adapter associated with this contact list view. */ private void updateListAdapter(ContactListChanges changes, Map contactMap, Map contactLocMap) { ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); adapter.update(changes, contactMap, contactLocMap); } /** * Initialize the list filling up its adapter with all the available data. * After initialization all changes shall be incremental (contacts added, contacts removed) */ //TODO:初始化联系人列表,从手机中读入联系人, private void initializeContactList() { ContactListAdapter adapter = ContactManager.getInstance().getAdapter(); //无顺序显示所有联系人 adapter.initialize(); //将在线联系人显示在最上面 adapter.initialize2(); //隐藏离线的联系人 //adapter.hideOffline(); contactsListView.setAdapter(adapter); overlay.initializePositions(); } /** * Defines an handler to show a toast when a contact disconnects * */ private class ContactDisconnectionHandler extends GuiEventHandler { /** * Handles the disconnection event */ protected void processEvent(MsnEvent event) { String eventName = event.getName(); if (eventName.equals(MsnEvent.CONTACT_DISCONNECT_EVENT)){ String discContactName = (String) event.getParam(MsnEvent.CONTACT_DISCONNECT_PARAM_CONTACTNAME); Toast.makeText(MainActivity.this, discContactName + getString(R.string.toast_discContact), Toast.LENGTH_LONG).show(); } } } /** * Handler for all events handled by the main {@link MainActivity} */ private class ContactListActivityUpdateHandler extends GuiEventHandler { /** * Handles both an incoming message and a refresh of the screen */ @SuppressWarnings("unchecked") protected void processEvent(MsnEvent event) { String eventName = event.getName(); if (eventName.equals(MsnEvent.VIEW_REFRESH_EVENT)){ ContactListChanges changes = (ContactListChanges) event.getParam(MsnEvent.VIEW_REFRESH_PARAM_LISTOFCHANGES); Map cMap = (Map) event.getParam(MsnEvent.VIEW_REFRESH_CONTACTSMAP); Map cLocMap = (Map) event.getParam(MsnEvent.VIEW_REFRESH_PARAM_LOCATIONMAP); Log.i("debug", "Thread "+ Thread.currentThread().getId() + ":GUI thread retrieves this list of changes from the event: " + changes.toString()); updateListAdapter(changes, cMap, cLocMap); overlay.update(changes, cMap, cLocMap); mapView.invalidate(); int selPos = contactsListView.getSelectedItemPosition(); ContactListAdapter adapter = ContactManager.getInstance() .getAdapter(); contactsListView.setAdapter(adapter); contactsListView.setSelection(selPos); } else if (eventName.equals(MsnEvent.INCOMING_MESSAGE_EVENT)){ Log.i("debug", "Thread "+ Thread.currentThread().getId() + ":Contact List activity received an INCOMING MSG EVENT!!!"); MsnSessionMessage msnMsg = (MsnSessionMessage) event.getParam(MsnEvent.INCOMING_MESSAGE_PARAM_MSG); String sessionId = (String) event.getParam(MsnEvent.INCOMING_MESSAGE_PARAM_SESSIONID); //if the incoming msg is not for our session, post a notification ChatSessionNotificationManager.getInstance().addNewMsgNotification(sessionId, msnMsg); Toast.makeText(MainActivity.this, msnMsg.getSenderName() +getString(R.string.toast_says) + msnMsg.getMessageContent(), Toast.LENGTH_LONG).show(); } } } /* * This method is needed to tell the Google server if we're showing info ???? */ protected boolean isRouteDisplayed() { return false; } ProgressDialog proDialog; public void showProDialog(Activity activity) { proDialog=new ProgressDialog(activity); proDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); proDialog.setTitle(R.string.prodialog_title); proDialog.setMessage(getString(R.string.prodialog_title)); proDialog.setIcon(R.drawable.prodialog); proDialog.setIndeterminate(false); proDialog.setCancelable(true); proDialog.show(); } //exit private long exitTime = 0; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){ if((System.currentTimeMillis()-exitTime) > 2000){ Toast.makeText(getApplicationContext(), R.string.toast_exit, Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else { MainActivity.this.finish(); //System.exit(0); } return true; } return super.onKeyDown(keyCode, event); } private void showNotification() { //创建一个Notification NotificationManager notificationManager=(NotificationManager) MainActivity.this.getSystemService(android.content.Context.NOTIFICATION_SERVICE); //定义Notification的各种属性 Notification notification=new Notification(R.drawable.notification,"",System.currentTimeMillis()); notification.flags|=Notification.FLAG_ONGOING_EVENT;//将此通知放到通知栏的"ongoing"即‘正在运行组中 notification.flags|=Notification.FLAG_NO_CLEAR;//表明在点击了通知栏的“清除通知”后,此通知不清楚,常与FLAG_ONGOING_EVENT一起使用 notification.flags|=Notification.FLAG_SHOW_LIGHTS; notification.defaults=Notification.DEFAULT_LIGHTS; notification.ledARGB=Color.BLUE; notification.ledOnMS=5000; //设置通知事件消息 CharSequence contentTitle="活点地图"; CharSequence contentText="正在运行..."; Intent notificationIntent=new Intent(this,MainActivity.class);//点击该通知后要跳转的Activity PendingIntent contentIntent=PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); //把Notification传递给NotificationManager notificationManager.notify(0,notification); } }