Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

修改线程池 #213

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
264 changes: 150 additions & 114 deletions app/src/main/java/com/example/ponycui_home/svgaplayer/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.example.ponycui_home.svgaplayer;

import android.app.Activity;
import android.content.Intent;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
Expand All @@ -15,146 +13,184 @@
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.util.Log;

import com.opensource.svgaplayer.SVGACallback;
import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGADynamicEntity;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAPlayer;
import com.opensource.svgaplayer.SVGAVideoEntity;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

class SampleItem {

String title;
Intent intent;

public SampleItem(String title, Intent intent) {
this.title = title;
this.intent = intent;
}

}
/**
* Created by cuiminghui on 2017/3/30.
* 这是最复杂的一个 Sample, 演示了从网络加载动画,并播放动画。
* 更多的 Sample 可以在这里找到 https://github.com/yyued/SVGA-Samples
*/

public class MainActivity extends AppCompatActivity {

ListView listView;
ArrayList<SampleItem> items = new ArrayList();
SVGAImageView testView = null;
SVGADynamicEntity dynamicItem = new SVGADynamicEntity();

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
// .detectDiskReads()
// .detectDiskWrites()
// .penaltyDialog()
// .detectAll()
// .penaltyLog()
// .build());
// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
// .detectLeakedSqlLiteObjects()
// .detectLeakedClosableObjects()
// .penaltyLog()
// .penaltyDeath()
// .build());
super.onCreate(savedInstanceState);
this.setupData();
this.setupListView();
setContentView(listView);
testView = new SVGAImageView(this);
testView.setBackgroundColor(Color.GRAY);
loadAnimation();
setContentView(testView);
}

void setupData() {
this.items.add(new SampleItem("Animation From Assets", new Intent(this, AnimationFromAssetsActivity.class)));
this.items.add(new SampleItem("Animation From Network", new Intent(this, AnimationFromNetworkActivity.class)));
this.items.add(new SampleItem("Animation From Layout XML", new Intent(this, AnimationFromLayoutActivity.class)));
this.items.add(new SampleItem("Animation With Dynamic Image", new Intent(this, AnimationWithDynamicImageActivity.class)));
this.items.add(new SampleItem("Animation With Dynamic Click", new Intent(this, AnimationFromClickActivity.class)));
private void loadAnimation() {
SVGAParser parser = new SVGAParser(this);
// resetDownloader(parser);
try {
parser.parse(
new URL("https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true"),
new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@NotNull SVGAVideoEntity videoItem) {
SVGADrawable drawable = new SVGADrawable(videoItem,
requestDynamicItemWithSpannableText());
testView.setImageDrawable(drawable);
testView.setDrawingCacheEnabled(true);
testView.setLoops(1);
testView.startAnimation();
testView.setCallback(new SVGACallback() {
@Override
public void onPause() {

}

@Override
public void onFinished() {

}

@Override
public void onRepeat() {

}

@Override
public void onStep(int frame, double percentage) {
if (percentage == 1.0) {
Bitmap bitmap =
Bitmap.createBitmap(testView.getDrawingCache());
Log.d("GYF", bitmap.toString());
}
}
});
}

@Override
public void onError() {

}
});
} catch (Exception e) {
System.out.print(true);
}
}

void setupListView() {
this.listView = new ListView(this);
this.listView.setAdapter(new ListAdapter() {
@Override
public boolean areAllItemsEnabled() {
return false;
}

@Override
public boolean isEnabled(int i) {
return false;
}

@Override
public void registerDataSetObserver(DataSetObserver dataSetObserver) {

}

@Override
public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {

}

@Override
public int getCount() {
return MainActivity.this.items.size();
}

@Override
public Object getItem(int i) {
return null;
}

@Override
public long getItemId(int i) {
return i;
}

@Override
public boolean hasStableIds() {
return false;
}

@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
LinearLayout linearLayout = new LinearLayout(MainActivity.this);
TextView textView = new TextView(MainActivity.this);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity.this.startActivity(MainActivity.this.items.get(i).intent);
}
});
textView.setText(MainActivity.this.items.get(i).title);
textView.setTextSize(24);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
linearLayout.addView(textView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (55 * getResources().getDisplayMetrics().density)));
return linearLayout;
}

@Override
public int getItemViewType(int i) {
return 1;
}

@Override
public int getViewTypeCount() {
return 1;
}
/**
* 进行简单的文本替换
*
* @return
*/
private SVGADynamicEntity requestDynamicItem() {
SVGADynamicEntity dynamicEntity = new SVGADynamicEntity();
TextPaint textPaint = new TextPaint();
textPaint.setColor(Color.WHITE);
textPaint.setTextSize(28);
dynamicEntity.setDynamicText("Pony 送了一打风油精给主播", textPaint, "banner");
return dynamicEntity;
}

/**
* 你可以设置富文本到 ImageKey 相关的元素上
* 富文本是会自动换行的,不要设置过长的文本
*
* @return
*/
private SVGADynamicEntity requestDynamicItemWithSpannableText() {
SVGADynamicEntity dynamicEntity = new SVGADynamicEntity();
SpannableStringBuilder spannableStringBuilder =
new SpannableStringBuilder("Pony 送了一打风油精给主播");
spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, 4,
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
TextPaint textPaint = new TextPaint();
textPaint.setColor(Color.WHITE);
textPaint.setTextSize(28);
dynamicEntity.setDynamicText(new StaticLayout(
spannableStringBuilder,
0,
spannableStringBuilder.length(),
textPaint,
0,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false
), "banner");
dynamicEntity.setDynamicDrawer(new Function2<Canvas, Integer, Boolean>() {
@Override
public boolean isEmpty() {
public Boolean invoke(Canvas canvas, Integer frameIndex) {
Paint aPaint = new Paint();
aPaint.setColor(Color.WHITE);
canvas.drawCircle(50, 54, frameIndex % 5, aPaint);
return false;
}
});
this.listView.setBackgroundColor(Color.WHITE);
}, "banner");
return dynamicEntity;
}

/**
* 设置下载器,这是一个可选的配置项。
*
* @param parser
*/
// private void resetDownloader(SVGAParser parser) {
// parser.setFileDownloader(new SVGAParser.FileDownloader() {
// @Override
// public void resume(final URL url, final Function1<? super InputStream, Unit> complete,
// final Function1<? super Exception, Unit> failure) {
// new Thread(new Runnable() {
// @Override
// public void run() {
// OkHttpClient client = new OkHttpClient();
// Request request = new Request.Builder().url(url).get().build();
// try {
// Response response = client.newCall(request).execute();
// complete.invoke(response.body().byteStream());
// } catch (IOException e) {
// e.printStackTrace();
// failure.invoke(e);
// }
// }
// }).start();
// }
// });
// }

}
5 changes: 3 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ android {
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.squareup.wire:wire-runtime:2.3.0-RC1'
compileOnly fileTree(include: ['*.jar'], dir: 'libs')
// implementation 'com.squareup.wire:wire-runtime:2.3.0-RC1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.okio:okio:2.4.2'
}
repositories {
mavenCentral()
Expand Down
Binary file added library/libs/wire-runtime-jvm-3.0.0-alpha02.jar
Binary file not shown.
Loading