Code drop from //branches/cupcake/...@124589
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.apis.app;
|
||||
|
||||
// Need the following import to get access to the app resources, since this
|
||||
// class is in a sub-package.
|
||||
import com.example.android.apis.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
|
||||
/**
|
||||
* Activity used by StatusBarNotification to show the notification to the user.
|
||||
*/
|
||||
public class NotificationDisplay extends Activity implements View.OnClickListener {
|
||||
/**
|
||||
* Initialization of the Activity after it is first created. Must at least
|
||||
* call {@link android.app.Activity#setContentView setContentView()} to
|
||||
* describe what is to be displayed in the screen.
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
// Be sure to call the super class.
|
||||
super.onCreate(icicle);
|
||||
|
||||
// Have the system blur any windows behind this one.
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
|
||||
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
|
||||
|
||||
RelativeLayout container = new RelativeLayout(this);
|
||||
|
||||
ImageButton button = new ImageButton(this);
|
||||
button.setImageResource(getIntent().getIntExtra("moodimg", 0));
|
||||
button.setOnClickListener(this);
|
||||
|
||||
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
|
||||
RelativeLayout.LayoutParams.WRAP_CONTENT,
|
||||
RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
|
||||
|
||||
container.addView(button, lp);
|
||||
|
||||
setContentView(container);
|
||||
}
|
||||
|
||||
public void onClick(View v) {
|
||||
// The user has confirmed this notification, so remove it.
|
||||
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
|
||||
.cancel(R.layout.status_bar_notifications);
|
||||
|
||||
// Pressing on the button brings the user back to our mood ring,
|
||||
// as part of the api demos app. Note the use of NEW_TASK here,
|
||||
// since the notification display activity is run as a separate task.
|
||||
Intent intent = new Intent(this, StatusBarNotifications.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
|
||||
// We're done.
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.SearchManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchRecentSuggestions;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -111,6 +112,8 @@ public class SearchInvoke extends Activity
|
||||
|
||||
// first, get rid of our menus (if any)
|
||||
menu.removeItem(0);
|
||||
menu.removeItem(1);
|
||||
|
||||
// next, add back item(s) based on current menu mode
|
||||
switch (mMenuMode.getSelectedItemPosition())
|
||||
{
|
||||
@@ -131,6 +134,8 @@ public class SearchInvoke extends Activity
|
||||
item = menu.add( 0, 0, 0, "(Disabled)");
|
||||
break;
|
||||
}
|
||||
|
||||
item = menu.add(0, 1, 0, "Clear History");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -167,6 +172,9 @@ public class SearchInvoke extends Activity
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
clearSearchHistory();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
@@ -211,4 +219,23 @@ public class SearchInvoke extends Activity
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Any application that implements search suggestions based on previous actions (such as
|
||||
* recent queries, page/items viewed, etc.) should provide a way for the user to clear the
|
||||
* history. This gives the user a measure of privacy, if they do not wish for their recent
|
||||
* searches to be replayed by other users of the device (via suggestions).
|
||||
*
|
||||
* This example shows how to clear the search history for apps that use
|
||||
* android.provider.SearchRecentSuggestions. If you have developed a custom suggestions
|
||||
* provider, you'll need to provide a similar API for clearing history.
|
||||
*
|
||||
* In this sample app we call this method from a "Clear History" menu item. You could also
|
||||
* implement the UI in your preferences, or any other logical place in your UI.
|
||||
*/
|
||||
private void clearSearchHistory() {
|
||||
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
|
||||
SearchSuggestionSampleProvider.AUTHORITY, SearchSuggestionSampleProvider.MODE);
|
||||
suggestions.clearHistory();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -144,6 +144,19 @@ public class StatusBarNotifications extends Activity {
|
||||
});
|
||||
}
|
||||
|
||||
private PendingIntent makeMoodIntent(int moodId) {
|
||||
// The PendingIntent to launch our activity if the user selects this
|
||||
// notification. Note the use of FLAG_UPDATE_CURRENT so that if there
|
||||
// is already an active matching pending intent, we will update its
|
||||
// extras to be the ones passed in here.
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, NotificationDisplay.class)
|
||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("moodimg", moodId),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
return contentIntent;
|
||||
}
|
||||
|
||||
private void setMood(int moodId, int textId, boolean showTicker) {
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(textId);
|
||||
@@ -155,13 +168,9 @@ public class StatusBarNotifications extends Activity {
|
||||
Notification notification = new Notification(moodId, tickerText,
|
||||
System.currentTimeMillis());
|
||||
|
||||
// The PendingIntent to launch our activity if the user selects this notification
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, StatusBarNotifications.class), 0);
|
||||
|
||||
// Set the info for the views that show in the notification panel.
|
||||
notification.setLatestEventInfo(this, getText(R.string.status_bar_notifications_mood_title),
|
||||
text, contentIntent);
|
||||
text, makeMoodIntent(moodId));
|
||||
|
||||
// Send the notification.
|
||||
// We use a layout id because it is a unique number. We use it later to cancel.
|
||||
@@ -176,8 +185,7 @@ public class StatusBarNotifications extends Activity {
|
||||
Notification notif = new Notification();
|
||||
|
||||
// This is who should be launched if the user selects our notification.
|
||||
notif.contentIntent = PendingIntent.getActivity(this, 0,
|
||||
new Intent(this, StatusBarNotifications.class), 0);
|
||||
notif.contentIntent = makeMoodIntent(moodId);
|
||||
|
||||
// In this sample, we'll use the same text for the ticker and the expanded notification
|
||||
CharSequence text = getText(textId);
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.view.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class BitmapDecode extends GraphicsActivity {
|
||||
|
||||
@@ -47,6 +48,19 @@ public class BitmapDecode extends GraphicsActivity {
|
||||
private Movie mMovie;
|
||||
private long mMovieStart;
|
||||
|
||||
private static byte[] streamToBytes(InputStream is) {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
while ((len = is.read(buffer)) >= 0) {
|
||||
os.write(buffer, 0, len);
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
}
|
||||
return os.toByteArray();
|
||||
}
|
||||
|
||||
public SampleView(Context context) {
|
||||
super(context);
|
||||
setFocusable(true);
|
||||
@@ -87,7 +101,12 @@ public class BitmapDecode extends GraphicsActivity {
|
||||
mDrawable.setBounds(150, 20, 300, 100);
|
||||
|
||||
is = context.getResources().openRawResource(R.drawable.animated_gif);
|
||||
mMovie = Movie.decodeStream(is);
|
||||
if (true) {
|
||||
mMovie = Movie.decodeStream(is);
|
||||
} else {
|
||||
byte[] array = streamToBytes(is);
|
||||
mMovie = Movie.decodeByteArray(array, 0, array.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void onDraw(Canvas canvas) {
|
||||
@@ -107,11 +126,17 @@ public class BitmapDecode extends GraphicsActivity {
|
||||
if (mMovieStart == 0) { // first time
|
||||
mMovieStart = now;
|
||||
}
|
||||
int relTime = (int)((now - mMovieStart) % mMovie.duration());
|
||||
mMovie.setTime(relTime);
|
||||
mMovie.draw(canvas, getWidth() - mMovie.width(),
|
||||
getHeight() - mMovie.height());
|
||||
invalidate();
|
||||
if (mMovie != null) {
|
||||
int dur = mMovie.duration();
|
||||
if (dur == 0) {
|
||||
dur = 1000;
|
||||
}
|
||||
int relTime = (int)((now - mMovieStart) % dur);
|
||||
mMovie.setTime(relTime);
|
||||
mMovie.draw(canvas, getWidth() - mMovie.width(),
|
||||
getHeight() - mMovie.height());
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.Bundle;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.Window;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -64,7 +64,13 @@ class Preview extends SurfaceView implements SurfaceHolder.Callback {
|
||||
// The Surface has been created, acquire the camera and tell it where
|
||||
// to draw.
|
||||
mCamera = Camera.open();
|
||||
mCamera.setPreviewDisplay(holder);
|
||||
try {
|
||||
mCamera.setPreviewDisplay(holder);
|
||||
} catch (IOException exception) {
|
||||
mCamera.release();
|
||||
mCamera = null;
|
||||
// TODO: add more exception handling logic here
|
||||
}
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
|
||||
@@ -17,8 +17,11 @@
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.opengl.GLSurfaceView;
|
||||
|
||||
/**
|
||||
* Render a pair of tumbling cubes.
|
||||
*/
|
||||
@@ -29,7 +32,7 @@ class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
mCube = new Cube();
|
||||
}
|
||||
|
||||
public void drawFrame(GL10 gl) {
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
/*
|
||||
* Usually, the first thing one might want to do is to clear
|
||||
* the screen. The most efficient way of doing this is to use
|
||||
@@ -84,7 +87,7 @@ class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void sizeChanged(GL10 gl, int width, int height) {
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
gl.glViewport(0, 0, width, height);
|
||||
|
||||
/*
|
||||
@@ -99,7 +102,7 @@ class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
|
||||
}
|
||||
|
||||
public void surfaceCreated(GL10 gl) {
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
/*
|
||||
* By default, OpenGL enables features that improve quality
|
||||
* but reduce performance. One might want to tweak that
|
||||
|
||||
@@ -1,519 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGL11;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
import javax.microedition.khronos.egl.EGLSurface;
|
||||
import javax.microedition.khronos.opengles.GL;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
/**
|
||||
* An implementation of SurfaceView that uses the dedicated surface for
|
||||
* displaying an OpenGL animation. This allows the animation to run in a
|
||||
* separate thread, without requiring that it be driven by the update mechanism
|
||||
* of the view hierarchy.
|
||||
*
|
||||
* The application-specific rendering code is delegated to a GLView.Renderer
|
||||
* instance.
|
||||
*/
|
||||
public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
|
||||
public GLSurfaceView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public GLSurfaceView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// Install a SurfaceHolder.Callback so we get notified when the
|
||||
// underlying surface is created and destroyed
|
||||
mHolder = getHolder();
|
||||
mHolder.addCallback(this);
|
||||
mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
|
||||
}
|
||||
|
||||
public SurfaceHolder getSurfaceHolder() {
|
||||
return mHolder;
|
||||
}
|
||||
|
||||
public void setGLWrapper(GLWrapper glWrapper) {
|
||||
mGLWrapper = glWrapper;
|
||||
}
|
||||
|
||||
public void setRenderer(Renderer renderer) {
|
||||
mGLThread = new GLThread(renderer);
|
||||
mGLThread.start();
|
||||
}
|
||||
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
mGLThread.surfaceCreated();
|
||||
}
|
||||
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
// Surface will be destroyed when we return
|
||||
mGLThread.surfaceDestroyed();
|
||||
}
|
||||
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
// Surface size or format has changed. This should not happen in this
|
||||
// example.
|
||||
mGLThread.onWindowResize(w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the view that the activity is paused.
|
||||
*/
|
||||
public void onPause() {
|
||||
mGLThread.onPause();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the view that the activity is resumed.
|
||||
*/
|
||||
public void onResume() {
|
||||
mGLThread.onResume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the view that the window focus has changed.
|
||||
*/
|
||||
@Override public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
mGLThread.onWindowFocusChanged(hasFocus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue an "event" to be run on the GL rendering thread.
|
||||
* @param r the runnable to be run on the GL rendering thread.
|
||||
*/
|
||||
public void queueEvent(Runnable r) {
|
||||
mGLThread.queueEvent(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mGLThread.requestExitAndWait();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public interface GLWrapper {
|
||||
GL wrap(GL gl);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A generic renderer interface.
|
||||
*/
|
||||
public interface Renderer {
|
||||
/**
|
||||
* @return the EGL configuration specification desired by the renderer.
|
||||
*/
|
||||
int[] getConfigSpec();
|
||||
|
||||
/**
|
||||
* Surface created.
|
||||
* Called when the surface is created. Called when the application
|
||||
* starts, and whenever the GPU is reinitialized. This will
|
||||
* typically happen when the device awakes after going to sleep.
|
||||
* Set your textures here.
|
||||
*/
|
||||
void surfaceCreated(GL10 gl);
|
||||
/**
|
||||
* Surface changed size.
|
||||
* Called after the surface is created and whenever
|
||||
* the OpenGL ES surface size changes. Set your viewport here.
|
||||
* @param gl
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
void sizeChanged(GL10 gl, int width, int height);
|
||||
/**
|
||||
* Draw the current frame.
|
||||
* @param gl
|
||||
*/
|
||||
void drawFrame(GL10 gl);
|
||||
}
|
||||
|
||||
/**
|
||||
* An EGL helper class.
|
||||
*/
|
||||
|
||||
private class EglHelper {
|
||||
public EglHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize EGL for a given configuration spec.
|
||||
* @param configSpec
|
||||
*/
|
||||
public void start(int[] configSpec){
|
||||
/*
|
||||
* Get an EGL instance
|
||||
*/
|
||||
mEgl = (EGL10) EGLContext.getEGL();
|
||||
|
||||
/*
|
||||
* Get to the default display.
|
||||
*/
|
||||
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
||||
|
||||
/*
|
||||
* We can now initialize EGL for that display
|
||||
*/
|
||||
int[] version = new int[2];
|
||||
mEgl.eglInitialize(mEglDisplay, version);
|
||||
|
||||
EGLConfig[] configs = new EGLConfig[1];
|
||||
int[] num_config = new int[1];
|
||||
mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1,
|
||||
num_config);
|
||||
mEglConfig = configs[0];
|
||||
|
||||
/*
|
||||
* Create an OpenGL ES context. This must be done only once, an
|
||||
* OpenGL context is a somewhat heavy object.
|
||||
*/
|
||||
mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig,
|
||||
EGL10.EGL_NO_CONTEXT, null);
|
||||
|
||||
mEglSurface = null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create and return an OpenGL surface
|
||||
*/
|
||||
public GL createSurface(SurfaceHolder holder) {
|
||||
/*
|
||||
* The window size has changed, so we need to create a new
|
||||
* surface.
|
||||
*/
|
||||
if (mEglSurface != null) {
|
||||
|
||||
/*
|
||||
* Unbind and destroy the old EGL surface, if
|
||||
* there is one.
|
||||
*/
|
||||
mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
|
||||
EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
|
||||
mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an EGL surface we can render into.
|
||||
*/
|
||||
mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay,
|
||||
mEglConfig, holder, null);
|
||||
|
||||
/*
|
||||
* Before we can issue GL commands, we need to make sure
|
||||
* the context is current and bound to a surface.
|
||||
*/
|
||||
mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
|
||||
mEglContext);
|
||||
|
||||
|
||||
GL gl = mEglContext.getGL();
|
||||
if (mGLWrapper != null) {
|
||||
gl = mGLWrapper.wrap(gl);
|
||||
}
|
||||
return gl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the current render surface.
|
||||
* @return false if the context has been lost.
|
||||
*/
|
||||
public boolean swap() {
|
||||
mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
|
||||
|
||||
/*
|
||||
* Always check for EGL_CONTEXT_LOST, which means the context
|
||||
* and all associated data were lost (For instance because
|
||||
* the device went to sleep). We need to sleep until we
|
||||
* get a new surface.
|
||||
*/
|
||||
return mEgl.eglGetError() != EGL11.EGL_CONTEXT_LOST;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
if (mEglSurface != null) {
|
||||
mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE,
|
||||
EGL10.EGL_NO_SURFACE,
|
||||
EGL10.EGL_NO_CONTEXT);
|
||||
mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
|
||||
mEglSurface = null;
|
||||
}
|
||||
if (mEglContext != null) {
|
||||
mEgl.eglDestroyContext(mEglDisplay, mEglContext);
|
||||
mEglContext = null;
|
||||
}
|
||||
if (mEglDisplay != null) {
|
||||
mEgl.eglTerminate(mEglDisplay);
|
||||
mEglDisplay = null;
|
||||
}
|
||||
}
|
||||
|
||||
EGL10 mEgl;
|
||||
EGLDisplay mEglDisplay;
|
||||
EGLSurface mEglSurface;
|
||||
EGLConfig mEglConfig;
|
||||
EGLContext mEglContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic GL Thread. Takes care of initializing EGL and GL. Delegates
|
||||
* to a Renderer instance to do the actual drawing.
|
||||
*
|
||||
*/
|
||||
|
||||
class GLThread extends Thread {
|
||||
GLThread(Renderer renderer) {
|
||||
super();
|
||||
mDone = false;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mRenderer = renderer;
|
||||
setName("GLThread");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
/*
|
||||
* When the android framework launches a second instance of
|
||||
* an activity, the new instance's onCreate() method may be
|
||||
* called before the first instance returns from onDestroy().
|
||||
*
|
||||
* This semaphore ensures that only one instance at a time
|
||||
* accesses EGL.
|
||||
*/
|
||||
try {
|
||||
try {
|
||||
sEglSemaphore.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
guardedRun();
|
||||
} catch (InterruptedException e) {
|
||||
// fall thru and exit normally
|
||||
} finally {
|
||||
sEglSemaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void guardedRun() throws InterruptedException {
|
||||
mEglHelper = new EglHelper();
|
||||
/*
|
||||
* Specify a configuration for our opengl session
|
||||
* and grab the first configuration that matches is
|
||||
*/
|
||||
int[] configSpec = mRenderer.getConfigSpec();
|
||||
mEglHelper.start(configSpec);
|
||||
|
||||
GL10 gl = null;
|
||||
boolean tellRendererSurfaceCreated = true;
|
||||
boolean tellRendererSurfaceChanged = true;
|
||||
|
||||
/*
|
||||
* This is our main activity thread's loop, we go until
|
||||
* asked to quit.
|
||||
*/
|
||||
while (!mDone) {
|
||||
|
||||
/*
|
||||
* Update the asynchronous state (window size)
|
||||
*/
|
||||
int w, h;
|
||||
boolean changed;
|
||||
boolean needStart = false;
|
||||
synchronized (this) {
|
||||
Runnable r;
|
||||
while ((r = getEvent()) != null) {
|
||||
r.run();
|
||||
}
|
||||
if (mPaused) {
|
||||
mEglHelper.finish();
|
||||
needStart = true;
|
||||
}
|
||||
if(needToWait()) {
|
||||
while (needToWait()) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
if (mDone) {
|
||||
break;
|
||||
}
|
||||
changed = mSizeChanged;
|
||||
w = mWidth;
|
||||
h = mHeight;
|
||||
mSizeChanged = false;
|
||||
}
|
||||
if (needStart) {
|
||||
mEglHelper.start(configSpec);
|
||||
tellRendererSurfaceCreated = true;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
gl = (GL10) mEglHelper.createSurface(mHolder);
|
||||
tellRendererSurfaceChanged = true;
|
||||
}
|
||||
if (tellRendererSurfaceCreated) {
|
||||
mRenderer.surfaceCreated(gl);
|
||||
tellRendererSurfaceCreated = false;
|
||||
}
|
||||
if (tellRendererSurfaceChanged) {
|
||||
mRenderer.sizeChanged(gl, w, h);
|
||||
tellRendererSurfaceChanged = false;
|
||||
}
|
||||
if ((w > 0) && (h > 0)) {
|
||||
/* draw a frame here */
|
||||
mRenderer.drawFrame(gl);
|
||||
|
||||
/*
|
||||
* Once we're done with GL, we need to call swapBuffers()
|
||||
* to instruct the system to display the rendered frame
|
||||
*/
|
||||
mEglHelper.swap();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* clean-up everything...
|
||||
*/
|
||||
mEglHelper.finish();
|
||||
}
|
||||
|
||||
private boolean needToWait() {
|
||||
return (mPaused || (! mHasFocus) || (! mHasSurface) || mContextLost)
|
||||
&& (! mDone);
|
||||
}
|
||||
|
||||
public void surfaceCreated() {
|
||||
synchronized(this) {
|
||||
mHasSurface = true;
|
||||
mContextLost = false;
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void surfaceDestroyed() {
|
||||
synchronized(this) {
|
||||
mHasSurface = false;
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
synchronized (this) {
|
||||
mPaused = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
synchronized (this) {
|
||||
mPaused = false;
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
synchronized (this) {
|
||||
mHasFocus = hasFocus;
|
||||
if (mHasFocus == true) {
|
||||
notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onWindowResize(int w, int h) {
|
||||
synchronized (this) {
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
mSizeChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void requestExitAndWait() {
|
||||
// don't call this from GLThread thread or it is a guaranteed
|
||||
// deadlock!
|
||||
synchronized(this) {
|
||||
mDone = true;
|
||||
notify();
|
||||
}
|
||||
try {
|
||||
join();
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue an "event" to be run on the GL rendering thread.
|
||||
* @param r the runnable to be run on the GL rendering thread.
|
||||
*/
|
||||
public void queueEvent(Runnable r) {
|
||||
synchronized(this) {
|
||||
mEventQueue.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable getEvent() {
|
||||
synchronized(this) {
|
||||
if (mEventQueue.size() > 0) {
|
||||
return mEventQueue.remove(0);
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean mDone;
|
||||
private boolean mPaused;
|
||||
private boolean mHasFocus;
|
||||
private boolean mHasSurface;
|
||||
private boolean mContextLost;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private Renderer mRenderer;
|
||||
private ArrayList<Runnable> mEventQueue = new ArrayList<Runnable>();
|
||||
private EglHelper mEglHelper;
|
||||
}
|
||||
|
||||
private static final Semaphore sEglSemaphore = new Semaphore(1);
|
||||
private boolean mSizeChanged = true;
|
||||
|
||||
private SurfaceHolder mHolder;
|
||||
private GLThread mGLThread;
|
||||
private GLWrapper mGLWrapper;
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* Wrapper activity demonstrating the use of {@link GLSurfaceView}, a view
|
||||
* that uses OpenGL drawing into a dedicated surface.
|
||||
*
|
||||
* Shows:
|
||||
* + How to redraw in response to user input.
|
||||
*/
|
||||
public class TouchRotateActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Create our Preview view and set it as the content of our
|
||||
// Activity
|
||||
mGLSurfaceView = new TouchSurfaceView(this);
|
||||
setContentView(mGLSurfaceView);
|
||||
mGLSurfaceView.requestFocus();
|
||||
mGLSurfaceView.setFocusableInTouchMode(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onResume();
|
||||
mGLSurfaceView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
// Ideally a game should implement onResume() and onPause()
|
||||
// to take appropriate action when the activity looses focus
|
||||
super.onPause();
|
||||
mGLSurfaceView.onPause();
|
||||
}
|
||||
|
||||
private GLSurfaceView mGLSurfaceView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement a simple rotation control.
|
||||
*
|
||||
*/
|
||||
class TouchSurfaceView extends GLSurfaceView {
|
||||
|
||||
public TouchSurfaceView(Context context) {
|
||||
super(context);
|
||||
mRenderer = new CubeRenderer();
|
||||
setRenderer(mRenderer);
|
||||
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
||||
}
|
||||
|
||||
@Override public boolean onTrackballEvent(MotionEvent e) {
|
||||
mRenderer.mAngleX += e.getX() * TRACKBALL_SCALE_FACTOR;
|
||||
mRenderer.mAngleY += e.getY() * TRACKBALL_SCALE_FACTOR;
|
||||
requestRender();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean onTouchEvent(MotionEvent e) {
|
||||
float x = e.getX();
|
||||
float y = e.getY();
|
||||
switch (e.getAction()) {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
float dx = x - mPreviousX;
|
||||
float dy = y - mPreviousY;
|
||||
mRenderer.mAngleX += dx * TOUCH_SCALE_FACTOR;
|
||||
mRenderer.mAngleY += dy * TOUCH_SCALE_FACTOR;
|
||||
requestRender();
|
||||
}
|
||||
mPreviousX = x;
|
||||
mPreviousY = y;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a cube.
|
||||
*/
|
||||
private class CubeRenderer implements GLSurfaceView.Renderer {
|
||||
public CubeRenderer() {
|
||||
mCube = new Cube();
|
||||
}
|
||||
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
/*
|
||||
* Usually, the first thing one might want to do is to clear
|
||||
* the screen. The most efficient way of doing this is to use
|
||||
* glClear().
|
||||
*/
|
||||
|
||||
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/*
|
||||
* Now we're ready to draw some 3D objects
|
||||
*/
|
||||
|
||||
gl.glMatrixMode(GL10.GL_MODELVIEW);
|
||||
gl.glLoadIdentity();
|
||||
gl.glTranslatef(0, 0, -3.0f);
|
||||
gl.glRotatef(mAngleX, 0, 1, 0);
|
||||
gl.glRotatef(mAngleY, 1, 0, 0);
|
||||
|
||||
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
|
||||
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
|
||||
|
||||
mCube.draw(gl);
|
||||
}
|
||||
|
||||
public int[] getConfigSpec() {
|
||||
// We want a depth buffer, don't care about the
|
||||
// details of the color buffer.
|
||||
int[] configSpec = {
|
||||
EGL10.EGL_DEPTH_SIZE, 16,
|
||||
EGL10.EGL_NONE
|
||||
};
|
||||
return configSpec;
|
||||
}
|
||||
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
gl.glViewport(0, 0, width, height);
|
||||
|
||||
/*
|
||||
* Set our projection matrix. This doesn't have to be done
|
||||
* each time we draw, but usually a new projection needs to
|
||||
* be set when the viewport is resized.
|
||||
*/
|
||||
|
||||
float ratio = (float) width / height;
|
||||
gl.glMatrixMode(GL10.GL_PROJECTION);
|
||||
gl.glLoadIdentity();
|
||||
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
|
||||
}
|
||||
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
/*
|
||||
* By default, OpenGL enables features that improve quality
|
||||
* but reduce performance. One might want to tweak that
|
||||
* especially on software renderer.
|
||||
*/
|
||||
gl.glDisable(GL10.GL_DITHER);
|
||||
|
||||
/*
|
||||
* Some one-time OpenGL initialization can be made here
|
||||
* probably based on features of this particular context
|
||||
*/
|
||||
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
|
||||
GL10.GL_FASTEST);
|
||||
|
||||
|
||||
gl.glClearColor(1,1,1,1);
|
||||
gl.glEnable(GL10.GL_CULL_FACE);
|
||||
gl.glShadeModel(GL10.GL_SMOOTH);
|
||||
gl.glEnable(GL10.GL_DEPTH_TEST);
|
||||
}
|
||||
private Cube mCube;
|
||||
public float mAngleX;
|
||||
public float mAngleY;
|
||||
}
|
||||
|
||||
private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
|
||||
private final float TRACKBALL_SCALE_FACTOR = 36.0f;
|
||||
private CubeRenderer mRenderer;
|
||||
private float mPreviousX;
|
||||
private float mPreviousY;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.example.android.apis.graphics;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
||||
@@ -37,7 +38,7 @@ public class TranslucentGLSurfaceViewActivity extends Activity {
|
||||
// of the cube:
|
||||
mGLSurfaceView.setRenderer(new CubeRenderer(true));
|
||||
// Use a surface format with an Alpha channel:
|
||||
mGLSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
|
||||
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
|
||||
setContentView(mGLSurfaceView);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class TriangleActivity extends Activity {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.example.android.apis.graphics;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -24,15 +23,19 @@ import java.nio.ByteOrder;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.opengl.GLU;
|
||||
import android.opengl.GLUtils;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
import com.example.android.apis.R;
|
||||
|
||||
public class TriangleRenderer implements GLSurfaceView.Renderer{
|
||||
|
||||
@@ -51,7 +54,7 @@ public class TriangleRenderer implements GLSurfaceView.Renderer{
|
||||
return configSpec;
|
||||
}
|
||||
|
||||
public void surfaceCreated(GL10 gl) {
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
/*
|
||||
* By default, OpenGL enables features that improve quality
|
||||
* but reduce performance. One might want to tweak that
|
||||
@@ -113,7 +116,7 @@ public class TriangleRenderer implements GLSurfaceView.Renderer{
|
||||
bitmap.recycle();
|
||||
}
|
||||
|
||||
public void drawFrame(GL10 gl) {
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
/*
|
||||
* By default, OpenGL enables features that improve quality
|
||||
* but reduce performance. One might want to tweak that
|
||||
@@ -159,7 +162,7 @@ public class TriangleRenderer implements GLSurfaceView.Renderer{
|
||||
mTriangle.draw(gl);
|
||||
}
|
||||
|
||||
public void sizeChanged(GL10 gl, int w, int h) {
|
||||
public void onSurfaceChanged(GL10 gl, int w, int h) {
|
||||
gl.glViewport(0, 0, w, h);
|
||||
|
||||
/*
|
||||
|
||||
@@ -20,7 +20,7 @@ import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
|
||||
import com.example.android.apis.graphics.GLSurfaceView;
|
||||
import android.opengl.GLSurfaceView;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
package com.example.android.apis.graphics.kube;
|
||||
|
||||
import com.example.android.apis.graphics.GLSurfaceView;
|
||||
import android.opengl.GLSurfaceView;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
|
||||
@@ -36,7 +37,7 @@ class KubeRenderer implements GLSurfaceView.Renderer {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
public void drawFrame(GL10 gl) {
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
if (mCallback != null) {
|
||||
mCallback.animate();
|
||||
}
|
||||
@@ -82,7 +83,7 @@ class KubeRenderer implements GLSurfaceView.Renderer {
|
||||
return configSpec;
|
||||
}
|
||||
|
||||
public void sizeChanged(GL10 gl, int width, int height) {
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||
gl.glViewport(0, 0, width, height);
|
||||
|
||||
/*
|
||||
@@ -105,7 +106,7 @@ class KubeRenderer implements GLSurfaceView.Renderer {
|
||||
gl.glActiveTexture(GL10.GL_TEXTURE0);
|
||||
}
|
||||
|
||||
public void surfaceCreated(GL10 gl) {
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
// Nothing special, don't have any textures we need to recreate.
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
|
||||
package com.example.android.apis.graphics.spritetext;
|
||||
|
||||
import com.example.android.apis.graphics.GLSurfaceView;
|
||||
|
||||
import javax.microedition.khronos.opengles.GL;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class SpriteTextActivity extends Activity {
|
||||
|
||||
@@ -16,17 +16,6 @@
|
||||
|
||||
package com.example.android.apis.graphics.spritetext;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Paint;
|
||||
import android.opengl.GLU;
|
||||
import android.opengl.GLUtils;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
import com.example.android.apis.graphics.GLSurfaceView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -35,8 +24,20 @@ import java.nio.FloatBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Paint;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.opengl.GLU;
|
||||
import android.opengl.GLUtils;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
|
||||
public class SpriteTextRenderer implements GLSurfaceView.Renderer{
|
||||
|
||||
public SpriteTextRenderer(Context context) {
|
||||
@@ -59,7 +60,7 @@ public class SpriteTextRenderer implements GLSurfaceView.Renderer{
|
||||
return configSpec;
|
||||
}
|
||||
|
||||
public void surfaceCreated(GL10 gl) {
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||
/*
|
||||
* By default, OpenGL enables features that improve quality
|
||||
* but reduce performance. One might want to tweak that
|
||||
@@ -141,7 +142,7 @@ public class SpriteTextRenderer implements GLSurfaceView.Renderer{
|
||||
mNumericSprite.initialize(gl, mLabelPaint);
|
||||
}
|
||||
|
||||
public void drawFrame(GL10 gl) {
|
||||
public void onDrawFrame(GL10 gl) {
|
||||
/*
|
||||
* By default, OpenGL enables features that improve quality
|
||||
* but reduce performance. One might want to tweak that
|
||||
@@ -237,7 +238,7 @@ public class SpriteTextRenderer implements GLSurfaceView.Renderer{
|
||||
mLabels.draw(gl, tx, ty, labelId);
|
||||
}
|
||||
|
||||
public void sizeChanged(GL10 gl, int w, int h) {
|
||||
public void onSurfaceChanged(GL10 gl, int w, int h) {
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
gl.glViewport(0, 0, w, h);
|
||||
|
||||
@@ -19,13 +19,66 @@ package com.example.android.apis.text;
|
||||
import com.example.android.apis.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Link extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
setContentView(R.layout.link);
|
||||
|
||||
// text1 shows the android:autoLink property, which
|
||||
// automatically linkifies things like URLs and phone numbers
|
||||
// found in the text. No java code is needed to make this
|
||||
// work.
|
||||
|
||||
// text2 has links specified by putting <a> tags in the string
|
||||
// resource. By default these links will appear but not
|
||||
// respond to user input. To make them active, you need to
|
||||
// call setMovementMethod() on the TextView object.
|
||||
|
||||
TextView t2 = (TextView) findViewById(R.id.text2);
|
||||
t2.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
// text3 shows creating text with links from HTML in the Java
|
||||
// code, rather than from a string resource. Note that for a
|
||||
// fixed string, using a (localizable) resource as shown above
|
||||
// is usually a better way to go; this example is intended to
|
||||
// illustrate how you might display text that came from a
|
||||
// dynamic source (eg, the network).
|
||||
|
||||
TextView t3 = (TextView) findViewById(R.id.text3);
|
||||
t3.setText(
|
||||
Html.fromHtml(
|
||||
"<b>text3:</b> Text with a " +
|
||||
"<a href=\"http://www.google.com\">link</a> " +
|
||||
"created in the Java source code using HTML."));
|
||||
t3.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
// text4 illustrates constructing a styled string containing a
|
||||
// link without using HTML at all. Again, for a fixed string
|
||||
// you should probably be using a string resource, not a
|
||||
// hardcoded value.
|
||||
|
||||
SpannableString ss = new SpannableString(
|
||||
"text4: Click here to dial the phone.");
|
||||
|
||||
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
TextView t4 = (TextView) findViewById(R.id.text4);
|
||||
t4.setText(ss);
|
||||
t4.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Google Inc.
|
||||
*
|
||||
* 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.apis.text;
|
||||
|
||||
import com.example.android.apis.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class Marquee extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.marquee);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user