Home | History | Annotate | Download | only in impl
      1 /*
      2  * Copyright 2018 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 
     17 package androidx.slice.builders.impl;
     18 
     19 import static androidx.annotation.RestrictTo.Scope.LIBRARY;
     20 import static androidx.slice.builders.ListBuilder.INFINITY;
     21 import static androidx.slice.builders.ListBuilder.SMALL_IMAGE;
     22 
     23 import android.graphics.drawable.Icon;
     24 
     25 import androidx.annotation.RequiresApi;
     26 import androidx.annotation.RestrictTo;
     27 import androidx.core.graphics.drawable.IconCompat;
     28 import androidx.slice.Slice;
     29 import androidx.slice.SliceSpec;
     30 
     31 /**
     32  * @hide
     33  */
     34 @RestrictTo(LIBRARY)
     35 public class MessagingListV1Impl extends TemplateBuilderImpl implements MessagingBuilder{
     36 
     37     private final ListBuilderV1Impl mListBuilder;
     38 
     39     /**
     40      */
     41     public MessagingListV1Impl(Slice.Builder b, SliceSpec spec) {
     42         super(b, spec);
     43         mListBuilder = new ListBuilderV1Impl(b, spec);
     44         mListBuilder.setTtl(INFINITY);
     45     }
     46 
     47     /**
     48      */
     49     @Override
     50     public void add(TemplateBuilderImpl builder) {
     51         MessageBuilder b = (MessageBuilder) builder;
     52         mListBuilder.addRow(b.mListBuilder);
     53     }
     54 
     55     /**
     56      */
     57     @Override
     58     public TemplateBuilderImpl createMessageBuilder() {
     59         return new MessageBuilder(this);
     60     }
     61 
     62     /**
     63      */
     64     @Override
     65     public void apply(Slice.Builder builder) {
     66         mListBuilder.apply(builder);
     67     }
     68 
     69     /**
     70      */
     71     public static final class MessageBuilder extends TemplateBuilderImpl
     72             implements MessagingBuilder.MessageBuilder {
     73         private final ListBuilderV1Impl.RowBuilderImpl mListBuilder;
     74 
     75         /**
     76          */
     77         public MessageBuilder(MessagingListV1Impl parent) {
     78             this(parent.createChildBuilder());
     79         }
     80 
     81         private MessageBuilder(Slice.Builder builder) {
     82             super(builder, null);
     83             mListBuilder = new ListBuilderV1Impl.RowBuilderImpl(builder);
     84         }
     85 
     86         /**
     87          */
     88         @Override
     89         @RequiresApi(23)
     90         public void addSource(Icon source) {
     91             mListBuilder.setTitleItem(IconCompat.createFromIcon(source), SMALL_IMAGE);
     92         }
     93 
     94         /**
     95          */
     96         @Override
     97         public void addText(CharSequence text) {
     98             mListBuilder.setSubtitle(text);
     99         }
    100 
    101         /**
    102          */
    103         @Override
    104         public void addTimestamp(long timestamp) {
    105             mListBuilder.addEndItem(timestamp);
    106         }
    107 
    108         /**
    109          */
    110         @Override
    111         public void apply(Slice.Builder builder) {
    112             mListBuilder.apply(builder);
    113         }
    114     }
    115 }
    116