-
Notifications
You must be signed in to change notification settings - Fork 0
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
赵永亮
committed
Jun 27, 2022
1 parent
1c25f22
commit 103e3a4
Showing
49 changed files
with
1,532 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,40 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
compileSdk 32 | ||
|
||
defaultConfig { | ||
applicationId "com.zyl.bubbleview" | ||
minSdk 21 | ||
targetSdk 32 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
//noinspection GradleCompatible | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:2.0.4' | ||
implementation project(':bubblelibrary') | ||
} |
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 |
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.zyl.bubbleview"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.BubbleView" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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,151 @@ | ||
package com.zyl.bubbleview | ||
|
||
import android.graphics.BitmapFactory | ||
import android.graphics.PixelFormat | ||
import android.opengl.GLES20 | ||
import android.opengl.GLSurfaceView | ||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.util.Log | ||
import android.view.MotionEvent | ||
import android.widget.Toast | ||
import com.zyl.bubblelibrary.BodyBitmapInfo | ||
import com.zyl.bubblelibrary.BubbleGLSurfaceView | ||
import com.zyl.bubblelibrary.BubbleGame | ||
import java.util.* | ||
import javax.microedition.khronos.egl.EGLConfig | ||
import javax.microedition.khronos.opengles.GL10 | ||
|
||
/** | ||
* Author: zhaoyl | ||
* Date: 2022/06/27 15:53 | ||
* remark:我只做了小球从小变大的动画,大变小没写,也可以自定义一个view 去实现这些方法 调用更简单 | ||
* | ||
**/ | ||
class MainActivity : AppCompatActivity(), GLSurfaceView.Renderer { | ||
private var mAccumulator = 0.0f | ||
private var mLastTicks: Long = -1 | ||
lateinit var bubbleGLSurfaceView: BubbleGLSurfaceView | ||
private var mBubbleGame: BubbleGame? = null | ||
private val ballSize = 7 | ||
private val mImageReSmallId = mutableListOf<BodyBitmapInfo>() | ||
private val mImageReBigId = mutableListOf<BodyBitmapInfo>() | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
bubbleGLSurfaceView = findViewById(R.id.bubbleGLSurfaceView) | ||
|
||
// Read in the resource | ||
for (i in 0 until ballSize) { | ||
val smallBit = BitmapFactory.decodeResource(resources, R.mipmap.ball_small) | ||
mImageReSmallId.add(BodyBitmapInfo(i, i, "我是+$i", smallBit)) | ||
val bigBit = BitmapFactory.decodeResource(resources, R.mipmap.ball_big) | ||
mImageReBigId.add(BodyBitmapInfo(i, i, "我是+$i", bigBit)) | ||
} | ||
initBubble() | ||
} | ||
|
||
|
||
override fun onSurfaceCreated(p0: GL10?, p1: EGLConfig?) { | ||
try { | ||
Log.e("http", "------>onSurfaceCreated"); | ||
if (mImageReSmallId.isNotEmpty() && mImageReBigId.isNotEmpty()) { | ||
mBubbleGame?.bubbleInit(mImageReSmallId, mImageReBigId) | ||
} | ||
//创建的时候设置背景色 | ||
GLES20.glClearColor(235f / 255.0f, 235f / 255.0f, 255f / 255.0f, 255f / 255.0f) | ||
// GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) { | ||
try { | ||
Log.e("http", "------>onSurfaceChanged"); | ||
gl?.glViewport(0, 0, width, height) | ||
if (mBubbleGame?.virtualHeight == 0f) mBubbleGame?.setSize(width, height) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
override fun onDrawFrame(p0: GL10?) { | ||
try { | ||
if (mLastTicks == -1L) mLastTicks = Calendar.getInstance().time.time | ||
val min_timestep = 1.0f / 100.0f | ||
val nowticks = Calendar.getInstance().time.time | ||
mAccumulator += (nowticks - mLastTicks).toFloat() / 1000.0f | ||
mLastTicks = nowticks | ||
while (mAccumulator > min_timestep) { | ||
mBubbleGame?.upDate(min_timestep) | ||
mAccumulator -= min_timestep | ||
} | ||
mBubbleGame?.draw() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
private fun initBubble() { | ||
try { | ||
bubbleGLSurfaceView.run { | ||
setEGLConfigChooser(8, 8, 8, 8, 16, 0) | ||
setEGLContextClientVersion(2) | ||
holder.setFormat(PixelFormat.TRANSLUCENT) | ||
setZOrderOnTop(true) | ||
setRenderer(this@MainActivity) | ||
renderMode = GLSurfaceView.RENDERMODE_CONTINUOUSLY | ||
setOnTouch(object : BubbleGLSurfaceView.OnTouch { | ||
override fun onTouchChild(event: MotionEvent) { | ||
try { | ||
mBubbleGame?.onTouchEvent(event) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
}) | ||
|
||
mBubbleGame = BubbleGame(this@MainActivity).apply { | ||
applyType = 0 | ||
bigWhPx = 184.0f | ||
smallWhPx = 114.0f | ||
maxBallRadius = 2.0499995f | ||
smallChangeBigValue = 2f | ||
setOnChildClick(object : BubbleGame.OnChildClick { | ||
|
||
override fun onChildClick(id: Int) { | ||
Toast.makeText(this@MainActivity, "第${id}个", Toast.LENGTH_SHORT).show() | ||
//选中的id | ||
// binding.kkFriendNotesSelectorTag.text = mImageReSmallId[id].notesExplain | ||
} | ||
|
||
}) | ||
} | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
mBubbleGame?.let { | ||
bubbleGLSurfaceView.onResume() | ||
} | ||
// binding.kkFriendNotesTopVideo.onResume() | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
mBubbleGame?.let { | ||
bubbleGLSurfaceView.onPause() | ||
} | ||
// binding.kkFriendNotesTopVideo.onPause() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
mBubbleGame?.destroy() | ||
} | ||
} |
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,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.