diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/pheelicks/app/MainActivity.java | 208 | ||||
-rw-r--r-- | src/com/pheelicks/utils/SystemPropertiesProxy.java | 73 | ||||
-rw-r--r-- | src/com/pheelicks/utils/TunnelPlayerWorkaround.java | 72 |
3 files changed, 0 insertions, 353 deletions
diff --git a/src/com/pheelicks/app/MainActivity.java b/src/com/pheelicks/app/MainActivity.java deleted file mode 100644 index a2d52dd..0000000 --- a/src/com/pheelicks/app/MainActivity.java +++ /dev/null @@ -1,208 +0,0 @@ -/** - * Copyright 2011, Felix Palmer - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ -package com.pheelicks.app; - -import java.io.IOException; - -import android.app.Activity; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.PorterDuff.Mode; -import android.graphics.PorterDuffXfermode; -import android.media.MediaPlayer; -import android.os.Bundle; -import android.view.View; - -import com.pheelicks.utils.TunnelPlayerWorkaround; -import com.pheelicks.visualizer.R; -import com.pheelicks.visualizer.VisualizerView; -import com.pheelicks.visualizer.renderer.BarGraphRenderer; -import com.pheelicks.visualizer.renderer.CircleBarRenderer; -import com.pheelicks.visualizer.renderer.CircleRenderer; -import com.pheelicks.visualizer.renderer.LineRenderer; - -/** - * Demo to show how to use VisualizerView - */ -public class MainActivity extends Activity { - private MediaPlayer mPlayer; - private MediaPlayer mSilentPlayer; /* to avoid tunnel player issue */ - private VisualizerView mVisualizerView; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - } - - @Override - protected void onResume() - { - super.onResume(); - initTunnelPlayerWorkaround(); - init(); - } - - @Override - protected void onPause() - { - cleanUp(); - super.onPause(); - } - - @Override - protected void onDestroy() - { - cleanUp(); - super.onDestroy(); - } - - private void init() - { - mPlayer = MediaPlayer.create(this, R.raw.test); - mPlayer.setLooping(true); - mPlayer.start(); - - // We need to link the visualizer view to the media player so that - // it displays something - mVisualizerView = (VisualizerView) findViewById(R.id.visualizerView); - mVisualizerView.link(mPlayer); - - // Start with just line renderer - addLineRenderer(); - } - - private void cleanUp() - { - if (mPlayer != null) - { - mVisualizerView.release(); - mPlayer.release(); - mPlayer = null; - } - - if (mSilentPlayer != null) - { - mSilentPlayer.release(); - mSilentPlayer = null; - } - } - - // Workaround (for Galaxy S4) - // - // "Visualization does not work on the new Galaxy devices" - // https://github.com/felixpalmer/android-visualizer/issues/5 - // - // NOTE: - // This code is not required for visualizing default "test.mp3" file, - // because tunnel player is used when duration is longer than 1 minute. - // (default "test.mp3" file: 8 seconds) - // - private void initTunnelPlayerWorkaround() { - // Read "tunnel.decode" system property to determine - // the workaround is needed - if (TunnelPlayerWorkaround.isTunnelDecodeEnabled(this)) { - mSilentPlayer = TunnelPlayerWorkaround.createSilentMediaPlayer(this); - } - } - - // Methods for adding renderers to visualizer - private void addBarGraphRenderers() - { - Paint paint = new Paint(); - paint.setStrokeWidth(50f); - paint.setAntiAlias(true); - paint.setColor(Color.argb(200, 56, 138, 252)); - BarGraphRenderer barGraphRendererBottom = new BarGraphRenderer(16, paint, false); - mVisualizerView.addRenderer(barGraphRendererBottom); - - Paint paint2 = new Paint(); - paint2.setStrokeWidth(12f); - paint2.setAntiAlias(true); - paint2.setColor(Color.argb(200, 181, 111, 233)); - BarGraphRenderer barGraphRendererTop = new BarGraphRenderer(4, paint2, true); - mVisualizerView.addRenderer(barGraphRendererTop); - } - - private void addCircleBarRenderer() - { - Paint paint = new Paint(); - paint.setStrokeWidth(8f); - paint.setAntiAlias(true); - paint.setXfermode(new PorterDuffXfermode(Mode.LIGHTEN)); - paint.setColor(Color.argb(255, 222, 92, 143)); - CircleBarRenderer circleBarRenderer = new CircleBarRenderer(paint, 32, true); - mVisualizerView.addRenderer(circleBarRenderer); - } - - private void addCircleRenderer() - { - Paint paint = new Paint(); - paint.setStrokeWidth(3f); - paint.setAntiAlias(true); - paint.setColor(Color.argb(255, 222, 92, 143)); - CircleRenderer circleRenderer = new CircleRenderer(paint, true); - mVisualizerView.addRenderer(circleRenderer); - } - - private void addLineRenderer() - { - Paint linePaint = new Paint(); - linePaint.setStrokeWidth(1f); - linePaint.setAntiAlias(true); - linePaint.setColor(Color.argb(88, 0, 128, 255)); - - Paint lineFlashPaint = new Paint(); - lineFlashPaint.setStrokeWidth(5f); - lineFlashPaint.setAntiAlias(true); - lineFlashPaint.setColor(Color.argb(188, 255, 255, 255)); - LineRenderer lineRenderer = new LineRenderer(linePaint, lineFlashPaint, true); - mVisualizerView.addRenderer(lineRenderer); - } - - // Actions for buttons defined in xml - public void startPressed(View view) throws IllegalStateException, IOException - { - if(mPlayer.isPlaying()) - { - return; - } - mPlayer.prepare(); - mPlayer.start(); - } - - public void stopPressed(View view) - { - mPlayer.stop(); - } - - public void barPressed(View view) - { - addBarGraphRenderers(); - } - - public void circlePressed(View view) - { - addCircleRenderer(); - } - - public void circleBarPressed(View view) - { - addCircleBarRenderer(); - } - - public void linePressed(View view) - { - addLineRenderer(); - } - - public void clearPressed(View view) - { - mVisualizerView.clearRenderers(); - } -}
\ No newline at end of file diff --git a/src/com/pheelicks/utils/SystemPropertiesProxy.java b/src/com/pheelicks/utils/SystemPropertiesProxy.java deleted file mode 100644 index 6e49979..0000000 --- a/src/com/pheelicks/utils/SystemPropertiesProxy.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2013, Haruki Hasegawa - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -/** - * from http://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties - */ - -package com.pheelicks.utils; - -import java.lang.reflect.Method; - -import android.content.Context; -import android.util.Log; - -public class SystemPropertiesProxy { - private static final String TAG = "SystemPropertiesProxy"; - - /** - * Get the value for the given key, returned as a boolean. Values 'n', 'no', - * '0', 'false' or 'off' are considered false. Values 'y', 'yes', '1', 'true' - * or 'on' are considered true. (case insensitive). If the key does not exist, - * or has any other value, then the default result is returned. - * - * @param key the key to lookup - * @param def a default value to return - * @return the key parsed as a boolean, or def if the key isn't found or is - * not able to be parsed as a boolean. - * @throws IllegalArgumentException if the key exceeds 32 characters - */ - public static Boolean getBoolean(Context context, String key, boolean def) - throws IllegalArgumentException { - return getBoolean(context.getClassLoader(), key, def); - } - - public static Boolean getBoolean(ClassLoader cl, String key, boolean def) - throws IllegalArgumentException { - - Boolean ret = def; - - try { - @SuppressWarnings("rawtypes") - Class SystemProperties = cl.loadClass("android.os.SystemProperties"); - - // Parameters Types - @SuppressWarnings("rawtypes") - Class[] paramTypes = new Class[2]; - paramTypes[0] = String.class; - paramTypes[1] = boolean.class; - - @SuppressWarnings("unchecked") - Method getBoolean = SystemProperties.getMethod("getBoolean", paramTypes); - - // Parameters - Object[] params = new Object[2]; - params[0] = new String(key); - params[1] = Boolean.valueOf(def); - - ret = (Boolean) getBoolean.invoke(SystemProperties, params); - - } catch (IllegalArgumentException iAE) { - throw iAE; - } catch (Exception e) { - Log.e(TAG, "getBoolean(context, key: " + key + ", def:" + def + ")", e); - ret = def; - } - - return ret; - } -} diff --git a/src/com/pheelicks/utils/TunnelPlayerWorkaround.java b/src/com/pheelicks/utils/TunnelPlayerWorkaround.java deleted file mode 100644 index c25caf0..0000000 --- a/src/com/pheelicks/utils/TunnelPlayerWorkaround.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2013, Haruki Hasegawa - * - * Licensed under the MIT license: - * http://creativecommons.org/licenses/MIT/ - */ - -package com.pheelicks.utils; - -import java.io.IOException; - -import android.content.Context; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.util.Log; - -import com.pheelicks.visualizer.R; - -public class TunnelPlayerWorkaround { - private static final String TAG = "TunnelPlayerWorkaround"; - - private static final String SYSTEM_PROP_TUNNEL_DECODE_ENABLED = "tunnel.decode"; - - private TunnelPlayerWorkaround() - { - } - - /** - * Obtain "tunnel.decode" system property value - * - * @param context Context - * @return Whether tunnel player is enabled - */ - public static boolean isTunnelDecodeEnabled(Context context) - { - return SystemPropertiesProxy.getBoolean( - context, SYSTEM_PROP_TUNNEL_DECODE_ENABLED, false); - } - - /** - * Create silent MediaPlayer instance to avoid tunnel player issue - * - * @param context Context - * @return MediaPlayer instance - */ - public static MediaPlayer createSilentMediaPlayer(Context context) - { - boolean result = false; - - MediaPlayer mp = null; - try { - mp = MediaPlayer.create(context, R.raw.workaround_1min); - mp.setAudioStreamType(AudioManager.STREAM_MUSIC); - - // NOTE: start() is no needed - // mp.start(); - - result = true; - } catch (RuntimeException e) { - Log.e(TAG, "createSilentMediaPlayer()", e); - } finally { - if (!result && mp != null) { - try { - mp.release(); - } catch (IllegalStateException e) { - } - } - } - - return mp; - } -} |