How to set masked input to edittext in android? [duplicate] - java

How to use inputfilter for CNIC i.e #####-#######-# ? Please help me.. I am new to Android and I dont know how to use it?
How to mask input? I went through various sites but couldn't find solution. I am so confused.

Have you tried using Masked EditText ? This is what you want ... :)
If you want a numeric keyboard instead of alphabetical, then comment the following lineof code:
this.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
in the file MaskedEditText.java. Now setting android:inputType = "numeric" will work.

) You can also try the fork of Masked EditText. It's derived but with works with Gradle, has some bugfixes, an example project, and a little bit another behavior :-)
The behavior is also changed:
You can set the flag and the hint will be always visible.
Your pattern is invisible initially and grows automatically as soon, as you type. For instance, in the beginning, it is: "+7(", then you type '999' and it shows you "+7(999)" with another brace. In the original library, AFAIK it works like: "+7( ) - - ", then you type '999' and it transforms into "+7(999) - - " and so on.

Related

Paste into text area

I tried to make my day easier making a program that will register my self into card game tournaments via selenium webdriver. I am beginner so I was thrilled even though it was just basics aka click here, confirm this, write that but at the end I ran into a problem that I am having trouble solving.
At the end you need to submit decks via deck code. The sendKeys function? (not sure if thats the correct wording) does not work since it actually needs to be pasted into the text area. Whenever you try to "just" write into the box it says its invalid deck code.
driver.findElement(By.xpath("//*[#id=\"react-root\"]/div/div/div[2]/div/div[2]/div/div[4]/div[1]/div/textarea")).click();
driver.findElement(By.xpath("//*[#id=\\\"react-root\\\"]/div/div/div[2]/div/div[2]/div/div[4]/div[1]/div/textarea")).sendKeys(Keys.chord(Keys.CONTROL + "v"));
I went with this, first line just clicking in to the text area and then trying to paste it in (while I copied the deck code manually, not sure how I will solve this since I need to paste 3 different ones, but that is issue for the future) but the code just wont paste and I have no idea where is the catch. I tried the paste function in different text area with the same settings meaning I have something copied in my clipboard and it worked just fine.
Example of the deck code is
" AAECAZICCiT3A94FrtICv/IC9fwC2KAD+KED9KID/KMDCkBWX/4BxAapogPIogPcogPvogPZqQMA "
I hope I provided everything I should have otherwise let me know and I will gladly post more :) Thanks in advance and I hope someone can help me
This might not work because I don't see you explicitly copying the deck code, as you mentioned you did it manually. I also modified your example to not use Keys.chord, as you might not need them here.
To copy the element:
deckCodeWebElement = driver.findElement(locatorToFindDeckCode);
deckCodeWebElement.send_keys(Keys.CONTROL+'a')
time.sleep(1)
deckCodeWebElement.send_keys(Keys.CONTROL+'c')
Then, to paste:
deckCodeWebElementToPaste = driver.findElement(locatorToFindDeckCodeToPaste);
deckCodeWebElementToPaste.send_keys(Keys.CONTROL+'v')
On another note, I recommend shortening your XPaths to relative notation, as the absolute notation you are using is very brittle and breaks very easy. You want to find elements irrespective of their location in the DOM tree.
You can change this:
//*[#id=\\\"react-root\\\"]/div/div/div[2]/div/div[2]/div/div[4]/div[1]/div/textarea
to just this:
//textarea
You may need to query on something like ID, class, or name if there are multiple textarea elements, but there is no need to start at the root node and use div[2] and div[4] unless absolutely necessary.

Adding emoji reaction by unicode not working

