Search in sources :

Example 6 with RequestCreator

use of com.squareup.picasso.RequestCreator in project android-sdk-examples by IndoorAtlas.

the class OpenStreetMapOverlay method fetchFloorPlanBitmap.

/**
 * Download floor plan using Picasso library.
 */
private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {
    final String url = floorPlan.getUrl();
    if (mLoadTarget == null) {
        mLoadTarget = new Target() {

            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x" + bitmap.getHeight());
                setupGroundOverlay(floorPlan, bitmap);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            // N/A
            }

            @Override
            public void onBitmapFailed(Drawable placeHolderDraweble) {
                Toast.makeText(OpenStreetMapOverlay.this, "Failed to load bitmap", Toast.LENGTH_SHORT).show();
                mOverlayFloorPlan = null;
            }
        };
    }
    RequestCreator request = Picasso.with(this).load(url);
    final int bitmapWidth = floorPlan.getBitmapWidth();
    final int bitmapHeight = floorPlan.getBitmapHeight();
    if (bitmapHeight > MAX_DIMENSION) {
        request.resize(0, MAX_DIMENSION);
    } else if (bitmapWidth > MAX_DIMENSION) {
        request.resize(MAX_DIMENSION, 0);
    }
    request.into(mLoadTarget);
}
Also used : Target(com.squareup.picasso.Target) Bitmap(android.graphics.Bitmap) Picasso(com.squareup.picasso.Picasso) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GeoPoint(org.osmdroid.util.GeoPoint) RequestCreator(com.squareup.picasso.RequestCreator)

Example 7 with RequestCreator

use of com.squareup.picasso.RequestCreator in project android-sdk-examples by IndoorAtlas.

the class WayfindingOverlayActivity method fetchFloorPlanBitmap.

/**
 * Download floor plan using Picasso library.
 */
private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {
    final String url = floorPlan.getUrl();
    if (mLoadTarget == null) {
        mLoadTarget = new Target() {

            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x" + bitmap.getHeight());
                setupGroundOverlay(floorPlan, bitmap);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            // N/A
            }

            @Override
            public void onBitmapFailed(Drawable placeHolderDraweble) {
                showInfo("Failed to load bitmap");
                mOverlayFloorPlan = null;
            }
        };
    }
    RequestCreator request = Picasso.with(this).load(url);
    final int bitmapWidth = floorPlan.getBitmapWidth();
    final int bitmapHeight = floorPlan.getBitmapHeight();
    if (bitmapHeight > MAX_DIMENSION) {
        request.resize(0, MAX_DIMENSION);
    } else if (bitmapWidth > MAX_DIMENSION) {
        request.resize(MAX_DIMENSION, 0);
    }
    request.into(mLoadTarget);
}
Also used : Target(com.squareup.picasso.Target) Bitmap(android.graphics.Bitmap) Picasso(com.squareup.picasso.Picasso) Drawable(android.graphics.drawable.Drawable) RequestCreator(com.squareup.picasso.RequestCreator)

Example 8 with RequestCreator

use of com.squareup.picasso.RequestCreator in project iNaturalistAndroid by inaturalist.

the class UserActivitiesAdapter method loadObsImage.

