Back to project page android_device.
The source code is released under:
[Apache License](http://www.apache.org/licenses/): Version 2.0, January 2004 =============== ## TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION ## ### 1. Definitions. ### "License" sha...
If you think the Android project android_device 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 (C) 2014 Martin Albedinsky [Wolf-ITechnologies] * ================================================================================================= * Licensed under the Apache License, Version 2.0 or later (further "License" only). * ------------------------------------------------------------------------------------------------- * You may use this file only in compliance with the License. More details and copy of this License * you may obtain at// ww w . ja va 2 s .c o m * * http://www.apache.org/licenses/LICENSE-2.0 * * You can redistribute, modify or publish any part of the code written within this file but as it * is described in the License, the software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES or CONDITIONS OF ANY KIND. * * See the License for the specific language governing permissions and limitations under the License. * ================================================================================================= */ package com.wit.android.device.examples.adapter; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import android.util.SparseIntArray; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; import com.wit.android.device.examples.R; import com.wit.android.examples.libs.adapter.ExSimpleAdapter; import com.wit.android.examples.libs.adapter.ExViewHolder; import com.wit.android.examples.libs.adapter.annotation.ExItemView; import com.wit.android.examples.libs.adapter.annotation.ExItemViewHolder; import com.wit.android.examples.libs.adapter.module.ExAdapterModule; import com.wit.android.examples.libs.adapter.module.ExSelectionModule; import java.io.File; /** * todo: description * * @author Martin Albedinsky */ @ExItemView(R.layout.item_list_file) @ExItemViewHolder(FilesAdapter.Holder.class) public class FilesAdapter extends ExSimpleAdapter<File> implements ExAdapterModule.ExModuleAdapter { /** * Log TAG. */ // private static final String TAG = FilesAdapter.class.getSimpleName(); /** * */ public static final int MODE_DEFAULT = 0x00; /** * */ public static final int MODE_SELECTION = 0x01; /** * */ final int mFileColor, mDirColor; /** * */ final ExSelectionModule SELECTOR = new ExSelectionModule(); /** * */ int mMode = MODE_DEFAULT; /** * @param context */ public FilesAdapter(Context context) { super(context); SELECTOR.setMode(ExSelectionModule.MODE_MULTIPLE); SELECTOR.dispatchAttachToAdapter(this); final Resources resources = context.getResources(); this.mFileColor = Color.WHITE; this.mDirColor = resources.getColor(R.color.exAccent); } /** * @param mode */ public void setMode(int mode) { if (mMode != mode) { switch (mode) { case MODE_DEFAULT: case MODE_SELECTION: if ((mMode = mode) == MODE_DEFAULT) { SELECTOR.clearSelection(); } else { notifyDataSetChanged(); } } } } /** * @param position */ public void dispatchItemSelected(int position) { SELECTOR.toggleSelectionState(position); } /** * @return */ public String[] getSelectedItemPaths() { final SparseIntArray selection = SELECTOR.getSelection(); final String[] paths = new String[selection.size()]; for (int i = 0; i < selection.size(); i++) { paths[i] = getItem(selection.keyAt(i)).getPath(); } return paths; } /** * */ public static final class Holder implements ExViewHolder<File, FilesAdapter> { TextView path; CheckBox check; /** */ @Override public void create(int position, View view) { this.path = (TextView) view.findViewById(R.id.item_list_file_text_view_path); this.check = (CheckBox) view.findViewById(R.id.item_list_file_check_box); } /** */ @Override public void bind(int position, File item, FilesAdapter adapter) { path.setText(item.getName()); switch (adapter.mMode) { case MODE_DEFAULT: if (check.getVisibility() == View.VISIBLE) { check.setVisibility(View.GONE); } break; case MODE_SELECTION: if (check.getVisibility() != View.VISIBLE) { check.setVisibility(View.VISIBLE); } check.setChecked(adapter.SELECTOR.isSelected(position)); break; } path.setTextColor(item.isDirectory() ? adapter.mDirColor : adapter.mFileColor); } } }