Search in sources :

Example 11 with Picasso

use of com.squareup.picasso.Picasso 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 12 with Picasso

use of com.squareup.picasso.Picasso 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 13 with Picasso

use of com.squareup.picasso.Picasso in project SeaStar by 13120241790.

the class MultiImageSelectorFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // 选择图片数量
    mDesireImageCount = getArguments().getInt(EXTRA_SELECT_COUNT);
    // 图片选择模式
    final int mode = getArguments().getInt(EXTRA_SELECT_MODE);
    // 默认选择
    if (mode == MODE_MULTI) {
        ArrayList<String> tmp = getArguments().getStringArrayList(EXTRA_DEFAULT_SELECTED_LIST);
        if (tmp != null && tmp.size() > 0) {
            resultList = tmp;
        }
    }
    mIsShowCamera = getArguments().getBoolean(EXTRA_SHOW_CAMERA, true);
    mImageAdapter = new ImageGridAdapter(getActivity(), mIsShowCamera);
    // 是否显示选择指示器
    mImageAdapter.showSelectIndicator(mode == MODE_MULTI);
    mPopupAnchorView = view.findViewById(R.id.footer);
    mTimeLineText = (TextView) view.findViewById(R.id.timeline_area);
    // 初始化,先隐藏当前timeline
    mTimeLineText.setVisibility(View.GONE);
    mCategoryText = (TextView) view.findViewById(R.id.category_btn);
    // 初始化,加载所有图片
    mCategoryText.setText(R.string.folder_all);
    mCategoryText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mFolderPopupWindow == null) {
                createPopupFolderList(mGridWidth, mGridHeight);
            }
            if (mFolderPopupWindow.isShowing()) {
                mFolderPopupWindow.dismiss();
            } else {
                mFolderPopupWindow.show();
                int index = mFolderAdapter.getSelectIndex();
                index = index == 0 ? index : index - 1;
                mFolderPopupWindow.getListView().setSelection(index);
            }
        }
    });
    mPreviewBtn = (Button) view.findViewById(R.id.preview);
    mPreviewBtn.setVisibility(View.VISIBLE);
    // 初始化,按钮状态初始化
    if (resultList == null || resultList.size() <= 0) {
        mPreviewBtn.setText(R.string.preview);
        mPreviewBtn.setEnabled(false);
    }
    mPreviewBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // TODO 预览
            Intent mIntent = new Intent(getActivity(), PreviewActivity.class);
            mIntent.putStringArrayListExtra("resultList", resultList);
            startActivityForResult(mIntent, PREVIEW_SHOW);
        }
    });
    mGridView = (GridView) view.findViewById(R.id.grid);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int state) {
            final Picasso picasso = Picasso.with(getActivity());
            if (state == SCROLL_STATE_IDLE || state == SCROLL_STATE_TOUCH_SCROLL) {
                picasso.resumeTag(getActivity());
            } else {
                picasso.pauseTag(getActivity());
            }
            if (state == SCROLL_STATE_IDLE) {
            // 停止滑动,日期指示器消失
            // mTimeLineText.setVisibility(View.GONE);
            } else if (state == SCROLL_STATE_FLING) {
                mTimeLineText.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (mTimeLineText.getVisibility() == View.VISIBLE) {
                int index = firstVisibleItem + 1 == view.getAdapter().getCount() ? view.getAdapter().getCount() - 1 : firstVisibleItem + 1;
                Image image = (Image) view.getAdapter().getItem(index);
                if (image != null) {
                    mTimeLineText.setText(TimeUtils.formatPhotoDate(image.path));
                }
            }
        }
    });
    mGridView.setAdapter(mImageAdapter);
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        public void onGlobalLayout() {
            final int width = mGridView.getWidth();
            final int height = mGridView.getHeight();
            mGridWidth = width;
            mGridHeight = height;
            final int desireSize = getResources().getDimensionPixelOffset(R.dimen.image_size);
            final int numCount = width / desireSize;
            final int columnSpace = getResources().getDimensionPixelOffset(R.dimen.space_size);
            int columnWidth = (width - columnSpace * (numCount - 1)) / numCount;
            mImageAdapter.setItemSize(columnWidth);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (mImageAdapter.isShowCamera()) {
                // 如果显示照相机,则第一个Grid显示为照相机,处理特殊逻辑
                if (i == 0) {
                    showCameraAction();
                } else {
                    // 正常操作
                    Image image = (Image) adapterView.getAdapter().getItem(i);
                    selectImageFromGrid(image, mode);
                }
            } else {
                // 正常操作
                Image image = (Image) adapterView.getAdapter().getItem(i);
                selectImageFromGrid(image, mode);
            }
        }
    });
    mFolderAdapter = new FolderAdapter(getActivity());
}
Also used : AbsListView(android.widget.AbsListView) Intent(android.content.Intent) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) Picasso(com.squareup.picasso.Picasso) AdapterView(android.widget.AdapterView) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi)

Example 14 with Picasso

use of com.squareup.picasso.Picasso in project greedo-layout-for-android by 500px.

the class App method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Picasso picasso = new Picasso.Builder(this).memoryCache(new LruCache(calculateMemoryCacheSize())).build();
    Picasso.setSingletonInstance(picasso);
}
Also used : LruCache(com.squareup.picasso.LruCache) Picasso(com.squareup.picasso.Picasso)

Example 15 with Picasso

use of com.squareup.picasso.Picasso in project android-shape-imageview by siyamed.

the class SampleListFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_list_sample, container, false);
    final Picasso picasso = Picasso.with(getActivity());
    picasso.setLoggingEnabled(true);
    picasso.setIndicatorsEnabled(false);
    int listLayout = getArguments().getInt(ARG_LAYOUT);
    final ListView listView = (ListView) view.findViewById(R.id.list);
    Adapter adapter = new Adapter(getActivity(), picasso, listLayout);
    listView.setAdapter(adapter);
    return view;
}
Also used : ListView(android.widget.ListView) Picasso(com.squareup.picasso.Picasso) ArrayAdapter(android.widget.ArrayAdapter) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) ListView(android.widget.ListView)

Aggregations

Picasso (com.squareup.picasso.Picasso)26 View (android.view.View)9 TextView (android.widget.TextView)7 RequestCreator (com.squareup.picasso.RequestCreator)7 ImageView (android.widget.ImageView)6 ArrayAdapter (android.widget.ArrayAdapter)5 ListView (android.widget.ListView)5 OkHttp3Downloader (com.jakewharton.picasso.OkHttp3Downloader)4 Bitmap (android.graphics.Bitmap)3 Drawable (android.graphics.drawable.Drawable)3 OkHttpDownloader (com.squareup.picasso.OkHttpDownloader)3 Target (com.squareup.picasso.Target)3 TargetApi (android.annotation.TargetApi)2 SharedPreferences (android.content.SharedPreferences)2 ViewTreeObserver (android.view.ViewTreeObserver)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 GridView (android.widget.GridView)2 Callback (com.squareup.picasso.Callback)2 LruCache (com.squareup.picasso.LruCache)2