private void loadObsImage(int obsId, final View view, BetterJSONObject item, final int position) {
    Log.e(TAG, obsId + ": loadObsImage " + position + ":" + view);
    ImageView obsPic = (ImageView) view.findViewById(R.id.obs_pic);
    ImageView userPic = (ImageView) view.findViewById(R.id.user_pic);
    ProgressBar loadingObs = (ProgressBar) view.findViewById(R.id.loading);
    final View loadingObsOverlay = view.findViewById(R.id.loading_overlay);
    view.post(new Runnable() {

        @Override
        public void run() {
            loadingObsOverlay.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, view.getHeight()));
        }
    });
    Cursor c = mContext.getContentResolver().query(Observation.CONTENT_URI, Observation.PROJECTION, "id = ?", new String[] { String.valueOf(obsId) }, null);
    if ((c.getCount() == 0) || (!blah.containsKey(obsId))) {
        blah.put(obsId, true);
        // Couldn't find observation (must be an old one that isn't saved locally) - download it
        c.close();
        // Show loading status
        obsPic.setImageResource(R.drawable.iconic_taxon_unknown);
        loadingObs.setVisibility(View.VISIBLE);
        loadingObsOverlay.setVisibility(View.VISIBLE);
        userPic.setVisibility(View.GONE);
        view.setBackgroundResource(R.drawable.activity_item_background);
        if (!mObsIdBeingDownloaded.containsKey(obsId) || !mObsIdBeingDownloaded.get(obsId)) {
            Intent serviceIntent = new Intent(INaturalistService.ACTION_GET_AND_SAVE_OBSERVATION, null, mContext, INaturalistService.class);
            serviceIntent.putExtra(INaturalistService.OBSERVATION_ID, obsId);
            mContext.startService(serviceIntent);
            Log.e(TAG, obsId + ": Start download: " + mObsIdBeingDownloaded.containsKey(obsId));
        } else {
            Log.e(TAG, obsId + ": Downloading");
        }
        mObsIdBeingDownloaded.put(obsId, true);
        // So when we get the result - we'll know which obs pic to set
        if (!mObsIdToView.containsKey(obsId)) {
            mObsIdToView.put(obsId, new ArrayList<Pair<View, Integer>>());
        }
        List<Pair<View, Integer>> views = mObsIdToView.get(obsId);
        views.add(new Pair<>(view, position));
        return;
    }
    Log.d(TAG, obsId + ": Showing");
    final Observation obs = new Observation(c);
    c.close();
    loadingObs.setVisibility(View.GONE);
    loadingObsOverlay.setVisibility(View.GONE);
    userPic.setVisibility(View.VISIBLE);
    view.setBackgroundResource(item.getBoolean("viewed") ? R.drawable.activity_item_background : R.drawable.activity_unviewed_item_background);
    // Get first image for the observation
    Cursor opc = mContext.getContentResolver().query(ObservationPhoto.CONTENT_URI, ObservationPhoto.PROJECTION, "observation_id = ?", new String[] { String.valueOf(obsId) }, ObservationPhoto.DEFAULT_SORT_ORDER);
    int iconicTaxonDrawable = ObservationCursorAdapter.getIconicTaxonDrawable(obs.iconic_taxon_name);
    if (opc.getCount() == 0) {
        // No photos for observation - just show iconic taxon image
        obsPic.setImageResource(iconicTaxonDrawable);
    } else {
        // Show first photo
        ObservationPhoto op = new ObservationPhoto(opc);
        RequestCreator rc;
        if (op.photo_url != null) {
            // Online photo
            rc = Picasso.with(mContext).load(op.photo_url);
        } else {
            // Offline photo
            rc = Picasso.with(mContext).load(new File(op.photo_filename));
        }
        rc.placeholder(iconicTaxonDrawable).fit().centerCrop().into(obsPic);
    }
    opc.close();
    View.OnClickListener showObs = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mOnUpdateViewed.onUpdateViewed(obs, position);
            // Show observation details screen
            Intent intent;
            if ((obs.user_login != null) && (obs.user_login.equals(mApp.currentUserLogin()))) {
                // It's our own observation - allow editing it
                Uri uri = obs.getUri();
                intent = new Intent(Intent.ACTION_VIEW, uri, mContext, ObservationViewerActivity.class);
            } else {
                // It's another user's observation - read only mode
                intent = new Intent(mContext, ObservationViewerActivity.class);
                intent.putExtra("observation", obs.toJSONObject().toString());
                intent.putExtra("read_only", true);
                intent.putExtra("reload", true);
            }
            intent.putExtra(ObservationViewerActivity.SHOW_COMMENTS, true);
            intent.putExtra(ObservationViewerActivity.SCROLL_TO_COMMENTS_BOTTOM, true);
            mContext.startActivity(intent);
            try {
                JSONObject eventParams = new JSONObject();
                eventParams.put(AnalyticsClient.EVENT_PARAM_VIA, AnalyticsClient.EVENT_VALUE_UPDATES);
                AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_NAVIGATE_OBS_DETAILS, eventParams);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            try {
                JSONObject item = mResultList.get(position);
                item.put("viewed", true);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            view.setBackgroundResource(R.drawable.activity_item_background);
            // Mark observation update as viewed
            Intent serviceIntent = new Intent(INaturalistService.ACTION_VIEWED_UPDATE, null, mContext, INaturalistService.class);
            serviceIntent.putExtra(INaturalistService.OBSERVATION_ID, obs.id);
            mContext.startService(serviceIntent);
        }
    };
    view.setOnClickListener(showObs);
}
Also used : JSONException(org.json.JSONException) Intent(android.content.Intent) Cursor(android.database.Cursor) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) RequestCreator(com.squareup.picasso.RequestCreator) JSONObject(org.json.JSONObject) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) File(java.io.File) Pair(android.util.Pair)

