diff options
author | Danny Baumann <dannybaumann@web.de> | 2014-11-11 10:44:49 +0100 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2015-10-25 11:55:22 +0200 |
commit | 09618116991575a0bd725dcaa3434c72d1bf8060 (patch) | |
tree | cac4d3e0eaaa714d173c75f04d686deb12fd2152 | |
parent | fe0bf1fbbba83e8906c3062184fe4d1dd04eac8e (diff) | |
download | android_packages_wallpapers_PhaseBeam-09618116991575a0bd725dcaa3434c72d1bf8060.tar.gz android_packages_wallpapers_PhaseBeam-09618116991575a0bd725dcaa3434c72d1bf8060.tar.bz2 android_packages_wallpapers_PhaseBeam-09618116991575a0bd725dcaa3434c72d1bf8060.zip |
Bring over PhaseBeam recoloring from cm-11.0 branch.
Change-Id: Idea935647ce4aa4c1e60657c071b6bd921712bce
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | AndroidManifest.xml | 9 | ||||
-rw-r--r-- | res/drawable-nodpi/beam_grey.png | bin | 0 -> 2059 bytes | |||
-rw-r--r-- | res/drawable-nodpi/dot_grey.png | bin | 0 -> 1359 bytes | |||
-rw-r--r-- | res/layout/selector.xml | 82 | ||||
-rw-r--r-- | res/raw/bg_fs.glsl | 27 | ||||
-rw-r--r-- | res/raw/bg_vs.glsl | 6 | ||||
-rw-r--r-- | res/raw/dot_fs.glsl | 30 | ||||
-rw-r--r-- | res/raw/dot_vs.glsl | 4 | ||||
-rw-r--r-- | res/values/cm_strings.xml | 22 | ||||
-rw-r--r-- | res/values/config.xml | 28 | ||||
-rw-r--r-- | res/values/styles.xml | 28 | ||||
-rw-r--r-- | res/xml/wallpaper.xml | 1 | ||||
-rw-r--r-- | src/com/android/phasebeam/PhaseBeamRS.java | 57 | ||||
-rw-r--r-- | src/com/android/phasebeam/PhaseBeamSelector.java | 289 | ||||
-rw-r--r-- | src/com/android/phasebeam/PhaseBeamView.java | 3 | ||||
-rw-r--r-- | src/com/android/phasebeam/PhaseBeamWallpaper.java | 9 | ||||
-rw-r--r-- | src/com/android/phasebeam/phasebeam.rs | 82 |
18 files changed, 631 insertions, 48 deletions
@@ -23,7 +23,7 @@ LOCAL_SRC_FILES := $(call all-subdir-java-files) $(call all-renderscript-files-u LOCAL_PACKAGE_NAME := PhaseBeam LOCAL_CERTIFICATE := shared -LOCAL_SDK_VERSION := 17 +LOCAL_RENDERSCRIPT_TARGET_API := 17 LOCAL_PROGUARD_FLAG_FILES := proguard.cfg diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a9ff539..04e6782 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -17,5 +17,12 @@ </intent-filter> <meta-data android:name="android.service.wallpaper" android:resource="@xml/wallpaper" /> </service> + + <activity + android:name="com.android.phasebeam.PhaseBeamSelector" + android:theme="@style/Transparent" + android:exported="true"> + </activity> + </application> -</manifest>
\ No newline at end of file +</manifest> diff --git a/res/drawable-nodpi/beam_grey.png b/res/drawable-nodpi/beam_grey.png Binary files differnew file mode 100644 index 0000000..0d3a3b7 --- /dev/null +++ b/res/drawable-nodpi/beam_grey.png diff --git a/res/drawable-nodpi/dot_grey.png b/res/drawable-nodpi/dot_grey.png Binary files differnew file mode 100644 index 0000000..d785ebf --- /dev/null +++ b/res/drawable-nodpi/dot_grey.png diff --git a/res/layout/selector.xml b/res/layout/selector.xml new file mode 100644 index 0000000..32cd68b --- /dev/null +++ b/res/layout/selector.xml @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/backgroundview" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginStart="15dip" + android:layout_marginEnd="15dip" + android:layout_marginBottom="20dip" > + + <CheckBox + android:id="@+id/recolor" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_above="@+id/hue_text" + android:layout_marginBottom="10dip" + android:text="@string/enable_recoloring" /> + + <TextView + android:id="@+id/hue_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_above="@+id/hue" + android:layout_marginBottom="5dip" + android:text="@string/color_label" /> + + <SeekBar + android:id="@+id/hue" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_above="@+id/saturation_text" + android:layout_marginStart="5dip" + android:layout_marginBottom="10dip" + android:max="1000" /> + + <TextView + android:id="@+id/saturation_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_above="@+id/saturation" + android:layout_marginBottom="5dip" + android:text="@string/saturation_label" /> + + <SeekBar + android:id="@+id/saturation" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_above="@+id/brightness_text" + android:layout_marginStart="5dip" + android:max="1000" /> + + <TextView + android:id="@+id/brightness_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_above="@+id/brightness" + android:layout_marginBottom="5dip" + android:text="@string/brightness_label" /> + + <SeekBar + android:id="@+id/brightness" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="5dip" + android:layout_alignParentBottom="true" + android:max="1000" /> + +</RelativeLayout> diff --git a/res/raw/bg_fs.glsl b/res/raw/bg_fs.glsl index d20885d..e063f86 100644 --- a/res/raw/bg_fs.glsl +++ b/res/raw/bg_fs.glsl @@ -1,5 +1,28 @@ varying lowp vec4 color; +varying vec3 adjust; + +// inspired by http://www.chilliant.com/rgb2hsv.html +vec3 hsl2rgb(vec3 hsl) +{ + // each line has the form abs(6 * hue - K1) * K2 + C + const vec3 K1 = vec3(0.5, 1.0 / 3.0, 2.0 / 3.0); + const vec3 K2 = vec3(1.0, -1.0, -1.0); + const vec3 C = vec3(-1.0, 2.0, 2.0); + + vec3 rgb = clamp(abs(6.0 * (hsl.xxx - K1.xyz)) * K2 + C, 0.0, 1.0); + float chroma = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y; + return (rgb - 0.5) * chroma + hsl.z; +} void main() { - gl_FragColor = color; -}
\ No newline at end of file + vec3 rgb = color.rgb; + + if (adjust.x >= 0.0) { + // rgb is already greyscale in that case, so r = g = b + vec3 hsl = adjust * vec3(1.0, 1.0, rgb.r); + rgb = hsl2rgb(hsl); + } + + // output pixel color + gl_FragColor = vec4(rgb, color.a); +} diff --git a/res/raw/bg_vs.glsl b/res/raw/bg_vs.glsl index 8eb23b3..eeb912b 100644 --- a/res/raw/bg_vs.glsl +++ b/res/raw/bg_vs.glsl @@ -1,6 +1,8 @@ varying lowp vec4 color; +varying vec3 adjust; void main() { - color = ATTRIB_color; + adjust = ATTRIB_adjust; + color = ATTRIB_realColor; gl_Position = vec4(ATTRIB_position.x + ATTRIB_offsetX/3.5, ATTRIB_position.y, 0.0, 1.0); -}
\ No newline at end of file +} diff --git a/res/raw/dot_fs.glsl b/res/raw/dot_fs.glsl index 3ef90ed..78e7ed3 100644 --- a/res/raw/dot_fs.glsl +++ b/res/raw/dot_fs.glsl @@ -1,6 +1,28 @@ varying float pointSize; +varying vec3 adjust; -void main() { - gl_FragColor = texture2D(UNI_Tex0, gl_PointCoord); - gl_FragColor.a = pointSize; -}
\ No newline at end of file +// inspired by http://www.chilliant.com/rgb2hsv.html +vec3 hsl2rgb(vec3 hsl) +{ + // each line has the form abs(6 * hue - K1) * K2 + C + const vec3 K1 = vec3(0.5, 1.0 / 3.0, 2.0 / 3.0); + const vec3 K2 = vec3(1.0, -1.0, -1.0); + const vec3 C = vec3(-1.0, 2.0, 2.0); + + vec3 rgb = clamp(abs(6.0 * (hsl.xxx - K1.xyz)) * K2 + C, 0.0, 1.0); + float chroma = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y; + return (rgb - 0.5) * chroma + hsl.z; +} + +void main() { + vec3 rgb = texture2D(UNI_Tex0, gl_PointCoord).rgb; + + if (adjust.x >= 0.0) { + // rgb is already greyscale in that case, so r = g = b + vec3 hsl = adjust * vec3(1.0, 1.0, rgb.r); + rgb = hsl2rgb(hsl); + } + + // output pixel color + gl_FragColor = vec4(rgb, pointSize); +} diff --git a/res/raw/dot_vs.glsl b/res/raw/dot_vs.glsl index 9cf3c74..8c7fdd1 100644 --- a/res/raw/dot_vs.glsl +++ b/res/raw/dot_vs.glsl @@ -1,4 +1,5 @@ varying float pointSize; +varying vec3 adjust; void main() { vec4 objPos = vec4(ATTRIB_position, 1.0); @@ -6,6 +7,7 @@ void main() { pointSize = 0.5-tmpPointSize/1000.0; objPos.z = 0.0; objPos.x = objPos.x - ATTRIB_offsetX * tmpPointSize/100.0; + adjust = ATTRIB_adjust; gl_Position = objPos; gl_PointSize = tmpPointSize*UNI_scaleSize; -}
\ No newline at end of file +} diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml new file mode 100644 index 0000000..5d62eee --- /dev/null +++ b/res/values/cm_strings.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2013-2014 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources> + <string name="enable_recoloring">Adjust beam colors</string> + <string name="color_label">Color</string> + <string name="saturation_label">Saturation</string> + <string name="brightness_label">Brightness</string> +</resources> diff --git a/res/values/config.xml b/res/values/config.xml new file mode 100644 index 0000000..3e7ae7e --- /dev/null +++ b/res/values/config.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 The CyanogenMod Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + + <!-- Whether recoloring is enabled by default --> + <bool name="recolor_enabled">false</bool> + <!-- Default values for the color controls --> + <item name="hue" format="float" type="string">0.0</item> + <item name="saturation" format="float" type="string">1.0</item> + <item name="brightness" format="float" type="string">1.0</item> + <!-- Whether horizontal scrolling is enabled --> + <bool name="scrolling_enabled">true</bool> + +</resources> diff --git a/res/values/styles.xml b/res/values/styles.xml new file mode 100644 index 0000000..81e2db6 --- /dev/null +++ b/res/values/styles.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +* Copyright (C) 2008 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +--> + +<resources> + <style name="Transparent"> + <item name="android:windowBackground">@android:color/transparent</item> + <item name="android:windowActionBar">false</item> + <item name="android:windowNoTitle">true</item> + <item name="android:windowContentOverlay">@null</item> + <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> + </style> +</resources> diff --git a/res/xml/wallpaper.xml b/res/xml/wallpaper.xml index 572063d..17cddeb 100644 --- a/res/xml/wallpaper.xml +++ b/res/xml/wallpaper.xml @@ -18,5 +18,6 @@ --> <wallpaper xmlns:android="http://schemas.android.com/apk/res/android" + android:settingsActivity="com.android.phasebeam.PhaseBeamSelector" android:author="@string/wallpaper_author" android:thumbnail="@drawable/wallpaper_thumb" /> diff --git a/src/com/android/phasebeam/PhaseBeamRS.java b/src/com/android/phasebeam/PhaseBeamRS.java index bd0687b..6963b4c 100644 --- a/src/com/android/phasebeam/PhaseBeamRS.java +++ b/src/com/android/phasebeam/PhaseBeamRS.java @@ -3,6 +3,8 @@ package com.android.phasebeam; import static android.renderscript.Sampler.Value.NEAREST; import static android.renderscript.Sampler.Value.WRAP; +import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Resources; import android.renderscript.Allocation; import android.renderscript.Matrix4f; @@ -29,7 +31,7 @@ import java.io.IOException; import java.util.ArrayList; import android.util.Log; -public class PhaseBeamRS { +public class PhaseBeamRS implements SharedPreferences.OnSharedPreferenceChangeListener { public static String LOG_TAG = "PhaseBeam"; public static final int DOT_COUNT = 28; private Resources mRes; @@ -51,18 +53,27 @@ public class PhaseBeamRS { private ScriptField_VertexColor_s mVertexColors; private int mDensityDPI; + private SharedPreferences mSharedPref; + private Context mContext; + private boolean mCanScroll; boolean mInited = false; - public void init(int dpi, RenderScriptGL rs, Resources res, int width, int height) { + public void init(Context context, int dpi, RenderScriptGL rs, + Resources res, int width, int height) { if (!mInited) { mDensityDPI = dpi; + mContext = context; + mSharedPref = mContext.getSharedPreferences(PhaseBeamSelector.KEY_PREFS, + Context.MODE_PRIVATE); + mSharedPref.registerOnSharedPreferenceChangeListener(this); mRS = rs; mRes = res; mWidth = width; mHeight = height; + mCanScroll = mRes.getBoolean(R.bool.scrolling_enabled); mDotParticles = new ScriptField_Particle(mRS, DOT_COUNT); Mesh.AllocationBuilder smb2 = new Mesh.AllocationBuilder(mRS); @@ -96,10 +107,41 @@ public class PhaseBeamRS { mRS.bindRootScript(mScript); mScript.invoke_positionParticles(); + makeNewState(); + mInited = true; } } + public void uninit() { + mSharedPref.unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(PhaseBeamSelector.KEY_ENABLED)) { + loadTextures(); + } + makeNewState(); + } + + private void makeNewState() { + Float3 adjust; + if (mSharedPref.getBoolean(PhaseBeamSelector.KEY_ENABLED, + mRes.getBoolean(R.bool.recolor_enabled))) { + adjust = new Float3( + mSharedPref.getFloat(PhaseBeamSelector.KEY_HUE, + Float.valueOf(mRes.getString(R.string.hue))), + mSharedPref.getFloat(PhaseBeamSelector.KEY_SATURATION, + Float.valueOf(mRes.getString(R.string.saturation))), + mSharedPref.getFloat(PhaseBeamSelector.KEY_BRIGHTNESS, + Float.valueOf(mRes.getString(R.string.brightness)))); + } else { + adjust = new Float3(-1.0f, 1.0f, 1.0f); + } + mScript.set_adjust(adjust); + } + private Matrix4f getProjectionNormalized(int w, int h) { // range -1,1 in the narrow axis at z = 0. Matrix4f m1 = new Matrix4f(); @@ -165,6 +207,8 @@ public class PhaseBeamRS { float blue = new Float(values[4]); mVertexColors.set_position(i, new Float3(xPos, yPos, 0.0f), false); mVertexColors.set_color(i, new Float4(red, green, blue, 1.0f), false); + mVertexColors.set_realColor(i, new Float4(red, green, blue, 1.0f), false); + mVertexColors.set_adjust(i, new Float3(-1.0f, 1.0f, 1.0f), false); } mVertexColors.copyAll(); @@ -183,8 +227,9 @@ public class PhaseBeamRS { } private void loadTextures() { - mDotAllocation = loadTexture(R.drawable.dot); - mBeamAllocation = loadTexture(R.drawable.beam); + boolean recolor = mSharedPref.getBoolean(PhaseBeamSelector.KEY_ENABLED, false); + mDotAllocation = loadTexture(recolor ? R.drawable.dot_grey : R.drawable.dot); + mBeamAllocation = loadTexture(recolor ? R.drawable.beam_grey : R.drawable.beam); mScript.set_textureDot(mDotAllocation); mScript.set_textureBeam(mBeamAllocation); } @@ -246,7 +291,9 @@ public class PhaseBeamRS { } public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) { - mScript.set_xOffset(xOffset); + if (mCanScroll) { + mScript.set_xOffset(xOffset); + } } public void resize(int w, int h) { diff --git a/src/com/android/phasebeam/PhaseBeamSelector.java b/src/com/android/phasebeam/PhaseBeamSelector.java new file mode 100644 index 0000000..f5df837 --- /dev/null +++ b/src/com/android/phasebeam/PhaseBeamSelector.java @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.phasebeam; + +import android.app.Activity; +import android.app.WallpaperManager; +import android.app.WallpaperInfo; +import android.app.Dialog; +import android.service.wallpaper.IWallpaperConnection; +import android.service.wallpaper.IWallpaperService; +import android.service.wallpaper.IWallpaperEngine; +import android.service.wallpaper.WallpaperSettingsActivity; +import android.content.ServiceConnection; +import android.content.Intent; +import android.content.Context; +import android.content.ComponentName; +import android.content.SharedPreferences; +import android.graphics.Rect; +import android.os.RemoteException; +import android.os.IBinder; +import android.os.ParcelFileDescriptor; +import android.os.Bundle; +import android.util.Log; +import android.view.MotionEvent; +import android.view.View; +import android.view.WindowManager; +import android.view.ViewGroup; +import android.view.Window; +import android.view.LayoutInflater; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.SeekBar; + +public class PhaseBeamSelector extends Activity implements + CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener { + private static final String LOG_TAG = "PhaseBeamSelector"; + + public static final String KEY_PREFS = "phasebeam"; + public static final String KEY_ENABLED = "enabled"; + public static final String KEY_HUE = "hue"; + public static final String KEY_SATURATION = "saturation"; + public static final String KEY_BRIGHTNESS = "brightness"; + + private static final float HUE_RANGE_MIN = 0.0f; + private static final float HUE_RANGE_MAX = 1.0f; + private static final float SATURATION_RANGE_MIN = 0.0f; + private static final float SATURATION_RANGE_MAX = 1.0f; + private static final float BRIGHTNESS_RANGE_MIN = 0.5f; + private static final float BRIGHTNESS_RANGE_MAX = 1.5f; + + private WallpaperManager mWallpaperManager; + private WallpaperConnection mWallpaperConnection; + private Intent mWallpaperIntent; + + private SharedPreferences mSharedPref; + + private CheckBox mEnableBox; + private SeekBar mColorSeekBar; + private SeekBar mSaturationSeekBar; + private SeekBar mBrightnessSeekBar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.selector); + + mWallpaperIntent = new Intent(this, PhaseBeamWallpaper.class); + mWallpaperManager = WallpaperManager.getInstance(this); + mWallpaperConnection = new WallpaperConnection(mWallpaperIntent); + + mSharedPref = getSharedPreferences(KEY_PREFS, Context.MODE_PRIVATE); + + mEnableBox = (CheckBox) findViewById(R.id.recolor); + mEnableBox.setOnCheckedChangeListener(this); + mColorSeekBar = (SeekBar) findViewById(R.id.hue); + mColorSeekBar.setOnSeekBarChangeListener(this); + mSaturationSeekBar = (SeekBar) findViewById(R.id.saturation); + mSaturationSeekBar.setOnSeekBarChangeListener(this); + mBrightnessSeekBar = (SeekBar) findViewById(R.id.brightness); + mBrightnessSeekBar.setOnSeekBarChangeListener(this); + } + + @Override + public void onResume() { + super.onResume(); + if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) { + try { + mWallpaperConnection.mEngine.setVisibility(true); + } catch (RemoteException e) { + // Ignore + } + } + updateUiFromPrefs(); + } + + @Override + public void onPause() { + super.onPause(); + if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) { + try { + mWallpaperConnection.mEngine.setVisibility(false); + } catch (RemoteException e) { + // Ignore + } + } + } + + @Override + public void onAttachedToWindow() { + super.onAttachedToWindow(); + + if (!mWallpaperConnection.connect()) { + mWallpaperConnection = null; + } + } + + @Override + public void onDetachedFromWindow() { + super.onDetachedFromWindow(); + + if (mWallpaperConnection != null) { + mWallpaperConnection.disconnect(); + } + mWallpaperConnection = null; + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mColorSeekBar.setEnabled(isChecked); + mSaturationSeekBar.setEnabled(isChecked); + mBrightnessSeekBar.setEnabled(isChecked); + mSharedPref.edit().putBoolean(KEY_ENABLED, isChecked).apply(); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (!fromUser) { + return; + } + + float min, max; + String key; + + if (seekBar == mColorSeekBar) { + min = HUE_RANGE_MIN; + max = HUE_RANGE_MAX; + key = KEY_HUE; + } else if (seekBar == mSaturationSeekBar) { + min = SATURATION_RANGE_MIN; + max = SATURATION_RANGE_MAX; + key = KEY_SATURATION; + } else { + min = BRIGHTNESS_RANGE_MIN; + max = BRIGHTNESS_RANGE_MAX; + key = KEY_BRIGHTNESS; + } + + float value = ((max - min) * progress / seekBar.getMax()) + min; + mSharedPref.edit().putFloat(key, value).apply(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Nothing to do here + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Nothing to do here + } + + private void updateUiFromPrefs() { + mEnableBox.setChecked(mSharedPref.getBoolean(KEY_ENABLED, false)); + + updateSeekBarFromFloat(mColorSeekBar, mSharedPref.getFloat(KEY_HUE, 0.0f), + HUE_RANGE_MIN, HUE_RANGE_MAX); + updateSeekBarFromFloat(mSaturationSeekBar, mSharedPref.getFloat(KEY_SATURATION, 1.0f), + SATURATION_RANGE_MIN, SATURATION_RANGE_MAX); + updateSeekBarFromFloat(mBrightnessSeekBar, mSharedPref.getFloat(KEY_BRIGHTNESS, 1.0f), + BRIGHTNESS_RANGE_MIN, BRIGHTNESS_RANGE_MAX); + } + + private void updateSeekBarFromFloat(SeekBar seekBar, float value, float min, float max) { + float progress = (value - min) * seekBar.getMax() / (max - min); + seekBar.setProgress((int) progress); + } + + class WallpaperConnection extends IWallpaperConnection.Stub implements ServiceConnection { + final Intent mIntent; + IWallpaperService mService; + IWallpaperEngine mEngine; + boolean mConnected; + + WallpaperConnection(Intent intent) { + mIntent = intent; + } + + public boolean connect() { + synchronized (this) { + if (!bindService(mIntent, this, Context.BIND_AUTO_CREATE)) { + return false; + } + + mConnected = true; + return true; + } + } + + public void disconnect() { + synchronized (this) { + mConnected = false; + if (mEngine != null) { + try { + mEngine.destroy(); + } catch (RemoteException e) { + // Ignore + } + mEngine = null; + } + unbindService(this); + mService = null; + } + } + + public void onServiceConnected(ComponentName name, IBinder service) { + if (mWallpaperConnection == this) { + mService = IWallpaperService.Stub.asInterface(service); + try { + final View view = findViewById(R.id.backgroundview); + final View root = view.getRootView(); + mService.attach(this, view.getWindowToken(), + WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY, + true, root.getWidth(), root.getHeight(), new Rect()); + } catch (RemoteException e) { + Log.w(LOG_TAG, "Failed attaching wallpaper; clearing", e); + } + } + } + + public void onServiceDisconnected(ComponentName name) { + mService = null; + mEngine = null; + if (mWallpaperConnection == this) { + Log.w(LOG_TAG, "Wallpaper service gone: " + name); + } + } + + public void attachEngine(IWallpaperEngine engine) { + synchronized (this) { + if (mConnected) { + mEngine = engine; + try { + engine.setVisibility(true); + } catch (RemoteException e) { + // Ignore + } + } else { + try { + engine.destroy(); + } catch (RemoteException e) { + // Ignore + } + } + } + } + + public ParcelFileDescriptor setWallpaper(String name) { + return null; + } + + public void engineShown(IWallpaperEngine engine) throws RemoteException { + } + } +} diff --git a/src/com/android/phasebeam/PhaseBeamView.java b/src/com/android/phasebeam/PhaseBeamView.java index e88a0b1..27689f2 100644 --- a/src/com/android/phasebeam/PhaseBeamView.java +++ b/src/com/android/phasebeam/PhaseBeamView.java @@ -25,7 +25,7 @@ public class PhaseBeamView extends RSSurfaceView { mRS.setSurface(holder, w, h); mRender = new PhaseBeamRS(); - mRender.init(240, mRS, getResources(), w, h); + mRender.init(getContext(), 240, mRS, getResources(), w, h); } } @@ -36,6 +36,7 @@ public class PhaseBeamView extends RSSurfaceView { mRS.setSurface(null, 0, 0); mRS = null; destroyRenderScriptGL(); + mRender.uninit(); } } diff --git a/src/com/android/phasebeam/PhaseBeamWallpaper.java b/src/com/android/phasebeam/PhaseBeamWallpaper.java index 2541ab2..0f51fc1 100644 --- a/src/com/android/phasebeam/PhaseBeamWallpaper.java +++ b/src/com/android/phasebeam/PhaseBeamWallpaper.java @@ -44,6 +44,7 @@ public class PhaseBeamWallpaper extends WallpaperService { public void destroyRenderer() { if (mWallpaperRS != null) { mWallpaperRS.stop(); + mWallpaperRS.uninit(); mWallpaperRS = null; } @@ -80,7 +81,8 @@ public class PhaseBeamWallpaper extends WallpaperService { if (mWallpaperRS == null) { mWallpaperRS = new PhaseBeamRS(); - mWallpaperRS.init(mDensityDPI, mRenderScript, getResources(), width, height); + mWallpaperRS.init(PhaseBeamWallpaper.this, mDensityDPI, + mRenderScript, getResources(), width, height); mWallpaperRS.start(); } @@ -108,8 +110,7 @@ public class PhaseBeamWallpaper extends WallpaperService { @Override public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) { - // TODO: Uncomment this once we can work out framerate issues - //mWallpaperRS.setOffset(xOffset, yOffset, xPixelOffset, yPixelOffset); + mWallpaperRS.setOffset(xOffset, yOffset, xPixelOffset, yPixelOffset); } } -}
\ No newline at end of file +} diff --git a/src/com/android/phasebeam/phasebeam.rs b/src/com/android/phasebeam/phasebeam.rs index ccbf60a..9f8ac26 100644 --- a/src/com/android/phasebeam/phasebeam.rs +++ b/src/com/android/phasebeam/phasebeam.rs @@ -22,6 +22,7 @@ static int numVertColors; typedef struct __attribute__((packed, aligned(4))) Particle { float3 position; float offsetX; + float3 adjust; } Particle_t; typedef struct VpConsts { @@ -34,6 +35,8 @@ typedef struct VertexColor_s { float3 position; float offsetX; float4 color; + float4 realColor; + float3 adjust; } VertexColor; VertexColor* vertexColors; @@ -43,6 +46,8 @@ rs_mesh dotMesh; rs_mesh beamMesh; rs_mesh gBackgroundMesh; +float3 adjust = { -1.0, 1.0, 1.0 }; +float3 oldAdjust = { -1.0, 1.0, 1.0 }; float densityDPI; float xOffset = 0.5; @@ -56,6 +61,11 @@ static float halfScreenHeight; static float newOffset = 0.5; static float oldOffset = 0.5; +static const float zxParticleSpeed = 0.0000780; +static const float zxBeamSpeed = 0.00005; +static const float yzParticleSpeed = 0.00011; +static const float yzBeamSpeed = 0.000080; + void positionParticles() { screenWidth = rsgGetWidth(); screenHeight = rsgGetHeight(); @@ -85,6 +95,7 @@ void positionParticles() { } particle->position.z = z; particle->offsetX = 0; + particle->adjust = adjust; particle++; } @@ -102,19 +113,34 @@ void positionParticles() { beamParticles->position.z = z; beamParticles->offsetX = 0; + beamParticles->adjust = adjust; beamParticles++; } } int root() { + float speedbump; newOffset = xOffset*2; + speedbump = newOffset != oldOffset ? 0.25 : 1.0; rsgClearColor(0.0f, 0.f, 0.f,1.0f); - if(newOffset != oldOffset) { + if(newOffset != oldOffset + || oldAdjust.x != adjust.x + || oldAdjust.y != adjust.y + || oldAdjust.z != adjust.z) { VertexColor* vert = vertexColors; + bool useAdjust = adjust.x >= 0; for(int i=0; i<numVertColors; i++) { vert->offsetX = -xOffset/2.0; + vert->realColor = vert->color; + if (useAdjust) { + float grey = 0.3 * vert->color.x + 0.59 * vert->color.y + 0.11 * vert->color.z; + vert->realColor.x = grey; + vert->realColor.y = grey; + vert->realColor.z = grey; + } + vert->adjust = adjust; vert++; } } @@ -127,36 +153,38 @@ int root() { Particle_t* beam = beamParticles; Particle_t* particle = dotParticles; - for(int i=0; i<numDotParticles; i++) { + for (int i=0; i<numBeamParticles; i++) { + if(beam->position.x/beam->position.z > 0.5) { + beam->position.x = -1.0; + } + if(beam->position.y > 1.15) { + beam->position.y = -1.15; + beam->position.x = rsRand(-1.25f, 1.25f); + } else { + beam->position.y += yzBeamSpeed * beam->position.z * speedbump; + } + beam->position.x += zxBeamSpeed * beam->position.z * speedbump; + beam->offsetX = newOffset; + beam->adjust = adjust; + beam++; + } - if(newOffset==oldOffset) { - if(beam->position.x/beam->position.z > 0.5) { - beam->position.x = -1.0; - } - if(particle->position.x/particle->position.z > 0.5) { - particle->position.x = -1.0; - } + for(int i=0; i<numDotParticles; i++) { + if(particle->position.x/particle->position.z > 0.5) { + particle->position.x = -1.0; + } - if(beam->position.y > 1.05) { - beam->position.y = -1.05; - beam->position.x = rsRand(-1.25f, 1.25f); - } else { - beam->position.y = beam->position.y + 0.000160*beam->position.z; - } - if(particle->position.y > 1.25) { - particle->position.y = -1.25; - particle->position.x = rsRand(0.0f, 3.0f); + if(particle->position.y > 1.25) { + particle->position.y = -1.25; + particle->position.x = rsRand(0.0f, 3.0f); - } else { - particle->position.y = particle->position.y + 0.00022*particle->position.z; - } + } else { + particle->position.y += yzParticleSpeed * particle->position.z * speedbump; } - beam->position.x = beam->position.x + 0.0001*beam->position.z; - beam->offsetX = newOffset; - beam++; particle->offsetX = newOffset; - particle->position.x = particle->position.x + 0.0001560*beam->position.z; + particle->position.x += zxParticleSpeed * particle->position.z * speedbump; + particle->adjust = adjust; particle++; } @@ -170,7 +198,7 @@ int root() { rsgDrawMesh(dotMesh); oldOffset = newOffset; + oldAdjust = adjust; - return 66; - + return 66 * speedbump; } |