Search in sources :

Example 16 with NonNull

use of android.support.annotation.NonNull in project CoCoin by Nightonke.

the class AccountBookSettingActivity method whetherSyncSettingsFromServer.

// whether sync the settings from server////////////////////////////////////////////////////////////
private void whetherSyncSettingsFromServer() {
    new MaterialDialog.Builder(this).iconRes(R.drawable.cocoin_logo).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.sync_dialog_title).forceStacking(true).content(R.string.sync_dialog_content).positiveText(R.string.sync_dialog_sync_to_local).negativeText(R.string.sync_dialog_sync_to_server).cancelable(false).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            if (which.equals(DialogAction.POSITIVE)) {
                // sync to local
                downloadLogoFromServer();
                User user = getCurrentUser();
                String tip = "";
                boolean accountBookPasswordChanged = false;
                if (!user.getAccountBookPassword().equals(SettingManager.getInstance().getPassword()))
                    accountBookPasswordChanged = true;
                SettingManager.getInstance().setIsMonthLimit(user.getIsMonthLimit());
                monthSB.setChecked(user.getIsMonthLimit());
                SettingManager.getInstance().setMonthLimit(user.getMonthLimit());
                if (SettingManager.getInstance().getIsMonthLimit())
                    monthMaxExpense.withNumber(SettingManager.getInstance().getMonthLimit()).setDuration(1000).start();
                SettingManager.getInstance().setIsColorRemind(user.getIsColorRemind());
                monthColorRemindSB.setChecked(user.getIsColorRemind());
                SettingManager.getInstance().setMonthWarning(user.getMonthWarning());
                if (SettingManager.getInstance().getIsMonthLimit() && SettingManager.getInstance().getIsColorRemind())
                    monthWarning.withNumber(SettingManager.getInstance().getMonthWarning()).setDuration(1000).start();
                SettingManager.getInstance().setRemindColor(user.getRemindColor());
                monthColorRemindTypeIcon.setColor(SettingManager.getInstance().getRemindColor());
                SettingManager.getInstance().setIsForbidden(user.getIsForbidden());
                monthForbiddenSB.setChecked(user.getIsForbidden());
                SettingManager.getInstance().setAccountBookName(user.getAccountBookName());
                accountBookName.setText(user.getAccountBookName());
                SettingManager.getInstance().setPassword(user.getAccountBookPassword());
                // Todo tag sort
                SettingManager.getInstance().setShowPicture(user.getShowPicture());
                showPictureSB.setChecked(user.getShowPicture());
                SettingManager.getInstance().setIsHollow(user.getIsHollow());
                hollowSB.setChecked(user.getIsHollow());
                SettingManager.getInstance().setMainViewMonthExpenseShouldChange(true);
                SettingManager.getInstance().setMainViewRemindColorShouldChange(true);
                SettingManager.getInstance().setMainViewTitleShouldChange(true);
                SettingManager.getInstance().setTodayViewMonthExpenseShouldChange(true);
                SettingManager.getInstance().setTodayViewPieShouldChange(true);
                SettingManager.getInstance().setTodayViewTitleShouldChange(true);
                // SettingManager.getInstance().getMainActivityTagShouldChange();
                if (accountBookPasswordChanged)
                    tip = "\n" + getString(R.string.your_current_account_book_password_is) + SettingManager.getInstance().getPassword();
                new MaterialDialog.Builder(mContext).typeface(CoCoinUtil.GetTypeface(), CoCoinUtil.GetTypeface()).limitIconToDefaultSize().title(R.string.sync_to_local_successfully_dialog_title).content(getString(R.string.sync_to_local_successfully_dialog_content) + tip).positiveText(R.string.ok).show();
            } else if (which.equals(DialogAction.NEGATIVE)) {
                // sync to server
                uploadLogoToServer();
                User user = getCurrentUser();
                user.setIsMonthLimit(SettingManager.getInstance().getIsMonthLimit());
                user.setMonthLimit(SettingManager.getInstance().getMonthLimit());
                user.setIsColorRemind(SettingManager.getInstance().getIsColorRemind());
                user.setMonthWarning(SettingManager.getInstance().getMonthWarning());
                user.setRemindColor(SettingManager.getInstance().getRemindColor());
                user.setIsForbidden(SettingManager.getInstance().getIsForbidden());
                user.setAccountBookName(SettingManager.getInstance().getAccountBookName());
                user.setAccountBookPassword(SettingManager.getInstance().getPassword());
                // Todo tag sort
                user.setShowPicture(SettingManager.getInstance().getShowPicture());
                user.setIsHollow(SettingManager.getInstance().getIsHollow());
                user.update(CoCoinApplication.getAppContext(), user.getObjectId(), new UpdateListener() {

                    @Override
                    public void onSuccess() {
                        showToast(9, "");
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        showToast(10, msg);
                    }
                });
            }
            dialog.dismiss();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) UpdateListener(cn.bmob.v3.listener.UpdateListener)

