Skip to content

Commit 651e24a

Browse files
author
Otang45
committed
add README.md
1 parent 2f4efe5 commit 651e24a

File tree

5 files changed

+111
-49
lines changed

5 files changed

+111
-49
lines changed

README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# About
2+
Pulse is custom Audio Visualizer for android, ported from [Derpfest-AOSP](https://github.com/DerpFest-AOSP) rom.
3+
4+
# Usage
5+
> AndroidManifest.xml
6+
```xml
7+
<!-- For using audioSessionId = 0 -->
8+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
9+
<!-- Recuired Permission -->
10+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
11+
```
12+
> xml layout
13+
```xml
14+
<otang.pulse.lib.VisualizerView
15+
android:id="@+id/visualizer_view"
16+
android:layout_width="match_parent"
17+
android:layout_height="match_parent" />
18+
```
19+
> Set audio session id
20+
```kt
21+
binding.visualizerView.setAudioSessionId(audioSessionId)
22+
```
23+
24+
# Configuration
25+
### Manual
26+
> Using PulseConfig
27+
```kt
28+
// Initialize PulseConfig
29+
var config = PulseConfig(this)
30+
31+
config.isCenterMirror // Boolean def = false
32+
config.isPulseEnabled // Boolean def = true
33+
config.isLeftInLandscape // Boolean def = false
34+
config.isSolidRounded // Boolean def = true
35+
config.isSmoothEnabled // Boolean def = true
36+
config.isVerticalMirror // Boolean def = false
37+
config.pulseColor // Int def = 0 (0 = Primary, 1 = Custom, 2 = LavaLamp)
38+
config.solidLineCount // Int def = 32
39+
config.fadingDim // Int def = 14
40+
config.fadingDiv // Int def = 16
41+
config.emptySize // Int def = 1
42+
config.fadingFudge // Int def = 5
43+
config.solidFudge // Int def = 5
44+
config.gravity // Int def = 0 (0 = Bottom, 1 = Top, 2 = Center)
45+
config.lavaSpeed // Int def = 10000
46+
config.solidOvacity // Int def = 200
47+
config.renderStyle // Int def = 1 (0 = Legacy, 1 = Solid)
48+
config.fillSize // Int def = 4
49+
config.customColor // ColorInt def = -0x6d000001
50+
```
51+
52+
### Using Preference
53+
> Use this key for preference
54+
```xml
55+
android:key="pref_pulse"
56+
android:key="pref_pulse_left"
57+
android:key="pref_pulse_render"
58+
android:key="pref_pulse_gravity"
59+
android:key="pref_pulse_center_mirrored"
60+
android:key="pref_pulse_vertical_mirror"
61+
android:key="pref_pulse_smooth"
62+
android:key="pref_pulse_color"
63+
android:key="pref_pulse_color_custom"
64+
android:key="pref_pulse_lava_speed"
65+
android:key="pref_pulse_fading_dimen"
66+
android:key="pref_pulse_fading_div"
67+
android:key="pref_pulse_fill_size"
68+
android:key="pref_pulse_empty_size"
69+
android:key="pref_pulse_fading_fudge"
70+
android:key="pref_pulse_rounded"
71+
android:key="pref_pulse_solid_ovacity"
72+
android:key="pref_pulse_line_count"
73+
android:key="pref_pulse_solid_fudge"
74+
```
75+

lib/src/main/java/otang/pulse/lib/ColorController.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ class ColorController(private val mContext: Context) : ColorAnimationListener,
6868
}
6969

7070
override fun onSharedPreferenceChanged(prefs: SharedPreferences, keys: String?) {
71-
updateSettings()
71+
if (keys == PulseConfig.PREF_PULSE_COLOR || keys == PulseConfig.PREF_PULSE_COLOR_CUSTOM || keys == PulseConfig.PREF_PULSE_LAVA_SPEED) {
72+
updateSettings()
73+
}
7274
}
7375

