Commit cf29174d authored by jiangjiantao's avatar jiangjiantao

first 提交

parent a0683270
package com.zxj.imagevideobanner;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.zxj.imagevideobanner", appContext.getPackageName());
}
}
package com.zxj.imagevideobanner.utils;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Created by jay on 2018/6/4.
*/
public class FileUtils {
public static InputStream readSdCardXml(String fileName){
try {
String path = Environment.getExternalStorageDirectory()+ File.separator + "imageVideo" + File.separator+fileName;
Log.e("zxj","path="+path);
File file = new File(path);
FileInputStream is = new FileInputStream(file);
return is;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static OutputStream writeSdCardXml(String fileName){
File fileDir = new File(Environment.getExternalStorageDirectory()+ File.separator + "imageVideo" + File.separator);
if(!fileDir.exists()){
fileDir.mkdirs();
}
File file = new File(fileDir,fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
return fos;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 获取SD卡根目录路径
*
* @return
*/
public static String getSdCardPath() {
boolean exist = isSdCardExist();
String sdpath = "";
if (exist) {
sdpath = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
sdpath = "不适用";
}
return sdpath;
}
/**
* 判断SDCard是否存在 [当没有外挂SD卡时,内置ROM也被识别为存在sd卡]
*
* @return
*/
public static boolean isSdCardExist() {
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}
}
package com.zxj.imagevideobanner.utils;
import com.zxj.imagevideobanner.bean.BannerBean;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
/**
* Created by itservice on 2017/9/14.
*/
public interface OperationParser {
/**
* 解析输入流 得到BannerBean对象集合
* @param is
* @return
* @throws Exception
*/
public List<BannerBean> parse(InputStream is) throws Exception;
/**
* 序列化BannerBean对象集合 得到XML形式的字符串
* @param lists
* @return
* @throws Exception
*/
public String serialize(List<BannerBean> lists,OutputStream is) throws Exception;
}
package com.zxj.imagevideobanner.utils;
import android.content.Context;
import android.os.Environment;
import android.util.Log;
import android.util.Xml;
import com.zxj.imagevideobanner.bean.BannerBean;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
/**
* Created by itservice on 2017/9/14.
*/
public class PullOperationParser implements OperationParser {
private Context context;
public PullOperationParser(Context context){
this.context = context;
}
@Override
public List<BannerBean> parse(InputStream is) throws Exception {
List<BannerBean> bannerBeans = null;
BannerBean bannerBean = null;
XmlPullParser parser = Xml.newPullParser(); //由android.util.Xml创建一个XmlPullParser实例
parser.setInput(is, "UTF-8"); //设置输入流 并指明编码方式
int eventType = parser.getEventType();
Log.e("zxj","eventType="+eventType);
while (eventType != XmlPullParser.END_DOCUMENT) {
String name = parser.getName();
switch (eventType){
case XmlPullParser.START_DOCUMENT:
bannerBeans = new ArrayList<>();
break;
case XmlPullParser.START_TAG:
if("imageVideo".equals(name)){
bannerBean = new BannerBean();
}else if("url".equals(name)){
String path = parser.nextText();
if(!path.startsWith("http")){
path = Environment.getExternalStorageDirectory() + File.separator + path;
}
bannerBean.setUrl(path);
}else if("type".equals(name)){
bannerBean.setType(Integer.parseInt(parser.nextText()));
}
break;
case XmlPullParser.END_TAG:
if("imageVideo".equals(name)){
bannerBeans.add(bannerBean);
bannerBean = null;
}
break;
}
eventType = parser.next();
}
return bannerBeans;
}
@Override
public String serialize(List<BannerBean> bannerBeans,OutputStream os) throws Exception {
XmlSerializer serializer = Xml.newSerializer(); //由android.util.Xml创建一个XmlSerializer实例
StringWriter writer = new StringWriter();
serializer.setOutput(os,"UTF-8");
// serializer.setOutput(writer); //设置输出方向为writer
serializer.startDocument("UTF-8", true);
serializer.text("\n");
serializer.startTag("", "imageVideos");
for(BannerBean bannerBean :bannerBeans){
serializer.text("\n\t");
serializer.startTag("","imageVideo");
serializer.text("\n\t\t");
serializer.startTag("","url");
serializer.text(bannerBean.getUrl());
serializer.endTag("","url");
serializer.text("\n\t\t");
serializer.startTag("","type");
serializer.text(String.valueOf(bannerBean.getType()));
serializer.endTag("","type");
serializer.text("\n\t");
serializer.endTag("","imageVideo");
serializer.text("\n");
}
serializer.endTag("","imageVideos");
serializer.endDocument();
os.flush();
os.close();
return null;
}
}
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/loading01"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading02"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading03"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading04"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading05"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading06"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading07"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading08"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading09"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading10"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading11"
android:duration="100">
</item>
<item
android:drawable="@drawable/loading12"
android:duration="100">
</item>
</animation-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.zxj.imagevideobanner.MainActivity">
<com.zxj.imagevideobanner.banner.ImageVideoBanner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="300dp"
app:period="2000"/>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/wait_loading_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<ProgressBar
android:id="@+id/loading_progress_bar"
style="@style/wait_loading"
android:layout_width="78dp"
android:layout_height="78dp"
android:layout_gravity="center"
android:gravity="center"
android:indeterminate="false" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
......
#Tue Jun 05 11:53:26 CST 2018
#Mon May 18 17:09:26 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "com.zxj.imagevideobanner"
minSdkVersion 15
minSdkVersion 18
targetSdkVersion 22
versionCode 1
versionName "1.0"
......@@ -20,10 +19,15 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.github.bumptech.glide:glide:3.7.0'
//当需要FFmpegMediaMetadataRetriever时必选
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi-v7a:1.0.14'
implementation 'com.wang.avi:library:2.1.3'
// compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zxj.imagevideobanner">
package="com.widget.imagevideobanner">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<application
android:allowBackup="true"
......@@ -14,13 +14,21 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--<activity-->
<!--android:name=".MainActivity"-->
<!--android:configChanges="orientation|keyboardHidden|screenSize|keyboard|navigation"-->
<!--android:exported="true"-->
<!--android:launchMode="singleTask"-->
<!--android:screenOrientation="portrait">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
<!--</activity>-->
</application>
</manifest>
\ No newline at end of file
package com.zxj.imagevideobanner;
package com.widget.imagevideobanner;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.zxj.imagevideobanner.banner.ImageVideoBanner;
import com.zxj.imagevideobanner.bean.BannerBean;
import com.zxj.imagevideobanner.utils.FileUtils;
import com.zxj.imagevideobanner.utils.PullOperationParser;
import com.widget.imagevideobanner.banner.ImageVideoBanner;
import com.widget.imagevideobanner.bean.BannerBean;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
......@@ -23,60 +19,60 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageVideoBanner banner = findViewById(R.id.banner);
Log.e("zxj", Environment.getExternalStorageDirectory()+ File.separator+"test/mov_bbb.mp4");
List<BannerBean> bannerBeans = getDatas();
if (null == bannerBeans) {
setDatas();
bannerBeans = getDatas();
}
banner.replaceData(bannerBeans);
// 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();
banner.addData(list);
banner.startBanner();
}
private void setDatas() {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 1; i++) {
BannerBean listBean = new BannerBean();
if (i == 1 ) {
listBean.setUrl("imageVideo/mov_bbb.mp4");
// listBean.setUrl("http://www.w3school.com.cn/example/html5/mov_bbb.mp4");
// listBean.setUrl("https://media.w3.org/2010/05/sintel/trailer.mp4");
if (i == 0) {
// 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==2){
} else if(i==1){
listBean.setUrl("http://pic11.nipic.com/20101201/4452735_182232064453_2.jpg");
listBean.setType(0);//图片类型 视频
list.add(listBean);
}else if(i == 3){
listBean.setUrl("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
}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.setType(1);//图片类型 视频
list.add(listBean);
}else {
listBean.setUrl("http://img.zcool.cn/community/01635d571ed29832f875a3994c7836.png@900w_1l_2o_100sh.jpg");
listBean.setType(0);//图片类型 图片
}else if(i == 3){
listBean.setUrl("http://120.26.246.123:18881/downloads/jjt1.jpg");
listBean.setType(0);//图片类型 视频
list.add(listBean);
} else if(i == 4){
listBean.setUrl("http://120.26.246.123:18881/downloads/jjt2.jpg");
listBean.setType(0);//图片类型 视频
list.add(listBean);
}
}
try {
OutputStream os = FileUtils.writeSdCardXml("image_video.xml");
PullOperationParser parser = new PullOperationParser(MainActivity.this);
parser.serialize(list, os);
} catch (Exception e) {
e.printStackTrace();
}
}
public List<BannerBean> getDatas() {
try {
InputStream is = FileUtils.readSdCardXml("image_video.xml");
PullOperationParser parser = new PullOperationParser(MainActivity.this);
List<BannerBean> bannerBeans = parser.parse(is);
return bannerBeans;
} catch (Exception e) {
e.printStackTrace();
}
return null;
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("###","我是onNewIntent时间");
}
}
package com.zxj.imagevideobanner.banner;
package com.widget.imagevideobanner.banner;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
......@@ -18,20 +19,24 @@ import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import com.zxj.imagevideobanner.R;
import com.zxj.imagevideobanner.bean.BannerBean;
import com.widget.imagevideobanner.R;
import com.widget.imagevideobanner.bean.BannerBean;
import com.widget.imagevideobanner.utils.BitmapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import wseemann.media.FFmpegMediaMetadataRetriever;
/**
* Created by jay on 2018/5/28.
*/
public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageChangeListener, ImageVideoFragment.OnVideoCompletionListener {
public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageChangeListener, com.widget.imagevideobanner.banner.ImageVideoFragment.OnVideoCompletionListener {
private static final int UPTATE_VIEWPAGER = 0;
private ViewPager mViewPager;
private List<BannerBean> mList = new ArrayList<>();
......@@ -40,22 +45,23 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCh
private Timer timer;
private TimerTask timerTask;
private long period;//轮播图展示时长,默认5秒
private int mCurrentPosition;
private Context context;
public static ScheduledExecutorService sExecutor;
public Context mContext;
public ImageVideoBanner(@NonNull Context context) {
super(context);
this.context = context;
mContext = context;
initView(context);
}
public ImageVideoBanner(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.banner);
mContext = context;
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.banner);
period = typedArray.getInt(R.styleable.banner_period,5000);
typedArray.recycle();
initView(context);
}
private void initView(Context context) {
......@@ -71,16 +77,73 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCh
return true;
}
});
}
public void replaceData(List<BannerBean> listBean){
public void replaceData(List<com.widget.imagevideobanner.bean.BannerBean> listBean){
mAdapter.replaceData(listBean);
}
public void addData(List<BannerBean> listBean){
public void addData(List<com.widget.imagevideobanner.bean.BannerBean> listBean){
mAdapter.addData(listBean);
}
/**
* 初始化视频的Bitmap
*/
private void initBannerBitmap() {
if(mList.size() == 0){
return;
}
for(BannerBean bannerBean : mList){
if(bannerBean.getType() == 1 && null == bannerBean.getLoadingImage()){
setLoadingImages(bannerBean);
}
}
}
/**
* 获取视频的第一帧作为截图
* @param bannerBean
*/
private void setLoadingImages(final BannerBean bannerBean){
if (sExecutor == null) {
sExecutor = Executors.newScheduledThreadPool(5);
}
Future<Boolean> submit = sExecutor.submit(new Callable<Boolean>() {
@Override
public Boolean call() {
try {
String url = bannerBean.getUrl();
if(!url.contains("android.resource")){
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(url);
mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ALBUM);
mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ARTIST);
Bitmap b = mmr.getFrameAtTime(); // frame at 2 seconds
bannerBean.setLoadingImage( BitmapUtils.getBytes(b));
mmr.release();
}
return true;
}catch (Exception e){
return false;
}
}
});
try {
submit.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
......@@ -127,8 +190,19 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCh
}
}
}
/**
* 设置轮播图 图片展示间隔
*/
public void setPeriod(int period ){
this.period = period;
}
public void startBanner(){
startBanner(period);
//如果第一页是视频 不用定时器
if(mList.get(0).getType() == 0){
startBanner(period);
}
}
public void startBanner(long delay){
......@@ -168,7 +242,7 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCh
}
private final class ViewsPagerAdapter extends FragmentStatePagerAdapter{
private ImageVideoFragment fragment;
private com.widget.imagevideobanner.banner.ImageVideoFragment fragment;
private FragmentManager fm;
public ViewsPagerAdapter(FragmentManager fm) {
super(fm);
......@@ -177,15 +251,27 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCh
@Override
public Fragment getItem(int position) {
fragment = new ImageVideoFragment();
fragment = new com.widget.imagevideobanner.banner.ImageVideoFragment();
fragment.setOnVideoCompletionListener(ImageVideoBanner.this);
BannerBean bannerBean = mList.get(position);
com.widget.imagevideobanner.bean.BannerBean bannerBean = mList.get(position);
Bundle bundle = new Bundle();
bundle.putSerializable("bannerBean",bannerBean);
bundle.putBoolean("loop",getLoop());
fragment.setArguments(bundle);
return fragment;
}
/**
* 只有1个视频的时候循环播放
* @return
*/
private boolean getLoop() {
if(mList.size() == 1 && mList.get(0).getType() == 1){
return true;
}
return false;
}
@Override
public int getCount() {
return mList.size();
......@@ -200,21 +286,61 @@ public class ImageVideoBanner extends FrameLayout implements ViewPager.OnPageCh
}
public void replaceData(List<BannerBean> listBean){
// 新数据和原来数据对比,不一致才去刷新
boolean change = compareData(listBean);
if(!change){
notifyDataSetChanged();
// startBanner();
return;
}
if(null != listBean){
mList.clear();
addData(listBean);
//如果第一张是图片 需要开启定时器
if(listBean.get(0).getType() == 0){
startBanner();
}
autoCurrIndex = 0;
// startBanner();
}
}
/**
* 对比数据
* @param listBean
* @return
*/
private boolean compareData(List<BannerBean> listBean){
if(listBean == null || listBean.size() == 0){
return false;
}
if(listBean.size() == mList.size()){
for(int i = 0 ; i < mList.size() ; i++){
if(mList.get(i).getType() != listBean.get(i).getType()
|| !mList.get(i).getUrl().equals(listBean.get(i).getUrl())){
return true;
}
}
return false;
}
return true;
}
public void addData(List<BannerBean> listBean){
if(null != listBean){
mList.addAll(listBean);
}
initBannerBitmap();
notifyDataSetChanged();
}
public ImageVideoFragment getFragment() {
return fragment;
}
}
}
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.zxj.imagevideobanner.banner;
package com.widget.imagevideobanner.banner;
import android.view.KeyEvent;
......@@ -95,17 +95,17 @@ public class KeyEventCompat {
static class HoneycombKeyEventVersionImpl implements KeyEventVersionImpl {
@Override
public int normalizeMetaState(int metaState) {
return KeyEventCompatHoneycomb.normalizeMetaState(metaState);
return com.widget.imagevideobanner.banner.KeyEventCompatHoneycomb.normalizeMetaState(metaState);
}
@Override
public boolean metaStateHasModifiers(int metaState, int modifiers) {
return KeyEventCompatHoneycomb.metaStateHasModifiers(metaState, modifiers);
return com.widget.imagevideobanner.banner.KeyEventCompatHoneycomb.metaStateHasModifiers(metaState, modifiers);
}
@Override
public boolean metaStateHasNoModifiers(int metaState) {
return KeyEventCompatHoneycomb.metaStateHasNoModifiers(metaState);
return com.widget.imagevideobanner.banner.KeyEventCompatHoneycomb.metaStateHasNoModifiers(metaState);
}
}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.zxj.imagevideobanner.banner;
package com.widget.imagevideobanner.banner;
import android.view.KeyEvent;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.zxj.imagevideobanner.banner;
package com.widget.imagevideobanner.banner;
import android.content.Context;
import android.content.res.TypedArray;
......
package com.zxj.imagevideobanner.bean;
import android.os.Parcel;
import android.os.Parcelable;
package com.widget.imagevideobanner.bean;
import java.io.Serializable;
/**
* Created by jay on 2018/5/30.
*/
public class BannerBean implements Serializable,Parcelable {
public class BannerBean implements Serializable {
private String url;
private int type;
private byte[] loadingImage;
public byte[] getLoadingImage() {
return loadingImage;
}
public void setLoadingImage(byte[] loadingImage) {
this.loadingImage = loadingImage;
}
public String getUrl() {
return url;
}
......@@ -30,37 +31,6 @@ public class BannerBean implements Serializable,Parcelable {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.url);
dest.writeInt(this.type);
}
public BannerBean() {
}
protected BannerBean(Parcel in) {
this.url = in.readString();
this.type = in.readInt();
}
public static final Creator<BannerBean> CREATOR = new Creator<BannerBean>() {
@Override
public BannerBean createFromParcel(Parcel source) {
return new BannerBean(source);
}
@Override
public BannerBean[] newArray(int size) {
return new BannerBean[size];
}
};
@Override
public String toString() {
return "BannerBean{" +
......
package com.widget.imagevideobanner.utils;
import android.os.Environment;
import android.text.TextUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class BannerLogFileUtils {
/**
* 将播放的错误信息记录到本地
* @param exInfo
* @return
*/
public static String saveInfo2File( String exInfo) {
if (TextUtils.isEmpty(exInfo)) {
return null;
}
String sampleDir = "/miyaterminal/log/";
String tmpDir = Environment.getExternalStorageDirectory().toString() + File.separator + sampleDir;
File file = new File(tmpDir);
if (!file.exists()) {
file.mkdir();
}
String logPath = tmpDir + "bannererr.log";
try {
FileOutputStream mFileOutputStream = new FileOutputStream(logPath);
mFileOutputStream.write(exInfo.getBytes());
mFileOutputStream.close();
return logPath;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
package com.widget.imagevideobanner.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class BitmapUtils {
public static byte[] getBytes(Bitmap bitmap){
//实例化字节数组输出流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos);//压缩位图
return baos.toByteArray();//创建分配字节数组
}
public static Bitmap getBitmap(byte[] data){
return BitmapFactory.decodeByteArray(data, 0, data.length);//从字节数组解码位图
}
/** 保存方法 */
public static void saveBitmap(Bitmap bitmap) {
String url = Environment.getExternalStorageDirectory() + "/huarun/video/xx.png";
File f = new File(url);
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#88000000" />
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
<com.zxj.imagevideobanner.banner.ViewPager
android:id="@+id/view_pager"
<com.widget.imagevideobanner.banner.ImageVideoBanner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:period="5000" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.widget.imagevideobanner.banner.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -9,4 +9,5 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ImageView
android:id="@+id/iv_wait_loading_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:background="@android:color/white">
</ImageView>
<LinearLayout
android:id="@+id/wait_loading_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:background="@drawable/progress_waitingbar_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="16dp"
android:orientation="vertical">
<com.wang.avi.AVLoadingIndicatorView
style="@style/AVLoadingIndicatorView.Small"
android:layout_width="36dp"
android:layout_height="36dp"
android:visibility="visible"
app:indicatorName="LineSpinFadeLoaderIndicator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="视频加载中 ..."
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:background="@drawable/progress_waitingbar_bg"
android:orientation="vertical"
android:gravity="center_horizontal" >
<com.wang.avi.AVLoadingIndicatorView
style="@style/AVLoadingIndicatorView.Small"
android:layout_width="36dp"
android:layout_height="36dp"
android:visibility="visible"
app:indicatorName="LineSpinFadeLoaderIndicator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="视频加载中 ..."
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -3,4 +3,7 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="white">#fff</color>
<color name="transparency">#0000</color>
</resources>
......@@ -8,12 +8,6 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- 加载旋转滚动条样式 -->
<style name="wait_loading">
<item name="android:indeterminate">true</item>
<item name="android:indeterminateDrawable">@drawable/wait_loading_anim</item>
<item name="android:indeterminateDuration">1000</item>
<item name="android:indeterminateOnly">true</item>
</style>
</resources>
include ':app'
include ':imageVideoBanner'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment