Word wrap text with break word in Android EditText

class WordBreakTransformationMethod extends ReplacementTransformationMethod
{
    private static WordBreakTransformationMethod instance;

    private WordBreakTransformationMethod() {}

    public static WordBreakTransformationMethod getInstance()
    {
        if (instance == null)
        {
            instance = new WordBreakTransformationMethod();
        }

        return instance;
    }

    private static char[] dash = new char[] {'-', '\u2011'};
    private static char[] space = new char[] {' ', '\u00A0'};

    private static char[] original = new char[] {dash[0], space[0]};
    private static char[] replacement = new char[] {dash[1], space[1]};

    @Override
    protected char[] getOriginal()
    {
        return original;
    }

    @Override
    protected char[] getReplacement()
    {
        return replacement;
    }
}
myEditText.setTransformationMethod(WordBreakTransformationMethod.getInstance());

References
https://stackoverflow.com/questions/22289161/word-wrap-break-word-in-edittext

Remote Debug Java Spring Boot in Intellij IDEA

Create Deployment Profile


Create Debug Configuration

Connect to server via SSH and go to mapped folder and run Spring Boot with –debug-jvm

gradle bootRun --debug-jvm

On Intellij IDEA run remote debug configuration

References
https://stackoverflow.com/questions/39490624/how-to-debug-spring-application-with-gradle
https://stackoverflow.com/questions/975271/remote-debugging-a-java-application
https://jdpgrailsdev.github.io/blog/2014/07/15/spring_boot_remote_debug.html

Sending email via Gmail SMTP in Java

Gradle

// https://mvnrepository.com/artifact/javax.mail/javax.mail-api
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.0'

// https://mvnrepository.com/artifact/com.sun.mail/javax.mail
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'

GMail via SSL

package com.mkyong.common;

import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMailSSL {
	public static void main(String[] args) {
		Properties props = new Properties();
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.socketFactory.port", "465");
		props.put("mail.smtp.socketFactory.class",
				"javax.net.ssl.SSLSocketFactory");
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.port", "465");

		Session session = Session.getDefaultInstance(props,
			new javax.mail.Authenticator() {
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication("username","password");
				}
			});

		try {

			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress("[email protected]"));
			message.setRecipients(Message.RecipientType.TO,
					InternetAddress.parse("[email protected]"));
			message.setSubject("Testing Subject");
			message.setText("Dear Mail Crawler," +
					"\n\n No spam to my email, please!");

			Transport.send(message);

			System.out.println("Done");

		} catch (MessagingException e) {
			throw new RuntimeException(e);
		}
	}
}

If you want to send HTML message :

message.setContent(someHtmlMessage, "text/html; charset=utf-8");

References
https://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/
https://stackoverflow.com/questions/5068827/how-do-i-send-an-html-email
https://www.campaignmonitor.com/css/
https://stackoverflow.com/questions/16807758/java-lang-noclassdeffounderror-com-sun-mail-util-maillogger-for-junit-test-case
https://stackoverflow.com/questions/46663/how-can-i-send-an-email-by-java-application-using-gmail-yahoo-or-hotmail
https://developers.google.com/gmail/api/guides/sending

Set a timer in Android using Handler

Runnable:

private final int interval = 1000; // 1 Second
private Handler handler = new Handler();
private Runnable runnable = new Runnable(){
    public void run() {
        Toast.makeText(MyActivity.this, "C'Mom no hands!", Toast.LENGTH_SHORT).show();
    }
};
...
handler.postAtTime(runnable, System.currentTimeMillis()+interval);
handler.postDelayed(runnable, interval);

Message:

private final int EVENT1 = 1; 
private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {         
        case Event1:
            Toast.makeText(MyActivity.this, "Event 1", Toast.LENGTH_SHORT).show();
            break;

        default:
            Toast.makeText(MyActivity.this, "Unhandled", Toast.LENGTH_SHORT).show();
            break;
        }
    }
};

...

Message msg = handler.obtainMessage(EVENT1);
handler.sendMessageAtTime(msg, System.currentTimeMillis()+interval);
handler.sendMessageDelayed(msg, interval);

References
https://stackoverflow.com/questions/1877417/how-to-set-a-timer-in-android