diff options
Diffstat (limited to 'carousel/test/src')
4 files changed, 0 insertions, 646 deletions
diff --git a/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java b/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java deleted file mode 100644 index 18adc5e..0000000 --- a/carousel/test/src/com/android/carouseltest/CarouselTestActivity.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.carouseltest; - -import com.android.ex.carousel.CarouselView; -import com.android.ex.carousel.CarouselViewHelper; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.Rect; -import android.os.Bundle; -import android.util.Log; - -public class CarouselTestActivity extends Activity { - private static final String TAG = "CarouselTestActivity"; - private static final int CARD_SLOTS = 56; - private static final int TOTAL_CARDS = 100; - private static final int TEXTURE_HEIGHT = 256; - private static final int TEXTURE_WIDTH = 256; - private static final int SLOTS_VISIBLE = 7; - - protected static final boolean DBG = false; - private static final int DETAIL_TEXTURE_WIDTH = 200; - private static final int DETAIL_TEXTURE_HEIGHT = 80; - private static final int VISIBLE_DETAIL_COUNT = 3; - private static boolean INCREMENTAL_ADD = false; // To debug incrementally adding cards - private CarouselView mView; - private Paint mPaint = new Paint(); - private CarouselViewHelper mHelper; - private Bitmap mGlossyOverlay; - private Bitmap mBorder; - - class LocalCarouselViewHelper extends CarouselViewHelper { - private static final int PIXEL_BORDER = 3; - private DetailTextureParameters mDetailTextureParameters - = new DetailTextureParameters(5.0f, 5.0f, 3.0f, 10.0f); - - LocalCarouselViewHelper(Context context) { - super(context); - } - - @Override - public void onCardSelected(final int id) { - postMessage("Selection", "Card " + id + " was selected"); - } - - @Override - public void onDetailSelected(final int id, int x, int y) { - postMessage("Selection", "Detail for card " + id + " was selected"); - } - - @Override - public void onCardLongPress(int n, int touchPosition[], Rect detailCoordinates) { - postMessage("Selection", "Long press on card " + n); - } - - @Override - public DetailTextureParameters getDetailTextureParameters(int id) { - return mDetailTextureParameters; - } - - @Override - public Bitmap getTexture(int n) { - Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, - Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - canvas.drawARGB(0, 0, 0, 0); - mPaint.setColor(0x40808080); - canvas.drawRect(2, 2, TEXTURE_WIDTH-2, TEXTURE_HEIGHT-2, mPaint); - mPaint.setTextSize(100.0f); - mPaint.setAntiAlias(true); - mPaint.setColor(0xffffffff); - canvas.drawText("" + n, 2, TEXTURE_HEIGHT-10, mPaint); - canvas.drawBitmap(mGlossyOverlay, null, - new Rect(PIXEL_BORDER, PIXEL_BORDER, - TEXTURE_WIDTH - PIXEL_BORDER, TEXTURE_HEIGHT - PIXEL_BORDER), mPaint); - return bitmap; - } - - @Override - public Bitmap getDetailTexture(int n) { - Bitmap bitmap = Bitmap.createBitmap(DETAIL_TEXTURE_WIDTH, DETAIL_TEXTURE_HEIGHT, - Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - canvas.drawARGB(32, 10, 10, 10); - mPaint.setTextSize(15.0f); - mPaint.setAntiAlias(true); - canvas.drawText("Detail text for card " + n, 0, DETAIL_TEXTURE_HEIGHT/2, mPaint); - return bitmap; - } - }; - - @Override - public CharSequence onCreateDescription() { - return getText(R.string.carousel_test_activity_description); - } - - private Runnable mAddCardRunnable = new Runnable() { - public void run() { - if (mView.getCardCount() < TOTAL_CARDS) { - mView.createCards(mView.getCardCount() + 1); - mView.postDelayed(mAddCardRunnable, 2000); - } - } - }; - - void postMessage(final CharSequence title, final CharSequence msg) { - runOnUiThread(new Runnable() { - public void run() { - new AlertDialog.Builder(CarouselTestActivity.this) - .setTitle(title) - .setMessage(msg) - .setPositiveButton("OK", null) - .create() - .show(); - } - }); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.carousel_test); - mView = (CarouselView) findViewById(R.id.carousel); - mView.getHolder().setFormat(PixelFormat.RGBA_8888); - mPaint.setColor(0xffffffff); - final Resources res = getResources(); - - mHelper = new LocalCarouselViewHelper(this); - mHelper.setCarouselView(mView); - mView.setSlotCount(CARD_SLOTS); - mView.createCards(INCREMENTAL_ADD ? 1: TOTAL_CARDS); - mView.setVisibleSlots(SLOTS_VISIBLE); - mView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS)); - mBorder = BitmapFactory.decodeResource(res, R.drawable.border); - mView.setDefaultBitmap(mBorder); - mView.setLoadingBitmap(mBorder); - mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 0.5f); - mView.setRezInCardCount(3.0f); - mView.setFadeInDuration(250); - mView.setVisibleDetails(VISIBLE_DETAIL_COUNT); - mView.setDragModel(CarouselView.DRAG_MODEL_PLANE); - if (INCREMENTAL_ADD) { - mView.postDelayed(mAddCardRunnable, 2000); - } - - mGlossyOverlay = BitmapFactory.decodeResource(res, R.drawable.glossy_overlay); - } - - @Override - protected void onResume() { - super.onResume(); - mHelper.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mHelper.onPause(); - } - -} diff --git a/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java b/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java deleted file mode 100644 index 0ed4993..0000000 --- a/carousel/test/src/com/android/carouseltest/MusicDemoActivity.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.carouseltest; - -import com.android.ex.carousel.CarouselView; -import com.android.ex.carousel.CarouselViewHelper; - -import android.app.Activity; -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.util.Log; - -public class MusicDemoActivity extends Activity { - private static final String TAG = "MusicDemoActivity"; - private static final int CD_GEOMETRY = R.raw.book; - private static final int VISIBLE_SLOTS = 7; - private static final int CARD_SLOTS = 56; - private static final int TOTAL_CARDS = 10000; - private CarouselView mView; - private int mImageResources[] = { - R.drawable.emo_im_angel, - R.drawable.emo_im_cool, - R.drawable.emo_im_crying, - R.drawable.emo_im_foot_in_mouth, - R.drawable.emo_im_happy, - R.drawable.emo_im_kissing, - R.drawable.emo_im_laughing, - R.drawable.emo_im_lips_are_sealed, - R.drawable.emo_im_money_mouth, - R.drawable.emo_im_sad, - R.drawable.emo_im_surprised, - R.drawable.emo_im_tongue_sticking_out, - R.drawable.emo_im_undecided, - R.drawable.emo_im_winking, - R.drawable.emo_im_wtf, - R.drawable.emo_im_yelling - }; - - private LocalCarouselViewHelper mHelper; - - class LocalCarouselViewHelper extends CarouselViewHelper { - - LocalCarouselViewHelper(Context context) { - super(context); - } - - @Override - public void onCardSelected(int id) { - Log.v(TAG, "Yay, item " + id + " was selected!"); - } - - @Override - public Bitmap getTexture(int n) { - return BitmapFactory.decodeResource(getResources(), - mImageResources[n % mImageResources.length]); - } - - @Override - public Bitmap getDetailTexture(int n) { - return null; - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - final Resources res = getResources(); - setContentView(R.layout.music_demo); - mView = (CarouselView) findViewById(R.id.carousel); - mHelper = new LocalCarouselViewHelper(this); - mHelper.setCarouselView(mView); - mView.setSlotCount(CARD_SLOTS); - mView.createCards(TOTAL_CARDS); - mView.setVisibleSlots(VISIBLE_SLOTS); - mView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS)); - mView.setDefaultBitmap(BitmapFactory.decodeResource(res, R.drawable.wait)); - mView.setLoadingBitmap(BitmapFactory.decodeResource(res, R.drawable.blank_album)); - mView.setBackgroundBitmap(BitmapFactory.decodeResource(res, R.drawable.background)); - mView.setDefaultGeometry(CD_GEOMETRY); - mView.setFadeInDuration(250); - mView.setRezInCardCount(3.0f); - mView.setForceBlendCardsWithZ(false); - } - - @Override - protected void onResume() { - super.onResume(); - mHelper.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - mHelper.onPause(); - } -} diff --git a/carousel/test/src/com/android/carouseltest/MyCarouselView.java b/carousel/test/src/com/android/carouseltest/MyCarouselView.java deleted file mode 100644 index 973a9bc..0000000 --- a/carousel/test/src/com/android/carouseltest/MyCarouselView.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.carouseltest; - -import android.content.Context; -import android.util.AttributeSet; - -import com.android.ex.carousel.CarouselController; -import com.android.ex.carousel.CarouselView; -import com.android.ex.carousel.CarouselView.Info; - -public class MyCarouselView extends CarouselView { - - public MyCarouselView(Context context, CarouselController controller) { - this(context, null, controller); - } - - public MyCarouselView(Context context, AttributeSet attrs) { - this(context, attrs, new CarouselController()); - } - - public MyCarouselView(Context context, AttributeSet attrs, CarouselController controller) { - super(context, attrs, controller); - } - - public Info getRenderScriptInfo() { - return new Info(R.raw.carousel); - } - - @Override - public boolean interpretLongPressEvents() { - return true; - } - -} diff --git a/carousel/test/src/com/android/carouseltest/TaskSwitcherActivity.java b/carousel/test/src/com/android/carouseltest/TaskSwitcherActivity.java deleted file mode 100644 index 0a76ecc..0000000 --- a/carousel/test/src/com/android/carouseltest/TaskSwitcherActivity.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package com.android.carouseltest; - -import java.util.ArrayList; -import java.util.List; -import com.android.carouseltest.R; - -import com.android.ex.carousel.CarouselController; -import com.android.ex.carousel.CarouselViewHelper; - -import android.app.Activity; -import android.app.ActivityManager; -import android.app.IThumbnailReceiver; -import android.app.ActivityManager.RunningTaskInfo; -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ActivityInfo; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.Bitmap.Config; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.os.RemoteException; -import android.util.Log; -import android.view.View; - -public class TaskSwitcherActivity extends Activity { - private static final String TAG = "TaskSwitcherActivity"; - private static final int CARD_SLOTS = 56; - private static final int MAX_TASKS = 20; - private static final int VISIBLE_SLOTS = 7; - protected static final boolean DBG = false; - private ActivityManager mActivityManager; - private List<RunningTaskInfo> mRunningTaskList; - private boolean mPortraitMode = true; - private ArrayList<ActivityDescription> mActivityDescriptions - = new ArrayList<ActivityDescription>(); - private CarouselController mController; - private MyCarouselView mView; - private Bitmap mBlankBitmap = Bitmap.createBitmap(128, 128, Config.RGB_565); - private LocalCarouselViewHelper mHelper; - - static class ActivityDescription { - int id; - Bitmap thumbnail; - Drawable icon; - CharSequence label; - CharSequence description; - Intent intent; - Matrix matrix; - - public ActivityDescription(Bitmap _thumbnail, - Drawable _icon, String _label, String _desc, int _id) - { - thumbnail = _thumbnail; - icon = _icon; - label = _label; - description = _desc; - id = _id; - } - - public void clear() { - icon = null; - thumbnail = null; - label = null; - description = null; - intent = null; - matrix = null; - id = -1; - } - }; - - private ActivityDescription findActivityDescription(int id) { - for (int i = 0; i < mActivityDescriptions.size(); i++) { - ActivityDescription item = mActivityDescriptions.get(i); - if (item != null && item.id == id) { - return item; - } - } - return null; - } - - class LocalCarouselViewHelper extends CarouselViewHelper { - private static final int DETAIL_TEXTURE_WIDTH = 256; - private static final int DETAIL_TEXTURE_HEIGHT = 80; - private Paint mPaint = new Paint(); - private DetailTextureParameters mDetailTextureParameters - = new DetailTextureParameters(5.0f, 5.0f); - - public LocalCarouselViewHelper(Context context) { - super(context); - } - - @Override - public DetailTextureParameters getDetailTextureParameters(int id) { - return mDetailTextureParameters; - } - - @Override - public void onCardSelected(int n) { - if (n < mActivityDescriptions.size()) { - ActivityDescription item = mActivityDescriptions.get(n); - // prepare a launch intent and send it - if (item.intent != null) { - item.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); - try { - Log.v(TAG, "Starting intent " + item.intent); - startActivity(item.intent); - overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit); - } catch (ActivityNotFoundException e) { - Log.w("Recent", "Unable to launch recent task", e); - } - finish(); - } - } - } - - @Override - public Bitmap getTexture(int n) { - ActivityDescription desc = mActivityDescriptions.get(n); - Bitmap bitmap = desc.thumbnail == null ? mBlankBitmap : desc.thumbnail; - return bitmap; - } - - @Override - public Bitmap getDetailTexture(int n) { - Bitmap bitmap = null; - if (n < mActivityDescriptions.size()) { - ActivityDescription item = mActivityDescriptions.get(n); - bitmap = Bitmap.createBitmap(DETAIL_TEXTURE_WIDTH, DETAIL_TEXTURE_HEIGHT, - Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - canvas.drawARGB(128,128,128,255); - mPaint.setTextSize(15.0f); - mPaint.setColor(0xffffffff); - mPaint.setAntiAlias(true); - canvas.drawText(item.label.toString(),0, DETAIL_TEXTURE_HEIGHT/2, mPaint); - } - return bitmap; - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - final Resources res = getResources(); - final View decorView = getWindow().getDecorView(); - - mController = new CarouselController(); - mView = new MyCarouselView(this, mController); - mHelper = new LocalCarouselViewHelper(this); - mHelper.setCarouselView(mView); - mView.setSlotCount(CARD_SLOTS); - mView.setVisibleSlots(VISIBLE_SLOTS); - mView.createCards(1); - mView.setStartAngle((float) -(2.0f*Math.PI * 5 / CARD_SLOTS)); - mView.setDefaultBitmap(BitmapFactory.decodeResource(res, R.drawable.wait)); - mView.setLoadingBitmap(BitmapFactory.decodeResource(res, R.drawable.wait)); - mView.setBackgroundColor(0.1f, 0.1f, 0.1f, 1.0f); - - mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); - mPortraitMode = decorView.getHeight() > decorView.getWidth(); - - refresh(); - setContentView(mView); - } - - @Override - protected void onResume() { - super.onResume(); - mHelper.onResume(); - refresh(); - } - - @Override - protected void onPause() { - super.onPause(); - mHelper.onPause(); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - mPortraitMode = newConfig.orientation == Configuration.ORIENTATION_PORTRAIT; - Log.v(TAG, "CONFIG CHANGE, mPortraitMode = " + mPortraitMode); - refresh(); - } - - void updateRunningTasks() { - mRunningTaskList = mActivityManager.getRunningTasks(MAX_TASKS + 2); - Log.v(TAG, "Portrait: " + mPortraitMode); - for (RunningTaskInfo r : mRunningTaskList) { - if (r.thumbnail != null) { - int thumbWidth = r.thumbnail.getWidth(); - int thumbHeight = r.thumbnail.getHeight(); - Log.v(TAG, "Got thumbnail " + thumbWidth + "x" + thumbHeight); - ActivityDescription desc = findActivityDescription(r.id); - if (desc != null) { - desc.thumbnail = r.thumbnail; - desc.description = r.description; - if ((mPortraitMode && thumbWidth > thumbHeight) - || (!mPortraitMode && thumbWidth < thumbHeight)) { - Matrix matrix = new Matrix(); - matrix.setRotate(90.0f, (float) thumbWidth / 2, (float) thumbHeight / 2); - desc.matrix = matrix; - } - } else { - Log.v(TAG, "Couldn't find ActivityDesc for id=" + r.id); - } - } else { - Log.v(TAG, "*** RUNNING THUMBNAIL WAS NULL ***"); - } - } - // HACK refresh carousel - mView.createCards(mActivityDescriptions.size()); - } - - private void updateRecentTasks() { - final PackageManager pm = getPackageManager(); - final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); - - final List<ActivityManager.RecentTaskInfo> recentTasks = - am.getRecentTasks(MAX_TASKS + 2, ActivityManager.RECENT_IGNORE_UNAVAILABLE); - - ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME) - .resolveActivityInfo(pm, 0); - - //IconUtilities iconUtilities = new IconUtilities(this); - - int numTasks = recentTasks.size(); - mActivityDescriptions.clear(); - for (int i = 1, index = 0; i < numTasks && (index < MAX_TASKS + 2); ++i) { - final ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(i); - - Intent intent = new Intent(recentInfo.baseIntent); - if (recentInfo.origActivity != null) { - intent.setComponent(recentInfo.origActivity); - } - - // Skip the current home activity. - if (homeInfo != null - && homeInfo.packageName.equals(intent.getComponent().getPackageName()) - && homeInfo.name.equals(intent.getComponent().getClassName())) { - continue; - } - - intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) - | Intent.FLAG_ACTIVITY_NEW_TASK); - final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); - if (resolveInfo != null) { - final ActivityInfo info = resolveInfo.activityInfo; - final String title = info.loadLabel(pm).toString(); - Drawable icon = info.loadIcon(pm); - - int id = recentInfo.id; - if (id != -1 && title != null && title.length() > 0 && icon != null) { - //icon = iconUtilities.createIconDrawable(icon); - ActivityDescription item = new ActivityDescription(null, icon, title, null, id); - item.intent = intent; - mActivityDescriptions.add(item); - Log.v(TAG, "Added item[" + index + "], id=" + item.id); - ++index; - } else { - Log.v(TAG, "SKIPPING item " + id); - } - } - } - } - - private void refresh() { - updateRecentTasks(); - updateRunningTasks(); - mView.createCards(mActivityDescriptions.size()); - } -} |