仿迅雷之Android版-私密空间弹窗验证

    上篇文章 http://blog.chinaunix.net/uid-25799257-id-4735623.html 主要构想了一下私密空间的实现,这就就做个简单的“单机版”的密码验证,根据用户对应的密码进行验证,密码正确则执行私密列表的加载,容器还是Listview,只是替换Adapter而以,Adapter的内容的管理目前我是每次都重新创建 - 也就是说每次都是重新查询的,是否会耗时了?是否会影响用户体验呢?如果每次加载10条,通过下拉刷新的话,我想应该还是没问题的,即使连接后台查询应该也OK的。  好了,多试多验证就好了。。。。
    密码弹窗验证应该也不难:
    PrivateVerifyPopwin.java

点击(此处)折叠或打开

  1. package com.errovenus.ui;

  2. import com.errorvenus.config.ScreenInfo;
  3. import com.errorvenus.fxunlei.R;

  4. import android.annotation.SuppressLint;
  5. import android.content.Context;
  6. import android.graphics.drawable.Drawable;
  7. import android.view.Gravity;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.PopupWindow;
  14. import android.widget.Toast;

  15. public class PrivateVerifyPopwin
  16. {
  17.     ///< 上下文
  18.     private Context context;
  19.     ///< 弹窗
  20.     private PopupWindow window = null;
  21.     ///< 输入密码后确认按钮
  22.     private Button passSureBtn = null;
  23.     ///< 密码框
  24.     private EditText private_passwordET = null;
  25.     ///< 弹窗布局视图
  26.     private View contentView = null;

  27.     public PrivateVerifyPopwin(Context _context)
  28.     {
  29.         this.context = _context;
  30.         if (null != window)
  31.         {
  32.             if (window.isShowing())
  33.             {
  34.                 window.dismiss();
  35.                 window = null;
  36.             }
  37.         }
  38.         window = new PopupWindow(_context);
  39.     }
  40.     
  41.     /// -----------------------me------------start-----------
  42.     
  43.     public PrivateVerifyPopwin(Context _context, Object obj)
  44.     {
  45.         this.context = _context;
  46.         ///< 初始化控件
  47.         initControl();
  48.         ///< 注册监听事件
  49.         register();
  50.     }
  51.     
  52.     /**
  53.      * 初始化控件
  54.      */
  55.     @SuppressLint("InflateParams")
  56.     private void initControl()
  57.     {
  58.         ///< 加载和设置布局
  59.         contentView = LayoutInflater.from(context).inflate(R.layout.privatepopuwin, null, true);
  60.         window = new PopupWindow(contentView, (int)ScreenInfo.SCREEN_WIDTH/2, (int)ScreenInfo.SCREEN_HEIGHT/2, true);

  61.         ///< 密码
  62.         private_passwordET = (EditText)contentView.findViewById(R.id.private_passwordET);
  63.         ///< 确认按钮
  64.         passSureBtn = (Button)contentView.findViewById(R.id.privatePassSureBtn);
  65.         
  66.         ///< 设置背景和动画
  67.         window.setBackgroundDrawable(this.context.getResources().getDrawable(R.drawable.ic_item_selected_bg));
  68.         window.setOutsideTouchable(true);
  69.         window.setAnimationStyle(R.style.anim_menu_bottombar);
  70.     }
  71.     
  72.     private void register()
  73.     {
  74.         passSureBtn.setOnClickListener(new OnClickListener()
  75.         {
  76.             
  77.             @Override
  78.             public void onClick(View v)
  79.             {
  80.                 ///< TODO 网络查询用户对应的私密空间密码是否正确,然后做处理
  81.                 ///< 单机版
  82.                 if (private_passwordET.getText().toString().equals("") || private_passwordET.getText().toString().length() < 6)
  83.                 {
  84.                     Toast.makeText(context, "请输入正确的密码,密码至少为6位", Toast.LENGTH_SHORT).show();
  85.                 }
  86.                 else if (private_passwordET.getText().toString().equals("123456"))
  87.                 {
  88.                     Toast.makeText(context, "登录成功", Toast.LENGTH_SHORT).show();
  89.                     if (null != window)
  90.                     {
  91.                         window.dismiss();
  92.                         window = null;
  93.                     }
  94.                     ///< TODO 进行私人列表展示
  95.                 }
  96.                 else
  97.                 {
  98.                     Toast.makeText(context, "密码错误", Toast.LENGTH_SHORT).show();
  99.                 }
  100.             }
  101.         });
  102.     }
  103.     
  104.     public void show(View anchor)
  105.     {
  106.         if (null != window)
  107.         {
  108.             window.showAtLocation(anchor, Gravity.CENTER, 0, 0);
  109.         }
  110.     }
  111.     
  112.     /// -----------------------me------------end-----------
  113.     
  114.     /// ------------------------自定义一些接口------------关于UI的未用-----------

  115.     public PopupWindow setBackGround(Drawable drawId)
  116.     {
  117.         if (null != window)
  118.         {
  119.             window.setBackgroundDrawable(drawId);
  120.         }
  121.         return window;
  122.     }

  123.     public PopupWindow setContentView(int layoutResID)
  124.     {
  125.         if (null != window)
  126.         {
  127.             LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  128.             window.setContentView(inflator.inflate(layoutResID, null));
  129.         }
  130.         return window;
  131.     }

  132.     public PopupWindow setOnDismissListener(PopupWindow.OnDismissListener listener)
  133.     {
  134.         if (null != window)
  135.         {
  136.             window.setOnDismissListener(listener);
  137.         }
  138.         return window;
  139.     }
  140.     
  141.     public void show(View anchor, int xoff, int yoff)
  142.     {
  143.         if (null != window)
  144.         {
  145.             window.showAsDropDown(anchor, xoff, yoff);
  146.         }
  147.     }
  148.     
  149.     public boolean isShowing()
  150.     {
  151.         if (null != window)
  152.         {
  153.             return window.isShowing();
  154.         }
  155.         return false;
  156.     }

  157.     public void dismiss()
  158.     {
  159.         if (null != window)
  160.         {
  161.             window.dismiss();
  162.         }
  163.     }
  164. }
    布局文件:
   privatepopuwin.xml
   

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:id="@+id/privatePopuLiner"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent" >

  6.     <TextView
  7.         android:id="@+id/private_tipTV"
  8.         android:layout_width="wrap_content"
  9.         android:layout_height="wrap_content"
  10.         android:layout_centerInParent="true"
  11.         android:layout_marginBottom="10dip"
  12.         android:gravity="center"
  13.         android:text="@string/privatepassStr"
  14.         android:textSize="@dimen/privatePopuTiptextSize" >
  15.     </TextView>

  16.     <EditText
  17.         android:id="@+id/private_passwordET"
  18.         android:layout_width="@dimen/editSizeWidth"
  19.         android:layout_height="@dimen/editSizeHeigth"
  20.         android:layout_below="@+id/private_tipTV"
  21.         android:layout_centerInParent="true"
  22.         android:inputType="textPassword"
  23.         android:textSize="@dimen/textSize" >
  24.     </EditText>

  25.     <Button
  26.         android:id="@+id/privatePassSureBtn"
  27.         android:layout_width="40dip"
  28.         android:layout_height="30dip"
  29.         android:layout_alignParentBottom="true"
  30.         android:layout_alignParentRight="true"
  31.         android:background="@drawable/ic_category_passsure_selector"
  32.         android:text="@string/privatepasssureStr" />

  33. </RelativeLayout>
    这里的尺寸我全部通过dimen.xml来获取,这样我做适配的时候非常方便,至少目前来看,
    的适配基本都OK了,包括字体,当然产品一般来将都是将自己做到图标上面的,这里就是学习,所以字体不在图标上啦!!
    
    大体就是这样的一个验证框:
    

    显示的时候 - 我每次dismiss之后都会把privatePopu = null, 这里如果很频繁的点击会有性能问题吗?再想想?求正规做法.....
    补充:
    后来我打印了下内存的损耗情况,大概这个popuwindow会占用2000多个byte,也就是2k左右,当privatePopu置空后,再点击,消失,再点击,这样反复几次 后,内存会从321932byte涨到368922byte,再来点击几次,又会回到32xxxx的状态,至少目前从日志上证明内存还是会回收的,不过是回收比较迟缓而已;而且再次证明其实每次重新分配,并不会耗太多性能,也不会占用太多内存。。。当然还是希望做到性能最佳....
    

点击(此处)折叠或打开

  1. ///< 私密空间
  2.         else if (v.equals(menuItem06))
  3.         {
  4.             if (null != privatePopu && privatePopu.isShowing())
  5.             {
  6.                 return;
  7.             }
  8.             else if (null != privatePopu && !privatePopu.isShowing())
  9.             {
  10.                 privatePopu.show(menuItem06);
  11.             }
  12.             else
  13.             {
  14.                 privatePopu = new PrivateVerifyPopwin(this.context, null);
  15.                 privatePopu.setOnDismissListener(new OnDismissListener()
  16.                 {
  17.                     @Override
  18.                     public void onDismiss()
  19.                     {
  20.                         privatePopu = null;
  21.                     }
  22.                 });
  23.                 privatePopu.show(menuItem06);
  24.             }
  25.         }
    下一篇是关于AndroidPN消息推送库的一些性能测试报告;至于列表的显示,适配器啥的,我想入门Android后应该剩下的是工作量或者细节上的问题,就不记录了,要是有好的知识再记录下吧....


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。