Search in sources :

Example 61 with Nullable

use of androidx.annotation.Nullable in project Douya by DreaminginCodeZH.

the class GalleryAdapter method loadImageForPosition.

private void loadImageForPosition(int position, ViewHolder holder) {
    ViewUtils.fadeIn(holder.progress);
    GlideApp.with(holder.progress.getContext()).downloadOnlyDefaultPriority().load(mImageList.get(position)).progressListener(new ProgressListener() {

        @Override
        public void onProgress(long bytesRead, long contentLength, boolean done) {
            int progress = Math.round((float) bytesRead / contentLength * holder.progress.getMax());
            ProgressBarCompat.setProgress(holder.progress, progress, true);
        }
    }).listener(new RequestListener<File>() {

        @Override
        public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
            return false;
        }

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
            showError(e, R.string.gallery_network_error, holder);
            return false;
        }
    }).into(new SimpleTarget<File>() {

        @Override
        public void onResourceReady(File file, Transition<? super File> transition) {
            mFileMap.put(position, file);
            if (mListener != null) {
                mListener.onFileDownloaded(position);
            }
            holder.progress.setIndeterminate(true);
            loadImageFromFile(file, holder);
        }
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) DataSource(com.bumptech.glide.load.DataSource) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) ProgressListener(me.zhanghai.android.douya.glide.progress.ProgressListener) File(java.io.File) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable)

Example 62 with Nullable

use of androidx.annotation.Nullable in project AntennaPod by AntennaPod.

the class OnlineFeedViewActivity method doParseFeed.

/**
 * Try to parse the feed.
 * @return  The FeedHandlerResult if successful.
 *          Null if unsuccessful but we started another attempt.
 * @throws Exception If unsuccessful but we do not know a resolution.
 */
@Nullable
private FeedHandlerResult doParseFeed() throws Exception {
    FeedHandler handler = new FeedHandler();
    try {
        return handler.parseFeed(feed);
    } catch (UnsupportedFeedtypeException e) {
        Log.d(TAG, "Unsupported feed type detected");
        if ("html".equalsIgnoreCase(e.getRootElement())) {
            boolean dialogShown = showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url());
            if (dialogShown) {
                // Should not display an error message
                return null;
            } else {
                throw new UnsupportedFeedtypeException(getString(R.string.download_error_unsupported_type_html));
            }
        } else {
            throw e;
        }
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
        throw e;
    } finally {
        boolean rc = new File(feed.getFile_url()).delete();
        Log.d(TAG, "Deleted feed source file. Result: " + rc);
    }
}
Also used : UnsupportedFeedtypeException(de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException) FeedHandler(de.danoeh.antennapod.parser.feed.FeedHandler) File(java.io.File) UnsupportedFeedtypeException(de.danoeh.antennapod.parser.feed.UnsupportedFeedtypeException) FeedUrlNotFoundException(de.danoeh.antennapod.core.feed.FeedUrlNotFoundException) IOException(java.io.IOException) Nullable(androidx.annotation.Nullable)

Example 63 with Nullable

use of androidx.annotation.Nullable in project AntennaPod by AntennaPod.

the class OnlineFeedViewActivity method showFeedInformation.

/**
 * Called when feed parsed successfully.
 * This method is executed on the GUI thread.
 */
