dialogにmarginを設定する

4526 ワード

	/**
	 *        
	 */
	private void editContact() {
		editContactView = View.inflate(this, R.layout.activity_editcontacet, null);
		final Dialog contactdialog = new Dialog(this, R.style.contactdialog);
		contactdialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		contactdialog.setContentView(editContactView);

		Window contactWindow = contactdialog.getWindow();
		WindowManager m = getWindowManager();
		Display defaultDisplay = m.getDefaultDisplay();

		//      90%  
		WindowManager.LayoutParams lp = contactWindow.getAttributes();
		lp.width = (int) (defaultDisplay.getWidth() * 0.80);
		contactWindow.setAttributes(lp);

		contactWindow.setGravity(Gravity.TOP);
		configWindow(contactWindow, lp);
		
		
//		contactWindow.setGravity(Gravity.CENTER_HORIZONTAL);
		etPhone = (EditText) contactdialog.findViewById(R.id.et_phone);
		contactdialog.show();
		etWeixin = (EditText) contactdialog.findViewById(R.id.et_wx);
		etQQ = (EditText) contactdialog.findViewById(R.id.et_qq);
		TextView tvcontactCancle = (TextView) contactdialog.findViewById(R.id.tv_editcontactcancle);
		TextView tvcontactSave = (TextView) contactdialog.findViewById(R.id.tv_editcontactsave);
		LoginResponse preUser = TpDataCache.getDataCache().getUser();
		TpleEmployee preEmployee = preUser.getEmployee();
		String code = preEmployee.getQqCode();
		String wechat = preEmployee.getWechat();
		String mobile = preEmployee.getMobile();
		etPhone.setText(mobile);
		etWeixin.setText(wechat);
		etQQ.setText(code);
		/**
		 *     
		 */
		tvcontactCancle.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				contactdialog.dismiss();
				editContactView.clearAnimation();
				imm.hideSoftInputFromWindow(etPhone.getWindowToken(), 0);
				 imm.hideSoftInputFromWindow(etQQ.getWindowToken(), 0);
				 imm.hideSoftInputFromWindow(etWeixin.getWindowToken(), 0);
			}
		});

		/**
		 *               textView 
		 */
		tvcontactSave.setOnClickListener(new OnClickListener() {

			

			@Override
			public void onClick(View v) {
				phoneText = etPhone.getText().toString();
				weixinText = etWeixin.getText().toString();
				qqText = etQQ.getText().toString();
				
//				if (phoneText.isEmpty() && qqText.isEmpty() && weixinText.isEmpty()) {
//					ToastShow("          。");
//					return;
//				}
				if (!TextUtils.isEmpty(phoneText)&&!CheckNumber.checkPhone(phoneText)) {
					ToastShow("         !");
					return;
				}
				if (!TextUtils.isEmpty(qqText)&&!CheckNumber.checkQQ(qqText)) {
					ToastShow("   QQ  !");
					return;
				}
				if (!TextUtils.isEmpty(weixinText)&&!CheckNumber.checkStr(weixinText)) {
					ToastShow("       !");
					return;
				}
				
				
				
				for (int i = 4; i < ids.length; i++) {

					View interView = findViewById(ids[i]);
					TextView right = (TextView) interView.findViewById(R.id.tv_right);
					switch (i) {
					case 4:

						right.setText(phoneText);

						break;
					case 5:

						right.setText(weixinText);
						break;
					case 6:

						right.setText(qqText);
						break;

					default:
						break;
					}

				}
				ModifyContactInfoRequest request = new ModifyContactInfoRequest();
				if (!TextUtils.isEmpty(phoneText)) {
					request.setMobile(phoneText);
				}
				if (!TextUtils.isEmpty(qqText)) {
					request.setQqCode(qqText);
				}
				if (!TextUtils.isEmpty(weixinText)) {
					request.setWechat(weixinText);
				}
				// TODO     token
				if (user != null) {
					request.setToken(user.getToken());
				}
				// request.setShowResult(showResult);
				TplRequest tplRequest = new TplRequest(TpPersonnalCenterActivity.this, true,
						TpPersonnalCenterActivity.this, RemoteService.shopService, RemoteService.MODIFY_CONTACT_INFO,
						request);
				tplRequest.execute();
				
				contactdialog.dismiss();
				editContactView.clearAnimation();
//				hiddenKeyboard();
//				if (imm.isActive()) {
//					InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//					//          
//					imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); 
//				}
				hiddenKeyboard();
			}
		});

	}


    private void configWindow(Window win, WindowManager.LayoutParams wAttrs) {  
        wAttrs.gravity = Gravity.BOTTOM;  
        wAttrs.horizontalMargin =0F;  
        //      gravity Gravity.LEFT Gravity.CENTER,             margin      
        wAttrs.verticalMargin = 0.59F;  
    }