仿迅雷之Android版-私密空间弹窗验证
密码弹窗验证应该也不难:
PrivateVerifyPopwin.java
点击(此处)折叠或打开
-
package com.errovenus.ui;
-
-
import com.errorvenus.config.ScreenInfo;
-
import com.errorvenus.fxunlei.R;
-
-
import android.annotation.SuppressLint;
-
import android.content.Context;
-
import android.graphics.drawable.Drawable;
-
import android.view.Gravity;
-
import android.view.LayoutInflater;
-
import android.view.View;
-
import android.view.View.OnClickListener;
-
import android.widget.Button;
-
import android.widget.EditText;
-
import android.widget.PopupWindow;
-
import android.widget.Toast;
-
-
public class PrivateVerifyPopwin
-
{
-
///< 上下文
-
private Context context;
-
///< 弹窗
-
private PopupWindow window = null;
-
///< 输入密码后确认按钮
-
private Button passSureBtn = null;
-
///< 密码框
-
private EditText private_passwordET = null;
-
///< 弹窗布局视图
-
private View contentView = null;
-
-
public PrivateVerifyPopwin(Context _context)
-
{
-
this.context = _context;
-
if (null != window)
-
{
-
if (window.isShowing())
-
{
-
window.dismiss();
-
window = null;
-
}
-
}
-
window = new PopupWindow(_context);
-
}
-
-
/// -----------------------me------------start-----------
-
-
public PrivateVerifyPopwin(Context _context, Object obj)
-
{
-
this.context = _context;
-
///< 初始化控件
-
initControl();
-
///< 注册监听事件
-
register();
-
}
-
-
/**
-
* 初始化控件
-
*/
-
@SuppressLint("InflateParams")
-
private void initControl()
-
{
-
///< 加载和设置布局
-
contentView = LayoutInflater.from(context).inflate(R.layout.privatepopuwin, null, true);
-
window = new PopupWindow(contentView, (int)ScreenInfo.SCREEN_WIDTH/2, (int)ScreenInfo.SCREEN_HEIGHT/2, true);
-
-
///< 密码
-
private_passwordET = (EditText)contentView.findViewById(R.id.private_passwordET);
-
///< 确认按钮
-
passSureBtn = (Button)contentView.findViewById(R.id.privatePassSureBtn);
-
-
///< 设置背景和动画
-
window.setBackgroundDrawable(this.context.getResources().getDrawable(R.drawable.ic_item_selected_bg));
-
window.setOutsideTouchable(true);
-
window.setAnimationStyle(R.style.anim_menu_bottombar);
-
}
-
-
private void register()
-
{
-
passSureBtn.setOnClickListener(new OnClickListener()
-
{
-
-
@Override
-
public void onClick(View v)
-
{
-
///< TODO 网络查询用户对应的私密空间密码是否正确,然后做处理
-
///< 单机版
-
if (private_passwordET.getText().toString().equals("") || private_passwordET.getText().toString().length() < 6)
-
{
-
Toast.makeText(context, "请输入正确的密码,密码至少为6位", Toast.LENGTH_SHORT).show();
-
}
-
else if (private_passwordET.getText().toString().equals("123456"))
-
{
-
Toast.makeText(context, "登录成功", Toast.LENGTH_SHORT).show();
-
if (null != window)
-
{
-
window.dismiss();
-
window = null;
-
}
-
///< TODO 进行私人列表展示
-
}
-
else
-
{
-
Toast.makeText(context, "密码错误", Toast.LENGTH_SHORT).show();
-
}
-
}
-
});
-
}
-
-
public void show(View anchor)
-
{
-
if (null != window)
-
{
-
window.showAtLocation(anchor, Gravity.CENTER, 0, 0);
-
}
-
}
-
-
/// -----------------------me------------end-----------
-
-
/// ------------------------自定义一些接口------------关于UI的未用-----------
-
-
public PopupWindow setBackGround(Drawable drawId)
-
{
-
if (null != window)
-
{
-
window.setBackgroundDrawable(drawId);
-
}
-
return window;
-
}
-
-
public PopupWindow setContentView(int layoutResID)
-
{
-
if (null != window)
-
{
-
LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
window.setContentView(inflator.inflate(layoutResID, null));
-
}
-
return window;
-
}
-
-
public PopupWindow setOnDismissListener(PopupWindow.OnDismissListener listener)
-
{
-
if (null != window)
-
{
-
window.setOnDismissListener(listener);
-
}
-
return window;
-
}
-
-
public void show(View anchor, int xoff, int yoff)
-
{
-
if (null != window)
-
{
-
window.showAsDropDown(anchor, xoff, yoff);
-
}
-
}
-
-
public boolean isShowing()
-
{
-
if (null != window)
-
{
-
return window.isShowing();
-
}
-
return false;
-
}
-
-
public void dismiss()
-
{
-
if (null != window)
-
{
-
window.dismiss();
-
}
-
}
- }
privatepopuwin.xml
点击(此处)折叠或打开
-
<?xml version="1.0" encoding="utf-8"?>
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-
android:id="@+id/privatePopuLiner"
-
android:layout_width="fill_parent"
-
android:layout_height="fill_parent" >
-
-
<TextView
-
android:id="@+id/private_tipTV"
-
android:layout_width="wrap_content"
-
android:layout_height="wrap_content"
-
android:layout_centerInParent="true"
-
android:layout_marginBottom="10dip"
-
android:gravity="center"
-
android:text="@string/privatepassStr"
-
android:textSize="@dimen/privatePopuTiptextSize" >
-
</TextView>
-
-
<EditText
-
android:id="@+id/private_passwordET"
-
android:layout_width="@dimen/editSizeWidth"
-
android:layout_height="@dimen/editSizeHeigth"
-
android:layout_below="@+id/private_tipTV"
-
android:layout_centerInParent="true"
-
android:inputType="textPassword"
-
android:textSize="@dimen/textSize" >
-
</EditText>
-
-
<Button
-
android:id="@+id/privatePassSureBtn"
-
android:layout_width="40dip"
-
android:layout_height="30dip"
-
android:layout_alignParentBottom="true"
-
android:layout_alignParentRight="true"
-
android:background="@drawable/ic_category_passsure_selector"
-
android:text="@string/privatepasssureStr" />
-
- </RelativeLayout>
的适配基本都OK了,包括字体,当然产品一般来将都是将自己做到图标上面的,这里就是学习,所以字体不在图标上啦!!
大体就是这样的一个验证框:
显示的时候 - 我每次dismiss之后都会把privatePopu = null, 这里如果很频繁的点击会有性能问题吗?再想想?求正规做法.....:
补充:
后来我打印了下内存的损耗情况,大概这个popuwindow会占用2000多个byte,也就是2k左右,当privatePopu置空后,再点击,消失,再点击,这样反复几次 后,内存会从321932byte涨到368922byte,再来点击几次,又会回到32xxxx的状态,至少目前从日志上证明内存还是会回收的,不过是回收比较迟缓而已;而且再次证明其实每次重新分配,并不会耗太多性能,也不会占用太多内存。。。当然还是希望做到性能最佳....
点击(此处)折叠或打开
-
///< 私密空间
-
else if (v.equals(menuItem06))
-
{
-
if (null != privatePopu && privatePopu.isShowing())
-
{
-
return;
-
}
-
else if (null != privatePopu && !privatePopu.isShowing())
-
{
-
privatePopu.show(menuItem06);
-
}
-
else
-
{
-
privatePopu = new PrivateVerifyPopwin(this.context, null);
-
privatePopu.setOnDismissListener(new OnDismissListener()
-
{
-
@Override
-
public void onDismiss()
-
{
-
privatePopu = null;
-
}
-
});
-
privatePopu.show(menuItem06);
-
}
- }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。