• android小应用帮美女更衣系列一(附源码)


    哈哈,在苹果手机上玩过类似游戏,在eoe上发现一个兄弟也模仿做了一个,今天趁周末自己也做了一个,借用了那位兄弟的一些美女图片,应该不涉及版权吧。程序有点yellow,希望iteye管理员高台贵手 ,本意是给大家带来点乐趣。 

    为保护你的隐私,设置了密码保护。
     
    下面贴部分关键代码: 
    Java代码  收藏代码
    1. @Override  
    2.     public void onClick(View v) {  
    3.         int id = v.getId();  
    4.         switch (id) {  
    5.         case R.id.yesBtn: {  
    6.             SharedPreferences preferences = getSharedPreferences("password",Activity.MODE_PRIVATE);    
    7.             String pwd = preferences.getString("pwd""");  
    8.             if(pwd!=null&&!"".equals(pwd)){  
    9.                 if(password.getText().toString()!=""&&password.getText()!=null&&password.getText().toString().equals(pwd)){  
    10.                     //Toast.makeText(PasswordActivity.this, "密码一致,请重新输入密码", Toast.LENGTH_SHORT).show();  
    11.                     Intent intent = new Intent();  
    12.                     intent.setClass(PasswordActivity.this, SettingsActivity.class);  
    13.                     startActivity(intent);  
    14.                     PasswordActivity.this.finish();  
    15.                 }else{  
    16.                     Toast.makeText(PasswordActivity.this"密码不一致,请重新输入密码", Toast.LENGTH_SHORT).show();  
    17.                 }  
    18.             }else{  
    19.                 SharedPreferences ferences = getSharedPreferences("password",Activity.MODE_PRIVATE);  
    20.                 SharedPreferences.Editor editor = ferences.edit();  
    21.                 editor.putString("pwd", password.getText().toString());  
    22.                 editor.commit();  
    23.                 //Toast.makeText(PasswordActivity.this, "已经设置密码", Toast.LENGTH_SHORT).show();  
    24.                 Intent intent = new Intent();  
    25.                 intent.setClass(PasswordActivity.this, SettingsActivity.class);  
    26.                 startActivity(intent);  
    27.                 PasswordActivity.this.finish();  
    28.             }  
    29.               
    30.               
    31.         }  
    32.             break;  
    33.         case R.id.cancelBtn: {  
    34.             PasswordActivity.this.finish();  
    35.         }  
    36.             break;  
    37.         }  
    38.     }  


    下面是下面这张图片所显示的界面的实现,底部是一个gallery,显示大图用的是ImageSwither这个组件,一点要注意的地方是要实现ViewFactory接口并实现方法makeView(); 

     
    Java代码  收藏代码
    1. package com.picture;  
    2.   
    3. import android.app.Activity;  
    4. import android.content.Context;  
    5. import android.content.Intent;  
    6. import android.os.Bundle;  
    7. import android.view.View;  
    8. import android.view.View.OnClickListener;  
    9. import android.view.ViewGroup;  
    10. import android.widget.AdapterView;  
    11. import android.widget.AdapterView.OnItemSelectedListener;  
    12. import android.widget.BaseAdapter;  
    13. import android.widget.Gallery;  
    14. import android.widget.Gallery.LayoutParams;  
    15. import android.widget.ImageSwitcher;  
    16. import android.widget.ImageView;  
    17. import android.widget.ImageView.ScaleType;  
    18. import android.widget.Toast;  
    19. import android.widget.ViewSwitcher.ViewFactory;  
    20.   
    21. public class MainActivity extends Activity implements ViewFactory {  
    22.     private ImageSwitcher is;  
    23.     private Gallery gallery;  
    24.   
    25.     @Override  
    26.     protected void onCreate(Bundle savedInstanceState) {  
    27.         super.onCreate(savedInstanceState);  
    28.         setContentView(R.layout.main);  
    29.         setupViews();  
    30.         setupListener();  
    31.     }  
    32.       
    33.     private void setupViews(){  
    34.         is = (ImageSwitcher)findViewById(R.id.image_switcher);  
    35.         is.setFactory(this);  
    36.         gallery = (Gallery)findViewById(R.id.gallery);  
    37.         gallery.setAdapter(new ImageAdapter(MainActivity.this));  
    38.     }  
    39.     private void setupListener(){  
    40.         gallery.setOnItemSelectedListener(new OnItemSelectedListener() {  
    41.             @Override  
    42.             public void onItemSelected(AdapterView<?> parent, View view,  
    43.                     int position, long id) {  
    44.                 int drawableId = 0;  
    45.                 try {  
    46.                     drawableId = R.drawable.class.getDeclaredField(  
    47.                             "pre" + position).getInt(this);  
    48.                 } catch (IllegalArgumentException e) {  
    49.                     e.printStackTrace();  
    50.                 } catch (SecurityException e) {  
    51.                     e.printStackTrace();  
    52.                 } catch (IllegalAccessException e) {  
    53.                     e.printStackTrace();  
    54.                 } catch (NoSuchFieldException e) {  
    55.                     e.printStackTrace();  
    56.                 }  
    57.                 is.setImageResource(drawableId);  
    58.                   
    59.             }  
    60.             @Override  
    61.             public void onNothingSelected(AdapterView<?> parent) {  
    62.             }    
    63.         });  
    64.           
    65.         is.setOnClickListener(new OnClickListener() {  
    66.             @Override  
    67.             public void onClick(View v){  
    68.                 Intent intent = new Intent();  
    69.                 intent.putExtra("imagePosition", gallery.getSelectedItemPosition());  
    70.                 intent.setClass(MainActivity.this, RemoveClothActivity.class);  
    71.                 startActivity(intent);  
    72.             }  
    73.         });  
    74.     }  
    75.       
    76.     private class ImageAdapter extends BaseAdapter {  
    77.         private Context mContext;  
    78.         public ImageAdapter(Context c){  
    79.             mContext = c;  
    80.         }  
    81.         @Override  
    82.         public int getCount() {  
    83.             return 11;//11张图片  
    84.         }  
    85.         @Override  
    86.         public Object getItem(int position) {  
    87.             return position;  
    88.         }  
    89.         @Override  
    90.         public long getItemId(int position) {  
    91.             return position;  
    92.         }  
    93.   
    94.         @Override  
    95.         public View getView(int position, View convertView, ViewGroup parent) {  
    96.             ImageView imageView = new ImageView(mContext);  
    97.             int drawableId = 0;  
    98.             try {  
    99.                 drawableId = R.drawable.class.getDeclaredField(  
    100.                         "pre" + position).getInt(this);  
    101.             } catch (IllegalArgumentException e) {  
    102.                 e.printStackTrace();  
    103.             } catch (SecurityException e) {  
    104.                 e.printStackTrace();  
    105.             } catch (IllegalAccessException e) {  
    106.                 e.printStackTrace();  
    107.             } catch (NoSuchFieldException e) {  
    108.                 e.printStackTrace();  
    109.             }  
    110.             imageView.setLayoutParams(new Gallery.LayoutParams(120,120));  
    111.             imageView.setScaleType(ScaleType.FIT_XY);  
    112.             imageView.setImageResource(drawableId);  
    113.             return imageView;  
    114.         }  
    115.     }  
    116.   
    117.     @Override  
    118.     public View makeView() {  
    119.         ImageView i = new ImageView(this);  
    120.         i.setBackgroundColor(0xFF000000);  
    121.         i.setScaleType(ImageView.ScaleType.FIT_CENTER);  
    122.         i.setLayoutParams(new ImageSwitcher.LayoutParams(  
    123.                 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));  
    124.         return i;  
    125.     };  
    126. }  



  • 相关阅读:
    C#如何防止程序多次运行的技巧
    C#导出Excel按照指定格式设置单元格属性值
    js前台遍历后台返回的Datatable数据
    Datatable数据分组
    DataTable 详解(转)
    遍历Datatable
    DataTable转Json
    键值集合List转换成datatable
    DataTable转换成实体
    泛型集合与DataSet相互转换
  • 原文地址:https://www.cnblogs.com/afly/p/2360262.html
Copyright © 2020-2023  润新知