package com.lee.gallery3d;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Toast;
import com.lee.gallery3d.utils.BitmapUtil;
import com.lee.gallery3d.widget.GalleryFlow;
public class GalleryFlowActivity extends Activity
{
GalleryFlow mGallery = null;
ArrayList<BitmapDrawable> mBitmaps = new ArrayList<BitmapDrawable>();
View.OnClickListener mListener = new View.OnClickListener()
{
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.space_confirm_btn:
onSpaceBtnClick(v);
break;
case R.id.max_zoom_confirm_btn:
onMaxZoomBtnClick(v);
break;
case R.id.max_rotate_angle_confirm_btn:
onMaxAngleBtnClick(v);
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
generateBitmaps();
mGallery = (GalleryFlow) findViewById(R.id.gallery_flow);
mGallery.setBackgroundColor(Color.GRAY);
mGallery.setSpacing(50);
mGallery.setFadingEdgeLength(0);
mGallery.setGravity(Gravity.CENTER_VERTICAL);
mGallery.setAdapter(new GalleryAdapter());
findViewById(R.id.space_confirm_btn).setOnClickListener(mListener);
findViewById(R.id.max_zoom_confirm_btn).setOnClickListener(mListener);
findViewById(R.id.max_rotate_angle_confirm_btn).setOnClickListener(mListener);
}
private void onSpaceBtnClick(View v)
{
EditText editText = (EditText) findViewById(R.id.space_edittext);
String text = editText.getText().toString();
try
{
int spacing = Integer.parseInt(text);
if (spacing >= -60 && spacing <= 60)
{
mGallery.setSpacing(spacing);
((GalleryAdapter)mGallery.getAdapter()).notifyDataSetChanged();
}
else
{
Toast.makeText(this,
getResources().getString(R.string.gallery_space_text_hint),
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void onMaxZoomBtnClick(View v)
{
EditText editText = (EditText) findViewById(R.id.max_zoom_edittext);
String text = editText.getText().toString();
try
{
int maxZoom = Integer.parseInt(text);
if (maxZoom >= -120 && maxZoom <= 120)
{
mGallery.setMaxZoom(maxZoom);
((GalleryAdapter)mGallery.getAdapter()).notifyDataSetChanged();
}
else
{
Toast.makeText(this,
getResources().getString(R.string.gallery_max_zoom_text_hint),
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void onMaxAngleBtnClick(View v)
{
EditText editText = (EditText) findViewById(R.id.max_rotate_angle_edittext);
String text = editText.getText().toString();
try
{
int maxRotationAngle = Integer.parseInt(text);
if (maxRotationAngle >= -60 && maxRotationAngle <= 60)
{
mGallery.setMaxRotationAngle(maxRotationAngle);
((GalleryAdapter)mGallery.getAdapter()).notifyDataSetChanged();
}
else
{
Toast.makeText(this,
getResources().getString(R.string.gallery_max_rotate_angle_text_hint),
Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private void generateBitmaps()
{
int[] ids =
{
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.f,
R.drawable.g,
R.drawable.h,
R.drawable.i,
R.drawable.j,
R.drawable.k,
R.drawable.l,
R.drawable.m,
R.drawable.n,
R.drawable.o,
R.drawable.p,
R.drawable.q,
R.drawable.r,
R.drawable.s,
R.drawable.t,
R.drawable.u,
R.drawable.v,
R.drawable.w,
R.drawable.x,
R.drawable.y,
R.drawable.z,
R.drawable.aa,
};
for (int id : ids)
{
Bitmap bitmap = createReflectedBitmapById(id);
if (null != bitmap)
{
BitmapDrawable drawable = new BitmapDrawable(bitmap);
drawable.setAntiAlias(true);
mBitmaps.add(drawable);
}
}
}
private Bitmap createReflectedBitmapById(int resId)
{
Drawable drawable = getResources().getDrawable(resId);
if (drawable instanceof BitmapDrawable)
{
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
Bitmap reflectedBitmap = BitmapUtil.createReflectedBitmap(bitmap);
return reflectedBitmap;
}
return null;
}
private class GalleryAdapter extends BaseAdapter
{
@Override
public int getCount()
{
return mBitmaps.size();
}
@Override
public Object getItem(int position)
{
return null;
}
@Override
public long getItemId(int position)
{
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (null == convertView)
{
convertView = new MyImageView(GalleryFlowActivity.this);
convertView.setLayoutParams(new Gallery.LayoutParams(110, 184));
}
ImageView imageView = (ImageView)convertView;
imageView.setImageDrawable(mBitmaps.get(position));
imageView.setScaleType(ScaleType.FIT_XY);
return imageView;
}
}
private class MyImageView extends ImageView
{
public MyImageView(Context context)
{
this(context, null);
}
public MyImageView(Context context, AttributeSet attrs)
{
super(context, attrs, 0);
}
public MyImageView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
GalleryFlow(3D倒影效果).rar (38个子文件)
GalleryFlow
GalleryFlow
.project 847B
default.properties 361B
bin
AndroidManifest.xml 783B
jarlist.cache 119B
res
classes
com
lee
gallery3d
GalleryFlowActivity$GalleryAdapter.class 2KB
utils
BitmapUtil.class 4KB
GalleryFlowActivity.class 4KB
widget
GalleryFlow.class 4KB
GalleryFlowActivity$MyImageView.class 1KB
BuildConfig.class 343B
GalleryFlowActivity$1.class 941B
proguard.cfg 1KB
AndroidManifest.xml 783B
src
com
lee
gallery3d
GalleryFlowActivity.java 8KB
utils
BitmapUtil.java 5KB
widget
GalleryFlow.java 5KB
project.properties 361B
res
values
strings.xml 875B
layout
main.xml 4KB
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable
i.png 51KB
j.png 44KB
b.png 45KB
e.png 51KB
d.png 44KB
c.png 49KB
k.png 29KB
a.png 37KB
l.png 47KB
h.png 46KB
f.png 48KB
g.png 38KB
drawable-mdpi
ic_launcher.png 3KB
.classpath 364B
gen
com
lee
gallery3d
BuildConfig.java 159B
assets
GalleryFlow.apk 981KB
ReadMe.docx 193KB
共 38 条
- 1
资源评论
- u0101461882014-08-04哈哈,是我要的效果,谢谢
- panyangdehao2014-05-07不是我要的C++版本的程序,纠结
- Omikilong2013-03-22很不错,还可以设置的!
姚虎才子
- 粉丝: 29
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功