Skip to content

Commit

Permalink
20161004
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-XiaoLiang committed Oct 4, 2016
1 parent 36fc68d commit 2d35bd0
Show file tree
Hide file tree
Showing 22 changed files with 392 additions and 169 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/AMap_Location_V2.9.0_20160906.jar')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'com.squareup.okio:okio:1.10.0'
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'org.dom4j:dom4j:2.0.0'
Expand All @@ -36,4 +35,5 @@ dependencies {
compile 'com.google.zxing:core:3.3.0'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="ad90d9a285507b7be97a91a7883a39ca" />
<meta-data android:name="xiaoliang.ltool.bean.GlideConfiguration"
android:value="GlideModule"/>
<!-- 定位需要的服务 -->
<service android:name="com.amap.api.location.APSService" />

Expand Down Expand Up @@ -78,7 +80,7 @@
<activity
android:name=".activity.MeizhiActivity"
android:label="@string/title_activity_meizhi"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar"/>
</application>

</manifest>
39 changes: 0 additions & 39 deletions app/src/main/java/xiaoliang/ltool/activity/LToolApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
import android.app.Application;
import android.widget.Toast;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;

/**
* Created by liuj on 2016/9/13.
* 应用上下文
Expand All @@ -19,37 +11,6 @@ public class LToolApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
initImageLoader();
}

/**
*
"https://site.com/image.png" // from Web
"file:https:///mnt/sdcard/image.png" // from SD card
"file:https:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content:https://media/external/images/media/13" // from content provider
"content:https://media/external/video/media/13" // from content provider (video thumbnail)
"assets:https://image.png" // from assets
"drawable:https://" + R.drawable.img // from drawables (non-9patch images)
*/
private void initImageLoader(){
ImageLoaderConfiguration config = new ImageLoaderConfiguration
.Builder(this)
.memoryCacheExtraOptions(480, 800) // max width, max height,即保存的每个缓存文件的最大长宽
.threadPoolSize(3)//线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
.memoryCacheSize(2 * 1024 * 1024)
.discCacheSize(50 * 1024 * 1024)
.discCacheFileNameGenerator(new Md5FileNameGenerator())//将保存的时候的URI名称用MD5 加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.discCacheFileCount(100) //缓存的文件数量
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.imageDownloader(new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
.writeDebugLogs() // Remove for release app
.build();//开始构建
ImageLoader.getInstance().init(config);//全局初始化此配置
}

public void T(String s){
Expand Down
48 changes: 26 additions & 22 deletions app/src/main/java/xiaoliang/ltool/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xiaoliang.ltool.activity;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -31,8 +30,9 @@
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;

import org.dom4j.DocumentException;

Expand All @@ -55,7 +55,6 @@

public class MainActivity extends AppCompatActivity implements View.OnClickListener,View.OnLongClickListener {
/*主要控件*/
private ImageLoader imageLoader;
private CollapsingToolbarLayout toolbarLayout;
private FloatingActionButton fab;
private ImageView headImg;
Expand Down Expand Up @@ -105,7 +104,6 @@ private void initView(){
qrRead = (CardView) findViewById(R.id.content_main_qrread);
qrCreate = (CardView) findViewById(R.id.content_main_qrcreate);
meizi = (CardView) findViewById(R.id.content_main_meizhi);
imageLoader = ImageLoader.getInstance();
handler = new MyHandler();
qrCreate.setOnClickListener(this);
qrRead.setOnClickListener(this);
Expand Down Expand Up @@ -196,10 +194,24 @@ private void loadImg(){
int networdType = OtherUtil.getNetworkType(this);
boolean onlyWifi = SharedPreferencesUtils.isOnlyWifi(this);
loadWebImg = SharedPreferencesUtils.isLoadWebImg(this);
imageLoader.displayImage(Constant.getBabkgroundPath(this),headImg,null,new MyImageLoadingListener(this,false));
Glide.with(this).load(Constant.getBabkgroundPath(this)).asBitmap().into(new SimpleTarget<Bitmap>(){
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Log.d("onResourceReady",resource.toString()+"---"+resource.getWidth()+"x"+resource.getHeight());
headImg.setImageBitmap(resource);
onHeadImgLoaded(false,resource);
}
});
if(networdType==Constant.NetWord_WIFI||(networdType==Constant.NetWord_MOBILE&&!onlyWifi)){
if(loadWebImg&&!SharedPreferencesUtils.isGetBgEnd(this)){
imageLoader.displayImage(Constant.head_img_url_720,headImg,null,new MyImageLoadingListener(this,true));
Glide.with(this).load(Constant.head_img_url_720).asBitmap().into(new SimpleTarget<Bitmap>(){
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
Log.d("onResourceReady-Net",resource.toString()+"---"+resource.getWidth()+"x"+resource.getHeight());
headImg.setImageBitmap(resource);
onHeadImgLoaded(true,resource);
}
});
}
}
}
Expand Down Expand Up @@ -227,28 +239,20 @@ public boolean onLongClick(View v) {
return false;
}

private class MyImageLoadingListener extends SimpleImageLoadingListener{
private Context context;
private boolean isSave;
public MyImageLoadingListener(Context context,boolean isSave) {
this.context = context;
this.isSave = isSave;
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if(isSave){
OtherUtil.saveBabkground(context,loadedImage);
SharedPreferencesUtils.setGetBgTime(context);
}
setBackground(loadedImage);
private void onHeadImgLoaded(boolean isSave,Bitmap loadedImage){
if(isSave){
OtherUtil.saveBabkground(this,loadedImage);
SharedPreferencesUtils.setGetBgTime(this);
}
setBackground(loadedImage);
}

/**
* 异步对图片进行高斯模糊
* @param bitmap
*/
private void setBackground(Bitmap bitmap){
private void setBackground(final Bitmap bitmap){
Log.d("setBackground",bitmap.toString()+"---"+bitmap.getWidth()+"x"+bitmap.getHeight());
HttpUtil.getThread(new BlurBitmapRunnable(bitmap,this,new BlurBitmapRunnable.BlurBitmapListener(){
@Override
public void onBlur(Bitmap bitmap) {
Expand Down
119 changes: 112 additions & 7 deletions app/src/main/java/xiaoliang/ltool/activity/MeizhiActivity.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
package xiaoliang.ltool.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import xiaoliang.ltool.R;
import xiaoliang.ltool.constant.MeizhiType;
import xiaoliang.ltool.dialog.LoadDialog;
import xiaoliang.ltool.fragment.MeizhiFragment;
import xiaoliang.ltool.util.DialogUtil;
import xiaoliang.ltool.util.HttpTaskRunnable;
import xiaoliang.ltool.util.MeizhiUtil;
import xiaoliang.ltool.util.NetTasks;

public class MeizhiActivity extends AppCompatActivity implements MeizhiFragment.OnFragmentInteractionListener {

private TabLayout tabLayout;
private ViewPager viewPager;
private ArrayList<MeizhiFragment> fragments;
private LoadDialog loadDialog;
private MeizhiType[] meizhiTypes = {MeizhiType.GANK,MeizhiType.DOUBAN_ALL,MeizhiType.DOUBAN_LIAN,MeizhiType.DOUBAN_OTHER,MeizhiType.DOUBAN_SIWA,MeizhiType.DOUBAN_TUI,MeizhiType.DOUBAN_TUN,MeizhiType.DOUBAN_XIONG};

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -33,51 +48,141 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
tabLayout = (TabLayout) findViewById(R.id.content_meizhi_viewpager_tab);
viewPager = (ViewPager) findViewById(R.id.content_meizhi_viewpager_pager);
initFragments();
viewPager.setAdapter(new PageAdapter(getSupportFragmentManager()));
viewPager.setCurrentItem(0);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
initFragments();
}

private void initFragments(){
fragments = new ArrayList<>();
fragments.add(MeizhiFragment.newInstance(MeizhiFragment.MeizhiType.GANK));
for(MeizhiType type:meizhiTypes){
MeizhiFragment fragment = MeizhiFragment.newInstance(type);
fragments.add(fragment);
}
}

private class PageAdapter extends FragmentPagerAdapter {
private class PageAdapter extends FragmentStatePagerAdapter {

public PageAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
// Log.d("getItem","doing----------------");
return fragments.get(position);
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}

@Override
public int getCount() {
// Log.d("getCount","doing----------------");
return fragments.size();
}

@Override
public CharSequence getPageTitle(int position) {
// Log.d("getPageTitle","doing----------------");
return fragments.get(position).getTitle();
}
}

@Override
public void onCardClick(Fragment fragment, String uri) {
public void onCardClick(MeizhiFragment fragment, String uri) {

}

@Override
public void onError(Fragment fragment, String msg) {
public void onError(MeizhiFragment fragment, String msg) {

}

@Override
public void onLoad(Fragment fragment, String url) {
public synchronized void onLoad(final MeizhiFragment fragment, String url) {
loadDialog = DialogUtil.getLoadDialog(this);
Log.d("onLoad",url);
final int fIndex = viewPager.getCurrentItem();
NetTasks.getSimpleData(url, new HttpTaskRunnable.CallBack<ArrayList<String>>(){
@Override
public void success(ArrayList<String> object) {
Message message = new Message();
message.what = 200;
message.obj = object;
message.arg1 = fragment.getType().getValue();
message.arg2 = fIndex;
handler.sendMessage(message);
}
@Override
public void error(int code, String msg) {
Message message = new Message();
message.what = 201;
message.obj = msg;
handler.sendMessage(message);
}
@Override
public ArrayList<String> str2Obj(String str) {
// Log.d("Meizhi_json",str);
switch (fragment.getType()){
case GANK:
return MeizhiUtil.getGankImgUrl(str);
case DOUBAN_ALL:
case DOUBAN_LIAN:
case DOUBAN_OTHER:
case DOUBAN_SIWA:
case DOUBAN_TUI:
case DOUBAN_TUN:
case DOUBAN_XIONG:
return null;
}
return null;
}
});
}

private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what){
case 200:
if(loadDialog!=null){
loadDialog.dismiss();
}
if(msg.arg1 == fragments.get(msg.arg2).getType().getValue()){
Log.d("Handler","返回数据");
fragments.get(msg.arg2).setData((ArrayList<String>) msg.obj);
}
break;
case 201:
break;
case 202:
break;
}
super.handleMessage(msg);
}
};

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_meizhi, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menu_meizhi_top:
int p = viewPager.getCurrentItem();
if(p>-1&&p<fragments.size())
fragments.get(p).selectedToTop();
return true;
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 2d35bd0

Please sign in to comment.