@Override public void onTextChanged(CharSequence s) { hidingInputBoard(mSearchText); searchingText = s.toString(); if (null == searchingText || searchingText.equals("")) mSearchClear.setVisibility(View.GONE); else mSearchClear.setVisibility(View.VISIBLE); mLoading.setVisibility(View.VISIBLE); // hidingInputBoard(mSearchText); // searchingText = mSearchText.getText().toString(); mSearchResult.clear(); if (!TextUtils.isEmpty(searchingText)) { new Searching().exec(); } else { mAdapter.notifyDataSetChanged(); mLoading.setVisibility(View.GONE); } }
@Override public void parse(final SetCookie cookie, final String value) throws MalformedCookieException { Args.notNull(cookie, "Cookie"); if (TextUtils.isBlank(value)) { return; } final Matcher matcher = MAX_AGE_PATTERN.matcher(value); if (matcher.matches()) { final int age; try { age = Integer.parseInt(value); } catch (final NumberFormatException e) { return; } final Date expiryDate = age >= 0 ? new Date(System.currentTimeMillis() + age * 1000L) : new Date(Long.MIN_VALUE); cookie.setExpiryDate(expiryDate); } }
private List<Dish> listDishByCondition(MenuSearchConditionBean condition) { DetachedCriteria cri = DetachedCriteria.forClass(Dish.class); if (!TextUtils.isEmpty(condition.keyWord)) { String[] keyWords = condition.keyWord.split(","); Junction junction = Restrictions.disjunction(); for (int i = 0; i < keyWords.length; i++) { String keyWord = keyWords[i]; junction.add(Restrictions.ilike("mTags", keyWord, MatchMode.ANYWHERE)); junction.add(Restrictions.ilike("mName", keyWord, MatchMode.ANYWHERE)); } cri.add(junction); } List<Dish> list = getBaseDAO().findByCriteria(cri, condition.startNum, condition.range, Dish.class); return list; }
@Override protected void run() throws Throwable { int fieldCount = 0; PsiMethod initViewMethod = getInitView(); StringBuilder methodBuild = new StringBuilder("private void initView() {"); for (ViewPart viewPart : viewPartList) { if (!viewPart.isSelected() || fieldExist(viewPart)) { continue; } mClass.add(mFactory.createFieldFromText(viewPart.getDeclareString(false, false), mClass)); if (initViewMethod != null) { initViewMethod .getBody() .add(mFactory.createStatementFromText(viewPart.getFindViewString(), mClass)); } else { if (isViewHolder) { methodBuild.append(viewPart.getFindViewStringForViewHolder("convertView")); } else if (isAddRootView && !TextUtils.isEmpty(rootViewStr)) { methodBuild.append(viewPart.getFindViewStringWithRootView(rootViewStr)); } else { methodBuild.append(viewPart.getFindViewString()); } fieldCount++; } } methodBuild.append("}"); if (fieldCount > 0) { mClass.add(mFactory.createMethodFromText(methodBuild.toString(), mClass)); } addInitViewAfterOnCreate(); // reformat class JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(mProject); styleManager.optimizeImports(psiFile); styleManager.shortenClassReferences(mClass); new ReformatCodeProcessor(mProject, mClass.getContainingFile(), null, false) .runWithoutProgress(); }
private void generatorLayoutCode(String contextName, String findPre) { List<Element> editTextElements = new ArrayList<>(); List<Element> clickableElements = new ArrayList<>(); List<Element> itemClickableElements = new ArrayList<>(); // generator findViewById code in initView() method StringBuilder initView = new StringBuilder(); if (TextUtils.isEmpty(findPre)) { initView.append("private void initView() {\n"); } else { initView.append("private void initView(View " + findPre + ") {\n"); } for (Element element : mElements) { String pre = TextUtils.isEmpty(findPre) ? "" : findPre + "."; initView.append( element.getFieldName() + " = (" + element.name + ") " + pre + "findViewById(" + element.getFullID() + ");\n"); // set flag if (element.isEditText) { editTextElements.add(element); } if (element.isClickable) { clickableElements.add(element); } if (element.isItemClickable) { itemClickableElements.add(element); } } // generator EditText validate code if need StringBuilder sbEditText = new StringBuilder(); if (editTextElements.size() > 0) { sbEditText.append("private void submit() {\n"); sbEditText.append("\t\t// validate\n"); for (Element element : editTextElements) { // generator EditText string name String idName = element.id; int index = idName.lastIndexOf("_"); String name = index == -1 ? idName : idName.substring(index + 1); if (name.equals(idName)) { name += "String"; } sbEditText.append("String " + name + " = " + idName + ".getText().toString().trim();\n"); sbEditText.append("if(TextUtils.isEmpty(" + name + ")) {\n"); // 提示的toast为EditText的hint文字,无hint时格式为"name不能为空" String emptyTint = name + "不能为空"; String hint = element.xml.getAttributeValue("android:hint"); if (!TextUtils.isEmpty(hint) && !hint.startsWith("@string")) { emptyTint = hint; } sbEditText.append( "Toast.makeText(" + contextName + ", \"" + emptyTint + "\", Toast.LENGTH_SHORT).show();\n"); sbEditText.append("return;\n"); sbEditText.append("}\n"); sbEditText.append("\n"); } sbEditText.append("\t\t// TODO validate success, do something\n"); sbEditText.append("\n\n}\n"); } // generator clickable code if need StringBuilder sbClickable = new StringBuilder(); if (clickableElements.size() > 0) { // let class implement OnClickListener PsiReferenceList implementsList = mClass.getImplementsList(); if (implementsList != null) { PsiJavaCodeReferenceElement[] referenceElements = implementsList.getReferenceElements(); boolean hasImpl = false; for (PsiJavaCodeReferenceElement re : referenceElements) { hasImpl = re.getText().contains("OnClickListener"); } // add implement if not exist if (!hasImpl) { PsiJavaCodeReferenceElement pjcre = mFactory.createReferenceElementByFQClassName( "android.view.View.OnClickListener", mClass.getResolveScope()); implementsList.add(pjcre); } } initView.append("\n"); sbClickable .append("@Override public void onClick(View v) {\n") .append("switch (v.getId()) {\n"); for (Element element : clickableElements) { // generator setOnClickListener code in initView() initView.append(element.getFieldName() + ".setOnClickListener(this);\n"); // generator override public void onClick(View v) method sbClickable.append("case " + element.getFullID() + " :\n\nbreak;\n"); } sbClickable.append("}\n}"); } // generator itemClickable code if need for (Element element : itemClickableElements) { // generator setOnClickListener code in initView() initView.append( element.getFieldName() + ".setOnItemClickListener(new AdapterView.OnItemClickListener() {\n"); initView.append("@Override\n"); initView.append( "public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\n\n"); initView.append("}\n"); initView.append("});\n"); } initView.append("}\n"); PsiMethod[] initViewMethods = mClass.findMethodsByName("initView", false); if (initViewMethods.length > 0 && initViewMethods[0].getBody() != null) { // already have method // append non-repeated field PsiCodeBlock initViewMethodBody = initViewMethods[0].getBody(); for (Element element : mElements) { // append findViewById String pre = TextUtils.isEmpty(findPre) ? "" : findPre + "."; String s2 = element.getFieldName() + " = (" + element.name + ") " + pre + "findViewById(" + element.getFullID() + ");"; initViewMethodBody.add(mFactory.createStatementFromText(s2, initViewMethods[0])); // append setOnClickListener String s1 = element.getFieldName() + ".setOnClickListener(this);"; initViewMethodBody.add(mFactory.createStatementFromText(s1, initViewMethods[0])); } } else { // new method mClass.add(mFactory.createMethodFromText(initView.toString(), mClass)); } if (clickableElements.size() > 0) { PsiMethod[] onClickMethods = mClass.findMethodsByName("onClick", false); if (onClickMethods.length > 0 && onClickMethods[0].getBody() != null) { // already have method // append non-repeated field PsiCodeBlock onClickMethodBody = onClickMethods[0].getBody(); for (PsiElement element : onClickMethodBody.getChildren()) { if (element instanceof PsiSwitchStatement) { PsiSwitchStatement switchStatement = (PsiSwitchStatement) element; PsiCodeBlock body = switchStatement.getBody(); if (body != null) { for (Element clickableElement : clickableElements) { String caseStr = "case " + clickableElement.getFullID() + " :"; body.add(mFactory.createStatementFromText(caseStr, body)); body.add(mFactory.createStatementFromText("break;", body)); } } break; } } } else { // new method mClass.add(mFactory.createMethodFromText(sbClickable.toString(), mClass)); } } if (editTextElements.size() > 0) { mClass.add(mFactory.createMethodFromText(sbEditText.toString(), mClass)); } }
public static Boolean sendOrderFormToRestaurant(OrderForm orderForm) { String toMail = orderForm.getmRestaurant().getmEmail(); if (TextUtils.isEmpty(toMail)) { return false; } Properties mailProps = new Properties(); mailProps.setProperty("mail.smtp.host", onemenuMailHostName); mailProps.setProperty("mail.smtp.starttls.enable", "true"); mailProps.setProperty("mail.smtp.auth", "true"); mailProps.setProperty("mail.smtp.quitwait", "false"); mailProps.setProperty("mail.smtp.ssl.trust", "*"); Authenticator authenticator = new EmailAuthenticator(onemenuMailAddress, onemenuPassword); javax.mail.Session mailSession = javax.mail.Session.getDefaultInstance(mailProps, authenticator); // mailSession.setDebug(true); try { Address fromAddress = new InternetAddress(onemenuMailAddress); Address toAddress = new InternetAddress(toMail); Address bccAddress = new InternetAddress(onemenuMailAddress); String content; try { content = FaxUtils.getOrderFormHtml(orderForm); } catch (IOException e) { LOGGER.error("", e); return false; } catch (URISyntaxException e) { LOGGER.error("", e); return false; } MimeMessage msg = new MimeMessage(mailSession); msg.setFrom(fromAddress); msg.setSubject("[OneMenu Order] " + orderForm.getmRestaurant().getmName()); msg.setSentDate(new Date()); msg.setContent(content, "text/html;charset=utf-8"); msg.setRecipient(RecipientType.TO, toAddress); msg.setRecipient(RecipientType.BCC, bccAddress); /* * Transport transport = session.getTransport("smtp"); transport.connect("smtp.163.com", * userName, password); transport.sendMessage(msg,msg.getAllRecipients()); * transport.close(); */ Transport.send(msg); if (LOGGER.isDebugEnabled()) LOGGER.debug("Send order form email to " + toMail); } catch (MessagingException e) { LOGGER.error("", e); } return true; }