7476
companion object {

lib/src/main/java/otang/pulse/lib/FadingBlockRenderer.kt

+10-15
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import android.graphics.Paint
1313
import android.graphics.PorterDuff
1414
import android.graphics.PorterDuffXfermode
1515
import android.util.TypedValue
16+
import otang.pulse.lib.util.PulseConfig
1617
import kotlin.math.log10
1718
import kotlin.math.max
1819
import kotlin.math.min
1920

2021
class FadingBlockRenderer(
21-
context: Context,
22-
view: VisualizerView,
23-
colorController: ColorController
22+
context: Context, view: VisualizerView, colorController: ColorController
2423
) : Renderer(context, view, colorController), OnSharedPreferenceChangeListener {
2524
private val mPaint: Paint
2625
private val mFadePaint: Paint
@@ -114,8 +113,7 @@ class FadingBlockRenderer(
114113
}
115114
}
116115
mFFTPoints!![i * 4] = (if (mLeftInLandscape) 0 else startPoint) as Float
117-
mFFTPoints!![i * 4 + 2] =
118-
if (mLeftInLandscape) (dbValue * fudgeFactor + DBFUZZ).toFloat() else startPoint - (dbValue * fudgeFactor + DBFUZZ)
116+
mFFTPoints!![i * 4 + 2] = startPoint - (dbValue * fudgeFactor + DBFUZZ)
119117
} else {
120118
var startPoint = mHeight.toFloat()
121119
when (mGravity) {
@@ -149,8 +147,7 @@ class FadingBlockRenderer(
149147
rfk = bytes[mDivisions * j]
150148
ifk = bytes[mDivisions * j + 1]
151149
magnitude = (rfk * rfk + ifk * ifk).toFloat()
152-
dbValue =
153-
if (magnitude > 0) (10 * log10(magnitude.toDouble())).toInt() else 0
150+
dbValue = if (magnitude > 0) (10 * log10(magnitude.toDouble())).toInt() else 0
154151
if (mSmoothingEnabled) {
155152
dbValue = mFFTAverage!![i]!!.average(dbValue)
156153
}
@@ -170,8 +167,7 @@ class FadingBlockRenderer(
170167
}
171168
}
172169
mFFTPoints!![i * 4] = (if (mLeftInLandscape) 0 else startPoint) as Float
173-
mFFTPoints!![i * 4 + 2] =
174-
if (mLeftInLandscape) (dbValue * fudgeFactor + DBFUZZ).toFloat() else startPoint - (dbValue * fudgeFactor + DBFUZZ)
170+
mFFTPoints!![i * 4 + 2] = startPoint - (dbValue * fudgeFactor + DBFUZZ)
175171
} else {
176172
var startPoint = mHeight.toFloat()
177173
when (mGravity) {
@@ -270,8 +266,7 @@ class FadingBlockRenderer(
270266
mLeftInLandscape = mPref.isLeftInLandscape
271267
mPaint.pathEffect =
272268
DashPathEffect(floatArrayOf(mPathEffect1.toFloat(), mPathEffect2.toFloat()), 0f)
273-
mPaint.strokeWidth =
274-
getLimitedDimenValue(customDimen, 1, 30, res).toFloat()
269+
mPaint.strokeWidth = getLimitedDimenValue(customDimen, 1, 30, res).toFloat()
275270
mDivisions = validateDivision(numDivision)
276271
mDbFuzzFactor = max(2, min(6, fudgeFactor))
277272
mSmoothingEnabled = mPref.isSmoothEnabled
@@ -282,7 +277,9 @@ class FadingBlockRenderer(
282277
}
283278

284279
override fun onSharedPreferenceChanged(prefs: SharedPreferences, keys: String?) {
285-
updateSettings()
280+
if (keys == PulseConfig.PREF_PULSE_LEFT || keys == PulseConfig.PREF_PULSE_GRAVITY || keys == PulseConfig.PREF_PULSE_CENTER_MIRRORED || keys == PulseConfig.PREF_PULSE_EMPTY_SIZE || keys == PulseConfig.PREF_PULSE_FADING_DIMEN || keys == PulseConfig.PREF_PULSE_FADING_DIV || keys == PulseConfig.PREF_PULSE_FADING_FUDGE || keys == PulseConfig.PREF_PULSE_SMOOTH || keys == PulseConfig.PREF_PULSE_VERTICAL_MIRROR || keys == PulseConfig.PREF_PULSE_FILL_SIZE) {
281+
updateSettings()
282+
}
286283
}
287284

288285
companion object {
@@ -292,9 +289,7 @@ class FadingBlockRenderer(
292289
private const val GRAVITY_CENTER = 2
293290
private fun getLimitedDimenValue(`val`: Int, min: Int, max: Int, res: Resources): Int {
294291
return TypedValue.applyDimension(
295-
TypedValue.COMPLEX_UNIT_DIP,
296-
max(min, min(max, `val`)).toFloat(),
297-
res.displayMetrics
292+
TypedValue.COMPLEX_UNIT_DIP, max(min, min(max, `val`)).toFloat(), res.displayMetrics
298293
).toInt()
299294
}
300295

lib/src/main/java/otang/pulse/lib/SolidLineRenderer.kt

+19-28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.graphics.Canvas
99
import android.graphics.Color
1010
import android.graphics.Paint
1111
import androidx.core.graphics.ColorUtils
12+
import otang.pulse.lib.util.PulseConfig
1213
import kotlin.math.log10
1314

1415
class SolidLineRenderer(context: Context, view: VisualizerView, colorController: ColorController) :
@@ -99,8 +100,7 @@ class SolidLineRenderer(context: Context, view: VisualizerView, colorController:
99100
}
100101
barUnit = barWidth + (barUnit - barWidth) * units / (units - 1)
101102
mPaint.strokeWidth = barWidth
102-
mPaint.strokeCap =
103-
if (mRounded) Paint.Cap.ROUND else Paint.Cap.BUTT
103+
mPaint.strokeCap = if (mRounded) Paint.Cap.ROUND else Paint.Cap.BUTT
104104
for (i in 0 until mUnits) {
105105
mFFTPoints[i * 4 + 2] = i * barUnit + barWidth / 2
106106
mFFTPoints[i * 4] = mFFTPoints[i * 4 + 2]
@@ -129,13 +129,12 @@ class SolidLineRenderer(context: Context, view: VisualizerView, colorController:
129129
}
130130
barUnit = barHeight + (barUnit - barHeight) * units / (units - 1)
131131
mPaint.strokeWidth = barHeight
132-
mPaint.strokeCap =
133-
if (mRounded) Paint.Cap.ROUND else Paint.Cap.BUTT
132+
mPaint.strokeCap = if (mRounded) Paint.Cap.ROUND else Paint.Cap.BUTT
134133
for (i in 0 until mUnits) {
135134
mFFTPoints[i * 4 + 3] = i * barUnit + barHeight / 2
136135
mFFTPoints[i * 4 + 1] = mFFTPoints[i * 4 + 3]
137136
mFFTPoints[i * 4] = (if (mLeftInLandscape) 0 else startPoint) as Float
138-
mFFTPoints[i * 4 + 2] = (if (mLeftInLandscape) 0 else startPoint) as Float
137+
mFFTPoints[i * 4 + 2] = (startPoint)
139138
}
140139
}
141140

@@ -191,25 +190,21 @@ class SolidLineRenderer(context: Context, view: VisualizerView, colorController:
191190
if (mVertical) {
192191
if (mLeftInLandscape || mGravity == GRAVITY_TOP) {
193192
mValueAnimators!![i]!!.setFloatValues(
194-
mFFTPoints[i * 4],
195-
(dbValue * fudgeFactor).toFloat()
193+
mFFTPoints[i * 4], (dbValue * fudgeFactor).toFloat()
196194
)
197195
} else if (mGravity == GRAVITY_BOTTOM || mGravity == GRAVITY_CENTER) {
198196
mValueAnimators!![i]!!.setFloatValues(
199-
mFFTPoints[i * 4],
200-
mFFTPoints[2] - dbValue * fudgeFactor
197+
mFFTPoints[i * 4], mFFTPoints[2] - dbValue * fudgeFactor
201198
)
202199
}
203200
} else {
204201
if (mGravity == GRAVITY_BOTTOM || mGravity == GRAVITY_CENTER) {
205202
mValueAnimators!![i]!!.setFloatValues(
206-
mFFTPoints[i * 4 + 1],
207-
mFFTPoints[3] - dbValue * fudgeFactor
203+
mFFTPoints[i * 4 + 1], mFFTPoints[3] - dbValue * fudgeFactor
208204
)
209205
} else if (mGravity == GRAVITY_TOP) {
210206
mValueAnimators!![i]!!.setFloatValues(
211-
mFFTPoints[i * 4 + 1],
212-
mFFTPoints[3] + dbValue * fudgeFactor
207+
mFFTPoints[i * 4 + 1], mFFTPoints[3] + dbValue * fudgeFactor
213208
)
214209
}
215210
}
@@ -237,28 +232,22 @@ class SolidLineRenderer(context: Context, view: VisualizerView, colorController:
237232
if (mVertical) {
238233
if (mLeftInLandscape || mGravity == GRAVITY_TOP) {
239234
mValueAnimators!![i]!!.setFloatValues(
240-
mFFTPoints[i * 4],
241-
(dbValue * fudgeFactor).toFloat()
235+
mFFTPoints[i * 4], (dbValue * fudgeFactor).toFloat()
242236
)
243237
} else if (mGravity == GRAVITY_BOTTOM || mGravity == GRAVITY_CENTER) {
244238
mValueAnimators!![i]!!.setFloatValues(
245-
mFFTPoints[i * 4],
246-
mFFTPoints[2] - dbValue * fudgeFactor
239+
mFFTPoints[i * 4], mFFTPoints[2] - dbValue * fudgeFactor
247240
)
248241
}
249242
} else {
250243
if (mGravity == GRAVITY_BOTTOM || mGravity == GRAVITY_CENTER) {
251-
mValueAnimators!![i]!!
252-
.setFloatValues(
253-
mFFTPoints[i * 4 + 1],
254-
mFFTPoints[3] - dbValue * fudgeFactor
255-
)
244+
mValueAnimators!![i]!!.setFloatValues(
245+
mFFTPoints[i * 4 + 1], mFFTPoints[3] - dbValue * fudgeFactor
246+
)
256247
} else if (mGravity == GRAVITY_TOP) {
257-
mValueAnimators!![i]!!
258-
.setFloatValues(
259-
mFFTPoints[i * 4 + 1],
260-
mFFTPoints[3] + dbValue * fudgeFactor
261-
)
248+
mValueAnimators!![i]!!.setFloatValues(
249+
mFFTPoints[i * 4 + 1], mFFTPoints[3] + dbValue * fudgeFactor
250+
)
262251
}
263252
}
264253
mValueAnimators!![i]!!.start()
@@ -337,7 +326,9 @@ class SolidLineRenderer(context: Context, view: VisualizerView, colorController:
337326
}
338327

339328
override fun onSharedPreferenceChanged(prefs: SharedPreferences, keys: String?) {
340-
updateSettings()
329+
if (keys == PulseConfig.PREF_PULSE_SOLID_FUDGE || keys == PulseConfig.PREF_PULSE_LINE_COUNT || keys == PulseConfig.PREF_PULSE_ROUNDED || keys == PulseConfig.PREF_PULSE_SOLID_OVACITY || keys == PulseConfig.PREF_PULSE_GRAVITY || keys == PulseConfig.PREF_PULSE_CENTER_MIRRORED || keys == PulseConfig.PREF_PULSE_LEFT || keys == PulseConfig.PREF_PULSE_VERTICAL_MIRROR || keys == PulseConfig.PREF_PULSE_SMOOTH) {
330+
updateSettings()
331+
}
341332
}
342333

343334
companion object {

lib/src/main/java/otang/pulse/lib/VisualizerView.kt

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import otang.pulse.lib.PulseController.PulseStateListener
1414
import otang.pulse.lib.util.PulseConfig
1515

1616
class VisualizerView @JvmOverloads constructor(
17-
context: Context?,
18-
attrs: AttributeSet?,
19-
defStyleAttr: Int = 0,
20-
defStyleRes: Int = 0
17+
context: Context?, attrs: AttributeSet?, defStyleAttr: Int = 0, defStyleRes: Int = 0
2118
) : View(context, attrs, defStyleAttr, defStyleRes), PulseController,
2219
OnSharedPreferenceChangeListener {
2320
constructor(context: Context) : this(context, null)
@@ -214,7 +211,9 @@ class VisualizerView @JvmOverloads constructor(
214211
}
215212

216213
override fun onSharedPreferenceChanged(prefs: SharedPreferences, keys: String?) {
217-
updateSettings()
214+
if (keys == PulseConfig.PREF_PULSE || keys == PulseConfig.PREF_PULSE_ROUNDED || keys == PulseConfig.PREF_PULSE_GRAVITY || keys == PulseConfig.PREF_PULSE_RENDER || keys == PulseConfig.PREF_PULSE_LEFT) {
215+
updateSettings()
216+
}
218217
}
219218

220219
companion object {

0 commit comments

Comments
 (0)