Wednesday, November 6, 2013

Difference between px, dp, dip and sp in Android.

px is one pixel. scale-independent pixels ( sp ) and density-independent pixels ( dip ) you want to use sp for font sizes and dip for everything else.dip==dp

px
Pixels - corresponds to actual pixels on the screen.
in
Inches - based on the physical size of the screen.
mm
Millimeters - based on the physical size of the screen.
pt
Points - 1/72 of an inch based on the physical size of the screen.
dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
How To Change Text Color And Back Ground Color Of Action Bar In Android.

Text Color:-
according to my knowledge,the id of Action Bar Title id hidden,first you have to get id of that Acton Bar Title like:-

int ActionBarTitleID = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
 now use settext on this ID like 
TextView yourTextView = (TextView)findViewById(ActionBarTitleID); yourTextView.setTextColor(colorId);



If you use 
Sherlock Actionbar you may use the sherlock-actionbar-id for supported actionbars (Android below 3.0)

int titleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android"); 
if ( 0 == titleId ) titleId = com.actionbarsherlock.R.id.abs__action_bar_title;



Back Ground Color:-

mActionBar.setBackgroundDrawable(new ColorDrawable(0xff00DDED)); mActionBar.setDisplayShowTitleEnabled(false);

 mActionBar.setDisplayShowTitleEnabled(true);

Saturday, November 2, 2013

How To Send Email In Android Or Java With Proxy Server.



import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class EMailSender {
public EMailSender(String host, final String from, final String pass, String to, String sub, String mess) throws Exception {
Properties props = System.getProperties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
Authenticator auth = new Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from, pass);
}};
Session session = Session.getInstance(props, auth);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject(sub);
message.setText(mess);
Transport.send(message);
}

public static void main(String arg[]) throws Exception {
if(arg.length == 5) {
StringBuilder message = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String temp = "", subject;
System.out.print("Enter subject: ");
subject = br.readLine();
System.out.println("Enter the message (end it with a . on a single line):");
while((temp = br.readLine()) != null) {
if(temp.equals("."))
break;
message.append(temp+"\n");
}
System.out.println("Sending message...");
new EMailSender(arg[0], arg[1], arg[2], arg[3], subject, message.toString());
System.out.println("Sent the message.");
}
else System.err.println("Usage:\njava SendTextMail <host> <port> <from> <pass> <to>");
}
}


Call Constructor Of This Class In Your Activity On Button Click.