Skip to content

Instantly share code, notes, and snippets.

Piotr Wittchen pwittchen

Block or report user

Report or block pwittchen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pwittchen
pwittchen / decodeSampledBitmap.java
Last active Aug 29, 2015
Decode sampled bitmap from file path.
View decodeSampledBitmap.java
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);
}
View application.xml
<application
android:name="com.pwittchen.example.generics.GenericApplication">
@pwittchen
pwittchen / Contact.java
Created Mar 2, 2014
Sample Contact class.
View Contact.java
public class Contact {
public int id;
public String name;
public String phone;
public String email;
public String uriString;
}
View GenericApplication.java
public class GenericApplication extends Application {
private static Application instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static Context getContext() {
View selection.java
String selection = STARRED_CONTACT + "='1'";
View permission.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
View SampleListview.java
@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();
View performClick.java
private void clickOnListItem(int position) {
contactList.performItemClick(contactListView, position, contactListView.getItemIdAtPosition(position));
}
View ContactsAdapter.java
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);
View uploadAndroidExample01.java
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 = "";
You can’t perform that action at this time.