1 /* 2 * Copyright (C) 2019 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 package com.android.launcher3.testcomponent; 17 18 import android.content.Intent; 19 import android.os.IBinder; 20 import android.widget.RemoteViews; 21 import android.widget.RemoteViewsService; 22 23 public class ListViewService extends RemoteViewsService { 24 25 public static IBinder sBinderForTest; 26 27 @Override onGetViewFactory(Intent intent)28 public RemoteViewsFactory onGetViewFactory(Intent intent) { 29 return new SimpleViewsFactory(); 30 } 31 32 @Override onBind(Intent intent)33 public IBinder onBind(Intent intent) { 34 return sBinderForTest != null ? sBinderForTest : super.onBind(intent); 35 } 36 37 public static class SimpleViewsFactory implements RemoteViewsFactory { 38 39 public int viewCount = 0; 40 41 @Override onCreate()42 public void onCreate() { } 43 44 @Override onDataSetChanged()45 public void onDataSetChanged() { } 46 47 @Override onDestroy()48 public void onDestroy() { } 49 50 @Override getCount()51 public int getCount() { 52 return viewCount; 53 } 54 55 @Override getViewAt(int i)56 public RemoteViews getViewAt(int i) { 57 RemoteViews views = new RemoteViews("android", android.R.layout.simple_list_item_1); 58 views.setTextViewText(android.R.id.text1, getLabel(i)); 59 return views; 60 } 61 getLabel(int i)62 public String getLabel(int i) { 63 return "Item " + i; 64 } 65 66 @Override getLoadingView()67 public RemoteViews getLoadingView() { 68 return null; 69 } 70 71 @Override getViewTypeCount()72 public int getViewTypeCount() { 73 return 1; 74 } 75 76 @Override getItemId(int i)77 public long getItemId(int i) { 78 return i; 79 } 80 81 @Override hasStableIds()82 public boolean hasStableIds() { 83 return false; 84 } 85 toBinder()86 public IBinder toBinder() { 87 return new RemoteViewsService() { 88 @Override 89 public RemoteViewsFactory onGetViewFactory(Intent intent) { 90 return SimpleViewsFactory.this; 91 } 92 }.onBind(new Intent("stub_intent")); 93 } 94 } 95 } 96