diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-02-10 09:51:34 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-02-10 09:51:34 -0800 |
commit | f1ff8b2fd6441d122e84c5040834bf6e0d845b05 (patch) | |
tree | d90b173e0bc10a8bb9417dbaafa4764979d64d2b /libs | |
parent | a8d3f02aaae6423bb969916d64283d3559faa3ff (diff) | |
parent | f82428a932333620401d657017110d5818308016 (diff) | |
download | frameworks_base-f1ff8b2fd6441d122e84c5040834bf6e0d845b05.zip frameworks_base-f1ff8b2fd6441d122e84c5040834bf6e0d845b05.tar.gz frameworks_base-f1ff8b2fd6441d122e84c5040834bf6e0d845b05.tar.bz2 |
Merge "Cleanup of the code in view to do creation/destruction in the right places." into honeycomb
Diffstat (limited to 'libs')
7 files changed, 46 insertions, 123 deletions
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsList.java b/libs/rs/java/Samples/src/com/android/samples/RsList.java index d47be42..2d7add0 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsList.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsList.java @@ -16,26 +16,8 @@ package com.android.samples; -import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; - import android.app.Activity; -import android.content.res.Configuration; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.provider.Settings.System; -import android.util.Config; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.Window; -import android.widget.Button; -import android.widget.ListView; - -import java.lang.Runtime; public class RsList extends Activity { diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java index 8e2d51f..6ee545ac 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java @@ -73,17 +73,12 @@ public class RsListRS { "Yemen", "Yugoslavia", "Zambia", "Zimbabwe" }; - int mWidth; - int mHeight; - public RsListRS() { } - public void init(RenderScriptGL rs, Resources res, int width, int height) { + public void init(RenderScriptGL rs, Resources res) { mRS = rs; mRes = res; - mWidth = width; - mHeight = height; initRS(); } diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListView.java b/libs/rs/java/Samples/src/com/android/samples/RsListView.java index 00b1723..b67bd48 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsListView.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsListView.java @@ -15,55 +15,40 @@ */ package com.android.samples; - -import java.io.Writer; -import java.util.ArrayList; -import java.util.concurrent.Semaphore; - import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; import android.renderscript.RenderScriptGL; import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Handler; -import android.os.Message; -import android.util.AttributeSet; -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.KeyEvent; import android.view.MotionEvent; public class RsListView extends RSSurfaceView { public RsListView(Context context) { super(context); - //setFocusable(true); + ensureRenderScript(); } private RenderScriptGL mRS; private RsListRS mRender; - - public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - super.surfaceChanged(holder, format, w, h); + private void ensureRenderScript() { if (mRS == null) { RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); - sc.setDepth(16, 24); mRS = createRenderScriptGL(sc); - mRS.setSurface(holder, w, h); mRender = new RsListRS(); - mRender.init(mRS, getResources(), w, h); + mRender.init(mRS, getResources()); } } @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + ensureRenderScript(); + } + + @Override protected void onDetachedFromWindow() { + mRender = null; if (mRS != null) { mRS = null; destroyRenderScriptGL(); @@ -71,23 +56,14 @@ public class RsListView extends RSSurfaceView { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) - { - // break point at here - // this method doesn't work when 'extends View' include 'extends ScrollView'. - return super.onKeyDown(keyCode, event); - } - - - @Override public boolean onTouchEvent(MotionEvent ev) { boolean ret = false; int act = ev.getAction(); - if (act == ev.ACTION_DOWN) { + if (act == MotionEvent.ACTION_DOWN) { mRender.onActionDown((int)ev.getX(), (int)ev.getY()); ret = true; - } else if (act == ev.ACTION_MOVE) { + } else if (act == MotionEvent.ACTION_MOVE) { mRender.onActionMove((int)ev.getX(), (int)ev.getY()); ret = true; } diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java index 33c1719..ff8c2de 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java @@ -16,26 +16,8 @@ package com.android.samples; -import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; - import android.app.Activity; -import android.content.res.Configuration; import android.os.Bundle; -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.provider.Settings.System; -import android.util.Config; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.Window; -import android.widget.Button; -import android.widget.ListView; - -import java.lang.Runtime; public class RsRenderStates extends Activity { diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java index 87840a7..49b65d6 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java @@ -16,8 +16,6 @@ package com.android.samples; -import java.io.Writer; - import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -39,11 +37,11 @@ public class RsRenderStatesRS { public RsRenderStatesRS() { } - public void init(RenderScriptGL rs, Resources res, int width, int height) { + public void init(RenderScriptGL rs, Resources res) { mRS = rs; + mWidth = mRS.getWidth(); + mHeight = mRS.getHeight(); mRes = res; - mWidth = width; - mHeight = height; mOptionsARGB.inScaled = false; mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888; mMode = 0; @@ -51,6 +49,15 @@ public class RsRenderStatesRS { initRS(); } + public void surfaceChanged() { + mWidth = mRS.getWidth(); + mHeight = mRS.getHeight(); + + Matrix4f proj = new Matrix4f(); + proj.loadOrthoWindow(mWidth, mHeight); + mPVA.setProjection(proj); + } + private Resources mRes; private RenderScriptGL mRS; diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java index 235d29b..4d339dd 100644 --- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java +++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java @@ -16,54 +16,48 @@ package com.android.samples; -import java.io.Writer; -import java.util.ArrayList; -import java.util.concurrent.Semaphore; - import android.renderscript.RSSurfaceView; -import android.renderscript.RenderScript; import android.renderscript.RenderScriptGL; import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Handler; -import android.os.Message; -import android.util.AttributeSet; -import android.util.Log; -import android.view.Surface; -import android.view.SurfaceHolder; -import android.view.SurfaceView; -import android.view.KeyEvent; import android.view.MotionEvent; +import android.view.SurfaceHolder; public class RsRenderStatesView extends RSSurfaceView { public RsRenderStatesView(Context context) { super(context); - //setFocusable(true); + ensureRenderScript(); } private RenderScriptGL mRS; private RsRenderStatesRS mRender; - - public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { - super.surfaceChanged(holder, format, w, h); + private void ensureRenderScript() { if (mRS == null) { RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); sc.setDepth(16, 24); mRS = createRenderScriptGL(sc); - mRS.setSurface(holder, w, h); mRender = new RsRenderStatesRS(); - mRender.init(mRS, getResources(), w, h); + mRender.init(mRS, getResources()); } } @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + ensureRenderScript(); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + super.surfaceChanged(holder, format, w, h); + mRender.surfaceChanged(); + } + + @Override protected void onDetachedFromWindow() { + mRender = null; if (mRS != null) { mRS = null; destroyRenderScriptGL(); @@ -71,25 +65,13 @@ public class RsRenderStatesView extends RSSurfaceView { } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) - { - // break point at here - // this method doesn't work when 'extends View' include 'extends ScrollView'. - return super.onKeyDown(keyCode, event); - } - - - @Override - public boolean onTouchEvent(MotionEvent ev) - { - boolean ret = false; - int act = ev.getAction(); - if (act == ev.ACTION_DOWN) { + public boolean onTouchEvent(MotionEvent ev) { + if (ev.getAction() == MotionEvent.ACTION_DOWN) { mRender.onActionDown((int)ev.getX(), (int)ev.getY()); - ret = true; + return true; } - return ret; + return false; } } diff --git a/libs/rs/java/Samples/src/com/android/samples/rslist.rs b/libs/rs/java/Samples/src/com/android/samples/rslist.rs index b79f4fc..52c870a 100644 --- a/libs/rs/java/Samples/src/com/android/samples/rslist.rs +++ b/libs/rs/java/Samples/src/com/android/samples/rslist.rs @@ -37,7 +37,6 @@ int textPos = 0; int root(int launchID) { rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f); - rsgClearDepth(1.0f); textPos -= (int)gDY*2; gDY *= 0.95; |