Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
3650c4ef
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3650c4ef
编写于
9月 11, 2017
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add runtime permission support to gallery sample.
上级
b01ac7be
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
66 addition
and
13 deletion
+66
-13
checkstyle.xml
checkstyle.xml
+3
-1
samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.java
...java/com/bumptech/glide/samples/gallery/MainActivity.java
+57
-5
samples/gallery/src/main/res/layout/main_activity.xml
samples/gallery/src/main/res/layout/main_activity.xml
+6
-7
未找到文件。
checkstyle.xml
浏览文件 @
3650c4ef
...
@@ -127,7 +127,9 @@
...
@@ -127,7 +127,9 @@
<!-- Checks for blocks. -->
<!-- Checks for blocks. -->
<!-- See http://checkstyle.sourceforge.net/config_blocks.html -->
<!-- See http://checkstyle.sourceforge.net/config_blocks.html -->
<module
name=
"AvoidNestedBlocks"
/>
<module
name=
"AvoidNestedBlocks"
>
<property
name=
"allowInSwitchCase"
value=
"true"
/>
</module>
<module
name=
"EmptyBlock"
>
<module
name=
"EmptyBlock"
>
<property
name=
"option"
value=
"text"
/>
<property
name=
"option"
value=
"text"
/>
</module>
</module>
...
...
samples/gallery/src/main/java/com/bumptech/glide/samples/gallery/MainActivity.java
浏览文件 @
3650c4ef
package
com.bumptech.glide.samples.gallery
;
package
com.bumptech.glide.samples.gallery
;
import
android.Manifest.permission
;
import
android.annotation.TargetApi
;
import
android.content.pm.PackageManager
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.ActivityCompat
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v4.content.ContextCompat
;
import
android.widget.Toast
;
import
com.bumptech.glide.MemoryCategory
;
import
com.bumptech.glide.MemoryCategory
;
/**
/**
...
@@ -9,10 +18,53 @@ import com.bumptech.glide.MemoryCategory;
...
@@ -9,10 +18,53 @@ import com.bumptech.glide.MemoryCategory;
*/
*/
public
class
MainActivity
extends
FragmentActivity
{
public
class
MainActivity
extends
FragmentActivity
{
private
static
final
int
REQUEST_READ_STORAGE
=
0
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
main_activity
);
setContentView
(
R
.
layout
.
main_activity
);
GlideApp
.
get
(
this
).
setMemoryCategory
(
MemoryCategory
.
HIGH
);
GlideApp
.
get
(
this
).
setMemoryCategory
(
MemoryCategory
.
HIGH
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
M
&&
ContextCompat
.
checkSelfPermission
(
this
,
permission
.
READ_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
requestStoragePermission
();
}
else
{
replaceFragment
();
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN
)
private
void
requestStoragePermission
()
{
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]{
permission
.
READ_EXTERNAL_STORAGE
},
REQUEST_READ_STORAGE
);
}
private
void
replaceFragment
()
{
Fragment
fragment
=
new
HorizontalGalleryFragment
();
getSupportFragmentManager
()
.
beginTransaction
()
.
replace
(
R
.
id
.
fragment_container
,
fragment
)
.
commit
();
}
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
switch
(
requestCode
)
{
case
REQUEST_READ_STORAGE:
{
// If request is cancelled, the result arrays are empty.
if
(
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
replaceFragment
();
}
else
{
Toast
.
makeText
(
this
,
"Storage permission is required"
,
Toast
.
LENGTH_LONG
)
.
show
();
requestStoragePermission
();
}
}
}
}
}
}
}
samples/gallery/src/main/res/layout/main_activity.xml
浏览文件 @
3650c4ef
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<
merge
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<
FrameLayout
<fragment
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:name=
"com.bumptech.glide.samples.gallery.HorizontalGalleryFragment
"
android:id=
"@+id/fragment_container
"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
>
android:id=
"@+id/horizontal_gallery_fragment"
/>
</FrameLayout>
</merge>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录