use of android.widget.GridView in project ion by koush.
the class ImageSearch method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Ion.getDefault(this).configure().setLogging("ion-sample", Log.DEBUG);
setContentView(R.layout.image_search);
final Button search = (Button) findViewById(R.id.search);
searchText = (EditText) findViewById(R.id.search_text);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
search();
}
});
int cols = getResources().getDisplayMetrics().widthPixels / getResources().getDisplayMetrics().densityDpi;
GridView view = (GridView) findViewById(R.id.results);
view.setNumColumns(cols);
mAdapter = new MyAdapter(this);
view.setAdapter(mAdapter);
search();
}
use of android.widget.GridView in project FolderLayout by kyze8439690.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFolderLayout = (FolderLayout) findViewById(R.id.folder_layout);
text1 = (TextView) findViewById(R.id.item1);
text2 = (TextView) findViewById(R.id.item2);
text3 = (TextView) findViewById(R.id.item3);
text4 = (TextView) findViewById(R.id.item4);
text1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mFolderLayout.toggleItem(3);
}
});
text2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mFolderLayout.toggleItem(2);
}
});
text3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mFolderLayout.toggleItem(1);
}
});
text4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mFolderLayout.toggleItem(0);
}
});
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return new ListFragment();
}
@Override
public int getCount() {
return 3;
}
});
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[] { "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item", "list item" });
mListView = (ListView) findViewById(R.id.list);
mListView.setAdapter(adapter);
mGridView = (GridView) findViewById(R.id.grid);
mGridView.setAdapter(adapter);
}
use of android.widget.GridView in project UltimateAndroid by cymcsg.
the class MultiImageSelectorFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// 选择图片数量
mDesireImageCount = getArguments().getInt(EXTRA_SELECT_COUNT);
// 图片选择模式
final int mode = getArguments().getInt(EXTRA_SELECT_MODE);
// 默认选择
if (mode == MODE_MULTI) {
ArrayList<String> tmp = getArguments().getStringArrayList(EXTRA_DEFAULT_SELECTED_LIST);
if (tmp != null && tmp.size() > 0) {
resultList = tmp;
}
}
// 是否显示照相机
final boolean showCamera = getArguments().getBoolean(EXTRA_SHOW_CAMERA, true);
mImageAdapter = new ImageGridAdapter(getActivity(), showCamera);
// 是否显示选择指示器
mImageAdapter.showSelectIndicator(mode == MODE_MULTI);
// 如果显示了照相机,则创建临时文件
if (showCamera) {
mTmpFile = FileUtils.createTmpFile(getActivity());
}
mPopupAnchorView = view.findViewById(R.id.footer);
mTimeLineText = (TextView) view.findViewById(R.id.timeline_area);
// 初始化,先隐藏当前timeline
mTimeLineText.setVisibility(View.GONE);
mCategoryText = (TextView) view.findViewById(R.id.category_btn);
// 初始化,加载所有图片
mCategoryText.setText("folder_all");
mCategoryText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mFolderPopupWindow.isShowing()) {
mFolderPopupWindow.dismiss();
} else {
mFolderPopupWindow.show();
int index = mFolderAdapter.getSelectIndex();
index = index == 0 ? index : index - 1;
mFolderPopupWindow.getListView().setSelection(index);
}
}
});
mPreviewBtn = (Button) view.findViewById(R.id.preview);
// 初始化,按钮状态初始化
if (resultList == null || resultList.size() <= 0) {
mPreviewBtn.setText("preview");
mPreviewBtn.setEnabled(false);
}
mPreviewBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO 预览
}
});
mGridView = (GridView) view.findViewById(R.id.grid);
mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int state) {
final Picasso picasso = Picasso.with(getActivity());
if (state == SCROLL_STATE_IDLE || state == SCROLL_STATE_TOUCH_SCROLL) {
picasso.resumeTag(getActivity());
} else {
picasso.pauseTag(getActivity());
}
if (state == SCROLL_STATE_IDLE) {
// 停止滑动,日期指示器消失
mTimeLineText.setVisibility(View.GONE);
} else if (state == SCROLL_STATE_FLING) {
mTimeLineText.setVisibility(View.VISIBLE);
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (mTimeLineText.getVisibility() == View.VISIBLE) {
int index = firstVisibleItem + 1 == view.getAdapter().getCount() ? view.getAdapter().getCount() - 1 : firstVisibleItem + 1;
Image image = (Image) view.getAdapter().getItem(index);
if (image != null) {
mTimeLineText.setText(TimeUtils.formatPhotoDate(image.path));
}
}
}
});
mGridView.setAdapter(mImageAdapter);
mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void onGlobalLayout() {
final int width = mGridView.getWidth();
final int height = mGridView.getHeight();
final int desireSize = getResources().getDimensionPixelOffset(R.dimen.multi_image_select_image_size);
final int numCount = width / desireSize;
final int columnSpace = getResources().getDimensionPixelOffset(R.dimen.multi_image_select_space_size);
int columnWidth = (width - columnSpace * (numCount - 1)) / numCount;
mImageAdapter.setItemSize(columnWidth);
if (mFolderPopupWindow == null) {
createPopupFolderList(width, height);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (mImageAdapter.isShowCamera()) {
// 如果显示照相机,则第一个Grid显示为照相机,处理特殊逻辑
if (i == 0) {
showCameraAction();
} else {
// 正常操作
Image image = (Image) adapterView.getAdapter().getItem(i);
selectImageFromGrid(image, mode);
}
} else {
// 正常操作
Image image = (Image) adapterView.getAdapter().getItem(i);
selectImageFromGrid(image, mode);
}
}
});
mFolderAdapter = new FolderAdapter(getActivity());
}
use of android.widget.GridView in project UltimateAndroid by cymcsg.
the class ImageBucketActivity method initView.
/**
* 初始化view视图
*/
private void initView() {
gridView = (GridView) findViewById(R.id.gridview);
adapter = new ImageBucketAdapter(ImageBucketActivity.this, dataList);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/**
* 根据position参数,可以获得跟GridView的子View相绑定的实体类,然后根据它的isSelected状态,
* 来判断是否显示选中效果。 至于选中效果的规则,下面适配器的代码中会有说明
*/
// if(dataList.get(position).isSelected()){
// dataList.get(position).setSelected(false);
// }else{
// dataList.get(position).setSelected(true);
// }
/**
* 通知适配器,绑定的数据发生了改变,应当刷新视图
*/
// adapter.notifyDataSetChanged();
Intent intent = new Intent(ImageBucketActivity.this, ImageGridActivity.class);
intent.putExtra(ImageBucketActivity.EXTRA_IMAGE_LIST, (Serializable) dataList.get(position).imageList);
startActivity(intent);
finish();
}
});
}
use of android.widget.GridView in project UltimateAndroid by cymcsg.
the class ImageGridActivity method initView.
private void initView() {
gridView = (GridView) findViewById(R.id.gridview);
gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
adapter = new ImageGridAdapter(ImageGridActivity.this, dataList, mHandler);
gridView.setAdapter(adapter);
adapter.setTextCallback(new ImageGridAdapter.TextCallback() {
public void onListen(int count) {
bt.setText("完成" + "(" + count + ")");
}
});
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
adapter.notifyDataSetChanged();
}
});
}
Aggregations