Search in sources :

Example 36 with NonNull

use of androidx.annotation.NonNull in project Timber by naman14.

the class SubStyleSelectorFragment method showPurchaseDialog.

private void showPurchaseDialog() {
    MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title("Purchase").content("This now playing style is available after a one time purchase of any amount. Support development and unlock this style?").positiveText("Support development").neutralText("Restore purchases").onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            startActivity(new Intent(getActivity(), DonateActivity.class));
            dialog.dismiss();
        }
    }).onNeutral(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            Intent intent = new Intent(getActivity(), DonateActivity.class);
            intent.putExtra("title", "Restoring purchases..");
            intent.setAction("restore");
            startActivity(intent);
            dialog.dismiss();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent)

Example 37 with NonNull

use of androidx.annotation.NonNull in project android by owncloud.

the class SynchronizeFolderOperation method fetchRemoteFolder.

/**
 * Get list of files in folder from remote server.
 *
 * @param client {@link OwnCloudClient} instance used to access the server.
 * @return Result of the fetch, including list of remote files in the synced folder.
 * @throws OperationCancelledException
 */
@NonNull
private RemoteOperationResult<ArrayList<RemoteFile>> fetchRemoteFolder(OwnCloudClient client) throws OperationCancelledException {
    Timber.d("Fetching list of files in  " + mAccount.name + mRemotePath + ", if changed");
    if (mCancellationRequested.get()) {
        throw new OperationCancelledException();
    }
    ReadRemoteFolderOperation readFolderOperation = new ReadRemoteFolderOperation(mRemotePath);
    return readFolderOperation.execute(client);
}
Also used : ReadRemoteFolderOperation(com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation) OperationCancelledException(com.owncloud.android.lib.common.operations.OperationCancelledException) NonNull(androidx.annotation.NonNull)

Example 38 with NonNull

use of androidx.annotation.NonNull in project Tusky by Vavassor.

