Posts

Gradient in XML– easy as pi

  Tired of using solid background colors but you think it’s a bit trouble to use you favorite graphics tool too create interesting backgrounds for you controls or layouts? well, creating gradients in your android app is easy enough, here’s an example: In your drawable folder , create an xml file. the next code creates a gradient which is from top to bottom, with start color of white and end color of somewhat orange, it begins to get a strong fade after 90% of the measure of the container view. <? xml version ="1.0" encoding ="utf-8" ? > < selector xmlns:android ="http://schemas.android.com/apk/res/android" > < item > < shape > < gradient android:angle ="90" android:startColor ="#fff" android:endColor ="#FFA812" android:type ="linear" android:centerY ="0.9" /> </ shape > </ item ...

Boil an egg app - step by step (step 1 - planning)

Image
     In this tutorial , I will demonstrate how I built the app, from the design, to the logic and the code itself.    This app was written for educational purposes and is free do download on the market at :  Boil An Egg   - for devices with API 1.6 and above.   So what's the deal with this app?   it's main goal is to provide users with an easy and useful tool to boil an egg, sounds funny and a bit redundant, but for me it's actually a real need, for I'm known to make boiled eggs which are too soft, or on the other hand -too hard. so I thought to myself that there's must be an app on the play store which will enable me to time the eggs so they'll be perfect each time.   After searching the market and installing couple of apps I found that they are too complicated for my needs so I decided to write an app for my own.   1. name for the app: simple is good – “Boil An Egg”      package name: becau...

How to upload an app to the Google Play store?

     You wrote an amazing app, it works on various resolutions and many tested and trusted devices, so the next step is to upload it to the Google Play store ! but wait, what's the best way to do it? This link explains all the important things you should do in order to prepare your app for publishing we'll cover the more important stuff. follow these next steps and you'll be on the market in no time: 1. Go over the code and remove all unnecessary code (Logs..unused code, unused     resources..etc..) 2. Choose a good package name - this will be your identifier for the store (on upgrade/update     we must use the same package name) 3. remove the android:debuggable attribute from your manifest file if exists 4. Don't forget an icon for the app 5. If you're supporting different resolutions - include matching graphics resources for them 6. We'll be using Eclipse's export wizard in order to get our app to "release" mode  ...

A simple Countdown Timer in Android

Of course we can implement a simple timer using threads but there's a better way out of the box.      The Android SDK offers us a rather simple way to use timers in our apps, Let's see how it works: CountDownTimer timer = new CountDownTimer(maxmillis, 1000) { @Override public void onTick(long lastknowtimer) { int seconds = (int) (lastknowtimer / 1000) % 60 ; int minutes = (int) ((lastknowtimer / (1000*60)) % 60);   tvTimerLabel.setVisibility(View.VISIBLE); tvTimer.setText(String.valueOf(minuts*seconds));     } @Override public void onFinish() { tvTimer.setText("finished"); } }; The  abstract class -  CountdownTimer's constructor receives two parameters (maxmillis which is the amount of milliseconds to countdown from, and the second parameter is the interval in which the tick happens). It has two methods which must be implemented:   1. onTick()   - the ac...

How to set the drawableRight resource by code?

Image
     Sometimes we want to include a small icon inside a Button, how to achieve this? Prepare your PNG file and put it your res/drawable folder along with the other image resources in your application. just like any other view handling - this can be done by Code or by XML. By XML                    <Button                        android:id="@+id/buttonId"                        android:layout_width="wrap_content"                        android:layout_height="wrap_content"                        android:layout_gravity="center"                        android:drawableRight="@drawable/timer_red"       ...

How to play a simple audio file in android

     In our application, it's sometimes necessary to play an audio file. The android sdk offers us a simple way to do it. let's examine the small snippet of code which does it: MediaPlayer mPlayer = MediaPlayer.create(getApplicationContext(), R.raw.audiofile); try { mPlayer.prepare();      } catch (IllegalStateException e) { e.printStackTrace();      } catch (IOException e) {         e.printStackTrace();      } mPlayer.start(); explanation: MediaPlayer -  MediaPlayer class can be used to control playback of audio/video files and   streams.  we need to pass : context and an id of the audio file, we will save the  f ile under the "raw" folder under the familiar "res" folder. after which we must call mPlayer.prepare() -  Prepares the player for playback, synchronously.  After setting the datasource and the display surface, you need to either call prepare...

Android Face Detection API

A cool feature I came across couple of days ago is the "face recognition" API available from SDK 4.0 (API level 14). Basically, it allows us to do is to detect faces from a bitmap , but also detect specific facial featues, such as eyes and mouth. How : The Camera class allows you programmers to set a face detection listener with a callback method which is called when a face is detected. this method is passed with an Array which contains data for each face it detects. Each face object in the array holds: 1. A unique ID which it is tracking so you'll be able to distinguish between the faces detected in the picture. 2. Data with the location of the user's eyes and mouth 3. Data with the boundary of the entire face A tutorial will be published soon enough