点击查看大图Activity

1.使用方式

Intent intent = new Intent(FriendCircleActivity.this, ImageGralleryPagerActivity.class);//0,索引,第几张图片
intent.putExtra(ImageGralleryPagerActivity.EXTRA_IMAGE_INDEX, 0);
 ArrayList<String> imgs = new ArrayList<String>();
 imgs.add(“图片URL”);
intent.putStringArrayListExtra("imgs", imgs);
startActivity(intent);

2.展示大图Activity

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.jlm.happyselling.R;
import com.jlm.happyselling.base.ECSuperActivity;
import com.jlm.happyselling.helper.IMessageSqlManager;
import com.jlm.happyselling.model.ViewImageInfo;
import com.jlm.happyselling.util.ECUtils;
import com.jlm.happyselling.util.FileAccessor;
import com.jlm.happyselling.util.LogUtil;
import com.jlm.happyselling.util.ToastUtil;
import com.jlm.happyselling.widget.HackyViewPager;

import java.io.File;
import java.util.List;

public class ImageGralleryPagerActivity extends ECSuperActivity implements View.OnClickListener {

    private static final String TAG = "ImageGralleryPagerActivity";

    private static final String STATE_POSITION = "STATE_POSITION";
    public static final String EXTRA_IMAGE_INDEX = "image_index";
    public static final String EXTRA_IMAGE_URLS = "image_urls";
    public static final String EXTRA_IMAGE_URLS_ID = "image_urls_id";
    public static boolean isFireMsg = false;

    /**
     *
     */
    private boolean mFullscreen = true;
    private HackyViewPager mPager;
    private int pagerPosition;
    private TextView indicator;
    private List<ViewImageInfo> urls;
    private List<String> imgs;

    @Override
    protected int getLayoutId() {
        return R.layout.image_grallery_container;
    }

    @Override
    protected boolean isEnableSwipe() {
        // TODO Auto-generated method stub
        return false;
    }

    public static String sgId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getTopBarView().setTopBarToStatus(1, R.drawable.topbar_back_bt, -1, "1 / 1", this);

        if (!getIntent().hasExtra("imgs")) {
            ImageGalleryFragment.i = 0;
            pagerPosition = getIntent().getIntExtra(EXTRA_IMAGE_INDEX, 0);
            urls = getIntent().getParcelableArrayListExtra(EXTRA_IMAGE_URLS);
            sgId = getIntent().getStringExtra(EXTRA_IMAGE_URLS_ID);
            onChatImgLayout();
        } else {
            ImageGalleryFragment2.i = 0;
            pagerPosition = getIntent().getIntExtra(EXTRA_IMAGE_INDEX, 0);
            imgs = getIntent().getStringArrayListExtra("imgs");
            onImgLayout();
        }

