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 17 package com.android.incallui.incall.impl; 18 19 import android.support.annotation.Nullable; 20 import android.support.v4.app.Fragment; 21 import android.support.v4.app.FragmentManager; 22 import android.support.v4.app.FragmentStatePagerAdapter; 23 import android.support.v4.view.PagerAdapter; 24 import android.text.TextUtils; 25 import com.android.dialer.multimedia.MultimediaData; 26 import com.android.incallui.sessiondata.MultimediaFragment; 27 28 /** View pager adapter for in call ui. */ 29 public class InCallPagerAdapter extends FragmentStatePagerAdapter { 30 31 @Nullable private MultimediaData attachments; 32 InCallPagerAdapter(FragmentManager fragmentManager, @Nullable MultimediaData attachments)33 public InCallPagerAdapter(FragmentManager fragmentManager, @Nullable MultimediaData attachments) { 34 super(fragmentManager); 35 this.attachments = attachments; 36 } 37 38 @Override getItem(int position)39 public Fragment getItem(int position) { 40 if (position == getButtonGridPosition()) { 41 return InCallButtonGridFragment.newInstance(); 42 } else { 43 // TODO: handle fragment invalidation for when the data changes. 44 return MultimediaFragment.newInstance(attachments, true, false, false); 45 } 46 } 47 48 @Override getCount()49 public int getCount() { 50 if (attachments != null 51 && (!TextUtils.isEmpty(attachments.getText()) || attachments.hasImageData())) { 52 return 2; 53 } 54 return 1; 55 } 56 setAttachments(@ullable MultimediaData attachments)57 public void setAttachments(@Nullable MultimediaData attachments) { 58 if (this.attachments != attachments) { 59 this.attachments = attachments; 60 notifyDataSetChanged(); 61 } 62 } 63 getButtonGridPosition()64 public int getButtonGridPosition() { 65 return getCount() - 1; 66 } 67 68 //this is called when notifyDataSetChanged() is called 69 @Override getItemPosition(Object object)70 public int getItemPosition(Object object) { 71 // refresh all fragments when data set changed 72 return PagerAdapter.POSITION_NONE; 73 } 74 } 75