Home | History | Annotate | Download | only in videoeditor
      1 /*
      2  * Copyright (C) 2010 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.videoeditor;
     18 
     19 import android.content.Context;
     20 import android.graphics.Bitmap;
     21 import android.graphics.BitmapFactory;
     22 import android.graphics.Canvas;
     23 import android.graphics.Paint;
     24 import android.view.LayoutInflater;
     25 import android.view.View;
     26 import android.view.ViewGroup;
     27 import android.widget.AbsListView;
     28 
     29 import com.android.videoeditor.util.ImageUtils;
     30 
     31 /**
     32  * Adapter which displays a list of supported overlays
     33  */
     34 public class OverlaysAdapter extends BaseAdapterWithImages<Integer> {
     35     // Static member variables
     36     private static final Paint sCopyPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
     37 
     38     // Instance variables
     39     private final Bitmap mGenericBitmap;
     40     private final String mTitle, mSubtitle;
     41     private final OverlayType[] mOverlays;
     42 
     43     /**
     44      * Constructor
     45      *
     46      * @param context The context
     47      * @param listView The list view
     48      */
     49     public OverlaysAdapter(Context context, AbsListView listView) {
     50         super(context, listView);
     51 
     52         mGenericBitmap = BitmapFactory.decodeResource(context.getResources(),
     53                 R.drawable.effects_generic);
     54         mTitle = context.getString(R.string.overlay_title_sample);
     55         mSubtitle = context.getString(R.string.overlay_subtitle_sample);
     56         mOverlays = OverlayType.getOverlays(context);
     57     }
     58 
     59     /*
     60      * {@inheritDoc}
     61      */
     62     @Override
     63     public int getCount() {
     64         return mOverlays.length;
     65     }
     66 
     67     /*
     68      * {@inheritDoc}
     69      */
     70     public Object getItem(int position) {
     71         return mOverlays[position];
     72     }
     73 
     74     /*
     75      * {@inheritDoc}
     76      */
     77     @SuppressWarnings("unchecked")
     78     public View getView(int position, View convertView, ViewGroup parent) {
     79         final ImageTextViewHolder<Integer> viewHolder;
     80         final View rowView;
     81         if (convertView == null) {
     82             final LayoutInflater vi = (LayoutInflater)mContext.getSystemService(
     83                     Context.LAYOUT_INFLATER_SERVICE);
     84             rowView = vi.inflate(R.layout.image_with_text_row_view, null);
     85             viewHolder = new ImageTextViewHolder<Integer>(rowView);
     86             rowView.setTag(viewHolder);
     87         } else {
     88             rowView = convertView;
     89             viewHolder = (ImageTextViewHolder<Integer>)convertView.getTag();
     90         }
     91 
     92         final OverlayType overlayType = mOverlays[position];
     93         initiateLoad(overlayType.getType(), overlayType.getType(), viewHolder);
     94 
     95         // Set the data in the views
     96         viewHolder.mNameView.setText(overlayType.getName());
     97 
     98         return rowView;
     99     }
    100 
    101     /*
    102      * {@inheritDoc}
    103      */
    104     @Override
    105     protected Bitmap loadImage(Object data) {
    106         final Bitmap overlayBitmap = Bitmap.createBitmap(mGenericBitmap.getWidth(),
    107                 mGenericBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    108 
    109         final Canvas canvas = new Canvas(overlayBitmap);
    110         canvas.drawBitmap(mGenericBitmap, 0, 0, sCopyPaint);
    111         canvas.drawBitmap(ImageUtils.buildOverlayBitmap(mContext, null, (Integer)data, mTitle,
    112                 mSubtitle,
    113                 mGenericBitmap.getWidth(), mGenericBitmap.getHeight()), 0, 0, sCopyPaint);
    114         return overlayBitmap;
    115     }
    116 }
    117