Skip to content

Commit

Permalink
夜间模式改善
Browse files Browse the repository at this point in the history
  • Loading branch information
wenmingvs committed Sep 4, 2016
1 parent 279ead7 commit 1aec98d
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.wenming.weiswift.entity.User;
import com.wenming.weiswift.mvp.model.imp.StatusDetailModelImp;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.ImageDetailsActivity;
import com.wenming.weiswift.ui.login.fragment.home.imagedetaillist.SaveImageDialog;
import com.wenming.weiswift.ui.login.fragment.home.timelineimagelist.ImageAdapter;
import com.wenming.weiswift.ui.login.fragment.home.userdetail.UserActivity;
import com.wenming.weiswift.ui.login.fragment.home.weiboitemdetail.activity.OriginPicTextCommentDetailActivity;
Expand Down Expand Up @@ -494,7 +495,7 @@ public void onLoadingStarted(String s, View view) {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap bitmap) {
File file = DiskCacheUtils.findInCache(urllist.get(position), ImageLoader.getInstance().getDiskCache());
if (file == null){
if (file == null) {
return;
}
if (imageUri.endsWith(".gif")) {
Expand Down Expand Up @@ -543,6 +544,47 @@ public void onClick(View v) {
context.startActivity(intent);
}
});
setOnLongClickListener(longImg, gifImg, norImg, context, status, position);
}

private static void setOnLongClickListener(SubsamplingScaleImageView longImg, GifImageView gifImg, ImageView norImg, final Context context, final Status status, final int position) {


longImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ArrayList<String> saveUrlArrayList;
if (NetUtil.isConnected(context)) {
saveUrlArrayList = status.origin_pic_urls;
} else {
saveUrlArrayList = status.bmiddle_pic_urls;
}
SaveImageDialog.showDialog(saveUrlArrayList.get(position), context);
return false;
}
});

gifImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
SaveImageDialog.showDialog(status.bmiddle_pic_urls.get(position), context);
return false;
}
});

norImg.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ArrayList<String> saveUrlArrayList;
if (NetUtil.isConnected(context)) {
saveUrlArrayList = status.origin_pic_urls;
} else {
saveUrlArrayList = status.bmiddle_pic_urls;
}
SaveImageDialog.showDialog(saveUrlArrayList.get(position), context);
return false;
}
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -45,9 +46,11 @@ public ArrowDialog(Context context, Status status) {
mStatus = status;
}


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.home_weiboitem_arrow_popwindow);
if(mWeiboAdapter == null){
mWeiBoArrowPresent = new WeiBoArrowPresenterImp2(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.wenming.weiswift.ui.login.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -11,6 +14,7 @@
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -106,6 +110,11 @@ public class MainActivity extends AppCompatActivity {
*/
private BarManager mBarManager;

private FrameLayout mFrameLayout;

private ImageView mThemeImg;
private static final long ANIMTION_TIME = 500;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -117,7 +126,8 @@ protected void onCreate(Bundle savedInstanceState) {
mProfile = (RelativeLayout) findViewById(R.id.tv_profile);
mPostTab = (ImageView) findViewById(R.id.fl_post);
mButtonBar = (LinearLayout) findViewById(R.id.buttonBarId);
//mSnackBarContainer = (CoordinatorLayout) findViewById(R.id.coordinatorLayoutId);
mFrameLayout = (FrameLayout) findViewById(R.id.main_layout);
mThemeImg = (ImageView) findViewById(R.id.themeImageView);

//LogReport.getInstance().upload(mContext);
mBarManager = new BarManager(mContext);
Expand Down Expand Up @@ -473,7 +483,43 @@ public void onClick(DialogInterface dialog, int id) {
});
AlertDialog alert = builder.create();
alert.show();
}

/**
* 获取布局的DrawableCahe给ImageView覆盖Fragment
*/
private void changeTheme() {
//设置false清除缓存
mFrameLayout.setDrawingCacheEnabled(false);
//设置true之后可以获取Bitmap
mFrameLayout.setDrawingCacheEnabled(true);
mThemeImg.setImageBitmap(mFrameLayout.getDrawingCache());
mThemeImg.setAlpha(1f);
mThemeImg.setVisibility(View.VISIBLE);
}


/**
* ImageView的动画
* @param view
*/
private void startAnimation(final View view) {
ValueAnimator animator = ValueAnimator.ofFloat(1f).setDuration(ANIMTION_TIME);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float n = (float) animation.getAnimatedValue();
view.setAlpha(1f - n);
}
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mThemeImg.setVisibility(View.INVISIBLE);
}
});
animator.start();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.nostra13.universalimageloader.utils.DiskCacheUtils;
import com.wenming.weiswift.R;
Expand All @@ -33,17 +32,9 @@ public class ImageDetailDialog extends Dialog {
* 用于加载微博列表图片的配置,进行安全压缩,尽可能的展示图片细节
*/
private static DisplayImageOptions mImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.message_image_default)
.showImageForEmptyUri(R.drawable.message_image_default)
.showImageOnFail(R.drawable.timeline_image_failure)
.bitmapConfig(Bitmap.Config.ARGB_8888)
.imageScaleType(ImageScaleType.NONE)
.considerExifParams(true)
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
;


