1 /*
2  * Copyright (C) 2017 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.example.android.autofill.service;
17 
18 import android.support.annotation.DrawableRes;
19 import android.widget.RemoteViews;
20 
21 /**
22  * This is a class containing helper methods for building Autofill Datasets and Responses.
23  */
24 public final class RemoteViewsHelper {
RemoteViewsHelper()25     private RemoteViewsHelper() {
26     }
27 
viewsWithAuth(String packageName, String text)28     public static RemoteViews viewsWithAuth(String packageName, String text) {
29         return simpleRemoteViews(packageName, text, R.drawable.ic_lock_black_24dp);
30     }
31 
viewsWithNoAuth(String packageName, String text)32     public static RemoteViews viewsWithNoAuth(String packageName, String text) {
33         return simpleRemoteViews(packageName, text, R.drawable.ic_person_black_24dp);
34     }
35 
simpleRemoteViews(String packageName, String remoteViewsText, @DrawableRes int drawableId)36     private static RemoteViews simpleRemoteViews(String packageName, String remoteViewsText,
37             @DrawableRes int drawableId) {
38         RemoteViews presentation = new RemoteViews(packageName,
39                 R.layout.multidataset_service_list_item);
40         presentation.setTextViewText(R.id.text, remoteViewsText);
41         presentation.setImageViewResource(R.id.icon, drawableId);
42         return presentation;
43     }
44 }
45