CODING


  • Debug link shared on facebook

    Sometimes when you share a link to you site on Facebook it uses old thumbnails for the link image. There’s a ton of useful info about your site here: https://developers.facebook.com/tools/debug

  • (Android) Find physical screen size programatically

    This method will find out if screen is a tablet size. You could of course make this even more corner case-compliant by getting the units dpi (dot per inch) and use the Pythagorean theorem to find the actual inch size of the diagonal. But this will probably suffice for most case. [java] private boolean isLargeScreen()…

  • (Android) Custom view orientation change – restore state.

    Here’s one pretty simple way to get your custom view to restore its current state after an orientation change: You can of course put any values in there, for example if you need to restore fields. (quickly plotted code. Haven’t run it, but it should work) [java] @Override protected Parcelable onSaveInstanceState() { Bundle bundle =…

  • (Android) Change background of a bitmap

    Create a new bitmap, with the size and config of the bitmap you wish to change. Create a Canvas and prepare it to paint to the new bitmap. Paint the new bitmap with your color using the canvas object. Draw the old bitmap to the new bitmap through the canvas object. Do what you want…

  • (Android) Convert Density-independent Pixels to Pixels (dp 2 px)

      A simple function to convert dp into pixels. Use when you have to pass pixels to a method and want to keep everything to scale. [java] private int dp2px(int dp) { float scale = getResources().getDisplayMetrics().density; int pixels = (int) (dp * scale + 0.5f); return pixels; } [/java] From Android Developer Center : pxPixels –…

  • (Android) NumberPicker with leading zero

    Set your number picker to show leading zeros by applying a formatter to it. Example is using an anonymous instance, but of course it doesn’t have to. [java] myNumberPicker.setFormatter(new NumberPicker.Formatter() { @Override public String format(int value) { return String.format("%02d", value); } }); [/java] For %02d this goes: 0 for filling with zeros 2 for length…

  • (Android) Set focus to dialog programmatically

    To get the keyboard to pop up after creating a dialog: [java]dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show();[/java]

  • (Java) Convert milliseconds to minutes and seconds (mm:ss)

    For a nice string representation, using the TimeUnit lib: [java] String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(milliSeconds), TimeUnit.MILLISECONDS.toSeconds(milliSeconds) – TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliSeconds))); [/java] or simply do the math: [java] int minutes = (int) (milliSeconds/ 1000) / 60; int seconds = (int) (milliSeconds/ 1000) % 60; [/java] and back to miliseconds again: [java] long milliSeconds= ((minutes * 60) + seconds) * 1000; [/java]

  • (Android) Prevent config change on orientation change

    Add to activity in manifest: [xml]android:configChanges="keyboardHidden|orientation|screenSize"[/xml]

  • CSS3 box shadow

    A nice feauture in CSS3 is the box-shadow. Instead of working with tedious PNG-images you can add shadows to any element with the CSS property box-shadow. The syntax works like this: box-shadow: <offset-x> <offset-y> <blur> <spread> <color> <inset> The offset settings will set the angle of the shadow. Where it will be cast in relation to…