📄 chatview.java
字号:
.setTitle(R.string.confirm) .setMessage(r.getString(R.string.confirm_block_contact, mNickName)) .setPositiveButton(R.string.no, null) // default button .setNegativeButton(R.string.yes, confirmListener) .setCancelable(false) .show(); } public long getProviderId() { return mProviderId; } public long getAccountId() { return mAccountId; } public String getUserName() { return mUserName; } public long getChatId () { try { return mChatSession == null ? -1 : mChatSession.getId(); } catch (RemoteException e) { mHandler.showServiceErrorAlert(); return -1; } } public IChatSession getCurrentChatSession() { return mChatSession; } private IChatSessionManager getChatSessionManager(long providerId) { if (mChatSessionMgr == null) { IImConnection conn = mApp.getConnection(providerId); if (conn != null) { try { mChatSessionMgr = conn.getChatSessionManager(); } catch (RemoteException e) { mHandler.showServiceErrorAlert(); } } } return mChatSessionMgr; } private IChatSession getChatSession(Cursor cursor) { long providerId = cursor.getLong(PROVIDER_COLUMN); String username = cursor.getString(USERNAME_COLUMN); IChatSessionManager sessionMgr = getChatSessionManager(providerId); if (sessionMgr != null) { try { return sessionMgr.getChatSession(username); } catch (RemoteException e) { mHandler.showServiceErrorAlert(); } } return null; } boolean isGroupChat() { return Im.Contacts.TYPE_GROUP == mType; } void sendMessage() { String msg = mEdtInput.getText().toString(); if (mChatSession != null && !TextUtils.isEmpty(msg.trim())) { try { mChatSession.sendMessage(msg); mEdtInput.setText(""); mEdtInput.requestFocus(); requeryCursor(); } catch (RemoteException e) { mHandler.showServiceErrorAlert(); } } } void registerChatListener() { if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)){ log("registerChatListener"); } try { if (mChatSession != null) { mChatSession.registerChatListener(mChatListener); } IImConnection conn = mApp.getConnection(mProviderId); if (conn != null) { IContactListManager listMgr = conn.getContactListManager(); listMgr.registerContactListListener(mContactListListener); } mApp.dismissNotifications(mProviderId); } catch (RemoteException e) { Log.w(ImApp.LOG_TAG, "<ChatView> registerChatListener fail:" + e.getMessage()); } } void unregisterChatListener() { if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)){ log("unregisterChatListener"); } try { if (mChatSession != null) { mChatSession.unregisterChatListener(mChatListener); } IImConnection conn = mApp.getConnection(mProviderId); if (conn != null) { IContactListManager listMgr = conn.getContactListManager(); listMgr.unregisterContactListListener(mContactListListener); } } catch (RemoteException e) { Log.w(ImApp.LOG_TAG, "<ChatView> unregisterChatListener fail:" + e.getMessage()); } } void registerChatSessionListener() { IChatSessionManager sessionMgr = getChatSessionManager(mProviderId); if (sessionMgr != null) { mChatSessionListener = new ChatSessionListener(); try { sessionMgr.registerChatSessionListener(mChatSessionListener); } catch (RemoteException e) { mHandler.showServiceErrorAlert(); } } } void unregisterChatSessionListener() { if (mChatSessionListener != null) { try { IChatSessionManager sessionMgr = getChatSessionManager(mProviderId); sessionMgr.unregisterChatSessionListener(mChatSessionListener); // We unregister the listener when the chat session we are // waiting for has been created or the activity is stopped. // Clear the listener so that we won't unregister the listener // twice. mChatSessionListener = null; } catch (RemoteException e) { mHandler.showServiceErrorAlert(); } } } void updateWarningView() { int visibility = View.GONE; int iconVisibility = View.GONE; String message = null; boolean isConnected; try { IImConnection conn = mApp.getConnection(mProviderId); isConnected = (conn == null) ? false : conn.getState() != ImConnection.SUSPENDED; } catch (RemoteException e) { // do nothing return; } if (isConnected) { if (mType == Im.Contacts.TYPE_TEMPORARY) { visibility = View.VISIBLE; message = mContext.getString(R.string.contact_not_in_list_warning, mNickName); } else if (mPresenceStatus == Im.Presence.OFFLINE) { visibility = View.VISIBLE; message = mContext.getString(R.string.contact_offline_warning, mNickName); } } else { visibility = View.VISIBLE; iconVisibility = View.VISIBLE; message = mContext.getString(R.string.disconnected_warning); } mStatusWarningView.setVisibility(visibility); if (visibility == View.VISIBLE) { mWarningIcon.setVisibility(iconVisibility); mWarningText.setText(message); } } private final class ChatViewHandler extends SimpleAlertHandler { public ChatViewHandler() { super(mScreen); } @Override public void handleMessage(Message msg) { long providerId = ((long)msg.arg1 << 32) | msg.arg2; if (providerId != mProviderId) { return; } switch(msg.what) { case ImApp.EVENT_CONNECTION_LOGGED_IN: log("Connection resumed"); updateWarningView(); return; case ImApp.EVENT_CONNECTION_SUSPENDED: log("Connection suspended"); updateWarningView(); return; } super.handleMessage(msg); } } class ChatSessionListener extends ChatSessionListenerAdapter { @Override public void onChatSessionCreated(IChatSession session) { try { if (session.isGroupChatSession()) { final long id = session.getId(); unregisterChatSessionListener(); mHandler.post(new Runnable() { public void run() { bindChat(id); }}); } } catch (RemoteException e) { mHandler.showServiceErrorAlert(); } } } public static class DeltaCursor implements Cursor { static final String DELTA_COLUMN_NAME = "delta"; private Cursor mCursor; private String[] mColumnNames; private int mDateColumn = -1; private int mDeltaColumn = -1; DeltaCursor(Cursor cursor) { mCursor = cursor; String[] columnNames = cursor.getColumnNames(); int len = columnNames.length; mColumnNames = new String[len + 1]; for (int i = 0 ; i < len ; i++) { mColumnNames[i] = columnNames[i]; if (mColumnNames[i].equals(Im.BaseMessageColumns.DATE)) { mDateColumn = i; } } mDeltaColumn = len; mColumnNames[mDeltaColumn] = DELTA_COLUMN_NAME; //if (DBG) log("##### DeltaCursor constructor: mDeltaColumn=" + // mDeltaColumn + ", columnName=" + mColumnNames[mDeltaColumn]); } public int getCount() { return mCursor.getCount(); } public int getPosition() { return mCursor.getPosition(); } public boolean move(int offset) { return mCursor.move(offset); } public boolean moveToPosition(int position) { return mCursor.moveToPosition(position); } public boolean moveToFirst() { return mCursor.moveToFirst(); } public boolean moveToLast() { return mCursor.moveToLast(); } public boolean moveToNext() { return mCursor.moveToNext(); } public boolean moveToPrevious() { return mCursor.moveToPrevious(); } public boolean isFirst() { return mCursor.isFirst(); } public boolean isLast() { return mCursor.isLast(); } public boolean isBeforeFirst() { return mCursor.isBeforeFirst(); } public boolean isAfterLast() { return mCursor.isAfterLast(); } public boolean deleteRow() { return mCursor.deleteRow(); } public int getColumnIndex(String columnName) { if (DELTA_COLUMN_NAME.equals(columnName)) { return mDeltaColumn; } int columnIndex = mCursor.getColumnIndex(columnName); return columnIndex; } public int getColumnIndexOrThrow(String columnName) throws IllegalArgumentException { if (DELTA_COLUMN_NAME.equals(columnName)) { return mDeltaColumn; } return mCursor.getColumnIndexOrThrow(columnName); } public String getColumnName(int columnIndex) { if (columnIndex == mDeltaColumn) { return DELTA_COLUMN_NAME; } return mCursor.getColumnName(columnIndex); } public int getColumnCount() { return mCursor.getColumnCount() + 1; } public boolean supportsUpdates() { return mCursor.supportsUpdates(); } public boolean hasUpdates() { return mCursor.hasUpdates(); } public boolean updateBlob(int columnIndex, byte[] value) { if (columnIndex == mDeltaColumn) { return false; } return mCursor.updateBlob(columnIndex, value); } public boolean updateString(int columnIndex, String value) { if (columnIndex == mDeltaColumn) { return false; } return mCursor.updateString(columnIndex, value); } public boolean updateShort(int columnIndex, short value) { if (columnIndex == mDeltaColumn) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -