ActivityTestMain.java revision f26fd99a7c2f554b0297760bb66336473c7db61f
1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.android.test.activity; 18 19import java.util.ArrayList; 20import java.util.List; 21 22import android.app.Activity; 23import android.app.ActivityManager; 24import android.app.ActivityThread; 25import android.app.Application; 26import android.os.Bundle; 27import android.graphics.BitmapFactory; 28import android.graphics.Bitmap; 29import android.graphics.Canvas; 30import android.graphics.drawable.BitmapDrawable; 31import android.graphics.drawable.Drawable; 32import android.widget.ImageView; 33import android.widget.LinearLayout; 34import android.widget.TextView; 35import android.widget.ScrollView; 36import android.view.LayoutInflater; 37import android.view.View; 38import android.content.Context; 39import android.content.pm.ApplicationInfo; 40import android.content.pm.PackageManager; 41import android.content.res.CompatibilityInfo; 42import android.util.DisplayMetrics; 43import android.util.Log; 44 45public class ActivityTestMain extends Activity { 46 private void addThumbnail(LinearLayout container, Bitmap bm) { 47 ImageView iv = new ImageView(this); 48 if (bm != null) { 49 iv.setImageBitmap(bm); 50 } 51 iv.setBackgroundResource(android.R.drawable.gallery_thumb); 52 int w = getResources().getDimensionPixelSize(android.R.dimen.thumbnail_width); 53 int h = getResources().getDimensionPixelSize(android.R.dimen.thumbnail_height); 54 container.addView(iv, new LinearLayout.LayoutParams(w, h)); 55 } 56 57 @Override 58 protected void onCreate(Bundle savedInstanceState) { 59 super.onCreate(savedInstanceState); 60 61 ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE); 62 63 LinearLayout top = new LinearLayout(this); 64 top.setOrientation(LinearLayout.VERTICAL); 65 66 List<ActivityManager.RecentTaskInfo> recents = am.getRecentTasks(10, 67 ActivityManager.RECENT_WITH_EXCLUDED); 68 if (recents != null) { 69 for (int i=0; i<recents.size(); i++) { 70 ActivityManager.RecentTaskInfo r = recents.get(i); 71 ActivityManager.TaskThumbnails tt = r != null 72 ? am.getTaskThumbnails(r.persistentId) : null; 73 TextView tv = new TextView(this); 74 tv.setText(r.baseIntent.getComponent().flattenToShortString()); 75 top.addView(tv, new LinearLayout.LayoutParams( 76 LinearLayout.LayoutParams.WRAP_CONTENT, 77 LinearLayout.LayoutParams.WRAP_CONTENT)); 78 LinearLayout item = new LinearLayout(this); 79 item.setOrientation(LinearLayout.HORIZONTAL); 80 addThumbnail(item, tt != null ? tt.mainThumbnail : null); 81 for (int j=0; j<tt.numSubThumbbails; j++) { 82 addThumbnail(item, tt.getSubThumbnail(j)); 83 } 84 top.addView(item, new LinearLayout.LayoutParams( 85 LinearLayout.LayoutParams.WRAP_CONTENT, 86 LinearLayout.LayoutParams.WRAP_CONTENT)); 87 } 88 } 89 90 setContentView(scrollWrap(top)); 91 } 92 93 private View scrollWrap(View view) { 94 ScrollView scroller = new ScrollView(this); 95 scroller.addView(view, new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, 96 ScrollView.LayoutParams.MATCH_PARENT)); 97 return scroller; 98 } 99} 100