Skip to content

Commit

Permalink
update fresco to 1.5.0 and build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
yrom committed Nov 13, 2017
1 parent 764a87e commit 7126d19
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android:
- extra-android-m2repository

script:
- ./gradlew clean check -Dpre-dex=false
- ./gradlew clean :draweetext:check --no-daemon --stacktrace

notifications:
email: false
Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:3.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
Expand All @@ -24,6 +26,6 @@ task clean(type: Delete) {
}

ext {
frescoVersion = '1.0'
supportLibraryVersion = '25.0.1'
frescoVersion = '1.5.0'
supportLibraryVersion = '26.0.2'
}
19 changes: 8 additions & 11 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "com.bilibili.draweetext.demo"
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// avoid warning for "Not all execution paths return a value"
return true
}

dependencies {
compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibraryVersion}"
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibraryVersion}"
compile project(':draweetext')
compile "com.facebook.fresco:webpsupport:${rootProject.ext.frescoVersion}"
compile "com.facebook.fresco:animated-gif:${rootProject.ext.frescoVersion}" /*add gif decoding support*/
implementation "com.android.support:recyclerview-v7:${rootProject.ext.supportLibraryVersion}"
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibraryVersion}"
implementation project(':draweetext')
implementation "com.facebook.fresco:webpsupport:${rootProject.ext.frescoVersion}"
implementation "com.facebook.fresco:animated-gif:${rootProject.ext.frescoVersion}" /*add gif decoding support*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
ViewPager pager = (ViewPager) findViewById(R.id.container);
ViewPager pager = findViewById(R.id.container);
pager.setAdapter(new SectionsAdapter(getSupportFragmentManager()));
}


private class SectionsAdapter extends FragmentPagerAdapter {

public SectionsAdapter(FragmentManager fm) {
SectionsAdapter(FragmentManager fm) {
super(fm);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final TextView textview = (TextView) view.findViewById(R.id.text1);
final TextView textview = view.findViewById(R.id.text1);
textview.setMovementMethod(ScrollingMovementMethod.getInstance());
textview.setText(buildText());
view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -310,7 +310,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler);
RecyclerView recyclerView = view.findViewById(R.id.recycler);
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
recyclerView.setHasFixedSize(true);

Expand Down Expand Up @@ -355,7 +355,7 @@ public int getItemCount() {
static class TextViewHolder extends RecyclerView.ViewHolder {
TextView text;

public TextViewHolder(View itemView) {
TextViewHolder(View itemView) {
super(itemView);
text = (TextView) itemView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.Log;

import com.facebook.common.logging.FLog;
import com.facebook.common.logging.FLogDefaultLoggingDelegate;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipelineConfig;

Expand All @@ -21,6 +22,7 @@ public void onCreate() {
.build());
// for debug
if (BuildConfig.DEBUG) {
FLogDefaultLoggingDelegate.getInstance().setApplicationTag("Drawee-text");
FLog.setMinimumLoggingLevel(Log.VERBOSE);
}
}
Expand Down
28 changes: 13 additions & 15 deletions draweetext/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Expand All @@ -16,19 +16,17 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// avoid warning for "Not all execution paths return a value"
return true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile('org.robolectric:robolectric:3.0') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile "com.android.support:support-core-utils:${rootProject.ext.supportLibraryVersion}"
compile "com.facebook.fresco:fresco:${rootProject.ext.frescoVersion}" /*required*/
compile "com.facebook.fresco:animated-base:${rootProject.ext.frescoVersion}" /*required*/
provided "com.facebook.fresco:animated-gif:${rootProject.ext.frescoVersion}"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.8.47'
testImplementation 'org.robolectric:robolectric:3.4.2'
api "com.android.support:support-core-utils:${rootProject.ext.supportLibraryVersion}"
api "com.facebook.fresco:fresco:${rootProject.ext.frescoVersion}" /*required*/
api "com.facebook.fresco:animated-base:${rootProject.ext.frescoVersion}" /*required*/
}

This file was deleted.