Example 9 with RequestCreator

use of com.squareup.picasso.RequestCreator in project Virtualview-Android by alibaba.

the class LocalPreviewActivity method initForPreview.

private void initForPreview() {
    if (mVafContext == null) {
        mVafContext = new VafContext(this);
        mVafContext.setImageLoaderAdapter(new IImageLoaderAdapter() {

            private List<ImageTarget> cache = new ArrayList<ImageTarget>();

            @Override
            public void bindImage(String uri, final ImageBase imageBase, int reqWidth, int reqHeight) {
                RequestCreator requestCreator = Picasso.with(LocalPreviewActivity.this).load(uri);
                Log.d("LocalPreviewActivity", "bindImage request width height " + reqHeight + " " + reqWidth);
                if (reqHeight > 0 || reqWidth > 0) {
                    requestCreator.resize(reqWidth, reqHeight);
                }
                ImageTarget imageTarget = new ImageTarget(imageBase);
                cache.add(imageTarget);
                requestCreator.into(imageTarget);
            }

            @Override
            public void getBitmap(String uri, int reqWidth, int reqHeight, final Listener lis) {
                RequestCreator requestCreator = Picasso.with(LocalPreviewActivity.this).load(uri);
                Log.d("LocalPreviewActivity", "getBitmap request width height " + reqHeight + " " + reqWidth);
                if (reqHeight > 0 || reqWidth > 0) {
                    requestCreator.resize(reqWidth, reqHeight);
                }
                ImageTarget imageTarget = new ImageTarget(lis);
                cache.add(imageTarget);
                requestCreator.into(imageTarget);
            }
        });
        mViewManager = mVafContext.getViewManager();
        mViewManager.init(this.getApplicationContext());
        mVafContext.getEventManager().register(EventManager.TYPE_Click, new ClickProcessorImpl());
        mVafContext.getEventManager().register(EventManager.TYPE_Exposure, new ExposureProcessorImpl());
    }
}
Also used : Listener(com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.Listener) ArrayList(java.util.ArrayList) RequestCreator(com.squareup.picasso.RequestCreator) VafContext(com.tmall.wireless.vaf.framework.VafContext) IImageLoaderAdapter(com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.IImageLoaderAdapter) ClickProcessorImpl(com.tmall.wireless.virtualviewdemo.custom.ClickProcessorImpl) ExposureProcessorImpl(com.tmall.wireless.virtualviewdemo.custom.ExposureProcessorImpl) ImageBase(com.tmall.wireless.vaf.virtualview.view.image.ImageBase)

Example 10 with RequestCreator

use of com.squareup.picasso.RequestCreator in project open-event-android by fossasia.

the class SpeakerViewHolder method bindSpeaker.

public void bindSpeaker(Speaker speaker) {
    this.speaker = speaker;
    String thumbnail = Utils.parseImageUri(this.speaker.getThumbnailImageUrl());
    String name = Utils.checkStringEmpty(speaker.getName());
    if (thumbnail == null)
        thumbnail = Utils.parseImageUri(this.speaker.getPhotoUrl());
    final Palette.PaletteAsyncListener paletteAsyncListener = palette -> {
        Palette.Swatch swatch = palette.getVibrantSwatch();
        if (speakerTextualInfo != null) {
            if (swatch != null) {
                // bitmap has vibrant swatch profile
                speakerTextualInfo.setBackgroundColor(swatch.getRgb());
            } else {
                Palette.Swatch swatch2 = palette.getDarkMutedSwatch();
                if (swatch2 != null) {
                    // bitmap has dark muted swatch profile
                    speakerTextualInfo.setBackgroundColor(swatch2.getRgb());
                } else {
                    speakerTextualInfo.setBackgroundColor(ContextCompat.getColor(context, R.color.color_primary_dark));
                }
            }
        }
    };
    RequestCreator requestCreator = StrategyRegistry.getInstance().getHttpStrategy().getPicassoWithCache().load(thumbnail);
    TextDrawable drawable;
    if (isImageCircle) {
        requestCreator.transform(new CircleTransform());
        drawable = Views.getTextDrawableBuilder().round().build(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
    } else {
        drawable = Views.getTextDrawableBuilder().buildRect(Utils.getNameLetters(name), ColorGenerator.MATERIAL.getColor(name));
    }
    final Target target = new Target() {

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            speakerImage.setImageBitmap(bitmap);
            if (speakerTextualInfo != null) {
                Palette.from(bitmap).generate(paletteAsyncListener);
            }
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            speakerImage.setImageDrawable(drawable);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            speakerImage.setImageDrawable(drawable);
        }
    };
    requestCreator.into(target);
    setStringField(speakerName, name);
    setStringField(speakerDesignation, String.format("%s %s", speaker.getPosition(), speaker.getOrganisation()));
    setStringField(speakerCountry, speaker.getCountry());
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Palette(android.support.v7.graphics.Palette) ButterKnife(butterknife.ButterKnife) Utils(org.fossasia.openevent.common.utils.Utils) ImageView(android.widget.ImageView) Intent(android.content.Intent) Drawable(android.graphics.drawable.Drawable) BindView(butterknife.BindView) Picasso(com.squareup.picasso.Picasso) ActivityOptions(android.app.ActivityOptions) Views(org.fossasia.openevent.common.ui.Views) Target(com.squareup.picasso.Target) View(android.view.View) CircleTransform(org.fossasia.openevent.common.ui.image.CircleTransform) Speaker(org.fossasia.openevent.data.Speaker) R(org.fossasia.openevent.R) StrategyRegistry(org.fossasia.openevent.config.StrategyRegistry) RequestCreator(com.squareup.picasso.RequestCreator) ContextCompat(android.support.v4.content.ContextCompat) TextUtils(android.text.TextUtils) ColorGenerator(com.amulyakhare.textdrawable.util.ColorGenerator) Timber(timber.log.Timber) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Bitmap(android.graphics.Bitmap) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Palette(android.support.v7.graphics.Palette) Target(com.squareup.picasso.Target) Bitmap(android.graphics.Bitmap) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) Drawable(android.graphics.drawable.Drawable) CircleTransform(org.fossasia.openevent.common.ui.image.CircleTransform) RequestCreator(com.squareup.picasso.RequestCreator)

Aggregations

RequestCreator (com.squareup.picasso.RequestCreator)24 Picasso (com.squareup.picasso.Picasso)10 View (android.view.View)8 ImageView (android.widget.ImageView)8 TextView (android.widget.TextView)6 Bitmap (android.graphics.Bitmap)5 Drawable (android.graphics.drawable.Drawable)5 Target (com.squareup.picasso.Target)5 Callback (com.squareup.picasso.Callback)4 File (java.io.File)4 Intent (android.content.Intent)3 Uri (android.net.Uri)3 VafContext (com.tmall.wireless.vaf.framework.VafContext)3 IImageLoaderAdapter (com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.IImageLoaderAdapter)3 NonNull (android.support.annotation.NonNull)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ViewGroup (android.view.ViewGroup)2 Listener (com.tmall.wireless.vaf.virtualview.Helper.ImageLoader.Listener)2 ImageBase (com.tmall.wireless.vaf.virtualview.view.image.ImageBase)2 ArrayList (java.util.ArrayList)2