165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/*
265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project
365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License");
565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License.
665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at
765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *      http://www.apache.org/licenses/LICENSE-2.0
965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software
1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS,
1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and
1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License.
1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.widget;
1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.List;
2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context;
2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.LayoutInflater;
2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.View;
2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.ViewGroup;
2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.ArrayAdapter;
2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.TextView;
2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class ScrollArrayAdapter<T> extends ArrayAdapter<T> implements ScrollAdapter {
2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    private int mLayoutResource = -1;
3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollArrayAdapter(Context context, int textViewResourceId) {
3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super(context, textViewResourceId);
3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollArrayAdapter(Context context, int resource, int textViewResourceId) {
3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super(context, resource, textViewResourceId);
3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mLayoutResource = resource;
3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollArrayAdapter(Context context, int textViewResourceId, T[] objects) {
4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super(context, textViewResourceId, objects);
4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollArrayAdapter(Context context, int resource, int textViewResourceId,
4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            T[] objects) {
4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super(context, resource, textViewResourceId, objects);
4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mLayoutResource = resource;
4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollArrayAdapter(Context context, int textViewResourceId, List<T> objects) {
5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super(context, textViewResourceId, objects);
5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollArrayAdapter(Context context, int resource, int textViewResourceId,
5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            List<T> objects) {
5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super(context, resource, textViewResourceId, objects);
5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mLayoutResource = resource;
5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public View getScrapView(ViewGroup parent) {
6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        if (getCount() > 0) {
6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            return getView(0, null, parent);
6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        } else {
6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            if (mLayoutResource != -1) {
6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                LayoutInflater inflater = (LayoutInflater)
6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                        parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                return inflater.inflate(mLayoutResource, parent);
7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            } else {
7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                return new TextView(parent.getContext());
7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            }
7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public void viewRemoved(View view) {
7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public ScrollAdapterBase getExpandAdapter() {
8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        return null;
8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane}
85