Example 17 with NonNull

use of android.support.annotation.NonNull in project Signal-Android by WhisperSystems.

the class CameraView method getCameraInfo.

@NonNull
private CameraInfo getCameraInfo() {
    final CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    return info;
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo) NonNull(android.support.annotation.NonNull)

Example 18 with NonNull

use of android.support.annotation.NonNull in project Signal-Android by WhisperSystems.

the class ContactsCursorLoader method filterNonPushContacts.

@NonNull
private Cursor filterNonPushContacts(@NonNull Cursor cursor) {
    try {
        final long startMillis = System.currentTimeMillis();
        final MatrixCursor matrix = new MatrixCursor(new String[] { ContactsDatabase.ID_COLUMN, ContactsDatabase.NAME_COLUMN, ContactsDatabase.NUMBER_COLUMN, ContactsDatabase.NUMBER_TYPE_COLUMN, ContactsDatabase.LABEL_COLUMN, ContactsDatabase.CONTACT_TYPE_COLUMN });
        while (cursor.moveToNext()) {
            final String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
            final Recipients recipients = RecipientFactory.getRecipientsFromString(getContext(), number, true);
            if (DirectoryHelper.getUserCapabilities(getContext(), recipients).getTextCapability() != Capability.SUPPORTED) {
                matrix.addRow(new Object[] { cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)), number, cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN)), cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN)), ContactsDatabase.NORMAL_TYPE });
            }
        }
        Log.w(TAG, "filterNonPushContacts() -> " + (System.currentTimeMillis() - startMillis) + "ms");
        return matrix;
    } finally {
        cursor.close();
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) MatrixCursor(android.database.MatrixCursor) NonNull(android.support.annotation.NonNull)

Example 19 with NonNull

use of android.support.annotation.NonNull in project Signal-Android by WhisperSystems.

the class ContactsDatabase method getSignalRawContacts.

@NonNull
private Map<String, SignalContact> getSignalRawContacts(@NonNull Account account, @NonNull String localNumber) {
    Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name).appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();
    Map<String, SignalContact> signalContacts = new HashMap<>();
    Cursor cursor = null;
    try {
        String[] projection;
        if (Build.VERSION.SDK_INT >= 11) {
            projection = new String[] { BaseColumns._ID, RawContacts.SYNC1, RawContacts.SYNC4, RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY, RawContacts.DISPLAY_NAME_SOURCE };
        } else {
            projection = new String[] { BaseColumns._ID, RawContacts.SYNC1, RawContacts.SYNC4, RawContacts.CONTACT_ID };
        }
        cursor = context.getContentResolver().query(currentContactsUri, projection, null, null, null);
        while (cursor != null && cursor.moveToNext()) {
            String currentNumber;
            try {
                currentNumber = PhoneNumberFormatter.formatNumber(cursor.getString(1), localNumber);
            } catch (InvalidNumberException e) {
                Log.w(TAG, e);
                currentNumber = cursor.getString(1);
            }
            long rawContactId = cursor.getLong(0);
            long contactId = cursor.getLong(3);
            String supportsVoice = cursor.getString(2);
            String rawContactDisplayName = null;
            String aggregateDisplayName = null;
            int rawContactDisplayNameSource = 0;
            if (Build.VERSION.SDK_INT >= 11) {
                rawContactDisplayName = cursor.getString(4);
                rawContactDisplayNameSource = cursor.getInt(5);
                aggregateDisplayName = getDisplayName(contactId);
            }
            signalContacts.put(currentNumber, new SignalContact(rawContactId, supportsVoice, rawContactDisplayName, aggregateDisplayName, rawContactDisplayNameSource));
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return signalContacts;
}
Also used : HashMap(java.util.HashMap) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) Cursor(android.database.Cursor) Uri(android.net.Uri) NonNull(android.support.annotation.NonNull)