Currently, I am making a music discord bot and I want it to display the list of songs it is currently playing.
The user should be able to interact with the list by moving to each page with a left arrow and right arrow emoji.
The problem is that, when I try to react to the message via a unicode, it does not seems to work as follows:
message.addReaction("U+2B05").queue();
message.addReaction("U+2B07").queue();
it throws an error saying that the Emoji is not found during runtime, even though that is the respective unicode for the emoji I wanted to sent.
I have tried to use 2B05 or Left Arrow in the string and it does not work too.
Encountered the same issue before, though one of the answers from this question helped me.
Specifically, one of the answer was:
I understood how to do it. Just need to add this line
e.getChannel().sendMessage(embedBuilder.build()).complete().addReaction("✔").queue();
Apparently adding the emoji directly into the string works.
Do this instead:
message.addReaction("➡").queue();
message.addReaction("⬅").queue();

How to set subscript and superscript text in string (such as math exponents)

I'm working on an Android app, and I need to be able to include the exponents/powers into a string (Java). I've done some searching and it seems that my scenario is making it difficult. I've looked into options such as ALT+ codes and Unicode. I'm not entirely sure if either of those, or any other options, are actually possible (I know the ALT+ codes only have '1' '2' and '3' subscripts oddly enough).
So, what's my best option, if any?
I'd like to keep it as simple as possible. I have a lot of strings to write (like math problems) and the need to subscript/superscript numbers is random. Can this be done easily?
EDIT: I suppose I was vague. My app is for studying. And the questions/answers are put into arrays and randomized each time. I'd like to be able to set the strings in the Java file as they are now
question[0].text = "solve x^2 if x=5";
But instead of the user seeing "^2", I'd like to use the actual superscripts.
ANOTHER EDIT:
global.java (class/structure that holds questions/answers)
question[0].question = "Question Text. I would like to add a superscript or two here, as if it were a math problem";
question[0].answer[0]. = "Answer 1. Add a subscript here";
question[0].answer[1]. = "Answer 2. Add another superscript here.";
question[0].answer[2]. = "Answer 3. Etc.";
question[0].answer[3]. = "Answer 4. Etc.";
Activity XML
<!--QUESTION-->
<TextView
android:id="#+id/textQuestion"/>
<!--ANSWERS-->
<Button
android:id="#+id/answerOne"
android:onClick="checkAnswer"/>
<Button
android:id="#+id/answerTwo"
android:onClick="checkAnswer"/>
<Button
android:id="#+id/answerThree"
android:onClick="checkAnswer"/>
<Button
android:id="#+id/answerFour"
android:onClick="checkAnswer"/>
Activity Java
//SET QUESTION STRING TO TEXTVIEW
textQuestion.setText(questionDatabase.getQuestion(index));
//SET ANSWER STRINGS TO BUTTONS' TEXT
buttonOne.setText(questionDatabase.getAnswer(index, 0));
buttonTwo.setText(questionDatabase.getAnswer(index, 1));
buttonThree.setText(questionDatabase.getAnswer(index, 2));
buttonFour.setText(questionDatabase.getAnswer(index, 3));
"NEXT" and "PREVIOUS" buttons allow the user to move through the questions by incrementing/decrementing the "index".
So, because of this, the activity never knows (I don't think) which questions/answers need text to be superscript, and why I'd like to be able to set the questions/answers sub/superscript myself when I enter the questions/answers into the array. Can this be done?
EDIT: #jared burrows was very helpful in chat and has helped me almost reach the end of my issue. I'm now able to use setText(Html.fromHtml()); on my textview (question text) and it shows the subscript and superscript properly. But on my buttons (answers) I tried to employ the same tactic and it doesn't work the same. "X2" just becomes "X2". Why is this? Why don't my buttons accept the html just like the textview.
Superscript:
textView.setText(Html.fromHtml("X<sup>2</sup>"));
Subscript:
textView.setText(Html.fromHtml("X<sub>2</sub>"));
References:
Subscript and Superscript a String in Android
http://www.w3schools.com/tags/tag_sub.asp
http://www.w3schools.com/tags/tag_sup.asp
The answer to this was a combination of help from #Jared Burrows and AlanV. So thank you to you both.
view.setText(Html.fromHtml(stringGoesHere));
This does work, but out of the box it doesn't work for buttons due to some frustrating feature in (I think) Android 5.0. Buttons are automatically set to all caps, and because of this, it overrides the html formatting.
So, to allow buttons the ability to use html properly, you must set the attribute to false.
<button
android:textAllCaps="false";/>
Thanks again to Jared Burrows and AlanV.

java swing jtextfiled unicode sinhala

***************************UPDATED***********************************************************************
i have found a similar question :
here : same question by another user
this one is with little details , but i still cant get it to work !
any help would be glad fully accepted !
I want to type Sinhalese words in (J2SE)swing textfileds , but they don't appear correctly in Java , same text in notepad shows correct word. how can i fix this ?
notepad picture:
http://imageupper.com/i/?S0200010080011O13734602521426968
java picture :
http://imageupper.com/i/?A0300010070011I13734604591427932
The same letters are in both images, so it's not problem of encoding.
The problem is that you have to set a proper font to the textfield. You can create the font if you don't have it, check this setting custom font
#AndrewThompson answer :)
Edit: That other user with the same question that you have mentioned is me. :)
As I found out, the char data type is not enough to render letters like "ශ්‍ර" because it needs 3 8bit characters. And the Java language isn't going to change the size of char data type just because we Sri Lankans want to render our characters. I had the similar question previously and I am the user you mentioned in your question.
"ශ්‍ ර" is shown with 2 8bit characters for each character and that's all we got till now. You might want to checout SWT because it shows characters pretty damn well in my experience.

