Posts

GPlayServices #1: Save to Google Drive

Image
A little snippet to save a file (or some contents) in Google Drive with the Drive API included in the Google Play Services . To use the Google Drive API we have to follow these steps:(this blog doesn't cover these topics) : Set Up Google Play Services SDK Register your app in Google Developers Console to activate the API Now we can build our code. First of all, we have to create an instance of GoogleApiClient using the GoogleApiClient.Builder and implementing the callback interfaces to manage the connection and the authorizations as described in GPlay Service #0 . Our scope is to save a file (an image) choosing a folder in Google Drive. To choose a folder inside our Google Drive we can use the Drive.DriveApi.newOpenFileActivityBuilder() . This method creates a builder for an Open File activity that allows user selection of a Drive file. Upon completion, the result Intent will contain the DriveId for the selected file. We can use the OnConnected interface to know...

GPlayServices #0: Configure the GoogleApiClient with Google Play Services.

Image
A little snippet to connect your app with the Google Play Services API. To use the Google Play Services API you have to follow these steps:(this blog doesn't cover these topics) : Set Up Google Play Services SDK Register your app in Google Developers Console to activate the API Now you can build your code. First of all, create an instance of GoogleApiClient using the GoogleApiClient.Builder. /** * Called when activity gets visible. A connection to Drive services need to * be initiated as soon as the activity is visible. Registers * {@code ConnectionCallbacks} and {@code OnConnectionFailedListener} on the * activities itself. */ @Override protected void onResume() { super.onResume(); if (mGoogleApiClient == null) { mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addScope(Drive.SCOPE_APPFOLDER) ...

Integrating an Android Github repo with Travis Ci with the new Android Plugin

In my previous post I wrote how to integrate an Android Github repo with Travis Ci. Now we can change something in our travis.yml , using the new Android plugin . Warning:The features described here are still in development! All the considerations described in the old post remain valid, but we can update some parts. First, declare the new language : language: android With this line, travis provides the Android SDK 22.6.2 with following preinstalled components : platform-tools android-19 sysimg-19 (ARM) android-18 sysimg-18 (ARM) android-17 sysimg-17 (ARM) android-16 sysimg-16 (ARM) android-15 sysimg-15 (ARM) android-10 extra-android-support extra-google-google_play_services extra-google-m2repository extra-android-m2repository Here you can find the updated list . Then we can add or update (a.k.a. re-install) some components to get the latest minor versions: android: components: - build-tools-19.0.3 Under the wood the plugin runs the command: androi...

Integrating an Android Github repo with Travis Ci

I have spent a bit of time to integrate my github repos with Travis CI . Travis is a hosted continuous integration service for the open source community and it is very popular, but I saw very few open-source Android projects which are using Travis. The main reason is that Travis CI's build environment provides different runtimes for different languages but it is not pre-configured with Android SDK, build tools, therefore it requires some knowledge. First of all, I am not an expert! The first steps to integrate travis with Github are very easy. 1. Sign in with your GitHub account and authorize Travis. Here you can find more detail about permissions . 2. Activate your projects in your profile page Then the real focal point: 3. Add .travis.yml to the root of your repository . In order for Travis CI to build your project, you need to tell the system a little bit about it. First, declare language . It tells Travis CI which language environment to select for your projec...

Snippet: align a TextView around an image

Image
A few weeks ago I discovered the Spans on Android,after reading the wonderful post by Flavien Laurent . In this post I will describe how to realize a particular layout not very common on Android: a text around an image. This layout is not an Android Pattern, but it can be useful in same cases. As always it is just an example, and you should improve some points in your real project. Use a simple layout: To achieve our scope, we can use a LeadingMarginSpan.LeadingMarginSpan2 . This span allows the implementor to specify the number of lines of text to which this object is attached that the "first line of paragraph" margin width will be applied to. /** * */ class MyLeadingMarginSpan2 implements LeadingMarginSpan.LeadingMarginSpan2 { private int margin; private int lines; MyLeadingMarginSpan2(int lines, int margin) { this.margin = margin; th...

A way to evaluate an Android open source library

This last year, I have had opportunity to learn many things about open source libraries. Working on my small library (thanks to everybody for the support and help!) I could see some aspects on the other side. Before using a library, you should check some points. License It is a very focal point! The first thing to look at is the what license the code has been released. Open source doesn't mean that you can use the code in any context. There are various types of licenses and you should check if the license is compatible with your project otherwise you can have legal issues. Maintenance Check the last commits in the repository. If the last commit was 1 year ago likely the project has been abandoned (or it is complete and doesn't require updates...). Also it is very important to check how often the project is updated (or was updated). Do not underestimate this point. If you use a library which is no longer maintained, you could have problems in the future. Branch...

Drawing shapes with fingers

Image
It is very simple to draw basic shapes with fingers. As always, it is just an example, you can improve it in many ways. First of all we need a custom View . public class DrawingView extends View { } Then we will use a Bitmap, a Canvas and a Paint ojbects: protected Paint mPaint; protected Bitmap mBitmap; protected Canvas mCanvas; To initialize the bitmap and the canvas, we can override this method in our View: @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } If you need to create a new Canvas, you must define the Bitmap upon which drawing will actually be performed. The Bitmap is always required for a Canvas. Then we can define the paint object. The Paint holds the information about the style and the color which we will use to draw. For example: public...