Tag Archives: how-to

Android Rotate and Scale Bitmap Example

I built an Android demo app so I could test my understanding of displaying bitmaps on a canvas. I had done scaling of bitmaps, rotation of bitmaps, and translation from one origin to another, but I had not done more than one of those transformations at a time.
Full source code for the Android example is provided. Continue reading

Posted in Android | Tagged , , , , | 1 Comment

Eclipse Debugging Fix for Nexus 7 and Galaxy Nexus

I found a way to get debugging back for my Galaxy Nexus while running Eclipse on Windows 8. It was very annoying to go without using ADB for my Galaxy Nexus. I had about 3-4 months where Eclipse ADB would not detect my device. I would turn debugging on and off, reset ADB with kill-server, reinstall device drives, but got nowhere. … Fortunately, Google searches related to Nexus 7 and ADB got me to a Stack Overflow page that had the information I needed. What I needed was buried in one of the comments: “how to activate USB debugging for the NEW Nexus 7 on Windows 8″. Continue reading

Posted in Android | Tagged , , , | Leave a comment

Android Fragment for an Item in a Store

I am working on a game that has items that players can buy from a store. I needed a way to display the list of items on the screen. I am using a StoreItemFragment to display them on the screen. In this blog post, I describe a demo app that I built that uses the fragment in a list of items for sale.
Each item for sale has a picture, a description, and a button to push to make the purchase. The image next to the purchase button indicates the currency used for the payment. In this demo, players pay in gold coins or crystals. I plan to use this Fragment for purchases made in the game with virtual currency, and I will use it with a second activity where the player can start an in-app purchase using real money to purchase game coins.

(Note: This is an excerpt of the blog article. Click the link for the full article, which includes screenshots, detailed explanations, and a link to the full source code.) Continue reading

Posted in Android, Game Design | Tagged , , , , , | 2 Comments

Two Progress Bars for Android

I built two different views to show progress bars in Android. One is a horizontal progress bar and the other is a vertical progress bar, made up of a stack of horizontal bars. Here they are displayed in a demo app, running on a Galaxy Nexus phone.

For the horizontal progress, you can control the colors used, the width and height of the bar, and the number of divisions. For the vertical progress bar, I wanted it to look like a stack of bars. When you run the demo app, you can see the values change by touching a progress bar. Complete source code is provided below.
Continue reading

Posted in Android | Tagged , , , , | 2 Comments

Multitouch Panning and Zooming Examples for Android

I have done some work so I better understand multitouch features in Android. I built a simple demo with examples of pinch zooming and panning. Most of the examples involve using drawing operations on the canvas of a view.
About two years ago, I started some work on moving images in Android. I started with the “Making Sense of Multitouch” blog article and ended up doing some simple things with moving images and then drag-drop based on the Android Launcher (see references for links). It’s interesting to me that I have gone back to that same article for a different purpose. I am working on apps where the basic zoom and pan operations are needed. Continue reading

Posted in Android | Tagged , , , , | 19 Comments

Three Variations for Image Square Grids in Android

In a new Android app I am working on, I have a need to display a a square grid of images. I have tried several variations of doing this using a GridView. Each of the solutions involves using aViewTreeObserver, which is something I would not have thought of on my own. Fortunately, I found several notes on StackOverflow that pointed me in the right direction.

I’ll describe three of the variations in this blog post. The end result for each variation is good: square images on a grid. My favorite variation is the one in which the sizes of the images are determined dynamically, based on the size of the screen. It requires the least amount of work and delivers good results.

Complete source code is provided for all three variations.
Continue reading

Posted in Android | Tagged , , , , , , | 1 Comment

Surprise Android Permission Requests

I found an interesting demo app on another blog and thought I would try it out on my phone. I downloaded the code, built the project, and then decided I’d package it as an apk file so I could share it easily in email. I sent it to myself and was ready to install it. I was a bit surprised to see a request for permissions. The app was requesting permission to modify SD card contents and to read phone state and identity.

Generally, it has been my policy not to install any Android app that asks for too much access to my Android device. Upon seeing this, I stopped. There was no reason for any permissions. A fix would certainly be easy, I thought.
It turns out it was, but it took me awhile to figure it out. My new simple rule for packaging apps: always specify the min SDK version in the manifest file.
Continue reading

Posted in Android | Tagged , , , | Leave a comment

What to do when your Android Emulator will not start from Eclipse

I do Android development work using Eclipse. I work on a MacBook. Like many people doing Android development in Eclipse, I often start an application to run in the Emulator and then see nothing happen. Everything starts out fine. You receive the first few reassuring messages in the console window and then nothing.

The figures below show where it gets stuck. You start with something like Figure 1 and you get stuck with something like Figure 2. What I used to do is keep starting new devices until I get one that starts up correctly. Occasionally, I would restart all of Eclipse. Lately, I have found something that gets Eclipse properly connected to the emulator. I start a Terminal app on my Mac and reset the adb server. (I assume that using a command window in Windows 7 will also work.) That gets Eclipse, the Android Device Chooser, and Adb back in sync.
Continue reading

Posted in Android | Tagged , , , | 3 Comments