Eclipse IDE Scope Highlighting?

When I first learned Java, I was using an IDE called "BlueJ." It had this feature called "Scope Highlighting" which made it very easy to read blocks of code. Now I've moved on from BlueJ and began using Eclipse. I'm currently in the process of customizing Eclipse to my liking and would like this Scope Highlighting feature inside Eclipse.
I've searched everywhere for an answer on how to do it but I cannot find any information pointing to a solution for doing it in Eclipse.
Here's a picture to demonstrate what Scope Highlighting looks like:
I think the best option for you is EditBox, a scope highlighting plugin for Eclipse:
http://editbox.sourceforge.net/
I'm afriad that closest you can get is Shift + Alt + arrow_up
It is selecting wider block of code. pressing this few times will give you very similar result to what you are searching for. I use it often.. it is useful, also for refactoring.
EDIT: As #j2emanue said: you can just double click the delimiter (like a bracket) and it will highlight the entire scope.
you can use Shift + Alt + arrow_up but many people dont realize you can just double click the delimiter (like a bracket) and it will highlight the entire scope. Try double clicking your if statements bracket for example and watch eclipse highlight the entire scope. It works with any delimiter. so you can use parenthesis as well.
as a side note: if your using intelliji checkout this plugin works great: https://github.com/izhangzhihao/intellij-rainbow-brackets#screenshots
This isn't exactly what you're after but you can put your cursor in a method and then click the Show Source Of Selected Element only button on the toolbar. Your editor gets reduced to just that method. Click again and your back to your entire file.
I doubt eclipse does have the same function as blue j.The best advise I can give you, is to change your theme to your liking which would enable you to easily select and highlight the block of code...and to customise your theme , go to http://eclipsecolorthemes.org/. ....
If you still have a problem, go to http://codejava.co.uk/contact.html and send your email.you can create a dummy one if want, then I will send you XML files I use for my eclipse themes.
can Bracketeer do this ? its an eclipse plug in ..
http://marketplace.eclipse.org/content/bracketeer-java-jdt#.UK6sY4fAdLc
Maybe you will also like the VSCode extension "Blockman". It highlights nested code blocks based on curly/square/round brackets, html/xml tags and Python/Yaml indentation. (I am the author of Blockman).
.
https://i.ibb.co/31F0rm9/vscode-blockman-intro-leodevbro-extension3.png
.
.

Categories