public void onMyButtonClick1(View view)
{
final EditText emailValidate = (EditText)findViewById(R.id.emailid);
final TextView passValidate = (TextView)findViewById(R.id.password);
String email = emailValidate.getText().toString().trim();
String pass= passValidate.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-]+#[a-z]+\\.+[a-z]+";
// onClick of button perform this simplest code.
if (email.matches(emailPattern)&&(passValidate!=null))
{
//Toast.makeText(this,"valid email address",Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Welcome To Sun Telematics", Toast.LENGTH_SHORT).show();
Intent getStarted = new Intent(getApplicationContext(), FourthActivity.class);
startActivity(getStarted);
/*else
{
Toast.makeText(this, "Field Required", Toast.LENGTH_SHORT).show();
}*/
}
else
{
Toast.makeText(getApplicationContext(),"Invalid email address", Toast.LENGTH_SHORT).show();
}
}
I want to check that password field is empty or not. If it is empty it will not go to the next activity. It will show toast message.
I can validate that field. Where can i do the changes in the code.
You shouldn't check if the instance of the password field is null but whether the string content is actually empty or not. There are various utility libraries for this but it would probably suffice to check !"".equals(pass)
Note that by putting the "" up front you will avoid a NullPointerException even if your string could be null. In this case it wouldn't matter since you already got the string and trimmed it.
I recommend using StringUtils in the common lang library by Apache to handle this kind of stuff though, you could just write StringUtils.isNotEmpty(pass) in that case and it has various utility methods for checking whitespaces, converting strings, etc.
Related
We have a chat application which is using Smack, XMPP, ejabberd. I'm wondering if it's possible to achieve something like below:
A chat is open between 2 users.
User1 is typing some message.
User2 is able to see the message typed by User1 as he types it.
I have done a bit of research but couldn't find anything related.
Please let me know how to achieve this use case.
Thanks in advance!
That is not possible. You can send the text as user types but each piece will go as independent message. If you want that one you might want to have your own way to do so. XMPP have no way to do so!
With Smack it is easy, whenever the user changes the text you send a typing stanza to the other person using the ChatStateExtension:
private void sendTypingStatus(final String toJid) {
//you must have a valid xmpp connection of course
if (null == mConnection)
return;
try {
Message message = new Message(JidCreate.from(toJid));
message.addExtension(new ChatStateExtension(ChatState.composing));
message.setType(Message.Type.chat);
mConnection.sendStanza(message);
} catch (InterruptedException | SmackException.NotConnectedException | XmppStringprepException ex) {
Log.w(TAG, "sendTypingStatus error", ex);
}
}
The other person should be prepared to receive the stanza and use it correctly. The best option is to use ChatStatesStanzaListener for that:
public class ChatStatesStanzaListener implements StanzaListener {
private static final String TAG = ChatStatesStanzaListener.class.getSimpleName();
#Override
public void processStanza(Stanza packet) {
Message message = (Message) packet;
if (message.hasExtension(ChatStateExtension.NAMESPACE)) {
ChatStateExtension chatStateExtension = (ChatStateExtension) message.getExtension(ChatStateExtension.NAMESPACE);
ChatState chatState = chatStateExtension.getChatState();
String fromJid = message.getFrom().asBareJid().toString();
if (message.getType().equals(Message.Type.chat)) {
Log.v(TAG, "got chat state " + fromJid + " " + message.getType() + " " + chatState);
//you got youe information here, call a callback or broadcast an event, whatever
} else if (message.getType().equals(Message.Type.groupchat)) {
//out of your question
}
}
}
}
Don't forget to add the stanza listener to your xmpp connection once it's established:
1. Set the stanza filter:
// set up a stanzalistener and filter chatstates messages only
StanzaFilter chatStatesStanzaFilter = stanza -> {
// filter for chatstates message only
return stanza.hasExtension(ChatStateExtension.NAMESPACE);
};
Use it once you initialize the xmpp connection:
mConnection.addAsyncStanzaListener(new ChatStatesStanzaListener(), chatStatesStanzaFilter);
I hope it helps :)
After few years doing some other stuff I'm back to CRM business. I'm already questioning my life choices. I don't understand what is wrong here. I'm trying to create a simple plugin that will run on Incident / Case creation. It will look if description field contains a valid url and if yes then it should update first url that has been found to another field. Here's the plugin execution method.
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext pluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (pluginExecutionContext.InputParameters.Contains("Target") && pluginExecutionContext.InputParameters["Target"] is Entity)
{
Entity targetEntity = (Entity)pluginExecutionContext.InputParameters["Target"];
if (targetEntity.LogicalName != Incident.EntityLogicalName)
{
return;
}
IOrganizationServiceFactory orgServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService orgService = orgServiceFactory.CreateOrganizationService(pluginExecutionContext.UserId);
try
{
string desc = (string)targetEntity.Attributes["description"];
string pattern = #"\b(?:https?://|www\.)[^ \f\n\r\t\v\]]+\b";
MatchCollection collection = Regex.Matches(desc, pattern);
if (collection.Count > 0)
{
throw new Exception(collection[0].Value);
}
}
catch (Exception ex)
{
tracingService.Trace("Error in CaseUrlPlugin {0}", ex.ToString());
throw ex;
}
}
}
The problem is that when I'm creating a new case (description field filled with text and url) and hit save I get "Given key was not present in the dictionary" exception as if description field is not there. When I hit ok to that error window and hit save again then description field is founded and my code throws an exception with that link.
So why is not the description field present in the first time? I don't like the idea doing this post operation because that would require another sql transaction right (to save incident again)?
Aah ffs. The problem was that when I was trying to save for the first time I used CTRL + S while my focus was still on description field because that's the last field I was filling. Now it seems that UI doesn't register that field to be filled if focus on that field and hitting CTRL + S. Hitting save icon works because that would get focus off the description field. And of course in my case hitting ok for that error window also unfocus the field thus second save works.............
Well, at least I figured it out right after posting question here. Been trying to solve this way too long.
I've successfully written an external record to an NFC tag. When I use a 3rd party tag reader to evaluate the external record that was written, I see the appropriate value, which is a single, positive integer.
However, when I run my code (below) to see what the value of the payload (external record) is on the tag (using a Toast) in order to incorporate that value into an "if" statement, I get different values. So far, I've seen the following:
B#41fb4278 or B#41fb1190.
At this point, the value of the external record is just "2". How can I just return/write simply 2?
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.hasExtra(NfcAdapter.EXTRA_TAG))
{
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] payload = "2".getBytes(); ///this is where the ID (payload) for the tag is assigned.
NdefRecord[] ndefRecords = new NdefRecord[2];
ndefRecords[0] = NdefRecord.createExternal("com.example.bmt_admin", "externaltype", payload);
ndefRecords[1] = NdefRecord.createApplicationRecord("com.example.bmt_01");
NdefMessage ndefMessage = new NdefMessage(ndefRecords);
writeNdefMessage(tag, ndefMessage);
Toast.makeText(this, "NFC Scan: " + payload, Toast.LENGTH_SHORT).show();
}
}
Thanks for any help!!
payload is defined as byte[]. When you use payload in your toast() statment, you use it a pointer to that array. Therefore what you see is the address of the array. When you want to get a string representation of a byte[], you can use for example:
String s = new String(payload);
I have a simple Bot as below:
[Serializable]
[Template(TemplateUsage.NotUnderstood, "I do not understand \"{0}\".", "Try again, I don't get \"{0}\".")]
class MyOrder
{
public string Subject;
public string Description;
public static IForm<MyOrder> BuildForm()
{
return new FormBuilder<MyOrder>()
.Field(nameof(MyOrder.Subject), "What Subject should I use?")
.Field(nameof(MyOrder.Description), "And what Description?")
.AddRemainingFields()
.OnCompletionAsync(MyFormComplete)
.Build();
}
private static async Task MyFormComplete(IDialogContext context, MyOrder order)
{
if (order != null)
{
await context.PostAsync($"Created. Number is 9833");
}
else
{
await context.PostAsync("Form returned empty response!");
}
}
Once the form is completed the MyFormComplete callback is made.
First question - How do I get access to the client details in that function? I need to know the Skype handle so that I can map it to a internal user.
Secondly - After completing the form I can't start a new one. No matter what I enter on the client it just keeps triggering the callback function. There must be a way to terminate the session/conversation so that the next text from the Skype client will start a new conversation/form. Yeah?
Worked out how to get the Skype caller id inside the Dialog's CompletionDelegate. Simply add the message's From details to the message.BotUserData inside the MessageController before building the dialog.
message.BotUserData = JObject.FromObject(message.From)
I can then access this on the context within that callback.
I've created an object previously that I'm now trying to update in an "edit" screen
The id of the object is correct (as it correctly queries earlier in the activity to update the text labels. This should save when a button is clicked.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Product");
Intent i = getIntent();
String queryString = i.getStringExtra("id");
query.getInBackground(queryString, new GetCallback<ParseObject>() {
public void done(ParseObject editProduct, ParseException e) {
if (e == null) {
editProduct.put("productName", ProductName.getText().toString());
editProduct.put("ISDN", ISDN_text.getText().toString());
editProduct.put("expiry", expiry_date.getText().toString());
editProduct.put("type", spinnercategory.getSelectedItem().toString());
editProduct.put("quantity", quantity.getText().toString());
editProduct.put("username", "Admin");
editProduct.put("shoppingList", true);
editProduct.put("mainList", false);
editProduct.saveInBackground();
}
}
});
This is lifted from the Parse Android developers guide, but doesn't appear to be working. Any suggestions
Figured it out. Sort of.
editProduct.put("expiry", expiry_date.getText().toString()); is the line that's breaking it. I'm trying to pass a string to what is defined as a date at the backend, which apparently cancels the whole save operation.
Commented this out in my solution for now until I can fix the issue with the date