Oct 31, 2014

NumberFormatException



If version lower than jelly-bean, you can see the exception, Of you setting range of scale animation 0%~100%.

Range of scale-animation  of the version can use just 0~1.

So I delete '%' and changed range.

Now my Genie sudoku Baseball is normal.




And my app updated score board!!



Oct 23, 2014

Simple android input popup


We using intent for popup window.

  1. intent=new Intent(getApplicationContext(),yourtext.class);
  2. startActivityForResult(intent,text);

And need a onActivityResult method and manifest setting!!

But we making simple popup using AlterDialog!!

  1.             AlertDialog.Builder alert = new AlertDialog.Builder(this);
  2.             alert.setTitle("Input your name");
  3.             alert.setMessage("Plz, input yourname");
  4.            
  5.             final EditText name = new EditText(this);
  6.             alert.setView(name);
  7.             alert.setPositiveButton("ok"new DialogInterface.OnClickListener() {
  8.                 public void onClick(DialogInterface dialog, int whichButton) {
  9.                     String username = name.getText().toString();
  10.                    
  11.                 }
  12.             });
  13.             alert.setNegativeButton("no",new DialogInterface.OnClickListener() {
  14.                         public void onClick(DialogInterface dialog, int whichButton) {
  15.                    
  16.                         }
  17.                     });
  18.            
  19.             alert.show();

See line 7~8!! adding EditText from normally alterdialog.

If we click to 'ok'button, we using edittext's text.

<Run>

This is simply popup input window!!



Make a Random number by Java(Android)


Math.random() method is useful for making random number.

Return value of Math.random() is double 0.0~1.0

If you want 'integer number',multiply 'integer number'.

For example, if you making lotto program.

In Korea, lotto has 45 numbers. 

Math.random()*45

  1. int lotto_first=(int)((Math.random()*44)+1);

Why '+1' ??

Because lotto number's range is 1~45.

Okay, we can using this code. But we meet another problem.

Duplication!!

So, we need checking duplicate.

But I propose another method.

'arraylist' and 'collection.shuffle'.

  1. ArrayList<Integer> lotto = new ArrayList<Integer>(45);
  2. lotto.add(1);lotto.add(2);lotto.add(3);lotto.add(4);lotto.add(5);
  3. lotto.add(6);lotto.add(7);lotto.add(8);lotto.add(9);lotto.add(10);
  4. .....
  5. lotto.add(36);lotto.add(37);lotto.add(38);lotto.add(39);lotto.add(40);
  6. lotto.add(41);lotto.add(42);lotto.add(43);lotto.add(44);lotto.add(45);
  7. Collections.shuffle(lotto);
  8. lotto_first=lotto.get(0);
  9. lotto_second=lotto.get(1);
  10. lotto_third=lotto.get(2);
  11. lotto_fourth=lotto.get(3);
  12. lotto_fifth=lotto.get(4);
  13. lotto_sixth=lotto.get(5);
  14. lotto_bonus=lotto.get(6);

We can make arraylist.

The arraylist's size is 45. 

We add lotto number to the arraylist then shuffle using 'collections.shuffle'.

Then we getting lotto number from arraylist!!




Genie Baseball published!!


I publishing new game for android.

The game name is Genie baseball!!

Genie baseball is number baseball

You can download it from Google play. 









Oct 8, 2014

email service by spring



First, need a dependency.

You can add dependency using mouse right click to pom.xml  then typing mail.

Or this way.

Add this code.

  1.     <!-- java mail -->
  2.     <dependency>
  3.         <groupId>javax.mail</groupId>
  4.         <artifactId>mail</artifactId>
  5.         <version>1.4</version>
  6.     </dependency>

Second, add package folder and java file Email.java, EmailSender.java.




Email.java is setter and getter, EmailSender.java is sender.

