merge from froyo-plus-aosp
Change-Id: I1f4c76c89aad748b006cfc1370a767782e4ca3e7
This commit is contained in:
@@ -10,12 +10,14 @@
|
|||||||
<classpathentry kind="src" path="packages/apps/Contacts/src"/>
|
<classpathentry kind="src" path="packages/apps/Contacts/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/DeskClock/src"/>
|
<classpathentry kind="src" path="packages/apps/DeskClock/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/Email/src"/>
|
<classpathentry kind="src" path="packages/apps/Email/src"/>
|
||||||
|
<classpathentry kind="src" path="packages/apps/Gallery3D/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/HTMLViewer/src"/>
|
<classpathentry kind="src" path="packages/apps/HTMLViewer/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/Launcher2/src"/>
|
<classpathentry kind="src" path="packages/apps/Launcher2/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/Mms/src"/>
|
<classpathentry kind="src" path="packages/apps/Mms/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/PackageInstaller/src"/>
|
<classpathentry kind="src" path="packages/apps/PackageInstaller/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/Phone/src"/>
|
<classpathentry kind="src" path="packages/apps/Phone/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/QuickSearchBox/src"/>
|
<classpathentry kind="src" path="packages/apps/QuickSearchBox/src"/>
|
||||||
|
<classpathentry kind="src" path="packages/apps/Provision/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/Settings/src"/>
|
<classpathentry kind="src" path="packages/apps/Settings/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/SoundRecorder/src"/>
|
<classpathentry kind="src" path="packages/apps/SoundRecorder/src"/>
|
||||||
<classpathentry kind="src" path="packages/apps/Stk/src"/>
|
<classpathentry kind="src" path="packages/apps/Stk/src"/>
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import com.example.android.apis.R;
|
|||||||
import com.example.android.apis.view.Controls1;
|
import com.example.android.apis.view.Controls1;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ package com.example.android.apis.app;
|
|||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -29,7 +27,6 @@ import android.widget.Button;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Front-end for launching {@link ContactsFilterInstrumentation} example
|
* Front-end for launching {@link ContactsFilterInstrumentation} example
|
||||||
* instrumentation class.
|
* instrumentation class.
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import android.view.KeyEvent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an example implementation of the {@link android.app.Instrumentation}
|
* This is an example implementation of the {@link android.app.Instrumentation}
|
||||||
* class, allowing you to run tests against application code. The
|
* class, allowing you to run tests against application code. The
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.example.android.apis.app;
|
|||||||
import com.example.android.apis.ApiDemosApplication;
|
import com.example.android.apis.ApiDemosApplication;
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ public class ForegroundService extends Service {
|
|||||||
static final String ACTION_BACKGROUND = "com.example.android.apis.BACKGROUND";
|
static final String ACTION_BACKGROUND = "com.example.android.apis.BACKGROUND";
|
||||||
|
|
||||||
// BEGIN_INCLUDE(foreground_compatibility)
|
// BEGIN_INCLUDE(foreground_compatibility)
|
||||||
private static final Class[] mStartForegroundSignature = new Class[] {
|
private static final Class<?>[] mStartForegroundSignature = new Class[] {
|
||||||
int.class, Notification.class};
|
int.class, Notification.class};
|
||||||
private static final Class[] mStopForegroundSignature = new Class[] {
|
private static final Class<?>[] mStopForegroundSignature = new Class[] {
|
||||||
boolean.class};
|
boolean.class};
|
||||||
|
|
||||||
private NotificationManager mNM;
|
private NotificationManager mNM;
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ package com.example.android.apis.app;
|
|||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -29,7 +27,6 @@ import android.widget.Button;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Front-end for launching {@link LocalSampleInstrumentation} example
|
* Front-end for launching {@link LocalSampleInstrumentation} example
|
||||||
* instrumentation class.
|
* instrumentation class.
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import android.view.KeyEvent;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an example implementation of the {@link android.app.Instrumentation}
|
* This is an example implementation of the {@link android.app.Instrumentation}
|
||||||
* class demonstrating instrumentation against one of this application's sample
|
* class demonstrating instrumentation against one of this application's sample
|
||||||
|
|||||||
@@ -45,6 +45,10 @@ import com.example.android.apis.R;
|
|||||||
public class LocalService extends Service {
|
public class LocalService extends Service {
|
||||||
private NotificationManager mNM;
|
private NotificationManager mNM;
|
||||||
|
|
||||||
|
// Unique Identification Number for the Notification.
|
||||||
|
// We use it on Notification start, and to cancel it.
|
||||||
|
private int NOTIFICATION = R.string.local_service_started;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for clients to access. Because we know this service always
|
* Class for clients to access. Because we know this service always
|
||||||
* runs in the same process as its clients, we don't need to deal with
|
* runs in the same process as its clients, we don't need to deal with
|
||||||
@@ -75,7 +79,7 @@ public class LocalService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
// Cancel the persistent notification.
|
// Cancel the persistent notification.
|
||||||
mNM.cancel(R.string.local_service_started);
|
mNM.cancel(NOTIFICATION);
|
||||||
|
|
||||||
// Tell the user we stopped.
|
// Tell the user we stopped.
|
||||||
Toast.makeText(this, R.string.local_service_stopped, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.local_service_stopped, Toast.LENGTH_SHORT).show();
|
||||||
@@ -110,8 +114,7 @@ public class LocalService extends Service {
|
|||||||
text, contentIntent);
|
text, contentIntent);
|
||||||
|
|
||||||
// Send the notification.
|
// Send the notification.
|
||||||
// We use a layout id because it is a unique number. We use it later to cancel.
|
mNM.notify(NOTIFICATION, notification);
|
||||||
mNM.notify(R.string.local_service_started, notification);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//END_INCLUDE(service)
|
//END_INCLUDE(service)
|
||||||
|
|||||||
@@ -24,14 +24,11 @@ import android.app.Activity;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity used by StatusBarNotification to show the notification to the user.
|
* Activity used by StatusBarNotification to show the notification to the user.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -21,14 +21,12 @@ package com.example.android.apis.app;
|
|||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller to start and stop a service. The serivce will update a status bar
|
* Controller to start and stop a service. The serivce will update a status bar
|
||||||
* notification every 5 seconds for a minute.
|
* notification every 5 seconds for a minute.
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import android.os.ConditionVariable;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.widget.RemoteViews;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an example of service that will update its status bar balloon
|
* This is an example of service that will update its status bar balloon
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ package com.example.android.apis.app;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
|
||||||
public class PreferencesFromXml extends PreferenceActivity {
|
public class PreferencesFromXml extends PreferenceActivity {
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ public class QuickContactsDemo extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
final ContactListItemCache cache = (ContactListItemCache) view.getTag();
|
final ContactListItemCache cache = (ContactListItemCache) view.getTag();
|
||||||
TextView nameView = cache.nameView;
|
|
||||||
QuickContactBadge photoView = cache.photoView;
|
|
||||||
// Set the name
|
// Set the name
|
||||||
cursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);
|
cursor.copyStringToBuffer(SUMMARY_NAME_COLUMN_INDEX, cache.nameBuffer);
|
||||||
int size = cache.nameBuffer.sizeCopied;
|
int size = cache.nameBuffer.sizeCopied;
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ package com.example.android.apis.app;
|
|||||||
|
|
||||||
// Need the following import to get access to the app resources, since this
|
// Need the following import to get access to the app resources, since this
|
||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -31,8 +29,6 @@ import android.view.View.OnClickListener;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows how an activity can send data to its launching activity when done.y.
|
* Shows how an activity can send data to its launching activity when done.y.
|
||||||
* <p>This can be used, for example, to implement a dialog alowing the user to
|
* <p>This can be used, for example, to implement a dialog alowing the user to
|
||||||
|
|||||||
@@ -32,8 +32,11 @@ import android.widget.TextView;
|
|||||||
*/
|
*/
|
||||||
public class RedirectGetter extends Activity
|
public class RedirectGetter extends Activity
|
||||||
{
|
{
|
||||||
|
private String mTextPref;
|
||||||
|
private TextView mText;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState)
|
protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
@@ -45,9 +48,12 @@ public class RedirectGetter extends Activity
|
|||||||
|
|
||||||
// The text being set.
|
// The text being set.
|
||||||
mText = (TextView)findViewById(R.id.text);
|
mText = (TextView)findViewById(R.id.text);
|
||||||
|
|
||||||
|
// Display the stored values, or if not stored initialize with an empty String
|
||||||
|
loadPrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final boolean loadPrefs()
|
private final void loadPrefs()
|
||||||
{
|
{
|
||||||
// Retrieve the current redirect values.
|
// Retrieve the current redirect values.
|
||||||
// NOTE: because this preference is shared between multiple
|
// NOTE: because this preference is shared between multiple
|
||||||
@@ -58,10 +64,9 @@ public class RedirectGetter extends Activity
|
|||||||
mTextPref = preferences.getString("text", null);
|
mTextPref = preferences.getString("text", null);
|
||||||
if (mTextPref != null) {
|
if (mTextPref != null) {
|
||||||
mText.setText(mTextPref);
|
mText.setText(mTextPref);
|
||||||
return true;
|
} else {
|
||||||
|
mText.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnClickListener mApplyListener = new OnClickListener()
|
private OnClickListener mApplyListener = new OnClickListener()
|
||||||
@@ -79,8 +84,4 @@ public class RedirectGetter extends Activity
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private String mTextPref;
|
|
||||||
TextView mText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import android.graphics.PorterDuff;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import com.example.android.apis.R;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.WindowManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h3>Wallpaper Activity</h3>
|
* <h3>Wallpaper Activity</h3>
|
||||||
|
|||||||
@@ -18,15 +18,12 @@ package com.example.android.apis.graphics;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
|
|
||||||
public class AlphaBitmap extends GraphicsActivity {
|
public class AlphaBitmap extends GraphicsActivity {
|
||||||
|
|
||||||
@@ -35,23 +32,23 @@ public class AlphaBitmap extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
private Bitmap mBitmap2;
|
private Bitmap mBitmap2;
|
||||||
private Bitmap mBitmap3;
|
private Bitmap mBitmap3;
|
||||||
private Shader mShader;
|
private Shader mShader;
|
||||||
|
|
||||||
private static void drawIntoBitmap(Bitmap bm) {
|
private static void drawIntoBitmap(Bitmap bm) {
|
||||||
float x = bm.getWidth();
|
float x = bm.getWidth();
|
||||||
float y = bm.getHeight();
|
float y = bm.getHeight();
|
||||||
Canvas c = new Canvas(bm);
|
Canvas c = new Canvas(bm);
|
||||||
Paint p = new Paint();
|
Paint p = new Paint();
|
||||||
p.setAntiAlias(true);
|
p.setAntiAlias(true);
|
||||||
|
|
||||||
p.setAlpha(0x80);
|
p.setAlpha(0x80);
|
||||||
c.drawCircle(x/2, y/2, x/2, p);
|
c.drawCircle(x/2, y/2, x/2, p);
|
||||||
|
|
||||||
p.setAlpha(0x30);
|
p.setAlpha(0x30);
|
||||||
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
|
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
|
||||||
p.setTextSize(60);
|
p.setTextSize(60);
|
||||||
@@ -59,28 +56,28 @@ public class AlphaBitmap extends GraphicsActivity {
|
|||||||
Paint.FontMetrics fm = p.getFontMetrics();
|
Paint.FontMetrics fm = p.getFontMetrics();
|
||||||
c.drawText("Alpha", x/2, (y-fm.ascent)/2, p);
|
c.drawText("Alpha", x/2, (y-fm.ascent)/2, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code);
|
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code);
|
||||||
mBitmap = BitmapFactory.decodeStream(is);
|
mBitmap = BitmapFactory.decodeStream(is);
|
||||||
mBitmap2 = mBitmap.extractAlpha();
|
mBitmap2 = mBitmap.extractAlpha();
|
||||||
mBitmap3 = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
|
mBitmap3 = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
|
||||||
drawIntoBitmap(mBitmap3);
|
drawIntoBitmap(mBitmap3);
|
||||||
|
|
||||||
mShader = new LinearGradient(0, 0, 100, 70, new int[] {
|
mShader = new LinearGradient(0, 0, 100, 70, new int[] {
|
||||||
Color.RED, Color.GREEN, Color.BLUE },
|
Color.RED, Color.GREEN, Color.BLUE },
|
||||||
null, Shader.TileMode.MIRROR);
|
null, Shader.TileMode.MIRROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
Paint p = new Paint();
|
Paint p = new Paint();
|
||||||
float y = 10;
|
float y = 10;
|
||||||
|
|
||||||
p.setColor(Color.RED);
|
p.setColor(Color.RED);
|
||||||
canvas.drawBitmap(mBitmap, 10, y, p);
|
canvas.drawBitmap(mBitmap, 10, y, p);
|
||||||
y += mBitmap.getHeight() + 10;
|
y += mBitmap.getHeight() + 10;
|
||||||
|
|||||||
@@ -23,23 +23,23 @@ import android.view.animation.AnimationUtils;
|
|||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
|
|
||||||
public class AnimateDrawable extends ProxyDrawable {
|
public class AnimateDrawable extends ProxyDrawable {
|
||||||
|
|
||||||
private Animation mAnimation;
|
private Animation mAnimation;
|
||||||
private Transformation mTransformation = new Transformation();
|
private Transformation mTransformation = new Transformation();
|
||||||
|
|
||||||
public AnimateDrawable(Drawable target) {
|
public AnimateDrawable(Drawable target) {
|
||||||
super(target);
|
super(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnimateDrawable(Drawable target, Animation animation) {
|
public AnimateDrawable(Drawable target, Animation animation) {
|
||||||
super(target);
|
super(target);
|
||||||
mAnimation = animation;
|
mAnimation = animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Animation getAnimation() {
|
public Animation getAnimation() {
|
||||||
return mAnimation;
|
return mAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAnimation(Animation anim) {
|
public void setAnimation(Animation anim) {
|
||||||
mAnimation = anim;
|
mAnimation = anim;
|
||||||
}
|
}
|
||||||
@@ -47,11 +47,11 @@ public class AnimateDrawable extends ProxyDrawable {
|
|||||||
public boolean hasStarted() {
|
public boolean hasStarted() {
|
||||||
return mAnimation != null && mAnimation.hasStarted();
|
return mAnimation != null && mAnimation.hasStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEnded() {
|
public boolean hasEnded() {
|
||||||
return mAnimation == null || mAnimation.hasEnded();
|
return mAnimation == null || mAnimation.hasEnded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
Drawable dr = getProxy();
|
Drawable dr = getProxy();
|
||||||
@@ -69,4 +69,4 @@ public class AnimateDrawable extends ProxyDrawable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ package com.example.android.apis.graphics;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.*;
|
import android.graphics.Color;
|
||||||
import android.view.animation.*;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.TranslateAnimation;
|
||||||
|
|
||||||
public class AnimateDrawables extends GraphicsActivity {
|
public class AnimateDrawables extends GraphicsActivity {
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ public class AnimateDrawables extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private AnimateDrawable mDrawable;
|
private AnimateDrawable mDrawable;
|
||||||
|
|
||||||
@@ -45,17 +45,18 @@ public class AnimateDrawables extends GraphicsActivity {
|
|||||||
|
|
||||||
Drawable dr = context.getResources().getDrawable(R.drawable.beach);
|
Drawable dr = context.getResources().getDrawable(R.drawable.beach);
|
||||||
dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
|
dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
|
||||||
|
|
||||||
Animation an = new TranslateAnimation(0, 100, 0, 200);
|
Animation an = new TranslateAnimation(0, 100, 0, 200);
|
||||||
an.setDuration(2000);
|
an.setDuration(2000);
|
||||||
an.setRepeatCount(-1);
|
an.setRepeatCount(-1);
|
||||||
an.initialize(10, 10, 10, 10);
|
an.initialize(10, 10, 10, 10);
|
||||||
|
|
||||||
mDrawable = new AnimateDrawable(dr, an);
|
mDrawable = new AnimateDrawable(dr, an);
|
||||||
an.startNow();
|
an.startNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package com.example.android.apis.graphics;
|
|||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
//import com.example.android.apis.R;
|
//import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -33,7 +32,7 @@ public class Arcs extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint[] mPaints;
|
private Paint[] mPaints;
|
||||||
private Paint mFramePaint;
|
private Paint mFramePaint;
|
||||||
@@ -43,27 +42,27 @@ public class Arcs extends GraphicsActivity {
|
|||||||
private float mStart;
|
private float mStart;
|
||||||
private float mSweep;
|
private float mSweep;
|
||||||
private int mBigIndex;
|
private int mBigIndex;
|
||||||
|
|
||||||
private static final float SWEEP_INC = 2;
|
private static final float SWEEP_INC = 2;
|
||||||
private static final float START_INC = 15;
|
private static final float START_INC = 15;
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mPaints = new Paint[4];
|
mPaints = new Paint[4];
|
||||||
mUseCenters = new boolean[4];
|
mUseCenters = new boolean[4];
|
||||||
mOvals = new RectF[4];
|
mOvals = new RectF[4];
|
||||||
|
|
||||||
mPaints[0] = new Paint();
|
mPaints[0] = new Paint();
|
||||||
mPaints[0].setAntiAlias(true);
|
mPaints[0].setAntiAlias(true);
|
||||||
mPaints[0].setStyle(Paint.Style.FILL);
|
mPaints[0].setStyle(Paint.Style.FILL);
|
||||||
mPaints[0].setColor(0x88FF0000);
|
mPaints[0].setColor(0x88FF0000);
|
||||||
mUseCenters[0] = false;
|
mUseCenters[0] = false;
|
||||||
|
|
||||||
mPaints[1] = new Paint(mPaints[0]);
|
mPaints[1] = new Paint(mPaints[0]);
|
||||||
mPaints[1].setColor(0x8800FF00);
|
mPaints[1].setColor(0x8800FF00);
|
||||||
mUseCenters[1] = true;
|
mUseCenters[1] = true;
|
||||||
|
|
||||||
mPaints[2] = new Paint(mPaints[0]);
|
mPaints[2] = new Paint(mPaints[0]);
|
||||||
mPaints[2].setStyle(Paint.Style.STROKE);
|
mPaints[2].setStyle(Paint.Style.STROKE);
|
||||||
mPaints[2].setStrokeWidth(4);
|
mPaints[2].setStrokeWidth(4);
|
||||||
@@ -73,36 +72,36 @@ public class Arcs extends GraphicsActivity {
|
|||||||
mPaints[3] = new Paint(mPaints[2]);
|
mPaints[3] = new Paint(mPaints[2]);
|
||||||
mPaints[3].setColor(0x88888888);
|
mPaints[3].setColor(0x88888888);
|
||||||
mUseCenters[3] = true;
|
mUseCenters[3] = true;
|
||||||
|
|
||||||
mBigOval = new RectF(40, 10, 280, 250);
|
mBigOval = new RectF(40, 10, 280, 250);
|
||||||
|
|
||||||
mOvals[0] = new RectF( 10, 270, 70, 330);
|
mOvals[0] = new RectF( 10, 270, 70, 330);
|
||||||
mOvals[1] = new RectF( 90, 270, 150, 330);
|
mOvals[1] = new RectF( 90, 270, 150, 330);
|
||||||
mOvals[2] = new RectF(170, 270, 230, 330);
|
mOvals[2] = new RectF(170, 270, 230, 330);
|
||||||
mOvals[3] = new RectF(250, 270, 310, 330);
|
mOvals[3] = new RectF(250, 270, 310, 330);
|
||||||
|
|
||||||
mFramePaint = new Paint();
|
mFramePaint = new Paint();
|
||||||
mFramePaint.setAntiAlias(true);
|
mFramePaint.setAntiAlias(true);
|
||||||
mFramePaint.setStyle(Paint.Style.STROKE);
|
mFramePaint.setStyle(Paint.Style.STROKE);
|
||||||
mFramePaint.setStrokeWidth(0);
|
mFramePaint.setStrokeWidth(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawArcs(Canvas canvas, RectF oval, boolean useCenter,
|
private void drawArcs(Canvas canvas, RectF oval, boolean useCenter,
|
||||||
Paint paint) {
|
Paint paint) {
|
||||||
canvas.drawRect(oval, mFramePaint);
|
canvas.drawRect(oval, mFramePaint);
|
||||||
canvas.drawArc(oval, mStart, mSweep, useCenter, paint);
|
canvas.drawArc(oval, mStart, mSweep, useCenter, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
drawArcs(canvas, mBigOval, mUseCenters[mBigIndex],
|
drawArcs(canvas, mBigOval, mUseCenters[mBigIndex],
|
||||||
mPaints[mBigIndex]);
|
mPaints[mBigIndex]);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
drawArcs(canvas, mOvals[i], mUseCenters[i], mPaints[i]);
|
drawArcs(canvas, mOvals[i], mUseCenters[i], mPaints[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSweep += SWEEP_INC;
|
mSweep += SWEEP_INC;
|
||||||
if (mSweep > 360) {
|
if (mSweep > 360) {
|
||||||
mSweep -= 360;
|
mSweep -= 360;
|
||||||
|
|||||||
@@ -18,36 +18,36 @@ package com.example.android.apis.graphics;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.*;
|
import android.graphics.drawable.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
public class BitmapDecode extends GraphicsActivity {
|
public class BitmapDecode extends GraphicsActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
private Bitmap mBitmap2;
|
private Bitmap mBitmap2;
|
||||||
private Bitmap mBitmap3;
|
private Bitmap mBitmap3;
|
||||||
private Bitmap mBitmap4;
|
private Bitmap mBitmap4;
|
||||||
private Drawable mDrawable;
|
private Drawable mDrawable;
|
||||||
|
|
||||||
private Movie mMovie;
|
private Movie mMovie;
|
||||||
private long mMovieStart;
|
private long mMovieStart;
|
||||||
|
|
||||||
|
//Set to false to use decodeByteArray
|
||||||
|
private static final boolean DECODE_STREAM = true;
|
||||||
|
|
||||||
private static byte[] streamToBytes(InputStream is) {
|
private static byte[] streamToBytes(InputStream is) {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
|
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
@@ -60,33 +60,33 @@ public class BitmapDecode extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
return os.toByteArray();
|
return os.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
java.io.InputStream is;
|
java.io.InputStream is;
|
||||||
is = context.getResources().openRawResource(R.drawable.beach);
|
is = context.getResources().openRawResource(R.drawable.beach);
|
||||||
|
|
||||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||||
Bitmap bm;
|
Bitmap bm;
|
||||||
|
|
||||||
opts.inJustDecodeBounds = true;
|
opts.inJustDecodeBounds = true;
|
||||||
bm = BitmapFactory.decodeStream(is, null, opts);
|
bm = BitmapFactory.decodeStream(is, null, opts);
|
||||||
|
|
||||||
// now opts.outWidth and opts.outHeight are the dimension of the
|
// now opts.outWidth and opts.outHeight are the dimension of the
|
||||||
// bitmap, even though bm is null
|
// bitmap, even though bm is null
|
||||||
|
|
||||||
opts.inJustDecodeBounds = false; // this will request the bm
|
opts.inJustDecodeBounds = false; // this will request the bm
|
||||||
opts.inSampleSize = 4; // scaled down by 4
|
opts.inSampleSize = 4; // scaled down by 4
|
||||||
bm = BitmapFactory.decodeStream(is, null, opts);
|
bm = BitmapFactory.decodeStream(is, null, opts);
|
||||||
|
|
||||||
mBitmap = bm;
|
mBitmap = bm;
|
||||||
|
|
||||||
// decode an image with transparency
|
// decode an image with transparency
|
||||||
is = context.getResources().openRawResource(R.drawable.frog);
|
is = context.getResources().openRawResource(R.drawable.frog);
|
||||||
mBitmap2 = BitmapFactory.decodeStream(is);
|
mBitmap2 = BitmapFactory.decodeStream(is);
|
||||||
|
|
||||||
// create a deep copy of it using getPixels() into different configs
|
// create a deep copy of it using getPixels() into different configs
|
||||||
int w = mBitmap2.getWidth();
|
int w = mBitmap2.getWidth();
|
||||||
int h = mBitmap2.getHeight();
|
int h = mBitmap2.getHeight();
|
||||||
@@ -96,32 +96,34 @@ public class BitmapDecode extends GraphicsActivity {
|
|||||||
Bitmap.Config.ARGB_8888);
|
Bitmap.Config.ARGB_8888);
|
||||||
mBitmap4 = Bitmap.createBitmap(pixels, 0, w, w, h,
|
mBitmap4 = Bitmap.createBitmap(pixels, 0, w, w, h,
|
||||||
Bitmap.Config.ARGB_4444);
|
Bitmap.Config.ARGB_4444);
|
||||||
|
|
||||||
mDrawable = context.getResources().getDrawable(R.drawable.button);
|
mDrawable = context.getResources().getDrawable(R.drawable.button);
|
||||||
mDrawable.setBounds(150, 20, 300, 100);
|
mDrawable.setBounds(150, 20, 300, 100);
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.drawable.animated_gif);
|
is = context.getResources().openRawResource(R.drawable.animated_gif);
|
||||||
if (true) {
|
|
||||||
|
if (DECODE_STREAM) {
|
||||||
mMovie = Movie.decodeStream(is);
|
mMovie = Movie.decodeStream(is);
|
||||||
} else {
|
} else {
|
||||||
byte[] array = streamToBytes(is);
|
byte[] array = streamToBytes(is);
|
||||||
mMovie = Movie.decodeByteArray(array, 0, array.length);
|
mMovie = Movie.decodeByteArray(array, 0, array.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override
|
||||||
canvas.drawColor(0xFFCCCCCC);
|
protected void onDraw(Canvas canvas) {
|
||||||
|
canvas.drawColor(0xFFCCCCCC);
|
||||||
|
|
||||||
Paint p = new Paint();
|
Paint p = new Paint();
|
||||||
p.setAntiAlias(true);
|
p.setAntiAlias(true);
|
||||||
|
|
||||||
canvas.drawBitmap(mBitmap, 10, 10, null);
|
canvas.drawBitmap(mBitmap, 10, 10, null);
|
||||||
canvas.drawBitmap(mBitmap2, 10, 170, null);
|
canvas.drawBitmap(mBitmap2, 10, 170, null);
|
||||||
canvas.drawBitmap(mBitmap3, 110, 170, null);
|
canvas.drawBitmap(mBitmap3, 110, 170, null);
|
||||||
canvas.drawBitmap(mBitmap4, 210, 170, null);
|
canvas.drawBitmap(mBitmap4, 210, 170, null);
|
||||||
|
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
|
|
||||||
long now = android.os.SystemClock.uptimeMillis();
|
long now = android.os.SystemClock.uptimeMillis();
|
||||||
if (mMovieStart == 0) { // first time
|
if (mMovieStart == 0) { // first time
|
||||||
mMovieStart = now;
|
mMovieStart = now;
|
||||||
@@ -140,4 +142,3 @@ public class BitmapDecode extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,16 +31,16 @@ public class BitmapMesh extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private static final int WIDTH = 20;
|
private static final int WIDTH = 20;
|
||||||
private static final int HEIGHT = 20;
|
private static final int HEIGHT = 20;
|
||||||
private static final int COUNT = (WIDTH + 1) * (HEIGHT + 1);
|
private static final int COUNT = (WIDTH + 1) * (HEIGHT + 1);
|
||||||
|
|
||||||
private final Bitmap mBitmap;
|
private final Bitmap mBitmap;
|
||||||
private final float[] mVerts = new float[COUNT*2];
|
private final float[] mVerts = new float[COUNT*2];
|
||||||
private final float[] mOrig = new float[COUNT*2];
|
private final float[] mOrig = new float[COUNT*2];
|
||||||
|
|
||||||
private final Matrix mMatrix = new Matrix();
|
private final Matrix mMatrix = new Matrix();
|
||||||
private final Matrix mInverse = new Matrix();
|
private final Matrix mInverse = new Matrix();
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public class BitmapMesh extends GraphicsActivity {
|
|||||||
|
|
||||||
mBitmap = BitmapFactory.decodeResource(getResources(),
|
mBitmap = BitmapFactory.decodeResource(getResources(),
|
||||||
R.drawable.beach);
|
R.drawable.beach);
|
||||||
|
|
||||||
float w = mBitmap.getWidth();
|
float w = mBitmap.getWidth();
|
||||||
float h = mBitmap.getHeight();
|
float h = mBitmap.getHeight();
|
||||||
// construct our mesh
|
// construct our mesh
|
||||||
@@ -63,17 +63,17 @@ public class BitmapMesh extends GraphicsActivity {
|
|||||||
for (int y = 0; y <= HEIGHT; y++) {
|
for (int y = 0; y <= HEIGHT; y++) {
|
||||||
float fy = h * y / HEIGHT;
|
float fy = h * y / HEIGHT;
|
||||||
for (int x = 0; x <= WIDTH; x++) {
|
for (int x = 0; x <= WIDTH; x++) {
|
||||||
float fx = w * x / WIDTH;
|
float fx = w * x / WIDTH;
|
||||||
setXY(mVerts, index, fx, fy);
|
setXY(mVerts, index, fx, fy);
|
||||||
setXY(mOrig, index, fx, fy);
|
setXY(mOrig, index, fx, fy);
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mMatrix.setTranslate(10, 10);
|
mMatrix.setTranslate(10, 10);
|
||||||
mMatrix.invert(mInverse);
|
mMatrix.invert(mInverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(0xFFCCCCCC);
|
canvas.drawColor(0xFFCCCCCC);
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class BitmapMesh extends GraphicsActivity {
|
|||||||
canvas.drawBitmapMesh(mBitmap, WIDTH, HEIGHT, mVerts, 0,
|
canvas.drawBitmapMesh(mBitmap, WIDTH, HEIGHT, mVerts, 0,
|
||||||
null, 0, null);
|
null, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void warp(float cx, float cy) {
|
private void warp(float cx, float cy) {
|
||||||
final float K = 10000;
|
final float K = 10000;
|
||||||
float[] src = mOrig;
|
float[] src = mOrig;
|
||||||
@@ -94,7 +94,7 @@ public class BitmapMesh extends GraphicsActivity {
|
|||||||
float dd = dx*dx + dy*dy;
|
float dd = dx*dx + dy*dy;
|
||||||
float d = FloatMath.sqrt(dd);
|
float d = FloatMath.sqrt(dd);
|
||||||
float pull = K / (dd + 0.000001f);
|
float pull = K / (dd + 0.000001f);
|
||||||
|
|
||||||
pull /= (d + 0.000001f);
|
pull /= (d + 0.000001f);
|
||||||
// android.util.Log.d("skia", "index " + i + " dist=" + d + " pull=" + pull);
|
// android.util.Log.d("skia", "index " + i + " dist=" + d + " pull=" + pull);
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ public class BitmapMesh extends GraphicsActivity {
|
|||||||
@Override public boolean onTouchEvent(MotionEvent event) {
|
@Override public boolean onTouchEvent(MotionEvent event) {
|
||||||
float[] pt = { event.getX(), event.getY() };
|
float[] pt = { event.getX(), event.getY() };
|
||||||
mInverse.mapPoints(pt);
|
mInverse.mapPoints(pt);
|
||||||
|
|
||||||
int x = (int)pt[0];
|
int x = (int)pt[0];
|
||||||
int y = (int)pt[1];
|
int y = (int)pt[1];
|
||||||
if (mLastWarpX != x || mLastWarpY != y) {
|
if (mLastWarpX != x || mLastWarpY != y) {
|
||||||
|
|||||||
@@ -16,32 +16,26 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.*;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
public class BitmapPixels extends GraphicsActivity {
|
public class BitmapPixels extends GraphicsActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Bitmap mBitmap1;
|
private Bitmap mBitmap1;
|
||||||
private Bitmap mBitmap2;
|
private Bitmap mBitmap2;
|
||||||
private Bitmap mBitmap3;
|
private Bitmap mBitmap3;
|
||||||
private Bitmap mBitmap4;
|
|
||||||
|
|
||||||
// access the red component from a premultiplied color
|
// access the red component from a premultiplied color
|
||||||
private static int getR32(int c) { return (c >> 0) & 0xFF; }
|
private static int getR32(int c) { return (c >> 0) & 0xFF; }
|
||||||
@@ -67,7 +61,7 @@ public class BitmapPixels extends GraphicsActivity {
|
|||||||
private static short pack4444(int r, int g, int b, int a) {
|
private static short pack4444(int r, int g, int b, int a) {
|
||||||
return (short)((a << 0) | ( b << 4) | (g << 8) | (r << 12));
|
return (short)((a << 0) | ( b << 4) | (g << 8) | (r << 12));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int mul255(int c, int a) {
|
private static int mul255(int c, int a) {
|
||||||
int prod = c * a + 128;
|
int prod = c * a + 128;
|
||||||
return (prod + (prod >> 8)) >> 8;
|
return (prod + (prod >> 8)) >> 8;
|
||||||
@@ -88,7 +82,7 @@ public class BitmapPixels extends GraphicsActivity {
|
|||||||
// now pack it in the correct order
|
// now pack it in the correct order
|
||||||
return pack8888(r, g, b, a);
|
return pack8888(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeRamp(int from, int to, int n,
|
private static void makeRamp(int from, int to, int n,
|
||||||
int[] ramp8888, short[] ramp565,
|
int[] ramp8888, short[] ramp565,
|
||||||
short[] ramp4444) {
|
short[] ramp4444) {
|
||||||
@@ -113,7 +107,7 @@ public class BitmapPixels extends GraphicsActivity {
|
|||||||
a += da;
|
a += da;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IntBuffer makeBuffer(int[] src, int n) {
|
private static IntBuffer makeBuffer(int[] src, int n) {
|
||||||
IntBuffer dst = IntBuffer.allocate(n*n);
|
IntBuffer dst = IntBuffer.allocate(n*n);
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@@ -122,7 +116,7 @@ public class BitmapPixels extends GraphicsActivity {
|
|||||||
dst.rewind();
|
dst.rewind();
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ShortBuffer makeBuffer(short[] src, int n) {
|
private static ShortBuffer makeBuffer(short[] src, int n) {
|
||||||
ShortBuffer dst = ShortBuffer.allocate(n*n);
|
ShortBuffer dst = ShortBuffer.allocate(n*n);
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
@@ -131,31 +125,31 @@ public class BitmapPixels extends GraphicsActivity {
|
|||||||
dst.rewind();
|
dst.rewind();
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
final int N = 100;
|
final int N = 100;
|
||||||
int[] data8888 = new int[N];
|
int[] data8888 = new int[N];
|
||||||
short[] data565 = new short[N];
|
short[] data565 = new short[N];
|
||||||
short[] data4444 = new short[N];
|
short[] data4444 = new short[N];
|
||||||
|
|
||||||
makeRamp(premultiplyColor(Color.RED), premultiplyColor(Color.GREEN),
|
makeRamp(premultiplyColor(Color.RED), premultiplyColor(Color.GREEN),
|
||||||
N, data8888, data565, data4444);
|
N, data8888, data565, data4444);
|
||||||
|
|
||||||
mBitmap1 = Bitmap.createBitmap(N, N, Bitmap.Config.ARGB_8888);
|
mBitmap1 = Bitmap.createBitmap(N, N, Bitmap.Config.ARGB_8888);
|
||||||
mBitmap2 = Bitmap.createBitmap(N, N, Bitmap.Config.RGB_565);
|
mBitmap2 = Bitmap.createBitmap(N, N, Bitmap.Config.RGB_565);
|
||||||
mBitmap3 = Bitmap.createBitmap(N, N, Bitmap.Config.ARGB_4444);
|
mBitmap3 = Bitmap.createBitmap(N, N, Bitmap.Config.ARGB_4444);
|
||||||
|
|
||||||
mBitmap1.copyPixelsFromBuffer(makeBuffer(data8888, N));
|
mBitmap1.copyPixelsFromBuffer(makeBuffer(data8888, N));
|
||||||
mBitmap2.copyPixelsFromBuffer(makeBuffer(data565, N));
|
mBitmap2.copyPixelsFromBuffer(makeBuffer(data565, N));
|
||||||
mBitmap3.copyPixelsFromBuffer(makeBuffer(data4444, N));
|
mBitmap3.copyPixelsFromBuffer(makeBuffer(data4444, N));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(0xFFCCCCCC);
|
canvas.drawColor(0xFFCCCCCC);
|
||||||
|
|
||||||
int y = 10;
|
int y = 10;
|
||||||
canvas.drawBitmap(mBitmap1, 10, y, null);
|
canvas.drawBitmap(mBitmap1, 10, y, null);
|
||||||
y += mBitmap1.getHeight() + 10;
|
y += mBitmap1.getHeight() + 10;
|
||||||
@@ -165,4 +159,3 @@ public class BitmapPixels extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,7 +28,7 @@ public class Clipping extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
@@ -37,46 +36,46 @@ public class Clipping extends GraphicsActivity {
|
|||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setStrokeWidth(6);
|
mPaint.setStrokeWidth(6);
|
||||||
mPaint.setTextSize(16);
|
mPaint.setTextSize(16);
|
||||||
mPaint.setTextAlign(Paint.Align.RIGHT);
|
mPaint.setTextAlign(Paint.Align.RIGHT);
|
||||||
|
|
||||||
mPath = new Path();
|
mPath = new Path();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawScene(Canvas canvas) {
|
private void drawScene(Canvas canvas) {
|
||||||
canvas.clipRect(0, 0, 100, 100);
|
canvas.clipRect(0, 0, 100, 100);
|
||||||
|
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
mPaint.setColor(Color.RED);
|
mPaint.setColor(Color.RED);
|
||||||
canvas.drawLine(0, 0, 100, 100, mPaint);
|
canvas.drawLine(0, 0, 100, 100, mPaint);
|
||||||
|
|
||||||
mPaint.setColor(Color.GREEN);
|
mPaint.setColor(Color.GREEN);
|
||||||
canvas.drawCircle(30, 70, 30, mPaint);
|
canvas.drawCircle(30, 70, 30, mPaint);
|
||||||
|
|
||||||
mPaint.setColor(Color.BLUE);
|
mPaint.setColor(Color.BLUE);
|
||||||
canvas.drawText("Clipping", 100, 30, mPaint);
|
canvas.drawText("Clipping", 100, 30, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.GRAY);
|
canvas.drawColor(Color.GRAY);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
drawScene(canvas);
|
drawScene(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(160, 10);
|
canvas.translate(160, 10);
|
||||||
canvas.clipRect(10, 10, 90, 90);
|
canvas.clipRect(10, 10, 90, 90);
|
||||||
canvas.clipRect(30, 30, 70, 70, Region.Op.DIFFERENCE);
|
canvas.clipRect(30, 30, 70, 70, Region.Op.DIFFERENCE);
|
||||||
drawScene(canvas);
|
drawScene(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10, 160);
|
canvas.translate(10, 160);
|
||||||
mPath.reset();
|
mPath.reset();
|
||||||
@@ -85,21 +84,21 @@ public class Clipping extends GraphicsActivity {
|
|||||||
canvas.clipPath(mPath, Region.Op.REPLACE);
|
canvas.clipPath(mPath, Region.Op.REPLACE);
|
||||||
drawScene(canvas);
|
drawScene(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(160, 160);
|
canvas.translate(160, 160);
|
||||||
canvas.clipRect(0, 0, 60, 60);
|
canvas.clipRect(0, 0, 60, 60);
|
||||||
canvas.clipRect(40, 40, 100, 100, Region.Op.UNION);
|
canvas.clipRect(40, 40, 100, 100, Region.Op.UNION);
|
||||||
drawScene(canvas);
|
drawScene(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10, 310);
|
canvas.translate(10, 310);
|
||||||
canvas.clipRect(0, 0, 60, 60);
|
canvas.clipRect(0, 0, 60, 60);
|
||||||
canvas.clipRect(40, 40, 100, 100, Region.Op.XOR);
|
canvas.clipRect(40, 40, 100, 100, Region.Op.XOR);
|
||||||
drawScene(canvas);
|
drawScene(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(160, 310);
|
canvas.translate(160, 310);
|
||||||
canvas.clipRect(0, 0, 60, 60);
|
canvas.clipRect(0, 0, 60, 60);
|
||||||
|
|||||||
@@ -23,18 +23,17 @@ import android.content.Context;
|
|||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.*;
|
import android.graphics.drawable.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
public class ColorFilters extends GraphicsActivity {
|
public class ColorFilters extends GraphicsActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private Drawable mDrawable;
|
private Drawable mDrawable;
|
||||||
@@ -52,7 +51,7 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
int center = (r.top + r.bottom) >> 1;
|
int center = (r.top + r.bottom) >> 1;
|
||||||
int h = curr.getIntrinsicHeight();
|
int h = curr.getIntrinsicHeight();
|
||||||
int y = center - (h >> 1);
|
int y = center - (h >> 1);
|
||||||
|
|
||||||
curr.setBounds(x, y, x + curr.getIntrinsicWidth(), y + h);
|
curr.setBounds(x, y, x + curr.getIntrinsicWidth(), y + h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +60,7 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
Context context = activity;
|
Context context = activity;
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mDrawable = context.getResources().getDrawable(R.drawable.btn_default_normal);
|
mDrawable = context.getResources().getDrawable(R.drawable.btn_default_normal);
|
||||||
mDrawable.setBounds(0, 0, 150, 48);
|
mDrawable.setBounds(0, 0, 150, 48);
|
||||||
mDrawable.setDither(true);
|
mDrawable.setDither(true);
|
||||||
@@ -84,13 +83,13 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setTextSize(16);
|
mPaint.setTextSize(16);
|
||||||
mPaint.setTextAlign(Paint.Align.CENTER);
|
mPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
mPaint2 = new Paint(mPaint);
|
mPaint2 = new Paint(mPaint);
|
||||||
mPaint2.setAlpha(64);
|
mPaint2.setAlpha(64);
|
||||||
|
|
||||||
Paint.FontMetrics fm = mPaint.getFontMetrics();
|
Paint.FontMetrics fm = mPaint.getFontMetrics();
|
||||||
mPaintTextOffset = (fm.descent + fm.ascent) * 0.5f;
|
mPaintTextOffset = (fm.descent + fm.ascent) * 0.5f;
|
||||||
|
|
||||||
mColors = new int[] {
|
mColors = new int[] {
|
||||||
0,
|
0,
|
||||||
0xCC0000FF,
|
0xCC0000FF,
|
||||||
@@ -106,10 +105,10 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
PorterDuff.Mode.MULTIPLY,
|
PorterDuff.Mode.MULTIPLY,
|
||||||
};
|
};
|
||||||
mModeIndex = 0;
|
mModeIndex = 0;
|
||||||
|
|
||||||
updateTitle();
|
updateTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void swapPaintColors() {
|
private void swapPaintColors() {
|
||||||
if (mPaint.getColor() == 0xFF000000) {
|
if (mPaint.getColor() == 0xFF000000) {
|
||||||
mPaint.setColor(0xFFFFFFFF);
|
mPaint.setColor(0xFFFFFFFF);
|
||||||
@@ -120,11 +119,11 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
mPaint2.setAlpha(64);
|
mPaint2.setAlpha(64);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTitle() {
|
private void updateTitle() {
|
||||||
mActivity.setTitle(mModes[mModeIndex].toString());
|
mActivity.setTitle(mModes[mModeIndex].toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawSample(Canvas canvas, ColorFilter filter) {
|
private void drawSample(Canvas canvas, ColorFilter filter) {
|
||||||
Rect r = mDrawable.getBounds();
|
Rect r = mDrawable.getBounds();
|
||||||
float x = (r.left + r.right) * 0.5f;
|
float x = (r.left + r.right) * 0.5f;
|
||||||
@@ -134,15 +133,15 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.drawText("Label", x+1, y+1, mPaint2);
|
canvas.drawText("Label", x+1, y+1, mPaint2);
|
||||||
canvas.drawText("Label", x, y, mPaint);
|
canvas.drawText("Label", x, y, mPaint);
|
||||||
|
|
||||||
for (Drawable dr : mDrawables) {
|
for (Drawable dr : mDrawables) {
|
||||||
dr.setColorFilter(filter);
|
dr.setColorFilter(filter);
|
||||||
dr.draw(canvas);
|
dr.draw(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(0xFFCCCCCC);
|
canvas.drawColor(0xFFCCCCCC);
|
||||||
|
|
||||||
canvas.translate(8, 12);
|
canvas.translate(8, 12);
|
||||||
for (int color : mColors) {
|
for (int color : mColors) {
|
||||||
@@ -160,8 +159,6 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
float x = event.getX();
|
|
||||||
float y = event.getY();
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
break;
|
break;
|
||||||
@@ -181,4 +178,3 @@ public class ColorFilters extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,35 +18,31 @@ package com.example.android.apis.graphics;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class ColorMatrixSample extends GraphicsActivity {
|
public class ColorMatrixSample extends GraphicsActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private ColorMatrix mCM = new ColorMatrix();
|
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
private float mSaturation;
|
|
||||||
private float mAngle;
|
private float mAngle;
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mBitmap = BitmapFactory.decodeResource(context.getResources(),
|
mBitmap = BitmapFactory.decodeResource(context.getResources(),
|
||||||
R.drawable.balloons);
|
R.drawable.balloons);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setTranslate(ColorMatrix cm, float dr, float dg,
|
private static void setTranslate(ColorMatrix cm, float dr, float dg,
|
||||||
float db, float da) {
|
float db, float da) {
|
||||||
cm.set(new float[] {
|
cm.set(new float[] {
|
||||||
@@ -55,7 +51,7 @@ public class ColorMatrixSample extends GraphicsActivity {
|
|||||||
0, 0, 2, 0, db,
|
0, 0, 2, 0, db,
|
||||||
0, 0, 0, 1, da });
|
0, 0, 0, 1, da });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setContrast(ColorMatrix cm, float contrast) {
|
private static void setContrast(ColorMatrix cm, float contrast) {
|
||||||
float scale = contrast + 1.f;
|
float scale = contrast + 1.f;
|
||||||
float translate = (-.5f * scale + .5f) * 255.f;
|
float translate = (-.5f * scale + .5f) * 255.f;
|
||||||
@@ -65,7 +61,7 @@ public class ColorMatrixSample extends GraphicsActivity {
|
|||||||
0, 0, scale, 0, translate,
|
0, 0, scale, 0, translate,
|
||||||
0, 0, 0, 1, 0 });
|
0, 0, 0, 1, 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setContrastTranslateOnly(ColorMatrix cm, float contrast) {
|
private static void setContrastTranslateOnly(ColorMatrix cm, float contrast) {
|
||||||
float scale = contrast + 1.f;
|
float scale = contrast + 1.f;
|
||||||
float translate = (-.5f * scale + .5f) * 255.f;
|
float translate = (-.5f * scale + .5f) * 255.f;
|
||||||
@@ -75,7 +71,7 @@ public class ColorMatrixSample extends GraphicsActivity {
|
|||||||
0, 0, 1, 0, translate,
|
0, 0, 1, 0, translate,
|
||||||
0, 0, 0, 1, 0 });
|
0, 0, 0, 1, 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setContrastScaleOnly(ColorMatrix cm, float contrast) {
|
private static void setContrastScaleOnly(ColorMatrix cm, float contrast) {
|
||||||
float scale = contrast + 1.f;
|
float scale = contrast + 1.f;
|
||||||
float translate = (-.5f * scale + .5f) * 255.f;
|
float translate = (-.5f * scale + .5f) * 255.f;
|
||||||
@@ -85,40 +81,40 @@ public class ColorMatrixSample extends GraphicsActivity {
|
|||||||
0, 0, scale, 0, 0,
|
0, 0, scale, 0, 0,
|
||||||
0, 0, 0, 1, 0 });
|
0, 0, 0, 1, 0 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
Paint paint = mPaint;
|
Paint paint = mPaint;
|
||||||
float x = 20;
|
float x = 20;
|
||||||
float y = 20;
|
float y = 20;
|
||||||
|
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
paint.setColorFilter(null);
|
paint.setColorFilter(null);
|
||||||
canvas.drawBitmap(mBitmap, x, y, paint);
|
canvas.drawBitmap(mBitmap, x, y, paint);
|
||||||
|
|
||||||
ColorMatrix cm = new ColorMatrix();
|
ColorMatrix cm = new ColorMatrix();
|
||||||
|
|
||||||
mAngle += 2;
|
mAngle += 2;
|
||||||
if (mAngle > 180) {
|
if (mAngle > 180) {
|
||||||
mAngle = 0;
|
mAngle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//convert our animated angle [-180...180] to a contrast value of [-1..1]
|
//convert our animated angle [-180...180] to a contrast value of [-1..1]
|
||||||
float contrast = mAngle / 180.f;
|
float contrast = mAngle / 180.f;
|
||||||
|
|
||||||
setContrast(cm, contrast);
|
setContrast(cm, contrast);
|
||||||
paint.setColorFilter(new ColorMatrixColorFilter(cm));
|
paint.setColorFilter(new ColorMatrixColorFilter(cm));
|
||||||
canvas.drawBitmap(mBitmap, x + mBitmap.getWidth() + 10, y, paint);
|
canvas.drawBitmap(mBitmap, x + mBitmap.getWidth() + 10, y, paint);
|
||||||
|
|
||||||
setContrastScaleOnly(cm, contrast);
|
setContrastScaleOnly(cm, contrast);
|
||||||
paint.setColorFilter(new ColorMatrixColorFilter(cm));
|
paint.setColorFilter(new ColorMatrixColorFilter(cm));
|
||||||
canvas.drawBitmap(mBitmap, x, y + mBitmap.getHeight() + 10, paint);
|
canvas.drawBitmap(mBitmap, x, y + mBitmap.getHeight() + 10, paint);
|
||||||
|
|
||||||
setContrastTranslateOnly(cm, contrast);
|
setContrastTranslateOnly(cm, contrast);
|
||||||
paint.setColorFilter(new ColorMatrixColorFilter(cm));
|
paint.setColorFilter(new ColorMatrixColorFilter(cm));
|
||||||
canvas.drawBitmap(mBitmap, x, y + 2*(mBitmap.getHeight() + 10),
|
canvas.drawBitmap(mBitmap, x, y + 2*(mBitmap.getHeight() + 10),
|
||||||
paint);
|
paint);
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
private Paint mCenterPaint;
|
private Paint mCenterPaint;
|
||||||
private final int[] mColors;
|
private final int[] mColors;
|
||||||
private OnColorChangedListener mListener;
|
private OnColorChangedListener mListener;
|
||||||
|
|
||||||
ColorPickerView(Context c, OnColorChangedListener l, int color) {
|
ColorPickerView(Context c, OnColorChangedListener l, int color) {
|
||||||
super(c);
|
super(c);
|
||||||
mListener = l;
|
mListener = l;
|
||||||
@@ -46,33 +46,33 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
0xFFFFFF00, 0xFFFF0000
|
0xFFFFFF00, 0xFFFF0000
|
||||||
};
|
};
|
||||||
Shader s = new SweepGradient(0, 0, mColors, null);
|
Shader s = new SweepGradient(0, 0, mColors, null);
|
||||||
|
|
||||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
mPaint.setShader(s);
|
mPaint.setShader(s);
|
||||||
mPaint.setStyle(Paint.Style.STROKE);
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
mPaint.setStrokeWidth(32);
|
mPaint.setStrokeWidth(32);
|
||||||
|
|
||||||
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
mCenterPaint.setColor(color);
|
mCenterPaint.setColor(color);
|
||||||
mCenterPaint.setStrokeWidth(5);
|
mCenterPaint.setStrokeWidth(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mTrackingCenter;
|
private boolean mTrackingCenter;
|
||||||
private boolean mHighlightCenter;
|
private boolean mHighlightCenter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
float r = CENTER_X - mPaint.getStrokeWidth()*0.5f;
|
float r = CENTER_X - mPaint.getStrokeWidth()*0.5f;
|
||||||
|
|
||||||
canvas.translate(CENTER_X, CENTER_X);
|
canvas.translate(CENTER_X, CENTER_X);
|
||||||
|
|
||||||
canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
|
canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
|
||||||
canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint);
|
canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint);
|
||||||
|
|
||||||
if (mTrackingCenter) {
|
if (mTrackingCenter) {
|
||||||
int c = mCenterPaint.getColor();
|
int c = mCenterPaint.getColor();
|
||||||
mCenterPaint.setStyle(Paint.Style.STROKE);
|
mCenterPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
|
||||||
if (mHighlightCenter) {
|
if (mHighlightCenter) {
|
||||||
mCenterPaint.setAlpha(0xFF);
|
mCenterPaint.setAlpha(0xFF);
|
||||||
} else {
|
} else {
|
||||||
@@ -81,17 +81,17 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
canvas.drawCircle(0, 0,
|
canvas.drawCircle(0, 0,
|
||||||
CENTER_RADIUS + mCenterPaint.getStrokeWidth(),
|
CENTER_RADIUS + mCenterPaint.getStrokeWidth(),
|
||||||
mCenterPaint);
|
mCenterPaint);
|
||||||
|
|
||||||
mCenterPaint.setStyle(Paint.Style.FILL);
|
mCenterPaint.setStyle(Paint.Style.FILL);
|
||||||
mCenterPaint.setColor(c);
|
mCenterPaint.setColor(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
setMeasuredDimension(CENTER_X*2, CENTER_Y*2);
|
setMeasuredDimension(CENTER_X*2, CENTER_Y*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int CENTER_X = 100;
|
private static final int CENTER_X = 100;
|
||||||
private static final int CENTER_Y = 100;
|
private static final int CENTER_Y = 100;
|
||||||
private static final int CENTER_RADIUS = 32;
|
private static final int CENTER_RADIUS = 32;
|
||||||
@@ -108,11 +108,11 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ave(int s, int d, float p) {
|
private int ave(int s, int d, float p) {
|
||||||
return s + java.lang.Math.round(p * (d - s));
|
return s + java.lang.Math.round(p * (d - s));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int interpColor(int colors[], float unit) {
|
private int interpColor(int colors[], float unit) {
|
||||||
if (unit <= 0) {
|
if (unit <= 0) {
|
||||||
return colors[0];
|
return colors[0];
|
||||||
@@ -120,7 +120,7 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
if (unit >= 1) {
|
if (unit >= 1) {
|
||||||
return colors[colors.length - 1];
|
return colors[colors.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
float p = unit * (colors.length - 1);
|
float p = unit * (colors.length - 1);
|
||||||
int i = (int)p;
|
int i = (int)p;
|
||||||
p -= i;
|
p -= i;
|
||||||
@@ -132,16 +132,16 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
int r = ave(Color.red(c0), Color.red(c1), p);
|
int r = ave(Color.red(c0), Color.red(c1), p);
|
||||||
int g = ave(Color.green(c0), Color.green(c1), p);
|
int g = ave(Color.green(c0), Color.green(c1), p);
|
||||||
int b = ave(Color.blue(c0), Color.blue(c1), p);
|
int b = ave(Color.blue(c0), Color.blue(c1), p);
|
||||||
|
|
||||||
return Color.argb(a, r, g, b);
|
return Color.argb(a, r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int rotateColor(int color, float rad) {
|
private int rotateColor(int color, float rad) {
|
||||||
float deg = rad * 180 / 3.1415927f;
|
float deg = rad * 180 / 3.1415927f;
|
||||||
int r = Color.red(color);
|
int r = Color.red(color);
|
||||||
int g = Color.green(color);
|
int g = Color.green(color);
|
||||||
int b = Color.blue(color);
|
int b = Color.blue(color);
|
||||||
|
|
||||||
ColorMatrix cm = new ColorMatrix();
|
ColorMatrix cm = new ColorMatrix();
|
||||||
ColorMatrix tmp = new ColorMatrix();
|
ColorMatrix tmp = new ColorMatrix();
|
||||||
|
|
||||||
@@ -150,17 +150,17 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
cm.postConcat(tmp);
|
cm.postConcat(tmp);
|
||||||
tmp.setYUV2RGB();
|
tmp.setYUV2RGB();
|
||||||
cm.postConcat(tmp);
|
cm.postConcat(tmp);
|
||||||
|
|
||||||
final float[] a = cm.getArray();
|
final float[] a = cm.getArray();
|
||||||
|
|
||||||
int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b);
|
int ir = floatToByte(a[0] * r + a[1] * g + a[2] * b);
|
||||||
int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b);
|
int ig = floatToByte(a[5] * r + a[6] * g + a[7] * b);
|
||||||
int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b);
|
int ib = floatToByte(a[10] * r + a[11] * g + a[12] * b);
|
||||||
|
|
||||||
return Color.argb(Color.alpha(color), pinToByte(ir),
|
return Color.argb(Color.alpha(color), pinToByte(ir),
|
||||||
pinToByte(ig), pinToByte(ib));
|
pinToByte(ig), pinToByte(ib));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final float PI = 3.1415926f;
|
private static final float PI = 3.1415926f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,7 +168,7 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
float x = event.getX() - CENTER_X;
|
float x = event.getX() - CENTER_X;
|
||||||
float y = event.getY() - CENTER_Y;
|
float y = event.getY() - CENTER_Y;
|
||||||
boolean inCenter = java.lang.Math.sqrt(x*x + y*y) <= CENTER_RADIUS;
|
boolean inCenter = java.lang.Math.sqrt(x*x + y*y) <= CENTER_RADIUS;
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
mTrackingCenter = inCenter;
|
mTrackingCenter = inCenter;
|
||||||
@@ -212,7 +212,7 @@ public class ColorPickerDialog extends Dialog {
|
|||||||
OnColorChangedListener listener,
|
OnColorChangedListener listener,
|
||||||
int initialColor) {
|
int initialColor) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
mInitialColor = initialColor;
|
mInitialColor = initialColor;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,10 +35,10 @@ public class Compass extends GraphicsActivity {
|
|||||||
private Sensor mSensor;
|
private Sensor mSensor;
|
||||||
private SampleView mView;
|
private SampleView mView;
|
||||||
private float[] mValues;
|
private float[] mValues;
|
||||||
|
|
||||||
private final SensorEventListener mListener = new SensorEventListener() {
|
private final SensorEventListener mListener = new SensorEventListener() {
|
||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
if (Config.LOGD) Log.d(TAG,
|
if (Config.DEBUG) Log.d(TAG,
|
||||||
"sensorChanged (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ")");
|
"sensorChanged (" + event.values[0] + ", " + event.values[1] + ", " + event.values[2] + ")");
|
||||||
mValues = event.values;
|
mValues = event.values;
|
||||||
if (mView != null) {
|
if (mView != null) {
|
||||||
@@ -62,17 +62,17 @@ public class Compass extends GraphicsActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
if (Config.LOGD) Log.d(TAG, "onResume");
|
if (Config.DEBUG) Log.d(TAG, "onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
mSensorManager.registerListener(mListener, mSensor,
|
mSensorManager.registerListener(mListener, mSensor,
|
||||||
SensorManager.SENSOR_DELAY_GAME);
|
SensorManager.SENSOR_DELAY_GAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop()
|
protected void onStop()
|
||||||
{
|
{
|
||||||
if (Config.LOGD) Log.d(TAG, "onStop");
|
if (Config.DEBUG) Log.d(TAG, "onStop");
|
||||||
mSensorManager.unregisterListener(mListener);
|
mSensorManager.unregisterListener(mListener);
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,6 @@ public class Compass extends GraphicsActivity {
|
|||||||
private Paint mPaint = new Paint();
|
private Paint mPaint = new Paint();
|
||||||
private Path mPath = new Path();
|
private Path mPath = new Path();
|
||||||
private boolean mAnimate;
|
private boolean mAnimate;
|
||||||
private long mNextTime;
|
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -93,12 +92,12 @@ public class Compass extends GraphicsActivity {
|
|||||||
mPath.lineTo(20, 60);
|
mPath.lineTo(20, 60);
|
||||||
mPath.close();
|
mPath.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
Paint paint = mPaint;
|
Paint paint = mPaint;
|
||||||
|
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setColor(Color.BLACK);
|
paint.setColor(Color.BLACK);
|
||||||
paint.setStyle(Paint.Style.FILL);
|
paint.setStyle(Paint.Style.FILL);
|
||||||
@@ -109,23 +108,24 @@ public class Compass extends GraphicsActivity {
|
|||||||
int cy = h / 2;
|
int cy = h / 2;
|
||||||
|
|
||||||
canvas.translate(cx, cy);
|
canvas.translate(cx, cy);
|
||||||
if (mValues != null) {
|
if (mValues != null) {
|
||||||
canvas.rotate(-mValues[0]);
|
canvas.rotate(-mValues[0]);
|
||||||
}
|
}
|
||||||
canvas.drawPath(mPath, mPaint);
|
canvas.drawPath(mPath, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
mAnimate = true;
|
mAnimate = true;
|
||||||
|
if (Config.DEBUG) Log.d(TAG, "onAttachedToWindow. mAnimate=" + mAnimate);
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
mAnimate = false;
|
mAnimate = false;
|
||||||
|
if (Config.DEBUG) Log.d(TAG, "onDetachedFromWindow. mAnimate=" + mAnimate);
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,9 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -34,11 +30,11 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int WIDTH = 50;
|
private static final int WIDTH = 50;
|
||||||
private static final int HEIGHT = 50;
|
private static final int HEIGHT = 50;
|
||||||
private static final int STRIDE = 64; // must be >= WIDTH
|
private static final int STRIDE = 64; // must be >= WIDTH
|
||||||
|
|
||||||
private static int[] createColors() {
|
private static int[] createColors() {
|
||||||
int[] colors = new int[STRIDE * HEIGHT];
|
int[] colors = new int[STRIDE * HEIGHT];
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
@@ -52,18 +48,18 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Bitmap[] mBitmaps;
|
private Bitmap[] mBitmaps;
|
||||||
private Bitmap[] mJPEG;
|
private Bitmap[] mJPEG;
|
||||||
private Bitmap[] mPNG;
|
private Bitmap[] mPNG;
|
||||||
private int[] mColors;
|
private int[] mColors;
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
|
|
||||||
private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
|
private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
|
||||||
int quality) {
|
int quality) {
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
src.compress(format, quality, os);
|
src.compress(format, quality, os);
|
||||||
|
|
||||||
byte[] array = os.toByteArray();
|
byte[] array = os.toByteArray();
|
||||||
return BitmapFactory.decodeByteArray(array, 0, array.length);
|
return BitmapFactory.decodeByteArray(array, 0, array.length);
|
||||||
@@ -72,7 +68,7 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mColors = createColors();
|
mColors = createColors();
|
||||||
int[] colors = mColors;
|
int[] colors = mColors;
|
||||||
|
|
||||||
@@ -84,7 +80,7 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
Bitmap.Config.RGB_565);
|
Bitmap.Config.RGB_565);
|
||||||
mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
|
mBitmaps[2] = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
|
||||||
Bitmap.Config.ARGB_4444);
|
Bitmap.Config.ARGB_4444);
|
||||||
|
|
||||||
// these three will have their colors set later
|
// these three will have their colors set later
|
||||||
mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT,
|
mBitmaps[3] = Bitmap.createBitmap(WIDTH, HEIGHT,
|
||||||
Bitmap.Config.ARGB_8888);
|
Bitmap.Config.ARGB_8888);
|
||||||
@@ -95,10 +91,10 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
for (int i = 3; i <= 5; i++) {
|
for (int i = 3; i <= 5; i++) {
|
||||||
mBitmaps[i].setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT);
|
mBitmaps[i].setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setDither(true);
|
mPaint.setDither(true);
|
||||||
|
|
||||||
// now encode/decode using JPEG and PNG
|
// now encode/decode using JPEG and PNG
|
||||||
mJPEG = new Bitmap[mBitmaps.length];
|
mJPEG = new Bitmap[mBitmaps.length];
|
||||||
mPNG = new Bitmap[mBitmaps.length];
|
mPNG = new Bitmap[mBitmaps.length];
|
||||||
@@ -107,7 +103,7 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
mPNG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.PNG, 0);
|
mPNG[i] = codec(mBitmaps[i], Bitmap.CompressFormat.PNG, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
@@ -117,7 +113,7 @@ public class CreateBitmap extends GraphicsActivity {
|
|||||||
canvas.drawBitmap(mPNG[i], 160, 0, null);
|
canvas.drawBitmap(mPNG[i], 160, 0, null);
|
||||||
canvas.translate(0, mBitmaps[i].getHeight());
|
canvas.translate(0, mBitmaps[i].getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw the color array directly, w/o craeting a bitmap object
|
// draw the color array directly, w/o craeting a bitmap object
|
||||||
canvas.drawBitmap(mColors, 0, STRIDE, 0, 0, WIDTH, HEIGHT,
|
canvas.drawBitmap(mColors, 0, STRIDE, 0, 0, WIDTH, HEIGHT,
|
||||||
true, null);
|
true, null);
|
||||||
|
|||||||
@@ -88,10 +88,10 @@ class Cube
|
|||||||
|
|
||||||
public void draw(GL10 gl)
|
public void draw(GL10 gl)
|
||||||
{
|
{
|
||||||
gl.glFrontFace(gl.GL_CW);
|
gl.glFrontFace(GL10.GL_CW);
|
||||||
gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer);
|
gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
|
||||||
gl.glColorPointer(4, gl.GL_FIXED, 0, mColorBuffer);
|
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
|
||||||
gl.glDrawElements(gl.GL_TRIANGLES, 36, gl.GL_UNSIGNED_BYTE, mIndexBuffer);
|
gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntBuffer mVertexBuffer;
|
private IntBuffer mVertexBuffer;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGL10;
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class DensityActivity extends Activity {
|
|||||||
|
|
||||||
final LayoutInflater li = (LayoutInflater)getSystemService(
|
final LayoutInflater li = (LayoutInflater)getSystemService(
|
||||||
LAYOUT_INFLATER_SERVICE);
|
LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
this.setTitle(R.string.density_title);
|
this.setTitle(R.string.density_title);
|
||||||
LinearLayout root = new LinearLayout(this);
|
LinearLayout root = new LinearLayout(this);
|
||||||
root.setOrientation(LinearLayout.VERTICAL);
|
root.setOrientation(LinearLayout.VERTICAL);
|
||||||
@@ -76,11 +76,11 @@ public class DensityActivity extends Activity {
|
|||||||
layout = (LinearLayout)li.inflate(R.layout.density_image_views, null);
|
layout = (LinearLayout)li.inflate(R.layout.density_image_views, null);
|
||||||
addLabelToRoot(root, "Inflated layout");
|
addLabelToRoot(root, "Inflated layout");
|
||||||
addChildToRoot(root, layout);
|
addChildToRoot(root, layout);
|
||||||
|
|
||||||
layout = (LinearLayout)li.inflate(R.layout.density_styled_image_views, null);
|
layout = (LinearLayout)li.inflate(R.layout.density_styled_image_views, null);
|
||||||
addLabelToRoot(root, "Inflated styled layout");
|
addLabelToRoot(root, "Inflated styled layout");
|
||||||
addChildToRoot(root, layout);
|
addChildToRoot(root, layout);
|
||||||
|
|
||||||
layout = new LinearLayout(this);
|
layout = new LinearLayout(this);
|
||||||
addCanvasBitmap(layout, R.drawable.logo120dpi, true);
|
addCanvasBitmap(layout, R.drawable.logo120dpi, true);
|
||||||
addCanvasBitmap(layout, R.drawable.logo160dpi, true);
|
addCanvasBitmap(layout, R.drawable.logo160dpi, true);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,7 +28,7 @@ public class DrawPoints extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint = new Paint();
|
private Paint mPaint = new Paint();
|
||||||
private float[] mPts;
|
private float[] mPts;
|
||||||
@@ -38,11 +37,11 @@ public class DrawPoints extends GraphicsActivity {
|
|||||||
private static final int SEGS = 32;
|
private static final int SEGS = 32;
|
||||||
private static final int X = 0;
|
private static final int X = 0;
|
||||||
private static final int Y = 1;
|
private static final int Y = 1;
|
||||||
|
|
||||||
private void buildPoints() {
|
private void buildPoints() {
|
||||||
final int ptCount = (SEGS + 1) * 2;
|
final int ptCount = (SEGS + 1) * 2;
|
||||||
mPts = new float[ptCount * 2];
|
mPts = new float[ptCount * 2];
|
||||||
|
|
||||||
float value = 0;
|
float value = 0;
|
||||||
final float delta = SIZE / SEGS;
|
final float delta = SIZE / SEGS;
|
||||||
for (int i = 0; i <= SEGS; i++) {
|
for (int i = 0; i <= SEGS; i++) {
|
||||||
@@ -53,16 +52,16 @@ public class DrawPoints extends GraphicsActivity {
|
|||||||
value += delta;
|
value += delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
buildPoints();
|
buildPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
Paint paint = mPaint;
|
Paint paint = mPaint;
|
||||||
|
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
|
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
@@ -70,7 +69,7 @@ public class DrawPoints extends GraphicsActivity {
|
|||||||
paint.setColor(Color.RED);
|
paint.setColor(Color.RED);
|
||||||
paint.setStrokeWidth(0);
|
paint.setStrokeWidth(0);
|
||||||
canvas.drawLines(mPts, paint);
|
canvas.drawLines(mPts, paint);
|
||||||
|
|
||||||
paint.setColor(Color.BLUE);
|
paint.setColor(Color.BLUE);
|
||||||
paint.setStrokeWidth(3);
|
paint.setStrokeWidth(3);
|
||||||
canvas.drawPoints(mPts, paint);
|
canvas.drawPoints(mPts, paint);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -26,7 +25,7 @@ import android.view.MotionEvent;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class FingerPaint extends GraphicsActivity
|
public class FingerPaint extends GraphicsActivity
|
||||||
implements ColorPickerDialog.OnColorChangedListener {
|
implements ColorPickerDialog.OnColorChangedListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -41,34 +40,34 @@ public class FingerPaint extends GraphicsActivity
|
|||||||
mPaint.setStrokeJoin(Paint.Join.ROUND);
|
mPaint.setStrokeJoin(Paint.Join.ROUND);
|
||||||
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
||||||
mPaint.setStrokeWidth(12);
|
mPaint.setStrokeWidth(12);
|
||||||
|
|
||||||
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
|
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
|
||||||
0.4f, 6, 3.5f);
|
0.4f, 6, 3.5f);
|
||||||
|
|
||||||
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
|
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private MaskFilter mEmboss;
|
private MaskFilter mEmboss;
|
||||||
private MaskFilter mBlur;
|
private MaskFilter mBlur;
|
||||||
|
|
||||||
public void colorChanged(int color) {
|
public void colorChanged(int color) {
|
||||||
mPaint.setColor(color);
|
mPaint.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MyView extends View {
|
public class MyView extends View {
|
||||||
|
|
||||||
private static final float MINP = 0.25f;
|
private static final float MINP = 0.25f;
|
||||||
private static final float MAXP = 0.75f;
|
private static final float MAXP = 0.75f;
|
||||||
|
|
||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
private Canvas mCanvas;
|
private Canvas mCanvas;
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
private Paint mBitmapPaint;
|
private Paint mBitmapPaint;
|
||||||
|
|
||||||
public MyView(Context c) {
|
public MyView(Context c) {
|
||||||
super(c);
|
super(c);
|
||||||
|
|
||||||
mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
|
mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
|
||||||
mCanvas = new Canvas(mBitmap);
|
mCanvas = new Canvas(mBitmap);
|
||||||
mPath = new Path();
|
mPath = new Path();
|
||||||
@@ -79,19 +78,19 @@ public class FingerPaint extends GraphicsActivity
|
|||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(0xFFAAAAAA);
|
canvas.drawColor(0xFFAAAAAA);
|
||||||
|
|
||||||
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
|
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
|
||||||
|
|
||||||
canvas.drawPath(mPath, mPaint);
|
canvas.drawPath(mPath, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float mX, mY;
|
private float mX, mY;
|
||||||
private static final float TOUCH_TOLERANCE = 4;
|
private static final float TOUCH_TOLERANCE = 4;
|
||||||
|
|
||||||
private void touch_start(float x, float y) {
|
private void touch_start(float x, float y) {
|
||||||
mPath.reset();
|
mPath.reset();
|
||||||
mPath.moveTo(x, y);
|
mPath.moveTo(x, y);
|
||||||
@@ -114,12 +113,12 @@ public class FingerPaint extends GraphicsActivity
|
|||||||
// kill this so we don't double draw
|
// kill this so we don't double draw
|
||||||
mPath.reset();
|
mPath.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
float x = event.getX();
|
float x = event.getX();
|
||||||
float y = event.getY();
|
float y = event.getY();
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
touch_start(x, y);
|
touch_start(x, y);
|
||||||
@@ -137,7 +136,7 @@ public class FingerPaint extends GraphicsActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int COLOR_MENU_ID = Menu.FIRST;
|
private static final int COLOR_MENU_ID = Menu.FIRST;
|
||||||
private static final int EMBOSS_MENU_ID = Menu.FIRST + 1;
|
private static final int EMBOSS_MENU_ID = Menu.FIRST + 1;
|
||||||
private static final int BLUR_MENU_ID = Menu.FIRST + 2;
|
private static final int BLUR_MENU_ID = Menu.FIRST + 2;
|
||||||
@@ -147,7 +146,7 @@ public class FingerPaint extends GraphicsActivity
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3', 'c');
|
menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3', 'c');
|
||||||
menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4', 's');
|
menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4', 's');
|
||||||
menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5', 'z');
|
menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5', 'z');
|
||||||
@@ -164,13 +163,13 @@ public class FingerPaint extends GraphicsActivity
|
|||||||
*****/
|
*****/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
super.onPrepareOptionsMenu(menu);
|
super.onPrepareOptionsMenu(menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
mPaint.setXfermode(null);
|
mPaint.setXfermode(null);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package com.example.android.apis.graphics;
|
|||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class GradientDrawable1 extends GraphicsActivity {
|
public class GradientDrawable1 extends GraphicsActivity {
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ import android.app.Activity;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
|
||||||
|
|
||||||
class GraphicsActivity extends Activity {
|
class GraphicsActivity extends Activity {
|
||||||
|
// set to true to test Picture
|
||||||
|
private static final boolean TEST_PICTURE = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -30,13 +32,12 @@ class GraphicsActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentView(View view) {
|
public void setContentView(View view) {
|
||||||
if (false) { // set to true to test Picture
|
if (TEST_PICTURE) {
|
||||||
ViewGroup vg = new PictureLayout(this);
|
ViewGroup vg = new PictureLayout(this);
|
||||||
vg.addView(view);
|
vg.addView(view);
|
||||||
view = vg;
|
view = vg;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.setContentView(view);
|
super.setContentView(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,7 +28,7 @@ public class Layers extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private static final int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG |
|
private static final int LAYER_FLAGS = Canvas.MATRIX_SAVE_FLAG |
|
||||||
Canvas.CLIP_SAVE_FLAG |
|
Canvas.CLIP_SAVE_FLAG |
|
||||||
@@ -42,23 +41,23 @@ public class Layers extends GraphicsActivity {
|
|||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
|
|
||||||
canvas.saveLayerAlpha(0, 0, 200, 200, 0x88, LAYER_FLAGS);
|
canvas.saveLayerAlpha(0, 0, 200, 200, 0x88, LAYER_FLAGS);
|
||||||
|
|
||||||
mPaint.setColor(Color.RED);
|
mPaint.setColor(Color.RED);
|
||||||
canvas.drawCircle(75, 75, 75, mPaint);
|
canvas.drawCircle(75, 75, 75, mPaint);
|
||||||
mPaint.setColor(Color.BLUE);
|
mPaint.setColor(Color.BLUE);
|
||||||
canvas.drawCircle(125, 125, 75, mPaint);
|
canvas.drawCircle(125, 125, 75, mPaint);
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,9 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
public class MeasureText extends GraphicsActivity {
|
public class MeasureText extends GraphicsActivity {
|
||||||
@@ -32,11 +28,11 @@ public class MeasureText extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int WIDTH = 50;
|
private static final int WIDTH = 50;
|
||||||
private static final int HEIGHT = 50;
|
private static final int HEIGHT = 50;
|
||||||
private static final int STRIDE = 64; // must be >= WIDTH
|
private static final int STRIDE = 64; // must be >= WIDTH
|
||||||
|
|
||||||
private static int[] createColors() {
|
private static int[] createColors() {
|
||||||
int[] colors = new int[STRIDE * HEIGHT];
|
int[] colors = new int[STRIDE * HEIGHT];
|
||||||
for (int y = 0; y < HEIGHT; y++) {
|
for (int y = 0; y < HEIGHT; y++) {
|
||||||
@@ -50,16 +46,16 @@ public class MeasureText extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private float mOriginX = 10;
|
private float mOriginX = 10;
|
||||||
private float mOriginY = 80;
|
private float mOriginY = 80;
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setStrokeWidth(5);
|
mPaint.setStrokeWidth(5);
|
||||||
@@ -68,22 +64,22 @@ public class MeasureText extends GraphicsActivity {
|
|||||||
mPaint.setTypeface(Typeface.create(Typeface.SERIF,
|
mPaint.setTypeface(Typeface.create(Typeface.SERIF,
|
||||||
Typeface.ITALIC));
|
Typeface.ITALIC));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showText(Canvas canvas, String text, Paint.Align align) {
|
private void showText(Canvas canvas, String text, Paint.Align align) {
|
||||||
// mPaint.setTextAlign(align);
|
// mPaint.setTextAlign(align);
|
||||||
|
|
||||||
Rect bounds = new Rect();
|
Rect bounds = new Rect();
|
||||||
float[] widths = new float[text.length()];
|
float[] widths = new float[text.length()];
|
||||||
|
|
||||||
int count = mPaint.getTextWidths(text, 0, text.length(), widths);
|
int count = mPaint.getTextWidths(text, 0, text.length(), widths);
|
||||||
float w = mPaint.measureText(text, 0, text.length());
|
float w = mPaint.measureText(text, 0, text.length());
|
||||||
mPaint.getTextBounds(text, 0, text.length(), bounds);
|
mPaint.getTextBounds(text, 0, text.length(), bounds);
|
||||||
|
|
||||||
mPaint.setColor(0xFF88FF88);
|
mPaint.setColor(0xFF88FF88);
|
||||||
canvas.drawRect(bounds, mPaint);
|
canvas.drawRect(bounds, mPaint);
|
||||||
mPaint.setColor(Color.BLACK);
|
mPaint.setColor(Color.BLACK);
|
||||||
canvas.drawText(text, 0, 0, mPaint);
|
canvas.drawText(text, 0, 0, mPaint);
|
||||||
|
|
||||||
float[] pts = new float[2 + count*2];
|
float[] pts = new float[2 + count*2];
|
||||||
float x = 0;
|
float x = 0;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
@@ -100,12 +96,12 @@ public class MeasureText extends GraphicsActivity {
|
|||||||
mPaint.setStrokeWidth(5);
|
mPaint.setStrokeWidth(5);
|
||||||
canvas.drawPoints(pts, 0, (count + 1) << 1, mPaint);
|
canvas.drawPoints(pts, 0, (count + 1) << 1, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
canvas.translate(mOriginX, mOriginY);
|
canvas.translate(mOriginX, mOriginY);
|
||||||
|
|
||||||
showText(canvas, "Measure", Paint.Align.LEFT);
|
showText(canvas, "Measure", Paint.Align.LEFT);
|
||||||
canvas.translate(0, 80);
|
canvas.translate(0, 80);
|
||||||
showText(canvas, "wiggy!", Paint.Align.CENTER);
|
showText(canvas, "wiggy!", Paint.Align.CENTER);
|
||||||
@@ -114,4 +110,3 @@ public class MeasureText extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -30,7 +29,7 @@ public class PathEffects extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
@@ -41,7 +40,7 @@ public class PathEffects extends GraphicsActivity {
|
|||||||
private static PathEffect makeDash(float phase) {
|
private static PathEffect makeDash(float phase) {
|
||||||
return new DashPathEffect(new float[] { 15, 5, 8, 5 }, phase);
|
return new DashPathEffect(new float[] { 15, 5, 8, 5 }, phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void makeEffects(PathEffect[] e, float phase) {
|
private static void makeEffects(PathEffect[] e, float phase) {
|
||||||
e[0] = null; // no effect
|
e[0] = null; // no effect
|
||||||
e[1] = new CornerPathEffect(10);
|
e[1] = new CornerPathEffect(10);
|
||||||
@@ -51,7 +50,7 @@ public class PathEffects extends GraphicsActivity {
|
|||||||
e[4] = new ComposePathEffect(e[2], e[1]);
|
e[4] = new ComposePathEffect(e[2], e[1]);
|
||||||
e[5] = new ComposePathEffect(e[3], e[1]);
|
e[5] = new ComposePathEffect(e[3], e[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
@@ -60,23 +59,23 @@ public class PathEffects extends GraphicsActivity {
|
|||||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
mPaint.setStyle(Paint.Style.STROKE);
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
mPaint.setStrokeWidth(6);
|
mPaint.setStrokeWidth(6);
|
||||||
|
|
||||||
mPath = makeFollowPath();
|
mPath = makeFollowPath();
|
||||||
|
|
||||||
mEffects = new PathEffect[6];
|
mEffects = new PathEffect[6];
|
||||||
|
|
||||||
mColors = new int[] { Color.BLACK, Color.RED, Color.BLUE,
|
mColors = new int[] { Color.BLACK, Color.RED, Color.BLUE,
|
||||||
Color.GREEN, Color.MAGENTA, Color.BLACK
|
Color.GREEN, Color.MAGENTA, Color.BLACK
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
RectF bounds = new RectF();
|
RectF bounds = new RectF();
|
||||||
mPath.computeBounds(bounds, false);
|
mPath.computeBounds(bounds, false);
|
||||||
canvas.translate(10 - bounds.left, 10 - bounds.top);
|
canvas.translate(10 - bounds.left, 10 - bounds.top);
|
||||||
|
|
||||||
makeEffects(mEffects, mPhase);
|
makeEffects(mEffects, mPhase);
|
||||||
mPhase += 1;
|
mPhase += 1;
|
||||||
invalidate();
|
invalidate();
|
||||||
@@ -88,7 +87,7 @@ public class PathEffects extends GraphicsActivity {
|
|||||||
canvas.translate(0, 28);
|
canvas.translate(0, 28);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
|
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||||
@@ -106,7 +105,7 @@ public class PathEffects extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Path makePathDash() {
|
private static Path makePathDash() {
|
||||||
Path p = new Path();
|
Path p = new Path();
|
||||||
p.moveTo(4, 0);
|
p.moveTo(4, 0);
|
||||||
|
|||||||
@@ -20,11 +20,9 @@ package com.example.android.apis.graphics;
|
|||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
//import com.example.android.apis.R;
|
//import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class PathFillTypes extends GraphicsActivity {
|
public class PathFillTypes extends GraphicsActivity {
|
||||||
@@ -34,7 +32,7 @@ public class PathFillTypes extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
@@ -48,7 +46,7 @@ public class PathFillTypes extends GraphicsActivity {
|
|||||||
mPath.addCircle(40, 40, 45, Path.Direction.CCW);
|
mPath.addCircle(40, 40, 45, Path.Direction.CCW);
|
||||||
mPath.addCircle(80, 80, 45, Path.Direction.CCW);
|
mPath.addCircle(80, 80, 45, Path.Direction.CCW);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPath(Canvas canvas, int x, int y, Path.FillType ft,
|
private void showPath(Canvas canvas, int x, int y, Path.FillType ft,
|
||||||
Paint paint) {
|
Paint paint) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
@@ -59,14 +57,14 @@ public class PathFillTypes extends GraphicsActivity {
|
|||||||
canvas.drawPath(mPath, paint);
|
canvas.drawPath(mPath, paint);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
Paint paint = mPaint;
|
Paint paint = mPaint;
|
||||||
|
|
||||||
canvas.drawColor(0xFFCCCCCC);
|
canvas.drawColor(0xFFCCCCCC);
|
||||||
|
|
||||||
canvas.translate(20, 20);
|
canvas.translate(20, 20);
|
||||||
|
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
|
|
||||||
showPath(canvas, 0, 0, Path.FillType.WINDING, paint);
|
showPath(canvas, 0, 0, Path.FillType.WINDING, paint);
|
||||||
|
|||||||
@@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
@@ -31,7 +29,7 @@ public class Patterns extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap makeBitmap1() {
|
private static Bitmap makeBitmap1() {
|
||||||
Bitmap bm = Bitmap.createBitmap(40, 40, Bitmap.Config.RGB_565);
|
Bitmap bm = Bitmap.createBitmap(40, 40, Bitmap.Config.RGB_565);
|
||||||
Canvas c = new Canvas(bm);
|
Canvas c = new Canvas(bm);
|
||||||
@@ -41,7 +39,7 @@ public class Patterns extends GraphicsActivity {
|
|||||||
c.drawRect(5, 5, 35, 35, p);
|
c.drawRect(5, 5, 35, 35, p);
|
||||||
return bm;
|
return bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap makeBitmap2() {
|
private static Bitmap makeBitmap2() {
|
||||||
Bitmap bm = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888);
|
Bitmap bm = Bitmap.createBitmap(64, 64, Bitmap.Config.ARGB_8888);
|
||||||
Canvas c = new Canvas(bm);
|
Canvas c = new Canvas(bm);
|
||||||
@@ -51,13 +49,13 @@ public class Patterns extends GraphicsActivity {
|
|||||||
c.drawCircle(32, 32, 27, p);
|
c.drawCircle(32, 32, 27, p);
|
||||||
return bm;
|
return bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private final Shader mShader1;
|
private final Shader mShader1;
|
||||||
private final Shader mShader2;
|
private final Shader mShader2;
|
||||||
private final Paint mPaint;
|
private final Paint mPaint;
|
||||||
private final DrawFilter mFastDF;
|
private final DrawFilter mFastDF;
|
||||||
|
|
||||||
private float mTouchStartX;
|
private float mTouchStartX;
|
||||||
private float mTouchStartY;
|
private float mTouchStartY;
|
||||||
private float mTouchCurrX;
|
private float mTouchCurrX;
|
||||||
@@ -72,25 +70,25 @@ public class Patterns extends GraphicsActivity {
|
|||||||
mFastDF = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG |
|
mFastDF = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG |
|
||||||
Paint.DITHER_FLAG,
|
Paint.DITHER_FLAG,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
mShader1 = new BitmapShader(makeBitmap1(), Shader.TileMode.REPEAT,
|
mShader1 = new BitmapShader(makeBitmap1(), Shader.TileMode.REPEAT,
|
||||||
Shader.TileMode.REPEAT);
|
Shader.TileMode.REPEAT);
|
||||||
mShader2 = new BitmapShader(makeBitmap2(), Shader.TileMode.REPEAT,
|
mShader2 = new BitmapShader(makeBitmap2(), Shader.TileMode.REPEAT,
|
||||||
Shader.TileMode.REPEAT);
|
Shader.TileMode.REPEAT);
|
||||||
|
|
||||||
Matrix m = new Matrix();
|
Matrix m = new Matrix();
|
||||||
m.setRotate(30);
|
m.setRotate(30);
|
||||||
mShader2.setLocalMatrix(m);
|
mShader2.setLocalMatrix(m);
|
||||||
|
|
||||||
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
|
mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.setDrawFilter(mDF);
|
canvas.setDrawFilter(mDF);
|
||||||
|
|
||||||
mPaint.setShader(mShader1);
|
mPaint.setShader(mShader1);
|
||||||
canvas.drawPaint(mPaint);
|
canvas.drawPaint(mPaint);
|
||||||
|
|
||||||
canvas.translate(mTouchCurrX - mTouchStartX,
|
canvas.translate(mTouchCurrX - mTouchStartX,
|
||||||
mTouchCurrY - mTouchStartY);
|
mTouchCurrY - mTouchStartY);
|
||||||
|
|
||||||
@@ -102,7 +100,7 @@ public class Patterns extends GraphicsActivity {
|
|||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
float x = event.getX();
|
float x = event.getX();
|
||||||
float y = event.getY();
|
float y = event.getY();
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
mTouchStartX = mTouchCurrX = x;
|
mTouchStartX = mTouchCurrX = x;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
|
|
||||||
|
|
||||||
public class PictureLayout extends ViewGroup {
|
public class PictureLayout extends ViewGroup {
|
||||||
private final Picture mPicture = new Picture();
|
private final Picture mPicture = new Picture();
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ public class PictureLayout extends ViewGroup {
|
|||||||
|
|
||||||
public PictureLayout(Context context, AttributeSet attrs) {
|
public PictureLayout(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addView(View child) {
|
public void addView(View child) {
|
||||||
@@ -105,7 +104,7 @@ public class PictureLayout extends ViewGroup {
|
|||||||
setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
|
setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec),
|
||||||
resolveSize(maxHeight, heightMeasureSpec));
|
resolveSize(maxHeight, heightMeasureSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawPict(Canvas canvas, int x, int y, int w, int h,
|
private void drawPict(Canvas canvas, int x, int y, int w, int h,
|
||||||
float sx, float sy) {
|
float sx, float sy) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
@@ -121,10 +120,10 @@ public class PictureLayout extends ViewGroup {
|
|||||||
protected void dispatchDraw(Canvas canvas) {
|
protected void dispatchDraw(Canvas canvas) {
|
||||||
super.dispatchDraw(mPicture.beginRecording(getWidth(), getHeight()));
|
super.dispatchDraw(mPicture.beginRecording(getWidth(), getHeight()));
|
||||||
mPicture.endRecording();
|
mPicture.endRecording();
|
||||||
|
|
||||||
int x = getWidth()/2;
|
int x = getWidth()/2;
|
||||||
int y = getHeight()/2;
|
int y = getHeight()/2;
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
canvas.drawPicture(mPicture);
|
canvas.drawPicture(mPicture);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -16,13 +16,11 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.PictureDrawable;
|
import android.graphics.drawable.PictureDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@@ -34,17 +32,17 @@ public class Pictures extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Picture mPicture;
|
private Picture mPicture;
|
||||||
private Drawable mDrawable;
|
private Drawable mDrawable;
|
||||||
|
|
||||||
static void drawSomething(Canvas canvas) {
|
static void drawSomething(Canvas canvas) {
|
||||||
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
|
||||||
p.setColor(0x88FF0000);
|
p.setColor(0x88FF0000);
|
||||||
canvas.drawCircle(50, 50, 40, p);
|
canvas.drawCircle(50, 50, 40, p);
|
||||||
|
|
||||||
p.setColor(Color.GREEN);
|
p.setColor(Color.GREEN);
|
||||||
p.setTextSize(30);
|
p.setTextSize(30);
|
||||||
canvas.drawText("Pictures", 60, 60, p);
|
canvas.drawText("Pictures", 60, 60, p);
|
||||||
@@ -58,20 +56,20 @@ public class Pictures extends GraphicsActivity {
|
|||||||
mPicture = new Picture();
|
mPicture = new Picture();
|
||||||
drawSomething(mPicture.beginRecording(200, 100));
|
drawSomething(mPicture.beginRecording(200, 100));
|
||||||
mPicture.endRecording();
|
mPicture.endRecording();
|
||||||
|
|
||||||
mDrawable = new PictureDrawable(mPicture);
|
mDrawable = new PictureDrawable(mPicture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
canvas.drawPicture(mPicture);
|
canvas.drawPicture(mPicture);
|
||||||
|
|
||||||
canvas.drawPicture(mPicture, new RectF(0, 100, getWidth(), 200));
|
canvas.drawPicture(mPicture, new RectF(0, 100, getWidth(), 200));
|
||||||
|
|
||||||
mDrawable.setBounds(0, 200, getWidth(), 300);
|
mDrawable.setBounds(0, 200, getWidth(), 300);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
|
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
mPicture.writeToStream(os);
|
mPicture.writeToStream(os);
|
||||||
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package com.example.android.apis.graphics;
|
|||||||
// class is in a sub-package.
|
// class is in a sub-package.
|
||||||
//import com.example.android.apis.R;
|
//import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -33,7 +32,7 @@ public class PolyToPoly extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private Matrix mMatrix = new Matrix();
|
private Matrix mMatrix = new Matrix();
|
||||||
@@ -43,13 +42,13 @@ public class PolyToPoly extends GraphicsActivity {
|
|||||||
canvas.save();
|
canvas.save();
|
||||||
mMatrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
|
mMatrix.setPolyToPoly(src, 0, dst, 0, src.length >> 1);
|
||||||
canvas.concat(mMatrix);
|
canvas.concat(mMatrix);
|
||||||
|
|
||||||
mPaint.setColor(Color.GRAY);
|
mPaint.setColor(Color.GRAY);
|
||||||
mPaint.setStyle(Paint.Style.STROKE);
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
canvas.drawRect(0, 0, 64, 64, mPaint);
|
canvas.drawRect(0, 0, 64, 64, mPaint);
|
||||||
canvas.drawLine(0, 0, 64, 64, mPaint);
|
canvas.drawLine(0, 0, 64, 64, mPaint);
|
||||||
canvas.drawLine(0, 64, 64, 0, mPaint);
|
canvas.drawLine(0, 64, 64, 0, mPaint);
|
||||||
|
|
||||||
mPaint.setColor(Color.RED);
|
mPaint.setColor(Color.RED);
|
||||||
mPaint.setStyle(Paint.Style.FILL);
|
mPaint.setStyle(Paint.Style.FILL);
|
||||||
// how to draw the text center on our square
|
// how to draw the text center on our square
|
||||||
@@ -58,7 +57,7 @@ public class PolyToPoly extends GraphicsActivity {
|
|||||||
// centering in Y, we need to measure ascent/descent first
|
// centering in Y, we need to measure ascent/descent first
|
||||||
float y = 64/2 - (mFontMetrics.ascent + mFontMetrics.descent)/2;
|
float y = 64/2 - (mFontMetrics.ascent + mFontMetrics.descent)/2;
|
||||||
canvas.drawText(src.length/2 + "", x, y, mPaint);
|
canvas.drawText(src.length/2 + "", x, y, mPaint);
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,10 +71,9 @@ public class PolyToPoly extends GraphicsActivity {
|
|||||||
mPaint.setTextAlign(Paint.Align.CENTER);
|
mPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
mFontMetrics = mPaint.getFontMetrics();
|
mFontMetrics = mPaint.getFontMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
|
||||||
Paint paint = mPaint;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
@@ -83,7 +81,7 @@ public class PolyToPoly extends GraphicsActivity {
|
|||||||
// translate (1 point)
|
// translate (1 point)
|
||||||
doDraw(canvas, new float[] { 0, 0 }, new float[] { 5, 5 });
|
doDraw(canvas, new float[] { 0, 0 }, new float[] { 5, 5 });
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(160, 10);
|
canvas.translate(160, 10);
|
||||||
// rotate/uniform-scale (2 points)
|
// rotate/uniform-scale (2 points)
|
||||||
@@ -107,4 +105,3 @@ public class PolyToPoly extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,18 +22,18 @@ import android.graphics.PixelFormat;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
public class ProxyDrawable extends Drawable {
|
public class ProxyDrawable extends Drawable {
|
||||||
|
|
||||||
private Drawable mProxy;
|
private Drawable mProxy;
|
||||||
private boolean mMutated;
|
private boolean mMutated;
|
||||||
|
|
||||||
public ProxyDrawable(Drawable target) {
|
public ProxyDrawable(Drawable target) {
|
||||||
mProxy = target;
|
mProxy = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable getProxy() {
|
public Drawable getProxy() {
|
||||||
return mProxy;
|
return mProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProxy(Drawable proxy) {
|
public void setProxy(Drawable proxy) {
|
||||||
if (proxy != this) {
|
if (proxy != this) {
|
||||||
mProxy = proxy;
|
mProxy = proxy;
|
||||||
@@ -46,43 +46,43 @@ public class ProxyDrawable extends Drawable {
|
|||||||
mProxy.draw(canvas);
|
mProxy.draw(canvas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIntrinsicWidth() {
|
public int getIntrinsicWidth() {
|
||||||
return mProxy != null ? mProxy.getIntrinsicWidth() : -1;
|
return mProxy != null ? mProxy.getIntrinsicWidth() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getIntrinsicHeight() {
|
public int getIntrinsicHeight() {
|
||||||
return mProxy != null ? mProxy.getIntrinsicHeight() : -1;
|
return mProxy != null ? mProxy.getIntrinsicHeight() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOpacity() {
|
public int getOpacity() {
|
||||||
return mProxy != null ? mProxy.getOpacity() : PixelFormat.TRANSPARENT;
|
return mProxy != null ? mProxy.getOpacity() : PixelFormat.TRANSPARENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFilterBitmap(boolean filter) {
|
public void setFilterBitmap(boolean filter) {
|
||||||
if (mProxy != null) {
|
if (mProxy != null) {
|
||||||
mProxy.setFilterBitmap(filter);
|
mProxy.setFilterBitmap(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDither(boolean dither) {
|
public void setDither(boolean dither) {
|
||||||
if (mProxy != null) {
|
if (mProxy != null) {
|
||||||
mProxy.setDither(dither);
|
mProxy.setDither(dither);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setColorFilter(ColorFilter colorFilter) {
|
public void setColorFilter(ColorFilter colorFilter) {
|
||||||
if (mProxy != null) {
|
if (mProxy != null) {
|
||||||
mProxy.setColorFilter(colorFilter);
|
mProxy.setColorFilter(colorFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAlpha(int alpha) {
|
public void setAlpha(int alpha) {
|
||||||
if (mProxy != null) {
|
if (mProxy != null) {
|
||||||
@@ -99,4 +99,4 @@ public class ProxyDrawable extends Drawable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,7 +28,7 @@ public class Regions extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private final Paint mPaint = new Paint();
|
private final Paint mPaint = new Paint();
|
||||||
private final Rect mRect1 = new Rect();
|
private final Rect mRect1 = new Rect();
|
||||||
@@ -38,11 +37,11 @@ public class Regions extends GraphicsActivity {
|
|||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setTextSize(16);
|
mPaint.setTextSize(16);
|
||||||
mPaint.setTextAlign(Paint.Align.CENTER);
|
mPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
mRect1.set(10, 10, 100, 80);
|
mRect1.set(10, 10, 100, 80);
|
||||||
mRect2.set(50, 50, 130, 110);
|
mRect2.set(50, 50, 130, 110);
|
||||||
}
|
}
|
||||||
@@ -55,25 +54,25 @@ public class Regions extends GraphicsActivity {
|
|||||||
mPaint.setColor(Color.BLUE);
|
mPaint.setColor(Color.BLUE);
|
||||||
mPaint.setAlpha(alpha);
|
mPaint.setAlpha(alpha);
|
||||||
drawCentered(canvas, mRect2, mPaint);
|
drawCentered(canvas, mRect2, mPaint);
|
||||||
|
|
||||||
// restore style
|
// restore style
|
||||||
mPaint.setStyle(Paint.Style.FILL);
|
mPaint.setStyle(Paint.Style.FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawRgn(Canvas canvas, int color, String str, Region.Op op) {
|
private void drawRgn(Canvas canvas, int color, String str, Region.Op op) {
|
||||||
if (str != null) {
|
if (str != null) {
|
||||||
mPaint.setColor(Color.BLACK);
|
mPaint.setColor(Color.BLACK);
|
||||||
canvas.drawText(str, 80, 24, mPaint);
|
canvas.drawText(str, 80, 24, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
Region rgn = new Region();
|
Region rgn = new Region();
|
||||||
rgn.set(mRect1);
|
rgn.set(mRect1);
|
||||||
rgn.op(mRect2, op);
|
rgn.op(mRect2, op);
|
||||||
|
|
||||||
mPaint.setColor(color);
|
mPaint.setColor(color);
|
||||||
RegionIterator iter = new RegionIterator(rgn);
|
RegionIterator iter = new RegionIterator(rgn);
|
||||||
Rect r = new Rect();
|
Rect r = new Rect();
|
||||||
|
|
||||||
canvas.translate(0, 30);
|
canvas.translate(0, 30);
|
||||||
mPaint.setColor(color);
|
mPaint.setColor(color);
|
||||||
while (iter.next(r)) {
|
while (iter.next(r)) {
|
||||||
@@ -81,7 +80,7 @@ public class Regions extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
drawOriginalRects(canvas, 0x80);
|
drawOriginalRects(canvas, 0x80);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawCentered(Canvas c, Rect r, Paint p) {
|
private static void drawCentered(Canvas c, Rect r, Paint p) {
|
||||||
float inset = p.getStrokeWidth() * 0.5f;
|
float inset = p.getStrokeWidth() * 0.5f;
|
||||||
if (inset == 0) { // catch hairlines
|
if (inset == 0) { // catch hairlines
|
||||||
@@ -90,32 +89,33 @@ public class Regions extends GraphicsActivity {
|
|||||||
c.drawRect(r.left + inset, r.top + inset,
|
c.drawRect(r.left + inset, r.top + inset,
|
||||||
r.right - inset, r.bottom - inset, p);
|
r.right - inset, r.bottom - inset, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override
|
||||||
canvas.drawColor(Color.GRAY);
|
protected void onDraw(Canvas canvas) {
|
||||||
|
canvas.drawColor(Color.GRAY);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(80, 5);
|
canvas.translate(80, 5);
|
||||||
drawOriginalRects(canvas, 0xFF);
|
drawOriginalRects(canvas, 0xFF);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
mPaint.setStyle(Paint.Style.FILL);
|
mPaint.setStyle(Paint.Style.FILL);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(0, 140);
|
canvas.translate(0, 140);
|
||||||
drawRgn(canvas, Color.RED, "Union", Region.Op.UNION);
|
drawRgn(canvas, Color.RED, "Union", Region.Op.UNION);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(0, 280);
|
canvas.translate(0, 280);
|
||||||
drawRgn(canvas, Color.BLUE, "Xor", Region.Op.XOR);
|
drawRgn(canvas, Color.BLUE, "Xor", Region.Op.XOR);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(160, 140);
|
canvas.translate(160, 140);
|
||||||
drawRgn(canvas, Color.GREEN, "Difference", Region.Op.DIFFERENCE);
|
drawRgn(canvas, Color.GREEN, "Difference", Region.Op.DIFFERENCE);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(160, 280);
|
canvas.translate(160, 280);
|
||||||
drawRgn(canvas, Color.WHITE, "Intersect", Region.Op.INTERSECT);
|
drawRgn(canvas, Color.WHITE, "Intersect", Region.Op.INTERSECT);
|
||||||
|
|||||||
@@ -16,14 +16,10 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.*;
|
import android.graphics.drawable.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
public class RoundRects extends GraphicsActivity {
|
public class RoundRects extends GraphicsActivity {
|
||||||
@@ -33,7 +29,7 @@ public class RoundRects extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
@@ -47,73 +43,71 @@ public class RoundRects extends GraphicsActivity {
|
|||||||
mPath = new Path();
|
mPath = new Path();
|
||||||
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
mRect = new Rect(0, 0, 120, 120);
|
mRect = new Rect(0, 0, 120, 120);
|
||||||
|
|
||||||
mDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR,
|
mDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR,
|
||||||
new int[] { 0xFFFF0000, 0xFF00FF00,
|
new int[] { 0xFFFF0000, 0xFF00FF00,
|
||||||
0xFF0000FF });
|
0xFF0000FF });
|
||||||
mDrawable.setShape(GradientDrawable.RECTANGLE);
|
mDrawable.setShape(GradientDrawable.RECTANGLE);
|
||||||
mDrawable.setGradientRadius((float)(Math.sqrt(2) * 60));
|
mDrawable.setGradientRadius((float)(Math.sqrt(2) * 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setCornerRadii(GradientDrawable drawable, float r0,
|
static void setCornerRadii(GradientDrawable drawable, float r0,
|
||||||
float r1, float r2, float r3) {
|
float r1, float r2, float r3) {
|
||||||
drawable.setCornerRadii(new float[] { r0, r0, r1, r1,
|
drawable.setCornerRadii(new float[] { r0, r0, r1, r1,
|
||||||
r2, r2, r3, r3 });
|
r2, r2, r3, r3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
|
|
||||||
mDrawable.setBounds(mRect);
|
mDrawable.setBounds(mRect);
|
||||||
|
|
||||||
float r = 16;
|
float r = 16;
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
||||||
setCornerRadii(mDrawable, r, r, 0, 0);
|
setCornerRadii(mDrawable, r, r, 0, 0);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10 + mRect.width() + 10, 10);
|
canvas.translate(10 + mRect.width() + 10, 10);
|
||||||
mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
|
mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
|
||||||
setCornerRadii(mDrawable, 0, 0, r, r);
|
setCornerRadii(mDrawable, 0, 0, r, r);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.translate(0, mRect.height() + 10);
|
canvas.translate(0, mRect.height() + 10);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
|
mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
|
||||||
setCornerRadii(mDrawable, 0, r, r, 0);
|
setCornerRadii(mDrawable, 0, r, r, 0);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10 + mRect.width() + 10, 10);
|
canvas.translate(10 + mRect.width() + 10, 10);
|
||||||
mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
|
||||||
setCornerRadii(mDrawable, r, 0, 0, r);
|
setCornerRadii(mDrawable, r, 0, 0, r);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.translate(0, mRect.height() + 10);
|
canvas.translate(0, mRect.height() + 10);
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
|
mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
|
||||||
setCornerRadii(mDrawable, r, 0, r, 0);
|
setCornerRadii(mDrawable, r, 0, r, 0);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(10 + mRect.width() + 10, 10);
|
canvas.translate(10 + mRect.width() + 10, 10);
|
||||||
mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
|
mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
|
||||||
setCornerRadii(mDrawable, 0, r, 0, r);
|
setCornerRadii(mDrawable, 0, r, 0, r);
|
||||||
mDrawable.draw(canvas);
|
mDrawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,14 +28,14 @@ public class ScaleToFit extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private final Paint mHairPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private final Paint mHairPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private final Paint mLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private final Paint mLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private final Matrix mMatrix = new Matrix();
|
private final Matrix mMatrix = new Matrix();
|
||||||
private final RectF mSrcR = new RectF();
|
private final RectF mSrcR = new RectF();
|
||||||
|
|
||||||
private static final Matrix.ScaleToFit[] sFits =
|
private static final Matrix.ScaleToFit[] sFits =
|
||||||
new Matrix.ScaleToFit[] {
|
new Matrix.ScaleToFit[] {
|
||||||
Matrix.ScaleToFit.FILL,
|
Matrix.ScaleToFit.FILL,
|
||||||
@@ -44,11 +43,11 @@ public class ScaleToFit extends GraphicsActivity {
|
|||||||
Matrix.ScaleToFit.CENTER,
|
Matrix.ScaleToFit.CENTER,
|
||||||
Matrix.ScaleToFit.END
|
Matrix.ScaleToFit.END
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] sFitLabels = new String[] {
|
private static final String[] sFitLabels = new String[] {
|
||||||
"FILL", "START", "CENTER", "END"
|
"FILL", "START", "CENTER", "END"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int[] sSrcData = new int[] {
|
private static final int[] sSrcData = new int[] {
|
||||||
80, 40, Color.RED,
|
80, 40, Color.RED,
|
||||||
40, 80, Color.GREEN,
|
40, 80, Color.GREEN,
|
||||||
@@ -56,7 +55,7 @@ public class ScaleToFit extends GraphicsActivity {
|
|||||||
80, 80, Color.BLACK
|
80, 80, Color.BLACK
|
||||||
};
|
};
|
||||||
private static final int N = 4;
|
private static final int N = 4;
|
||||||
|
|
||||||
private static final int WIDTH = 52;
|
private static final int WIDTH = 52;
|
||||||
private static final int HEIGHT = 52;
|
private static final int HEIGHT = 52;
|
||||||
private final RectF mDstR = new RectF(0, 0, WIDTH, HEIGHT);
|
private final RectF mDstR = new RectF(0, 0, WIDTH, HEIGHT);
|
||||||
@@ -67,34 +66,33 @@ public class ScaleToFit extends GraphicsActivity {
|
|||||||
mHairPaint.setStyle(Paint.Style.STROKE);
|
mHairPaint.setStyle(Paint.Style.STROKE);
|
||||||
mLabelPaint.setTextSize(16);
|
mLabelPaint.setTextSize(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSrcR(int index) {
|
private void setSrcR(int index) {
|
||||||
int w = sSrcData[index*3 + 0];
|
int w = sSrcData[index*3 + 0];
|
||||||
int h = sSrcData[index*3 + 1];
|
int h = sSrcData[index*3 + 1];
|
||||||
mSrcR.set(0, 0, w, h);
|
mSrcR.set(0, 0, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawSrcR(Canvas canvas, int index) {
|
private void drawSrcR(Canvas canvas, int index) {
|
||||||
mPaint.setColor(sSrcData[index*3 + 2]);
|
mPaint.setColor(sSrcData[index*3 + 2]);
|
||||||
canvas.drawOval(mSrcR, mPaint);
|
canvas.drawOval(mSrcR, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawFit(Canvas canvas, int index, Matrix.ScaleToFit stf) {
|
private void drawFit(Canvas canvas, int index, Matrix.ScaleToFit stf) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
|
|
||||||
setSrcR(index);
|
setSrcR(index);
|
||||||
mMatrix.setRectToRect(mSrcR, mDstR, stf);
|
mMatrix.setRectToRect(mSrcR, mDstR, stf);
|
||||||
canvas.concat(mMatrix);
|
canvas.concat(mMatrix);
|
||||||
drawSrcR(canvas, index);
|
drawSrcR(canvas, index);
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.drawRect(mDstR, mHairPaint);
|
canvas.drawRect(mDstR, mHairPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override
|
||||||
Paint paint = mPaint;
|
protected void onDraw(Canvas canvas) {
|
||||||
|
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
canvas.translate(10, 10);
|
canvas.translate(10, 10);
|
||||||
@@ -106,7 +104,7 @@ public class ScaleToFit extends GraphicsActivity {
|
|||||||
canvas.translate(mSrcR.width() + 15, 0);
|
canvas.translate(mSrcR.width() + 15, 0);
|
||||||
}
|
}
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.translate(0, 100);
|
canvas.translate(0, 100);
|
||||||
for (int j = 0; j < sFits.length; j++) {
|
for (int j = 0; j < sFits.length; j++) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
@@ -121,4 +119,3 @@ public class ScaleToFit extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.hardware.SensorEventListener;
|
|||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Config;
|
import android.util.Config;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class SensorTest extends GraphicsActivity {
|
public class SensorTest extends GraphicsActivity {
|
||||||
@@ -33,7 +34,7 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
private Sensor mSensor;
|
private Sensor mSensor;
|
||||||
private SampleView mView;
|
private SampleView mView;
|
||||||
private float[] mValues;
|
private float[] mValues;
|
||||||
|
|
||||||
private static class RunAve {
|
private static class RunAve {
|
||||||
private final float[] mWeights;
|
private final float[] mWeights;
|
||||||
private final float mWeightScale;
|
private final float mWeightScale;
|
||||||
@@ -43,7 +44,7 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
|
|
||||||
public RunAve(float[] weights) {
|
public RunAve(float[] weights) {
|
||||||
mWeights = weights;
|
mWeights = weights;
|
||||||
|
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
for (int i = 0; i < weights.length; i++) {
|
for (int i = 0; i < weights.length; i++) {
|
||||||
sum += weights[i];
|
sum += weights[i];
|
||||||
@@ -54,12 +55,12 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
mSamples = new float[mDepth];
|
mSamples = new float[mDepth];
|
||||||
mCurr = 0;
|
mCurr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSample(float value) {
|
public void addSample(float value) {
|
||||||
mSamples[mCurr] = value;
|
mSamples[mCurr] = value;
|
||||||
mCurr = (mCurr + 1) % mDepth;
|
mCurr = (mCurr + 1) % mDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float computeAve() {
|
public float computeAve() {
|
||||||
final int depth = mDepth;
|
final int depth = mDepth;
|
||||||
int index = mCurr;
|
int index = mCurr;
|
||||||
@@ -92,20 +93,20 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
mPrev[i] = event.values[i];
|
mPrev[i] = event.values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show) {
|
if (show) {
|
||||||
// only shows if we think the delta is big enough, in an attempt
|
// only shows if we think the delta is big enough, in an attempt
|
||||||
// to detect "serious" moves left/right or up/down
|
// to detect "serious" moves left/right or up/down
|
||||||
android.util.Log.e(TAG, "sensorChanged " + event.sensor.getName() +
|
Log.e(TAG, "sensorChanged " + event.sensor.getName() +
|
||||||
" (" + event.values[0] + ", " + event.values[1] + ", " +
|
" (" + event.values[0] + ", " + event.values[1] + ", " +
|
||||||
event.values[2] + ")" + " diff(" + diff[0] +
|
event.values[2] + ")" + " diff(" + diff[0] +
|
||||||
" " + diff[1] + " " + diff[2] + ")");
|
" " + diff[1] + " " + diff[2] + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
long now = android.os.SystemClock.uptimeMillis();
|
long now = android.os.SystemClock.uptimeMillis();
|
||||||
if (now - mLastGestureTime > 1000) {
|
if (now - mLastGestureTime > 1000) {
|
||||||
mLastGestureTime = 0;
|
mLastGestureTime = 0;
|
||||||
|
|
||||||
float x = diff[0];
|
float x = diff[0];
|
||||||
float y = diff[1];
|
float y = diff[1];
|
||||||
boolean gestX = Math.abs(x) > 3;
|
boolean gestX = Math.abs(x) > 3;
|
||||||
@@ -114,15 +115,15 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
if ((gestX || gestY) && !(gestX && gestY)) {
|
if ((gestX || gestY) && !(gestX && gestY)) {
|
||||||
if (gestX) {
|
if (gestX) {
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
android.util.Log.e("test", "<<<<<<<< LEFT <<<<<<<<<<<<");
|
Log.e("test", "<<<<<<<< LEFT <<<<<<<<<<<<");
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.e("test", ">>>>>>>>> RITE >>>>>>>>>>>");
|
Log.e("test", ">>>>>>>>> RITE >>>>>>>>>>>");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (y < -2) {
|
if (y < -2) {
|
||||||
android.util.Log.e("test", "<<<<<<<< UP <<<<<<<<<<<<");
|
Log.e("test", "<<<<<<<< UP <<<<<<<<<<<<");
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.e("test", ">>>>>>>>> DOWN >>>>>>>>>>>");
|
Log.e("test", ">>>>>>>>> DOWN >>>>>>>>>>>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mLastGestureTime = now;
|
mLastGestureTime = now;
|
||||||
@@ -141,28 +142,27 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||||
mView = new SampleView(this);
|
mView = new SampleView(this);
|
||||||
setContentView(mView);
|
setContentView(mView);
|
||||||
if (Config.LOGD) android.util.Log.d(TAG, "create " + mSensorManager);
|
if (Config.DEBUG) Log.d(TAG, "create " + mSensorManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
mSensorManager.registerListener(mListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
|
mSensorManager.registerListener(mListener, mSensor, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
if (Config.LOGD) android.util.Log.d(TAG, "resume " + mSensorManager);
|
if (Config.DEBUG) Log.d(TAG, "resume " + mSensorManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
mSensorManager.unregisterListener(mListener);
|
mSensorManager.unregisterListener(mListener);
|
||||||
super.onStop();
|
super.onStop();
|
||||||
if (Config.LOGD) android.util.Log.d(TAG, "stop " + mSensorManager);
|
if (Config.DEBUG) Log.d(TAG, "stop " + mSensorManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SampleView extends View {
|
private class SampleView extends View {
|
||||||
private Paint mPaint = new Paint();
|
private Paint mPaint = new Paint();
|
||||||
private Path mPath = new Path();
|
private Path mPath = new Path();
|
||||||
private boolean mAnimate;
|
private boolean mAnimate;
|
||||||
private long mNextTime;
|
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -174,13 +174,13 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
mPath.lineTo(20, 60);
|
mPath.lineTo(20, 60);
|
||||||
mPath.close();
|
mPath.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
Paint paint = mPaint;
|
Paint paint = mPaint;
|
||||||
|
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
paint.setColor(Color.BLACK);
|
paint.setColor(Color.BLACK);
|
||||||
paint.setStyle(Paint.Style.FILL);
|
paint.setStyle(Paint.Style.FILL);
|
||||||
@@ -191,21 +191,23 @@ public class SensorTest extends GraphicsActivity {
|
|||||||
int cy = h / 2;
|
int cy = h / 2;
|
||||||
|
|
||||||
canvas.translate(cx, cy);
|
canvas.translate(cx, cy);
|
||||||
if (mValues != null) {
|
if (mValues != null) {
|
||||||
canvas.rotate(-mValues[0]);
|
canvas.rotate(-mValues[0]);
|
||||||
}
|
}
|
||||||
canvas.drawPath(mPath, mPaint);
|
canvas.drawPath(mPath, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
mAnimate = true;
|
mAnimate = true;
|
||||||
|
if (Config.DEBUG) Log.d(TAG, "onAttachedToWindow. mAnimate="+mAnimate);
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
mAnimate = false;
|
mAnimate = false;
|
||||||
|
if (Config.DEBUG) Log.d(TAG, "onAttachedToWindow. mAnimate="+mAnimate);
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,12 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.ShapeDrawable;
|
import android.graphics.drawable.ShapeDrawable;
|
||||||
import android.graphics.drawable.shapes.*;
|
import android.graphics.drawable.shapes.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
public class ShapeDrawable1 extends GraphicsActivity {
|
public class ShapeDrawable1 extends GraphicsActivity {
|
||||||
@@ -35,49 +31,49 @@ public class ShapeDrawable1 extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private ShapeDrawable[] mDrawables;
|
private ShapeDrawable[] mDrawables;
|
||||||
|
|
||||||
private static Shader makeSweep() {
|
private static Shader makeSweep() {
|
||||||
return new SweepGradient(150, 25,
|
return new SweepGradient(150, 25,
|
||||||
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFF0000 },
|
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFF0000 },
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Shader makeLinear() {
|
private static Shader makeLinear() {
|
||||||
return new LinearGradient(0, 0, 50, 50,
|
return new LinearGradient(0, 0, 50, 50,
|
||||||
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF },
|
new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF },
|
||||||
null, Shader.TileMode.MIRROR);
|
null, Shader.TileMode.MIRROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Shader makeTiling() {
|
private static Shader makeTiling() {
|
||||||
int[] pixels = new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0};
|
int[] pixels = new int[] { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0};
|
||||||
Bitmap bm = Bitmap.createBitmap(pixels, 2, 2,
|
Bitmap bm = Bitmap.createBitmap(pixels, 2, 2,
|
||||||
Bitmap.Config.ARGB_8888);
|
Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
return new BitmapShader(bm, Shader.TileMode.REPEAT,
|
return new BitmapShader(bm, Shader.TileMode.REPEAT,
|
||||||
Shader.TileMode.REPEAT);
|
Shader.TileMode.REPEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MyShapeDrawable extends ShapeDrawable {
|
private static class MyShapeDrawable extends ShapeDrawable {
|
||||||
private Paint mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private Paint mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
|
||||||
public MyShapeDrawable(Shape s) {
|
public MyShapeDrawable(Shape s) {
|
||||||
super(s);
|
super(s);
|
||||||
mStrokePaint.setStyle(Paint.Style.STROKE);
|
mStrokePaint.setStyle(Paint.Style.STROKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Paint getStrokePaint() {
|
public Paint getStrokePaint() {
|
||||||
return mStrokePaint;
|
return mStrokePaint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Shape s, Canvas c, Paint p) {
|
@Override protected void onDraw(Shape s, Canvas c, Paint p) {
|
||||||
s.draw(c, p);
|
s.draw(c, p);
|
||||||
s.draw(c, mStrokePaint);
|
s.draw(c, mStrokePaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
@@ -85,14 +81,14 @@ public class ShapeDrawable1 extends GraphicsActivity {
|
|||||||
float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
|
float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
|
||||||
RectF inset = new RectF(6, 6, 6, 6);
|
RectF inset = new RectF(6, 6, 6, 6);
|
||||||
float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };
|
float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };
|
||||||
|
|
||||||
Path path = new Path();
|
Path path = new Path();
|
||||||
path.moveTo(50, 0);
|
path.moveTo(50, 0);
|
||||||
path.lineTo(0, 50);
|
path.lineTo(0, 50);
|
||||||
path.lineTo(50, 100);
|
path.lineTo(50, 100);
|
||||||
path.lineTo(100, 50);
|
path.lineTo(100, 50);
|
||||||
path.close();
|
path.close();
|
||||||
|
|
||||||
mDrawables = new ShapeDrawable[7];
|
mDrawables = new ShapeDrawable[7];
|
||||||
mDrawables[0] = new ShapeDrawable(new RectShape());
|
mDrawables[0] = new ShapeDrawable(new RectShape());
|
||||||
mDrawables[1] = new ShapeDrawable(new OvalShape());
|
mDrawables[1] = new ShapeDrawable(new OvalShape());
|
||||||
@@ -104,7 +100,7 @@ public class ShapeDrawable1 extends GraphicsActivity {
|
|||||||
innerR));
|
innerR));
|
||||||
mDrawables[5] = new ShapeDrawable(new PathShape(path, 100, 100));
|
mDrawables[5] = new ShapeDrawable(new PathShape(path, 100, 100));
|
||||||
mDrawables[6] = new MyShapeDrawable(new ArcShape(45, -270));
|
mDrawables[6] = new MyShapeDrawable(new ArcShape(45, -270));
|
||||||
|
|
||||||
mDrawables[0].getPaint().setColor(0xFFFF0000);
|
mDrawables[0].getPaint().setColor(0xFFFF0000);
|
||||||
mDrawables[1].getPaint().setColor(0xFF00FF00);
|
mDrawables[1].getPaint().setColor(0xFF00FF00);
|
||||||
mDrawables[2].getPaint().setColor(0xFF0000FF);
|
mDrawables[2].getPaint().setColor(0xFF0000FF);
|
||||||
@@ -112,26 +108,26 @@ public class ShapeDrawable1 extends GraphicsActivity {
|
|||||||
mDrawables[4].getPaint().setShader(makeLinear());
|
mDrawables[4].getPaint().setShader(makeLinear());
|
||||||
mDrawables[5].getPaint().setShader(makeTiling());
|
mDrawables[5].getPaint().setShader(makeTiling());
|
||||||
mDrawables[6].getPaint().setColor(0x88FF8844);
|
mDrawables[6].getPaint().setColor(0x88FF8844);
|
||||||
|
|
||||||
PathEffect pe = new DiscretePathEffect(10, 4);
|
PathEffect pe = new DiscretePathEffect(10, 4);
|
||||||
PathEffect pe2 = new CornerPathEffect(4);
|
PathEffect pe2 = new CornerPathEffect(4);
|
||||||
mDrawables[3].getPaint().setPathEffect(
|
mDrawables[3].getPaint().setPathEffect(
|
||||||
new ComposePathEffect(pe2, pe));
|
new ComposePathEffect(pe2, pe));
|
||||||
|
|
||||||
MyShapeDrawable msd = (MyShapeDrawable)mDrawables[6];
|
MyShapeDrawable msd = (MyShapeDrawable)mDrawables[6];
|
||||||
msd.getStrokePaint().setStrokeWidth(4);
|
msd.getStrokePaint().setStrokeWidth(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
|
|
||||||
int x = 10;
|
int x = 10;
|
||||||
int y = 10;
|
int y = 10;
|
||||||
int width = 300;
|
int width = 300;
|
||||||
int height = 50;
|
int height = 50;
|
||||||
|
|
||||||
for (Drawable dr : mDrawables) {
|
for (Drawable dr : mDrawables) {
|
||||||
dr.setBounds(x, y, x + width, y + height);
|
dr.setBounds(x, y, x + width, y + height);
|
||||||
dr.draw(canvas);
|
dr.draw(canvas);
|
||||||
y += height + 5;
|
y += height + 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
// 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.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -34,7 +29,7 @@ public class Sweep extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private float mRotate;
|
private float mRotate;
|
||||||
@@ -55,7 +50,7 @@ public class Sweep extends GraphicsActivity {
|
|||||||
Color.GREEN }, null);
|
Color.GREEN }, null);
|
||||||
mPaint.setShader(mShader);
|
mPaint.setShader(mShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
Paint paint = mPaint;
|
Paint paint = mPaint;
|
||||||
float x = 160;
|
float x = 160;
|
||||||
|
|||||||
@@ -16,13 +16,9 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
public class TextAlign extends GraphicsActivity {
|
public class TextAlign extends GraphicsActivity {
|
||||||
@@ -32,27 +28,27 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private float mX;
|
private float mX;
|
||||||
private float[] mPos;
|
private float[] mPos;
|
||||||
|
|
||||||
private Path mPath;
|
private Path mPath;
|
||||||
private Paint mPathPaint;
|
private Paint mPathPaint;
|
||||||
|
|
||||||
private static final int DY = 30;
|
private static final int DY = 30;
|
||||||
private static final String TEXT_L = "Left";
|
private static final String TEXT_L = "Left";
|
||||||
private static final String TEXT_C = "Center";
|
private static final String TEXT_C = "Center";
|
||||||
private static final String TEXT_R = "Right";
|
private static final String TEXT_R = "Right";
|
||||||
private static final String POSTEXT = "Positioned";
|
private static final String POSTEXT = "Positioned";
|
||||||
private static final String TEXTONPATH = "Along a path";
|
private static final String TEXTONPATH = "Along a path";
|
||||||
|
|
||||||
private static void makePath(Path p) {
|
private static void makePath(Path p) {
|
||||||
p.moveTo(10, 0);
|
p.moveTo(10, 0);
|
||||||
p.cubicTo(100, -50, 200, 50, 300, 0);
|
p.cubicTo(100, -50, 200, 50, 300, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float[] buildTextPositions(String text, float y, Paint paint) {
|
private float[] buildTextPositions(String text, float y, Paint paint) {
|
||||||
float[] widths = new float[text.length()];
|
float[] widths = new float[text.length()];
|
||||||
// initially get the widths for each char
|
// initially get the widths for each char
|
||||||
@@ -67,18 +63,18 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setTextSize(30);
|
mPaint.setTextSize(30);
|
||||||
mPaint.setTypeface(Typeface.SERIF);
|
mPaint.setTypeface(Typeface.SERIF);
|
||||||
|
|
||||||
mPos = buildTextPositions(POSTEXT, 0, mPaint);
|
mPos = buildTextPositions(POSTEXT, 0, mPaint);
|
||||||
|
|
||||||
mPath = new Path();
|
mPath = new Path();
|
||||||
makePath(mPath);
|
makePath(mPath);
|
||||||
|
|
||||||
@@ -87,7 +83,7 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
mPathPaint.setColor(0x800000FF);
|
mPathPaint.setColor(0x800000FF);
|
||||||
mPathPaint.setStyle(Paint.Style.STROKE);
|
mPathPaint.setStyle(Paint.Style.STROKE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
@@ -95,13 +91,13 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
float x = mX;
|
float x = mX;
|
||||||
float y = 0;
|
float y = 0;
|
||||||
float[] pos = mPos;
|
float[] pos = mPos;
|
||||||
|
|
||||||
// draw the normal strings
|
// draw the normal strings
|
||||||
|
|
||||||
p.setColor(0x80FF0000);
|
p.setColor(0x80FF0000);
|
||||||
canvas.drawLine(x, y, x, y+DY*3, p);
|
canvas.drawLine(x, y, x, y+DY*3, p);
|
||||||
p.setColor(Color.BLACK);
|
p.setColor(Color.BLACK);
|
||||||
|
|
||||||
canvas.translate(0, DY);
|
canvas.translate(0, DY);
|
||||||
p.setTextAlign(Paint.Align.LEFT);
|
p.setTextAlign(Paint.Align.LEFT);
|
||||||
canvas.drawText(TEXT_L, x, y, p);
|
canvas.drawText(TEXT_L, x, y, p);
|
||||||
@@ -113,11 +109,11 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
canvas.translate(0, DY);
|
canvas.translate(0, DY);
|
||||||
p.setTextAlign(Paint.Align.RIGHT);
|
p.setTextAlign(Paint.Align.RIGHT);
|
||||||
canvas.drawText(TEXT_R, x, y, p);
|
canvas.drawText(TEXT_R, x, y, p);
|
||||||
|
|
||||||
canvas.translate(100, DY*2);
|
canvas.translate(100, DY*2);
|
||||||
|
|
||||||
// now draw the positioned strings
|
// now draw the positioned strings
|
||||||
|
|
||||||
p.setColor(0xBB00FF00);
|
p.setColor(0xBB00FF00);
|
||||||
for (int i = 0; i < pos.length/2; i++) {
|
for (int i = 0; i < pos.length/2; i++) {
|
||||||
canvas.drawLine(pos[i*2+0], pos[i*2+1]-DY,
|
canvas.drawLine(pos[i*2+0], pos[i*2+1]-DY,
|
||||||
@@ -127,17 +123,17 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
|
|
||||||
p.setTextAlign(Paint.Align.LEFT);
|
p.setTextAlign(Paint.Align.LEFT);
|
||||||
canvas.drawPosText(POSTEXT, pos, p);
|
canvas.drawPosText(POSTEXT, pos, p);
|
||||||
|
|
||||||
canvas.translate(0, DY);
|
canvas.translate(0, DY);
|
||||||
p.setTextAlign(Paint.Align.CENTER);
|
p.setTextAlign(Paint.Align.CENTER);
|
||||||
canvas.drawPosText(POSTEXT, pos, p);
|
canvas.drawPosText(POSTEXT, pos, p);
|
||||||
|
|
||||||
canvas.translate(0, DY);
|
canvas.translate(0, DY);
|
||||||
p.setTextAlign(Paint.Align.RIGHT);
|
p.setTextAlign(Paint.Align.RIGHT);
|
||||||
canvas.drawPosText(POSTEXT, pos, p);
|
canvas.drawPosText(POSTEXT, pos, p);
|
||||||
|
|
||||||
// now draw the text on path
|
// now draw the text on path
|
||||||
|
|
||||||
canvas.translate(-100, DY*2);
|
canvas.translate(-100, DY*2);
|
||||||
|
|
||||||
canvas.drawPath(mPath, mPathPaint);
|
canvas.drawPath(mPath, mPathPaint);
|
||||||
@@ -148,7 +144,7 @@ public class TextAlign extends GraphicsActivity {
|
|||||||
canvas.drawPath(mPath, mPathPaint);
|
canvas.drawPath(mPath, mPathPaint);
|
||||||
p.setTextAlign(Paint.Align.CENTER);
|
p.setTextAlign(Paint.Align.CENTER);
|
||||||
canvas.drawTextOnPath(TEXTONPATH, mPath, 0, 0, p);
|
canvas.drawTextOnPath(TEXTONPATH, mPath, 0, 0, p);
|
||||||
|
|
||||||
canvas.translate(0, DY*1.5f);
|
canvas.translate(0, DY*1.5f);
|
||||||
canvas.drawPath(mPath, mPathPaint);
|
canvas.drawPath(mPath, mPathPaint);
|
||||||
p.setTextAlign(Paint.Align.RIGHT);
|
p.setTextAlign(Paint.Align.RIGHT);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@@ -41,34 +40,34 @@ import android.view.View;
|
|||||||
public class TouchPaint extends GraphicsActivity {
|
public class TouchPaint extends GraphicsActivity {
|
||||||
/** Used as a pulse to gradually fade the contents of the window. */
|
/** Used as a pulse to gradually fade the contents of the window. */
|
||||||
private static final int FADE_MSG = 1;
|
private static final int FADE_MSG = 1;
|
||||||
|
|
||||||
/** Menu ID for the command to clear the window. */
|
/** Menu ID for the command to clear the window. */
|
||||||
private static final int CLEAR_ID = Menu.FIRST;
|
private static final int CLEAR_ID = Menu.FIRST;
|
||||||
/** Menu ID for the command to toggle fading. */
|
/** Menu ID for the command to toggle fading. */
|
||||||
private static final int FADE_ID = Menu.FIRST+1;
|
private static final int FADE_ID = Menu.FIRST+1;
|
||||||
|
|
||||||
/** How often to fade the contents of the window (in ms). */
|
/** How often to fade the contents of the window (in ms). */
|
||||||
private static final int FADE_DELAY = 100;
|
private static final int FADE_DELAY = 100;
|
||||||
|
|
||||||
/** The view responsible for drawing the window. */
|
/** The view responsible for drawing the window. */
|
||||||
MyView mView;
|
MyView mView;
|
||||||
/** Is fading mode enabled? */
|
/** Is fading mode enabled? */
|
||||||
boolean mFading;
|
boolean mFading;
|
||||||
|
|
||||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Create and attach the view that is responsible for painting.
|
// Create and attach the view that is responsible for painting.
|
||||||
mView = new MyView(this);
|
mView = new MyView(this);
|
||||||
setContentView(mView);
|
setContentView(mView);
|
||||||
mView.requestFocus();
|
mView.requestFocus();
|
||||||
|
|
||||||
// Restore the fading option if we are being thawed from a
|
// Restore the fading option if we are being thawed from a
|
||||||
// previously saved state. Note that we are not currently remembering
|
// previously saved state. Note that we are not currently remembering
|
||||||
// the contents of the bitmap.
|
// the contents of the bitmap.
|
||||||
mFading = savedInstanceState != null ? savedInstanceState.getBoolean("fading", true) : true;
|
mFading = savedInstanceState != null ? savedInstanceState.getBoolean("fading", true) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onCreateOptionsMenu(Menu menu) {
|
@Override public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
menu.add(0, CLEAR_ID, 0, "Clear");
|
menu.add(0, CLEAR_ID, 0, "Clear");
|
||||||
menu.add(0, FADE_ID, 0, "Fade").setCheckable(true);
|
menu.add(0, FADE_ID, 0, "Fade").setCheckable(true);
|
||||||
@@ -130,14 +129,14 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
mHandler.sendMessageDelayed(
|
mHandler.sendMessageDelayed(
|
||||||
mHandler.obtainMessage(FADE_MSG), FADE_DELAY);
|
mHandler.obtainMessage(FADE_MSG), FADE_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop the pulse to fade the screen.
|
* Stop the pulse to fade the screen.
|
||||||
*/
|
*/
|
||||||
void stopFading() {
|
void stopFading() {
|
||||||
mHandler.removeMessages(FADE_MSG);
|
mHandler.removeMessages(FADE_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Handler mHandler = new Handler() {
|
private Handler mHandler = new Handler() {
|
||||||
@Override public void handleMessage(Message msg) {
|
@Override public void handleMessage(Message msg) {
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
@@ -155,7 +154,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public class MyView extends View {
|
public class MyView extends View {
|
||||||
private static final int FADE_ALPHA = 0x06;
|
private static final int FADE_ALPHA = 0x06;
|
||||||
private static final int MAX_FADE_STEPS = 256/FADE_ALPHA + 4;
|
private static final int MAX_FADE_STEPS = 256/FADE_ALPHA + 4;
|
||||||
@@ -171,7 +170,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
private float mCurSize;
|
private float mCurSize;
|
||||||
private int mCurWidth;
|
private int mCurWidth;
|
||||||
private int mFadeSteps = MAX_FADE_STEPS;
|
private int mFadeSteps = MAX_FADE_STEPS;
|
||||||
|
|
||||||
public MyView(Context c) {
|
public MyView(Context c) {
|
||||||
super(c);
|
super(c);
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
@@ -190,7 +189,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
mFadeSteps = MAX_FADE_STEPS;
|
mFadeSteps = MAX_FADE_STEPS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fade() {
|
public void fade() {
|
||||||
if (mCanvas != null && mFadeSteps < MAX_FADE_STEPS) {
|
if (mCanvas != null && mFadeSteps < MAX_FADE_STEPS) {
|
||||||
mCanvas.drawPaint(mFadePaint);
|
mCanvas.drawPaint(mFadePaint);
|
||||||
@@ -198,7 +197,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
mFadeSteps++;
|
mFadeSteps++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onSizeChanged(int w, int h, int oldw,
|
@Override protected void onSizeChanged(int w, int h, int oldw,
|
||||||
int oldh) {
|
int oldh) {
|
||||||
int curW = mBitmap != null ? mBitmap.getWidth() : 0;
|
int curW = mBitmap != null ? mBitmap.getWidth() : 0;
|
||||||
@@ -206,10 +205,10 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
if (curW >= w && curH >= h) {
|
if (curW >= w && curH >= h) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curW < w) curW = w;
|
if (curW < w) curW = w;
|
||||||
if (curH < h) curH = h;
|
if (curH < h) curH = h;
|
||||||
|
|
||||||
Bitmap newBitmap = Bitmap.createBitmap(curW, curH,
|
Bitmap newBitmap = Bitmap.createBitmap(curW, curH,
|
||||||
Bitmap.Config.RGB_565);
|
Bitmap.Config.RGB_565);
|
||||||
Canvas newCanvas = new Canvas();
|
Canvas newCanvas = new Canvas();
|
||||||
@@ -221,7 +220,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
mCanvas = newCanvas;
|
mCanvas = newCanvas;
|
||||||
mFadeSteps = MAX_FADE_STEPS;
|
mFadeSteps = MAX_FADE_STEPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
if (mBitmap != null) {
|
if (mBitmap != null) {
|
||||||
canvas.drawBitmap(mBitmap, 0, 0, null);
|
canvas.drawBitmap(mBitmap, 0, 0, null);
|
||||||
@@ -252,7 +251,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
mCurDown = oldDown;
|
mCurDown = oldDown;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean onTouchEvent(MotionEvent event) {
|
@Override public boolean onTouchEvent(MotionEvent event) {
|
||||||
int action = event.getAction();
|
int action = event.getAction();
|
||||||
mCurDown = action == MotionEvent.ACTION_DOWN
|
mCurDown = action == MotionEvent.ACTION_DOWN
|
||||||
@@ -268,7 +267,7 @@ public class TouchPaint extends GraphicsActivity {
|
|||||||
event.getSize());
|
event.getSize());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawPoint(float x, float y, float pressure, float size) {
|
private void drawPoint(float x, float y, float pressure, float size) {
|
||||||
//Log.i("TouchPaint", "Drawing: " + x + "x" + y + " p="
|
//Log.i("TouchPaint", "Drawing: " + x + "x" + y + " p="
|
||||||
// + pressure + " s=" + size);
|
// + pressure + " s=" + size);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGL10;
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import java.nio.ByteOrder;
|
|||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.ShortBuffer;
|
import java.nio.ShortBuffer;
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGL10;
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,20 +28,20 @@ public class Typefaces extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
private Typeface mFace;
|
private Typeface mFace;
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mFace = Typeface.createFromAsset(getContext().getAssets(),
|
mFace = Typeface.createFromAsset(getContext().getAssets(),
|
||||||
"fonts/samplefont.ttf");
|
"fonts/samplefont.ttf");
|
||||||
|
|
||||||
mPaint.setTextSize(64);
|
mPaint.setTextSize(64);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -29,20 +28,20 @@ public class UnicodeChart extends GraphicsActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private Paint mBigCharPaint;
|
private Paint mBigCharPaint;
|
||||||
private Paint mLabelPaint;
|
private Paint mLabelPaint;
|
||||||
private final char[] mChars = new char[256];
|
private final char[] mChars = new char[256];
|
||||||
private final float[] mPos = new float[512];
|
private final float[] mPos = new float[512];
|
||||||
|
|
||||||
private int mBase;
|
private int mBase;
|
||||||
|
|
||||||
private static final int XMUL = 20;
|
private static final int XMUL = 20;
|
||||||
private static final int YMUL = 28;
|
private static final int YMUL = 28;
|
||||||
private static final int YBASE = 18;
|
private static final int YBASE = 18;
|
||||||
@@ -51,49 +50,49 @@ public class UnicodeChart extends GraphicsActivity {
|
|||||||
super(context);
|
super(context);
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
setFocusableInTouchMode(true);
|
setFocusableInTouchMode(true);
|
||||||
|
|
||||||
mBigCharPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mBigCharPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
mBigCharPaint.setTextSize(15);
|
mBigCharPaint.setTextSize(15);
|
||||||
mBigCharPaint.setTextAlign(Paint.Align.CENTER);
|
mBigCharPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
mLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
mLabelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
mLabelPaint.setTextSize(8);
|
mLabelPaint.setTextSize(8);
|
||||||
mLabelPaint.setTextAlign(Paint.Align.CENTER);
|
mLabelPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
// the position array is the same for all charts
|
// the position array is the same for all charts
|
||||||
float[] pos = mPos;
|
float[] pos = mPos;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int col = 0; col < 16; col++) {
|
for (int col = 0; col < 16; col++) {
|
||||||
final float x = col * 20 + 10;
|
final float x = col * XMUL + 10;
|
||||||
for (int row = 0; row < 16; row++) {
|
for (int row = 0; row < 16; row++) {
|
||||||
pos[index++] = x;
|
pos[index++] = x;
|
||||||
pos[index++] = row * YMUL + YBASE;
|
pos[index++] = row * YMUL + YBASE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float computeX(int index) {
|
private float computeX(int index) {
|
||||||
return (index >> 4) * 20 + 10;
|
return (index >> 4) * XMUL + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float computeY(int index) {
|
private float computeY(int index) {
|
||||||
return (index & 0xF) * YMUL + YMUL;
|
return (index & 0xF) * YMUL + YMUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawChart(Canvas canvas, int base) {
|
private void drawChart(Canvas canvas, int base) {
|
||||||
char[] chars = mChars;
|
char[] chars = mChars;
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
int unichar = base + i;
|
int unichar = base + i;
|
||||||
chars[i] = (char)unichar;
|
chars[i] = (char)unichar;
|
||||||
|
|
||||||
canvas.drawText(Integer.toHexString(unichar),
|
canvas.drawText(Integer.toHexString(unichar),
|
||||||
computeX(i), computeY(i), mLabelPaint);
|
computeX(i), computeY(i), mLabelPaint);
|
||||||
}
|
}
|
||||||
canvas.drawPosText(chars, 0, 256, mPos, mBigCharPaint);
|
canvas.drawPosText(chars, 0, 256, mPos, mBigCharPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
canvas.translate(0, 1);
|
canvas.translate(0, 1);
|
||||||
drawChart(canvas, mBase * 256);
|
drawChart(canvas, mBase * 256);
|
||||||
@@ -118,4 +117,3 @@ public class UnicodeChart extends GraphicsActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,17 +18,11 @@ package com.example.android.apis.graphics;
|
|||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
import android.graphics.drawable.*;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.KeyEvent;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class Vertices extends GraphicsActivity {
|
public class Vertices extends GraphicsActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,14 +30,13 @@ public class Vertices extends GraphicsActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private final Paint mPaint = new Paint();
|
private final Paint mPaint = new Paint();
|
||||||
private final float[] mVerts = new float[10];
|
private final float[] mVerts = new float[10];
|
||||||
private final float[] mTexs = new float[10];
|
private final float[] mTexs = new float[10];
|
||||||
private final int[] mColors = new int[10];
|
|
||||||
private final short[] mIndices = { 0, 1, 2, 3, 4, 1 };
|
private final short[] mIndices = { 0, 1, 2, 3, 4, 1 };
|
||||||
|
|
||||||
private final Matrix mMatrix = new Matrix();
|
private final Matrix mMatrix = new Matrix();
|
||||||
private final Matrix mInverse = new Matrix();
|
private final Matrix mInverse = new Matrix();
|
||||||
|
|
||||||
@@ -61,7 +54,7 @@ public class Vertices extends GraphicsActivity {
|
|||||||
Shader s = new BitmapShader(bm, Shader.TileMode.CLAMP,
|
Shader s = new BitmapShader(bm, Shader.TileMode.CLAMP,
|
||||||
Shader.TileMode.CLAMP);
|
Shader.TileMode.CLAMP);
|
||||||
mPaint.setShader(s);
|
mPaint.setShader(s);
|
||||||
|
|
||||||
float w = bm.getWidth();
|
float w = bm.getWidth();
|
||||||
float h = bm.getHeight();
|
float h = bm.getHeight();
|
||||||
// construct our mesh
|
// construct our mesh
|
||||||
@@ -70,18 +63,18 @@ public class Vertices extends GraphicsActivity {
|
|||||||
setXY(mTexs, 2, w, 0);
|
setXY(mTexs, 2, w, 0);
|
||||||
setXY(mTexs, 3, w, h);
|
setXY(mTexs, 3, w, h);
|
||||||
setXY(mTexs, 4, 0, h);
|
setXY(mTexs, 4, 0, h);
|
||||||
|
|
||||||
setXY(mVerts, 0, w/2, h/2);
|
setXY(mVerts, 0, w/2, h/2);
|
||||||
setXY(mVerts, 1, 0, 0);
|
setXY(mVerts, 1, 0, 0);
|
||||||
setXY(mVerts, 2, w, 0);
|
setXY(mVerts, 2, w, 0);
|
||||||
setXY(mVerts, 3, w, h);
|
setXY(mVerts, 3, w, h);
|
||||||
setXY(mVerts, 4, 0, h);
|
setXY(mVerts, 4, 0, h);
|
||||||
|
|
||||||
mMatrix.setScale(0.8f, 0.8f);
|
mMatrix.setScale(0.8f, 0.8f);
|
||||||
mMatrix.preTranslate(20, 20);
|
mMatrix.preTranslate(20, 20);
|
||||||
mMatrix.invert(mInverse);
|
mMatrix.invert(mInverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(0xFFCCCCCC);
|
canvas.drawColor(0xFFCCCCCC);
|
||||||
canvas.save();
|
canvas.save();
|
||||||
@@ -104,7 +97,7 @@ public class Vertices extends GraphicsActivity {
|
|||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.example.android.apis.graphics;
|
package com.example.android.apis.graphics;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
@@ -33,35 +32,35 @@ import android.os.Bundle;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class Xfermodes extends GraphicsActivity {
|
public class Xfermodes extends GraphicsActivity {
|
||||||
|
|
||||||
// create a bitmap with a circle, used for the "dst" image
|
// create a bitmap with a circle, used for the "dst" image
|
||||||
static Bitmap makeDst(int w, int h) {
|
static Bitmap makeDst(int w, int h) {
|
||||||
Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
||||||
Canvas c = new Canvas(bm);
|
Canvas c = new Canvas(bm);
|
||||||
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
|
||||||
p.setColor(0xFFFFCC44);
|
p.setColor(0xFFFFCC44);
|
||||||
c.drawOval(new RectF(0, 0, w*3/4, h*3/4), p);
|
c.drawOval(new RectF(0, 0, w*3/4, h*3/4), p);
|
||||||
return bm;
|
return bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a bitmap with a rect, used for the "src" image
|
// create a bitmap with a rect, used for the "src" image
|
||||||
static Bitmap makeSrc(int w, int h) {
|
static Bitmap makeSrc(int w, int h) {
|
||||||
Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
||||||
Canvas c = new Canvas(bm);
|
Canvas c = new Canvas(bm);
|
||||||
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
|
|
||||||
p.setColor(0xFF66AAFF);
|
p.setColor(0xFF66AAFF);
|
||||||
c.drawRect(w/3, h/3, w*19/20, h*19/20, p);
|
c.drawRect(w/3, h/3, w*19/20, h*19/20, p);
|
||||||
return bm;
|
return bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(new SampleView(this));
|
setContentView(new SampleView(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SampleView extends View {
|
private static class SampleView extends View {
|
||||||
private static final int W = 64;
|
private static final int W = 64;
|
||||||
private static final int H = 64;
|
private static final int H = 64;
|
||||||
@@ -70,7 +69,7 @@ public class Xfermodes extends GraphicsActivity {
|
|||||||
private Bitmap mSrcB;
|
private Bitmap mSrcB;
|
||||||
private Bitmap mDstB;
|
private Bitmap mDstB;
|
||||||
private Shader mBG; // background checker-board pattern
|
private Shader mBG; // background checker-board pattern
|
||||||
|
|
||||||
private static final Xfermode[] sModes = {
|
private static final Xfermode[] sModes = {
|
||||||
new PorterDuffXfermode(PorterDuff.Mode.CLEAR),
|
new PorterDuffXfermode(PorterDuff.Mode.CLEAR),
|
||||||
new PorterDuffXfermode(PorterDuff.Mode.SRC),
|
new PorterDuffXfermode(PorterDuff.Mode.SRC),
|
||||||
@@ -89,20 +88,20 @@ public class Xfermodes extends GraphicsActivity {
|
|||||||
new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY),
|
new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY),
|
||||||
new PorterDuffXfermode(PorterDuff.Mode.SCREEN)
|
new PorterDuffXfermode(PorterDuff.Mode.SCREEN)
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] sLabels = {
|
private static final String[] sLabels = {
|
||||||
"Clear", "Src", "Dst", "SrcOver",
|
"Clear", "Src", "Dst", "SrcOver",
|
||||||
"DstOver", "SrcIn", "DstIn", "SrcOut",
|
"DstOver", "SrcIn", "DstIn", "SrcOut",
|
||||||
"DstOut", "SrcATop", "DstATop", "Xor",
|
"DstOut", "SrcATop", "DstATop", "Xor",
|
||||||
"Darken", "Lighten", "Multiply", "Screen"
|
"Darken", "Lighten", "Multiply", "Screen"
|
||||||
};
|
};
|
||||||
|
|
||||||
public SampleView(Context context) {
|
public SampleView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mSrcB = makeSrc(W, H);
|
mSrcB = makeSrc(W, H);
|
||||||
mDstB = makeDst(W, H);
|
mDstB = makeDst(W, H);
|
||||||
|
|
||||||
// make a ckeckerboard pattern
|
// make a ckeckerboard pattern
|
||||||
Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
|
Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
|
||||||
0xFFCCCCCC, 0xFFFFFFFF }, 2, 2,
|
0xFFCCCCCC, 0xFFFFFFFF }, 2, 2,
|
||||||
@@ -114,18 +113,18 @@ public class Xfermodes extends GraphicsActivity {
|
|||||||
m.setScale(6, 6);
|
m.setScale(6, 6);
|
||||||
mBG.setLocalMatrix(m);
|
mBG.setLocalMatrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onDraw(Canvas canvas) {
|
@Override protected void onDraw(Canvas canvas) {
|
||||||
canvas.drawColor(Color.WHITE);
|
canvas.drawColor(Color.WHITE);
|
||||||
|
|
||||||
Paint labelP = new Paint(Paint.ANTI_ALIAS_FLAG);
|
Paint labelP = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||||
labelP.setTextAlign(Paint.Align.CENTER);
|
labelP.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
paint.setFilterBitmap(false);
|
paint.setFilterBitmap(false);
|
||||||
|
|
||||||
canvas.translate(15, 35);
|
canvas.translate(15, 35);
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 0;
|
int y = 0;
|
||||||
for (int i = 0; i < sModes.length; i++) {
|
for (int i = 0; i < sModes.length; i++) {
|
||||||
@@ -134,12 +133,12 @@ public class Xfermodes extends GraphicsActivity {
|
|||||||
paint.setShader(null);
|
paint.setShader(null);
|
||||||
canvas.drawRect(x - 0.5f, y - 0.5f,
|
canvas.drawRect(x - 0.5f, y - 0.5f,
|
||||||
x + W + 0.5f, y + H + 0.5f, paint);
|
x + W + 0.5f, y + H + 0.5f, paint);
|
||||||
|
|
||||||
// draw the checker-board pattern
|
// draw the checker-board pattern
|
||||||
paint.setStyle(Paint.Style.FILL);
|
paint.setStyle(Paint.Style.FILL);
|
||||||
paint.setShader(mBG);
|
paint.setShader(mBG);
|
||||||
canvas.drawRect(x, y, x + W, y + H, paint);
|
canvas.drawRect(x, y, x + W, y + H, paint);
|
||||||
|
|
||||||
// draw the src/dst example into our offscreen bitmap
|
// draw the src/dst example into our offscreen bitmap
|
||||||
int sc = canvas.saveLayer(x, y, x + W, y + H, null,
|
int sc = canvas.saveLayer(x, y, x + W, y + H, null,
|
||||||
Canvas.MATRIX_SAVE_FLAG |
|
Canvas.MATRIX_SAVE_FLAG |
|
||||||
@@ -153,13 +152,13 @@ public class Xfermodes extends GraphicsActivity {
|
|||||||
canvas.drawBitmap(mSrcB, 0, 0, paint);
|
canvas.drawBitmap(mSrcB, 0, 0, paint);
|
||||||
paint.setXfermode(null);
|
paint.setXfermode(null);
|
||||||
canvas.restoreToCount(sc);
|
canvas.restoreToCount(sc);
|
||||||
|
|
||||||
// draw the label
|
// draw the label
|
||||||
canvas.drawText(sLabels[i],
|
canvas.drawText(sLabels[i],
|
||||||
x + W/2, y - labelP.getTextSize()/2, labelP);
|
x + W/2, y - labelP.getTextSize()/2, labelP);
|
||||||
|
|
||||||
x += W + 10;
|
x += W + 10;
|
||||||
|
|
||||||
// wrap around when we've drawn enough for one row
|
// wrap around when we've drawn enough for one row
|
||||||
if ((i % ROW_MAX) == ROW_MAX - 1) {
|
if ((i % ROW_MAX) == ROW_MAX - 1) {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class Animation2 extends Activity implements
|
|||||||
s.setOnItemSelectedListener(this);
|
s.setOnItemSelectedListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemSelected(AdapterView parent, View v, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
|
||||||
switch (position) {
|
switch (position) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
@@ -79,7 +79,7 @@ public class Animation2 extends Activity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNothingSelected(AdapterView parent) {
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] mStrings = {
|
private String[] mStrings = {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class Animation3 extends Activity implements AdapterView.OnItemSelectedLi
|
|||||||
s.setOnItemSelectedListener(this);
|
s.setOnItemSelectedListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemSelected(AdapterView parent, View v, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
|
||||||
final View target = findViewById(R.id.target);
|
final View target = findViewById(R.id.target);
|
||||||
final View targetParent = (View) target.getParent();
|
final View targetParent = (View) target.getParent();
|
||||||
|
|
||||||
@@ -96,6 +96,6 @@ public class Animation3 extends Activity implements AdapterView.OnItemSelectedLi
|
|||||||
target.startAnimation(a);
|
target.startAnimation(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNothingSelected(AdapterView parent) {
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,9 @@ package com.example.android.apis.view;
|
|||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
|
|
||||||
public class AutoComplete1 extends Activity {
|
public class AutoComplete1 extends Activity {
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,9 @@ package com.example.android.apis.view;
|
|||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.MultiAutoCompleteTextView;
|
import android.widget.MultiAutoCompleteTextView;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
|
|
||||||
public class AutoComplete6 extends Activity {
|
public class AutoComplete6 extends Activity {
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ import com.example.android.apis.R;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A gallery of the different styles of buttons.
|
* A gallery of the different styles of buttons.
|
||||||
|
|||||||
@@ -20,12 +20,10 @@ import com.example.android.apis.R;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demonstrates the use of non-focusable views.
|
* Demonstrates the use of non-focusable views.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class Gallery1 extends Activity {
|
|||||||
|
|
||||||
// Set a item click listener, and just Toast the clicked position
|
// Set a item click listener, and just Toast the clicked position
|
||||||
g.setOnItemClickListener(new OnItemClickListener() {
|
g.setOnItemClickListener(new OnItemClickListener() {
|
||||||
public void onItemClick(AdapterView parent, View v, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||||
Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show();
|
Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -56,11 +56,11 @@ public class ImageSwitcher1 extends Activity implements
|
|||||||
g.setOnItemSelectedListener(this);
|
g.setOnItemSelectedListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemSelected(AdapterView parent, View v, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
|
||||||
mSwitcher.setImageResource(mImageIds[position]);
|
mSwitcher.setImageResource(mImageIds[position]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onNothingSelected(AdapterView parent) {
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public View makeView() {
|
public View makeView() {
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public class List13 extends ListActivity implements ListView.OnScrollListener {
|
|||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
|
|
||||||
public SlowAdapter(Context context) {
|
public SlowAdapter(Context context) {
|
||||||
mContext = context;
|
|
||||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,11 +113,6 @@ public class List13 extends ListActivity implements ListView.OnScrollListener {
|
|||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remember our context so we can use it when constructing views.
|
|
||||||
*/
|
|
||||||
private Context mContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -111,8 +111,8 @@ public class List9 extends ListActivity implements ListView.OnScrollListener {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
public void onScroll(AbsListView view, int firstVisibleItem,
|
||||||
int lastItem = firstVisibleItem + visibleItemCount - 1;
|
int visibleItemCount, int totalItemCount) {
|
||||||
if (mReady) {
|
if (mReady) {
|
||||||
char firstLetter = mStrings[firstVisibleItem].charAt(0);
|
char firstLetter = mStrings[firstVisibleItem].charAt(0);
|
||||||
|
|
||||||
@@ -120,8 +120,6 @@ public class List9 extends ListActivity implements ListView.OnScrollListener {
|
|||||||
|
|
||||||
mShowing = true;
|
mShowing = true;
|
||||||
mDialogText.setVisibility(View.VISIBLE);
|
mDialogText.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
mDialogText.setText(((Character)firstLetter).toString());
|
mDialogText.setText(((Character)firstLetter).toString());
|
||||||
mHandler.removeCallbacks(mRemoveWindow);
|
mHandler.removeCallbacks(mRemoveWindow);
|
||||||
@@ -316,5 +314,4 @@ public class List9 extends ListActivity implements ListView.OnScrollListener {
|
|||||||
"Woodside Cabecou", "Xanadu", "Xynotyro", "Yarg Cornish",
|
"Woodside Cabecou", "Xanadu", "Xynotyro", "Yarg Cornish",
|
||||||
"Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano",
|
"Yarra Valley Pyramid", "Yorkshire Blue", "Zamorano",
|
||||||
"Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"};
|
"Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.example.android.apis.view;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.RatingBar;
|
import android.widget.RatingBar;
|
||||||
import android.widget.SeekBar;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Demonstrates wrapping a layout in a ScrollView.
|
* Demonstrates wrapping a layout in a ScrollView.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -19,15 +19,9 @@ package com.example.android.apis.view;
|
|||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.widget.TableLayout;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
|
|
||||||
public class TableLayout10 extends Activity {
|
public class TableLayout10 extends Activity {
|
||||||
private boolean mShrink;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ import android.os.Bundle;
|
|||||||
* <p>This example shows how to use horizontal gravity in a table layout.</p>
|
* <p>This example shows how to use horizontal gravity in a table layout.</p>
|
||||||
*/
|
*/
|
||||||
public class TableLayout11 extends Activity {
|
public class TableLayout11 extends Activity {
|
||||||
private boolean mShrink;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ import android.os.Bundle;
|
|||||||
* <p>This example shows how to use cell spanning in a table layout.</p>
|
* <p>This example shows how to use cell spanning in a table layout.</p>
|
||||||
*/
|
*/
|
||||||
public class TableLayout12 extends Activity {
|
public class TableLayout12 extends Activity {
|
||||||
private boolean mShrink;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.os.Bundle;
|
|||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user