点击查看大图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;
}
}
3.布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#ff171b19"> <com.jlm.happyselling.widget.HackyViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" /> <RelativeLayout
android:id="@+id/imagebrower_layout_pagelayout"
android:background="#5e171b19"
android:paddingLeft="15.0dip"
android:paddingRight="15.0dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="80.0dip"
android:layout_alignParentBottom="true"> <ImageView
android:id="@+id/imagebrower_iv_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" /> <TextView
android:textSize="18.0sp"
android:textColor="#ffcdcdcd"
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout> </RelativeLayout>
点击查看大图Activity的更多相关文章
- vue项目 PC端点击查看大图
今天,发现了一款还不错的插件来实现查看大图,成熟度也比较高,支持各种操作 原作品的github地址为 https://github.com/mirari/v-viewer 也有对应的中文文档,使用方法 ...
- 点击查看大图滑动预览(h5,pc通用)
点击预览大图并滑动观看,支持手机端和pc端,具体功能如下图: 一. touchTouch 的js和css 以及jquery依赖库 <link rel="stylesheet" ...
- eazyui 或bootstrap table表格里插入图片,点击查看大图
columns: [ {field: 'state',checkbox: true,align: 'center',valign: 'middle'}, {field: 'contacts',sort ...
- android开发:点击缩略图查看大图
android中点击缩略图查看大图的方法一般有两种,一种是想新浪微博list页面那样,弹出一个窗口显示大图(原activity为背景).另一种就是直接打开一个新的activity显示大图. 1.第一种 ...
- [原创]WKWebview点击图片查看大图
大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...
- jquery层居中,点击小图查看大图,弹出层居中代码,顶部层固定不动,滚动条滚动情况
jquery层居中,点击小图查看大图,弹出层居中代码 http://www.cnblogs.com/simpledev/p/3566280.html 见第一版,发现一个情况,如果页面内容多出一屏的情况 ...
- WKWebview点击图片查看大图
大家都知道,WKWebview是没有查看大图的属性或者方法的,所以只能通过js与之交互来实现这一功能,原理:通过js获取页面的图片,把它存放到数组,给图片添加点击事件,通过index显示大图就行了 其 ...
- 点击图片查看大图(纯js)
$(function(){ $(".pimg").click(function(){ var _this = $(this);//将当前的pimg元素作为_this传入函数 img ...
- Android下QQ空间查看大图特效
近期在做一个项目,里面有一个功能是实现Android QQ好友动态里面的缩略图放大,查看大图的效果.用过都知道,这个特效非常赞的,没用过的下载个玩玩吧.我刚開始以为放大的那个大图是一个Activity ...
随机推荐
- CentOS 7 下 Oracle 11g 安装教程
一.准备工作 1.关闭selinux 查看selinux状态: getenforce或者sestatus -v 临时关闭: setenforce 0 永久关闭: vim /et ...
- 关于 'list' object has no attribute 'select'
我是在写爬虫是遇到了这个问题: c = chapter.select('href')AttributeError: 'list' object has no attribute 'select' 这是 ...
- 【cisco探索之路】
CISCO探索之路 show&debug&clear 1:show show version:显示版本信息show running-config:显示当前的配置show interfa ...
- 在Vue项目里面使用d3.js
之前写一个 Demo里面 有些东西要使用d3实现一些效果 但是在很多论坛找资源都找不到可以在Vue里面使用D3.js的方法,npm 上面的D3相对来说 可以说是很不人性化了 完全没有说 在webpac ...
- PHP创建MySQL并引入后执行sql语句
一:创建sql.php文件 <?php function sqlMethod($sql){ $servername = "localhost"; $username = &q ...
- 查询表名里含有Bill的表有哪些
Select Name from Master.dbo.sysobjects where xtype='u' and Name like '%Bill%' order by name
- TP5部署服务器问题总结
及最近部署TP5遇到了很多坑,各种环境下都会出现一些问题,下面是我记录的排坑之路 先说最简单的lnmp一键安装包,我用的是1.5稳定版 安装命令:wget http://soft.vpser.net/ ...
- PADS快捷键
问:在pads layout中怎样显示或隐藏铺铜的效果 答: 无模命令:po 或者spo 前者是平面层 后者是混合层. 同时你可以在ctrl+alt+c 色彩项中关闭 copper . 使用 无模命令 ...
- ubuntu配置机器学习环境(一) ubuntu安装
第一部分:Ubuntu14.04安装 Step :安装Ubuntu Step 1.1:准备安装U盘 首先到官网下载Ubuntu的镜像,我使用的是Ubuntu 14.04.3的ISO. 然后使用Ultr ...
- DESCRIBEFIELD
実行時データ型識別.略語は RTTI です.プログラム実行時にデータ型を識別して処理を行う仕組みです.. DESCRIBE FIELD命令を使用 DESCRIBE FIELD命令を使用して.変数のデー ...