Update browseable samples for lmp-docs
Synced to commit df5e5013422b81b4fd05c0ac9fd964b13624847a. Includes new samples for Android Auto. Change-Id: I3fec46e2a6b3f196682a92f1afd91eb682dc2dc1
This commit is contained in:
43
samples/browseable/MediaEffects/AndroidManifest.xml
Normal file
43
samples/browseable/MediaEffects/AndroidManifest.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2014 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.
|
||||
-->
|
||||
|
||||
<manifest
|
||||
package="com.example.android.mediaeffects"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
12
samples/browseable/MediaEffects/_index.jd
Normal file
12
samples/browseable/MediaEffects/_index.jd
Normal file
@@ -0,0 +1,12 @@
|
||||
page.tags="MediaEffects"
|
||||
sample.group=Media
|
||||
@jd:body
|
||||
|
||||
<p>
|
||||
|
||||
This sample shows how to use the Media Effects APIs that were introduced in Android 4.0.
|
||||
These APIs let you apply effects to image frames represented as OpenGL ES 2.0 textures.
|
||||
Image frames can be images loaded from disk, frames from the device\'s camera, or other
|
||||
video streams.
|
||||
|
||||
</p>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
BIN
samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png
Normal file
BIN
samples/browseable/MediaEffects/res/drawable-hdpi/tile.9.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 196 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg
Normal file
BIN
samples/browseable/MediaEffects/res/drawable-nodpi/puppy.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 72 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
73
samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml
Executable file
73
samples/browseable/MediaEffects/res/layout-w720dp/activity_main.xml
Executable file
@@ -0,0 +1,73 @@
|
||||
<!--
|
||||
Copyright 2013 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.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/sample_main_layout">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/sample_output"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<FrameLayout
|
||||
style="@style/Widget.SampleMessageTile"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
style="@style/Widget.SampleMessage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/margin_medium"
|
||||
android:paddingRight="@dimen/margin_medium"
|
||||
android:paddingTop="@dimen/margin_large"
|
||||
android:paddingBottom="@dimen/margin_large"
|
||||
android:text="@string/intro_message" />
|
||||
</FrameLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/darker_gray" />
|
||||
|
||||
<fragment
|
||||
android:name="com.example.android.common.logger.LogFragment"
|
||||
android:id="@+id/log_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0px"
|
||||
android:layout_weight="1" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/darker_gray" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/sample_content_fragment"
|
||||
android:layout_weight="2"
|
||||
android:layout_width="0px"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
65
samples/browseable/MediaEffects/res/layout/activity_main.xml
Executable file
65
samples/browseable/MediaEffects/res/layout/activity_main.xml
Executable file
@@ -0,0 +1,65 @@
|
||||
<!--
|
||||
Copyright 2013 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.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/sample_main_layout">
|
||||
|
||||
<ViewAnimator
|
||||
android:id="@+id/sample_output"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0px"
|
||||
android:layout_weight="1">
|
||||
|
||||
<ScrollView
|
||||
style="@style/Widget.SampleMessageTile"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
style="@style/Widget.SampleMessage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="@dimen/horizontal_page_margin"
|
||||
android:paddingRight="@dimen/horizontal_page_margin"
|
||||
android:paddingTop="@dimen/vertical_page_margin"
|
||||
android:paddingBottom="@dimen/vertical_page_margin"
|
||||
android:text="@string/intro_message" />
|
||||
</ScrollView>
|
||||
|
||||
<fragment
|
||||
android:name="com.example.android.common.logger.LogFragment"
|
||||
android:id="@+id/log_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</ViewAnimator>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/darker_gray" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/sample_content_fragment"
|
||||
android:layout_weight="2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0px" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 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.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.opengl.GLSurfaceView
|
||||
android:id="@+id/effectsview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0.93"/>
|
||||
</LinearLayout>
|
||||
21
samples/browseable/MediaEffects/res/menu/main.xml
Normal file
21
samples/browseable/MediaEffects/res/menu/main.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2013 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.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/menu_toggle_log"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/sample_show_log" />
|
||||
</menu>
|
||||
112
samples/browseable/MediaEffects/res/menu/media_effects.xml
Normal file
112
samples/browseable/MediaEffects/res/menu/media_effects.xml
Normal file
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 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.
|
||||
-->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@+id/none"
|
||||
android:title="@string/none"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/autofix"
|
||||
android:title="@string/autofix"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/bw"
|
||||
android:title="@string/bw"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/brightness"
|
||||
android:title="@string/brightness"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/contrast"
|
||||
android:title="@string/contrast"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/crossprocess"
|
||||
android:title="@string/crossprocess"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/documentary"
|
||||
android:title="@string/documentary"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/duotone"
|
||||
android:title="@string/duotone"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/filllight"
|
||||
android:title="@string/filllight"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/fisheye"
|
||||
android:title="@string/fisheye"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/flipvert"
|
||||
android:title="@string/flipvert"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/fliphor"
|
||||
android:title="@string/fliphor"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/grain"
|
||||
android:title="@string/grain"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/grayscale"
|
||||
android:title="@string/grayscale"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/lomoish"
|
||||
android:title="@string/lomoish"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/negative"
|
||||
android:title="@string/negative"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/posterize"
|
||||
android:title="@string/posterize"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/rotate"
|
||||
android:title="@string/rotate"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/saturate"
|
||||
android:title="@string/saturate"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/sepia"
|
||||
android:title="@string/sepia"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/sharpen"
|
||||
android:title="@string/sharpen"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/temperature"
|
||||
android:title="@string/temperature"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/tint"
|
||||
android:title="@string/tint"
|
||||
android:showAsAction="never" />
|
||||
|
||||
<item android:id="@+id/vignette"
|
||||
android:title="@string/vignette"
|
||||
android:showAsAction="never" />
|
||||
</menu>
|
||||
@@ -0,0 +1,24 @@
|
||||
<!--
|
||||
Copyright 2013 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>
|
||||
|
||||
<!-- Semantic definitions -->
|
||||
|
||||
<dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
|
||||
<dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright 2013 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="Widget.SampleMessage">
|
||||
<item name="android:textAppearance">?android:textAppearanceLarge</item>
|
||||
<item name="android:lineSpacingMultiplier">1.2</item>
|
||||
<item name="android:shadowDy">-6.5</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,22 @@
|
||||
<!--
|
||||
Copyright 2013 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>
|
||||
|
||||
<!-- Activity themes -->
|
||||
<style name="Theme.Base" parent="android:Theme.Holo.Light" />
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,22 @@
|
||||
<!--
|
||||
Copyright 2014 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>
|
||||
|
||||
<!-- Activity themes -->
|
||||
<style name="Theme.Base" parent="android:Theme.Material.Light" />
|
||||
|
||||
</resources>
|
||||
31
samples/browseable/MediaEffects/res/values/base-strings.xml
Normal file
31
samples/browseable/MediaEffects/res/values/base-strings.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2013 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>
|
||||
<string name="app_name">MediaEffects</string>
|
||||
<string name="intro_message">
|
||||
<![CDATA[
|
||||
|
||||
|
||||
This sample shows how to use the Media Effects APIs that were introduced in Android 4.0.
|
||||
These APIs let you apply effects to image frames represented as OpenGL ES 2.0 textures.
|
||||
Image frames can be images loaded from disk, frames from the device\'s camera, or other
|
||||
video streams.
|
||||
|
||||
|
||||
]]>
|
||||
</string>
|
||||
</resources>
|
||||
19
samples/browseable/MediaEffects/res/values/fragmentview_strings.xml
Executable file
19
samples/browseable/MediaEffects/res/values/fragmentview_strings.xml
Executable file
@@ -0,0 +1,19 @@
|
||||
<!--
|
||||
Copyright 2013 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>
|
||||
<string name="sample_show_log">Show Log</string>
|
||||
<string name="sample_hide_log">Hide Log</string>
|
||||
</resources>
|
||||
41
samples/browseable/MediaEffects/res/values/strings.xml
Normal file
41
samples/browseable/MediaEffects/res/values/strings.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 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>
|
||||
<string name="none">None</string>
|
||||
<string name="autofix">Autofix</string>
|
||||
<string name="bw">Min/Max Color Intensity</string>
|
||||
<string name="brightness">Brightness</string>
|
||||
<string name="contrast">Contrast</string>
|
||||
<string name="crossprocess">Cross Process</string>
|
||||
<string name="documentary">Documentary</string>
|
||||
<string name="duotone">Duo Tone</string>
|
||||
<string name="filllight">Fill Light</string>
|
||||
<string name="fisheye">Fish Eye</string>
|
||||
<string name="flipvert">Flip Vertical</string>
|
||||
<string name="fliphor">Flip Horizontal</string>
|
||||
<string name="grain">Grain</string>
|
||||
<string name="grayscale">Grayscale</string>
|
||||
<string name="lomoish">Lomoish</string>
|
||||
<string name="negative">Negative</string>
|
||||
<string name="posterize">Posterize</string>
|
||||
<string name="rotate">Rotate</string>
|
||||
<string name="saturate">Saturate</string>
|
||||
<string name="sepia">Sepia</string>
|
||||
<string name="sharpen">Sharpen</string>
|
||||
<string name="temperature">Temperature</string>
|
||||
<string name="tint">Tint</string>
|
||||
<string name="vignette">Vignette</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,32 @@
|
||||
<!--
|
||||
Copyright 2013 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>
|
||||
|
||||
<!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
|
||||
|
||||
<dimen name="margin_tiny">4dp</dimen>
|
||||
<dimen name="margin_small">8dp</dimen>
|
||||
<dimen name="margin_medium">16dp</dimen>
|
||||
<dimen name="margin_large">32dp</dimen>
|
||||
<dimen name="margin_huge">64dp</dimen>
|
||||
|
||||
<!-- Semantic definitions -->
|
||||
|
||||
<dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
|
||||
<dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,42 @@
|
||||
<!--
|
||||
Copyright 2013 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>
|
||||
|
||||
<!-- Activity themes -->
|
||||
|
||||
<style name="Theme.Base" parent="android:Theme.Light" />
|
||||
|
||||
<style name="Theme.Sample" parent="Theme.Base" />
|
||||
|
||||
<style name="AppTheme" parent="Theme.Sample" />
|
||||
<!-- Widget styling -->
|
||||
|
||||
<style name="Widget" />
|
||||
|
||||
<style name="Widget.SampleMessage">
|
||||
<item name="android:textAppearance">?android:textAppearanceMedium</item>
|
||||
<item name="android:lineSpacingMultiplier">1.1</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.SampleMessageTile">
|
||||
<item name="android:background">@drawable/tile</item>
|
||||
<item name="android:shadowColor">#7F000000</item>
|
||||
<item name="android:shadowDy">-3.5</item>
|
||||
<item name="android:shadowRadius">2</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2013 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.example.android.common.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import com.example.android.common.logger.Log;
|
||||
import com.example.android.common.logger.LogWrapper;
|
||||
|
||||
/**
|
||||
* Base launcher activity, to handle most of the common plumbing for samples.
|
||||
*/
|
||||
public class SampleActivityBase extends FragmentActivity {
|
||||
|
||||
public static final String TAG = "SampleActivityBase";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
initializeLogging();
|
||||
}
|
||||
|
||||
/** Set up targets to receive log data */
|
||||
public void initializeLogging() {
|
||||
// Using Log, front-end to the logging chain, emulates android.util.log method signatures.
|
||||
// Wraps Android's native log framework
|
||||
LogWrapper logWrapper = new LogWrapper();
|
||||
Log.setLogNode(logWrapper);
|
||||
|
||||
Log.i(TAG, "Ready");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.example.android.common.logger;
|
||||
|
||||
/**
|
||||
* Helper class for a list (or tree) of LoggerNodes.
|
||||
*
|
||||
* <p>When this is set as the head of the list,
|
||||
* an instance of it can function as a drop-in replacement for {@link android.util.Log}.
|
||||
* Most of the methods in this class server only to map a method call in Log to its equivalent
|
||||
* in LogNode.</p>
|
||||
*/
|
||||
public class Log {
|
||||
// Grabbing the native values from Android's native logging facilities,
|
||||
// to make for easy migration and interop.
|
||||
public static final int NONE = -1;
|
||||
public static final int VERBOSE = android.util.Log.VERBOSE;
|
||||
public static final int DEBUG = android.util.Log.DEBUG;
|
||||
public static final int INFO = android.util.Log.INFO;
|
||||
public static final int WARN = android.util.Log.WARN;
|
||||
public static final int ERROR = android.util.Log.ERROR;
|
||||
public static final int ASSERT = android.util.Log.ASSERT;
|
||||
|
||||
// Stores the beginning of the LogNode topology.
|
||||
private static LogNode mLogNode;
|
||||
|
||||
/**
|
||||
* Returns the next LogNode in the linked list.
|
||||
*/
|
||||
public static LogNode getLogNode() {
|
||||
return mLogNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the LogNode data will be sent to.
|
||||
*/
|
||||
public static void setLogNode(LogNode node) {
|
||||
mLogNode = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the LogNode to print the log data provided. Other LogNodes can
|
||||
* be chained to the end of the LogNode as desired.
|
||||
*
|
||||
* @param priority Log level of the data being logged. Verbose, Error, etc.
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void println(int priority, String tag, String msg, Throwable tr) {
|
||||
if (mLogNode != null) {
|
||||
mLogNode.println(priority, tag, msg, tr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the LogNode to print the log data provided. Other LogNodes can
|
||||
* be chained to the end of the LogNode as desired.
|
||||
*
|
||||
* @param priority Log level of the data being logged. Verbose, Error, etc.
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged. The actual message to be logged.
|
||||
*/
|
||||
public static void println(int priority, String tag, String msg) {
|
||||
println(priority, tag, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at VERBOSE priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void v(String tag, String msg, Throwable tr) {
|
||||
println(VERBOSE, tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at VERBOSE priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
*/
|
||||
public static void v(String tag, String msg) {
|
||||
v(tag, msg, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints a message at DEBUG priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void d(String tag, String msg, Throwable tr) {
|
||||
println(DEBUG, tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at DEBUG priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
*/
|
||||
public static void d(String tag, String msg) {
|
||||
d(tag, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at INFO priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void i(String tag, String msg, Throwable tr) {
|
||||
println(INFO, tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at INFO priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
*/
|
||||
public static void i(String tag, String msg) {
|
||||
i(tag, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at WARN priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void w(String tag, String msg, Throwable tr) {
|
||||
println(WARN, tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at WARN priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
*/
|
||||
public static void w(String tag, String msg) {
|
||||
w(tag, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at WARN priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void w(String tag, Throwable tr) {
|
||||
w(tag, null, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at ERROR priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void e(String tag, String msg, Throwable tr) {
|
||||
println(ERROR, tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at ERROR priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
*/
|
||||
public static void e(String tag, String msg) {
|
||||
e(tag, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at ASSERT priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void wtf(String tag, String msg, Throwable tr) {
|
||||
println(ASSERT, tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at ASSERT priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged.
|
||||
*/
|
||||
public static void wtf(String tag, String msg) {
|
||||
wtf(tag, msg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints a message at ASSERT priority.
|
||||
*
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public static void wtf(String tag, Throwable tr) {
|
||||
wtf(tag, null, tr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2013 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.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2013 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.example.android.common.logger;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ScrollView;
|
||||
|
||||
/**
|
||||
* Simple fraggment which contains a LogView and uses is to output log data it receives
|
||||
* through the LogNode interface.
|
||||
*/
|
||||
public class LogFragment extends Fragment {
|
||||
|
||||
private LogView mLogView;
|
||||
private ScrollView mScrollView;
|
||||
|
||||
public LogFragment() {}
|
||||
|
||||
public View inflateViews() {
|
||||
mScrollView = new ScrollView(getActivity());
|
||||
ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
mScrollView.setLayoutParams(scrollParams);
|
||||
|
||||
mLogView = new LogView(getActivity());
|
||||
ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
|
||||
logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
mLogView.setLayoutParams(logParams);
|
||||
mLogView.setClickable(true);
|
||||
mLogView.setFocusable(true);
|
||||
mLogView.setTypeface(Typeface.MONOSPACE);
|
||||
|
||||
// Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
|
||||
int paddingDips = 16;
|
||||
double scale = getResources().getDisplayMetrics().density;
|
||||
int paddingPixels = (int) ((paddingDips * (scale)) + .5);
|
||||
mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
|
||||
mLogView.setCompoundDrawablePadding(paddingPixels);
|
||||
|
||||
mLogView.setGravity(Gravity.BOTTOM);
|
||||
mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
|
||||
|
||||
mScrollView.addView(mLogView);
|
||||
return mScrollView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View result = inflateViews();
|
||||
|
||||
mLogView.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public LogView getLogView() {
|
||||
return mLogView;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.example.android.common.logger;
|
||||
|
||||
/**
|
||||
* Basic interface for a logging system that can output to one or more targets.
|
||||
* Note that in addition to classes that will output these logs in some format,
|
||||
* one can also implement this interface over a filter and insert that in the chain,
|
||||
* such that no targets further down see certain data, or see manipulated forms of the data.
|
||||
* You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
|
||||
* it received to HTML and sent it along to the next node in the chain, without printing it
|
||||
* anywhere.
|
||||
*/
|
||||
public interface LogNode {
|
||||
|
||||
/**
|
||||
* Instructs first LogNode in the list to print the log data provided.
|
||||
* @param priority Log level of the data being logged. Verbose, Error, etc.
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged. The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
public void println(int priority, String tag, String msg, Throwable tr);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.example.android.common.logger;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.*;
|
||||
import android.widget.TextView;
|
||||
|
||||
/** Simple TextView which is used to output log data received through the LogNode interface.
|
||||
*/
|
||||
public class LogView extends TextView implements LogNode {
|
||||
|
||||
public LogView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public LogView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public LogView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the log data and prints it out to the LogView.
|
||||
* @param priority Log level of the data being logged. Verbose, Error, etc.
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged. The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
@Override
|
||||
public void println(int priority, String tag, String msg, Throwable tr) {
|
||||
|
||||
|
||||
String priorityStr = null;
|
||||
|
||||
// For the purposes of this View, we want to print the priority as readable text.
|
||||
switch(priority) {
|
||||
case android.util.Log.VERBOSE:
|
||||
priorityStr = "VERBOSE";
|
||||
break;
|
||||
case android.util.Log.DEBUG:
|
||||
priorityStr = "DEBUG";
|
||||
break;
|
||||
case android.util.Log.INFO:
|
||||
priorityStr = "INFO";
|
||||
break;
|
||||
case android.util.Log.WARN:
|
||||
priorityStr = "WARN";
|
||||
break;
|
||||
case android.util.Log.ERROR:
|
||||
priorityStr = "ERROR";
|
||||
break;
|
||||
case android.util.Log.ASSERT:
|
||||
priorityStr = "ASSERT";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Handily, the Log class has a facility for converting a stack trace into a usable string.
|
||||
String exceptionStr = null;
|
||||
if (tr != null) {
|
||||
exceptionStr = android.util.Log.getStackTraceString(tr);
|
||||
}
|
||||
|
||||
// Take the priority, tag, message, and exception, and concatenate as necessary
|
||||
// into one usable line of text.
|
||||
final StringBuilder outputBuilder = new StringBuilder();
|
||||
|
||||
String delimiter = "\t";
|
||||
appendIfNotNull(outputBuilder, priorityStr, delimiter);
|
||||
appendIfNotNull(outputBuilder, tag, delimiter);
|
||||
appendIfNotNull(outputBuilder, msg, delimiter);
|
||||
appendIfNotNull(outputBuilder, exceptionStr, delimiter);
|
||||
|
||||
// In case this was originally called from an AsyncTask or some other off-UI thread,
|
||||
// make sure the update occurs within the UI thread.
|
||||
((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Display the text we just generated within the LogView.
|
||||
appendToLog(outputBuilder.toString());
|
||||
}
|
||||
})));
|
||||
|
||||
if (mNext != null) {
|
||||
mNext.println(priority, tag, msg, tr);
|
||||
}
|
||||
}
|
||||
|
||||
public LogNode getNext() {
|
||||
return mNext;
|
||||
}
|
||||
|
||||
public void setNext(LogNode node) {
|
||||
mNext = node;
|
||||
}
|
||||
|
||||
/** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
|
||||
* the logger takes so many arguments that might be null, this method helps cut out some of the
|
||||
* agonizing tedium of writing the same 3 lines over and over.
|
||||
* @param source StringBuilder containing the text to append to.
|
||||
* @param addStr The String to append
|
||||
* @param delimiter The String to separate the source and appended strings. A tab or comma,
|
||||
* for instance.
|
||||
* @return The fully concatenated String as a StringBuilder
|
||||
*/
|
||||
private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
|
||||
if (addStr != null) {
|
||||
if (addStr.length() == 0) {
|
||||
delimiter = "";
|
||||
}
|
||||
|
||||
return source.append(addStr).append(delimiter);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
// The next LogNode in the chain.
|
||||
LogNode mNext;
|
||||
|
||||
/** Outputs the string as a new line of log data in the LogView. */
|
||||
public void appendToLog(String s) {
|
||||
append("\n" + s);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.example.android.common.logger;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Helper class which wraps Android's native Log utility in the Logger interface. This way
|
||||
* normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
|
||||
*/
|
||||
public class LogWrapper implements LogNode {
|
||||
|
||||
// For piping: The next node to receive Log data after this one has done its work.
|
||||
private LogNode mNext;
|
||||
|
||||
/**
|
||||
* Returns the next LogNode in the linked list.
|
||||
*/
|
||||
public LogNode getNext() {
|
||||
return mNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the LogNode data will be sent to..
|
||||
*/
|
||||
public void setNext(LogNode node) {
|
||||
mNext = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints data out to the console using Android's native log mechanism.
|
||||
* @param priority Log level of the data being logged. Verbose, Error, etc.
|
||||
* @param tag Tag for for the log data. Can be used to organize log statements.
|
||||
* @param msg The actual message to be logged. The actual message to be logged.
|
||||
* @param tr If an exception was thrown, this can be sent along for the logging facilities
|
||||
* to extract and print useful information.
|
||||
*/
|
||||
@Override
|
||||
public void println(int priority, String tag, String msg, Throwable tr) {
|
||||
// There actually are log methods that don't take a msg parameter. For now,
|
||||
// if that's the case, just convert null to the empty string and move on.
|
||||
String useMsg = msg;
|
||||
if (useMsg == null) {
|
||||
useMsg = "";
|
||||
}
|
||||
|
||||
// If an exeption was provided, convert that exception to a usable string and attach
|
||||
// it to the end of the msg method.
|
||||
if (tr != null) {
|
||||
msg += "\n" + Log.getStackTraceString(tr);
|
||||
}
|
||||
|
||||
// This is functionally identical to Log.x(tag, useMsg);
|
||||
// For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
|
||||
Log.println(priority, tag, useMsg);
|
||||
|
||||
// If this isn't the last node in the chain, move things along.
|
||||
if (mNext != null) {
|
||||
mNext.println(priority, tag, msg, tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2013 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.example.android.common.logger;
|
||||
|
||||
/**
|
||||
* Simple {@link LogNode} filter, removes everything except the message.
|
||||
* Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
|
||||
* just easy-to-read message updates as they're happening.
|
||||
*/
|
||||
public class MessageOnlyLogFilter implements LogNode {
|
||||
|
||||
LogNode mNext;
|
||||
|
||||
/**
|
||||
* Takes the "next" LogNode as a parameter, to simplify chaining.
|
||||
*
|
||||
* @param next The next LogNode in the pipeline.
|
||||
*/
|
||||
public MessageOnlyLogFilter(LogNode next) {
|
||||
mNext = next;
|
||||
}
|
||||
|
||||
public MessageOnlyLogFilter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(int priority, String tag, String msg, Throwable tr) {
|
||||
if (mNext != null) {
|
||||
getNext().println(Log.NONE, null, msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next LogNode in the chain.
|
||||
*/
|
||||
public LogNode getNext() {
|
||||
return mNext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the LogNode data will be sent to..
|
||||
*/
|
||||
public void setNext(LogNode node) {
|
||||
mNext = node;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.example.android.mediaeffects;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
public class GLToolbox {
|
||||
|
||||
public static int loadShader(int shaderType, String source) {
|
||||
int shader = GLES20.glCreateShader(shaderType);
|
||||
if (shader != 0) {
|
||||
GLES20.glShaderSource(shader, source);
|
||||
GLES20.glCompileShader(shader);
|
||||
int[] compiled = new int[1];
|
||||
GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
|
||||
if (compiled[0] == 0) {
|
||||
String info = GLES20.glGetShaderInfoLog(shader);
|
||||
GLES20.glDeleteShader(shader);
|
||||
throw new RuntimeException("Could not compile shader " + shaderType + ":" + info);
|
||||
}
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
public static int createProgram(String vertexSource, String fragmentSource) {
|
||||
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
|
||||
if (vertexShader == 0) {
|
||||
return 0;
|
||||
}
|
||||
int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
|
||||
if (pixelShader == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int program = GLES20.glCreateProgram();
|
||||
if (program != 0) {
|
||||
GLES20.glAttachShader(program, vertexShader);
|
||||
checkGlError("glAttachShader");
|
||||
GLES20.glAttachShader(program, pixelShader);
|
||||
checkGlError("glAttachShader");
|
||||
GLES20.glLinkProgram(program);
|
||||
int[] linkStatus = new int[1];
|
||||
GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus,
|
||||
0);
|
||||
if (linkStatus[0] != GLES20.GL_TRUE) {
|
||||
String info = GLES20.glGetProgramInfoLog(program);
|
||||
GLES20.glDeleteProgram(program);
|
||||
throw new RuntimeException("Could not link program: " + info);
|
||||
}
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
public static void checkGlError(String op) {
|
||||
int error;
|
||||
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
|
||||
throw new RuntimeException(op + ": glError " + error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initTexParams() {
|
||||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
|
||||
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
|
||||
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
|
||||
GLES20.GL_TEXTURE_MIN_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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2013 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.example.android.mediaeffects;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.ViewAnimator;
|
||||
|
||||
import com.example.android.common.activities.SampleActivityBase;
|
||||
import com.example.android.common.logger.Log;
|
||||
import com.example.android.common.logger.LogFragment;
|
||||
import com.example.android.common.logger.LogWrapper;
|
||||
import com.example.android.common.logger.MessageOnlyLogFilter;
|
||||
|
||||
/**
|
||||
* A simple launcher activity containing a summary sample description, sample log and a custom
|
||||
* {@link android.support.v4.app.Fragment} which can display a view.
|
||||
* <p>
|
||||
* For devices with displays with a width of 720dp or greater, the sample log is always visible,
|
||||
* on other devices it's visibility is controlled by an item on the Action Bar.
|
||||
*/
|
||||
public class MainActivity extends SampleActivityBase {
|
||||
|
||||
public static final String TAG = "MainActivity";
|
||||
|
||||
// Whether the Log Fragment is currently shown
|
||||
private boolean mLogShown;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
MediaEffectsFragment fragment = new MediaEffectsFragment();
|
||||
transaction.replace(R.id.sample_content_fragment, fragment);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
|
||||
logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
|
||||
logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_toggle_log:
|
||||
mLogShown = !mLogShown;
|
||||
ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output);
|
||||
if (mLogShown) {
|
||||
output.setDisplayedChild(1);
|
||||
} else {
|
||||
output.setDisplayedChild(0);
|
||||
}
|
||||
supportInvalidateOptionsMenu();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/** Create a chain of targets that will receive log data */
|
||||
@Override
|
||||
public void initializeLogging() {
|
||||
// Wraps Android's native log framework.
|
||||
LogWrapper logWrapper = new LogWrapper();
|
||||
// Using Log, front-end to the logging chain, emulates android.util.log method signatures.
|
||||
Log.setLogNode(logWrapper);
|
||||
|
||||
// Filter strips out everything except the message text.
|
||||
MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
|
||||
logWrapper.setNext(msgFilter);
|
||||
|
||||
// On screen logging via a fragment with a TextView.
|
||||
LogFragment logFragment = (LogFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.log_fragment);
|
||||
msgFilter.setNext(logFragment.getLogView());
|
||||
|
||||
Log.i(TAG, "Ready");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.example.android.mediaeffects;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.media.effect.Effect;
|
||||
import android.media.effect.EffectContext;
|
||||
import android.media.effect.EffectFactory;
|
||||
import android.opengl.GLES20;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.opengl.GLUtils;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
public class MediaEffectsFragment extends Fragment implements GLSurfaceView.Renderer {
|
||||
|
||||
private static final String STATE_CURRENT_EFFECT = "current_effect";
|
||||
|
||||
private GLSurfaceView mEffectView;
|
||||
private int[] mTextures = new int[2];
|
||||
private EffectContext mEffectContext;
|
||||
private Effect mEffect;
|
||||
private TextureRenderer mTexRenderer = new TextureRenderer();
|
||||
private int mImageWidth;
|
||||
private int mImageHeight;
|
||||
private boolean mInitialized = false;
|
||||
private int mCurrentEffect;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_media_effects, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
mEffectView = (GLSurfaceView) view.findViewById(R.id.effectsview);
|
||||
mEffectView.setEGLContextClientVersion(2);
|
||||
mEffectView.setRenderer(this);
|
||||
mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
||||
if (null != savedInstanceState && savedInstanceState.containsKey(STATE_CURRENT_EFFECT)) {
|
||||
setCurrentEffect(savedInstanceState.getInt(STATE_CURRENT_EFFECT));
|
||||
} else {
|
||||
setCurrentEffect(R.id.none);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.media_effects, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
setCurrentEffect(item.getItemId());
|
||||
mEffectView.requestRender();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(STATE_CURRENT_EFFECT, mCurrentEffect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
if (mTexRenderer != null) {
|
||||
mTexRenderer.updateViewSize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
if (!mInitialized) {
|
||||
//Only need to do this once
|
||||
mEffectContext = EffectContext.createWithCurrentGlContext();
|
||||
mTexRenderer.init();
|
||||
loadTextures();
|
||||
mInitialized = true;
|
||||
}
|
||||
if (mCurrentEffect != R.id.none) {
|
||||
//if an effect is chosen initialize it and apply it to the texture
|
||||
initEffect();
|
||||
applyEffect();
|
||||
}
|
||||
renderResult();
|
||||
}
|
||||
|
||||
private void setCurrentEffect(int effect) {
|
||||
mCurrentEffect = effect;
|
||||
}
|
||||
|
||||
private void loadTextures() {
|
||||
// Generate textures
|
||||
GLES20.glGenTextures(2, mTextures, 0);
|
||||
|
||||
// Load input bitmap
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.puppy);
|
||||
mImageWidth = bitmap.getWidth();
|
||||
mImageHeight = bitmap.getHeight();
|
||||
mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);
|
||||
|
||||
// Upload to texture
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
|
||||
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
|
||||
|
||||
// Set texture parameters
|
||||
GLToolbox.initTexParams();
|
||||
}
|
||||
|
||||
private void initEffect() {
|
||||
EffectFactory effectFactory = mEffectContext.getFactory();
|
||||
if (mEffect != null) {
|
||||
mEffect.release();
|
||||
}
|
||||
// Initialize the correct effect based on the selected menu/action item
|
||||
switch (mCurrentEffect) {
|
||||
|
||||
case R.id.none:
|
||||
break;
|
||||
|
||||
case R.id.autofix:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX);
|
||||
mEffect.setParameter("scale", 0.5f);
|
||||
break;
|
||||
|
||||
case R.id.bw:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BLACKWHITE);
|
||||
mEffect.setParameter("black", .1f);
|
||||
mEffect.setParameter("white", .7f);
|
||||
break;
|
||||
|
||||
case R.id.brightness:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BRIGHTNESS);
|
||||
mEffect.setParameter("brightness", 2.0f);
|
||||
break;
|
||||
|
||||
case R.id.contrast:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CONTRAST);
|
||||
mEffect.setParameter("contrast", 1.4f);
|
||||
break;
|
||||
|
||||
case R.id.crossprocess:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CROSSPROCESS);
|
||||
break;
|
||||
|
||||
case R.id.documentary:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DOCUMENTARY);
|
||||
break;
|
||||
|
||||
case R.id.duotone:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DUOTONE);
|
||||
mEffect.setParameter("first_color", Color.YELLOW);
|
||||
mEffect.setParameter("second_color", Color.DKGRAY);
|
||||
break;
|
||||
|
||||
case R.id.filllight:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FILLLIGHT);
|
||||
mEffect.setParameter("strength", .8f);
|
||||
break;
|
||||
|
||||
case R.id.fisheye:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE);
|
||||
mEffect.setParameter("scale", .5f);
|
||||
break;
|
||||
|
||||
case R.id.flipvert:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
|
||||
mEffect.setParameter("vertical", true);
|
||||
break;
|
||||
|
||||
case R.id.fliphor:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
|
||||
mEffect.setParameter("horizontal", true);
|
||||
break;
|
||||
|
||||
case R.id.grain:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN);
|
||||
mEffect.setParameter("strength", 1.0f);
|
||||
break;
|
||||
|
||||
case R.id.grayscale:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAYSCALE);
|
||||
break;
|
||||
|
||||
case R.id.lomoish:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_LOMOISH);
|
||||
break;
|
||||
|
||||
case R.id.negative:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE);
|
||||
break;
|
||||
|
||||
case R.id.posterize:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_POSTERIZE);
|
||||
break;
|
||||
|
||||
case R.id.rotate:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_ROTATE);
|
||||
mEffect.setParameter("angle", 180);
|
||||
break;
|
||||
|
||||
case R.id.saturate:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SATURATE);
|
||||
mEffect.setParameter("scale", .5f);
|
||||
break;
|
||||
|
||||
case R.id.sepia:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SEPIA);
|
||||
break;
|
||||
|
||||
case R.id.sharpen:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SHARPEN);
|
||||
break;
|
||||
|
||||
case R.id.temperature:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TEMPERATURE);
|
||||
mEffect.setParameter("scale", .9f);
|
||||
break;
|
||||
|
||||
case R.id.tint:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
|
||||
mEffect.setParameter("tint", Color.MAGENTA);
|
||||
break;
|
||||
|
||||
case R.id.vignette:
|
||||
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_VIGNETTE);
|
||||
mEffect.setParameter("scale", .5f);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyEffect() {
|
||||
mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
|
||||
}
|
||||
|
||||
private void renderResult() {
|
||||
if (mCurrentEffect != R.id.none) {
|
||||
// if no effect is chosen, just render the original bitmap
|
||||
mTexRenderer.renderTexture(mTextures[1]);
|
||||
} else {
|
||||
// render the result of applyEffect()
|
||||
mTexRenderer.renderTexture(mTextures[0]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.example.android.mediaeffects;
|
||||
|
||||
import android.opengl.GLES20;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
|
||||
public class TextureRenderer {
|
||||
|
||||
private int mProgram;
|
||||
private int mTexSamplerHandle;
|
||||
private int mTexCoordHandle;
|
||||
private int mPosCoordHandle;
|
||||
|
||||
private FloatBuffer mTexVertices;
|
||||
private FloatBuffer mPosVertices;
|
||||
|
||||
private int mViewWidth;
|
||||
private int mViewHeight;
|
||||
|
||||
private int mTexWidth;
|
||||
private int mTexHeight;
|
||||
|
||||
private static final String VERTEX_SHADER =
|
||||
"attribute vec4 a_position;\n" +
|
||||
"attribute vec2 a_texcoord;\n" +
|
||||
"varying vec2 v_texcoord;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_Position = a_position;\n" +
|
||||
" v_texcoord = a_texcoord;\n" +
|
||||
"}\n";
|
||||
|
||||
private static final String FRAGMENT_SHADER =
|
||||
"precision mediump float;\n" +
|
||||
"uniform sampler2D tex_sampler;\n" +
|
||||
"varying vec2 v_texcoord;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_FragColor = texture2D(tex_sampler, v_texcoord);\n" +
|
||||
"}\n";
|
||||
|
||||
private static final float[] TEX_VERTICES = {
|
||||
0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
private static final float[] POS_VERTICES = {
|
||||
-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f
|
||||
};
|
||||
|
||||
private static final int FLOAT_SIZE_BYTES = 4;
|
||||
|
||||
public void init() {
|
||||
// Create program
|
||||
mProgram = GLToolbox.createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
|
||||
|
||||
// Bind attributes and uniforms
|
||||
mTexSamplerHandle = GLES20.glGetUniformLocation(mProgram,
|
||||
"tex_sampler");
|
||||
mTexCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_texcoord");
|
||||
mPosCoordHandle = GLES20.glGetAttribLocation(mProgram, "a_position");
|
||||
|
||||
// Setup coordinate buffers
|
||||
mTexVertices = ByteBuffer.allocateDirect(
|
||||
TEX_VERTICES.length * FLOAT_SIZE_BYTES)
|
||||
.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
||||
mTexVertices.put(TEX_VERTICES).position(0);
|
||||
mPosVertices = ByteBuffer.allocateDirect(
|
||||
POS_VERTICES.length * FLOAT_SIZE_BYTES)
|
||||
.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
||||
mPosVertices.put(POS_VERTICES).position(0);
|
||||
}
|
||||
|
||||
public void tearDown() {
|
||||
GLES20.glDeleteProgram(mProgram);
|
||||
}
|
||||
|
||||
public void updateTextureSize(int texWidth, int texHeight) {
|
||||
mTexWidth = texWidth;
|
||||
mTexHeight = texHeight;
|
||||
computeOutputVertices();
|
||||
}
|
||||
|
||||
public void updateViewSize(int viewWidth, int viewHeight) {
|
||||
mViewWidth = viewWidth;
|
||||
mViewHeight = viewHeight;
|
||||
computeOutputVertices();
|
||||
}
|
||||
|
||||
public void renderTexture(int texId) {
|
||||
// Bind default FBO
|
||||
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
|
||||
|
||||
// Use our shader program
|
||||
GLES20.glUseProgram(mProgram);
|
||||
GLToolbox.checkGlError("glUseProgram");
|
||||
|
||||
// Set viewport
|
||||
GLES20.glViewport(0, 0, mViewWidth, mViewHeight);
|
||||
GLToolbox.checkGlError("glViewport");
|
||||
|
||||
// Disable blending
|
||||
GLES20.glDisable(GLES20.GL_BLEND);
|
||||
|
||||
// Set the vertex attributes
|
||||
GLES20.glVertexAttribPointer(mTexCoordHandle, 2, GLES20.GL_FLOAT, false,
|
||||
0, mTexVertices);
|
||||
GLES20.glEnableVertexAttribArray(mTexCoordHandle);
|
||||
GLES20.glVertexAttribPointer(mPosCoordHandle, 2, GLES20.GL_FLOAT, false,
|
||||
0, mPosVertices);
|
||||
GLES20.glEnableVertexAttribArray(mPosCoordHandle);
|
||||
GLToolbox.checkGlError("vertex attribute setup");
|
||||
|
||||
// Set the input texture
|
||||
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
|
||||
GLToolbox.checkGlError("glActiveTexture");
|
||||
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);
|
||||
GLToolbox.checkGlError("glBindTexture");
|
||||
GLES20.glUniform1i(mTexSamplerHandle, 0);
|
||||
|
||||
// Draw
|
||||
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
|
||||
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
private void computeOutputVertices() {
|
||||
if (mPosVertices != null) {
|
||||
float imgAspectRatio = mTexWidth / (float)mTexHeight;
|
||||
float viewAspectRatio = mViewWidth / (float)mViewHeight;
|
||||
float relativeAspectRatio = viewAspectRatio / imgAspectRatio;
|
||||
float x0, y0, x1, y1;
|
||||
if (relativeAspectRatio > 1.0f) {
|
||||
x0 = -1.0f / relativeAspectRatio;
|
||||
y0 = -1.0f;
|
||||
x1 = 1.0f / relativeAspectRatio;
|
||||
y1 = 1.0f;
|
||||
} else {
|
||||
x0 = -1.0f;
|
||||
y0 = -relativeAspectRatio;
|
||||
x1 = 1.0f;
|
||||
y1 = relativeAspectRatio;
|
||||
}
|
||||
float[] coords = new float[] { x0, y0, x1, y0, x0, y1, x1, y1 };
|
||||
mPosVertices.put(coords).position(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user