Skip to content

Commit

Permalink
this:图片缓存 over
Browse files Browse the repository at this point in the history
next:接入到红客中去
  • Loading branch information
yline committed Apr 11, 2017
1 parent 61e93c6 commit ee727ec
Show file tree
Hide file tree
Showing 25 changed files with 367 additions and 288 deletions.
2 changes: 1 addition & 1 deletion Glide&OKHttp/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Glide&OKHttp/Gilde&OkHttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
flatDir {
dirs 'Libs'
}
}
}

dependencies {
Expand All @@ -32,5 +27,5 @@ dependencies {
compile files('libs/glide-okhttp3-integration-1.4.0.jar')
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile(name: 'LibSDK', ext: 'aar')
compile 'com.yline.lib:LibSDK:1.1.2'
}
Binary file removed Glide&OKHttp/Gilde&OkHttp/libs/LibSDK.aar
Binary file not shown.
4 changes: 4 additions & 0 deletions Glide&OKHttp/Gilde&OkHttp/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

-keepnames class com.glide.config.SingleGlideModule
# or more generally:
#-keep public class * implements com.bumptech.glide.module.GlideModule

This file was deleted.

20 changes: 13 additions & 7 deletions Glide&OKHttp/Gilde&OkHttp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

<application
android:name=".activity.MainApplication"
android:name="com.yline.application.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activity.MainActivity">

<!-- 这个必须在 activity 的前面; debug时, 不需要去混淆 -->
<meta-data
android:name="com.glide.config.SingleGlideModule"
android:value="GlideModule"/>
<!--
<meta-data
android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule"
android:value="GlideModule"/>-->

<activity android:name=".activity.InnerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activity.ListActivity">
<activity android:name=".activity.SampleSingleActivity">
</activity>
</application>

<meta-data
android:name="com.bumptech.glide.integration.okhttp3.OkHttpGlideModule"
android:value="GlideModule"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.glide.activity;

import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.yline.log.LogFileUtil;
import com.yline.test.BaseTestActivity;
import com.yline.utils.FileSizeUtil;

public class InnerActivity extends BaseTestActivity
{
@Override
protected void testStart(final Bundle savedInstanceState)
{
addButton("使用Glide", new View.OnClickListener()
{
@Override
public void onClick(View v)
{
SampleSingleActivity.actionStart(InnerActivity.this);
}
});

addButton("查看缓存大小", new View.OnClickListener()
{
@Override
public void onClick(View v)
{
long size = FileSizeUtil.getDirSize(InnerActivity.this.getExternalFilesDir("GlidePicture"));
LogFileUtil.v("DirSize = " + size);
}
});

addButton("清除内存缓存", new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Glide.get(InnerActivity.this).clearMemory(); // 清理内存缓存 只能在UI主线程中进行
}
});

addButton("清除磁盘缓存", new View.OnClickListener()
{
@Override
public void onClick(View v)
{
new Thread(new Runnable()
{
@Override
public void run()
{
Glide.get(InnerActivity.this).clearDiskCache();
}
}).start();
}
});
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.glide.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.glide.R;
import com.glide.helper.DeleteConstant;
import com.yline.base.BaseAppCompatActivity;
import com.yline.common.CommonRecyclerAdapter;
import com.yline.common.CommonRecyclerViewHolder;

import java.util.ArrayList;
import java.util.List;

public class SampleSingleActivity extends BaseAppCompatActivity
{
private SampleSingleAdapter recyclerAdapter;

private List<String> dataList;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_single);

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_sample_single);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerAdapter = new SampleSingleAdapter();
recyclerView.setAdapter(recyclerAdapter);

initData();
}

private void initData()
{
dataList = new ArrayList<>();
for (int i = 0; i < 30; i++)
{
dataList.add(DeleteConstant.getUrlSquare());
}
recyclerAdapter.addAll(dataList);
}

private class SampleSingleAdapter extends CommonRecyclerAdapter<String>
{
public SampleSingleAdapter()
{
sList = new ArrayList<>();
}

@Override
public int getItemRes()
{
return R.layout.item_sample_single;
}

@Override
public void onBindViewHolder(CommonRecyclerViewHolder viewHolder, int position)
{
viewHolder.setText(R.id.tv_title, sList.get(position));

ImageView imageView = viewHolder.get(R.id.iv_title);
Glide.with(SampleSingleActivity.this) // 初始化
.load(sList.get(position)) // 下载资源
.asBitmap() // 确认是静态图片,就不加载动态了
.override(400, 400) // 设置加载的图片尺寸
.placeholder(R.mipmap.global_load_failed) // 占位图(图形和将要加载的图,需要保持比例一致;否则会导致拉伸)
.diskCacheStrategy(DiskCacheStrategy.RESULT) // 占位符 默认RESULT
.error(R.mipmap.global_load_failed)
.into(imageView); // 放置到View中
/*
Glide.get(SampleSingleActivity.this).clearDiskCache(); // 清理磁盘缓存 需要在子线程中执行
Glide.get(SampleSingleActivity.this).clearMemory(); // 清理内存缓存 可以在UI主线程中进行*/
}
}

public static void actionStart(Context context)
{
context.startActivity(new Intent(context, SampleSingleActivity.class));
}
}
Loading

0 comments on commit ee727ec

Please sign in to comment.