xuxiuxi
2017-03-28 0588949cb2006680be01ab4cb5599b985b082edc


git-svn-id: http://192.168.1.226/svn/proxy@211 454eff88-639b-444f-9e54-f578c98de674
2个文件已添加
1个文件已修改
214 ■■■■■ 已修改文件
VisitFace/DemoForBsk/app/src/main/java/com/bsk/zhangbo/demoforbsk/widget/VisitPurposePopup.java 144 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/DemoForBsk/app/src/main/res/layout/visit_purpose_popup.xml 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/DemoForBsk/app/src/main/res/values/strings.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/DemoForBsk/app/src/main/java/com/bsk/zhangbo/demoforbsk/widget/VisitPurposePopup.java
New file
@@ -0,0 +1,144 @@
package com.bsk.zhangbo.demoforbsk.widget;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bsk.zhangbo.demoforbsk.R;
import com.bsk.zhangbo.demoforbsk.adapter.MyWheelAdapter;
import com.bsk.zhangbo.demoforbsk.listeners.OkButtonClickedListener;
import com.wx.wheelview.widget.WheelView;
import java.util.ArrayList;
import java.util.List;
import cn.com.basic.face.discern.entity.Dictionary;
/**
 * Created by Sinoe on 2017/2/27.
 */
public class VisitPurposePopup extends PopupWindow implements View.OnClickListener,WheelView.OnWheelItemSelectedListener{
    private View view;
    private TextView mTvConfirm,mTvCancel,mTvTitle;
    private List mList;
    private WheelView mWheelView;
    private Context mContext;
    public VisitPurposePopup(Context context, List mList, String mTitle) {
        this.mContext = context;
        view = LayoutInflater.from(context).inflate(R.layout.visit_purpose_popup,null);
        this.mList = mList;
        mTvTitle = (TextView) view.findViewById(R.id.pop_single_title);
        if (mTitle !=null && mTitle.length() > 0){
            mTvTitle.setText(mTitle);
        }else {
            mTvTitle.setText("标题");
        }
        mWheelView = (WheelView) view.findViewById(R.id. pop_single_wheel);
        mWheelView.setOnWheelItemSelectedListener(this);
        mTvCancel = (TextView) view.findViewById(R.id.pop_single_cancel);
        mTvConfirm = (TextView) view.findViewById(R.id.pop_single_confirm);
        mTvCancel.setOnClickListener(this);
        mTvConfirm.setOnClickListener(this);
        mWheelView.setWheelAdapter(new MyWheelAdapter(context));
        mWheelView.setSkin(WheelView.Skin.Holo);
        if (mList != null && mList.size() > 0) {
            mWheelView.setWheelData(mList);
        }
        mWheelView.setWheelSize(5);
        mWheelView.setBackgroundResource(R.color.colorBackground);
        WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
        style.selectedTextColor = Color.parseColor("#11c3e3");
        style.textColor = Color.parseColor("#bcc6cf");
        style.selectedTextSize = 22;
        style.textSize = 16;
        style.holoBorderColor = Color.parseColor("#11c3e3");
        mWheelView.setStyle(style);
        //外部可点击
        setOutsideTouchable(true);
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
            View popLayout = view.findViewById(R.id.pop_single_ll);
            int top = popLayout.getTop();
            int bottom = popLayout.getBottom();
            int left = popLayout.getLeft();
            int right = popLayout.getRight();
            int y = (int) motionEvent.getY();
            int x = (int) motionEvent.getX();
            if (motionEvent.getAction() == MotionEvent.ACTION_UP){
                if (y<top || y> bottom){
                    dismiss();
                }
                if (x < left || x > right){
                    dismiss();
                }
            }
            return true;
            }
        });
        /*
             设置窗口特征
         */
        //设置视图
        this.setContentView(this.view);
        //设置窗口宽高
        this.setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        //设置弹出窗口可点击
        this.setFocusable(true);
        //实例化Color
        ColorDrawable colorDrawable = new ColorDrawable(0x7f000000);
        this.setBackgroundDrawable(colorDrawable);
        this.setAnimationStyle(R.style.PopupAnimation);
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.pop_single_cancel:
                dismiss();
                break;
            case R.id.pop_single_add:
                dismiss();
                break;
            case R.id.pop_single_confirm:
                for (OkButtonClickedListener okButtonClickedListener : okButtonClickedListeners) {
                    if (mWheelView.getCurrentPosition() >= 0) {
                        Object o = mList.get(mWheelView.getCurrentPosition());
                        String item = "";
                        if (o instanceof Dictionary) {
                            item = ((Dictionary) o).getName();
                        } else {
                            item = o+"";
                        }
                        okButtonClickedListener.onItemSelected(mWheelView.getCurrentPosition(), o, item);
                    }
                }
                dismiss();
                break;
        }
    }
    @Override
    public void onItemSelected(int position, Object o) {
        //Toast.makeText(mContext,mList.get(position),Toast.LENGTH_SHORT).show();
    }
    private List<OkButtonClickedListener> okButtonClickedListeners = new ArrayList<OkButtonClickedListener>();
    public void addOkButtonClickedListener(OkButtonClickedListener okButtonClickedListener) {
        this.okButtonClickedListeners.add(okButtonClickedListener);
    }
}
VisitFace/DemoForBsk/app/src/main/res/layout/visit_purpose_popup.xml
New file
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/pop_single_ll"
        android:layout_width="350dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="@android:color/white"
        android:orientation="vertical">
        <TextView
            android:id="@+id/pop_single_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:gravity="center"
            android:textColor="@android:color/white"
            android:textSize="@dimen/text_size_big"
            android:background="@color/colorPrimary"/>
        <com.wx.wheelview.widget.WheelView
            android:id="@+id/pop_single_wheel"
            android:layout_width="200dp"
            android:layout_height="wrap_content"></com.wx.wheelview.widget.WheelView>
        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:background="@color/colorText_5"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal">
            <TextView
            android:id="@+id/pop_single_confirm"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="@string/confirm"
            android:textSize="@dimen/text_size_big"/>
            <View
                android:layout_width="0.5dp"
                android:layout_height="match_parent"
                android:background="@color/colorText_5"/>
            <TextView
                android:id="@+id/pop_single_add"
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="@string/add"
                android:textSize="@dimen/text_size_big"/>
            <View
                android:layout_width="0.5dp"
                android:layout_height="match_parent"
                android:background="@color/colorText_5"/>
            <TextView
                android:id="@+id/pop_single_cancel"
                android:layout_weight="1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="@string/cancel"
                android:textSize="@dimen/text_size_big"/>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
VisitFace/DemoForBsk/app/src/main/res/values/strings.xml
@@ -23,6 +23,7 @@
    <string name="confirm">确认</string>
    <string name="add">添加</string>
    <string name="cancel">取消</string>