public ImageDetailDialog(String url, Context context) {
super(context, R.style.ImageSaveDialog);
Expand Down Expand Up @@ -75,11 +66,15 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
dismiss();
ImageLoader.getInstance().loadImage(mImgURL, new SimpleImageLoadingListener() {
ImageLoader.getInstance().loadImage(mImgURL, mImageOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
File imgFile = DiskCacheUtils.findInCache(mImgURL, ImageLoader.getInstance().getDiskCache());
if (imgFile == null) {
ToastUtil.showShort(mContext, "保存文件失败,请检查SD卡是否已满!");
return;
}
SaveImgUtil.create(mContext).saveImage(imgFile, loadedImage);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.wenming.weiswift.R;
import com.wenming.weiswift.entity.Status;
import com.wenming.weiswift.ui.common.FillContent;
Expand Down Expand Up @@ -64,6 +63,8 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
FillContent.fillImageList(mContext, mStatus, options, position, holder.longImg, holder.norImg, holder.gifImg, holder.imageLabel);


}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public UserPhotoAdapter(ArrayList<String> bmiddle_pic_urls, Context context) {
this.bmiddle_pic_urls = bmiddle_pic_urls;
this.mContext = context;
options = new DisplayImageOptions.Builder()
.imageScaleType(ImageScaleType.NONE_SAFE)
.bitmapConfig(Bitmap.Config.ARGB_8888)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
Expand All @@ -48,7 +48,9 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(final ViewHolder holder, final int position) {
//FillContent.fillImageList(mContext, mStatus, position, holder.imageItem, holder.imageType);
//FillContent.fillImageList(mContext, mStatus, position, holder.longImg, holder.norImg, holder.gifImg, holder.imageLabel);
ImageLoader.getInstance().displayImage(bmiddle_pic_urls.get(position), holder.imageItem, options);
if (bmiddle_pic_urls.size() > 0) {
ImageLoader.getInstance().displayImage(bmiddle_pic_urls.get(position), holder.imageItem, options);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ public void arrowClick(Status status, int position) {
int width = ScreenUtil.getScreenWidth(mContext) - DensityUtil.dp2px(mContext, 80);
arrowDialog.show();
arrowDialog.getWindow().setLayout(width, (ViewGroup.LayoutParams.WRAP_CONTENT));


}
};
mMentionFooterAdapter = new HeaderAndFooterRecyclerViewAdapter(mMentionAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
Expand All @@ -18,6 +22,7 @@
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.CircleBitmapDisplayer;
import com.wenming.weiswift.MyApplication;
import com.wenming.weiswift.R;
import com.wenming.weiswift.api.UsersAPI;
import com.wenming.weiswift.entity.User;
Expand All @@ -33,6 +38,7 @@
import com.wenming.weiswift.ui.login.fragment.profile.myphoto.MyPhotoActivity;
import com.wenming.weiswift.ui.login.fragment.profile.myweibo.MyWeiBoActivity;
import com.wenming.weiswift.ui.login.fragment.profile.setting.SettingActivity;
import com.wenming.weiswift.utils.SharedPreferencesUtil;
import com.wenming.weiswift.widget.mdprogressbar.CircleProgressBar;

/**
Expand Down Expand Up @@ -60,6 +66,9 @@ public class ProfileFragment extends Fragment implements ProfileFragmentView {
private CircleProgressBar mProgressBar;
private ScrollView mScrollView;
private RelativeLayout mMyprofile_layout;
private RelativeLayout mSettingRl;
private CheckBox mCheckBox;
private RelativeLayout mNightModeRl;
private User mUser;

public ProfileFragment() {
Expand Down Expand Up @@ -101,13 +110,22 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mSettings = (TextView) mView.findViewById(R.id.setting);
mProgressBar = (CircleProgressBar) mView.findViewById(R.id.progressbar);
mMyprofile_layout = (RelativeLayout) mView.findViewById(R.id.myprofile_layout);
mSettingRl = (RelativeLayout) mView.findViewById(R.id.settingRl);
mCheckBox = (CheckBox) mView.findViewById(R.id.nightMode_cb);
mNightModeRl = (RelativeLayout) mView.findViewById(R.id.nightmode_rl);

mProgressBar.setColorSchemeResources(android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
refreshUserDetail(mContext, true);
initContent();
setUpListener();
return mView;
}

private void initContent() {
boolean isNightMode = (boolean) SharedPreferencesUtil.get(mContext, "setNightMode", false);
mCheckBox.setChecked(isNightMode);
refreshUserDetail(mContext, true);
}

@Override
public void onHiddenChanged(boolean hidden) {
super.onHiddenChanged(hidden);
Expand Down Expand Up @@ -182,6 +200,37 @@ public void onClick(View v) {
mContext.startActivity(intent);
}
});
mSettingRl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), SettingActivity.class));
}
});
mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if (isChecked) {
SharedPreferencesUtil.put(mContext, "setNightMode", true);
((AppCompatActivity)getActivity()).getDelegate().setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
SharedPreferencesUtil.put(mContext, "setNightMode", false);
((AppCompatActivity)getActivity()).getDelegate().setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
((MyApplication) mContext.getApplicationContext()).recreateAll();
}
});

mNightModeRl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mCheckBox.isChecked()){
mCheckBox.setChecked(false);
}else {
mCheckBox.setChecked(true);
}
}
});
}

@Override
Expand Down
Loading

0 comments on commit 1aec98d

Please sign in to comment.