the class NotificationsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_timeline_notifications, container, false);
    // from inflater to silence warning
    @NonNull Context context = inflater.getContext();
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean showNotificationsFilterSetting = preferences.getBoolean("showNotificationsFilter", true);
    // Clear notifications on filter visibility change to force refresh
    if (showNotificationsFilterSetting != showNotificationsFilter)
        notifications.clear();
    showNotificationsFilter = showNotificationsFilterSetting;
    // Setup the SwipeRefreshLayout.
    swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout);
    recyclerView = rootView.findViewById(R.id.recyclerView);
    progressBar = rootView.findViewById(R.id.progressBar);
    statusView = rootView.findViewById(R.id.statusView);
    appBarOptions = rootView.findViewById(R.id.appBarOptions);
    swipeRefreshLayout.setOnRefreshListener(this);
    swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
    loadNotificationsFilter();
    // Setup the RecyclerView.
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(context);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAccessibilityDelegateCompat(new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> {
        NotificationViewData notification = notifications.getPairedItemOrNull(pos);
        // We support replies only for now
        if (notification instanceof NotificationViewData.Concrete) {
            return ((NotificationViewData.Concrete) notification).getStatusViewData();
        } else {
            return null;
        }
    }));
    recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
    StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions(preferences.getBoolean("animateGifAvatars", false), accountManager.getActiveAccount().getMediaPreviewEnabled(), preferences.getBoolean("absoluteTimeView", false), preferences.getBoolean("showBotOverlay", true), preferences.getBoolean("useBlurhash", true), CardViewMode.NONE, preferences.getBoolean("confirmReblogs", true), preferences.getBoolean("confirmFavourites", false), preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false), preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false));
    adapter = new NotificationsAdapter(accountManager.getActiveAccount().getAccountId(), dataSource, statusDisplayOptions, this, this, this);
    alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
    alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
    recyclerView.setAdapter(adapter);
    topLoading = false;
    bottomLoading = false;
    bottomId = null;
    updateAdapter();
    Button buttonClear = rootView.findViewById(R.id.buttonClear);
    buttonClear.setOnClickListener(v -> confirmClearNotifications());
    buttonFilter = rootView.findViewById(R.id.buttonFilter);
    buttonFilter.setOnClickListener(v -> showFilterMenu());
    if (notifications.isEmpty()) {
        swipeRefreshLayout.setEnabled(false);
        sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1);
    } else {
        progressBar.setVisibility(View.GONE);
    }
    ((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
    updateFilterVisibility();
    return rootView;
}
Also used : Context(android.content.Context) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) AsyncDifferConfig(androidx.recyclerview.widget.AsyncDifferConfig) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) Utils(at.connyduck.sparkbutton.helpers.Utils) AccountActionListener(com.keylesspalace.tusky.interfaces.AccountActionListener) NotificationTypeConverterKt(com.keylesspalace.tusky.util.NotificationTypeConverterKt) AppBarLayout(com.google.android.material.appbar.AppBarLayout) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) Locale(java.util.Locale) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ActionButtonActivity(com.keylesspalace.tusky.interfaces.ActionButtonActivity) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Function(androidx.arch.core.util.Function) Log(android.util.Log) ViewDataUtils(com.keylesspalace.tusky.util.ViewDataUtils) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) ListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback) DiffUtil(androidx.recyclerview.widget.DiffUtil) PreferenceChangedEvent(com.keylesspalace.tusky.appstore.PreferenceChangedEvent) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) Set(java.util.Set) Function1(kotlin.jvm.functions.Function1) Relationship(com.keylesspalace.tusky.entity.Relationship) ViewGroup(android.view.ViewGroup) ReselectableFragment(com.keylesspalace.tusky.interfaces.ReselectableFragment) Objects(java.util.Objects) FavoriteEvent(com.keylesspalace.tusky.appstore.FavoriteEvent) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) List(java.util.List) Unit(kotlin.Unit) AutoDispose.autoDisposable(autodispose2.AutoDispose.autoDisposable) Nullable(androidx.annotation.Nullable) Pair(androidx.core.util.Pair) Disposable(io.reactivex.rxjava3.disposables.Disposable) CollectionsKt(kotlin.collections.CollectionsKt) AsyncListDiffer(androidx.recyclerview.widget.AsyncListDiffer) ListView(android.widget.ListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StringUtils.isLessThan(com.keylesspalace.tusky.util.StringUtils.isLessThan) AccountEntity(com.keylesspalace.tusky.db.AccountEntity) Context(android.content.Context) BookmarkEvent(com.keylesspalace.tusky.appstore.BookmarkEvent) Notification(com.keylesspalace.tusky.entity.Notification) Single(io.reactivex.rxjava3.core.Single) AlertDialog(androidx.appcompat.app.AlertDialog) Status(com.keylesspalace.tusky.entity.Status) AndroidLifecycleScopeProvider.from(autodispose2.androidx.lifecycle.AndroidLifecycleScopeProvider.from) ReblogEvent(com.keylesspalace.tusky.appstore.ReblogEvent) Poll(com.keylesspalace.tusky.entity.Poll) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) PairedList(com.keylesspalace.tusky.util.PairedList) ArrayList(java.util.ArrayList) StatusBaseViewHolder(com.keylesspalace.tusky.adapter.StatusBaseViewHolder) PrefKeys(com.keylesspalace.tusky.settings.PrefKeys) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Lifecycle(androidx.lifecycle.Lifecycle) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) Observable(io.reactivex.rxjava3.core.Observable) AttachmentViewData(com.keylesspalace.tusky.viewdata.AttachmentViewData) DialogInterface(android.content.DialogInterface) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) EventHub(com.keylesspalace.tusky.appstore.EventHub) BlockEvent(com.keylesspalace.tusky.appstore.BlockEvent) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) PopupWindow(android.widget.PopupWindow) HttpHeaderLink(com.keylesspalace.tusky.util.HttpHeaderLink) Either(com.keylesspalace.tusky.util.Either) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) ArrayAdapter(android.widget.ArrayAdapter) SparseBooleanArray(android.util.SparseBooleanArray) PinEvent(com.keylesspalace.tusky.appstore.PinEvent) SharedPreferences(android.content.SharedPreferences) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) PreferenceManager(androidx.preference.PreferenceManager) ListUtils(com.keylesspalace.tusky.util.ListUtils) AccountManager(com.keylesspalace.tusky.db.AccountManager) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) Injectable(com.keylesspalace.tusky.di.Injectable) Activity(android.app.Activity) Collections(java.util.Collections) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) SharedPreferences(android.content.SharedPreferences) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) BackgroundMessageView(com.keylesspalace.tusky.view.BackgroundMessageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ListView(android.widget.ListView) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) ListStatusAccessibilityDelegate(com.keylesspalace.tusky.util.ListStatusAccessibilityDelegate) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Button(android.widget.Button) NonNull(androidx.annotation.NonNull) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) Nullable(androidx.annotation.Nullable)

Example 39 with NonNull

use of androidx.annotation.NonNull in project Tusky by Vavassor.

the class LinkHelper method setClickableText.

/**
 * Finds links, mentions, and hashtags in a piece of text and makes them clickable, associating
 * them with callbacks to notify when they're clicked.
 *
 * @param view the returned text will be put in
 * @param content containing text with mentions, links, or hashtags
 * @param mentions any '@' mentions which are known to be in the content
 * @param listener to notify about particular spans that are clicked
 */
