📄 contactlistactivity.java
字号:
handled = mContactListView.dispatchKeyEvent(event); if (!handled && isReadable(keyCode, event) && (KeyEvent.ACTION_DOWN == event.getAction())) { showFilterView(); handled = mFilterView.dispatchKeyEvent(event); } } if (!handled) { handled = super.dispatchKeyEvent(event); } return handled; } private static boolean isReadable(int keyCode, KeyEvent event) { if (KeyEvent.isModifierKey(keyCode) || event.isSystem()) { return false; } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_ENTER: return false; } return true; } private void showFilterView() { if (mFilterView == null ) { mFilterView = (ContactListFilterView)getLayoutInflater().inflate( R.layout.contact_list_filter_view, null); mFilterView.getListView().setOnCreateContextMenuListener(this); } Uri uri = mSettingMap.getHideOfflineContacts() ? Im.Contacts.CONTENT_URI_ONLINE_CONTACTS_BY : Im.Contacts.CONTENT_URI_CONTACTS_BY; uri = ContentUris.withAppendedId(uri, mProviderId); uri = ContentUris.withAppendedId(uri, mAccountId); mFilterView.doFilter(uri, null); setContentView(mFilterView); mFilterView.requestFocus(); mIsFiltering = true; } void showContactListView() { if (mIsFiltering) { setContentView(mContactListView); mContactListView.requestFocus(); mContactListView.invalidate(); mIsFiltering = false; } } @Override protected void onPause() { super.onPause(); mApp.unregisterForConnEvents(mHandler); } @Override protected void onResume() { super.onResume(); mApp.registerForConnEvents(mHandler); } @Override protected void onDestroy() { mDestroyed = true; // set connection to null to unregister listeners. mContactListView.setConnection(null); if (mSettingMap != null) { mSettingMap.close(); } super.onDestroy(); } static void log(String msg) { Log.d(ImApp.LOG_TAG, "<ContactListActivity> " +msg); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { boolean chatSelected = false; boolean contactSelected = false; Cursor contactCursor; if (mIsFiltering) { AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; mContextMenuHandler.mPosition = info.position; contactSelected = true; contactCursor = mFilterView.getContactAtPosition(info.position); } else { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo; mContextMenuHandler.mPosition = info.packedPosition; contactSelected = mContactListView.isContactAtPosition(info.packedPosition); chatSelected = mContactListView.isConversationAtPosition(info.packedPosition); contactCursor = mContactListView.getContactAtPosition(info.packedPosition); } boolean allowBlock = true; if (contactCursor != null) { //XXX HACK: Yahoo! doesn't allow to block a friend. We can only block a temporary contact. ProviderDef provider = mApp.getProvider(mProviderId); if (Im.ProviderNames.YAHOO.equals(provider.mName)) { int type = contactCursor.getInt(contactCursor.getColumnIndexOrThrow(Im.Contacts.TYPE)); allowBlock = (type == Im.Contacts.TYPE_TEMPORARY); } int nickNameIndex = contactCursor.getColumnIndexOrThrow(Im.Contacts.NICKNAME); menu.setHeaderTitle(contactCursor.getString(nickNameIndex)); } BrandingResources brandingRes = mApp.getBrandingResource(mProviderId); String menu_end_conversation = brandingRes.getString( BrandingResourceIDs.STRING_MENU_END_CHAT); String menu_view_profile = brandingRes.getString( BrandingResourceIDs.STRING_MENU_VIEW_PROFILE); String menu_block_contact = brandingRes.getString( BrandingResourceIDs.STRING_MENU_BLOCK_CONTACT); String menu_start_conversation = brandingRes.getString( BrandingResourceIDs.STRING_MENU_START_CHAT); String menu_delete_contact = brandingRes.getString( BrandingResourceIDs.STRING_MENU_DELETE_CONTACT); if (chatSelected) { menu.add(0, MENU_END_CONVERSATION, 0, menu_end_conversation) .setIcon(R.drawable.ic_menu_end_conversation) .setOnMenuItemClickListener(mContextMenuHandler); menu.add(0, MENU_VIEW_PROFILE, 0, menu_view_profile) .setIcon(R.drawable.ic_menu_my_profile) .setOnMenuItemClickListener(mContextMenuHandler); if (allowBlock) { menu.add(0, MENU_BLOCK_CONTACT, 0, menu_block_contact) .setIcon(R.drawable.ic_menu_block) .setOnMenuItemClickListener(mContextMenuHandler); } } else if (contactSelected) { menu.add(0, MENU_START_CONVERSATION, 0, menu_start_conversation) .setIcon(R.drawable.ic_menu_start_conversation) .setOnMenuItemClickListener(mContextMenuHandler); menu.add(0, MENU_VIEW_PROFILE, 0, menu_view_profile) .setIcon(R.drawable.ic_menu_view_profile) .setOnMenuItemClickListener(mContextMenuHandler); if (allowBlock) { menu.add(0, MENU_BLOCK_CONTACT, 0, menu_block_contact) .setIcon(R.drawable.ic_menu_block) .setOnMenuItemClickListener(mContextMenuHandler); } menu.add(0, MENU_DELETE_CONTACT, 0, menu_delete_contact) .setIcon(android.R.drawable.ic_menu_delete) .setOnMenuItemClickListener(mContextMenuHandler); } } final class ContextMenuHandler implements MenuItem.OnMenuItemClickListener { long mPosition; public boolean onMenuItemClick(MenuItem item) { Cursor c; if (mIsFiltering) { c = mFilterView.getContactAtPosition((int)mPosition); } else { c = mContactListView.getContactAtPosition(mPosition); } switch (item.getItemId()) { case MENU_START_CONVERSATION: mContactListView.startChat(c); break; case MENU_VIEW_PROFILE: mContactListView.viewContactPresence(c); break; case MENU_BLOCK_CONTACT: mContactListView.blockContact(c); break; case MENU_DELETE_CONTACT: mContactListView.removeContact(c); break; case MENU_END_CONVERSATION: mContactListView.endChat(c); break; default: return false; } if (mIsFiltering) { showContactListView(); } return true; } } final class MyHandler extends SimpleAlertHandler { public MyHandler(Activity activity) { super(activity); } @Override public void handleMessage(Message msg) { if (msg.what == ImApp.EVENT_CONNECTION_DISCONNECTED) { if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) { log("Handle event connection disconnected."); } promptDisconnectedEvent(msg); long providerId = ((long)msg.arg1 << 32) | msg.arg2; if (providerId == mProviderId) { if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) { log("Current connection disconnected, finish"); } finish(); } return; } super.handleMessage(msg); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -