200 lines
5.8 KiB
Java
200 lines
5.8 KiB
Java
|
|
package imageselector;
|
|||
|
|
|
|||
|
|
import android.app.Activity;
|
|||
|
|
import android.content.Context;
|
|||
|
|
import android.content.Intent;
|
|||
|
|
import android.content.res.Configuration;
|
|||
|
|
import android.content.res.Resources;
|
|||
|
|
import android.graphics.Color;
|
|||
|
|
import android.os.Build;
|
|||
|
|
import android.os.Bundle;
|
|||
|
|
import android.support.annotation.Nullable;
|
|||
|
|
import android.support.v4.view.ViewPager;
|
|||
|
|
import android.support.v7.app.AppCompatActivity;
|
|||
|
|
import android.view.View;
|
|||
|
|
import android.view.Window;
|
|||
|
|
import android.view.WindowManager;
|
|||
|
|
import android.widget.TextView;
|
|||
|
|
|
|||
|
|
import com.sl.house_property.R;
|
|||
|
|
|
|||
|
|
import java.io.File;
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
|
|||
|
|
import imageselector.adapter.FullScreenImagePagerAdapter;
|
|||
|
|
import imageselector.adapter.FullScreenOnlineImagePagerAdapter;
|
|||
|
|
import imageselector.entry.Image;
|
|||
|
|
import imageselector.utils.ImageSelector;
|
|||
|
|
import imageselector.view.MyViewPager;
|
|||
|
|
|
|||
|
|
public class FullScreenOnlinePreviewActivity extends AppCompatActivity {
|
|||
|
|
|
|||
|
|
private MyViewPager vpImage;
|
|||
|
|
private TextView tvIndicator;
|
|||
|
|
|
|||
|
|
|
|||
|
|
//tempImages和tempSelectImages用于图片列表数据的页面传输。
|
|||
|
|
//之所以不要Intent传输这两个图片列表,因为要保证两位页面操作的是同一个列表数据,同时可以避免数据量大时,
|
|||
|
|
// 用Intent传输发生的错误问题。
|
|||
|
|
private static ArrayList<String> tempImages;
|
|||
|
|
|
|||
|
|
private ArrayList<String> mImages;
|
|||
|
|
private boolean isShowBar = true;
|
|||
|
|
private boolean isConfirm = false;
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static void openActivity(Activity activity, ArrayList<String> images, int position) {
|
|||
|
|
tempImages = images;
|
|||
|
|
Intent intent = new Intent(activity, FullScreenOnlinePreviewActivity.class);
|
|||
|
|
intent.putExtra(ImageSelector.POSITION, position);
|
|||
|
|
activity.startActivityForResult(intent, ImageSelector.RESULT_CODE);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|||
|
|
super.onCreate(savedInstanceState);
|
|||
|
|
setContentView(R.layout.activity_full_screen_preview);
|
|||
|
|
|
|||
|
|
setStatusBarVisible(true);
|
|||
|
|
mImages = tempImages;
|
|||
|
|
tempImages = null;
|
|||
|
|
Intent intent = getIntent();
|
|||
|
|
setStatusBarColor();
|
|||
|
|
initView();
|
|||
|
|
initListener();
|
|||
|
|
initViewPager();
|
|||
|
|
|
|||
|
|
tvIndicator.setText(1 + "/" + mImages.size());
|
|||
|
|
vpImage.setCurrentItem(intent.getIntExtra(ImageSelector.POSITION, 0));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void initView() {
|
|||
|
|
vpImage = (MyViewPager) findViewById(R.id.vp_image);
|
|||
|
|
tvIndicator = (TextView) findViewById(R.id.tv_indicator);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void initListener() {
|
|||
|
|
findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
|
|||
|
|
@Override
|
|||
|
|
public void onClick(View v) {
|
|||
|
|
finish();
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 初始化ViewPager
|
|||
|
|
*/
|
|||
|
|
private void initViewPager() {
|
|||
|
|
FullScreenOnlineImagePagerAdapter adapter = new FullScreenOnlineImagePagerAdapter(this, mImages);
|
|||
|
|
vpImage.setAdapter(adapter);
|
|||
|
|
|
|||
|
|
vpImage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|||
|
|
@Override
|
|||
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public void onPageSelected(int position) {
|
|||
|
|
tvIndicator.setText(position + 1 + "/" + mImages.size());
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public void onPageScrollStateChanged(int state) {
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 修改状态栏颜色
|
|||
|
|
*/
|
|||
|
|
private void setStatusBarColor() {
|
|||
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|||
|
|
Window window = getWindow();
|
|||
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
|||
|
|
window.setStatusBarColor(Color.parseColor("#373c3d"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取状态栏高度
|
|||
|
|
*
|
|||
|
|
* @param context
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public static int getStatusBarHeight(Context context) {
|
|||
|
|
int result = 0;
|
|||
|
|
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
|||
|
|
if (resourceId > 0) {
|
|||
|
|
result = context.getResources().getDimensionPixelSize(resourceId);
|
|||
|
|
}
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 显示和隐藏状态栏
|
|||
|
|
*
|
|||
|
|
* @param show
|
|||
|
|
*/
|
|||
|
|
private void setStatusBarVisible(boolean show) {
|
|||
|
|
if (show) {
|
|||
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
|||
|
|
} else {
|
|||
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|||
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 显示头部和尾部栏
|
|||
|
|
*/
|
|||
|
|
private void showBar() {
|
|||
|
|
isShowBar = true;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 隐藏头部和尾部栏
|
|||
|
|
*/
|
|||
|
|
private void hideBar() {
|
|||
|
|
isShowBar = false;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public void finish() {
|
|||
|
|
//Activity关闭时,通过Intent把用户的操作(确定/返回)传给ImageSelectActivity。
|
|||
|
|
Intent intent = new Intent();
|
|||
|
|
intent.putExtra(ImageSelector.IS_CONFIRM, isConfirm);
|
|||
|
|
setResult(ImageSelector.RESULT_CODE, intent);
|
|||
|
|
super.finish();
|
|||
|
|
}
|
|||
|
|
@Override
|
|||
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|||
|
|
//非默认值
|
|||
|
|
if (newConfig.fontScale != 1){
|
|||
|
|
getResources();
|
|||
|
|
}
|
|||
|
|
super.onConfigurationChanged(newConfig);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Override
|
|||
|
|
public Resources getResources() {//还原字体大小
|
|||
|
|
Resources res = super.getResources();
|
|||
|
|
//非默认值
|
|||
|
|
if (res.getConfiguration().fontScale != 1) {
|
|||
|
|
Configuration newConfig = new Configuration();
|
|||
|
|
newConfig.setToDefaults();//设置默认
|
|||
|
|
res.updateConfiguration(newConfig, res.getDisplayMetrics());
|
|||
|
|
}
|
|||
|
|
return res;
|
|||
|
|
}
|
|||
|
|
}
|