Showing posts with label software development. Show all posts
Showing posts with label software development. Show all posts

06 October 2011

Google App Engine Blog: Google Cloud SQL: Your database in the cloud

Google App Engine Blog: Google Cloud SQL: Your database in the cloud: Cross-posted from the Google Code Blog One of App Engine’s most requested features has been a simple way to develop traditional database-d...

30 March 2011

[Technote] Eclipse shortcut keys

To accelerate your programming speed on Eclipse, it's essential that you master the shortcut keys in Eclipse. Here I list a few shortcuts I found particularly useful:

Navigation shortcuts

CTRL+L - Jump to a line with line number x.
CTRL+Q - Go to the last edit location.
ALT+Left/Right - Same as CTRL+Q.
F3 - Go to the definition of a variable, method or class.
CTRL+O - Go to the declaration of a variable, method, or class.
CTRL+ALT+H - Show call hierarchy of a method.

File navigation shortcuts

CTRL+E - open a searchable list of all the open editors for you.
CTRL+SHIFT+T - Open a file by summon a file search box.

Editing shortcuts

CTRL+SHIFT+O - Doing all the imports automatically for you!
CTRL+I - Correcting indentation.
CTRL+/ - To comment out a line or lines (by selecting a group lines).
CTRL+D - To delete a line.
CTRL+SPACE (SHIFT+A in my IDE setting) - Autocomplete codes.
CTRL+1 - Suggest quick fixes.
ALT+SHIFT+R - Doing rename and refactoring for you.

Search shortcuts

CTRL+J - Incremental search.
CTRL+F - Single search.

Other shortcuts


CTRL+SHIFT+F - List all the shortcut keys and their mappings for you.

I will add more to this list once I find out other useful shortcuts.

27 March 2011

[Technote] Saving states from Android Activities

When you start to develop applications on Android devices, managing Activity states definitely is the first major thing to master in order to create reliable, robust Android apps. Here I will simply go through what I have found during developing Android apps myself:

First, you have to think carefully what states are necessary to be retained when Android Activity is destroyed. Usually, the less states you save, the better (because that reduces your Activity start-up time as well as destroying time). For instance, you might not need to save the 'look' of View, because it can always be redrawn/recomputed every time when an Activity comes to live; instead, saving some states necessary for Android to recompute that look, i.e., the current position of the cursor on screen.

Second, you can then think about HOW to save states after determining what to save. Generally, there are three ways to do it (not including saving data on Android internal filesystem or SD card):
  • Using Bundle to save primitive typed (check for Bundle API), temporary data.
  • Using SharedPreferences to save primitive typed, persistent data.
  • Using onRetainNonConfigurationInstance to save temporary object instances.
I personally find the last bullet very useful because the data we want to save cannot always be primitive typed! For more details about the differences and usages of the three approaches, check out here.

To retrieve data you saved, onCreate is a good place for your activity to reload states. According to my experience, onCreate is probably and mostly what you really want, not onResume or onStart otherwise.

A side note for the above: the easiest and best way to test if your management of Activity's life cycle is correct, is to change the orientation of the screen. It should not crash and the behavior should be the same as before orientation.

Last, sometimes what we really want is to have some simple communication mechanism between activities (i.e., the calling activity and the callee activity) instead of saving states, how to achieve that? In the caller activity, call the callee with startActivityForResult, and also implement the onActivityResult method. Then, in the callee, remember to call setResult to set the result to be returned, before the activity is finished.

24 February 2011

Git - ignoring files using .gitignore

When you work on a project with Git, sometimes you don't want Git to track certain files, what you can do is edit .gitignore file so that Git knows the files listed in .gitignore should not be tracked. You should use .gitignore to keep annoying irrelevant files out of your development process.

Check out link here for more elaborated explanation: http://bit.ly/geMoTy

18 February 2011

[Technotes] invalidate() method

In android system, the class View (android.view.View) is an important interface for rendering UI objects. Inside it, a method called invalidate() plays a key role.

The function of invalidate is simple, it marks a region on the view to be 'dirty', which tells the android system that region must be redrawn soon in the near future. The region can be the whole View or just a designated region passed to invalidate. And obviously, invalidating only a small portion of the view can have some performance advantages for the UI system. Therefore, make sure you use invalidate() wisely!

Also, an important point: never call any drawing functions except in the onDraw( ) method (a method of class View). Instead, you use the invalidate( ) method to mark rectangles as dirty. The window manager will combine all the dirty rectangles at some point in the future and call onDraw( ) again for you. The dirty rectangles become the clip region, so screen updates are optimized to only those areas that change.

14 February 2011

06 February 2011

[Tech notes] How to delete objects in Java?

There is no delete or free keyword in Java. The only thing that can collect the unreferenced memory chunk is garbage collector (GC). To take advantage of that, the best practice is to 'null' out your object reference whenever you want the GC to free that object:


MyObject a = new MyObject();

... /* Do something with object a */

a = null; /* Tell GC to free the memory referenced by a! */

05 February 2011

What is focus in computing?

'In computing, the focus indicates the component of the graphical user interface which is currently selected to receive input. Moving the focus away from a specific user interface element is known as a blur event in relation to this element.'