private void showFeedInformation(final Feed feed, Map<String, String> alternateFeedUrls) {
    viewBinding.progressBar.setVisibility(View.GONE);
    viewBinding.feedDisplayContainer.setVisibility(View.VISIBLE);
    if (isFeedFoundBySearch) {
        int resId = R.string.no_feed_url_podcast_found_by_search;
        Snackbar.make(findViewById(android.R.id.content), resId, Snackbar.LENGTH_LONG).show();
    }
    this.feed = feed;
    this.selectedDownloadUrl = feed.getDownload_url();
    viewBinding.backgroundImage.setColorFilter(new LightingColorFilter(0xff828282, 0x000000));
    View header = View.inflate(this, R.layout.onlinefeedview_header, null);
    viewBinding.listView.addHeaderView(header);
    viewBinding.listView.setSelector(android.R.color.transparent);
    viewBinding.listView.setAdapter(new FeedItemlistDescriptionAdapter(this, 0, feed.getItems()));
    TextView description = header.findViewById(R.id.txtvDescription);
    if (StringUtils.isNotBlank(feed.getImageUrl())) {
        Glide.with(this).load(feed.getImageUrl()).apply(new RequestOptions().placeholder(R.color.light_gray).error(R.color.light_gray).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).fitCenter().dontAnimate()).into(viewBinding.coverImage);
        Glide.with(this).load(feed.getImageUrl()).apply(new RequestOptions().placeholder(R.color.image_readability_tint).error(R.color.image_readability_tint).diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).transform(new FastBlurTransformation()).dontAnimate()).into(viewBinding.backgroundImage);
    }
    viewBinding.titleLabel.setText(feed.getTitle());
    viewBinding.authorLabel.setText(feed.getAuthor());
    description.setText(HtmlToPlainText.getPlainText(feed.getDescription()));
    viewBinding.subscribeButton.setOnClickListener(v -> {
        if (feedInFeedlist(feed)) {
            openFeed();
        } else {
            Feed f = new Feed(selectedDownloadUrl, null, feed.getTitle());
            f.setPreferences(feed.getPreferences());
            this.feed = f;
            DownloadService.download(this, false, DownloadRequestCreator.create(f).build());
            didPressSubscribe = true;
            handleUpdatedFeedStatus(feed);
        }
    });
    viewBinding.stopPreviewButton.setOnClickListener(v -> {
        PlaybackPreferences.writeNoMediaPlaying();
        IntentUtils.sendLocalBroadcast(this, PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE);
    });
    if (UserPreferences.isEnableAutodownload()) {
        SharedPreferences preferences = getSharedPreferences(PREFS, MODE_PRIVATE);
        viewBinding.autoDownloadCheckBox.setChecked(preferences.getBoolean(PREF_LAST_AUTO_DOWNLOAD, true));
    }
    final int MAX_LINES_COLLAPSED = 10;
    description.setMaxLines(MAX_LINES_COLLAPSED);
    description.setOnClickListener(v -> {
        if (description.getMaxLines() > MAX_LINES_COLLAPSED) {
            description.setMaxLines(MAX_LINES_COLLAPSED);
        } else {
            description.setMaxLines(2000);
        }
    });
    if (alternateFeedUrls.isEmpty()) {
        viewBinding.alternateUrlsSpinner.setVisibility(View.GONE);
    } else {
        viewBinding.alternateUrlsSpinner.setVisibility(View.VISIBLE);
        final List<String> alternateUrlsList = new ArrayList<>();
        final List<String> alternateUrlsTitleList = new ArrayList<>();
        alternateUrlsList.add(feed.getDownload_url());
        alternateUrlsTitleList.add(feed.getTitle());
        alternateUrlsList.addAll(alternateFeedUrls.keySet());
        for (String url : alternateFeedUrls.keySet()) {
            alternateUrlsTitleList.add(alternateFeedUrls.get(url));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.alternate_urls_item, alternateUrlsTitleList) {

            @Override
            public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                // reusing the old view causes a visual bug on Android <= 10
                return super.getDropDownView(position, null, parent);
            }
        };
        adapter.setDropDownViewResource(R.layout.alternate_urls_dropdown_item);
        viewBinding.alternateUrlsSpinner.setAdapter(adapter);
        viewBinding.alternateUrlsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                selectedDownloadUrl = alternateUrlsList.get(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
    }
    handleUpdatedFeedStatus(feed);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) FastBlurTransformation(de.danoeh.antennapod.core.glide.FastBlurTransformation) FeedItemlistDescriptionAdapter(de.danoeh.antennapod.adapter.FeedItemlistDescriptionAdapter) NonNull(androidx.annotation.NonNull) LightingColorFilter(android.graphics.LightingColorFilter) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) Nullable(androidx.annotation.Nullable) Feed(de.danoeh.antennapod.model.feed.Feed)

Example 64 with Nullable

use of androidx.annotation.Nullable in project RSAndroidApp by RailwayStations.

the class DetailsActivity method checkForLocalPhoto.

/**
 * Check if there's a local photo file for this station.
 *
 * @return the Bitmap of the photo, or null if none exists.
 */
@Nullable
private Bitmap checkForLocalPhoto(final Upload upload) {
    // show the image
    final File localFile = getStoredMediaFile(upload);
    Log.d(TAG, "File: " + localFile);
    crc32 = null;
    if (localFile != null && localFile.canRead()) {
        Log.d(TAG, "FileGetPath: " + localFile.getPath());
        try (final CheckedInputStream cis = new CheckedInputStream(new FileInputStream(localFile), new CRC32())) {
            final Bitmap scaledScreen = BitmapFactory.decodeStream(cis);
            crc32 = cis.getChecksum().getValue();
            Log.d(TAG, "img width " + scaledScreen.getWidth() + ", height " + scaledScreen.getHeight() + ", crc32 " + crc32);
            localFotoUsed = true;
            setButtonEnabled(binding.details.buttonUpload, true);
            return scaledScreen;
        } catch (final Exception e) {
            Log.e(TAG, String.format("Error reading media file for station %s", bahnhofId), e);
        }
    } else {
        localFotoUsed = false;
        setButtonEnabled(binding.details.buttonUpload, false);
        Log.e(TAG, String.format("Media file not available for station %s", bahnhofId));
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) CRC32(java.util.zip.CRC32) File(java.io.File) CheckedInputStream(java.util.zip.CheckedInputStream) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Nullable(androidx.annotation.Nullable)

Example 65 with Nullable

use of androidx.annotation.Nullable in project Conversations by siacs.

the class ActionBarUtil method findViewSupportOrAndroid.

@SuppressWarnings("ConstantConditions")
@Nullable
private static View findViewSupportOrAndroid(@NonNull View root, @NonNull String resourceName) {
    Context context = root.getContext();
    View result = null;
    if (result == null) {
        int supportID = context.getResources().getIdentifier(resourceName, "id", context.getPackageName());
        result = root.findViewById(supportID);
    }
    if (result == null) {
        int androidID = context.getResources().getIdentifier(resourceName, "id", "android");
        result = root.findViewById(androidID);
    }
    return result;
}
Also used : Context(android.content.Context) View(android.view.View) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1124 View (android.view.View)188 Bundle (android.os.Bundle)111 IOException (java.io.IOException)99 NonNull (androidx.annotation.NonNull)96 ArrayList (java.util.ArrayList)95 Context (android.content.Context)93 TextView (android.widget.TextView)92 Cursor (android.database.Cursor)71 SuppressLint (android.annotation.SuppressLint)69 Uri (android.net.Uri)66 RecyclerView (androidx.recyclerview.widget.RecyclerView)59 List (java.util.List)58 ViewGroup (android.view.ViewGroup)56 Test (org.junit.Test)55 Intent (android.content.Intent)53 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 R (org.thoughtcrime.securesms.R)46 LayoutInflater (android.view.LayoutInflater)45 ImageView (android.widget.ImageView)43