Exemple #1
0
 @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;
 }
Exemple #2
0
  @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);
            }
          }
        }
      }
    }
  }
Exemple #3
0
 @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;
 }