Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
ImageVideoBanner
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
ImageVideoBanner
Commits
61e53d36
Commit
61e53d36
authored
Mar 06, 2021
by
委座-江
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
高度自适应
parent
a59db2b6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
419 additions
and
89 deletions
+419
-89
AndroidManifest.xml
imageVideoBanner/src/main/AndroidManifest.xml
+12
-12
MainActivity.java
...c/main/java/com/widget/imagevideobanner/MainActivity.java
+8
-42
ImageVideoBanner.java
.../com/widget/imagevideobanner/banner/ImageVideoBanner.java
+15
-0
ImageVideoFragment.java
...om/widget/imagevideobanner/banner/ImageVideoFragment.java
+141
-30
BannerBean.java
...ain/java/com/widget/imagevideobanner/bean/BannerBean.java
+27
-0
BitmapUtils.java
...n/java/com/widget/imagevideobanner/utils/BitmapUtils.java
+201
-0
item_video_view.xml
imageVideoBanner/src/main/res/layout/item_video_view.xml
+15
-5
No files found.
imageVideoBanner/src/main/AndroidManifest.xml
View file @
61e53d36
...
@@ -15,18 +15,18 @@
...
@@ -15,18 +15,18 @@
android:supportsRtl=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
android:theme=
"@style/AppTheme"
>
<
!--<activity-->
<
activity
<!--android:name=".MainActivity"-->
android:name=
".MainActivity"
<!--android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"-->
android:configChanges=
"orientation|keyboardHidden|screenSize|keyboard|navigation"
<!--android:exported="true"-->
android:exported=
"true"
<!--android:launchMode="singleTask"-->
android:launchMode=
"singleTask"
<!--android:screenOrientation="portrait">--
>
android:screenOrientation=
"portrait"
>
<
!--<intent-filter>--
>
<
intent-filter
>
<
!--<action android:name="android.intent.action.MAIN" />--
>
<
action
android:name=
"android.intent.action.MAIN"
/
>
<
!--<category android:name="android.intent.category.LAUNCHER" />--
>
<
category
android:name=
"android.intent.category.LAUNCHER"
/
>
<
!--</intent-filter>--
>
<
/intent-filter
>
<
!--</activity>--
>
<
/activity
>
</application>
</application>
...
...
imageVideoBanner/src/main/java/com/widget/imagevideobanner/MainActivity.java
View file @
61e53d36
package
com
.
widget
.
imagevideobanner
;
package
com
.
widget
.
imagevideobanner
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.os.Environment
;
import
android.support.v7.app.AppCompatActivity
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
com.widget.imagevideobanner.banner.ImageVideoBanner
;
import
com.widget.imagevideobanner.banner.ImageVideoBanner
;
import
com.widget.imagevideobanner.bean.BannerBean
;
import
com.widget.imagevideobanner.bean.BannerBean
;
...
@@ -13,66 +11,34 @@ import java.util.ArrayList;
...
@@ -13,66 +11,34 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.List
;
public
class
MainActivity
extends
AppCompatActivity
{
public
class
MainActivity
extends
AppCompatActivity
{
private
List
<
BannerBean
>
list
=
new
ArrayList
<>();
private
List
<
BannerBean
>
list
=
new
ArrayList
<>();
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
ImageVideoBanner
banner
=
findViewById
(
R
.
id
.
banner
);
ImageVideoBanner
banner
=
findViewById
(
R
.
id
.
banner
);
// Button goSecondPager = findViewById(R.id.goSecondPager);
// goSecondPager.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// startActivity(new Intent(MainActivity.this, com.widget.imagevideobanner.MainActivity2.class));
// }
// });
setDatas
();
setDatas
();
banner
.
addData
(
list
);
banner
.
addData
(
list
);
banner
.
startBanner
();
banner
.
startBanner
();
}
}
private
void
setDatas
()
{
private
void
setDatas
()
{
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
BannerBean
listBean
=
new
BannerBean
();
BannerBean
listBean
=
new
BannerBean
();
if
(
i
==
0
)
{
if
(
i
==
0
)
{
String
url
=
Environment
.
getExternalStorageDirectory
()
+
"/Video_Compressed_converseBanner_2021_01_05_03_05_11_0.mp4"
;
// String url = Environment.getExternalStorageDirectory() + "/huarun/video/video_home_1_72m.mp4";
String
uri
=
"android.resource://"
+
getPackageName
()
+
"/"
+
R
.
raw
.
default_guide
;
listBean
.
setUrl
(
uri
);
listBean
.
setType
(
1
);
//图片类型 视频
list
.
add
(
listBean
);
}
else
if
(
i
==
1
){
listBean
.
setUrl
(
"http://pic11.nipic.com/20101201/4452735_182232064453_2.jpg"
);
listBean
.
setType
(
0
);
//图片类型 视频
list
.
add
(
listBean
);
}
else
if
(
i
==
2
){
String
url
=
Environment
.
getExternalStorageDirectory
()
+
"/huarun/video/video_scan.mp4"
;
// String uri = "android.resource://" + getPackageName() + "/" + R.raw.video_scan;
listBean
.
setUrl
(
url
);
listBean
.
setUrl
(
url
);
listBean
.
setType
(
1
);
//图片类型 视频
listBean
.
setType
(
1
);
list
.
add
(
listBean
);
list
.
add
(
listBean
);
}
else
if
(
i
==
3
){
}
else
if
(
i
==
1
)
{
listBean
.
setUrl
(
"http://120.26.246.123:18881/downloads/jjt1.jpg"
);
String
url
=
Environment
.
getExternalStorageDirectory
()
+
"/vertical_test.mp4"
;
listBean
.
setType
(
0
);
//图片类型 视频
listBean
.
setUrl
(
url
);
list
.
add
(
listBean
);
listBean
.
setType
(
1
);
}
else
if
(
i
==
4
){
listBean
.
setUrl
(
"http://120.26.246.123:18881/downloads/jjt2.jpg"
);
listBean
.
setType
(
0
);
//图片类型 视频
list
.
add
(
listBean
);
list
.
add
(
listBean
);
}
}
}
}
}
}
@Override
protected
void
onNewIntent
(
Intent
intent
)
{
super
.
onNewIntent
(
intent
);
Log
.
e
(
"###"
,
"我是onNewIntent时间"
);
}
}
}
imageVideoBanner/src/main/java/com/widget/imagevideobanner/banner/ImageVideoBanner.java
View file @
61e53d36
...
@@ -125,7 +125,10 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
...
@@ -125,7 +125,10 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
mmr
.
extractMetadata
(
FFmpegMediaMetadataRetriever
.
METADATA_KEY_ARTIST
);
mmr
.
extractMetadata
(
FFmpegMediaMetadataRetriever
.
METADATA_KEY_ARTIST
);
Bitmap
b
=
mmr
.
getFrameAtTime
();
// frame at 2 seconds
Bitmap
b
=
mmr
.
getFrameAtTime
();
// frame at 2 seconds
bannerBean
.
setLoadingImage
(
BitmapUtils
.
getBytes
(
b
));
bannerBean
.
setLoadingImage
(
BitmapUtils
.
getBytes
(
b
));
Bitmap
bx
=
BitmapUtils
.
createBlurBitmap
(
b
,
40
);
bannerBean
.
setLoadingBlurImage
(
BitmapUtils
.
getBytes
(
bx
));
b
.
recycle
();
b
.
recycle
();
bx
.
recycle
();
mmr
.
release
();
mmr
.
release
();
}
}
return
true
;
return
true
;
...
@@ -241,6 +244,18 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
...
@@ -241,6 +244,18 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCha
startBanner
(
0
);
startBanner
(
0
);
}
}
@Override
public
void
updateSize
(
BannerBean
bannerBean
)
{
if
(
mList
.
size
()
>
0
){
for
(
BannerBean
bean
:
mList
){
if
(
bannerBean
.
getUrl
().
equals
(
bean
.
getUrl
())){
bean
.
setHeight
(
bannerBean
.
getHeight
());
bean
.
setWidth
(
bannerBean
.
getWidth
());
}
}
}
}
private
final
class
ViewsPagerAdapter
extends
FragmentStatePagerAdapter
{
private
final
class
ViewsPagerAdapter
extends
FragmentStatePagerAdapter
{
private
com
.
widget
.
imagevideobanner
.
banner
.
ImageVideoFragment
fragment
;
private
com
.
widget
.
imagevideobanner
.
banner
.
ImageVideoFragment
fragment
;
private
FragmentManager
fm
;
private
FragmentManager
fm
;
...
...
imageVideoBanner/src/main/java/com/widget/imagevideobanner/banner/ImageVideoFragment.java
View file @
61e53d36
This diff is collapsed.
Click to expand it.
imageVideoBanner/src/main/java/com/widget/imagevideobanner/bean/BannerBean.java
View file @
61e53d36
...
@@ -6,6 +6,33 @@ public class BannerBean implements Serializable {
...
@@ -6,6 +6,33 @@ public class BannerBean implements Serializable {
private
String
url
;
private
String
url
;
private
int
type
;
private
int
type
;
private
byte
[]
loadingImage
;
private
byte
[]
loadingImage
;
private
byte
[]
loadingBlurImage
;
private
int
width
;
private
int
height
;
public
int
getWidth
()
{
return
width
;
}
public
void
setWidth
(
int
width
)
{
this
.
width
=
width
;
}
public
int
getHeight
()
{
return
height
;
}
public
void
setHeight
(
int
height
)
{
this
.
height
=
height
;
}
public
byte
[]
getLoadingBlurImage
()
{
return
loadingBlurImage
;
}
public
void
setLoadingBlurImage
(
byte
[]
loadingBlurImage
)
{
this
.
loadingBlurImage
=
loadingBlurImage
;
}
public
byte
[]
getLoadingImage
()
{
public
byte
[]
getLoadingImage
()
{
return
loadingImage
;
return
loadingImage
;
...
...
imageVideoBanner/src/main/java/com/widget/imagevideobanner/utils/BitmapUtils.java
View file @
61e53d36
...
@@ -2,6 +2,8 @@ package com.widget.imagevideobanner.utils;
...
@@ -2,6 +2,8 @@ package com.widget.imagevideobanner.utils;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.BitmapFactory
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.os.Environment
;
import
android.os.Environment
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
...
@@ -42,5 +44,204 @@ public class BitmapUtils {
...
@@ -42,5 +44,204 @@ public class BitmapUtils {
}
}
}
}
/**
* 传递bitmap 传递模糊半径 返回一个被模糊的bitmap
* 比较耗时
* @param sentBitmap
* @param radius
* @return
*/
public
static
Bitmap
createBlurBitmap
(
Bitmap
sentBitmap
,
int
radius
)
{
Bitmap
bitmap
=
sentBitmap
.
copy
(
sentBitmap
.
getConfig
(),
true
);
if
(
radius
<
1
)
{
return
(
null
);
}
int
w
=
bitmap
.
getWidth
();
int
h
=
bitmap
.
getHeight
();
int
[]
pix
=
new
int
[
w
*
h
];
bitmap
.
getPixels
(
pix
,
0
,
w
,
0
,
0
,
w
,
h
);
int
wm
=
w
-
1
;
int
hm
=
h
-
1
;
int
wh
=
w
*
h
;
int
div
=
radius
+
radius
+
1
;
int
r
[]
=
new
int
[
wh
];
int
g
[]
=
new
int
[
wh
];
int
b
[]
=
new
int
[
wh
];
int
rsum
,
gsum
,
bsum
,
x
,
y
,
i
,
p
,
yp
,
yi
,
yw
;
int
vmin
[]
=
new
int
[
Math
.
max
(
w
,
h
)];
int
divsum
=
(
div
+
1
)
>>
1
;
divsum
*=
divsum
;
int
dv
[]
=
new
int
[
256
*
divsum
];
for
(
i
=
0
;
i
<
256
*
divsum
;
i
++)
{
dv
[
i
]
=
(
i
/
divsum
);
}
yw
=
yi
=
0
;
int
[][]
stack
=
new
int
[
div
][
3
];
int
stackpointer
;
int
stackstart
;
int
[]
sir
;
int
rbs
;
int
r1
=
radius
+
1
;
int
routsum
,
goutsum
,
boutsum
;
int
rinsum
,
ginsum
,
binsum
;
for
(
y
=
0
;
y
<
h
;
y
++)
{
rinsum
=
ginsum
=
binsum
=
routsum
=
goutsum
=
boutsum
=
rsum
=
gsum
=
bsum
=
0
;
for
(
i
=
-
radius
;
i
<=
radius
;
i
++)
{
p
=
pix
[
yi
+
Math
.
min
(
wm
,
Math
.
max
(
i
,
0
))];
sir
=
stack
[
i
+
radius
];
sir
[
0
]
=
(
p
&
0xff0000
)
>>
16
;
sir
[
1
]
=
(
p
&
0x00ff00
)
>>
8
;
sir
[
2
]
=
(
p
&
0x0000ff
);
rbs
=
r1
-
Math
.
abs
(
i
);
rsum
+=
sir
[
0
]
*
rbs
;
gsum
+=
sir
[
1
]
*
rbs
;
bsum
+=
sir
[
2
]
*
rbs
;
if
(
i
>
0
)
{
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
}
else
{
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
}
}
stackpointer
=
radius
;
for
(
x
=
0
;
x
<
w
;
x
++)
{
r
[
yi
]
=
dv
[
rsum
];
g
[
yi
]
=
dv
[
gsum
];
b
[
yi
]
=
dv
[
bsum
];
rsum
-=
routsum
;
gsum
-=
goutsum
;
bsum
-=
boutsum
;
stackstart
=
stackpointer
-
radius
+
div
;
sir
=
stack
[
stackstart
%
div
];
routsum
-=
sir
[
0
];
goutsum
-=
sir
[
1
];
boutsum
-=
sir
[
2
];
if
(
y
==
0
)
{
vmin
[
x
]
=
Math
.
min
(
x
+
radius
+
1
,
wm
);
}
p
=
pix
[
yw
+
vmin
[
x
]];
sir
[
0
]
=
(
p
&
0xff0000
)
>>
16
;
sir
[
1
]
=
(
p
&
0x00ff00
)
>>
8
;
sir
[
2
]
=
(
p
&
0x0000ff
);
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
rsum
+=
rinsum
;
gsum
+=
ginsum
;
bsum
+=
binsum
;
stackpointer
=
(
stackpointer
+
1
)
%
div
;
sir
=
stack
[(
stackpointer
)
%
div
];
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
rinsum
-=
sir
[
0
];
ginsum
-=
sir
[
1
];
binsum
-=
sir
[
2
];
yi
++;
}
yw
+=
w
;
}
for
(
x
=
0
;
x
<
w
;
x
++)
{
rinsum
=
ginsum
=
binsum
=
routsum
=
goutsum
=
boutsum
=
rsum
=
gsum
=
bsum
=
0
;
yp
=
-
radius
*
w
;
for
(
i
=
-
radius
;
i
<=
radius
;
i
++)
{
yi
=
Math
.
max
(
0
,
yp
)
+
x
;
sir
=
stack
[
i
+
radius
];
sir
[
0
]
=
r
[
yi
];
sir
[
1
]
=
g
[
yi
];
sir
[
2
]
=
b
[
yi
];
rbs
=
r1
-
Math
.
abs
(
i
);
rsum
+=
r
[
yi
]
*
rbs
;
gsum
+=
g
[
yi
]
*
rbs
;
bsum
+=
b
[
yi
]
*
rbs
;
if
(
i
>
0
)
{
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
}
else
{
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
}
if
(
i
<
hm
)
{
yp
+=
w
;
}
}
yi
=
x
;
stackpointer
=
radius
;
for
(
y
=
0
;
y
<
h
;
y
++)
{
pix
[
yi
]
=
(
0xff000000
&
pix
[
yi
])
|
(
dv
[
rsum
]
<<
16
)
|
(
dv
[
gsum
]
<<
8
)
|
dv
[
bsum
];
rsum
-=
routsum
;
gsum
-=
goutsum
;
bsum
-=
boutsum
;
stackstart
=
stackpointer
-
radius
+
div
;
sir
=
stack
[
stackstart
%
div
];
routsum
-=
sir
[
0
];
goutsum
-=
sir
[
1
];
boutsum
-=
sir
[
2
];
if
(
x
==
0
)
{
vmin
[
y
]
=
Math
.
min
(
y
+
r1
,
hm
)
*
w
;
}
p
=
x
+
vmin
[
y
];
sir
[
0
]
=
r
[
p
];
sir
[
1
]
=
g
[
p
];
sir
[
2
]
=
b
[
p
];
rinsum
+=
sir
[
0
];
ginsum
+=
sir
[
1
];
binsum
+=
sir
[
2
];
rsum
+=
rinsum
;
gsum
+=
ginsum
;
bsum
+=
binsum
;
stackpointer
=
(
stackpointer
+
1
)
%
div
;
sir
=
stack
[
stackpointer
];
routsum
+=
sir
[
0
];
goutsum
+=
sir
[
1
];
boutsum
+=
sir
[
2
];
rinsum
-=
sir
[
0
];
ginsum
-=
sir
[
1
];
binsum
-=
sir
[
2
];
yi
+=
w
;
}
}
bitmap
.
setPixels
(
pix
,
0
,
w
,
0
,
0
,
w
,
h
);
return
(
bitmap
);
}
public
static
Drawable
bitmap2Drawable
(
Bitmap
bitmap
)
{
@SuppressWarnings
(
"deprecation"
)
BitmapDrawable
bd
=
new
BitmapDrawable
(
bitmap
);
Drawable
d
=
(
Drawable
)
bd
;
return
d
;
}
}
}
imageVideoBanner/src/main/res/layout/item_video_view.xml
View file @
61e53d36
...
@@ -2,21 +2,30 @@
...
@@ -2,21 +2,30 @@
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
android:id=
"@+id/cVideoView"
>
<VideoView
<VideoView
android:id=
"@+id/video_view"
android:id=
"@+id/video_view"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
android:layout_height=
"match_parent"
android:visibility=
"visible"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
/>
<ImageView
<ImageView
android:id=
"@+id/iv_wait_loading_layout"
android:id=
"@+id/iv_wait_loading_layout"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:scaleType=
"fitXY"
android:scaleType=
"fitXY"
android:background=
"@android:color/white"
>
android:visibility=
"gone"
</ImageView>
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
android:background=
"@android:color/white"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/wait_loading_layout"
android:id=
"@+id/wait_loading_layout"
...
@@ -28,6 +37,7 @@
...
@@ -28,6 +37,7 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
android:gravity=
"center"
android:gravity=
"center"
android:background=
"@color/white"
android:background=
"@color/white"
android:visibility=
"invisible"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<LinearLayout
<LinearLayout
...
...
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