public static void setClickableText(TextView view, CharSequence content, @Nullable List<Status.Mention> mentions, final LinkListener listener) {
    SpannableStringBuilder builder = SpannableStringBuilder.valueOf(content);
    URLSpan[] urlSpans = builder.getSpans(0, content.length(), URLSpan.class);
    for (URLSpan span : urlSpans) {
        int start = builder.getSpanStart(span);
        int end = builder.getSpanEnd(span);
        int flags = builder.getSpanFlags(span);
        CharSequence text = builder.subSequence(start, end);
        ClickableSpan customSpan = null;
        if (text.charAt(0) == '#') {
            final String tag = text.subSequence(1, text.length()).toString();
            customSpan = new NoUnderlineURLSpan(span.getURL()) {

                @Override
                public void onClick(@NonNull View widget) {
                    listener.onViewTag(tag);
                }
            };
        } else if (text.charAt(0) == '@' && mentions != null && mentions.size() > 0) {
            // https://github.com/tuskyapp/Tusky/pull/2339
            String id = null;
            for (Status.Mention mention : mentions) {
                if (mention.getUrl().equals(span.getURL())) {
                    id = mention.getId();
                    break;
                }
            }
            if (id != null) {
                final String accountId = id;
                customSpan = new NoUnderlineURLSpan(span.getURL()) {

                    @Override
                    public void onClick(@NonNull View widget) {
                        listener.onViewAccount(accountId);
                    }
                };
            }
        }
        if (customSpan == null) {
            customSpan = new NoUnderlineURLSpan(span.getURL()) {

                @Override
                public void onClick(@NonNull View widget) {
                    listener.onViewUrl(getURL());
                }
            };
        }
        builder.removeSpan(span);
        builder.setSpan(customSpan, start, end, flags);
        /* Add zero-width space after links in end of line to fix its too large hitbox.
             * See also : https://github.com/tuskyapp/Tusky/issues/846
             *            https://github.com/tuskyapp/Tusky/pull/916 */
        if (end >= builder.length() || builder.subSequence(end, end + 1).toString().equals("\n")) {
            builder.insert(end, "\u200B");
        }
    }
    view.setText(builder);
    view.setMovementMethod(LinkMovementMethod.getInstance());
}
Also used : NonNull(androidx.annotation.NonNull) URLSpan(android.text.style.URLSpan) ClickableSpan(android.text.style.ClickableSpan) TextView(android.widget.TextView) View(android.view.View) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 40 with NonNull

use of androidx.annotation.NonNull in project kdeconnect-android by KDE.

the class SMSHelper method parseMMS.

/**
 * Parse all parts of the MMS message into a message
 * Original implementation from https://stackoverflow.com/a/6446831/3723163
 */