By convention, the tab key is used to move the focus to the next focusable component and shift + tab to the previous one.

There are several window management policies for focus:

Click to focus

On most mainstream user-interfaces, such as ones made by Microsoft and Apple, where one must click the mouse inside of the window for that window to gain focus.

Focus follows pointer

Another common policy on UNIX systems using X11 is the "focus follows mouse" policy (or FFM), where the focus automatically follows the current placement of the pointer.

[Tech notes] Android UI basics overview

Some overviews of Android UI programming:
Key classes of UI system: 

04 February 2011

[Tech notes] Android UI basics

In an Android application, the user interface is built using View and ViewGroup objects. There are many types of views and view groups, each of which is a descendant of the View class.

View objects are the basic units of user interface expression on the Android platform. The View class serves as the base for subclasses called "widgets," which offer fully implemented UI objects, like text fields and buttons.

The ViewGroup class serves as the base for subclasses called "layouts," which offer different kinds of layout architecture, like linear, tabular and relative.

On the Android platform, you define an Activity's UI using a hierarchy of View and ViewGroup nodes (as shown here). In order to attach the view hierarchy tree to the screen for rendering, your Activity must call the setContentView() method and pass a reference to the root node object. The Android system receives this reference and uses it to invalidate, measure, and draw the tree. The root node of the hierarchy requests that its child nodes draw themselves — in turn, each view group node is responsible for calling upon each of its own child views to draw themselves.

Android parses the elements of your layout in-order (from the top of the hierarchy tree), instantiating the Views and adding them to their parent(s). Because these are drawn in-order, if there are elements that overlap positions, the last one to be drawn will lie on top of others previously drawn to that space.

01 February 2011

[Tech notes] Android API levels

The following table specifies the API Level supported by each version of the Android platform:

Platform VersionAPI Level
Android 2.39
Android 2.28
Android 2.17
Android 2.0.16
Android 2.05
Android 1.64
Android 1.53
Android 1.12
Android 1.01

The API Level identifier serves a key role in ensuring the best possible experience for users and application developers:
  • It lets the Android platform describe the maximum framework API revision that it supports
  • It lets applications describe the framework API revision that they require
  • It lets the system negotiate the installation of applications on the user's device, such that version-incompatible applications are not installed.

Applications can use a manifest element provided by the framework API — uses-sdk — to describe the minimum and maximum API Levels under which they are able to run, as well as the preferred API Level that they are designed to support.

Development Considerations

Application forward compatibility

Android applications are generally forward-compatible with new versions of the Android platform.

Because almost all changes to the framework API are additive, an Android application developed using any given version of the API (as specified by its API Level) is forward-compatible with later versions of the Android platform and higher API levels.

Application backward compatibility

Android applications are not necessarily backward compatible with versions of the Android platform older than the version against which they were compiled.

Reference

26 January 2011

[Tech notes] Android executable file - .apk

"Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — is bundled by the aapt tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application."

The above is just an except from the Android dev guide.

Android aapt tool

aapt stands for Android Asset Packaging Tool and is included in tools/ directory of the SDK. This tool allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.

Most important of all, build scripts and IDE plugins can utilize this tool to package the apk file that constitutes an Android application.

To use aapt directly, open a terminal, go to the tools/ directory, and run the command (for linux and Mac OS X):

$ ./aapt

22 January 2011

[solved] Unparsed aapt error(s)! Check the console for output

Today I wrote some codes for my Android application as usual, and I found a parsing error that says:

"Unparsed aapt error(s)! Check the console for output"

However, I didn't see any errors after checking all the files. So what is going on here? It happens when some *.out.xml files are generated before the entire project gets built for execution. How can this happen? It happens when you run the application when in a resource file.

The solution to this issue is simple: make sure you clean any post-built files before building your application for a run. To achieve this, go to Project --- Clean in the Eclipse menu and it will work again. Or, you can just delete R.java file. It will get created again and the problem is solved.

21 January 2011

[Tech Notes] Android basics II - Android SDK building blocks

A few objects are defined in the Android SDK that every developer needs to be familiar with. There are the building blocks of your android applications.

The most important ones are: Activities, Intents, Services, and Content Providers.

Activities - represents a user interface screen. Applications can define one or more activities to handle different phases of the program.

Intents - a mechanism for describing a specific action, such as "pick a photo". Everything has to go through Intents before creating activities or actions.

Services - a service is a task that runs in the background without the user's direct interaction, similar to a Unix daemon.

Content Providers - a set of data wrapped up in a common API to read and write it. This is the best way to share global data between applications.

[Tech Notes] Android Basics I - Android System Architecture

Android system architecture:

Get get the big picture of system architecture, please check out this documentation online. To sum up, there are four primary layers for the software system - Linux Kernel, Libraries and Android Runtime, Application Framework, Applications and Widgets.

This concept is essential because you need to know what layer (s) you will be dealing with when developing apps, making your own frameworks and libraries or even modifying Linux Kernel. For application development, you will not see Linux Kernel, all you can see is Application Framework and Application layers.

Android System Architecture