ActivityTestMain.java revision c7b57b1e65b487defad4967cf42cf076b499cbee
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.ActivityOptions; 25import android.app.AlarmManager; 26import android.app.AlertDialog; 27import android.app.PendingIntent; 28import android.content.ActivityNotFoundException; 29import android.content.BroadcastReceiver; 30import android.content.ComponentName; 31import android.content.ContentProviderClient; 32import android.content.Intent; 33import android.content.ServiceConnection; 34import android.graphics.BitmapFactory; 35import android.net.Uri; 36import android.os.Bundle; 37import android.os.Handler; 38import android.os.IBinder; 39import android.os.Message; 40import android.os.PowerManager; 41import android.os.RemoteException; 42import android.os.SystemClock; 43import android.os.UserHandle; 44import android.os.UserManager; 45import android.graphics.Bitmap; 46import android.provider.Settings; 47import android.widget.ImageView; 48import android.widget.LinearLayout; 49import android.widget.TextView; 50import android.widget.ScrollView; 51import android.widget.Toast; 52import android.view.Menu; 53import android.view.MenuItem; 54import android.view.View; 55import android.content.Context; 56import android.content.pm.UserInfo; 57import android.content.res.Configuration; 58import android.util.Log; 59 60public class ActivityTestMain extends Activity { 61 static final String TAG = "ActivityTest"; 62 63 static final String KEY_CONFIGURATION = "configuration"; 64 65 ActivityManager mAm; 66 PowerManager mPower; 67 AlarmManager mAlarm; 68 Configuration mOverrideConfig; 69 int mSecondUser; 70 71 ArrayList<ServiceConnection> mConnections = new ArrayList<ServiceConnection>(); 72 73 ServiceConnection mIsolatedConnection; 74 75 static final int MSG_SPAM = 1; 76 static final int MSG_SPAM_ALARM = 2; 77 78 final Handler mHandler = new Handler() { 79 @Override 80 public void handleMessage(Message msg) { 81 switch (msg.what) { 82 case MSG_SPAM: { 83 boolean fg = msg.arg1 != 0; 84 Intent intent = new Intent(ActivityTestMain.this, SpamActivity.class); 85 Bundle options = null; 86 if (fg) { 87 ActivityOptions opts = ActivityOptions.makeTaskLaunchBehind(); 88 options = opts.toBundle(); 89 } 90 startActivity(intent, options); 91 scheduleSpam(!fg); 92 } break; 93 case MSG_SPAM_ALARM: { 94 long when = SystemClock.elapsedRealtime(); 95 Intent intent = new Intent(ActivityTestMain.this, AlarmSpamReceiver.class); 96 intent.setAction("com.example.SPAM_ALARM=" + when); 97 PendingIntent pi = PendingIntent.getBroadcast(ActivityTestMain.this, 98 0, intent, 0); 99 mAlarm.setAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME, when+(30*1000), pi); 100 scheduleSpamAlarm(30*1000); 101 } break; 102 } 103 super.handleMessage(msg); 104 } 105 }; 106 107 class BroadcastResultReceiver extends BroadcastReceiver { 108 @Override 109 public void onReceive(Context context, Intent intent) { 110 Bundle res = getResultExtras(true); 111 int user = res.getInt("user", -1); 112 Toast.makeText(ActivityTestMain.this, 113 "Receiver executed as user " 114 + (user >= 0 ? Integer.toString(user) : "unknown"), 115 Toast.LENGTH_LONG).show(); 116 } 117 } 118 119 private void addThumbnail(LinearLayout container, Bitmap bm, 120 final ActivityManager.RecentTaskInfo task, 121 final ActivityManager.TaskThumbnail thumbs) { 122 ImageView iv = new ImageView(this); 123 if (bm != null) { 124 iv.setImageBitmap(bm); 125 } 126 iv.setBackgroundResource(android.R.drawable.gallery_thumb); 127 int w = getResources().getDimensionPixelSize(android.R.dimen.thumbnail_width); 128 int h = getResources().getDimensionPixelSize(android.R.dimen.thumbnail_height); 129 container.addView(iv, new LinearLayout.LayoutParams(w, h)); 130 131 iv.setOnClickListener(new View.OnClickListener() { 132 @Override 133 public void onClick(View v) { 134 if (task.id >= 0 && thumbs != null) { 135 mAm.moveTaskToFront(task.id, ActivityManager.MOVE_TASK_WITH_HOME); 136 } else { 137 try { 138 startActivity(task.baseIntent); 139 } catch (ActivityNotFoundException e) { 140 Log.w("foo", "Unable to start task: " + e); 141 } 142 } 143 buildUi(); 144 } 145 }); 146 iv.setOnLongClickListener(new View.OnLongClickListener() { 147 @Override 148 public boolean onLongClick(View v) { 149 if (task.id >= 0 && thumbs != null) { 150 mAm.removeTask(task.id); 151 buildUi(); 152 return true; 153 } 154 return false; 155 } 156 }); 157 } 158 159 @Override 160 protected void onCreate(Bundle savedInstanceState) { 161 super.onCreate(savedInstanceState); 162 163 Log.i(TAG, "Referrer: " + getReferrer()); 164 165 mAm = getSystemService(ActivityManager.class); 166 mPower = getSystemService(PowerManager.class); 167 mAlarm = getSystemService(AlarmManager.class); 168 if (savedInstanceState != null) { 169 mOverrideConfig = savedInstanceState.getParcelable(KEY_CONFIGURATION); 170 if (mOverrideConfig != null) { 171 applyOverrideConfiguration(mOverrideConfig); 172 } 173 } 174 175 UserManager um = (UserManager)getSystemService(Context.USER_SERVICE); 176 List<UserInfo> users = um.getUsers(); 177 mSecondUser = Integer.MAX_VALUE; 178 for (UserInfo ui : users) { 179 if (ui.id != 0 && mSecondUser > ui.id) { 180 mSecondUser = ui.id; 181 } 182 } 183 184 /* 185 AlertDialog ad = new AlertDialog.Builder(this).setTitle("title").setMessage("message").create(); 186 ad.getWindow().getAttributes().type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 187 ad.show(); 188 */ 189 } 190 191 @Override 192 public boolean onCreateOptionsMenu(Menu menu) { 193 menu.add("Animate!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 194 @Override 195 public boolean onMenuItemClick(MenuItem item) { 196 AlertDialog.Builder builder = new AlertDialog.Builder(ActivityTestMain.this, 197 R.style.SlowDialog); 198 builder.setTitle("This is a title"); 199 builder.show(); 200 return true; 201 } 202 }); 203 menu.add("Bind!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 204 @Override public boolean onMenuItemClick(MenuItem item) { 205 Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class); 206 ServiceConnection conn = new ServiceConnection() { 207 @Override 208 public void onServiceConnected(ComponentName name, IBinder service) { 209 Log.i(TAG, "Service connected " + name + " " + service); 210 } 211 @Override 212 public void onServiceDisconnected(ComponentName name) { 213 Log.i(TAG, "Service disconnected " + name); 214 } 215 }; 216 if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) { 217 mConnections.add(conn); 218 } else { 219 Toast.makeText(ActivityTestMain.this, "Failed to bind", 220 Toast.LENGTH_LONG).show(); 221 } 222 return true; 223 } 224 }); 225 menu.add("Start!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 226 @Override public boolean onMenuItemClick(MenuItem item) { 227 Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class); 228 startService(intent); 229 return true; 230 } 231 }); 232 menu.add("Rebind Isolated!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 233 @Override public boolean onMenuItemClick(MenuItem item) { 234 Intent intent = new Intent(ActivityTestMain.this, IsolatedService.class); 235 ServiceConnection conn = new ServiceConnection() { 236 @Override 237 public void onServiceConnected(ComponentName name, IBinder service) { 238 Log.i(TAG, "Isolated service connected " + name + " " + service); 239 } 240 @Override 241 public void onServiceDisconnected(ComponentName name) { 242 Log.i(TAG, "Isolated service disconnected " + name); 243 } 244 }; 245 if (mIsolatedConnection != null) { 246 Log.i(TAG, "Unbinding existing service: " + mIsolatedConnection); 247 unbindService(mIsolatedConnection); 248 mIsolatedConnection = null; 249 } 250 Log.i(TAG, "Binding new service: " + conn); 251 if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) { 252 mIsolatedConnection = conn; 253 } else { 254 Toast.makeText(ActivityTestMain.this, "Failed to bind", 255 Toast.LENGTH_LONG).show(); 256 } 257 return true; 258 } 259 }); 260 menu.add("Send!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 261 @Override public boolean onMenuItemClick(MenuItem item) { 262 Intent intent = new Intent(ActivityTestMain.this, SingleUserReceiver.class); 263 sendOrderedBroadcast(intent, null, new BroadcastResultReceiver(), 264 null, Activity.RESULT_OK, null, null); 265 return true; 266 } 267 }); 268 menu.add("Call!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 269 @Override public boolean onMenuItemClick(MenuItem item) { 270 ContentProviderClient cpl = getContentResolver().acquireContentProviderClient( 271 SingleUserProvider.AUTHORITY); 272 Bundle res = null; 273 try { 274 res = cpl.call("getuser", null, null); 275 } catch (RemoteException e) { 276 } 277 int user = res != null ? res.getInt("user", -1) : -1; 278 Toast.makeText(ActivityTestMain.this, 279 "Provider executed as user " 280 + (user >= 0 ? Integer.toString(user) : "unknown"), 281 Toast.LENGTH_LONG).show(); 282 cpl.release(); 283 return true; 284 } 285 }); 286 menu.add("Send to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 287 @Override public boolean onMenuItemClick(MenuItem item) { 288 Intent intent = new Intent(ActivityTestMain.this, UserTarget.class); 289 sendOrderedBroadcastAsUser(intent, new UserHandle(0), null, 290 new BroadcastResultReceiver(), 291 null, Activity.RESULT_OK, null, null); 292 return true; 293 } 294 }); 295 menu.add("Send to user " + mSecondUser + "!").setOnMenuItemClickListener( 296 new MenuItem.OnMenuItemClickListener() { 297 @Override public boolean onMenuItemClick(MenuItem item) { 298 Intent intent = new Intent(ActivityTestMain.this, UserTarget.class); 299 sendOrderedBroadcastAsUser(intent, new UserHandle(mSecondUser), null, 300 new BroadcastResultReceiver(), 301 null, Activity.RESULT_OK, null, null); 302 return true; 303 } 304 }); 305 menu.add("Bind to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 306 @Override public boolean onMenuItemClick(MenuItem item) { 307 Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class); 308 ServiceConnection conn = new ServiceConnection() { 309 @Override 310 public void onServiceConnected(ComponentName name, IBinder service) { 311 Log.i(TAG, "Service connected " + name + " " + service); 312 } 313 @Override 314 public void onServiceDisconnected(ComponentName name) { 315 Log.i(TAG, "Service disconnected " + name); 316 } 317 }; 318 if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.OWNER)) { 319 mConnections.add(conn); 320 } else { 321 Toast.makeText(ActivityTestMain.this, "Failed to bind", 322 Toast.LENGTH_LONG).show(); 323 } 324 return true; 325 } 326 }); 327 menu.add("Bind to user " + mSecondUser + "!").setOnMenuItemClickListener( 328 new MenuItem.OnMenuItemClickListener() { 329 @Override public boolean onMenuItemClick(MenuItem item) { 330 Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class); 331 ServiceConnection conn = new ServiceConnection() { 332 @Override 333 public void onServiceConnected(ComponentName name, IBinder service) { 334 Log.i(TAG, "Service connected " + name + " " + service); 335 } 336 @Override 337 public void onServiceDisconnected(ComponentName name) { 338 Log.i(TAG, "Service disconnected " + name); 339 } 340 }; 341 if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, 342 new UserHandle(mSecondUser))) { 343 mConnections.add(conn); 344 } else { 345 Toast.makeText(ActivityTestMain.this, "Failed to bind", 346 Toast.LENGTH_LONG).show(); 347 } 348 return true; 349 } 350 }); 351 menu.add("Density!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 352 @Override public boolean onMenuItemClick(MenuItem item) { 353 if (mOverrideConfig == null) { 354 mOverrideConfig = new Configuration(); 355 } 356 if (mOverrideConfig.densityDpi == Configuration.DENSITY_DPI_UNDEFINED) { 357 mOverrideConfig.densityDpi = (getApplicationContext().getResources() 358 .getConfiguration().densityDpi*2)/3; 359 } else { 360 mOverrideConfig.densityDpi = Configuration.DENSITY_DPI_UNDEFINED; 361 } 362 recreate(); 363 return true; 364 } 365 }); 366 menu.add("HashArray").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 367 @Override public boolean onMenuItemClick(MenuItem item) { 368 ArrayMapTests.run(); 369 return true; 370 } 371 }); 372 menu.add("Add App Recent").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 373 @Override public boolean onMenuItemClick(MenuItem item) { 374 addAppRecents(1); 375 return true; 376 } 377 }); 378 menu.add("Add App 10x Recent").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 379 @Override public boolean onMenuItemClick(MenuItem item) { 380 addAppRecents(10); 381 return true; 382 } 383 }); 384 menu.add("Exclude!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 385 @Override public boolean onMenuItemClick(MenuItem item) { 386 setExclude(true); 387 return true; 388 } 389 }); 390 menu.add("Include!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 391 @Override public boolean onMenuItemClick(MenuItem item) { 392 setExclude(false); 393 return true; 394 } 395 }); 396 menu.add("Open Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 397 @Override public boolean onMenuItemClick(MenuItem item) { 398 ActivityManager.AppTask task = findDocTask(); 399 if (task == null) { 400 Intent intent = new Intent(ActivityTestMain.this, DocActivity.class); 401 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT 402 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK 403 | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS); 404 startActivity(intent); 405 } else { 406 task.moveToFront(); 407 } 408 return true; 409 } 410 }); 411 menu.add("Stack Doc").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 412 @Override public boolean onMenuItemClick(MenuItem item) { 413 ActivityManager.AppTask task = findDocTask(); 414 if (task != null) { 415 ActivityManager.RecentTaskInfo recent = task.getTaskInfo(); 416 Intent intent = new Intent(ActivityTestMain.this, DocActivity.class); 417 if (recent.id >= 0) { 418 // Stack on top. 419 intent.putExtra(DocActivity.LABEL, "Stacked"); 420 } else { 421 // Start root activity. 422 intent.putExtra(DocActivity.LABEL, "New Root"); 423 } 424 task.startActivity(ActivityTestMain.this, intent, null); 425 } 426 return true; 427 } 428 }); 429 menu.add("Spam!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 430 @Override public boolean onMenuItemClick(MenuItem item) { 431 scheduleSpam(false); 432 return true; 433 } 434 }); 435 menu.add("Track time").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { 436 @Override public boolean onMenuItemClick(MenuItem item) { 437 Intent intent = new Intent(Intent.ACTION_SEND); 438 intent.setType("text/plain"); 439 intent.putExtra(Intent.EXTRA_TEXT, "We are sharing this with you!"); 440 ActivityOptions options = ActivityOptions.makeBasic(); 441 Intent receiveIntent = new Intent(ActivityTestMain.this, TrackTimeReceiver.class); 442 receiveIntent.putExtra("something", "yeah, this is us!"); 443 options.requestUsageTimeReport(PendingIntent.getBroadcast(ActivityTestMain.this, 444 0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT)); 445 startActivity(Intent.createChooser(intent, "Who do you love?"), options.toBundle()); 446 return true; 447 } 448 }); 449 menu.add("Transaction fail").setOnMenuItemClickListener( 450 new MenuItem.OnMenuItemClickListener() { 451 @Override public boolean onMenuItemClick(MenuItem item) { 452 Intent intent = new Intent(Intent.ACTION_MAIN); 453 intent.putExtra("gulp", new int[1024 * 1024]); 454 startActivity(intent); 455 return true; 456 } 457 }); 458 menu.add("Spam idle alarm").setOnMenuItemClickListener( 459 new MenuItem.OnMenuItemClickListener() { 460 @Override public boolean onMenuItemClick(MenuItem item) { 461 scheduleSpamAlarm(0); 462 return true; 463 } 464 }); 465 menu.add("Ignore battery optimizations").setOnMenuItemClickListener( 466 new MenuItem.OnMenuItemClickListener() { 467 @Override public boolean onMenuItemClick(MenuItem item) { 468 Intent intent; 469 if (!mPower.isIgnoringBatteryOptimizations(getPackageName())) { 470 intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); 471 intent.setData(Uri.fromParts("package", getPackageName(), null)); 472 } else { 473 intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); 474 } 475 startActivity(intent); 476 return true; 477 } 478 }); 479 return true; 480 } 481 482 @Override 483 protected void onStart() { 484 super.onStart(); 485 buildUi(); 486 } 487 488 @Override 489 protected void onPause() { 490 super.onPause(); 491 Log.i(TAG, "I'm such a slooow poor loser"); 492 try { 493 Thread.sleep(500); 494 } catch (InterruptedException e) { 495 } 496 Log.i(TAG, "See?"); 497 } 498 499 @Override 500 protected void onSaveInstanceState(Bundle outState) { 501 super.onSaveInstanceState(outState); 502 if (mOverrideConfig != null) { 503 outState.putParcelable(KEY_CONFIGURATION, mOverrideConfig); 504 } 505 } 506 507 @Override 508 protected void onStop() { 509 super.onStop(); 510 mHandler.removeMessages(MSG_SPAM_ALARM); 511 for (ServiceConnection conn : mConnections) { 512 unbindService(conn); 513 } 514 mConnections.clear(); 515 if (mIsolatedConnection != null) { 516 unbindService(mIsolatedConnection); 517 mIsolatedConnection = null; 518 } 519 } 520 521 @Override 522 protected void onDestroy() { 523 super.onDestroy(); 524 mHandler.removeMessages(MSG_SPAM); 525 } 526 527 void addAppRecents(int count) { 528 ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); 529 Intent intent = new Intent(Intent.ACTION_MAIN); 530 intent.addCategory(Intent.CATEGORY_LAUNCHER); 531 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); 532 intent.setComponent(new ComponentName(this, ActivityTestMain.class)); 533 for (int i=0; i<count; i++) { 534 ActivityManager.TaskDescription desc = new ActivityManager.TaskDescription(); 535 desc.setLabel("Added #" + i); 536 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon); 537 if ((i&1) == 0) { 538 desc.setIcon(bitmap); 539 } 540 int taskId = am.addAppTask(this, intent, desc, bitmap); 541 Log.i(TAG, "Added new task id #" + taskId); 542 } 543 } 544 545 void setExclude(boolean exclude) { 546 ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); 547 List<ActivityManager.AppTask> tasks = am.getAppTasks(); 548 int taskId = getTaskId(); 549 for (int i=0; i<tasks.size(); i++) { 550 ActivityManager.AppTask task = tasks.get(i); 551 if (task.getTaskInfo().id == taskId) { 552 task.setExcludeFromRecents(exclude); 553 } 554 } 555 } 556 557 ActivityManager.AppTask findDocTask() { 558 ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); 559 List<ActivityManager.AppTask> tasks = am.getAppTasks(); 560 if (tasks != null) { 561 for (int i=0; i<tasks.size(); i++) { 562 ActivityManager.AppTask task = tasks.get(i); 563 ActivityManager.RecentTaskInfo recent = task.getTaskInfo(); 564 if (recent.baseIntent != null 565 && recent.baseIntent.getComponent().getClassName().equals( 566 DocActivity.class.getCanonicalName())) { 567 return task; 568 } 569 } 570 } 571 return null; 572 } 573 574 void scheduleSpam(boolean fg) { 575 mHandler.removeMessages(MSG_SPAM); 576 Message msg = mHandler.obtainMessage(MSG_SPAM, fg ? 1 : 0, 0); 577 mHandler.sendMessageDelayed(msg, 500); 578 } 579 580 void scheduleSpamAlarm(long delay) { 581 mHandler.removeMessages(MSG_SPAM_ALARM); 582 Message msg = mHandler.obtainMessage(MSG_SPAM_ALARM); 583 mHandler.sendMessageDelayed(msg, delay); 584 } 585 586 private View scrollWrap(View view) { 587 ScrollView scroller = new ScrollView(this); 588 scroller.addView(view, new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, 589 ScrollView.LayoutParams.MATCH_PARENT)); 590 return scroller; 591 } 592 593 private void buildUi() { 594 LinearLayout top = new LinearLayout(this); 595 top.setOrientation(LinearLayout.VERTICAL); 596 597 List<ActivityManager.RecentTaskInfo> recents = mAm.getRecentTasks(10, 598 ActivityManager.RECENT_WITH_EXCLUDED); 599 if (recents != null) { 600 for (int i=0; i<recents.size(); i++) { 601 ActivityManager.RecentTaskInfo r = recents.get(i); 602 ActivityManager.TaskThumbnail tt = mAm.getTaskThumbnail(r.persistentId); 603 TextView tv = new TextView(this); 604 tv.setText(r.baseIntent.getComponent().flattenToShortString()); 605 top.addView(tv, new LinearLayout.LayoutParams( 606 LinearLayout.LayoutParams.WRAP_CONTENT, 607 LinearLayout.LayoutParams.WRAP_CONTENT)); 608 LinearLayout item = new LinearLayout(this); 609 item.setOrientation(LinearLayout.HORIZONTAL); 610 addThumbnail(item, tt != null ? tt.mainThumbnail : null, r, tt); 611 top.addView(item, new LinearLayout.LayoutParams( 612 LinearLayout.LayoutParams.WRAP_CONTENT, 613 LinearLayout.LayoutParams.WRAP_CONTENT)); 614 } 615 } 616 617 setContentView(scrollWrap(top)); 618 } 619} 620