Search This Blog

Sunday, September 29, 2013

Friday, September 6, 2013

Android change time zone - programmatically

i use the next code to change OS time zone ... seems to be working

AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone("Europe/Athens");

add the next permisiion :
android.permission.SET_TIME_ZONE


Sunday, September 1, 2013

SVN - for dummies

Create TAG , is good idea when you have like a big delivery to client.
TAG is like base line.
while Brunch is like a Stream.

Trunk is the main development stream , Usually you will have Tags on the trunk.

you can Merge stuff from brunch to trunk - with the merge options.



Friday, August 23, 2013

Android screen size info

Supporting Multiple Screens


nice tool
http://coh.io/adpi/

Understanding Screen Densities and the “dp”

Resolution is the actual number of pixels available in the display, density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface. These are interrelated: increase the resolution and density together, and size stays about the same. This is why the 320x480 screen on a G1 and 480x800 screen on a Droid are both the same screen size: the 480x800 screen has more pixels, but it is also higher density.
To remove the size/density calculations from the picture, the Android framework works wherever possible in terms of "dp" units, which are corrected for density. In medium-density ("mdpi") screens, which correspond to the original Android phones, physical pixels are identical to dp's; the devices’ dimensions are 320x480 in either scale. A more recent phone might have physical-pixel dimensions of 480x800 but be a high-density device. The conversion factor from hdpi to mdpi in this case is 1.5, so for a developer's purposes, the device is 320x533 in dp's.

Screen-size Buckets

Android has included support for three screen-size “buckets” since 1.6, based on these “dp” units: “normal” is currently the most popular device format (originally 320x480, more recently higher-density 480x800); “small” is for smaller screens, and “large” is for “substantially larger” screens. Devices that fall in the “large” bucket include the Dell Streak and original 7” Samsung Galaxy Tab. Android 2.3 introduced a new bucket size “xlarge”, in preparation for the approximately-10” tablets (such as the Motorola Xoom) that Android 3.0 was designed to support.
The definitions are:
  • xlarge screens are at least 960dp x 720dp.
  • large screens are at least 640dp x 480dp.
  • normal screens are at least 470dp x 320dp.
  • small screens are at least 426dp x 320dp. (Android does not currently support screens smaller than this.)
Here are some more examples of how this works with real screens:
  • A QVGA screen is 320x240 ldpi. Converting to mdpi (a 4/3 scaling factor) gives us 426dp x 320dp; this matches the minimum size above for the small screen bucket.
  • The Xoom is a typical 10” tablet with a 1280x800 mdpi screen. This places it into the xlarge screen bucket.
  • The Dell Streak is a 800x480 mdpi screen. This places it into the bottom of the large size bucket.
  • A typical 7” tablet has a 1024x600 mdpi screen. This also counts as a large screen.
  • The original Samsung Galaxy Tab is an interesting case. Physically it is a 1024x600 7” screen and thus classified as “large”. However the device configures its screen as hdpi, which means after applying the appropriate ⅔ scaling factor the actual space on the screen is 682dp x 400dp. This actually moves it out of the “large” bucket and into a “normal” screen size. The Tab actually reports that it is “large”; this was a mistake in the framework’s computation of the size for that device that we made. Today no devices should ship like this.


Thursday, July 18, 2013

sim card - How to get all android contacts but without those which are on SIM

sim card - How to get all android contacts but without those which are on SIM - Stack Overflow:


i used the next function to get the contacts  with phone, include/exclude from sim  , in one query
the function is part of big program so you might need to change /add it

// the idea is get the contacts with the phone first
public static List<Contact> getContacts(Context context,
boolean favoritesOnly, boolean removeSimContacts) {

boolean withEmail = true;
List<Contact> contactsList = null;
HashMap<String, Contact> contactsMap = new HashMap<String, Contact>();
String starred = favoritesOnly ? " AND starred=1 " : "";
String sNOSimContacs = removeSimContacts ? "%sim%": "%%";
String filter = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1 " + starred + " AND " ;
if(removeSimContacts)
filter += RawContacts.ACCOUNT_TYPE + " NOT LIKE ? AND ";
else
filter += RawContacts.ACCOUNT_TYPE + " LIKE ? AND ";

filter += Data.MIMETYPE + "=?";

Cursor cursor = null;
try {

String[] projection = new String[] {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
ContactsContract.Contacts._ID,
ContactsContract.Contacts.STARRED,
ContactsContract.CommonDataKinds.Phone.DATA,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.LABEL,
ContactsContract.RawContacts.CONTACT_ID};

cursor = context.getContentResolver().query(Data.CONTENT_URI,
projection,
filter, new String[] { sNOSimContacs,Phone.CONTENT_ITEM_TYPE},
ContactsContract.Contacts.DISPLAY_NAME);

while (cursor != null && cursor.moveToNext()) {

String contactId = cursor.getString(cursor
.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));
// if we dont have this contact add it
// if the user have multi numbers we get the same contact here
if(!contactsMap.containsKey(contactId)){
Contact contact;

if(Const.IS_USE_SHARED_PREF_ONLY)
contact = ContactProviderAlternative.getContact(context,
Integer.parseInt(contactId));
else
contact = ContactProvider.getContact(context,
Integer.parseInt(contactId));

// if (favoritesOnly)
// Log.d("Info", "pos: " + contact.getContactPosition());


boolean isFav  = (cursor.getShort(cursor
.getColumnIndex(ContactsContract.Contacts.STARRED)) == 1);

contact.setFavorite(isFav);
contact.setContactId(contactId);
contact.setContactName(cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
contact.setContactPhoto(Utils.openPhoto(context,
Long.parseLong(contactId), false));
contact.setContactUri(Integer.parseInt(contactId));
contact.setContactPhone(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA)));
int type = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
contact.setContactPhoneType(type == 1 ? Const.NEW_CONTACT_PHONE_TYPE_LANDLINE : Const.NEW_CONTACT_PHONE_TYPE_MOBILE);

contactsMap.put(contactId,contact);
}else{
// we have this conatct lets update his phone the latest one we get
Contact contact = contactsMap.get(contactId);
contact.setContactPhone(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA)));
int type = cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
contact.setContactPhoneType(type == 1 ? Const.NEW_CONTACT_PHONE_TYPE_LANDLINE : Const.NEW_CONTACT_PHONE_TYPE_MOBILE);
}
}
if(cursor != null){
cursor.close();
cursor = null;
}

contactsList = new ArrayList<Contact>(contactsMap.values());
if(withEmail){
String[] projectionEmail = new String[] {
ContactsContract.CommonDataKinds.Email.DATA,
ContactsContract.CommonDataKinds.Email.TYPE,
ContactsContract.CommonDataKinds.Email.LABEL
};

String where= Data.CONTACT_ID + " = ? AND " + Data.MIMETYPE + "=?";

for(Contact c : contactsList){
//email & phone

String[] params = new String[]{c.getContactId(), Email.CONTENT_ITEM_TYPE};

cursor = context.getContentResolver().query(
Data.CONTENT_URI,
       projectionEmail,
       where,
       params,
       null);

while(cursor != null && cursor.moveToNext()) {
c.setContactEmail(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
    }
if(cursor != null){
cursor.close();
cursor = null;
}

}
}

}

catch (Exception e) {
e.printStackTrace();
}finally{
if(cursor != null)
cursor.close();
}

return contactsList;
}

Yaniv Tzannay

Sunday, July 14, 2013

Android icons size for tab

for mdpi use - 32x32 pixel
for hdpi use - 48x48 pixel
for xhdpi use - 64x64 pixel

more stuff could be found here

Iconography

http://developer.android.com/design/style/iconography.html

please note when you put an image on xhdpi - android know how to scale down your image ...

yaniv tzanany