Home | History | Annotate | Download | only in launcher2
      1 /*
      2  * Copyright (C) 2008 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.launcher2;
     18 
     19 import android.content.Context;
     20 import android.content.pm.PackageManager;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.widget.ArrayAdapter;
     25 import android.widget.TextView;
     26 
     27 import java.util.ArrayList;
     28 
     29 import com.android.launcher.R;
     30 
     31 /**
     32  * GridView adapter to show the list of applications and shortcuts
     33  */
     34 public class ShortcutsAdapter  extends ArrayAdapter<ShortcutInfo> {
     35     private final LayoutInflater mInflater;
     36     private final IconCache mIconCache;
     37 
     38     public ShortcutsAdapter(Context context, ArrayList<ShortcutInfo> apps) {
     39         super(context, 0, apps);
     40         mInflater = LayoutInflater.from(context);
     41         mIconCache = ((LauncherApplication)context.getApplicationContext()).getIconCache();
     42     }
     43 
     44     @Override
     45     public View getView(int position, View convertView, ViewGroup parent) {
     46         final ShortcutInfo info = getItem(position);
     47 
     48         if (convertView == null) {
     49             convertView = mInflater.inflate(R.layout.application_boxed, parent, false);
     50         }
     51 
     52         final TextView textView = (TextView) convertView;
     53         textView.setCompoundDrawablesWithIntrinsicBounds(null,
     54                 new FastBitmapDrawable(info.getIcon(mIconCache)), null, null);
     55         textView.setText(info.title);
     56 
     57         return convertView;
     58     }
     59 }
     60