-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hamlingong
committed
Sep 22, 2020
1 parent
c7b2f0c
commit dbd0b10
Showing
39 changed files
with
659 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.tencent.libpag.sample.libpag_sample" | ||
minSdkVersion 19 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
lintOptions { | ||
abortOnError false | ||
} | ||
|
||
repositories { | ||
flatDir { | ||
dirs 'libs' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation(name: 'libpag_release_3.2.5.1', ext: 'aar') | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# 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 |
26 changes: 26 additions & 0 deletions
26
...src/androidTest/java/com/tencent/libpag/sample/libpag_sample/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.tencent.libpag.sample.libpag_sample; | ||
|
||
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() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.tencent.libpag.sample.libpag_sample", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.tencent.libpag.sample.libpag_sample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
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> | ||
</application> | ||
|
||
</manifest> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
40 changes: 40 additions & 0 deletions
40
sample/app/src/main/java/com/tencent/libpag/sample/libpag_sample/BackgroundView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.tencent.libpag.sample.libpag_sample; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
public class BackgroundView extends View { | ||
public BackgroundView(Context context) { | ||
super(context); | ||
} | ||
|
||
public BackgroundView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
protected void onDraw(Canvas canvas) { | ||
super.onDraw(canvas); | ||
canvas.drawColor(Color.WHITE); | ||
int width = getWidth(); | ||
int height = getHeight(); | ||
int tileSize = (int)(8 * getContext().getResources().getDisplayMetrics().density); | ||
Path path = new Path(); | ||
for (int y = 0; y < height; y += tileSize) { | ||
boolean draw = (y / tileSize) % 2 == 1; | ||
for (int x = 0; x < width; x += tileSize) { | ||
if (draw) { | ||
path.addRect(x, y, x + tileSize, y + tileSize, Path.Direction.CCW); | ||
} | ||
draw = !draw; | ||
} | ||
} | ||
Paint paint = new Paint(); | ||
paint.setColor(Color.argb(255, 204, 204, 204)); | ||
canvas.drawPath(path, paint); | ||
} | ||
} |
149 changes: 149 additions & 0 deletions
149
sample/app/src/main/java/com/tencent/libpag/sample/libpag_sample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package com.tencent.libpag.sample.libpag_sample; | ||
|
||
import android.content.res.AssetManager; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.opengl.EGL14; | ||
import android.opengl.EGLConfig; | ||
import android.opengl.EGLContext; | ||
import android.opengl.EGLDisplay; | ||
import android.opengl.EGLSurface; | ||
import android.opengl.GLES20; | ||
import android.opengl.GLUtils; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.ViewGroup; | ||
import android.view.WindowManager; | ||
import android.widget.RelativeLayout; | ||
|
||
import org.libpag.PAGFile; | ||
import org.libpag.PAGImage; | ||
import org.libpag.PAGText; | ||
import org.libpag.PAGView; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private EGLDisplay eglDisplay; | ||
private EGLSurface eglSurface; | ||
private EGLContext eglContext; | ||
|
||
private synchronized void eglSetup() { | ||
eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); | ||
int[] version = new int[2]; | ||
EGL14.eglInitialize(eglDisplay, version, 0, version, 1); | ||
EGL14.eglBindAPI(EGL14.EGL_OPENGL_ES_API); | ||
int[] attributeList = { | ||
EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, | ||
EGL14.EGL_RED_SIZE, 8, | ||
EGL14.EGL_GREEN_SIZE, 8, | ||
EGL14.EGL_BLUE_SIZE, 8, | ||
EGL14.EGL_ALPHA_SIZE, 8, | ||
EGL14.EGL_STENCIL_SIZE, 8, | ||
EGL14.EGL_SAMPLE_BUFFERS, 1, | ||
EGL14.EGL_SAMPLES, 4, | ||
EGL14.EGL_NONE | ||
}; | ||
EGLConfig[] configs = new EGLConfig[1]; | ||
int[] numConfigs = new int[1]; | ||
EGL14.eglChooseConfig(eglDisplay, attributeList, 0, configs, 0, | ||
configs.length, numConfigs, 0); | ||
|
||
int[] attribute_list = { | ||
EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, | ||
EGL14.EGL_NONE | ||
}; | ||
|
||
eglContext = EGL14.eglCreateContext(eglDisplay, configs[0], EGL14.EGL_NO_CONTEXT, | ||
attribute_list, 0); | ||
|
||
int[] surfaceAttributes = { | ||
EGL14.EGL_WIDTH, 1, | ||
EGL14.EGL_HEIGHT, 1, | ||
EGL14.EGL_NONE | ||
}; | ||
eglSurface = EGL14.eglCreatePbufferSurface(eglDisplay, configs[0], surfaceAttributes, 0); | ||
EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); | ||
} | ||
|
||
private PAGImage createPAGImage() { | ||
// eglSetup(); | ||
|
||
AssetManager assetManager = getAssets(); | ||
InputStream stream = null; | ||
try { | ||
stream = assetManager.open("test.png"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
Bitmap bitmap = BitmapFactory.decodeStream(stream); | ||
if (bitmap == null) { | ||
return null; | ||
} | ||
|
||
return PAGImage.FromBitmap(bitmap); | ||
|
||
// int[] textures = new int[1]; | ||
// GLES20.glGenTextures(1, textures, 0); | ||
// int textureID = textures[0]; | ||
// GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID); | ||
// GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, | ||
// GLES20.GL_LINEAR); | ||
// GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, | ||
// GLES20.GL_LINEAR); | ||
// GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, | ||
// GLES20.GL_CLAMP_TO_EDGE); | ||
// GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, | ||
// GLES20.GL_CLAMP_TO_EDGE); | ||
// GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, bitmap.getWidth(), | ||
// bitmap.getHeight(), 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, null); | ||
// GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); | ||
// | ||
// return PAGImage.FromTexture(textureID, GLES20.GL_TEXTURE_2D, | ||
// bitmap.getWidth(), bitmap.getHeight()); | ||
} | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
setContentView(R.layout.activity_main); | ||
|
||
RelativeLayout backgroundView = findViewById(R.id.background_view); | ||
final PAGView pagView = new PAGView(this, eglContext); | ||
pagView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); | ||
backgroundView.addView(pagView); | ||
PAGFile pagFile = PAGFile.Load(getAssets(), "replacement.pag"); | ||
|
||
testReplaceImage(pagFile, pagView); | ||
|
||
testEditText(pagFile, pagView); | ||
|
||
pagView.setRepeatCount(-1); | ||
pagView.setFile(pagFile); | ||
pagView.play(); | ||
} | ||
|
||
/** | ||
* Test replace image. | ||
*/ | ||
void testReplaceImage(PAGFile pagFile, PAGView pagView) { | ||
if (pagFile == null || pagView == null || pagFile.numImages() <= 0) return; | ||
pagView.replaceImage(0, createPAGImage()); | ||
} | ||
|
||
/** | ||
* | ||
* Test edit text. | ||
*/ | ||
void testEditText(PAGFile pagFile, PAGView pagView) { | ||
if (pagFile == null || pagView == null || pagFile.numTexts() <= 0) return; | ||
PAGText textData = pagFile.getTextData(0); | ||
textData.text = "haha哈哈大😆"; | ||
textData.fontSize = 13; | ||
pagView.setTextData(0, textData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?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=".MainActivity"> | ||
<RelativeLayout | ||
android:id="@+id/background_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<com.tencent.libpag.sample.libpag_sample.BackgroundView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</RelativeLayout> | ||
|
||
|
||
</android.support.constraint.ConstraintLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#008577</color> | ||
<color name="colorPrimaryDark">#00574B</color> | ||
<color name="colorAccent">#D81B60</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">libpag-sample</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
17 changes: 17 additions & 0 deletions
17
sample/app/src/test/java/com/tencent/libpag/sample/libpag_sample/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tencent.libpag.sample.libpag_sample; | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
|
||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.2.1' | ||
|
||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
google() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
Oops, something went wrong.