Search in sources :

Example 36 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class MessageGenerator method generateChatState.

public MessagePacket generateChatState(Conversation conversation) {
    final Account account = conversation.getAccount();
    MessagePacket packet = new MessagePacket();
    packet.setType(conversation.getMode() == Conversation.MODE_MULTI ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
    packet.setTo(conversation.getJid().toBareJid());
    packet.setFrom(account.getJid());
    packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
    packet.addChild("no-store", "urn:xmpp:hints");
    // wrong! don't copy this. Its *store*
    packet.addChild("no-storage", "urn:xmpp:hints");
    return packet;
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Account(de.pixart.messenger.entities.Account)

Example 37 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method selectPresenceToAttachFile.

protected void selectPresenceToAttachFile(final int attachmentChoice) {
    final int encryption = conversation.getNextEncryption();
    final Account account = conversation.getAccount();
    final PresenceSelector.OnPresenceSelected callback = () -> {
        final Intent intent = new Intent();
        boolean chooser = false;
        String fallbackPackageId = null;
        switch(attachmentChoice) {
            case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
                intent.setAction(Intent.ACTION_GET_CONTENT);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                }
                intent.setType("image/*");
                chooser = true;
                break;
            case ATTACHMENT_CHOICE_CHOOSE_VIDEO:
                chooser = true;
                intent.setType("video/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setAction(Intent.ACTION_GET_CONTENT);
                break;
            case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA:
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(getString(R.string.attach_take_from_camera));
                builder.setNegativeButton(getString(R.string.action_take_photo), (dialog, which) -> {
                    final Uri uri = activity.xmppConnectionService.getFileBackend().getTakePhotoUri();
                    pendingTakePhotoUri.push(uri);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent, attachmentChoice);
                });
                builder.setPositiveButton(getString(R.string.action_take_video), (dialog, which) -> {
                    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
                    startActivityForResult(intent, attachmentChoice);
                });
                builder.create().show();
                break;
            case ATTACHMENT_CHOICE_CHOOSE_FILE:
                chooser = true;
                intent.setType("*/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setAction(Intent.ACTION_GET_CONTENT);
                break;
            case ATTACHMENT_CHOICE_RECORD_VOICE:
                startActivityForResult(new Intent(getActivity(), RecordingActivity.class), attachmentChoice);
                break;
            case ATTACHMENT_CHOICE_LOCATION:
                startActivityForResult(new Intent(getActivity(), ShareLocationActivity.class), attachmentChoice);
                break;
        }
        if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
            Log.d(Config.LOGTAG, "Attachment: " + attachmentChoice);
            if (chooser) {
                startActivityForResult(Intent.createChooser(intent, getString(R.string.perform_action_with)), attachmentChoice);
            } else {
                startActivityForResult(intent, attachmentChoice);
            }
        } else if (fallbackPackageId != null) {
            startActivity(getInstallApkIntent(fallbackPackageId));
        }
    };
    if (account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
        if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) {
            conversation.setNextCounterpart(null);
            callback.onPresenceSelected();
        } else {
            activity.selectPresence(conversation, callback);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Arrays(java.util.Arrays) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection) Bundle(android.os.Bundle) MessageUtils(de.pixart.messenger.utils.MessageUtils) TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) Uri(android.net.Uri) ImageView(android.widget.ImageView) EXTRA_ACCOUNT(de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT) Account(de.pixart.messenger.entities.Account) Manifest(android.Manifest) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) PopupMenu(android.widget.PopupMenu) ActivityResult(de.pixart.messenger.ui.util.ActivityResult) Log(android.util.Log) Set(java.util.Set) SendButtonTool(de.pixart.messenger.ui.util.SendButtonTool) Contact(de.pixart.messenger.entities.Contact) Transferable(de.pixart.messenger.entities.Transferable) EditMessage(de.pixart.messenger.ui.widget.EditMessage) TextWatcher(android.text.TextWatcher) UIHelper(de.pixart.messenger.utils.UIHelper) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) SimpleDateFormat(java.text.SimpleDateFormat) BitmapFactory(android.graphics.BitmapFactory) SystemClock(android.os.SystemClock) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) SessionStatus(net.java.otr4j.session.SessionStatus) ArrayList(java.util.ArrayList) Conversation(de.pixart.messenger.entities.Conversation) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ReadByMarker(de.pixart.messenger.entities.ReadByMarker) ENCRYPTION_EXCEPTIONS(de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS) Fragment(android.app.Fragment) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) IOException(java.io.IOException) ScrollState(de.pixart.messenger.ui.util.ScrollState) File(java.io.File) IdRes(android.support.annotation.IdRes) Gravity(android.view.Gravity) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DataBindingUtil(android.databinding.DataBindingUtil) SendButtonAction(de.pixart.messenger.ui.util.SendButtonAction) ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) PendingIntent(android.app.PendingIntent) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) Jid(de.pixart.messenger.xmpp.jid.Jid) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) AdapterView(android.widget.AdapterView) SendIntentException(android.content.IntentSender.SendIntentException) PreferenceManager(android.preference.PreferenceManager) Presence(de.pixart.messenger.entities.Presence) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) MessageAdapter(de.pixart.messenger.ui.adapter.MessageAdapter) ExifInterface(android.support.media.ExifInterface) FragmentConversationBinding(de.pixart.messenger.databinding.FragmentConversationBinding) UUID(java.util.UUID) ViewGroup(android.view.ViewGroup) OnScrollListener(android.widget.AbsListView.OnScrollListener) ConversationMenuConfigurator(de.pixart.messenger.ui.util.ConversationMenuConfigurator) List(java.util.List) ActivityNotFoundException(android.content.ActivityNotFoundException) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) FileUtils(de.pixart.messenger.utils.FileUtils) ListView(android.widget.ListView) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) XmppConnection(de.pixart.messenger.xmpp.XmppConnection) EditorInfo(android.view.inputmethod.EditorInfo) Blockable(de.pixart.messenger.entities.Blockable) Context(android.content.Context) ContextMenu(android.view.ContextMenu) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) MessageArchiveService(de.pixart.messenger.services.MessageArchiveService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) FileBackend(de.pixart.messenger.persistance.FileBackend) OnSwipeTouchListener(de.pixart.messenger.ui.interfaces.OnSwipeTouchListener) MotionEvent(android.view.MotionEvent) R(de.pixart.messenger.R) AttachmentTool(de.pixart.messenger.ui.util.AttachmentTool) Build(android.os.Build) Config(de.pixart.messenger.Config) NickValidityChecker(de.pixart.messenger.utils.NickValidityChecker) DialogInterface(android.content.DialogInterface) Message(de.pixart.messenger.entities.Message) MucOptions(de.pixart.messenger.entities.MucOptions) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) StylingHelper(de.pixart.messenger.utils.StylingHelper) InputConnectionCompat(android.support.v13.view.inputmethod.InputConnectionCompat) PendingItem(de.pixart.messenger.ui.util.PendingItem) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) Collections(java.util.Collections) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) OnClickListener(android.view.View.OnClickListener) REQUEST_INVITE_TO_CONVERSATION(de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION) Account(de.pixart.messenger.entities.Account) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint)

