实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 | package com.way.activity; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; import android.database.ContentObserver; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.ScrollView; import android.widget.TextView; import com.way.adapter.RosterAdapter; import com.way.app.XXBroadcastReceiver; import com.way.app.XXBroadcastReceiver.EventHandler; import com.way.db.ChatProvider; import com.way.db.RosterProvider; import com.way.db.RosterProvider.RosterConstants; import com.way.fragment.RecentChatFragment; import com.way.fragment.SettingsFragment; import com.way.iphonetreeview.IphoneTreeView; import com.way.pulltorefresh.PullToRefreshBase; import com.way.pulltorefresh.PullToRefreshBase.OnRefreshListener; import com.way.pulltorefresh.PullToRefreshScrollView; import com.way.quickaction.ActionItem; import com.way.quickaction.QuickAction; import com.way.quickaction.QuickAction.OnActionItemClickListener; import com.way.service.IConnectionStatusCallback; import com.way.service.XXService; import com.way.slidingmenu.BaseSlidingFragmentActivity; import com.way.slidingmenu.SlidingMenu; import com.way.util.L; import com.way.util.NetUtil; import com.way.util.PreferenceConstants; import com.way.util.PreferenceUtils; import com.way.util.StatusMode; import com.way.util.T; import com.way.util.XMPPHelper; import com.way.view.AddRosterItemDialog; import com.way.view.CustomDialog; import com.way.view.GroupNameView; import com.way.xx.R; public class MainActivity extends BaseSlidingFragmentActivity implements OnClickListener, IConnectionStatusCallback, EventHandler, FragmentCallBack { private static final int ID_CHAT = 0 ; private static final int ID_AVAILABLE = 1 ; private static final int ID_AWAY = 2 ; private static final int ID_XA = 3 ; private static final int ID_DND = 4 ; public static HashMap<String, Integer> mStatusMap; static { mStatusMap = new HashMap<String, Integer>(); mStatusMap.put(PreferenceConstants.OFFLINE, - 1 ); mStatusMap.put(PreferenceConstants.DND, R.drawable.status_shield); mStatusMap.put(PreferenceConstants.XA, R.drawable.status_invisible); mStatusMap.put(PreferenceConstants.AWAY, R.drawable.status_leave); mStatusMap.put(PreferenceConstants.AVAILABLE, R.drawable.status_online); mStatusMap.put(PreferenceConstants.CHAT, R.drawable.status_qme); } private Handler mainHandler = new Handler(); private XXService mXxService; private SlidingMenu mSlidingMenu; private View mNetErrorView; private TextView mTitleNameView; private ImageView mTitleStatusView; private ProgressBar mTitleProgressBar; private PullToRefreshScrollView mPullRefreshScrollView; private IphoneTreeView mIphoneTreeView; private RosterAdapter mRosterAdapter; private ContentObserver mRosterObserver = new RosterObserver(); private int mLongPressGroupId, mLongPressChildId; ServiceConnection mServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { mXxService = ((XXService.XXBinder) service).getService(); mXxService.registerConnectionStatusCallback(MainActivity. this ); // 开始连接xmpp服务器 if (!mXxService.isAuthenticated()) { String usr = PreferenceUtils.getPrefString(MainActivity. this , PreferenceConstants.ACCOUNT, "" ); String password = PreferenceUtils.getPrefString( MainActivity. this , PreferenceConstants.PASSWORD, "" ); mXxService.Login(usr, password); // mTitleNameView.setText(R.string.login_prompt_msg); // setStatusImage(false); // mTitleProgressBar.setVisibility(View.VISIBLE); } else { mTitleNameView.setText(XMPPHelper .splitJidAndServer(PreferenceUtils.getPrefString( MainActivity. this , PreferenceConstants.ACCOUNT, "" ))); setStatusImage( true ); mTitleProgressBar.setVisibility(View.GONE); } } @Override public void onServiceDisconnected(ComponentName name) { mXxService.unRegisterConnectionStatusCallback(); mXxService = null ; } }; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); startService( new Intent(MainActivity. this , XXService. class )); initSlidingMenu(); setContentView(R.layout.main_center_layout); initViews(); registerListAdapter(); } /** * 连续按两次返回键就退出 */ private long firstTime; @Override public void onBackPressed() { if (System.currentTimeMillis() - firstTime < 3000 ) { finish(); } else { firstTime = System.currentTimeMillis(); T.showShort( this , R.string.press_again_backrun); } } @Override protected void onResume() { super .onResume(); bindXMPPService(); getContentResolver().registerContentObserver( RosterProvider.CONTENT_URI, true , mRosterObserver); setStatusImage(isConnected()); mRosterAdapter.requery(); XXBroadcastReceiver.mListeners.add( this ); if (NetUtil.getNetworkState( this ) == NetUtil.NETWORN_NONE) mNetErrorView.setVisibility(View.VISIBLE); else mNetErrorView.setVisibility(View.GONE); } @Override protected void onPause() { super .onPause(); getContentResolver().unregisterContentObserver(mRosterObserver); unbindXMPPService(); XXBroadcastReceiver.mListeners.remove( this ); } @Override protected void onDestroy() { super .onDestroy(); } private void registerListAdapter() { mRosterAdapter = new RosterAdapter( this , mIphoneTreeView, mPullRefreshScrollView); mIphoneTreeView.setAdapter(mRosterAdapter); mRosterAdapter.requery(); } private void unbindXMPPService() { try { unbindService(mServiceConnection); L.i(LoginActivity. class , "[SERVICE] Unbind" ); } catch (IllegalArgumentException e) { L.e(LoginActivity. class , "Service wasn't bound!" ); } } private void bindXMPPService() { L.i(LoginActivity. class , "[SERVICE] Unbind" ); bindService( new Intent(MainActivity. this , XXService. class ), mServiceConnection, Context.BIND_AUTO_CREATE Context.BIND_DEBUG_UNBIND); } private void initViews() { mNetErrorView = findViewById(R.id.net_status_bar_top); mSlidingMenu.setSecondaryMenu(R.layout.main_right_layout); FragmentTransaction mFragementTransaction = getSupportFragmentManager() .beginTransaction(); Fragment mFrag = new SettingsFragment(); mFragementTransaction.replace(R.id.main_right_fragment, mFrag); mFragementTransaction.commit(); ImageButton mLeftBtn = ((ImageButton) findViewById(R.id.show_left_fragment_btn)); mLeftBtn.setVisibility(View.VISIBLE); mLeftBtn.setOnClickListener( this ); ImageButton mRightBtn = ((ImageButton) findViewById(R.id.show_right_fragment_btn)); mRightBtn.setVisibility(View.VISIBLE); mRightBtn.setOnClickListener( this ); mTitleNameView = (TextView) findViewById(R.id.ivTitleName); mTitleProgressBar = (ProgressBar) findViewById(R.id.ivTitleProgress); mTitleStatusView = (ImageView) findViewById(R.id.ivTitleStatus); mTitleNameView.setText(XMPPHelper.splitJidAndServer(PreferenceUtils .getPrefString( this , PreferenceConstants.ACCOUNT, "" ))); mTitleNameView.setOnClickListener( this ); mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview); // mPullRefreshScrollView.setMode(Mode.DISABLED); // mPullRefreshScrollView.getLoadingLayoutProxy().setLastUpdatedLabel( // "最近更新:刚刚"); mPullRefreshScrollView .setOnRefreshListener( new OnRefreshListener<ScrollView>() { @Override public void onRefresh( PullToRefreshBase<ScrollView> refreshView) { new GetDataTask().execute(); } }); mIphoneTreeView = (IphoneTreeView) findViewById(R.id.iphone_tree_view); mIphoneTreeView.setHeaderView(getLayoutInflater().inflate( R.layout.contact_buddy_list_group, mIphoneTreeView, false )); mIphoneTreeView.setEmptyView(findViewById(R.id.empty)); mIphoneTreeView .setOnItemLongClickListener( new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { int groupPos = (Integer) view.getTag(R.id.xxx01); // 参数值是在setTag时使用的对应资源id号 int childPos = (Integer) view.getTag(R.id.xxx02); mLongPressGroupId = groupPos; mLongPressChildId = childPos; if (childPos == - 1 ) { // 长按的是父项 // 根据groupPos判断你长按的是哪个父项,做相应处理(弹框等) showGroupQuickActionBar(view .findViewById(R.id.group_name)); // T.showShort(MainActivity.this, // "LongPress group position = " groupPos); } else { // 根据groupPos及childPos判断你长按的是哪个父项下的哪个子项,然后做相应处理。 // T.showShort(MainActivity.this, // "onClick child position = " groupPos // ":" childPos); showChildQuickActionBar(view .findViewById(R.id.icon)); } return false ; } }); mIphoneTreeView.setOnChildClickListener( new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { String userJid = mRosterAdapter.getChild(groupPosition, childPosition).getJid(); String userName = mRosterAdapter.getChild(groupPosition, childPosition).getAlias(); startChatActivity(userJid, userName); return false ; } }); } private void startChatActivity(String userJid, String userName) { Intent chatIntent = new Intent(MainActivity. this , ChatActivity. class ); Uri userNameUri = Uri.parse(userJid); chatIntent.setData(userNameUri); chatIntent.putExtra(ChatActivity.INTENT_EXTRA_USERNAME, userName); startActivity(chatIntent); } private boolean isConnected() { return mXxService != null && mXxService.isAuthenticated(); } private void showGroupQuickActionBar(View view) { QuickAction quickAction = new QuickAction( this , QuickAction.HORIZONTAL); quickAction .addActionItem( new ActionItem( 0 , getString(R.string.rename))); quickAction.addActionItem( new ActionItem( 1 , getString(R.string.add_friend))); quickAction .setOnActionItemClickListener( new OnActionItemClickListener() { @Override public void onItemClick(QuickAction source, int pos, int actionId) { // 如果没有连接直接返回 if (!isConnected()) { T.showShort(MainActivity. this , R.string.conversation_net_error_label); return ; } switch (actionId) { case 0 : String groupName = mRosterAdapter.getGroup( mLongPressGroupId).getGroupName(); if (TextUtils.isEmpty(groupName)) { // 系统默认分组不允许重命名 T.showShort(MainActivity. this , R.string.roster_group_rename_failed); return ; } renameRosterGroupDialog(mRosterAdapter.getGroup( mLongPressGroupId).getGroupName()); break ; case 1 : new AddRosterItemDialog(MainActivity. this , mXxService).show(); // 添加联系人 break ; default : break ; } } }); quickAction.show(view); quickAction.setAnimStyle(QuickAction.ANIM_GROW_FROM_CENTER); } private void showChildQuickActionBar(View view) { QuickAction quickAction = new QuickAction( this , QuickAction.HORIZONTAL); quickAction.addActionItem( new ActionItem( 0 , getString(R.string.open))); quickAction .addActionItem( new ActionItem( 1 , getString(R.string.rename))); quickAction.addActionItem( new ActionItem( 2 , getString(R.string.move))); quickAction .addActionItem( new ActionItem( 3 , getString(R.string.delete))); quickAction .setOnActionItemClickListener( new OnActionItemClickListener() { @Override public void onItemClick(QuickAction source, int pos, int actionId) { String userJid = mRosterAdapter.getChild( mLongPressGroupId, mLongPressChildId).getJid(); String userName = mRosterAdapter.getChild( mLongPressGroupId, mLongPressChildId) .getAlias(); switch (actionId) { case 0 : startChatActivity(userJid, userName); break ; case 1 : if (!isConnected()) { T.showShort(MainActivity. this , R.string.conversation_net_error_label); break ; } renameRosterItemDialog(userJid, userName); break ; case 2 : if (!isConnected()) { T.showShort(MainActivity. this , R.string.conversation_net_error_label); break ; } moveRosterItemToGroupDialog(userJid); break ; case 3 : if (!isConnected()) { T.showShort(MainActivity. this , R.string.conversation_net_error_label); break ; } removeRosterItemDialog(userJid, userName); break ; default : break ; } } }); quickAction.show(view); } private void initSlidingMenu() { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int mScreenWidth = dm.widthPixels; // 获取屏幕分辨率宽度 setBehindContentView(R.layout.main_left_layout); // 设置左菜单 FragmentTransaction mFragementTransaction = getSupportFragmentManager() .beginTransaction(); Fragment mFrag = new RecentChatFragment(); mFragementTransaction.replace(R.id.main_left_fragment, mFrag); mFragementTransaction.commit(); // customize the SlidingMenu mSlidingMenu = getSlidingMenu(); mSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT); // 设置是左滑还是右滑,还是左右都可以滑,我这里左右都可以滑 mSlidingMenu.setShadowWidth(mScreenWidth / 40 ); // 设置阴影宽度 mSlidingMenu.setBehindOffset(mScreenWidth / 8 ); // 设置菜单宽度 mSlidingMenu.setFadeDegree( 0 .35f); // 设置淡入淡出的比例 mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN); mSlidingMenu.setShadowDrawable(R.drawable.shadow_left); // 设置左菜单阴影图片 mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right); // 设置右菜单阴影图片 mSlidingMenu.setFadeEnabled( true ); // 设置滑动时菜单的是否淡入淡出 mSlidingMenu.setBehindScrollScale( 0 .333f); // 设置滑动时拖拽效果 } private static final String[] GROUPS_QUERY = new String[] { RosterConstants._ID, RosterConstants.GROUP, }; private static final String[] ROSTER_QUERY = new String[] { RosterConstants._ID, RosterConstants.JID, RosterConstants.ALIAS, RosterConstants.STATUS_MODE, RosterConstants.STATUS_MESSAGE, }; public List<String> getRosterGroups() { // we want all, online and offline List<String> list = new ArrayList<String>(); Cursor cursor = getContentResolver().query(RosterProvider.GROUPS_URI, GROUPS_QUERY, null , null , RosterConstants.GROUP); int idx = cursor.getColumnIndex(RosterConstants.GROUP); cursor.moveToFirst(); while (!cursor.isAfterLast()) { list.add(cursor.getString(idx)); cursor.moveToNext(); } cursor.close(); return list; } public List<String[]> getRosterContacts() { // we want all, online and offline List<String[]> list = new ArrayList<String[]>(); Cursor cursor = getContentResolver().query(RosterProvider.CONTENT_URI, ROSTER_QUERY, null , null , RosterConstants.ALIAS); int JIDIdx = cursor.getColumnIndex(RosterConstants.JID); int aliasIdx = cursor.getColumnIndex(RosterConstants.ALIAS); cursor.moveToFirst(); while (!cursor.isAfterLast()) { String jid = cursor.getString(JIDIdx); String alias = cursor.getString(aliasIdx); if ((alias == null ) || (alias.length() == 0 )) alias = jid; list.add( new String[] { jid, alias }); cursor.moveToNext(); } cursor.close(); return list; } protected void setViewImage(ImageView v, String value) { int presenceMode = Integer.parseInt(value); int statusDrawable = getIconForPresenceMode(presenceMode); v.setImageResource(statusDrawable); if (statusDrawable == R.drawable.status_busy) v.setVisibility(View.INVISIBLE); } private int getIconForPresenceMode( int presenceMode) { return StatusMode.values()[presenceMode].getDrawableId(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.show_left_fragment_btn: mSlidingMenu.showMenu( true ); break ; case R.id.show_right_fragment_btn: mSlidingMenu.showSecondaryMenu( true ); break ; case R.id.ivTitleName: if (isConnected()) showStatusQuickAction(v); break ; default : break ; } } private void showStatusQuickAction(View v) { QuickAction quickAction = new QuickAction( this , QuickAction.VERTICAL); quickAction.addActionItem( new ActionItem(ID_CHAT, getString(R.string.status_chat), getResources().getDrawable( R.drawable.status_qme))); quickAction.addActionItem( new ActionItem(ID_AVAILABLE, getString(R.string.status_available), getResources() .getDrawable(R.drawable.status_online))); quickAction.addActionItem( new ActionItem(ID_AWAY, getString(R.string.status_away), getResources().getDrawable( R.drawable.status_leave))); quickAction.addActionItem( new ActionItem(ID_XA, getString(R.string.status_xa), getResources().getDrawable( R.drawable.status_invisible))); quickAction.addActionItem( new ActionItem(ID_DND, getString(R.string.status_dnd), getResources().getDrawable( R.drawable.status_shield))); quickAction .setOnActionItemClickListener( new OnActionItemClickListener() { @Override public void onItemClick(QuickAction source, int pos, int actionId) { // TODO Auto-generated method stub if (!isConnected()) { T.showShort(MainActivity. this , R.string.conversation_net_error_label); return ; } switch (actionId) { case ID_CHAT: mTitleStatusView .setImageResource(R.drawable.status_qme); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MODE, PreferenceConstants.CHAT); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MESSAGE, getString(R.string.status_chat)); break ; case ID_AVAILABLE: mTitleStatusView .setImageResource(R.drawable.status_online); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MODE, PreferenceConstants.AVAILABLE); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MESSAGE, getString(R.string.status_available)); break ; case ID_AWAY: mTitleStatusView .setImageResource(R.drawable.status_leave); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MODE, PreferenceConstants.AWAY); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MESSAGE, getString(R.string.status_away)); break ; case ID_XA: mTitleStatusView .setImageResource(R.drawable.status_invisible); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MODE, PreferenceConstants.XA); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MESSAGE, getString(R.string.status_xa)); break ; case ID_DND: mTitleStatusView .setImageResource(R.drawable.status_shield); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MODE, PreferenceConstants.DND); PreferenceUtils.setPrefString(MainActivity. this , PreferenceConstants.STATUS_MESSAGE, getString(R.string.status_dnd)); break ; default : break ; } mXxService.setStatusFromConfig(); SettingsFragment fragment = (SettingsFragment) getSupportFragmentManager() .findFragmentById(R.id.main_right_fragment); fragment.readData(); } }); quickAction.show(v); } public abstract class EditOk { abstract public void ok(String result); } void removeChatHistory( final String JID) { getContentResolver().delete(ChatProvider.CONTENT_URI, ChatProvider.ChatConstants.JID " = ?" , new String[] { JID }); } void removeRosterItemDialog( final String JID, final String userName) { new CustomDialog.Builder( this ) .setTitle(R.string.deleteRosterItem_title) .setMessage( getString(R.string.deleteRosterItem_text, userName, JID)) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mXxService.removeRosterItem(JID); } }) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create().show(); } private void editTextDialog( int titleId, CharSequence message, String text, final EditOk ok) { LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.edittext_dialog, null ); TextView messageView = (TextView) layout.findViewById(R.id.text); messageView.setText(message); final EditText input = (EditText) layout.findViewById(R.id.editText); input.setTransformationMethod(android.text.method.SingleLineTransformationMethod .getInstance()); input.setText(text); new CustomDialog.Builder( this ) .setTitle(titleId) .setView(layout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String newName = input.getText().toString(); if (newName.length() != 0 ) ok.ok(newName); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create().show(); } void renameRosterItemDialog( final String JID, final String userName) { editTextDialog(R.string.RenameEntry_title, getString(R.string.RenameEntry_summ, userName, JID), userName, new EditOk() { public void ok(String result) { if (mXxService != null ) mXxService.renameRosterItem(JID, result); } }); } void renameRosterGroupDialog( final String groupName) { editTextDialog(R.string.RenameGroup_title, getString(R.string.RenameGroup_summ, groupName), groupName, new EditOk() { public void ok(String result) { if (mXxService != null ) mXxService.renameRosterGroup(groupName, result); } }); } void moveRosterItemToGroupDialog( final String jabberID) { LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View group = inflater .inflate(R.layout.moverosterentrytogroupview, null ); final GroupNameView gv = (GroupNameView) group .findViewById(R.id.moverosterentrytogroupview_gv); gv.setGroupList(getRosterGroups()); new CustomDialog.Builder( this ) .setTitle(R.string.MoveRosterEntryToGroupDialog_title) .setView(group) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { L.d( "new group: " gv.getGroupName()); if (isConnected()) mXxService.moveRosterItemToGroup(jabberID, gv.getGroupName()); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create().show(); } @Override public void onNetChange() { if (NetUtil.getNetworkState( this ) == NetUtil.NETWORN_NONE) { T.showShort( this , R.string.net_error_tip); mNetErrorView.setVisibility(View.VISIBLE); } else { mNetErrorView.setVisibility(View.GONE); } } private void setStatusImage( boolean isConnected) { if (!isConnected) { mTitleStatusView.setVisibility(View.GONE); return ; } String statusMode = PreferenceUtils.getPrefString( this , PreferenceConstants.STATUS_MODE, PreferenceConstants.AVAILABLE); int statusId = mStatusMap.get(statusMode); if (statusId == - 1 ) { mTitleStatusView.setVisibility(View.GONE); } else { mTitleStatusView.setVisibility(View.VISIBLE); mTitleStatusView.setImageResource(statusId); } } @Override public void connectionStatusChanged( int connectedState, String reason) { switch (connectedState) { case XXService.CONNECTED: mTitleNameView.setText(XMPPHelper.splitJidAndServer(PreferenceUtils .getPrefString(MainActivity. this , PreferenceConstants.ACCOUNT, "" ))); mTitleProgressBar.setVisibility(View.GONE); // mTitleStatusView.setVisibility(View.GONE); setStatusImage( true ); break ; case XXService.CONNECTING: mTitleNameView.setText(R.string.login_prompt_msg); mTitleProgressBar.setVisibility(View.VISIBLE); mTitleStatusView.setVisibility(View.GONE); break ; case XXService.DISCONNECTED: mTitleNameView.setText(R.string.login_prompt_no); mTitleProgressBar.setVisibility(View.GONE); mTitleStatusView.setVisibility(View.GONE); T.showLong( this , reason); break ; default : break ; } } @Override public XXService getService() { return mXxService; } @Override public MainActivity getMainActivity() { return this ; } public void updateRoster() { mRosterAdapter.requery(); } private class RosterObserver extends ContentObserver { public RosterObserver() { super (mainHandler); } public void onChange( boolean selfChange) { L.d(MainActivity. class , "RosterObserver.onChange: " selfChange); if (mRosterAdapter != null ) mainHandler.postDelayed( new Runnable() { public void run() { updateRoster(); } }, 100 ); } } private class GetDataTask extends AsyncTask<Void, Void, String[]> { @Override protected void onPreExecute() { super .onPreExecute(); // if (mPullRefreshScrollView.getState() != State.REFRESHING) // mPullRefreshScrollView.setState(State.REFRESHING, true); } @Override protected String[] doInBackground(Void... params) { // Simulates a background job. if (!isConnected()) { // 如果没有连接重新连接 String usr = PreferenceUtils.getPrefString(MainActivity. this , PreferenceConstants.ACCOUNT, "" ); String password = PreferenceUtils.getPrefString( MainActivity. this , PreferenceConstants.PASSWORD, "" ); mXxService.Login(usr, password); } try { Thread.sleep( 2000 ); } catch (InterruptedException e) { } return null ; } @Override protected void onPostExecute(String[] result) { // Do some stuff here // Call onRefreshComplete when the list has been refreshed. mRosterAdapter.requery(); // 重新查询一下数据库 mPullRefreshScrollView.onRefreshComplete(); // mPullRefreshScrollView.getLoadingLayoutProxy().setLastUpdatedLabel( // "最近更新:刚刚"); T.showShort(MainActivity. this , "刷新成功!" ); super .onPostExecute(result); } } } |
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论