@Override protected void onResume() { super.onResume(); Application.getInstance().addUIListener(OnAccountChangedListener.class, this); Application.getInstance().addUIListener(OnContactChangedListener.class, this); update(); }
static { instance = new ConnectionManager(); Application.getInstance().addManager(instance); SmackConfiguration.setPacketReplyTimeout(PACKET_REPLY_TIMEOUT); ServiceDiscoveryManager.setIdentityType("handheld"); ServiceDiscoveryManager.setIdentityName( Application.getInstance().getString(R.string.client_name)); SASLAuthentication.registerSASLMechanism("X-MESSENGER-OAUTH2", XMessengerOAuth2.class); SASLAuthentication.supportSASLMechanism("X-MESSENGER-OAUTH2"); String path = System.getProperty("javax.net.ssl.trustStore"); if (path == null) TRUST_STORE_PATH = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security" + File.separator + "cacerts.bks"; else TRUST_STORE_PATH = path; Connection.addConnectionCreationListener( new ConnectionCreationListener() { @Override public void connectionCreated(final Connection connection) { ServiceDiscoveryManager.getInstanceFor(connection).addFeature("sslc2s"); } }); }
/** * @return Group's name to be display. * @see {@link #IS_ROOM}, {@link #ACTIVE_CHATS}, {@link #NO_GROUP}, {@link #IS_ACCOUNT}, {@link * #NO_ACCOUNT}. */ public String getGroupName(String account, String group) { if (group == GroupManager.NO_GROUP) return Application.getInstance().getString(R.string.group_none); else if (group == GroupManager.IS_ROOM) return Application.getInstance().getString(R.string.group_room); else if (group == GroupManager.ACTIVE_CHATS) return Application.getInstance().getString(R.string.group_active_chat); else if (group == GroupManager.IS_ACCOUNT) return AccountManager.getInstance().getVerboseName(account); return group; }
public void onAuthorized(ConnectionThread connectionThread) { if (!managedConnections.contains(connectionThread)) return; LogManager.i(this, "onAuthorized: " + connectionThread.getConnectionItem()); for (OnAuthorizedListener listener : Application.getInstance().getManagers(OnAuthorizedListener.class)) listener.onAuthorized(connectionThread.getConnectionItem()); }
private void startEncryption(String account, String user) { try { OTRManager.getInstance().startSession(account, user); } catch (NetworkException e) { Application.getInstance().onError(e); } }
private void callAttention() { try { AttentionManager.getInstance().sendAttention(account, user); } catch (NetworkException e) { Application.getInstance().onError(e); } }
@Override public void onClick(View view) { switch (view.getId()) { case R.id.ok: String user = userView.getText().toString(); if ("".equals(user)) { Toast.makeText(this, getString(R.string.EMPTY_USER_NAME), Toast.LENGTH_LONG).show(); return; } String account = (String) accountView.getSelectedItem(); if (account == null) { Toast.makeText(this, getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show(); return; } try { RosterManager.getInstance() .createContact(account, user, nameView.getText().toString(), getSelected()); PresenceManager.getInstance().requestSubscription(account, user); } catch (NetworkException e) { Application.getInstance().onError(e); finish(); return; } MessageManager.getInstance().openChat(account, user); finish(); break; default: break; } }
@Override public void onLoad() { final NestedMap<GroupConfiguration> groupConfigurations = new NestedMap<GroupConfiguration>(); Cursor cursor = GroupTable.getInstance().list(); try { if (cursor.moveToFirst()) { do { GroupConfiguration rosterConfiguration = new GroupConfiguration(); rosterConfiguration.setExpanded(GroupTable.isExpanded(cursor)); rosterConfiguration.setShowOfflineMode(GroupTable.getShowOfflineMode(cursor)); groupConfigurations.put( GroupTable.getAccount(cursor), GroupTable.getGroup(cursor), rosterConfiguration); } while (cursor.moveToNext()); } } finally { cursor.close(); } Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { onLoaded(groupConfigurations); } }); }
@Override public void onLoad() { final Collection<RoomChat> roomChats = new ArrayList<RoomChat>(); final Collection<RoomChat> needJoins = new ArrayList<RoomChat>(); Cursor cursor = RoomTable.getInstance().list(); try { if (cursor.moveToFirst()) { do { RoomChat roomChat = new RoomChat( RoomTable.getAccount(cursor), RoomTable.getRoom(cursor), RoomTable.getNickname(cursor), RoomTable.getPassword(cursor)); if (RoomTable.needJoin(cursor)) needJoins.add(roomChat); roomChats.add(roomChat); } while (cursor.moveToNext()); } } finally { cursor.close(); } Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { onLoaded(roomChats, needJoins); } }); }
@Override public void onDestroy() { super.onDestroy(); LogManager.i(this, "onDestroy"); stopForegroundWrapper(); Application.getInstance().onServiceDestroy(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isFinishing()) return; setContentView(R.layout.fingerprint_viewer); integrator = new IntentIntegrator(this); Intent intent = getIntent(); account = getAccount(intent); user = getUser(intent); if (AccountManager.getInstance().getAccount(account) == null || user == null) { Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); finish(); return; } if (savedInstanceState != null) { remoteFingerprint = savedInstanceState.getString(SAVED_REMOTE_FINGERPRINT); localFingerprint = savedInstanceState.getString(SAVED_LOCAL_FINGERPRINT); } else { remoteFingerprint = OTRManager.getInstance().getRemoteFingerprint(account, user); localFingerprint = OTRManager.getInstance().getLocalFingerprint(account); } verifiedView = (CheckBox) findViewById(R.id.verified); verifiedView.setOnCheckedChangeListener(this); scanView = findViewById(R.id.scan); scanView.setOnClickListener(this); showView = findViewById(R.id.show); showView.setOnClickListener(this); copyView = findViewById(R.id.copy); copyView.setOnClickListener(this); isUpdating = false; }
/** Called when connection was closed for some reason. */ protected void onClose(ConnectionThread connectionThread) { if (onDisconnect(connectionThread)) { state = ConnectionState.waiting; this.connectionThread = null; if (connectionRequest) Application.getInstance().onError(R.string.CONNECTION_FAILED); connectionRequest = false; } }
@Override protected void onInflate(Bundle savedInstanceState) { setContentView(R.layout.contact_add); ListView listView = getListView(); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.contact_add_header, listView, false); listView.addHeaderView(view, null, false); accountView = (Spinner) view.findViewById(R.id.contact_account); accountView.setAdapter(new AccountChooseAdapter(this)); accountView.setOnItemSelectedListener(this); userView = (EditText) view.findViewById(R.id.contact_user); nameView = (EditText) view.findViewById(R.id.contact_name); ((Button) view.findViewById(R.id.ok)).setOnClickListener(this); String name; Intent intent = getIntent(); if (savedInstanceState != null) { account = savedInstanceState.getString(SAVED_ACCOUNT); user = savedInstanceState.getString(SAVED_USER); name = savedInstanceState.getString(SAVED_NAME); } else { account = getAccount(intent); user = getUser(intent); if (account == null || user == null) name = null; else { name = RosterManager.getInstance().getName(account, user); if (user.equals(name)) name = null; } } if (account == null) { Collection<String> accounts = AccountManager.getInstance().getAccounts(); if (accounts.size() == 1) account = accounts.iterator().next(); } if (account != null) { for (int position = 0; position < accountView.getCount(); position++) if (account.equals(accountView.getItemAtPosition(position))) { accountView.setSelection(position); break; } } if (user != null) userView.setText(user); if (name != null) nameView.setText(name); if (ACTION_SUBSCRIPTION_REQUEST.equals(intent.getAction())) { subscriptionRequest = PresenceManager.getInstance().getSubscriptionRequest(account, user); if (subscriptionRequest == null) { Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND); finish(); return; } } else { subscriptionRequest = null; } }
/** Clear list of status presets. */ public void clearSavedStatuses() { savedStatuses.clear(); Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance().clear(); } }); }
/** * Remove status from presets. * * @param statusMode * @param statusText */ public void removeSavedStatus(final SavedStatus savedStatus) { if (!savedStatuses.remove(savedStatus)) return; Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance() .remove(savedStatus.getStatusMode(), savedStatus.getStatusText()); } }); }
public void onAccountsChanged(final Collection<String> accounts) { Application.getInstance() .runOnUiThread( new Runnable() { @Override public void run() { for (OnAccountChangedListener accountListener : Application.getInstance().getUIListeners(OnAccountChangedListener.class)) accountListener.onAccountsChanged(accounts); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isFinishing()) return; actionWithItem = null; setContentView(R.layout.status_editor); Intent intent = getIntent(); account = StatusEditor.getAccount(intent); if (account == null) setTitle(getString(R.string.status_editor)); else setTitle( getString( R.string.status_editor_for, AccountManager.getInstance().getVerboseName(account))); ListView listView = getListView(); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View header = inflater.inflate(R.layout.status_editor_header, listView, false); listView.addHeaderView(header, null, false); listView.setOnItemClickListener(this); registerForContextMenu(listView); setListAdapter(new StatusEditorAdapter(this)); statusTextView = (EditText) header.findViewById(R.id.status_text); statusModeView = (Spinner) header.findViewById(R.id.status_mode); statusModeView.setAdapter(new StatusModeAdapter(this)); ((Button) findViewById(R.id.ok)).setOnClickListener(this); StatusMode statusMode; String statusText; if (savedInstanceState == null) { if (account == null) { statusMode = SettingsManager.statusMode(); statusText = SettingsManager.statusText(); } else { AccountItem accountItem = AccountManager.getInstance().getAccount(account); if (accountItem == null) { Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT); finish(); return; } statusMode = accountItem.getFactualStatusMode(); statusText = accountItem.getStatusText(); } } else { statusMode = StatusMode.valueOf(savedInstanceState.getString(SAVED_MODE)); statusText = savedInstanceState.getString(SAVED_TEXT); } showStatus(statusMode, statusText); }
public void onDisconnect(ConnectionThread connectionThread) { if (!managedConnections.remove(connectionThread)) return; ConnectionItem connectionItem = connectionThread.getConnectionItem(); if (connectionItem instanceof AccountItem) { String account = ((AccountItem) connectionItem).getAccount(); for (Entry<String, RequestHolder> entry : requests.getNested(account).entrySet()) entry.getValue().getListener().onDisconnect(account, entry.getKey()); requests.clear(account); } for (OnDisconnectListener listener : Application.getInstance().getManagers(OnDisconnectListener.class)) listener.onDisconnect(connectionThread.getConnectionItem()); }
/** * Save status in presets. * * @param statusMode * @param statusText */ private void addSavedStatus(final StatusMode statusMode, final String statusText) { SavedStatus savedStatus = new SavedStatus(statusMode, statusText); if (savedStatuses.contains(savedStatus)) return; savedStatuses.add(savedStatus); Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { StatusTable.getInstance().write(statusMode, statusText); } }); }
private void requestToWriteGroup( final String account, final String group, final boolean expanded, final ShowOfflineMode showOfflineMode) { Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { GroupTable.getInstance().write(account, group, expanded, showOfflineMode); } }); }
private void exit() { Application.getInstance().requestToClose(); showDialog(DIALOG_CLOSE_APPLICATION_ID); getContactListFragment().unregisterListeners(); new Handler() .postDelayed( new Runnable() { @Override public void run() { // Close activity if application was not killed yet. finish(); } }, CLOSE_ACTIVITY_AFTER_DELAY); }
@Override public void onAccept(DialogBuilder dialogBuilder) { super.onAccept(dialogBuilder); switch (dialogBuilder.getDialogId()) { case DIALOG_SUBSCRIPTION_REQUEST_ID: try { PresenceManager.getInstance() .acceptSubscription(subscriptionRequest.getAccount(), subscriptionRequest.getUser()); } catch (NetworkException e) { Application.getInstance().onError(e); } getIntent().setAction(null); break; } }
@Override public void onDecline(DialogBuilder dialogBuilder) { super.onDecline(dialogBuilder); switch (dialogBuilder.getDialogId()) { case DIALOG_SUBSCRIPTION_REQUEST_ID: try { PresenceManager.getInstance() .discardSubscription(subscriptionRequest.getAccount(), subscriptionRequest.getUser()); } catch (NetworkException e) { Application.getInstance().onError(e); } finish(); break; } }
@Override protected boolean onPositiveClick() { String newName = nameView.getText().toString(); if ("".equals(newName)) { Toast.makeText(getActivity(), getString(R.string.group_is_empty), Toast.LENGTH_LONG).show(); return false; } try { if (account == null) RosterManager.getInstance().renameGroup(group, newName); else RosterManager.getInstance().renameGroup(account, group, newName); } catch (NetworkException e) { Application.getInstance().onError(e); } return true; }
private void requestToWriteRoom( final String account, final String room, final String nickname, final String password, final boolean join) { Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { RoomTable.getInstance().write(account, room, nickname, password, join); } }); }
private AccountManager() { this.application = Application.getInstance(); accountItems = new HashMap<String, AccountItem>(); enabledAccounts = new HashSet<String>(); savedStatuses = new ArrayList<SavedStatus>(); authorizationErrorProvider = new BaseAccountNotificationProvider<AccountAuthorizationError>( R.drawable.ic_stat_auth_failed); passwordRequestProvider = new BaseAccountNotificationProvider<PasswordRequest>(R.drawable.ic_stat_request); TypedArray accountAvatars = application.getResources().obtainTypedArray(R.array.account_avatars); colors = accountAvatars.length(); accountAvatars.recycle(); TypedArray types = application.getResources().obtainTypedArray(R.array.account_types); accountTypes = new ArrayList<AccountType>(); for (int index = 0; index < types.length(); index++) { int id = types.getResourceId(index, 0); TypedArray values = application.getResources().obtainTypedArray(id); AccountProtocol protocol = AccountProtocol.valueOf(values.getString(0)); if (Application.SDK_INT < 8 && protocol == AccountProtocol.wlm) { values.recycle(); continue; } ArrayList<String> servers = new ArrayList<String>(); servers.add(values.getString(9)); for (int i = 10; i < values.length(); i++) servers.add(values.getString(i)); accountTypes.add( new AccountType( id, protocol, values.getString(1), values.getString(2), values.getString(3), values.getDrawable(4), values.getBoolean(5, false), values.getString(6), values.getInt(7, 5222), values.getBoolean(8, false), servers)); values.recycle(); } types.recycle(); away = false; xa = false; }
public void removeRoom(final String account, final String room) { removeInvite(getInvite(account, room)); RoomChat roomChat = getRoomChat(account, room); if (roomChat == null) return; leaveRoom(account, room); MessageManager.getInstance().removeChat(roomChat); RosterManager.getInstance().onContactChanged(account, room); Application.getInstance() .runInBackground( new Runnable() { @Override public void run() { RoomTable.getInstance().remove(account, room); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); findViewById(android.R.id.button3).setVisibility(View.GONE); View layout = getLayoutInflater().inflate(R.layout.password_request, null); passwordView = (EditText) layout.findViewById(R.id.account_password); storePasswordView = (CheckBox) layout.findViewById(R.id.store_password); account = getAccount(getIntent()); if (AccountManager.getInstance().getAccount(account) == null) { Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT); finish(); return; } setDialogTitle(AccountManager.getInstance().getVerboseName(account)); setCustomView(layout, true); }
/** * Sends invitation. * * @param account * @param room * @param user * @throws NetworkException */ public void invite(String account, String room, String user) throws NetworkException { RoomChat roomChat = getRoomChat(account, room); if (roomChat == null || roomChat.getState() != RoomState.available) { Application.getInstance().onError(R.string.NOT_CONNECTED); return; } Message message = new Message(room); MUCUser mucUser = new MUCUser(); MUCUser.Invite invite = new MUCUser.Invite(); invite.setTo(user); invite.setReason(""); mucUser.setInvite(invite); message.addExtension(mucUser); ConnectionManager.getInstance().sendPacket(account, message); roomChat.putInvite(message.getPacketID(), user); roomChat.newAction(roomChat.getNickname(), user, ChatAction.invite_sent); }
@Override public void onContactClick(AbstractContact abstractContact) { if (action == null) { startActivity( ChatViewer.createSpecificChatIntent( this, abstractContact.getAccount(), abstractContact.getUser())); return; } switch (action) { case ACTION_ROOM_INVITE: { action = null; Intent intent = getIntent(); String account = getRoomInviteAccount(intent); String user = getRoomInviteUser(intent); if (account != null && user != null) { try { MUCManager.getInstance().invite(account, user, abstractContact.getUser()); } catch (NetworkException e) { Application.getInstance().onError(e); } } finish(); break; } case Intent.ACTION_SEND: action = null; startActivity( ChatViewer.createSendIntent( this, abstractContact.getAccount(), abstractContact.getUser(), sendText)); finish(); break; case Intent.ACTION_CREATE_SHORTCUT: { createShortcut(abstractContact); finish(); break; } default: startActivity( ChatViewer.createSpecificChatIntent( this, abstractContact.getAccount(), abstractContact.getUser())); break; } }