33 changes: 13 additions & 20 deletions draweetext/src/main/java/com/bilibili/draweetext/DraweeSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
Expand All @@ -43,13 +44,10 @@
import com.facebook.drawee.components.DeferredReleaser;
import com.facebook.drawee.drawable.ForwardingDrawable;
import com.facebook.drawee.drawable.OrientedDrawable;
import com.facebook.imagepipeline.animated.base.AbstractAnimatedDrawable;
import com.facebook.imagepipeline.animated.base.AnimatableDrawable;
import com.facebook.imagepipeline.animated.base.AnimatedDrawable;
import com.facebook.imagepipeline.animated.base.AnimatedImageResult;
import com.facebook.imagepipeline.animated.factory.AnimatedFactory;
import com.facebook.imagepipeline.common.ImageDecodeOptions;
import com.facebook.imagepipeline.core.ImagePipelineFactory;
import com.facebook.imagepipeline.drawable.DrawableFactory;
import com.facebook.imagepipeline.image.CloseableAnimatedImage;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.image.CloseableStaticBitmap;
Expand Down Expand Up @@ -128,8 +126,8 @@ public void setImage(Drawable drawable) {
if (mDrawable != drawable) {
releaseDrawable(mDrawable);
setDrawableInner(drawable);
if (drawable instanceof AnimatedDrawable) {
((AnimatableDrawable) drawable).start();
if (drawable instanceof Animatable) {
((Animatable) drawable).start();
}
mDrawable = drawable;
}
Expand Down Expand Up @@ -160,8 +158,8 @@ public void onAttach(@NonNull DraweeTextView view) {
mDeferredReleaser.cancelDeferredRelease(this);
if (!mIsRequestSubmitted) {
submitRequest();
} else if (mShouldShowAnim && mDrawable instanceof AnimatableDrawable) {
((AnimatableDrawable) mDrawable).start();
} else if (mShouldShowAnim && mDrawable instanceof Animatable) {
((Animatable) mDrawable).start();
}
}

Expand Down Expand Up @@ -287,14 +285,9 @@ private Drawable createDrawable(CloseableReference<CloseableImage> result) {
? new OrientedDrawable(bitmapDrawable, closeableStaticBitmap.getRotationAngle()) : bitmapDrawable);
} else if (closeableImage instanceof CloseableAnimatedImage) {
if (mShouldShowAnim) {
AnimatedFactory afactory = ImagePipelineFactory.getInstance().getAnimatedFactory();
if (afactory != null) {
Drawable drawable = afactory.getAnimatedDrawableFactory(mAttachedView.getContext())
.create(closeableImage);
if (drawable instanceof AbstractAnimatedDrawable) {
((AbstractAnimatedDrawable) drawable).setLogId(getId());
}
return drawable;
DrawableFactory factory = ImagePipelineFactory.getInstance().getAnimatedDrawableFactory(mAttachedView.getContext());
if (factory != null) {
return factory.createDrawable(closeableImage);
}
}
AnimatedImageResult image = ((CloseableAnimatedImage) closeableImage).getImageResult();
Expand Down Expand Up @@ -329,8 +322,8 @@ protected BitmapDrawable createBitmapDrawable(Bitmap bitmap) {
public void onDetach() {
if (!mIsAttached)
return;
if (mShouldShowAnim && mDrawable instanceof AnimatableDrawable) {
((AnimatableDrawable) mDrawable).stop();
if (mShouldShowAnim && mDrawable instanceof Animatable) {
((Animatable) mDrawable).stop();
}
mActualDrawable.setCallback(null);
mAttachedView = null;
Expand Down Expand Up @@ -358,8 +351,8 @@ public void release() {
}

void releaseDrawable(@Nullable Drawable drawable) {
if (drawable instanceof AnimatableDrawable && ((AnimatableDrawable) drawable).isRunning()) {
((AnimatableDrawable) drawable).stop();
if (drawable instanceof Animatable && ((Animatable) drawable).isRunning()) {
((Animatable) drawable).stop();
}
if (drawable instanceof DrawableWithCaches) {
((DrawableWithCaches) drawable).dropCaches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Spanned;
import android.util.AttributeSet;
import android.widget.TextView;

import com.facebook.drawee.drawable.ForwardingDrawable;
import com.facebook.imagepipeline.animated.base.AnimatableDrawable;

/**
* Like {@link com.facebook.drawee.view.DraweeView} that displays drawables {@link DraweeSpan} but surrounded with text.
Expand Down Expand Up @@ -112,7 +112,7 @@ public void invalidateDrawable(Drawable dr) {
protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || mHasDraweeInText
// only schedule animation on AnimatableDrawable
&& (who instanceof ForwardingDrawable && who.getCurrent() instanceof AnimatableDrawable);
&& (who instanceof ForwardingDrawable && who.getCurrent() instanceof Animatable);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author yrom.
*/
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 21, manifest = Config.NONE)
@Config(manifest = Config.NONE)
public class DraweeSpanTest {
@Test
public void testBuild() {
Expand All @@ -52,6 +52,7 @@ public void testBuild() {
@Test
public void testLifeCycle(){
Activity activity = Robolectric.buildActivity(Activity.class).create().get();
@SuppressWarnings("unchecked")
ResourceReleaser<Bitmap> releaser = mock(ResourceReleaser.class);
Bitmap bitmap = ShadowBitmap.createBitmap(1,1, Bitmap.Config.ARGB_8888);
CloseableImage image = Mockito.spy(new CloseableStaticBitmap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @author yrom.
*/
@RunWith(RobolectricTestRunner.class)
@Config(sdk = 21, manifest = Config.NONE)
@Config(manifest = Config.NONE)
public class DraweeTextViewTest {

private DraweeTextView mText;
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 31 22:09:54 CST 2016
#Mon Nov 13 11:19:21 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit 7126d19

Please sign in to comment.