Example 20 with NonNull

use of android.support.annotation.NonNull in project Signal-Android by WhisperSystems.

the class ContactsDatabase method setRegisteredUsers.

@NonNull
public synchronized List<String> setRegisteredUsers(@NonNull Account account, @NonNull String localNumber, @NonNull List<ContactTokenDetails> registeredContacts, boolean remove) throws RemoteException, OperationApplicationException {
    Map<String, ContactTokenDetails> registeredNumbers = new HashMap<>();
    List<String> addedNumbers = new LinkedList<>();
    ArrayList<ContentProviderOperation> operations = new ArrayList<>();
    Map<String, SignalContact> currentContacts = getSignalRawContacts(account, localNumber);
    for (ContactTokenDetails registeredContact : registeredContacts) {
        String registeredNumber = registeredContact.getNumber();
        registeredNumbers.put(registeredNumber, registeredContact);
        if (!currentContacts.containsKey(registeredNumber)) {
            Optional<SystemContactInfo> systemContactInfo = getSystemContactInfo(registeredNumber, localNumber);
            if (systemContactInfo.isPresent()) {
                Log.w(TAG, "Adding number: " + registeredNumber);
                addedNumbers.add(registeredNumber);
                addTextSecureRawContact(operations, account, systemContactInfo.get().number, systemContactInfo.get().name, systemContactInfo.get().id, true);
            }
        }
    }
    for (Map.Entry<String, SignalContact> currentContactEntry : currentContacts.entrySet()) {
        ContactTokenDetails tokenDetails = registeredNumbers.get(currentContactEntry.getKey());
        if (tokenDetails == null) {
            if (remove) {
                Log.w(TAG, "Removing number: " + currentContactEntry.getKey());
                removeTextSecureRawContact(operations, account, currentContactEntry.getValue().getId());
            }
        } else if (!currentContactEntry.getValue().isVoiceSupported()) {
            Log.w(TAG, "Adding voice support: " + currentContactEntry.getKey());
            addContactVoiceSupport(operations, currentContactEntry.getKey(), currentContactEntry.getValue().getId());
        } else if (!Util.isStringEquals(currentContactEntry.getValue().getRawDisplayName(), currentContactEntry.getValue().getAggregateDisplayName())) {
            Log.w(TAG, "Updating display name: " + currentContactEntry.getKey());
            updateDisplayName(operations, currentContactEntry.getValue().getAggregateDisplayName(), currentContactEntry.getValue().getId(), currentContactEntry.getValue().getDisplayNameSource());
        }
    }
    if (!operations.isEmpty()) {
        context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
    }
    return addedNumbers;
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) HashMap(java.util.HashMap) ContactTokenDetails(org.whispersystems.signalservice.api.push.ContactTokenDetails) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)610 TextView (android.widget.TextView)65 View (android.view.View)64 ArrayList (java.util.ArrayList)57 Test (org.junit.Test)45 Intent (android.content.Intent)38 Cursor (android.database.Cursor)35 ContentValues (android.content.ContentValues)32 Bundle (android.os.Bundle)32 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)29 IOException (java.io.IOException)27 DialogAction (com.afollestad.materialdialogs.DialogAction)25 AlertDialog (android.support.v7.app.AlertDialog)24 Override (java.lang.Override)24 DialogInterface (android.content.DialogInterface)22 File (java.io.File)21 WorkerThread (android.support.annotation.WorkerThread)19 RecyclerView (android.support.v7.widget.RecyclerView)19 ImageView (android.widget.ImageView)19 HashMap (java.util.HashMap)19