/*
* Copyright (C) 2015 The Android Open Source 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 com.android.launcher3.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.LinearLayout;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.WidgetPreviewLoader;
import com.android.launcher3.model.PackageItemInfo;
import com.android.launcher3.model.WidgetsModel;
import java.util.List;
/**
* List view adapter for the widget tray.
*
*
Memory vs. Performance:
* The less number of types of views are inserted into a {@link RecyclerView}, the more recycling
* happens and less memory is consumed. {@link #getItemViewType} was not overridden as there is
* only a single type of view.
*/
public class WidgetsListAdapter extends Adapter {
private static final String TAG = "WidgetsListAdapter";
private static final boolean DEBUG = false;
private Launcher mLauncher;
private LayoutInflater mLayoutInflater;
private WidgetsModel mWidgetsModel;
private WidgetPreviewLoader mWidgetPreviewLoader;
private View.OnClickListener mIconClickListener;
private View.OnLongClickListener mIconLongClickListener;
private static final int PRESET_INDENT_SIZE_TABLET = 56;
private int mIndent = 0;
public WidgetsListAdapter(Context context,
View.OnClickListener iconClickListener,
View.OnLongClickListener iconLongClickListener,
Launcher launcher) {
mLayoutInflater = LayoutInflater.from(context);
mIconClickListener = iconClickListener;
mIconLongClickListener = iconLongClickListener;
mLauncher = launcher;
setContainerHeight();
}
public void setWidgetsModel(WidgetsModel w) {
mWidgetsModel = w;
}
@Override
public int getItemCount() {
if (mWidgetsModel == null) {
return 0;
}
return mWidgetsModel.getPackageSize();
}
@Override
public void onBindViewHolder(WidgetsRowViewHolder holder, int pos) {
List