Commit aecd4fe7 authored by gaodapeng's avatar gaodapeng

修改以适配androidx版本

parent cf29174d
/build
\ No newline at end of file
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.github.bumptech.glide:glide:4.9.0'
//当需要FFmpegMediaMetadataRetriever时必选
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever-armeabi-v7a:1.0.14'
implementation 'com.wang.avi:library:2.1.3'
implementation "androidx.viewpager2:viewpager2:1.0.0"
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.widget.imagebanner;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.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() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.widget.imagebanner.test", appContext.getPackageName());
}
}
\ No newline at end of file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.widget.imagebanner">
/
</manifest>
\ No newline at end of file
package com.widget.imagevideobanner.bean; package com.widget.imagebanner.bean;
import java.io.Serializable; import java.io.Serializable;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.widget.imagevideobanner.banner; package com.widget.imagebanner.event;
import android.view.KeyEvent; import android.view.KeyEvent;
...@@ -95,17 +95,17 @@ public class KeyEventCompat { ...@@ -95,17 +95,17 @@ public class KeyEventCompat {
static class HoneycombKeyEventVersionImpl implements KeyEventVersionImpl { static class HoneycombKeyEventVersionImpl implements KeyEventVersionImpl {
@Override @Override
public int normalizeMetaState(int metaState) { public int normalizeMetaState(int metaState) {
return com.widget.imagevideobanner.banner.KeyEventCompatHoneycomb.normalizeMetaState(metaState); return KeyEventCompatHoneycomb.normalizeMetaState(metaState);
} }
@Override @Override
public boolean metaStateHasModifiers(int metaState, int modifiers) { public boolean metaStateHasModifiers(int metaState, int modifiers) {
return com.widget.imagevideobanner.banner.KeyEventCompatHoneycomb.metaStateHasModifiers(metaState, modifiers); return KeyEventCompatHoneycomb.metaStateHasModifiers(metaState, modifiers);
} }
@Override @Override
public boolean metaStateHasNoModifiers(int metaState) { public boolean metaStateHasNoModifiers(int metaState) {
return com.widget.imagevideobanner.banner.KeyEventCompatHoneycomb.metaStateHasNoModifiers(metaState); return KeyEventCompatHoneycomb.metaStateHasNoModifiers(metaState);
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.widget.imagevideobanner.banner; package com.widget.imagebanner.event;
import android.view.KeyEvent; import android.view.KeyEvent;
......
package com.widget.imagevideobanner.utils; package com.widget.imagebanner.utils;
import android.os.Environment; import android.os.Environment;
import android.text.TextUtils; import android.text.TextUtils;
......
package com.widget.imagevideobanner.utils; package com.widget.imagebanner.utils;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
......
package com.widget.imagevideobanner.banner; package com.widget.imagebanner.view;
import android.graphics.Color; import android.graphics.Color;
import android.media.MediaPlayer; import android.media.MediaPlayer;
...@@ -6,9 +6,11 @@ import android.net.Uri; ...@@ -6,9 +6,11 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import androidx.annotation.NonNull;
import android.support.v4.app.Fragment; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -18,10 +20,10 @@ import android.widget.LinearLayout; ...@@ -18,10 +20,10 @@ import android.widget.LinearLayout;
import android.widget.VideoView; import android.widget.VideoView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.widget.imagevideobanner.R; import com.widget.imagebanner.R;
import com.widget.imagevideobanner.bean.BannerBean; import com.widget.imagebanner.bean.BannerBean;
import com.widget.imagevideobanner.utils.BannerLogFileUtils; import com.widget.imagebanner.utils.BannerLogFileUtils;
import com.widget.imagevideobanner.utils.BitmapUtils; import com.widget.imagebanner.utils.BitmapUtils;
import java.io.File; import java.io.File;
...@@ -88,10 +90,10 @@ public class ImageVideoFragment extends Fragment { ...@@ -88,10 +90,10 @@ public class ImageVideoFragment extends Fragment {
view = LayoutInflater.from(getActivity()).inflate(R.layout.item_image_view, container, false); view = LayoutInflater.from(getActivity()).inflate(R.layout.item_image_view, container, false);
ImageView imageView = view.findViewById(R.id.iv); ImageView imageView = view.findViewById(R.id.iv);
File file = new File(bannerBean.getUrl()); File file = new File(bannerBean.getUrl());
if(file.exists()){ if (file.exists()) {
Glide.with(container.getContext()).load(file) Glide.with(container.getContext()).load(file)
.into(imageView); .into(imageView);
}else { } else {
Glide.with(container.getContext()).load(bannerBean.getUrl()) Glide.with(container.getContext()).load(bannerBean.getUrl())
.into(imageView); .into(imageView);
} }
...@@ -116,16 +118,16 @@ public class ImageVideoFragment extends Fragment { ...@@ -116,16 +118,16 @@ public class ImageVideoFragment extends Fragment {
*/ */
public void setPicture() { public void setPicture() {
//视频未加载完成,使用菊花 //视频未加载完成,使用菊花
if(bannerBean.getLoadingImage() == null){ if (bannerBean.getLoadingImage() == null) {
if(bannerBean.getUrl().contains("android.resource")){ if (bannerBean.getUrl().contains("android.resource")) {
ivWaitLoading.setVisibility(View.VISIBLE); ivWaitLoading.setVisibility(View.VISIBLE);
ivWaitLoading.setImageResource(R.drawable.guide_defaut); ivWaitLoading.setImageResource(R.drawable.guide_defaut);
llWaitLoading.setVisibility(View.GONE); llWaitLoading.setVisibility(View.GONE);
}else{ } else {
ivWaitLoading.setVisibility(View.GONE); ivWaitLoading.setVisibility(View.GONE);
llWaitLoading.setVisibility(View.VISIBLE); llWaitLoading.setVisibility(View.VISIBLE);
} }
}else{//加载完成使用首帧图片 } else {//加载完成使用首帧图片
ivWaitLoading.setVisibility(View.VISIBLE); ivWaitLoading.setVisibility(View.VISIBLE);
ivWaitLoading.setImageBitmap(BitmapUtils.getBitmap(bannerBean.getLoadingImage())); ivWaitLoading.setImageBitmap(BitmapUtils.getBitmap(bannerBean.getLoadingImage()));
llWaitLoading.setVisibility(View.GONE); llWaitLoading.setVisibility(View.GONE);
...@@ -142,7 +144,7 @@ public class ImageVideoFragment extends Fragment { ...@@ -142,7 +144,7 @@ public class ImageVideoFragment extends Fragment {
mVideoView.requestFocus(); mVideoView.requestFocus();
try { try {
mVideoView.setVideoURI(Uri.parse(bannerBean.getUrl())); mVideoView.setVideoURI(Uri.parse(bannerBean.getUrl()));
}catch (Exception e){ } catch (Exception e) {
} }
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
...@@ -221,7 +223,7 @@ public class ImageVideoFragment extends Fragment { ...@@ -221,7 +223,7 @@ public class ImageVideoFragment extends Fragment {
public void startPlayer() { public void startPlayer() {
if (null != mVideoView) { if (null != mVideoView) {
// setWaitLoading(); // setWaitLoading();
Log.e(TAG, "startPlayer "+currentPosition); Log.e(TAG, "startPlayer " + currentPosition);
mVideoView.setBackgroundColor(Color.TRANSPARENT); mVideoView.setBackgroundColor(Color.TRANSPARENT);
mVideoView.seekTo(currentPosition); mVideoView.seekTo(currentPosition);
mVideoView.start(); mVideoView.start();
...@@ -265,8 +267,8 @@ public class ImageVideoFragment extends Fragment { ...@@ -265,8 +267,8 @@ public class ImageVideoFragment extends Fragment {
private void pausePlayer() { private void pausePlayer() {
if (null != mVideoView) { if (null != mVideoView) {
Log.e(TAG, "pausePlayer 当前进度是"+mVideoView.getCurrentPosition()); Log.e(TAG, "pausePlayer 当前进度是" + mVideoView.getCurrentPosition());
mVideoView.setBackgroundColor(getResources().getColor(R.color.white)); mVideoView.setBackgroundColor(getResources().getColor(android.R.color.white));
playerPaused = true; playerPaused = true;
this.currentPosition = mVideoView.getCurrentPosition(); this.currentPosition = mVideoView.getCurrentPosition();
mVideoView.pause(); mVideoView.pause();
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<com.widget.imagevideobanner.banner.ViewPager <androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager" android:id="@+id/view_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -14,4 +13,4 @@ ...@@ -14,4 +13,4 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
...@@ -10,4 +10,4 @@ ...@@ -10,4 +10,4 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="fitXY"/> android:scaleType="fitXY"/>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.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">
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
android:gravity="center" android:gravity="center"
android:background="@color/white" android:background="#fff"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
...@@ -57,4 +57,4 @@ ...@@ -57,4 +57,4 @@
</LinearLayout> </LinearLayout>
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
package com.widget.imagebanner;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
# Specifies the JVM arguments used for the daemon process. # Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings. # The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode. # When configured, Gradle will run in incubating parallel mode.
......
...@@ -4,10 +4,10 @@ android { ...@@ -4,10 +4,10 @@ android {
compileSdkVersion 28 compileSdkVersion 28
defaultConfig { defaultConfig {
minSdkVersion 18 minSdkVersion 18
targetSdkVersion 22 targetSdkVersion 28
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
} }
buildTypes { buildTypes {
release { release {
...@@ -19,13 +19,8 @@ android { ...@@ -19,13 +19,8 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0' implementation project(':banner')
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' // compile 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
......
...@@ -3,11 +3,11 @@ package com.widget.imagevideobanner; ...@@ -3,11 +3,11 @@ package com.widget.imagevideobanner;
import android.content.Intent; 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 androidx.appcompat.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import com.widget.imagevideobanner.banner.ImageVideoBanner; import com.widget.imagebanner.ImageVideoBanner;
import com.widget.imagevideobanner.bean.BannerBean; import com.widget.imagebanner.bean.BannerBean;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.widget.imagevideobanner.banner.ImageVideoBanner <com.widget.imagebanner.ImageVideoBanner
android:id="@+id/banner" android:id="@+id/banner"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
app:period="5000" /> app:period="5000" />
</android.support.constraint.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file \ No newline at end of file
include ':banner'
include ':imageVideoBanner' 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