android listview仿iphone通讯录ios 3dTouch

接上篇android listview仿ios 3dTouch效果,对代码进行整合进类似ios通讯录里面,效果图如下:

                android listview仿iphone通讯录ios 3dTouch_第1张图片    、android listview仿iphone通讯录ios 3dTouch_第2张图片


效果如上,在上篇的内容后面跳出电话信息。

popmenu布局文件代码





    
        
        
            
        
        
    

    

        

            

            
        

        

            

            
        
    
在源代码中,通讯录的点击事件的页面是在Fragment里面的,这时候不能将高斯模糊的图片放在该布局上,要放到对应的activity,点击的时候利用回调处理popmenu的弹出。要注意的是弹出的和高斯模糊图片颜色过于接近,肉眼分别不出来效果,在最上面的高斯模糊图片上面再加一个带透明灰色的全屏view。

AllContactsFragment.java

//begin add by csc
        getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView parent, View view, int position, long id) {
                 uri = (Uri) view.getTag();
               if(uri!=null) {
                   count = 0;
                   sampleImg = DialerUtils.captureScreen(getActivity());
                   DialtactsActivity.imageUp.setVisibility(View.VISIBLE);
                   DialtactsActivity.imageDown.setVisibility(View.VISIBLE);
                   DialtactsActivity.imageUp.setImageBitmap(sampleImg);
                   gaussianBlurImg = DialerUtils.blur(getActivity(),sampleImg, 25f);// 高斯模糊图片
                   DialtactsActivity.imageDown.setImageBitmap(gaussianBlurImg);
                   DialtactsActivity.imageUp.setImageAlpha(255);
//                HashMap item = (HashMap)getListView().getItemAtPosition(position);
//                String section =String.valueOf(item.get("name").toString());//get每一行的数据的名字
                   nameOrNum = DialerUtils.getPhoneContacts(getActivity(),uri)[0] == null ? DialerUtils.getPhoneContacts(getActivity(),uri)[1] : DialerUtils.getPhoneContacts(getActivity(),uri)[0];
                   phoneNum = DialerUtils.getPhoneContacts(getActivity(),uri)[1];
                   DialtactsActivity.testTv.setText(nameOrNum);
                   int[] location = new int[2];
                   getListView().getChildAt(position - getListView().getFirstVisiblePosition()).getLocationOnScreen(location);
                   lp.setMargins(0, location[1], 0, 0);
                   DialtactsActivity.testTv.setLayoutParams(lp);
                   DialtactsActivity.viewShadow.setVisibility(View.VISIBLE);
                   DialtactsActivity.testTv.setVisibility(View.VISIBLE);
                   is3DTouch = true;
               }
                return false;
            }
        });
        getListView().setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {

                    case MotionEvent.ACTION_DOWN:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        if (is3DTouch) {
                            if (count < 255)
                                count = count + 8;
                            int alpha = 255 - count;
                            if (alpha < 0)
                                alpha = 0;
                            DialtactsActivity.imageUp.setImageAlpha(alpha);

                            if(alpha == 0){
                                myListener.showPopupWindow(DialtactsActivity.testTv,nameOrNum,phoneNum,uri);
                                DialtactsActivity.testTv.setVisibility(View.GONE);
                                return false;
                            }
                        }
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                }
                return false;
            }
        });
		
		// end add by csc

myListener.showPopupWindow(DialtactsActivity.testTv,nameOrNum,phoneNum,uri);
当第一个出来的item透明度为不透明的时候,回调showPopupWindow(View view,String popName,String phoneNum,Uri uri)方法,处理popmenu的弹出

public interface MyListener
    {
        public void showPopupWindow(View view,String popName,String phoneNum,Uri uri);
    }
该方法在DialtactActivity.java中实现:

/*begin add by csc for 3d touch*/
    public void showPopupWindow(View view,String popName, String phoneNum,Uri uri) {
        final Uri uris = uri;
        final String phoneNumber =phoneNum;
        popNameTv.setText(popName);
        popPhotoTv.setText(popName.subSequence(0, 1));
        viewShadow.setVisibility(View.VISIBLE);

        popNameLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (CompatUtils.hasPrioritizedMimeType()) {
                    ContactsContract.QuickContact.showQuickContact(getApplicationContext(), v, uris, null,
                            ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
                } else {
                    ContactsContract.QuickContact.showQuickContact(getApplicationContext(), v, uris, ContactsContract.QuickContact.MODE_LARGE,
                            null);
                }
                popupWindow.dismiss();
            }
        });
        popMmsLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(phoneNumber!=null) {
                    Uri smsToUri = Uri.parse("smsto:" + phoneNumber);

                    Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);

                    startActivity(intent);
                    popupWindow.dismiss();

                }
            }
        });

        popCallLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(phoneNumber!=null) {

                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
                    startActivity(intent);
                    popupWindow.dismiss();
                }
            }
        });

        popupWindow.setTouchable(true);
        popupWindow.showAsDropDown(view);


    }
    /*end add by csc for 3d touch*/




你可能感兴趣的:(android,开发)