@NonNull
private static Message parseMMS(@NonNull Context context, @NonNull Map<String, String> messageInfo, @NonNull List<TelephonyHelper.LocalPhoneNumber> userPhoneNumbers) {
    int event = Message.EVENT_UNKNOWN;
    @NonNull String body = "";
    long date;
    int type;
    int read = Integer.parseInt(messageInfo.get(Message.READ));
    @NonNull ThreadID threadID = new ThreadID(Long.parseLong(messageInfo.get(Message.THREAD_ID)));
    long uID = Long.parseLong(messageInfo.get(Message.U_ID));
    int subscriptionID = NumberUtils.toInt(messageInfo.get(Message.SUBSCRIPTION_ID));
    List<Attachment> attachments = new ArrayList<>();
    String[] columns = { // The content ID of this part
    Telephony.Mms.Part._ID, // The location in the filesystem of the data
    Telephony.Mms.Part._DATA, // The mime type of the data
    Telephony.Mms.Part.CONTENT_TYPE, // The plain text body of this MMS
    Telephony.Mms.Part.TEXT, // Charset of the plain text body
    Telephony.Mms.Part.CHARSET };
    String mmsID = messageInfo.get(Message.U_ID);
    String selection = Telephony.Mms.Part.MSG_ID + " = ?";
    String[] selectionArgs = { mmsID };
    // Get text body and attachments of the message
    try (Cursor cursor = context.getContentResolver().query(getMMSPartUri(), columns, selection, selectionArgs, null)) {
        if (cursor != null && cursor.moveToFirst()) {
            int partIDColumn = cursor.getColumnIndexOrThrow(Telephony.Mms.Part._ID);
            int contentTypeColumn = cursor.getColumnIndexOrThrow(Telephony.Mms.Part.CONTENT_TYPE);
            int dataColumn = cursor.getColumnIndexOrThrow(Telephony.Mms.Part._DATA);
            int textColumn = cursor.getColumnIndexOrThrow(Telephony.Mms.Part.TEXT);
            do {
                long partID = cursor.getLong(partIDColumn);
                String contentType = cursor.getString(contentTypeColumn);
                String data = cursor.getString(dataColumn);
                if (MimeType.isTypeText(contentType)) {
                    if (data != null) {
                        // data != null means the data is on disk. Go get it.
                        body = getMmsText(context, partID);
                    } else {
                        body = cursor.getString(textColumn);
                    }
                    event = addEventFlag(event, Message.EVENT_TEXT_MESSAGE);
                } else if (MimeType.isTypeImage(contentType)) {
                    String fileName = data.substring(data.lastIndexOf('/') + 1);
                    // Get the actual image from the mms database convert it into thumbnail and encode to Base64
                    Bitmap image = SmsMmsUtils.getMmsImage(context, partID);
                    Bitmap thumbnailImage = ThumbnailUtils.extractThumbnail(image, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
                    String encodedThumbnail = SmsMmsUtils.bitMapToBase64(thumbnailImage);
                    attachments.add(new Attachment(partID, contentType, encodedThumbnail, fileName));
                } else if (MimeType.isTypeVideo(contentType)) {
                    String fileName = data.substring(data.lastIndexOf('/') + 1);
                    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
                    retriever.setDataSource(context, ContentUris.withAppendedId(getMMSPartUri(), partID));
                    Bitmap videoThumbnail = retriever.getFrameAtTime();
                    String encodedThumbnail = SmsMmsUtils.bitMapToBase64(Bitmap.createScaledBitmap(videoThumbnail, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, true));
                    attachments.add(new Attachment(partID, contentType, encodedThumbnail, fileName));
                } else if (MimeType.isTypeAudio(contentType)) {
                    String fileName = data.substring(data.lastIndexOf('/') + 1);
                    attachments.add(new Attachment(partID, contentType, null, fileName));
                } else {
                    Log.v("SMSHelper", "Unsupported attachment type: " + contentType);
                }
            } while (cursor.moveToNext());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Determine whether the message was in- our out- bound
    long messageBox = Long.parseLong(messageInfo.get(Telephony.Mms.MESSAGE_BOX));
    if (messageBox == Telephony.Mms.MESSAGE_BOX_INBOX) {
        type = Telephony.Sms.MESSAGE_TYPE_INBOX;
    } else if (messageBox == Telephony.Mms.MESSAGE_BOX_SENT) {
        type = Telephony.Sms.MESSAGE_TYPE_SENT;
    } else {
        // As an undocumented feature, it looks like the values of Mms.MESSAGE_BOX_*
        // are the same as Sms.MESSAGE_TYPE_* of the same type. So by default let's just use
        // the value we've got.
        // This includes things like drafts, which are a far-distant plan to support
        type = Integer.parseInt(messageInfo.get(Telephony.Mms.MESSAGE_BOX));
    }
    // Get address(es) of the message
    MultimediaMessagePdu msg = getMessagePdu(context, uID);
    Address from = SmsMmsUtils.getMmsFrom(msg);
    List<Address> to = SmsMmsUtils.getMmsTo(msg);
    List<Address> addresses = new ArrayList<>();
    if (from != null) {
        boolean isLocalPhoneNumber = userPhoneNumbers.stream().anyMatch(localPhoneNumber -> localPhoneNumber.isMatchingPhoneNumber(from.address));
        if (!isLocalPhoneNumber && !from.toString().equals("insert-address-token")) {
            addresses.add(from);
        }
    }
    if (to != null) {
        for (Address address : to) {
            boolean isLocalPhoneNumber = userPhoneNumbers.stream().anyMatch(localPhoneNumber -> localPhoneNumber.isMatchingPhoneNumber(address.address));
            if (!isLocalPhoneNumber && !from.toString().equals("insert-address-token")) {
                addresses.add(address);
            }
        }
    }
    if (addresses.size() >= 2) {
        event = addEventFlag(event, Message.EVENT_MULTI_TARGET);
    }
    // Canonicalize the date field
    // SMS uses epoch milliseconds, MMS uses epoch seconds. Standardize on milliseconds.
    long rawDate = Long.parseLong(messageInfo.get(Message.DATE));
    date = rawDate * 1000;
    return new Message(addresses, body, date, type, read, threadID, uID, event, subscriptionID, attachments);
}
Also used : ArrayList(java.util.ArrayList) MultimediaMessagePdu(com.google.android.mms.pdu_alt.MultimediaMessagePdu) Cursor(android.database.Cursor) SuppressLint(android.annotation.SuppressLint) SQLiteException(android.database.sqlite.SQLiteException) JSONException(org.json.JSONException) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) NonNull(androidx.annotation.NonNull) MediaMetadataRetriever(android.media.MediaMetadataRetriever) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1200 View (android.view.View)192 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)118 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)77 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62