哈哈,在苹果手机上玩过类似游戏,在eoe上发现一个兄弟也模仿做了一个,今天趁周末自己也做了一个,借用了那位兄弟的一些美女图片,应该不涉及版权吧。程序有点yellow,希望iteye管理员高台贵手 ,本意是给大家带来点乐趣。
为保护你的隐私,设置了密码保护。
下面贴部分关键代码:
下面是下面这张图片所显示的界面的实现,底部是一个gallery,显示大图用的是ImageSwither这个组件,一点要注意的地方是要实现ViewFactory接口并实现方法makeView();
为保护你的隐私,设置了密码保护。
下面贴部分关键代码:
- @Override
- public void onClick(View v) {
- int id = v.getId();
- switch (id) {
- case R.id.yesBtn: {
- SharedPreferences preferences = getSharedPreferences("password",Activity.MODE_PRIVATE);
- String pwd = preferences.getString("pwd", "");
- if(pwd!=null&&!"".equals(pwd)){
- if(password.getText().toString()!=""&&password.getText()!=null&&password.getText().toString().equals(pwd)){
- //Toast.makeText(PasswordActivity.this, "密码一致,请重新输入密码", Toast.LENGTH_SHORT).show();
- Intent intent = new Intent();
- intent.setClass(PasswordActivity.this, SettingsActivity.class);
- startActivity(intent);
- PasswordActivity.this.finish();
- }else{
- Toast.makeText(PasswordActivity.this, "密码不一致,请重新输入密码", Toast.LENGTH_SHORT).show();
- }
- }else{
- SharedPreferences ferences = getSharedPreferences("password",Activity.MODE_PRIVATE);
- SharedPreferences.Editor editor = ferences.edit();
- editor.putString("pwd", password.getText().toString());
- editor.commit();
- //Toast.makeText(PasswordActivity.this, "已经设置密码", Toast.LENGTH_SHORT).show();
- Intent intent = new Intent();
- intent.setClass(PasswordActivity.this, SettingsActivity.class);
- startActivity(intent);
- PasswordActivity.this.finish();
- }
- }
- break;
- case R.id.cancelBtn: {
- PasswordActivity.this.finish();
- }
- break;
- }
- }
下面是下面这张图片所显示的界面的实现,底部是一个gallery,显示大图用的是ImageSwither这个组件,一点要注意的地方是要实现ViewFactory接口并实现方法makeView();
- package com.picture;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemSelectedListener;
- import android.widget.BaseAdapter;
- import android.widget.Gallery;
- import android.widget.Gallery.LayoutParams;
- import android.widget.ImageSwitcher;
- import android.widget.ImageView;
- import android.widget.ImageView.ScaleType;
- import android.widget.Toast;
- import android.widget.ViewSwitcher.ViewFactory;
- public class MainActivity extends Activity implements ViewFactory {
- private ImageSwitcher is;
- private Gallery gallery;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- setupViews();
- setupListener();
- }
- private void setupViews(){
- is = (ImageSwitcher)findViewById(R.id.image_switcher);
- is.setFactory(this);
- gallery = (Gallery)findViewById(R.id.gallery);
- gallery.setAdapter(new ImageAdapter(MainActivity.this));
- }
- private void setupListener(){
- gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view,
- int position, long id) {
- int drawableId = 0;
- try {
- drawableId = R.drawable.class.getDeclaredField(
- "pre" + position).getInt(this);
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- is.setImageResource(drawableId);
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- is.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v){
- Intent intent = new Intent();
- intent.putExtra("imagePosition", gallery.getSelectedItemPosition());
- intent.setClass(MainActivity.this, RemoveClothActivity.class);
- startActivity(intent);
- }
- });
- }
- private class ImageAdapter extends BaseAdapter {
- private Context mContext;
- public ImageAdapter(Context c){
- mContext = c;
- }
- @Override
- public int getCount() {
- return 11;//11张图片
- }
- @Override
- public Object getItem(int position) {
- return position;
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView imageView = new ImageView(mContext);
- int drawableId = 0;
- try {
- drawableId = R.drawable.class.getDeclaredField(
- "pre" + position).getInt(this);
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- imageView.setLayoutParams(new Gallery.LayoutParams(120,120));
- imageView.setScaleType(ScaleType.FIT_XY);
- imageView.setImageResource(drawableId);
- return imageView;
- }
- }
- @Override
- public View makeView() {
- ImageView i = new ImageView(this);
- i.setBackgroundColor(0xFF000000);
- i.setScaleType(ImageView.ScaleType.FIT_CENTER);
- i.setLayoutParams(new ImageSwitcher.LayoutParams(
- LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
- return i;
- };
- }