Example how to take photo and upload it’s thumbnail to your server using okhttp3 (first I convert it to jpeg)

Categories: ANDROID like

//part when you click on item and start camera imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Context context = v.getContext(); if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } } }); //part when you get the thumbnail from camera @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { […]

Notepad++ with regex, re-using match variables

Categories: NON ANDROID like

Here is an simple example how to use regex in notepad++ with reusing selected match variables. For example we have special code for simulating gcm notifications. We would like to see it in pretty style. To achieve this we must to move all elements with minus to the new lines. How to do it? Here […]

Working example POST in android

Categories: ANDROID like

Here is another short (IMHO) example how to post in android app. private void postSms(String text) { URL url; HttpURLConnection urlConnection = null; try { url = new URL("http://yourserver.com/sendsms"); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoOutput(true); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("sms", text));//POST param as "sms" OutputStream os = urlConnection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new […]

GCM notification with custom sound – shorter version (part)

Categories: ANDROID like

Here is a short example how to create notification with default stuff but different sound: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("title") .setStyle(new NotificationCompat.BigTextStyle() .bigText("message")) .setContentText("message") .setAutoCancel(true) .setSound(soundUri) .setDefaults(NotificationCompat.DEFAULT_ALL ^ NotificationCompat.DEFAULT_SOUND); The most important part is here: .setDefaults(NotificationCompat.DEFAULT_ALL ^ NotificationCompat.DEFAULT_SOUND) Symbol ^ says “except”, so the last part would say “give me default notification except […]

Working example – changing drawable background in runtime, dynamically

Categories: NON ANDROID like

Here is a short example code how to do it: I’ve created xml file shape.xml and one method for flexible changing color of shape. shape.xml: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="@android:color/holo_blue_bright" /> <corners android:radius="30dp" /> <size android:height="15dp" android:width="15dp" /> </shape> And here is a method for flexible changing color:

Working example of setting alarm with repeating stuff, checking if alarm was set with pendingIntent

Categories: ANDROID like

Here is short and quite (imho) understanding part of code: //starting #1 AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(getActivity(), MyReceiver.class); intent.setAction(MyReceiver.ACTION_ALARM_RECEIVER);//my custom string action name PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 1001, intent, PendingIntent.FLAG_CANCEL_CURRENT);//used unique ID as 1001 alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), aroundInterval, pendingIntent);//first start will start asap #1 – first we are getting alarm service. […]

Custom checkable list item with checkbox (layout+code)

Categories: ANDROID like

Here is simple example how to create simple checkable list item with checbox. This a code for widget: public class CheckableTextView extends LinearLayout { private TextView checkLabel; private CheckBox checkBox; public CheckableTextView(Context context) { super(context); } public CheckableTextView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public CheckableTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, […]