        // 更新下标
        mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrollStateChanged(int arg0) {
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageSelected(int arg0) {
                initIndicatorIndex(arg0);
            }

        });
        if (savedInstanceState != null) {
            pagerPosition = savedInstanceState.getInt(STATE_POSITION);
        }

        mPager.setCurrentItem(pagerPosition);
        initIndicatorIndex(pagerPosition);
        setTitleFooterVisible(true);
    }

    private void onImgLayout() {
        if (imgs == null || imgs.isEmpty()) {
            finish();
            return;
        }
        if (pagerPosition > imgs.size()) {
            pagerPosition = 0;
        }
        setActionBarTitle(pagerPosition + "/" + (imgs != null ? imgs.size() : 0));
        mPager = (HackyViewPager) findViewById(R.id.pager);
        final ImagePagerAdapter1 adapter1 = new ImagePagerAdapter1(getSupportFragmentManager(),imgs);
        mPager.setAdapter(adapter1);
        indicator = (TextView) findViewById(R.id.indicator);
    }

    private void onChatImgLayout() {
        if (urls == null || urls.isEmpty()) {
            finish();
            return;
        }
        if (pagerPosition > urls.size()) {
            pagerPosition = 0;
        }

        setActionBarTitle(pagerPosition + "/" + (urls != null ? urls.size() : 0));
        mPager = (HackyViewPager) findViewById(R.id.pager);
        final ImagePagerAdapter mAdapter = new ImagePagerAdapter(getSupportFragmentManager(), urls);
        mPager.setAdapter(mAdapter);
        indicator = (TextView) findViewById(R.id.indicator);
        findViewById(R.id.imagebrower_iv_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mAdapter != null) {
                    ViewImageInfo viewImageInfo = urls.get(mPager.getCurrentItem());
                    if (viewImageInfo == null || !viewImageInfo.isDownload()) {
                        ToastUtil.show(R.string.save_img_waite_download);
                        return;
                    }
                    try {
                        File file = new File(FileAccessor.getImagePathName(), viewImageInfo.getPicurl());
                        if (viewImageInfo != null && viewImageInfo.isGif()) {
                            ECUtils.saveImage(file.getAbsolutePath(), ".gif");
                            return;
                        }
                        ECUtils.saveImage(file.getAbsolutePath());
                    } catch (Exception e) {
                        LogUtil.e(TAG, "onContextItemSelected error ");
                    }

                }
            }
        });
        //待改 lu
        if (mAdapter != null) {
            ViewImageInfo viewImageInfoItem = urls.get(mPager.getCurrentItem());
            if (viewImageInfoItem != null && IMessageSqlManager.isFireMsg(viewImageInfoItem.getMsgLocalId())) {
                findViewById(R.id.imagebrower_iv_save).setVisibility(View.GONE);
            } else {
                findViewById(R.id.imagebrower_iv_save).setVisibility(View.GONE);

            }

        }
    }

    private void initIndicatorIndex(int arg0) {
        CharSequence text = getString(R.string.viewpager_indicator, arg0 + 1, mPager.getAdapter().getCount());
        SpannableString spannableString = new SpannableString(text);
        spannableString.setSpan(new RelativeSizeSpan(1.5F), 0, text.toString().indexOf("/"), SpannableString.SPAN_PRIORITY);
        indicator.setText(spannableString);
    }

    @Override
    public void onClick(View v) {
        mHandlerCallbck.sendEmptyMessageDelayed(1, 350L);
        switch (v.getId()) {
            case R.id.btn_left:
                hideSoftKeyboard();
                finish();
                break;

            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (urls != null) {
            urls.clear();
            urls = null;
        }
        if (mHandlerCallbck != null) {
            mHandlerCallbck.removeCallbacksAndMessages(null);
        }
        mPager = null;
        isFireMsg = false;
        ImageGalleryFragment.i = 0;
        System.gc();

    }

    private final Handler mHandlerCallbck = new Handler() {

        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            mFullscreen = !mFullscreen;
            setTitleFooterVisible(mFullscreen);
        }

    };

    @Override
    public void onBaseContentViewAttach(View contentView) {
        View activityLayoutView = getActivityLayoutView();
        ((ViewGroup) activityLayoutView.getParent()).removeView(activityLayoutView);
        ((ViewGroup) getWindow().getDecorView()).addView(activityLayoutView, 1);

    }

    /**
     * @param request
     */
    private void requestStatusbars(boolean request) {
        if (request) {
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            return;
        }
        LogUtil.d(getClass().getSimpleName(), "request custom title");
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    /**
     * Full screen, hidden actionBar
     *
     * @param visible
     */
    void setTitleFooterVisible(boolean visible) {
        if (visible) {
            requestStatusbars(false);
            showTitleView();
            return;
        }

        requestStatusbars(true);
        hideTitleView();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(STATE_POSITION, mPager.getCurrentItem());
    }

    private class ImagePagerAdapter extends FragmentStatePagerAdapter {

        public List<ViewImageInfo> fileList;

        public ImagePagerAdapter(FragmentManager fm, List<ViewImageInfo> fileList) {
            super(fm);
            this.fileList = fileList;
        }

        @Override
        public int getCount() {
            return fileList == null ? 0 : fileList.size();
        }

        @Override
        public Fragment getItem(int position) {
            ViewImageInfo url = fileList.get(position);
            return ImageGalleryFragment.newInstance(url);
        }

    }

    private class ImagePagerAdapter1 extends FragmentStatePagerAdapter {

        public List<String> fileList;

        public ImagePagerAdapter1(FragmentManager fm, List<String> fileList) {
            super(fm);
            this.fileList = fileList;
        }

        @Override
        public int getCount() {
            return fileList == null ? 0 : fileList.size();
        }

        @Override
        public Fragment getItem(int position) {
            String url = fileList.get(position);
            return ImageGalleryFragment2.newInstance(url);
        }

    }

    @Override
    public boolean isEnableRightSlideGesture() {
        return false;
    }
}
时间: 2024-10-05 05:21:27

点击查看大图Activity的相关文章

iOS点击查看大图的动画效果

对于图片来说,除了表情包,几乎都会被点击查看大图.今天就讲解一个查看和收起大图的动画效果,先直接看效果图: 如图所示,最开始是一个小图,点击小图可以查看大图.大图会从小图的位置和大小"弹"出来,同时背景变成半透明的阴影.点击大图或者阴影后,收起大图,同样地弹回到小图去,同时去掉阴影背景,就像是一张图片在伸大缩小一样. 现在看看这是怎么实现的.在思考一个动画的实现方法时,把动画的动作进行分解然后再一个个去思考怎么实现是一个好的习惯,我们稍微分解一下,这个动画在显示大图和收起大图的时候做了

UIWebView 点击查看大图

UIWebView 点击查看大图 UIWebView 点击查看大图,参考示例如下: ShowBigImgViewController.h #import <UIKit/UIKit.h> @interface ShowBigImgViewController : UIViewController //UIWebView @property (weak, nonatomic) IBOutlet UIWebView *webDetails; @end ShowBigImgViewController

微信JSSDK上传多图预览,点击查看大图

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="ap

android开发:点击缩略图查看大图

android中点击缩略图查看大图的方法一般有两种,一种是想新浪微博list页面那样,弹出一个窗口显示大图(原activity为背景).另一种就是直接打开一个新的activity显示大图. 1.第一种方法我们可以使用自定义的AlertDialog来实现,代码如下: ImageView image=(ImageView)findViewById(R.id.small_image); image.setOnClickListener(new OnClickListener() { // 点击放大 p

WKWebview点击图片查看大图

大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其实很简单,给WKWebview写个类别,添加两个方法就行了,然后在WKWebview的两个协议中调用下这两个方法就行了 首先声明个数组来接收图片数组,可是有个问题,那就是类别是声明不了属性的,那怎么办呢?我们可以通过runtime来设置属性,runtime非常有用,我们以后的篇章会说到. stati

移动端点击图片查看大图

一.需求 点击图片查看大图,再点大图隐藏.多用于移动端,因为移动端屏幕小,可能需要查看大图. 二.代码 <!DOCTYPE html> <html> <meta charset="utf-8"/> <head runat="server"> <title>JQuery点击图片查看大图by starof</title> <style type="text/css">

即拿即用-选择头像,可以选择相册,拍照,查看大图,保存到本地

如图所示: 显示图片用的是Glide 选择图片用的是GalleryFinal 查看大图用的是PhotView 圆形图片用的是SelectableRoundedImageView GitHub地址:https://github.com/mocn26169/Avatar 核心代码: 点击选择图片 @Override public void onClick(View v) { switch (v.getId()) { case R.id.avatar: if (!TextUtils.isEmpty(u

Android下QQ空间查看大图特效

最近在做一个项目,里面有一个功能是实现Android QQ好友动态里面的缩略图放大,查看大图的效果.用过都知道,这个特效很赞的,没用过的下载个玩玩吧.我刚开始以为放大的那个大图是一个Activity或者是一个Dialog.可是尝试过后发现怎么也实现不了那种效果(有实现出来的朋友的话还请相告,一起交流交流).然后到android官网上发现了一个图片放大特效的demo.这个Demo确实是实现了QQ里面图片放大的基本效果,可是要求是Android 3.0以上才能用,因为里面用到Animator.我知道

android 查看 当前activity

adb shell dumpsys activity|grep mResume 或者 adb shell dumpsys window windows | grep -E 'mCurrentFocus' copy 自 http://www.cnblogs.com/tt_mc/p/4269833.html 使用adb shell dumpsys检测Android的Activity任务栈 谈起Android程序开发,就需要了解其四个主要的部件:Activity.Service.ContentProv