Back to project page app_list_widget.
The source code is released under:
Apache License
If you think the Android project app_list_widget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright 2013 acbelter/*from www.j av a 2 s.c o m*/ * * 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.acbelter.applistwidget.ui; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import com.acbelter.applistwidget.R; import java.util.ArrayList; public class AppListOrderAdapter extends ArrayAdapter<AppItem> { private LayoutInflater mInflater; private ArrayList<AppItem> mAppItems; public AppListOrderAdapter(Context context, ArrayList<AppItem> appItems) { super(context, R.layout.item_app_order, appItems); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mAppItems = appItems; } public ArrayList<AppItem> getApps() { return mAppItems; } static class ViewHolder { ImageView icon; TextView appName; TextView packageName; ImageView arrowUp; ImageView arrowDown; } @Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate(R.layout.item_app_order, null); final ViewHolder holder = new ViewHolder(); holder.icon = (ImageView) convertView.findViewById(R.id.app_icon); holder.appName = (TextView) convertView.findViewById(R.id.app_name); holder.packageName = (TextView) convertView.findViewById(R.id.app_package); holder.arrowUp = (ImageView) convertView.findViewById(R.id.arrow_up); holder.arrowDown = (ImageView) convertView.findViewById(R.id.arrow_down); convertView.setTag(holder); } ViewHolder viewHolder = (ViewHolder) convertView.getTag(); final AppItem appItem = mAppItems.get(position); viewHolder.icon.setImageDrawable(appItem.getIcon()); viewHolder.appName.setText(appItem.getAppName()); viewHolder.packageName.setText(appItem.getPackageName()); viewHolder.arrowUp.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (position > 0) { AppItem prev = mAppItems.get(position - 1); mAppItems.set(position - 1, mAppItems.get(position)); mAppItems.set(position, prev); notifyDataSetChanged(); } } }); viewHolder.arrowDown.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (position >= 0 && position < mAppItems.size() - 1) { AppItem next = mAppItems.get(position + 1); mAppItems.set(position + 1, mAppItems.get(position)); mAppItems.set(position, next); notifyDataSetChanged(); } } }); return convertView; } }