aboutsummaryrefslogtreecommitdiff
path: root/renderScript
diff options
context:
space:
mode:
authorHak Matsuda <hakuro@google.com>2014-01-27 17:50:20 -0800
committerHak Matsuda <hakuro@google.com>2014-02-06 12:34:33 -0800
commit19b8151afc6bc3d025eec92281bbde5b96857377 (patch)
tree08e23191e8a8e43baeafccc3d9fb1566aa6f8ad4 /renderScript
parent521559ef2de2797e9b8fba0f4cd741975e0fcd5b (diff)
downloadandroid-19b8151afc6bc3d025eec92281bbde5b96857377.tar.gz
BasicRenderScript sample, initial check in
Now sample template compatible, in KLP-DEV branch. Change-Id: Id3f31f9d56a908098aa9a76bef6f944416bff6fe
Diffstat (limited to 'renderScript')
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/.gitignore16
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/AndroidManifest.xml29
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/build.gradle67
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/project.properties15
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/AndroidManifest.xml45
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/java/com/example/android/basicrenderscript/MainActivity.java190
-rwxr-xr-xrenderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-hdpi/ic_launcher.pngbin0 -> 4440 bytes
-rwxr-xr-xrenderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-mdpi/ic_launcher.pngbin0 -> 2742 bytes
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-nodpi/data.jpgbin0 -> 76367 bytes
-rwxr-xr-xrenderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xhdpi/ic_launcher.pngbin0 -> 6245 bytes
-rwxr-xr-xrenderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xxhdpi/ic_launcher.pngbin0 -> 11130 bytes
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/layout/main_layout.xml22
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v11/styles.xml24
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v14/styles.xml12
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/attrs.xml14
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/colors.xml5
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/styles.xml22
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/rs/saturation.rs36
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/tests/AndroidManifest.xml42
-rw-r--r--renderScript/BasicRenderScript/BasicRenderScriptSample/tests/src/com/example/android/basicrenderscript/tests/SampleTests.java79
-rw-r--r--renderScript/BasicRenderScript/build.gradle14
-rw-r--r--renderScript/BasicRenderScript/buildSrc/build.gradle18
-rw-r--r--renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.jarbin0 -> 50557 bytes
-rw-r--r--renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.properties6
-rwxr-xr-xrenderScript/BasicRenderScript/gradlew164
-rw-r--r--renderScript/BasicRenderScript/gradlew.bat90
-rw-r--r--renderScript/BasicRenderScript/settings.gradle4
-rw-r--r--renderScript/BasicRenderScript/template-params.xml47
28 files changed, 961 insertions, 0 deletions
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/.gitignore b/renderScript/BasicRenderScript/BasicRenderScriptSample/.gitignore
new file mode 100644
index 00000000..6eb878d4
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/.gitignore
@@ -0,0 +1,16 @@
+# 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.
+src/template/
+src/common/
+build.gradle
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/AndroidManifest.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/AndroidManifest.xml
new file mode 100644
index 00000000..1e35dc30
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.basicrenderscript"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:name="com.example.android.basicrenderscript.MainActivity"
+ android:configChanges="orientation|keyboardHidden|screenSize"
+ android:label="@string/app_name"
+ android:theme="@style/FullscreenTheme" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/build.gradle b/renderScript/BasicRenderScript/BasicRenderScriptSample/build.gradle
new file mode 100644
index 00000000..a9df66dd
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/build.gradle
@@ -0,0 +1,67 @@
+
+
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.8.+'
+ }
+}
+
+apply plugin: 'android'
+
+dependencies {
+ // Add the support lib that is appropriate for SDK 8
+ compile "com.android.support:support-v4:19.0.+"
+ compile "com.android.support:gridlayout-v7:19.0.+"
+ compile files('renderscript-v8.jar')
+}
+
+// The sample build uses multiple directories to
+// keep boilerplate and common code separate from
+// the main sample code.
+List<String> dirs = [
+ 'main', // main sample code; look here for the interesting stuff.
+ 'common', // components that are reused by multiple samples
+ 'template'] // boilerplate code that is generated by the sample template process
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion "19.0.1"
+
+ sourceSets {
+ main {
+ dirs.each { dir ->
+ java.srcDirs "src/${dir}/java"
+ res.srcDirs "src/${dir}/res"
+ }
+ }
+ instrumentTest.setRoot('tests')
+ instrumentTest.java.srcDirs = ['tests/src']
+
+ defaultConfig {
+
+ renderscriptTargetApi 18
+ renderscriptSupportMode true
+
+ }
+ }
+}
+// BEGIN_EXCLUDE
+// Tasks below this line will be hidden from release output
+
+task preflight (dependsOn: parent.preflight) {
+ project.afterEvaluate {
+ // Inject a preflight task into each variant so we have a place to hook tasks
+ // that need to run before any of the android build tasks.
+ //
+ android.applicationVariants.each { variant ->
+ tasks.getByPath("prepare${variant.name.capitalize()}Dependencies").dependsOn preflight
+ }
+ }
+}
+
+// END_EXCLUDE
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/project.properties b/renderScript/BasicRenderScript/BasicRenderScriptSample/project.properties
new file mode 100644
index 00000000..aa550f1f
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/project.properties
@@ -0,0 +1,15 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
+renderscript.support.mode=true \ No newline at end of file
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/AndroidManifest.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..e1e2dfc1
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/AndroidManifest.xml
@@ -0,0 +1,45 @@
+<?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 xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.basicrenderscript"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:label="@string/app_name"
+ android:icon="@drawable/ic_launcher"
+ android:theme="@style/AppTheme">
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:theme="@style/FullscreenTheme">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+
+</manifest>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/java/com/example/android/basicrenderscript/MainActivity.java b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/java/com/example/android/basicrenderscript/MainActivity.java
new file mode 100644
index 00000000..ed6d5ad1
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/java/com/example/android/basicrenderscript/MainActivity.java
@@ -0,0 +1,190 @@
+/*
+ * 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.basicrenderscript;
+
+import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.widget.ImageView;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.support.v8.renderscript.*;
+
+public class MainActivity extends Activity {
+ /* Number of bitmaps that is used for renderScript thread and UI thread synchronization.
+ Ideally, this can be reduced to 2, however in some devices, 2 buffers still showing tierings on UI.
+ Investigating a root cause.
+ */
+ private final int NUM_BITMAPS = 3;
+ private int mCurrentBitmap = 0;
+ private Bitmap mBitmapIn;
+ private Bitmap[] mBitmapsOut;
+ private ImageView mImageView;
+
+ private RenderScript mRS;
+ private Allocation mInAllocation;
+ private Allocation[] mOutAllocations;
+ private ScriptC_saturation mScript;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main_layout);
+
+ /*
+ * Initialize UI
+ */
+ mBitmapIn = loadBitmap(R.drawable.data);
+ mBitmapsOut = new Bitmap[NUM_BITMAPS];
+ for (int i = 0; i < NUM_BITMAPS; ++i) {
+ mBitmapsOut[i] = Bitmap.createBitmap(mBitmapIn.getWidth(),
+ mBitmapIn.getHeight(), mBitmapIn.getConfig());
+ }
+
+ mImageView = (ImageView) findViewById(R.id.imageView);
+ mImageView.setImageBitmap(mBitmapsOut[mCurrentBitmap]);
+ mCurrentBitmap += (mCurrentBitmap + 1) % NUM_BITMAPS;
+
+ SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar1);
+ seekbar.setProgress(50);
+ seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
+ public void onProgressChanged(SeekBar seekBar, int progress,
+ boolean fromUser) {
+ float max = 2.0f;
+ float min = 0.0f;
+ float f = (float) ((max - min) * (progress / 100.0) + min);
+ updateImage(f);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+
+ /*
+ * Create renderScript
+ */
+ createScript();
+
+ /*
+ * Invoke renderScript kernel and update imageView
+ */
+ updateImage(1.0f);
+ }
+
+ /*
+ * Initialize RenderScript
+ * In the sample, it creates RenderScript kernel that performs saturation manipulation.
+ */
+ private void createScript() {
+ //Initialize RS
+ mRS = RenderScript.create(this);
+
+ //Allocate buffers
+ mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn);
+ mOutAllocations = new Allocation[NUM_BITMAPS];
+ for (int i = 0; i < NUM_BITMAPS; ++i) {
+ mOutAllocations[i] = Allocation.createFromBitmap(mRS, mBitmapsOut[i]);
+ }
+
+ //Load script
+ mScript = new ScriptC_saturation(mRS);
+ }
+
+ /*
+ * In the AsyncTask, it invokes RenderScript intrinsics to do a filtering.
+ * After the filtering is done, an operation blocks at Allication.copyTo() in AsyncTask thread.
+ * Once all operation is finished at onPostExecute() in UI thread, it can invalidate and update ImageView UI.
+ */
+ private class RenderScriptTask extends AsyncTask<Float, Integer, Integer> {
+ Boolean issued = false;
+
+ protected Integer doInBackground(Float... values) {
+ int index = -1;
+ if (isCancelled() == false) {
+ issued = true;
+ index = mCurrentBitmap;
+
+ /*
+ * Set global variable in RS
+ */
+ mScript.set_saturationValue(values[0]);
+
+ /*
+ * Invoke saturation filter kernel
+ */
+ mScript.forEach_saturation(mInAllocation, mOutAllocations[index]);
+
+ /*
+ * Copy to bitmap and invalidate image view
+ */
+ mOutAllocations[index].copyTo(mBitmapsOut[index]);
+ mCurrentBitmap = (mCurrentBitmap + 1) % NUM_BITMAPS;
+ }
+ return index;
+ }
+
+ void updateView(Integer result) {
+ if (result != -1) {
+ // Request UI update
+ mImageView.setImageBitmap(mBitmapsOut[result]);
+ mImageView.invalidate();
+ }
+ }
+
+ protected void onPostExecute(Integer result) {
+ updateView(result);
+ }
+
+ protected void onCancelled(Integer result) {
+ if (issued) {
+ updateView(result);
+ }
+ }
+ }
+
+ RenderScriptTask currentTask = null;
+
+ /*
+ Invoke AsynchTask and cancel previous task.
+ When AsyncTasks are piled up (typically in slow device with heavy kernel),
+ Only the latest (and already started) task invokes RenderScript operation.
+ */
+ private void updateImage(final float f) {
+ if (currentTask != null)
+ currentTask.cancel(false);
+ currentTask = new RenderScriptTask();
+ currentTask.execute(f);
+ }
+
+ /*
+ Helper to load Bitmap from resource
+ */
+ private Bitmap loadBitmap(int resource) {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ return BitmapFactory.decodeResource(getResources(), resource, options);
+ }
+
+}
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-hdpi/ic_launcher.png b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 00000000..75b3c978
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-mdpi/ic_launcher.png b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 00000000..4ccd98e0
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-nodpi/data.jpg b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-nodpi/data.jpg
new file mode 100644
index 00000000..81a87b17
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-nodpi/data.jpg
Binary files differ
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xhdpi/ic_launcher.png b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 00000000..7c5aeed0
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xxhdpi/ic_launcher.png b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 00000000..3c45f511
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/layout/main_layout.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/layout/main_layout.xml
new file mode 100644
index 00000000..69695f07
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/layout/main_layout.xml
@@ -0,0 +1,22 @@
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#0099cc"
+ tools:context=".MainActivity">
+
+ <ImageView
+ android:id="@+id/imageView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:scaleType="fitCenter"
+ android:src="@drawable/data" />
+
+ <SeekBar
+ android:id="@+id/seekBar1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom"
+ android:layout_marginBottom="16dp" />
+
+</FrameLayout>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v11/styles.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v11/styles.xml
new file mode 100644
index 00000000..f3a90c68
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v11/styles.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <!--
+ Base application theme for API 11+. This theme completely replaces
+ AppBaseTheme from res/values/styles.xml on API 11+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+ <!-- API 11 theme customizations can go here. -->
+ </style>
+
+ <style name="FullscreenTheme" parent="android:Theme.Holo">
+ <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
+ <item name="android:windowActionBarOverlay">true</item>
+ <item name="android:windowBackground">@null</item>
+ <item name="buttonBarStyle">?android:attr/buttonBarStyle</item>
+ <item name="buttonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
+ </style>
+
+ <style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar">
+ <item name="android:background">@color/black_overlay</item>
+ </style>
+
+</resources>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v14/styles.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v14/styles.xml
new file mode 100644
index 00000000..a91fd037
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values-v14/styles.xml
@@ -0,0 +1,12 @@
+<resources>
+
+ <!--
+ Base application theme for API 14+. This theme completely replaces
+ AppBaseTheme from BOTH res/values/styles.xml and
+ res/values-v11/styles.xml on API 14+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- API 14 theme customizations can go here. -->
+ </style>
+
+</resources>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/attrs.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/attrs.xml
new file mode 100644
index 00000000..e67df0a3
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/attrs.xml
@@ -0,0 +1,14 @@
+<resources>
+
+ <!--
+ Declare custom theme attributes that allow changing which styles are
+ used for button bars depending on the API level.
+ ?android:attr/buttonBarStyle is new as of API 11 so this is
+ necessary to support previous API levels.
+ -->
+ <declare-styleable name="ButtonBarContainerTheme">
+ <attr name="buttonBarStyle" format="reference" />
+ <attr name="buttonBarButtonStyle" format="reference" />
+ </declare-styleable>
+
+</resources>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/colors.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/colors.xml
new file mode 100644
index 00000000..327c0604
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/colors.xml
@@ -0,0 +1,5 @@
+<resources>
+
+ <color name="black_overlay">#66000000</color>
+
+</resources>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/styles.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/styles.xml
new file mode 100644
index 00000000..49299b98
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/res/values/styles.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+
+ <style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowBackground">@null</item>
+ <item name="buttonBarStyle">@style/ButtonBar</item>
+ <item name="buttonBarButtonStyle">@style/ButtonBarButton</item>
+ </style>
+
+ <style name="ButtonBar">
+ <item name="android:paddingLeft">2dp</item>
+ <item name="android:paddingTop">5dp</item>
+ <item name="android:paddingRight">2dp</item>
+ <item name="android:paddingBottom">0dp</item>
+ <item name="android:background">@android:drawable/bottom_bar</item>
+ </style>
+
+ <style name="ButtonBarButton" />
+
+</resources>
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/rs/saturation.rs b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/rs/saturation.rs
new file mode 100644
index 00000000..cf043d14
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/src/main/rs/saturation.rs
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.example.android.basicrenderscript)
+#pragma rs_fp_relaxed
+
+const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
+
+float saturationValue = 0.f;
+
+/*
+RenderScript kernel that performs saturation manipulation.
+*/
+uchar4 __attribute__((kernel)) saturation(uchar4 in)
+{
+ float4 f4 = rsUnpackColor8888(in);
+ float3 result = dot(f4.rgb, gMonoMult);
+ result = mix( result, f4.rgb, saturationValue );
+
+ return rsPackColorTo8888(result);
+}
+
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/tests/AndroidManifest.xml b/renderScript/BasicRenderScript/BasicRenderScriptSample/tests/AndroidManifest.xml
new file mode 100644
index 00000000..02a8db36
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/tests/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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 name must be unique so suffix with "tests" so package loader doesn't ignore us -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.basicrenderscript.tests"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="19" />
+
+ <!-- We add an application tag here just so that we can indicate that
+ this package needs to link against the android.test library,
+ which is needed when building test cases. -->
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!--
+ Specifies the instrumentation test runner used to run the tests.
+ -->
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.example.android.basicrenderscript"
+ android:label="Tests for com.example.android.basicrenderscript" />
+
+</manifest> \ No newline at end of file
diff --git a/renderScript/BasicRenderScript/BasicRenderScriptSample/tests/src/com/example/android/basicrenderscript/tests/SampleTests.java b/renderScript/BasicRenderScript/BasicRenderScriptSample/tests/src/com/example/android/basicrenderscript/tests/SampleTests.java
new file mode 100644
index 00000000..b361507f
--- /dev/null
+++ b/renderScript/BasicRenderScript/BasicRenderScriptSample/tests/src/com/example/android/basicrenderscript/tests/SampleTests.java
@@ -0,0 +1,79 @@
+/*
+* 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 (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.basicrenderscript.tests;
+
+import com.example.android.basicrenderscript.*;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+* Tests for BasicRenderScript sample.
+*/
+public class SampleTests extends ActivityInstrumentationTestCase2<MainActivity> {
+
+ private MainActivity mTestActivity;
+ private BasicRenderScriptFragment mTestFragment;
+
+ public SampleTests() {
+ super(MainActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Starts the activity under test using the default Intent with:
+ // action = {@link Intent#ACTION_MAIN}
+ // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
+ // All other fields are null or empty.
+ mTestActivity = getActivity();
+ mTestFragment = (BasicRenderScriptFragment)
+ mTestActivity.getSupportFragmentManager().getFragments().get(1);
+ }
+
+ /**
+ * Test if the test fixture has been set up correctly.
+ */
+ public void testPreconditions() {
+ //Try to add a message to add context to your assertions. These messages will be shown if
+ //a tests fails and make it easy to understand why a test failed
+ assertNotNull("mTestActivity is null", mTestActivity);
+ assertNotNull("mTestFragment is null", mTestFragment);
+ }
+
+ /**
+ * Add more tests below.
+ */
+
+} \ No newline at end of file
diff --git a/renderScript/BasicRenderScript/build.gradle b/renderScript/BasicRenderScript/build.gradle
new file mode 100644
index 00000000..f9f6f652
--- /dev/null
+++ b/renderScript/BasicRenderScript/build.gradle
@@ -0,0 +1,14 @@
+
+
+
+
+// BEGIN_EXCLUDE
+import com.example.android.samples.build.SampleGenPlugin
+apply plugin: SampleGenPlugin
+
+samplegen {
+ pathToBuild "../../../../build"
+ pathToSamplesCommon "../../common"
+}
+apply from: "../../../../build/build.gradle"
+// END_EXCLUDE
diff --git a/renderScript/BasicRenderScript/buildSrc/build.gradle b/renderScript/BasicRenderScript/buildSrc/build.gradle
new file mode 100644
index 00000000..29282af4
--- /dev/null
+++ b/renderScript/BasicRenderScript/buildSrc/build.gradle
@@ -0,0 +1,18 @@
+
+
+
+repositories {
+ mavenCentral()
+}
+dependencies {
+ compile 'org.freemarker:freemarker:2.3.20'
+}
+
+sourceSets {
+ main {
+ groovy {
+ srcDir new File(rootDir, "../../../../../build/buildSrc/src/main/groovy")
+ }
+ }
+}
+
diff --git a/renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.jar b/renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..58385981
--- /dev/null
+++ b/renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.properties b/renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..8e914ab9
--- /dev/null
+++ b/renderScript/BasicRenderScript/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Thu Jan 30 14:48:26 PST 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-bin.zip
diff --git a/renderScript/BasicRenderScript/gradlew b/renderScript/BasicRenderScript/gradlew
new file mode 100755
index 00000000..91a7e269
--- /dev/null
+++ b/renderScript/BasicRenderScript/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/renderScript/BasicRenderScript/gradlew.bat b/renderScript/BasicRenderScript/gradlew.bat
new file mode 100644
index 00000000..aec99730
--- /dev/null
+++ b/renderScript/BasicRenderScript/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/renderScript/BasicRenderScript/settings.gradle b/renderScript/BasicRenderScript/settings.gradle
new file mode 100644
index 00000000..cb170069
--- /dev/null
+++ b/renderScript/BasicRenderScript/settings.gradle
@@ -0,0 +1,4 @@
+
+
+
+include 'BasicRenderScriptSample'
diff --git a/renderScript/BasicRenderScript/template-params.xml b/renderScript/BasicRenderScript/template-params.xml
new file mode 100644
index 00000000..cf35d311
--- /dev/null
+++ b/renderScript/BasicRenderScript/template-params.xml
@@ -0,0 +1,47 @@
+<?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.
+-->
+
+
+
+<sample>
+ <name>BasicRenderScript</name>
+ <group>RenderScript</group>
+ <package>com.example.android.basicrenderscript</package>
+
+ <!-- change minSdk if needed-->
+ <minSdk>8</minSdk>
+
+ <dependency_external>'renderscript-v8.jar'</dependency_external>
+
+ <defaultConfig>
+ renderscriptTargetApi 18
+ renderscriptSupportMode true
+ </defaultConfig>
+
+ <strings>
+ <intro>
+ <![CDATA[
+ BasicRenderScript sample demonstrates basic steps how to use renderScript.
+ In the sample, it performs graphical filter operation on a image with renderScript.
+ ]]>
+ </intro>
+ </strings>
+
+ <template src="base"/>
+ <common src="media"/>
+
+</sample>