/* show submit button if password, ip and proxy settings are valid */ private void enableSubmitIfAppropriate() { Button submit = mConfigUi.getSubmitButton(); if (submit == null) return; boolean enabled = false; boolean passwordInvalid = false; /* Check password invalidity for manual network set up alone */ if (chosenNetworkSetupMethod() == MANUAL && ((mAccessPointSecurity == AccessPoint.SECURITY_WEP && mPasswordView.length() == 0) || (mAccessPointSecurity == AccessPoint.SECURITY_PSK && mPasswordView.length() < 8))) { passwordInvalid = true; } if ((mSsidView != null && mSsidView.length() == 0) || ((mAccessPoint == null || mAccessPoint.networkId == INVALID_NETWORK_ID) && passwordInvalid)) { enabled = false; } else { if (ipAndProxyFieldsAreValid()) { enabled = true; } else { enabled = false; } } submit.setEnabled(enabled); }
public boolean TextViewChecks() { Pattern p = Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(tbPass.getText()); int count = 0; // Add Check for username with DB if (tbUser.length() < 6 | tbUser.length() > 12) { tbUser.setError("Enter a username between 6-12 Characters"); } else { count++; } if (tbPass.length() < 6 | tbPass.length() > 12) { tbPass.setError("Enter a password between 6-12 Characters"); } else { count++; } if (!m.find()) { count++; tbPass.setError("Enter a special character"); } else { count++; } if (count == 3) return true; return false; }
private void addSymbol(String upCase, String lowCase) { if (mSelectedMode == LAST_NAME_SELECTED) { if (tvLastName.length() > 0) tvLastName.append(lowCase); else tvLastName.append(upCase); } else { if (tvName.length() > 0) tvName.append(lowCase); else tvName.append(upCase); } }
/** * Concatenates with the specified text (two spaces and appendix) to the TextView with RTL * support. * * @param text the String that is concatenated to the TextView * @param textColor the <code>text</code> color */ @SuppressLint("SetTextI18n") public static void concatWithTwoSpacesForRtlSupport( TextView textView, CharSequence text, @ColorInt int textColor) { if (ResourceUtil.isRTL(textView.getResources())) { textView.setText(text + StringUtil.TWO_SPACES + textView.getText()); ViewUtil.setForegroundColor(textView, textColor, 0, text.length()); } else { int start = textView.length(); textView.append(StringUtil.TWO_SPACES + text); ViewUtil.setForegroundColor(textView, textColor, start, textView.length()); } }
private int validateIpConfigFields(LinkProperties linkProperties) { String ipAddr = mIpAddressView.getText().toString(); InetAddress inetAddr = null; try { inetAddr = NetworkUtils.numericToInetAddress(ipAddr); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_ip_address; } int networkPrefixLength = -1; try { networkPrefixLength = Integer.parseInt(mNetworkPrefixLengthView.getText().toString()); } catch (NumberFormatException e) { // Use -1 } if (networkPrefixLength < 0 || networkPrefixLength > 32) { return R.string.wifi_ip_settings_invalid_network_prefix_length; } linkProperties.addLinkAddress(new LinkAddress(inetAddr, networkPrefixLength)); String gateway = mGatewayView.getText().toString(); InetAddress gatewayAddr = null; try { gatewayAddr = NetworkUtils.numericToInetAddress(gateway); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_gateway; } linkProperties.addRoute(new RouteInfo(gatewayAddr)); String dns = mDns1View.getText().toString(); InetAddress dnsAddr = null; try { dnsAddr = NetworkUtils.numericToInetAddress(dns); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_dns; } linkProperties.addDns(dnsAddr); if (mDns2View.length() > 0) { dns = mDns2View.getText().toString(); try { dnsAddr = NetworkUtils.numericToInetAddress(dns); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_dns; } linkProperties.addDns(dnsAddr); } return 0; }
private RelativeLayout initializeContentView(final Resources resources) { RelativeLayout contentView = new RelativeLayout(this.activity); contentView.setLayoutParams( new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); // set padding int padding = this.style.paddingInPixels; // if a padding dimension has been set, this will overwrite any padding // in pixels if (this.style.paddingDimensionResId > 0) { padding = resources.getDimensionPixelSize(this.style.paddingDimensionResId); } contentView.setPadding(padding, padding, padding, padding); // only setup image if one is requested ImageView image = null; if ((null != this.style.imageDrawable) || (0 != this.style.imageResId)) { image = initializeImageView(); contentView.addView(image, image.getLayoutParams()); } TextView text = initializeTextView(resources); RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); if (null != image) { textParams.addRule(RelativeLayout.RIGHT_OF, image.getId()); } if ((this.style.gravity & Gravity.CENTER) != 0) { textParams.addRule(RelativeLayout.CENTER_IN_PARENT); } else if ((this.style.gravity & Gravity.CENTER_VERTICAL) != 0) { textParams.addRule(RelativeLayout.CENTER_VERTICAL); } else if ((this.style.gravity & Gravity.CENTER_HORIZONTAL) != 0) { textParams.addRule(RelativeLayout.CENTER_HORIZONTAL); } // 显示内容过长则居左显示 if (text.length() > 20) { text.setGravity(Gravity.LEFT); } contentView.addView(text, textParams); return contentView; }
/* package */ WifiConfiguration getConfig() { if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID && !mEdit) { return null; } WifiConfiguration config = new WifiConfiguration(); if (mAccessPoint == null) { config.SSID = AccessPoint.convertToQuotedString(mSsidView.getText().toString()); // If the user adds a network manually, assume that it is hidden. config.hiddenSSID = true; } else if (mAccessPoint.networkId == INVALID_NETWORK_ID) { config.SSID = AccessPoint.convertToQuotedString(mAccessPoint.ssid); } else { config.networkId = mAccessPoint.networkId; } config.mode = mAccessPoint.mode; switch (mAccessPointSecurity) { case AccessPoint.SECURITY_NONE: config.allowedKeyManagement.set(KeyMgmt.NONE); break; case AccessPoint.SECURITY_WEP: config.allowedKeyManagement.set(KeyMgmt.NONE); config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED); if (mPasswordView.length() != 0) { int length = mPasswordView.length(); String password = mPasswordView.getText().toString(); // WEP-40, WEP-104, and 256-bit WEP (WEP-232?) if ((length == 10 || length == 26 || length == 58) && password.matches("[0-9A-Fa-f]*")) { config.wepKeys[0] = password; } else { config.wepKeys[0] = '"' + password + '"'; } } break; case AccessPoint.SECURITY_PSK: config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); if (mPasswordView.length() != 0) { String password = mPasswordView.getText().toString(); if (password.matches("[0-9A-Fa-f]{64}")) { config.preSharedKey = password; } else { config.preSharedKey = '"' + password + '"'; } } break; case AccessPoint.SECURITY_EAP: config.allowedKeyManagement.set(KeyMgmt.WPA_EAP); config.allowedKeyManagement.set(KeyMgmt.IEEE8021X); config.eap.setValue((String) mEapMethodSpinner.getSelectedItem()); config.phase2.setValue( (mPhase2Spinner.getSelectedItemPosition() == 0) ? "" : "auth=" + mPhase2Spinner.getSelectedItem()); config.ca_cert.setValue( (mEapCaCertSpinner.getSelectedItemPosition() == 0) ? "" : KEYSTORE_SPACE + Credentials.CA_CERTIFICATE + (String) mEapCaCertSpinner.getSelectedItem()); config.client_cert.setValue( (mEapUserCertSpinner.getSelectedItemPosition() == 0) ? "" : KEYSTORE_SPACE + Credentials.USER_CERTIFICATE + (String) mEapUserCertSpinner.getSelectedItem()); config.private_key.setValue( (mEapUserCertSpinner.getSelectedItemPosition() == 0) ? "" : KEYSTORE_SPACE + Credentials.USER_PRIVATE_KEY + (String) mEapUserCertSpinner.getSelectedItem()); config.identity.setValue( (mEapIdentityView.length() == 0) ? "" : mEapIdentityView.getText().toString()); config.anonymous_identity.setValue( (mEapAnonymousView.length() == 0) ? "" : mEapAnonymousView.getText().toString()); if (mPasswordView.length() != 0) { config.password.setValue(mPasswordView.getText().toString()); } break; default: return null; } config.proxySettings = mProxySettings; config.ipAssignment = mIpAssignment; config.linkProperties = new LinkProperties(mLinkProperties); return config; }
@Override public boolean onLongClick(View v) { switch (v.getId()) { case (R.id.button1): numeros.setText(numeros.getText().toString() + "1"); speakOut("1"); vibration.vibrate(100); break; case (R.id.button2): numeros.setText(numeros.getText().toString() + "2"); speakOut("2"); vibration.vibrate(100); break; case (R.id.button3): numeros.setText(numeros.getText().toString() + "3"); speakOut("3"); vibration.vibrate(100); break; case (R.id.button4): numeros.setText(numeros.getText().toString() + "4"); speakOut("4"); vibration.vibrate(100); break; case (R.id.button5): numeros.setText(numeros.getText().toString() + "5"); speakOut("5"); vibration.vibrate(100); break; case (R.id.button6): numeros.setText(numeros.getText().toString() + "6"); speakOut("6"); vibration.vibrate(100); break; case (R.id.button7): numeros.setText(numeros.getText().toString() + "7"); speakOut("7"); vibration.vibrate(100); break; case (R.id.button8): numeros.setText(numeros.getText().toString() + "8"); speakOut("8"); vibration.vibrate(100); break; case (R.id.button9): numeros.setText(numeros.getText().toString() + "9"); speakOut("9"); vibration.vibrate(100); break; case (R.id.button11): numeros.setText(numeros.getText().toString() + "0"); speakOut("0"); vibration.vibrate(100); break; case (R.id.button_etoile): numeros.setText(numeros.getText().toString() + "*"); speakOut("étoile"); vibration.vibrate(100); break; case (R.id.button_dieze): numeros.setText(numeros.getText().toString() + "#"); speakOut("dièze"); vibration.vibrate(100); break; case (R.id.button_plus): numeros.setText(numeros.getText().toString() + "+"); speakOut("+"); vibration.vibrate(100); break; case (R.id.button_effacer): if (numeros.length() > 0) { numeros.setText(""); speakOut("numéro éffacé"); vibration.vibrate(100); break; } break; case (R.id.button_appeler): if (numeros.length() > 0) { String dialedNumber = "tel:" + numeros.getText().toString(); speakOut("appel vers " + numeros.getText().toString()); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Appeler(dialedNumber); // setResult(1000); finish(); break; } break; } return true; }
private int validateIpConfigFields(LinkProperties linkProperties) { if (mIpAddressView == null) return 0; String ipAddr = mIpAddressView.getText().toString(); if (TextUtils.isEmpty(ipAddr)) return R.string.wifi_ip_settings_invalid_ip_address; InetAddress inetAddr = null; try { inetAddr = NetworkUtils.numericToInetAddress(ipAddr); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_ip_address; } int networkPrefixLength = -1; try { networkPrefixLength = Integer.parseInt(mNetworkPrefixLengthView.getText().toString()); if (networkPrefixLength < 0 || networkPrefixLength > 32) { return R.string.wifi_ip_settings_invalid_network_prefix_length; } linkProperties.addLinkAddress(new LinkAddress(inetAddr, networkPrefixLength)); } catch (NumberFormatException e) { // Set the hint as default after user types in ip address mNetworkPrefixLengthView.setText( mConfigUi.getContext().getString(R.string.wifi_network_prefix_length_hint)); } String gateway = mGatewayView.getText().toString(); if (TextUtils.isEmpty(gateway)) { try { // Extract a default gateway from IP address InetAddress netPart = NetworkUtils.getNetworkPart(inetAddr, networkPrefixLength); byte[] addr = netPart.getAddress(); addr[addr.length - 1] = 1; mGatewayView.setText(InetAddress.getByAddress(addr).getHostAddress()); } catch (RuntimeException ee) { } catch (java.net.UnknownHostException u) { } } else { InetAddress gatewayAddr = null; try { gatewayAddr = NetworkUtils.numericToInetAddress(gateway); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_gateway; } linkProperties.addRoute(new RouteInfo(gatewayAddr)); } String dns = mDns1View.getText().toString(); InetAddress dnsAddr = null; if (TextUtils.isEmpty(dns)) { // If everything else is valid, provide hint as a default option mDns1View.setText(mConfigUi.getContext().getString(R.string.wifi_dns1_hint)); } else { try { dnsAddr = NetworkUtils.numericToInetAddress(dns); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_dns; } linkProperties.addDns(dnsAddr); } if (mDns2View.length() > 0) { dns = mDns2View.getText().toString(); try { dnsAddr = NetworkUtils.numericToInetAddress(dns); } catch (IllegalArgumentException e) { return R.string.wifi_ip_settings_invalid_dns; } linkProperties.addDns(dnsAddr); } return 0; }
/* package */ WifiConfiguration getConfig() { if (mAccessPoint != null && mAccessPoint.networkId != INVALID_NETWORK_ID && !mEdit) { return null; } WifiConfiguration config = new WifiConfiguration(); if (mAccessPoint == null) { config.SSID = AccessPoint.convertToQuotedString(mSsidView.getText().toString()); // If the user adds a network manually, assume that it is hidden. config.hiddenSSID = true; } else if (mAccessPoint.networkId == INVALID_NETWORK_ID) { config.SSID = AccessPoint.convertToQuotedString(mAccessPoint.ssid); } else { config.networkId = mAccessPoint.networkId; } switch (mAccessPointSecurity) { case AccessPoint.SECURITY_NONE: config.allowedKeyManagement.set(KeyMgmt.NONE); break; case AccessPoint.SECURITY_WEP: config.allowedKeyManagement.set(KeyMgmt.NONE); config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED); if (mPasswordView.length() != 0) { int length = mPasswordView.length(); String password = mPasswordView.getText().toString(); // WEP-40, WEP-104, and 256-bit WEP (WEP-232?) if ((length == 10 || length == 26 || length == 58) && password.matches("[0-9A-Fa-f]*")) { config.wepKeys[0] = password; } else { config.wepKeys[0] = '"' + password + '"'; } } break; case AccessPoint.SECURITY_PSK: config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); if (mPasswordView.length() != 0) { String password = mPasswordView.getText().toString(); if (password.matches("[0-9A-Fa-f]{64}")) { config.preSharedKey = password; } else { config.preSharedKey = '"' + password + '"'; } } break; case AccessPoint.SECURITY_EAP: config.allowedKeyManagement.set(KeyMgmt.WPA_EAP); config.allowedKeyManagement.set(KeyMgmt.IEEE8021X); config.enterpriseConfig = new WifiEnterpriseConfig(); int eapMethod = mEapMethodSpinner.getSelectedItemPosition(); int phase2Method = mPhase2Spinner.getSelectedItemPosition(); config.enterpriseConfig.setEapMethod(eapMethod); switch (eapMethod) { case Eap.PEAP: // PEAP supports limited phase2 values // Map the index from the PHASE2_PEAP_ADAPTER to the one used // by the API which has the full list of PEAP methods. switch (phase2Method) { case WIFI_PEAP_PHASE2_NONE: config.enterpriseConfig.setPhase2Method(Phase2.NONE); break; case WIFI_PEAP_PHASE2_MSCHAPV2: config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2); break; case WIFI_PEAP_PHASE2_GTC: config.enterpriseConfig.setPhase2Method(Phase2.GTC); break; default: Log.e(TAG, "Unknown phase2 method" + phase2Method); break; } break; default: // The default index from PHASE2_FULL_ADAPTER maps to the API config.enterpriseConfig.setPhase2Method(phase2Method); break; } String caCert = (String) mEapCaCertSpinner.getSelectedItem(); if (caCert.equals(unspecifiedCert)) caCert = ""; config.enterpriseConfig.setCaCertificateAlias(caCert); String clientCert = (String) mEapUserCertSpinner.getSelectedItem(); if (clientCert.equals(unspecifiedCert)) clientCert = ""; config.enterpriseConfig.setClientCertificateAlias(clientCert); config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString()); config.enterpriseConfig.setAnonymousIdentity(mEapAnonymousView.getText().toString()); if (mPasswordView.isShown()) { // For security reasons, a previous password is not displayed to user. // Update only if it has been changed. if (mPasswordView.length() > 0) { config.enterpriseConfig.setPassword(mPasswordView.getText().toString()); } } else { // clear password config.enterpriseConfig.setPassword(mPasswordView.getText().toString()); } break; default: return null; } config.proxySettings = mProxySettings; config.ipAssignment = mIpAssignment; config.linkProperties = new LinkProperties(mLinkProperties); return config; }