Skip to content

Instantly share code, notes, and snippets.

View pwittchen's full-sized avatar
🎯
Focusing

Piotr Wittchen pwittchen

🎯
Focusing
View GitHub Profile
@pwittchen
pwittchen / decodeSampledBitmap.java
Last active August 29, 2015 13:56
Decode sampled bitmap from file path.
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);
}
@pwittchen
pwittchen / Contact.java
Created March 2, 2014 21:58
Sample Contact class.
public class Contact {
public int id;
public String name;
public String phone;
public String email;
public String uriString;
}
@pwittchen
pwittchen / GenericApplication.java
Created March 2, 2014 22:09
GenericApplication class
public class GenericApplication extends Application {
private static Application instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static Context getContext() {
String selection = STARRED_CONTACT + "='1'";
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:name="com.pwittchen.example.generics.GenericApplication">
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);
@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();
private void clickOnListItem(int position) {
contactList.performItemClick(contactListView, position, contactListView.getItemIdAtPosition(position));
}
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 = "";