diff options
Diffstat (limited to 'src/org/lineageos/appdrawer/ApplicationAdapter.java')
-rw-r--r-- | src/org/lineageos/appdrawer/ApplicationAdapter.java | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/org/lineageos/appdrawer/ApplicationAdapter.java b/src/org/lineageos/appdrawer/ApplicationAdapter.java new file mode 100644 index 0000000..1b761ab --- /dev/null +++ b/src/org/lineageos/appdrawer/ApplicationAdapter.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.appdrawer; + +import android.content.Context; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> { + private List<ApplicationInfo> appsList = null; + private Context context; + private PackageManager packageManager; + + public ApplicationAdapter(Context context, int textViewResourceId, + List<ApplicationInfo> appsList) { + super(context, textViewResourceId, appsList); + this.context = context; + this.appsList = appsList; + packageManager = context.getPackageManager(); + } + + @Override + public int getCount() { + return ((null != appsList) ? appsList.size() : 0); + } + + @Override + public ApplicationInfo getItem(int position) { + return ((null != appsList) ? appsList.get(position) : null); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view = convertView; + if (null == view) { + LayoutInflater layoutInflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + view = layoutInflater.inflate(R.layout.grid_item, null); + } + + ApplicationInfo data = appsList.get(position); + if (null != data) { + TextView appName = (TextView) view.findViewById(R.id.app_name); + ImageView iconview = (ImageView) view.findViewById(R.id.app_icon); + + appName.setText(data.loadLabel(packageManager)); + iconview.setImageDrawable(data.loadIcon(packageManager)); + } + return view; + } +}; |