1 /* 2 * Copyright (C) 2015 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.messaging.ui.mediapicker; 18 19 import android.content.Context; 20 import android.database.Cursor; 21 import android.view.LayoutInflater; 22 import android.view.View; 23 import android.view.ViewGroup; 24 import android.widget.CursorAdapter; 25 26 import com.android.messaging.R; 27 import com.android.messaging.ui.mediapicker.GalleryGridItemView.HostInterface; 28 import com.android.messaging.util.Assert; 29 30 /** 31 * Bridges between the image cursor loaded by GalleryBoundCursorLoader and the GalleryGridView. 32 */ 33 public class GalleryGridAdapter extends CursorAdapter { 34 private GalleryGridItemView.HostInterface mGgivHostInterface; 35 36 public GalleryGridAdapter(final Context context, final Cursor cursor) { 37 super(context, cursor, 0); 38 } 39 40 public void setHostInterface(final HostInterface ggivHostInterface) { 41 mGgivHostInterface = ggivHostInterface; 42 } 43 44 /** 45 * {@inheritDoc} 46 */ 47 @Override 48 public void bindView(final View view, final Context context, final Cursor cursor) { 49 Assert.isTrue(view instanceof GalleryGridItemView); 50 final GalleryGridItemView galleryImageView = (GalleryGridItemView) view; 51 galleryImageView.bind(cursor, mGgivHostInterface); 52 } 53 54 /** 55 * {@inheritDoc} 56 */ 57 @Override 58 public View newView(final Context context, final Cursor cursor, final ViewGroup parent) { 59 final LayoutInflater layoutInflater = LayoutInflater.from(context); 60 return layoutInflater.inflate(R.layout.gallery_grid_item_view, parent, false); 61 } 62 } 63