仿迅雷之Android版-私密空間彈窗驗證

來源:互聯網
上載者:User

仿迅雷之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. /// -----------------------me------------start-----------

  41. public PrivateVerifyPopwin(Context _context, Object obj)
  42. {
  43. this.context = _context;
  44. ///< 初始化控制項
  45. initControl();
  46. ///< 註冊監聽事件
  47. register();
  48. }

  49. /**
  50. * 初始化控制項
  51. */
  52. @SuppressLint("InflateParams")
  53. private void initControl()
  54. {
  55. ///< 載入和設定布局
  56. contentView = LayoutInflater.from(context).inflate(R.layout.privatepopuwin, null, true);
  57. window = new PopupWindow(contentView, (int)ScreenInfo.SCREEN_WIDTH/2, (int)ScreenInfo.SCREEN_HEIGHT/2, true);

  58. ///< 密碼
  59. private_passwordET = (EditText)contentView.findViewById(R.id.private_passwordET);
  60. ///< 確認按鈕
  61. passSureBtn = (Button)contentView.findViewById(R.id.privatePassSureBtn);

  62. ///< 設定背景和動畫
  63. window.setBackgroundDrawable(this.context.getResources().getDrawable(R.drawable.ic_item_selected_bg));
  64. window.setOutsideTouchable(true);
  65. window.setAnimationStyle(R.style.anim_menu_bottombar);
  66. }

  67. private void register()
  68. {
  69. passSureBtn.setOnClickListener(new OnClickListener()
  70. {

  71. @Override
  72. public void onClick(View v)
  73. {
  74. ///< TODO 網路查詢使用者對應的私密空間密碼是否正確,然後做處理
  75. ///< 單機版
  76. if (private_passwordET.getText().toString().equals("") || private_passwordET.getText().toString().length() < 6)
  77. {
  78. Toast.makeText(context, "請輸入正確的密碼,密碼至少為6位", Toast.LENGTH_SHORT).show();
  79. }
  80. else if (private_passwordET.getText().toString().equals("123456"))
  81. {
  82. Toast.makeText(context, "登入成功", Toast.LENGTH_SHORT).show();
  83. if (null != window)
  84. {
  85. window.dismiss();
  86. window = null;
  87. }
  88. ///< TODO 進行私人列表展示
  89. }
  90. else
  91. {
  92. Toast.makeText(context, "密碼錯誤", Toast.LENGTH_SHORT).show();
  93. }
  94. }
  95. });
  96. }

  97. public void show(View anchor)
  98. {
  99. if (null != window)
  100. {
  101. window.showAtLocation(anchor, Gravity.CENTER, 0, 0);
  102. }
  103. }

  104. /// -----------------------me------------end-----------

  105. /// ------------------------自訂一些介面------------關於UI的未用-----------

  106. public PopupWindow setBackGround(Drawable drawId)
  107. {
  108. if (null != window)
  109. {
  110. window.setBackgroundDrawable(drawId);
  111. }
  112. return window;
  113. }

  114. public PopupWindow setContentView(int layoutResID)
  115. {
  116. if (null != window)
  117. {
  118. LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  119. window.setContentView(inflator.inflate(layoutResID, null));
  120. }
  121. return window;
  122. }

  123. public PopupWindow setOnDismissListener(PopupWindow.OnDismissListener listener)
  124. {
  125. if (null != window)
  126. {
  127. window.setOnDismissListener(listener);
  128. }
  129. return window;
  130. }

  131. public void show(View anchor, int xoff, int yoff)
  132. {
  133. if (null != window)
  134. {
  135. window.showAsDropDown(anchor, xoff, yoff);
  136. }
  137. }

  138. public boolean isShowing()
  139. {
  140. if (null != window)
  141. {
  142. return window.isShowing();
  143. }
  144. return false;
  145. }

  146. public void dismiss()
  147. {
  148. if (null != window)
  149. {
  150. window.dismiss();
  151. }
  152. }
  153. }
布局檔案:
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後應該剩下的是工作量或者細節上的問題,就不記錄了,要是有好的知識再記錄下吧....


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.