Category: programming

  • Android Genymotion Mock Location Google Play

    To get Android Genymotion Mock Location Google Play fused location provider working in an emulator these are the necessary components and steps.  (For Genymotion 2.5.x emulator versions) Download: Genymotion ARM Translation v1.1 Google Apps / Play Store for a Genymotion emulator running SDK 5.1 (API Level 22) Steps Install these two zipped APK archive files by…

  • Spring Boot SSL with Android Retrofit

    To setup Spring Boot SSL with Android Retrofit connecting on HTTPS 443: In Spring Boot <your project>/src/main/resources/application.properties – add the following values (not the “1.” which is just WordPress ordered list numbering) security.require-ssl=true server.port=8443 server.ssl.key-store=src/main/resources/private/keystore server.ssl.key-store-password=changeit server.ssl.key-password=changeit create and add an SSL key to the location specified by server.ssl.key-store. Note: the SSL certificate file is…

  • Android AsyncTask return result

    To get Android AsyncTask to return a result use a callback method (Observer pattern) by following these steps. Define a constructor for our async class which extends AsyncTask (we’re required to subclass/extend AsyncTask for use). Let’s call our AsyncTask class MyAsyncTask. Constructor parameter takes a class which will handle the AsyncTask result.  Usually an Activity or Fragment,…

  • Retrofit error 415 400 object with Date field Fix @JsonFormat annotation

    Retrofit error 415 or error 400 on an object with a Date field can be fixed by using @JsonFormat annotation with the proper date pattern format specified in the annotation. java.util.Date toString() (for my locale/region) returns a string date format of MMM dd, yyyy hh:mm:ss aa Example: Oct 22, 2015 11:09:55 PM For Retrofit /…

  • H2 Web Console to In Memory Database – Spring Boot

    To get an H2 Database Web Console accessing an in-memory database running on Spring Boot: Register H2’s WebServlet (with UrlMapping /console/*) to your Spring project in a Configuration annotated class. Restart your Application. Open a web page to http://localhost:8080/console/ Be sure you’re accessing the correct database JDBC URL (default would be jdbc:h2:mem:testdb) (Credit: Spring Framework Guru)   import org.h2.server.web.WebServlet;…

  • Android Robolectric Support Fragment FragmentTestUtil

    To use Android Support Fragment v4 in Robolectric 3.0 you must add gradle dependency in /app/build.gradle testCompile ‘org.robolectric:shadows-support-v4:3.0’ Then import into your Robolectric testing java class import org.robolectric.shadows.support.v4.SupportFragmentTestUtil; then you can create/start android support v4 fragments within your Robolectric testing java class for unit testing: SupportFragmentTestUtil.startVisibleFragment(fragment); Cross posted to StackOverflow Android Robolectric Support Fragment.

  • Android Studio generate foreach loop

    Begin typing foreach until autocomplete pops up.  Select “Create a for each loop”. You’ll then get an empty for each loop that you can start filling in, first supplying the Type of each object, a variable name of your choice for that object, then hit Enter to move to the name of the variable (a…

  • Android Studio androidTest sourceSets gradle not recognized

    Android Studio (app) build.gradle sourceSets androidTest java.srcDir property may not be recognized when using the array format of this source directory property setting. BAD sourceSets { androidTest { java.srcDirs = [‘androidTest/java’] } } GOOD sourceSets { androidTest { java.srcDir file(‘androidTest/java’) } } For setting up Robotium UI / Integration testing, it’s important that your androidTest source directory…

  • Refresh Gradle build.gradle Dependencies

    In Project Explorer: Right click on Gradle project Gradle Refresh All New dependencies should be downloaded and project refreshed. Java import statements for new Gradle project dependencies should work after this.

  • Eclipse – Add Java Gradle Project to existing Eclipse Project

    How to add a java Gradle Project into an existing Eclipse project Start by importing your required Java Gradle projects into Eclipse’s Project Explorer. Highlight your main project in Project Explorer. This is the project you want to add a Gradle java project to (so you can use import statements on packages found in the other Gradle project).…