@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { RosterItem item = (RosterItem) parent.getItemAtPosition(position); String name = item.getName(); String account = item.getAccount(); if (item.isGroup() || item.isAccount()) { if (item.isCollapsed()) { while (service.getCollapsedGroups().contains(name)) service.getCollapsedGroups().remove(name); item.setCollapsed(false); } else { service.getCollapsedGroups().add(name); item.setCollapsed(true); } updateList(); } else if (item.isEntry() || item.isSelf()) { RosterEntry re = item.getEntry(); String jid = re.getUser(); Intent i = new Intent(this, Chat.class); i.putExtra("account", account); i.putExtra("jid", jid); startActivity(i); } else if (item.isMuc()) { Intent i = new Intent(this, Chat.class); i.putExtra("account", account); i.putExtra("jid", item.getName()); startActivity(i); } }
private void updateStatus() { if (service.isAuthenticated()) { String status = statusArray[prefs.getInt("currentSelection", 0)]; // String substatus = prefs.getString("currentStatus", ""); getActionBar().setTitle(status); getActionBar().setSubtitle(service.getGlobalState()); } else { getActionBar().setTitle(getString(R.string.NotConnected)); getActionBar().setSubtitle(service.getGlobalState()); } }
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { RosterItem item = (RosterItem) parent.getItemAtPosition(position); if (item.isGroup()) { String name = item.getName(); if (!name.equals(getString(R.string.Nogroup)) && !name.equals(getString(R.string.SelfGroup)) && !name.equals(getString(R.string.MUC)) && !name.equals(getString(R.string.Privates)) && !name.equals(getString(R.string.ActiveChats))) RosterDialogs.renameGroupDialog(this, item.getAccount(), item.getName()); } else if (item.isAccount()) { RosterDialogs.AccountMenuDialog(this, item); } else if (item.isEntry()) { String j = item.getEntry().getUser(); if (!service.getPrivateMessages(item.getAccount()).contains(j)) RosterDialogs.ContactMenuDialog(this, item); else RosterDialogs.PrivateMenuDialog(this, item); } else if (item.isSelf()) { RosterDialogs.SelfContactMenuDialog(this, item); } else if (item.isMuc()) { MucDialogs.roomMenu(this, item.getAccount(), item.getName()); } return true; }
@Override public void onResume() { super.onResume(); errorReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { service = JTalkService.getInstance(); String error = intent.getStringExtra("error"); Toast.makeText(context, error, Toast.LENGTH_LONG).show(); } }; updateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { service = JTalkService.getInstance(); updateMenu(); updateStatus(); long now = System.currentTimeMillis(); if ((now - lastUpdateReceived) < RosterActivity.UPDATE_INTERVAL) return; lastUpdateReceived = now; updateList(); } }; service = JTalkService.getInstance(); service.setCurrentJid("me"); registerReceiver(errorReceiver, new IntentFilter(Constants.ERROR)); registerReceiver(updateReceiver, new IntentFilter(Constants.UPDATE)); registerReceiver(updateReceiver, new IntentFilter(Constants.NEW_MESSAGE)); if (service != null) service.resetTimer(); updateList(); updateMenu(); updateStatus(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == ACTIVITY_PREFERENCES) { if (resultCode == RESULT_OK) { Intent intent = getIntent(); intent.putExtra("password", false); finish(); startActivity(intent); service.removeSmiles(); } } }
@Override public void onReceive(Context context, Intent intent) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean("PlayingNow", false)) { String artist = null; String album = null; String track = null; if (intent.getBooleanExtra("playing", false)) { artist = intent.getStringExtra("artist"); album = intent.getStringExtra("album"); track = intent.getStringExtra("track"); } JTalkService.getInstance().sendTunes(artist, track, album); } }
public void connectionClosedOnError(Exception e) { Log.e("ConListener", "connectionClosedOnError"); if (!service.isAuthenticated()) Notify.offlineNotify(context, "Connection closed"); if (!isStarted) { isStarted = true; context.sendBroadcast(new Intent(Constants.UPDATE)); Log.e("ConListener", "Trying to connect"); new Thread() { public void run() { while (!service.isAuthenticated(account)) { service.reconnect(account); try { Thread.sleep(30000); } catch (Exception ignored) { } } isStarted = false; } }.start(); } }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(this)); Colors.updateColors(this); startService(new Intent(this, JTalkService.class)); service = JTalkService.getInstance(); prefs = PreferenceManager.getDefaultSharedPreferences(this); setTheme(Colors.isLight ? R.style.AppThemeLight : R.style.AppThemeDark); setContentView(R.layout.roster); LinearLayout roster = (LinearLayout) findViewById(R.id.roster_linear); roster.setBackgroundColor(Colors.BACKGROUND); getActionBar().setHomeButtonEnabled(true); statusArray = getResources().getStringArray(R.array.statusArray); rosterAdapter = new RosterAdapter(this); simpleAdapter = new NoGroupsAdapter(this); searchAdapter = new SearchAdapter(this); int cols = 1; if (!prefs.getBoolean("ShowGroups", true) && !prefs.getBoolean("ShowMucGroup", false)) { try { cols = Integer.parseInt(prefs.getString("RosterColumns", "1")); } catch (Exception e) { cols = 1; } } gridView = (GridView) findViewById(R.id.users); gridView.setNumColumns(cols); gridView.setCacheColorHint(0x00000000); gridView.setOnItemClickListener(this); gridView.setOnItemLongClickListener(this); gridView.setAdapter(rosterAdapter); if (getIntent().getBooleanExtra("status", false)) { RosterDialogs.changeStatusDialog(this, null, null); } if (getIntent().getBooleanExtra("password", false)) { String account = getIntent().getStringExtra("account"); RosterDialogs.passwordDialog(this, account); } if (getIntent().getBooleanExtra("subscribtion", false)) { String account = getIntent().getStringExtra("account"); String jid = getIntent().getStringExtra("jid"); RosterDialogs.subscribtionRequestDialog(this, account, jid); } File table = new File(Constants.PATH_SMILES + "/default/table.xml"); if (!table.exists()) { new CreateDefaultSmiles().execute(); } else { Cursor cursor = getContentResolver() .query( JTalkProvider.ACCOUNT_URI, null, AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null); if (cursor == null || cursor.getCount() < 1) startActivity(new Intent(this, Accounts.class)); } if (prefs.getBoolean("BUG", false)) { new ErrorDialog(this).show(); } String action = getIntent().getAction(); if (action != null && action.equals(Intent.ACTION_VIEW)) { Uri data = getIntent().getData(); if (data != null && data.getScheme().equals("xmpp")) { XMPPUri xmppUri; try { xmppUri = new XMPPUri(data); } catch (IllegalArgumentException e) { xmppUri = null; } List<String> accounts = new ArrayList<String>(); for (XMPPConnection connection : service.getAllConnections()) { accounts.add(StringUtils.parseBareAddress(connection.getUser())); } if (xmppUri != null && !accounts.isEmpty()) { final String xmppJid = xmppUri.getJid(); final String body = xmppUri.getBody(); String queryType = xmppUri.getQueryType(); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, accounts); if (queryType.equals("roster")) { RosterDialogs.addDialog(this, xmppUri.getJid()); } else if (queryType.equals("join")) { if (accounts.size() > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.Accounts); builder.setAdapter( adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String account = adapter.getItem(which); MucDialogs.joinDialog(RosterActivity.this, account, xmppJid, null); } }); builder.create().show(); } else MucDialogs.joinDialog(RosterActivity.this, accounts.get(0), xmppJid, null); } else { service.setText(xmppJid, body); if (accounts.size() > 1) { service.setText(xmppJid, body); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.Accounts); builder.setAdapter( adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String account = adapter.getItem(which); Intent intent = new Intent(RosterActivity.this, Chat.class); intent.putExtra("account", account); intent.putExtra("jid", xmppJid); startActivity(intent); } }); builder.create().show(); } else { Intent intent = new Intent(RosterActivity.this, Chat.class); intent.putExtra("account", accounts.get(0)); intent.putExtra("jid", xmppJid); startActivity(intent); } } } } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.offline: if (prefs.getBoolean("hideOffline", false)) service.setPreference("hideOffline", false); else service.setPreference("hideOffline", true); updateMenu(); updateList(); break; case R.id.status: RosterDialogs.changeStatusDialog(this, null, null); break; case android.R.id.home: RosterDialogs.changeStatusDialog(this, null, null); break; case R.id.add: RosterDialogs.addDialog(this, null); break; case R.id.search: menu.removeItem(R.id.chats); item.expandActionView(); break; case R.id.bookmarks: Intent bIntent = new Intent(this, Bookmarks.class); startActivity(bIntent); break; case R.id.chats: ChangeChatDialog.show(this); break; case R.id.accounts: Intent aIntent = new Intent(this, Accounts.class); startActivity(aIntent); break; case R.id.prefs: startActivityForResult(new Intent(this, Preferences.class), ACTIVITY_PREFERENCES); break; case R.id.disco: startActivity(new Intent(this, ServiceDiscovery.class)); break; case R.id.notes: startActivity(new Intent(this, NotesActivity.class)); break; case R.id.xml: startActivity(new Intent(this, XMLConsole.class)); break; case R.id.notify: if (prefs.getBoolean("soundDisabled", false)) service.setPreference("soundDisabled", false); else service.setPreference("soundDisabled", true); updateMenu(); break; case R.id.exit: if (prefs.getBoolean("DeleteHistory", false)) { getContentResolver().delete(JTalkProvider.CONTENT_URI, null, null); } Notify.cancelAll(this); stopService(new Intent(this, JTalkService.class)); finish(); System.exit(0); break; default: return false; } return true; }
private void updateMenu() { if (menu != null) { if (gridView.getAdapter() instanceof SearchAdapter) return; menu.clear(); getMenuInflater().inflate(R.menu.roster, menu); menu.findItem(R.id.add).setEnabled(service.isAuthenticated()); menu.findItem(R.id.notes).setEnabled(service.isAuthenticated()); menu.findItem(R.id.disco).setEnabled(service.isAuthenticated()); menu.findItem(R.id.offline) .setTitle( prefs.getBoolean("hideOffline", false) ? R.string.ShowOfflineContacts : R.string.HideOfflineContacts); MenuItem sound = menu.findItem(R.id.notify); sound.setShowAsActionFlags( prefs.getBoolean("showSound", false) ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); if (prefs.getBoolean("soundDisabled", false)) { sound.setTitle(R.string.EnableSound); sound.setIcon(R.drawable.ic_menu_sound_off); } else { sound.setTitle(R.string.DisableSound); sound.setIcon(R.drawable.ic_menu_sound_on); } MenuItem.OnActionExpandListener listener = new MenuItem.OnActionExpandListener() { @Override public boolean onMenuItemActionCollapse(MenuItem item) { gridView.setAdapter(null); searchString = null; updateList(); updateMenu(); return true; } @Override public boolean onMenuItemActionExpand(MenuItem item) { gridView.setAdapter(searchAdapter); searchString = ""; updateList(); return true; } }; SearchView searchView = new SearchView(this); searchView.setQueryHint(getString(android.R.string.search_go)); searchView.setSubmitButtonEnabled(false); searchView.setOnQueryTextListener( new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { searchString = newText; updateList(); return true; } @Override public boolean onQueryTextSubmit(String query) { return true; } }); MenuItem item = menu.findItem(R.id.search); item.setActionView(searchView); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); item.setOnActionExpandListener(listener); super.onCreateOptionsMenu(menu); } }
public ConListener(Context context, String account) { this.context = context; this.account = account; this.service = JTalkService.getInstance(); }