This is Email.java

  1. public class Email {
  2.     private String subject;
  3.     private String content;
  4.     private String receiver;
  5.      
  6.     public String getReceiver() {
  7.         return receiver;
  8.     }
  9.     public void setReceiver(String receiver) {
  10.         this.receiver = receiver;
  11.     }
  12.     public String getSubject() {
  13.         return subject;
  14.     }
  15.     public void setSubject(String subject) {
  16.         this.subject = subject;
  17.     }
  18.     public String getContent() {
  19.         return content;
  20.     }
  21.     public void setContent(String content) {
  22.         this.content = content;
  23.     }
  24. }

Email.java consist of subject, content and receiver.

This is EmailSender.java

  1. import javax.mail.MessagingException;
  2. import javax.mail.internet.InternetAddress;
  3. import javax.mail.internet.MimeMessage;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.mail.MailException;
  6. import org.springframework.mail.javamail.JavaMailSender;
  7.    
  8.     public class EmailSender  {
  9.          
  10.         @Autowired
  11.         protected JavaMailSender  mailSender;
  12.         public void SendEmail(Email email) throws Exception {
  13.              
  14.             MimeMessage msg = mailSender.createMimeMessage();
  15.             try {
  16.                 msg.setSubject(email.getSubject());
  17.                 msg.setText(email.getContent());
  18.                 msg.setRecipients(MimeMessage.RecipientType.TO , InternetAddress.parse(email.getReceiver()));
  19.                
  20.             }catch(MessagingException e) {
  21.                 System.out.println("MessagingException");
  22.                 e.printStackTrace();
  23.             }
  24.             try {
  25.                 mailSender.send(msg);
  26.             }catch(MailException e) {
  27.                 System.out.println("MailException발생");
  28.                 e.printStackTrace();
  29.             }
  30.         }
  31. }

EmailSender getting content, receiver and subject from Email.java then Sending using JavaMailSender.

This is Controller code.

  1.    @Autowired
  2.    private EmailSender emailSender;
  3.    @Autowired
  4.    private Email email;
  5.     @RequestMapping("/sendpw.do")
  6.     public ModelAndView sendEmailAction (@RequestParam Map<String, Object> paramMap, ModelMap model) throws Exception {
  7.         ModelAndView mav;
  8.         String id=(String) paramMap.get("id");
  9.         String e_mail=(String) paramMap.get("email");
  10.         String pw=mainService.getPw(paramMap);
  11.         System.out.println(pw);
  12.         if(pw!=null) {
  13.             email.setContent("비밀번호는 "+pw+" 입니다.");
  14.             email.setReceiver(e_mail);
  15.             email.setSubject(id+"님 비밀번호 찾기 메일입니다.");
  16.             emailSender.SendEmail(email);
  17.             mav= new ModelAndView("redirect:/login.do");
  18.             return mav;
  19.         }else {
  20.             mav=new ModelAndView("redirect:/logout.do");
  21.             return mav;
  22.         }
  23.     }

This code getting id and e-mail from jsp.

And check the information. 

If id and e-mail is right getting password from database.

This is bean setting.

  1. <!-- gmail -->
  2.     <bean id="mailSender" class ="org.springframework.mail.javamail.JavaMailSenderImpl" >
  3.         <property name="host" value="smtp.gmail.com" />
  4.         <property name="port" value="587" />
  5.         <property name="defaultEncoding" value="utf-8"/>
  6.         <property name="username" value="your id@gmail.com" />
  7.         <property name="password" value="your password" />
  8.        
  9.         <property name="javaMailProperties">
  10.             <props>
  11.                 <prop key="mail.smtp.starttls.enable">true</prop>
  12.                 <prop key="mail.smtp.auth">true</prop>
  13.                
  14.                
  15.             </props>
  16.         </property>
  17.        
  18.     </bean>
  19.     <bean id="email" class="spring.board.email.Email">
  20.     </bean>
  21.     <bean id="emailSender" class="spring.board.email.EmailSender">
  22.     </bean>

Line 2~18 : mailSender is bean for JavaMailSender.

The bean consist of protocol, port, username and password.

Detail setting for Gmail is here .

Line 19~22 is bean for  email and emailSender.

Running program

Redbox is link searching password.

If you click to link.


You can typing id and e-mail then click to button.



Go to my mailbox.

Arrived mail.



You can see your password.

If e-mail is wrong you can see this.