Example 38 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class WelcomeActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    if (getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayShowHomeEnabled(false);
        ab.setDisplayHomeAsUpEnabled(false);
    }
    // check if there is a backed up database --
    if (hasStoragePermission(REQUEST_READ_EXTERNAL_STORAGE)) {
        BackupAvailable();
    }
    final Button ImportDatabase = findViewById(R.id.import_database);
    final TextView ImportText = findViewById(R.id.import_text);
    if (BackupAvailable()) {
        ImportDatabase.setVisibility(View.VISIBLE);
        ImportText.setVisibility(View.VISIBLE);
    }
    ImportDatabase.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            enterPasswordDialog();
        }
    });
    final Button createAccount = findViewById(R.id.create_account);
    createAccount.setOnClickListener(v -> {
        final Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        addInviteUri(intent);
        startActivity(intent);
    });
    final Button useOwnProvider = findViewById(R.id.use_existing_account);
    useOwnProvider.setOnClickListener(v -> {
        List<Account> accounts = xmppConnectionService.getAccounts();
        Intent intent = new Intent(WelcomeActivity.this, EditAccountActivity.class);
        if (accounts.size() == 1) {
            intent.putExtra("jid", accounts.get(0).getJid().toBareJid().toString());
            intent.putExtra("init", true);
        } else if (accounts.size() >= 1) {
            intent = new Intent(WelcomeActivity.this, ManageAccountActivity.class);
        }
        addInviteUri(intent);
        startActivity(intent);
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Button(android.widget.Button) TextView(android.widget.TextView) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar)

Example 39 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class AccountAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    final Account account = getItem(position);
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.account_row, parent, false);
    }
    TextView jid = view.findViewById(R.id.account_jid);
    if (Config.DOMAIN_LOCK != null) {
        jid.setText(account.getJid().getLocalpart());
    } else {
        jid.setText(account.getJid().toBareJid().toString());
    }
    TextView statusView = view.findViewById(R.id.account_status);
    ImageView imageView = view.findViewById(R.id.account_image);
    loadAvatar(account, imageView);
    statusView.setText(getContext().getString(account.getStatus().getReadableId()));
    switch(account.getStatus()) {
        case ONLINE:
            statusView.setTextColor(activity.getOnlineColor());
            break;
        case DISABLED:
        case CONNECTING:
            statusView.setTextColor(Color.get(activity, android.R.attr.textColorSecondary));
            break;
        default:
            statusView.setTextColor(activity.getWarningTextColor());
            break;
    }
    return view;
}
Also used : Account(de.pixart.messenger.entities.Account) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 40 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class ShareViaAccountActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_accounts);
    accountListView = findViewById(R.id.account_list);
    this.mAccountAdapter = new AccountAdapter(this, accountList);
    accountListView.setAdapter(this.mAccountAdapter);
    accountListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
            final Account account = accountList.get(position);
            final String body = getIntent().getStringExtra(EXTRA_BODY);
            try {
                final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contact, false, false);
                switchToConversation(conversation, body, false);
            } catch (InvalidJidException e) {
            // ignore error
            }
            finish();
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) AccountAdapter(de.pixart.messenger.ui.adapter.AccountAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6