use of com.github.obsessive.library.adapter.ViewHolderCreator in project SimplifyReader by chentao0707.
the class CommonImagePickerDetailActivity method initViewsAndEvents.
@Override
protected void initViewsAndEvents() {
mGridViewAdapter = new ListViewDataAdapter<>(new ViewHolderCreator<ImageItem>() {
@Override
public ViewHolderBase<ImageItem> createViewHolder(int position) {
return new ViewHolderBase<ImageItem>() {
ImageView mItemImage;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.grid_item_common_image_picker, null);
mItemImage = ButterKnife.findById(convertView, R.id.grid_item_common_image_picker_image);
return convertView;
}
@Override
public void showData(int position, ImageItem itemData) {
if (null != itemData) {
String imagePath = itemData.getImagePath();
if (!CommonUtils.isEmpty(imagePath)) {
ImageLoader.getInstance().displayImage("file://" + imagePath, mItemImage, ImageLoaderHelper.getInstance(mContext).getDisplayOptions());
}
}
}
};
}
});
mGridViewAdapter.getDataList().addAll(mGridListData);
commonImagePickerDetailGridView.setAdapter(mGridViewAdapter);
commonImagePickerDetailGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mGridViewAdapter && null != mGridViewAdapter.getDataList() && !mGridViewAdapter.getDataList().isEmpty() && position < mGridViewAdapter.getDataList().size()) {
Intent intent = new Intent();
intent.putExtra(KEY_BUNDLE_RESULT_IMAGE_PATH, mGridViewAdapter.getDataList().get(position).getImagePath());
setResult(RESULT_OK, intent);
finish();
}
}
});
}
use of com.github.obsessive.library.adapter.ViewHolderCreator in project SimplifyReader by chentao0707.
the class CommonImagePickerListActivity method initViewsAndEvents.
@Override
protected void initViewsAndEvents() {
setTitle(getResources().getString(R.string.title_image_picker));
mListViewAdapter = new ListViewDataAdapter<ImageBucket>(new ViewHolderCreator<ImageBucket>() {
@Override
public ViewHolderBase<ImageBucket> createViewHolder(int position) {
return new ViewHolderBase<ImageBucket>() {
ImageView mItemImage;
TextView mItemTitle;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.list_item_common_image_picker, null);
mItemImage = ButterKnife.findById(convertView, R.id.list_item_common_image_picker_thumbnail);
mItemTitle = ButterKnife.findById(convertView, R.id.list_item_common_image_picker_title);
return convertView;
}
@Override
public void showData(int position, ImageBucket itemData) {
if (null != itemData) {
String imagePath = itemData.bucketList.get(0).getImagePath();
if (!CommonUtils.isEmpty(imagePath)) {
ImageLoader.getInstance().displayImage("file://" + imagePath, mItemImage, ImageLoaderHelper.getInstance(mContext).getDisplayOptions());
}
int count = itemData.count;
String title = itemData.bucketName;
if (!CommonUtils.isEmpty(title)) {
mItemTitle.setText(title + "(" + count + ")");
}
}
}
};
}
});
mImagePickerListView.setAdapter(mListViewAdapter);
mImagePickerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mListViewAdapter && null != mListViewAdapter.getDataList() && !mListViewAdapter.getDataList().isEmpty() && position < mListViewAdapter.getDataList().size()) {
Bundle extras = new Bundle();
extras.putParcelableArrayList(KEY_BUNDLE_ALBUM_PATH, mListViewAdapter.getDataList().get(position).bucketList);
extras.putString(KEY_BUNDLE_ALBUM_NAME, mListViewAdapter.getDataList().get(position).bucketName);
readyGoForResult(CommonImagePickerDetailActivity.class, IMAGE_PICKER_DETAIL_REQUEST_CODE, extras);
}
}
});
mAlbumLoadTask = new AsyncTask<Void, Void, List<ImageBucket>>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
toggleShowLoading(true, null);
ImagePickerHelper.getHelper().init(mContext);
}
@Override
protected List<ImageBucket> doInBackground(Void... params) {
return ImagePickerHelper.getHelper().getImagesBucketList();
}
@Override
protected void onPostExecute(List<ImageBucket> list) {
toggleShowLoading(false, null);
mListViewAdapter.getDataList().addAll(list);
mListViewAdapter.notifyDataSetChanged();
}
};
mAlbumLoadTask.execute();
}
use of com.github.obsessive.library.adapter.ViewHolderCreator in project SimplifyReader by chentao0707.
the class HomeActivity method initializeViews.
@Override
public void initializeViews(List<BaseLazyFragment> fragments, List<NavigationEntity> navigationList) {
mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
setTitle(getString(R.string.app_name));
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (null != mNavListAdapter) {
setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
}
}
};
mActionBarDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
if (null != fragments && !fragments.isEmpty()) {
mViewPager.setEnableScroll(false);
mViewPager.setOffscreenPageLimit(fragments.size());
mViewPager.setAdapter(new VPFragmentAdapter(getSupportFragmentManager(), fragments));
}
mNavListAdapter = new ListViewDataAdapter<NavigationEntity>(new ViewHolderCreator<NavigationEntity>() {
@Override
public ViewHolderBase<NavigationEntity> createViewHolder(int position) {
return new ViewHolderBase<NavigationEntity>() {
ImageView itemIcon;
TextView itemName;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.list_item_navigation, null);
itemIcon = ButterKnife.findById(convertView, R.id.list_item_navigation_icon);
itemName = ButterKnife.findById(convertView, R.id.list_item_navigation_name);
return convertView;
}
@Override
public void showData(int i, NavigationEntity navigationEntity) {
itemIcon.setImageResource(navigationEntity.getIconResId());
itemName.setText(navigationEntity.getName());
if (mCurrentMenuCheckedPos == i) {
// checked
itemName.setTextColor(getResources().getColor(mCheckedListItemColorResIds[i]));
} else {
// unchecked
itemName.setTextColor(getResources().getColor(android.R.color.black));
}
}
};
}
});
mNavListView.setAdapter(mNavListAdapter);
mNavListAdapter.getDataList().addAll(navigationList);
mNavListAdapter.notifyDataSetChanged();
setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
mNavListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mCurrentMenuCheckedPos = position;
mNavListAdapter.notifyDataSetChanged();
mDrawerLayout.closeDrawer(Gravity.LEFT);
mViewPager.setCurrentItem(mCurrentMenuCheckedPos, false);
}
});
}
use of com.github.obsessive.library.adapter.ViewHolderCreator in project SimplifyReader by chentao0707.
the class AboutUsActivity method initViewsAndEvents.
@Override
protected void initViewsAndEvents() {
mAboutArray = getResources().getStringArray(R.array.about_list);
mListViewDataAdapter = new ListViewDataAdapter<>(new ViewHolderCreator<AboutListEntity>() {
@Override
public ViewHolderBase<AboutListEntity> createViewHolder(int position) {
return new ViewHolderBase<AboutListEntity>() {
TextView mTitle;
TextView mSubTitle;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.list_item_about, null);
mTitle = ButterKnife.findById(convertView, R.id.list_item_about_title);
mSubTitle = ButterKnife.findById(convertView, R.id.list_item_about_sub_title);
return convertView;
}
@Override
public void showData(int position, AboutListEntity itemData) {
if (null != itemData) {
if (!CommonUtils.isEmpty(itemData.getTitle())) {
mTitle.setText(itemData.getTitle());
}
if (!CommonUtils.isEmpty(itemData.getSubTitle())) {
mSubTitle.setText(itemData.getSubTitle());
}
}
}
};
}
});
mListView.setAdapter(mListViewDataAdapter);
mItemData = new AboutListEntity();
mItemData.setTitle(mAboutArray[0]);
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
String version = String.format(getResources().getString(R.string.splash_version), packageInfo.versionName);
if (!CommonUtils.isEmpty(version)) {
mItemData.setSubTitle(version);
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
mListViewDataAdapter.getDataList().add(mItemData);
mItemData = new AboutListEntity();
mItemData.setTitle(mAboutArray[1]);
mItemData.setSubTitle("https://github.com/SkillCollege");
mListViewDataAdapter.getDataList().add(mItemData);
mItemData = new AboutListEntity();
mItemData.setTitle(mAboutArray[2]);
mItemData.setSubTitle("https://github.com/SkillCollege/SimplifyReader");
mListViewDataAdapter.getDataList().add(mItemData);
mItemData = new AboutListEntity();
mItemData.setTitle(mAboutArray[3]);
mListViewDataAdapter.getDataList().add(mItemData);
mItemData = new AboutListEntity();
mItemData.setTitle(mAboutArray[4]);
mListViewDataAdapter.getDataList().add(mItemData);
mListViewDataAdapter.notifyDataSetChanged();
mPayCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
DecodeUtils decodeUtils = new DecodeUtils(DecodeUtils.DECODE_DATA_MODE_ALL);
String url = decodeUtils.decodeWithZxing(BitmapFactory.decodeResource(getResources(), R.drawable.pay_qrcode));
if (!CommonUtils.isEmpty(url)) {
TLog.d(TAG_LOG, url);
intent.setData(Uri.parse(url));
}
startActivity(intent);
}
});
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Bundle extras = new Bundle();
switch(position) {
case 0:
// version
break;
case 1:
// author
extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[1]);
extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, true);
extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "https://github.com/SkillCollege");
readyGo(BaseWebActivity.class, extras);
break;
case 2:
// project index
extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[2]);
extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, true);
extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "https://github.com/SkillCollege/SimplifyReader");
readyGo(BaseWebActivity.class, extras);
break;
case 3:
// project description
extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[3]);
extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "file:///android_asset/project_description.html");
readyGo(BaseWebActivity.class, extras);
break;
case 4:
// open source description
extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[4]);
extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "file:///android_asset/open_source.html");
readyGo(BaseWebActivity.class, extras);
break;
}
}
});
}
use of com.github.obsessive.library.adapter.ViewHolderCreator in project SimplifyReader by chentao0707.
the class ImagesListFragment method initViewsAndEvents.
@Override
protected void initViewsAndEvents() {
mListViewAdapter = new ListViewDataAdapter<ImagesListEntity>(new ViewHolderCreator<ImagesListEntity>() {
@Override
public ViewHolderBase<ImagesListEntity> createViewHolder(int position) {
return new ViewHolderBase<ImagesListEntity>() {
PLAImageView mItemImage;
@Override
public View createView(LayoutInflater layoutInflater) {
View convertView = layoutInflater.inflate(R.layout.list_item_images_list, null);
mItemImage = ButterKnife.findById(convertView, R.id.list_item_images_list_image);
return convertView;
}
@Override
public void showData(int position, ImagesListEntity itemData) {
int width = itemData.getThumbnailWidth();
int height = itemData.getThumbnailHeight();
String imageUrl = itemData.getThumbnailUrl();
if (!CommonUtils.isEmpty(imageUrl)) {
ImageLoader.getInstance().displayImage(imageUrl, mItemImage);
}
mItemImage.setImageWidth(width);
mItemImage.setImageHeight(height);
}
};
}
});
mListView.setOnItemClickListener(this);
mListView.setOnLoadMoreListener(this);
mListView.setAdapter(mListViewAdapter);
mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.gplus_color_1), getResources().getColor(R.color.gplus_color_2), getResources().getColor(R.color.gplus_color_3), getResources().getColor(R.color.gplus_color_4));
mSwipeRefreshLayout.setOnRefreshListener(this);
}
Aggregations