Maven & Android: complete pom.xml files contents

The complete pom.xml file I use for Android projects is as follows. 1. Main Android application's pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>pl.looksok</groupId> <artifactId>ColCalc</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>apk</packaging> <build> <sourceDirectory>${project.basedir}/src</sourceDirectory> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.3.2</version> <configuration> <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> <assetsDirectory>${project.basedir}/assets</assetsDirectory> <resourceDirectory>${project.basedir}/res</resourceDirectory> <genDirectory>${project.basedir}/gen</genDirectory> <deleteConflictingFiles>true</deleteConflictingFiles> <undeployBeforeDeploy>true</undeployBeforeDeploy> <sdk> <platform>7</platform> </sdk> </configuration> <extensions>true</extensions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> … Continue reading Maven & Android: complete pom.xml files contents

Android: remove confirmation dialog window

Another tutorial today is how to build confirmation dialog window. Android provides API for that. What I am going to build here is dialog window triggered by some action (button click) and react on confirm or cancel button click: 1. Create dialog's id constant This is simply dialog's ID. it should be unique among any … Continue reading Android: remove confirmation dialog window

Android custom ListView tutorial (including source code)

This tutorial will show how to prepare ListView with custom items and buttons (with click handlers) like this: Source Code The source code for this tutorial is in this post. You can download it and use as You like. 1. Create single list item layout Item consists of three views: name, value (EtitTexts) and delete … Continue reading Android custom ListView tutorial (including source code)

Android: button with rotated (vertical) text

If you want to build button with vertical text like that: You can override standard button and its onDraw() method. There you have to rotate text before drawing it. Same thing can be done with TextView - since button actually is extended TextView. 1. Write your own Button implementation Here is code that actually you can … Continue reading Android: button with rotated (vertical) text

Play sound in Android tutorial

To play sounds in android you can use SoundPool. My solution is based on a SoundUtils class having two methods (in simpliest scenario). Audio files has to be in /res/raw/ initTiltSounds(Context context) loads sounds from resources and sets boolean flag after it has finished loading. If flag is false it means that sounds can't be … Continue reading Play sound in Android tutorial

Fix: SharedPreferences not saved after app restart

It is quite common error that SharedPreference setting is being reset or cleared to default, after Android application is restarted. There are two things you have to remember. Commit changes made by prefs editor (the obvious one) prefsEditor.commit(); Clear prefs editor before using it (the tricky one) prefsEditor.clear(); The clear() method clears your preferences made by … Continue reading Fix: SharedPreferences not saved after app restart

Android: Action listener on EditText change

If business logic requires to trigger any kind of action right after the user changes text in EditText View, the TextWatcher listener can be used. Good example of use is filter, that updates when user provides filtering criteria. Add textChanged listener to EditText: myEditText.addTextChangedListener(onSearchFieldTextChanged); Implement listener to perform desired actions: TextWatcher onSearchFieldTextChanged = new TextWatcher(){ … Continue reading Android: Action listener on EditText change

Android dp and px: what is it about

What is it While programing GUI on Android one should mostly define dimensions in dp (density independent pixels) instead of px (pixels). The main difference between both is: dp will always have the same size on every smartphone screen. px is not always the same dimensions. It is well visualized on screenshots on Android API Guides, in section Density … Continue reading Android dp and px: what is it about