⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chooseaccountactivity.java

📁 Android平台上即时通讯聊天工具源代码。 支持手机聊天。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }        case ID_REMOVE_ACCOUNT:        {            Cursor c = (Cursor)mAdapter.getItem(position);            if (c != null) {                long accountId = c.getLong(ACTIVE_ACCOUNT_ID_COLUMN);                Uri accountUri = ContentUris.withAppendedId(Im.Account.CONTENT_URI, accountId);                getContentResolver().delete(accountUri, null, null);                // Requery the cursor to force refreshing screen                c.requery();            }            return true;        }        case ID_VIEW_CONTACT_LIST:        case ID_ADD_ACCOUNT:        case ID_SIGN_IN:            Intent i = mAdapter.intentForPosition(position);            if (i != null) {                startActivity(i);            }            return true;        case ID_SIGN_OUT:            // TODO: progress bar            IImConnection conn = mApp.getConnection(providerId);            if (conn != null) {                try {                    conn.logout();                } catch (RemoteException e) {                }            }            return true;        case ID_SETTINGS:            Intent settingsIntent = mAdapter.settingsIntentForPosition(position);            if (settingsIntent != null) {                startActivity(settingsIntent);            }            return true;        }        return false;    }    @Override    protected void onListItemClick(ListView l, View v, int position, long id) {        startActivityAtPosition(position);    }    void startActivityAtPosition(int position) {        Intent i = mAdapter.intentForPosition(position);        if (i != null) {            startActivity(i);        }    }    static void log(String msg) {        Log.d(ImApp.LOG_TAG, "[ChooseAccount]" + msg);    }    @Override    protected void onRestart() {        super.onRestart();        mApp.startImServiceIfNeed();        mApp.registerForConnEvents(mHandler);    }    @Override    protected void onStop() {        super.onStop();        mApp.unregisterForConnEvents(mHandler);        mApp.unregisterForBroadcastEvent(ImApp.EVENT_SERVICE_CONNECTED, mHandler);        mApp.stopImServiceIfInactive();    }    boolean isSigningIn(long accountId) {        IImConnection conn = mApp.getConnectionByAccount(accountId);        try {            return (conn == null) ? false : (conn.getState() == ImConnection.LOGGING_IN);        } catch (RemoteException e) {            return false;        }    }    boolean isSignedIn(long accountId) {        try {            IImConnection conn = mApp.getConnectionByAccount(accountId);            if (conn == null) {                return false;            }            int state = conn.getState();            return state == ImConnection.LOGGED_IN || state == ImConnection.SUSPENDED;        } catch (RemoteException e) {            return false;        }    }    private final class MyHandler extends SimpleAlertHandler {        public MyHandler() {            super(ChooseAccountActivity.this);        }        @Override        public void handleMessage(Message msg) {            switch(msg.what) {                case ImApp.EVENT_CONNECTION_DISCONNECTED:                    promptDisconnectedEvent(msg);                // fall through                case ImApp.EVENT_SERVICE_CONNECTED:                case ImApp.EVENT_CONNECTION_CREATED:                case ImApp.EVENT_CONNECTION_LOGGING_IN:                case ImApp.EVENT_CONNECTION_LOGGED_IN:                    getListView().invalidateViews();                    return;            }            super.handleMessage(msg);        }    }    private class ProviderListItemFactory implements LayoutInflater.Factory {        public View onCreateView(String name, Context context, AttributeSet attrs) {            if (name != null && name.equals(ProviderListItem.class.getName())) {                return new ProviderListItem(context, ChooseAccountActivity.this);            }            return null;        }    }    private final class ProviderAdapter extends CursorAdapter {        private LayoutInflater mInflater;        public ProviderAdapter(Context context, Cursor c) {            super(context, c);            mInflater = LayoutInflater.from(context).cloneInContext(context);            mInflater.setFactory(new ProviderListItemFactory());        }        @Override        public View newView(Context context, Cursor cursor, ViewGroup parent) {            // create a custom view, so we can manage it ourselves. Mainly, we want to            // initialize the widget views (by calling getViewById()) in newView() instead of in            // bindView(), which can be called more often.            ProviderListItem view = (ProviderListItem) mInflater.inflate(                    R.layout.account_view, parent, false);            view.init(cursor);            return view;        }        @Override        public void bindView(View view, Context context, Cursor cursor) {            ((ProviderListItem) view).bindView(cursor);        }        public Intent intentForPosition(int position) {            Intent intent = null;            if (mCursor == null) {                return null;            }            mCursor.moveToPosition(position);            long providerId = mCursor.getLong(PROVIDER_ID_COLUMN);            if (mCursor.isNull(ACTIVE_ACCOUNT_ID_COLUMN)) {                // add account                intent = new Intent(ChooseAccountActivity.this, AccountActivity.class);                intent.setAction(Intent.ACTION_INSERT);                intent.setData(ContentUris.withAppendedId(Im.Provider.CONTENT_URI, providerId));            } else {                long accountId = mCursor.getLong(ACTIVE_ACCOUNT_ID_COLUMN);                IImConnection conn = mApp.getConnection(providerId);                int state = getConnState(conn);                if (state < ImConnection.LOGGED_IN ) {                    Uri accountUri = ContentUris.withAppendedId(Im.Account.CONTENT_URI, accountId);                    if (mCursor.isNull(ACTIVE_ACCOUNT_PW_COLUMN)) {                        // no password, edit the account                        intent = new Intent(ChooseAccountActivity.this, AccountActivity.class);                        intent.setAction(Intent.ACTION_EDIT);                        intent.setData(accountUri);                    } else {                        // intent for sign in                        intent = new Intent(ChooseAccountActivity.this, SigningInActivity.class);                        intent.setData(accountUri);                    }                } else if (state == ImConnection.LOGGED_IN || state == ImConnection.SUSPENDED) {                    intent = new Intent(Intent.ACTION_VIEW);                    intent.setClass(ChooseAccountActivity.this, ContactListActivity.class);                    intent.putExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, accountId);                }            }            return intent;        }        public Intent settingsIntentForPosition(int position) {            Intent intent = null;            if (mCursor == null) {                return null;            }            mCursor.moveToPosition(position);            Long providerId = mCursor.getLong(PROVIDER_ID_COLUMN);            intent = new Intent(ChooseAccountActivity.this, SettingActivity.class);            intent.putExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, providerId);            return intent;        }        private int getConnState(IImConnection conn) {            try {                return conn == null ? ImConnection.DISCONNECTED : conn.getState();            } catch (RemoteException e) {                return ImConnection.DISCONNECTED;            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -