Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Sobot_module_Dev
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sobot_android
Sobot_module_Dev
Commits
65774c88
Commit
65774c88
authored
Sep 13, 2021
by
app_dev@sobot.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sobot picture 优化更新到0.2
parent
93511f3a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
4 deletions
+109
-4
build.gradle
sobot_pictureframe/build.gradle
+0
-3
sobot-picture-publish-mavencentral.gradle
sobot_pictureframe/sobot-picture-publish-mavencentral.gradle
+1
-1
SobotBitmapUtil.java
...src/main/java/com/sobot/pictureframe/SobotBitmapUtil.java
+27
-0
SobotPictureUtils.java
...c/main/java/com/sobot/pictureframe/SobotPictureUtils.java
+81
-0
No files found.
sobot_pictureframe/build.gradle
View file @
65774c88
...
@@ -16,9 +16,6 @@ dependencies {
...
@@ -16,9 +16,6 @@ dependencies {
compileOnly
'com.github.bumptech.glide:glide:3.8.0'
compileOnly
'com.github.bumptech.glide:glide:3.8.0'
compileOnly
'com.squareup.picasso:picasso:2.5.2'
compileOnly
'com.squareup.picasso:picasso:2.5.2'
api
'com.sobot.chat:sobotsupport-glidev4:2.0'
api
'com.sobot.chat:sobotsupport-glidev4:2.0'
//如果主项目中使用的是glide,那么需要在加上
//api 'com.sobot.chat:sobotsupport-glidev4:2.0'
}
}
//添加发布到mavenCentral脚本
//添加发布到mavenCentral脚本
...
...
sobot_pictureframe/sobot-picture-publish-mavencentral.gradle
View file @
65774c88
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
...
@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext
{
ext
{
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_GROUP_ID
=
"com.sobot.library"
//项目包名
PUBLISH_ARTIFACT_ID
=
'picture'
//项目名
PUBLISH_ARTIFACT_ID
=
'picture'
//项目名
PUBLISH_VERSION
=
'
1.0
'
//版本号
PUBLISH_VERSION
=
'
0.2
'
//版本号
}
}
...
...
sobot_pictureframe/src/main/java/com/sobot/pictureframe/SobotBitmapUtil.java
View file @
65774c88
package
com
.
sobot
.
pictureframe
;
package
com
.
sobot
.
pictureframe
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.os.Build
;
import
android.os.Environment
;
import
android.view.WindowManager
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
com.sobot.chat.imageloader.SobotGlideV4ImageLoader
;
import
com.sobot.chat.imageloader.SobotGlideV4ImageLoader
;
import
com.sobot.chat.imageloader.SobotImageLoader
;
import
com.sobot.chat.imageloader.SobotImageLoader
;
//图片显示工具类
public
class
SobotBitmapUtil
{
public
class
SobotBitmapUtil
{
private
static
SobotImageLoader
sImageLoader
;
private
static
SobotImageLoader
sImageLoader
;
...
@@ -67,4 +73,24 @@ public class SobotBitmapUtil {
...
@@ -67,4 +73,24 @@ public class SobotBitmapUtil {
}
}
}
}
@SuppressWarnings
(
"deprecation"
)
public
static
Bitmap
compress
(
String
filePath
,
Context
context
,
boolean
isCamera
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
Q
||
Environment
.
isExternalStorageLegacy
()
||
isCamera
)
{
BitmapFactory
.
Options
options
=
new
BitmapFactory
.
Options
();
options
.
inJustDecodeBounds
=
true
;
// 设置后decode图片不会返回一个bitmap对象,但是会将图片的信息封装到Options中
BitmapFactory
.
decodeFile
(
filePath
,
options
);
WindowManager
wm
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
int
width
=
wm
.
getDefaultDisplay
().
getWidth
();
int
height
=
wm
.
getDefaultDisplay
().
getHeight
();
options
.
inSampleSize
=
SobotPictureUtils
.
calculateInSampleSize
(
options
,
width
,
height
);
options
.
inJustDecodeBounds
=
false
;
return
BitmapFactory
.
decodeFile
(
filePath
,
options
);
}
else
{
return
SobotPictureUtils
.
getBitmapFromUri
(
context
,
SobotPictureUtils
.
getImageContentUri
(
context
,
filePath
));
}
}
}
}
\ No newline at end of file
sobot_pictureframe/src/main/java/com/sobot/pictureframe/SobotPictureUtils.java
0 → 100644
View file @
65774c88
package
com
.
sobot
.
pictureframe
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.os.ParcelFileDescriptor
;
import
android.provider.MediaStore
;
import
java.io.File
;
import
java.io.FileDescriptor
;
public
class
SobotPictureUtils
{
public
static
Bitmap
getBitmapFromUri
(
Context
context
,
Uri
uri
)
{
try
{
ParcelFileDescriptor
parcelFileDescriptor
=
context
.
getContentResolver
().
openFileDescriptor
(
uri
,
"r"
);
FileDescriptor
fileDescriptor
=
parcelFileDescriptor
.
getFileDescriptor
();
Bitmap
image
=
BitmapFactory
.
decodeFileDescriptor
(
fileDescriptor
);
parcelFileDescriptor
.
close
();
return
image
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
Uri
getImageContentUri
(
Context
context
,
String
path
)
{
Cursor
cursor
=
context
.
getContentResolver
().
query
(
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
,
new
String
[]{
MediaStore
.
Images
.
Media
.
_ID
},
MediaStore
.
Images
.
Media
.
DATA
+
"=? "
,
new
String
[]{
path
},
null
);
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
int
id
=
cursor
.
getInt
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
_ID
));
Uri
baseUri
=
Uri
.
parse
(
"content://media/external/images/media"
);
return
Uri
.
withAppendedPath
(
baseUri
,
""
+
id
);
}
else
{
// 如果图片不在手机的共享图片数据库,就先把它插入。
if
(
new
File
(
path
).
exists
())
{
ContentValues
values
=
new
ContentValues
();
values
.
put
(
MediaStore
.
Images
.
Media
.
DATA
,
path
);
return
context
.
getContentResolver
().
insert
(
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
,
values
);
}
else
{
return
null
;
}
}
}
/**
* 计算采样大小
*
* @param options 选项
* @param reqWidth 最大宽度
* @param reqHeight 最大高度
* @return 采样大小
*/
public
static
int
calculateInSampleSize
(
BitmapFactory
.
Options
options
,
int
reqWidth
,
int
reqHeight
)
{
// Raw height and width of image
final
int
height
=
options
.
outHeight
;
final
int
width
=
options
.
outWidth
;
int
inSampleSize
=
1
;
if
(
height
>
reqHeight
||
width
>
reqWidth
)
{
// Calculate ratios of height and width to requested height and width
final
int
heightRatio
=
Math
.
round
((
float
)
height
/
(
float
)
reqHeight
);
final
int
widthRatio
=
Math
.
round
((
float
)
width
/
(
float
)
reqWidth
);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize
=
heightRatio
<
widthRatio
?
heightRatio
:
widthRatio
;
}
return
inSampleSize
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment