This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Bitmap decodeSampledBitmap(String filePath, int reqWidth, int reqHeight) { | |
final BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = true; | |
BitmapFactory.decodeFile(filePath,options); | |
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); | |
options.inJustDecodeBounds = false; | |
return BitmapFactory.decodeFile(filePath,options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Contact { | |
public int id; | |
public String name; | |
public String phone; | |
public String email; | |
public String uriString; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GenericApplication extends Application { | |
private static Application instance; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
instance = this; | |
} | |
public static Context getContext() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String selection = STARRED_CONTACT + "='1'"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.READ_CONTACTS" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
android:name="com.pwittchen.example.generics.GenericApplication"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContactsAdapter extends BaseAdapter { | |
private final ArrayList list; | |
private int selectedItem = -1; // no item selected by default | |
// put neccessary code here - it's not important in this description | |
public ContactsAdapter(List<Contact> contacts) { | |
list = new ArrayList(); | |
list.addAll(contacts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onResume() { | |
List<Contact> contacts = getContactsFromYourSource(); | |
ContactsAdapter contactsAdapter = new ContactsAdapter(contacts); | |
contactListView.setAdapter(contactsAdapter); | |
highlightListItem(2); // this simple function call does the trick | |
} | |
private void highlightListItem(int position) { | |
ContactsAdapter contactsAdapter = (ContactsAdapter) contactListView.getAdapter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void clickOnListItem(int position) { | |
contactList.performItemClick(contactListView, position, contactListView.getItemIdAtPosition(position)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String multipartRequest(String urlTo, String post, String filepath, String filefield) throws ParseException, IOException { | |
HttpURLConnection connection = null; | |
DataOutputStream outputStream = null; | |
InputStream inputStream = null; | |
String twoHyphens = "--"; | |
String boundary = "*****"+Long.toString(System.currentTimeMillis())+"*****"; | |
String lineEnd = "\r\n"; | |
String result = ""; |
OlderNewer