Aug 9, 2011

Android Selectors




GUI is always an important part of any application, because ordinary users dont know and don't care what's behind the scene; they want something easy to work with and nowadays attractive GUI is a must for most applications. although making an appealing and innovative interface needs something more than just programming skills and knowledge, every programmer should know how to customize different GUI components within whatever framework and environment they are working.
Today I'm gonna talk about one of the beautiful features of Android which gives you the ability to change the default behavior of GUI components.
when designing GUIs, most of the times you want to change the appearance of buttons, input Fields, menus and.... Android Selectors have been provided to solve all these kind of problems, they enable us to decide what to show and how to show based on different states of each components...for example you can tell a button to have black background color with red text color when it is in pressed state or whatever else.
In this post i will show you an example of customizing a ListView

which is gonna look like this :






It is nothing but a simple ListView... believe me, and here is the XML which is being used to create it











the code which I've used to populate the list :





ListView view = (ListView)findViewById(R.id.list);
view.setAdapter(new ArrayAdapter(this, R.layout.menu_item, ITEMS));
view.setOnItemClickListener(this);




and finally, here is the content of menu_item.xml file :


see? it's a simple, ordinary list, there is no secret here but a simple trick; I've used selectors for both background and text color for our TextView, what do you think "selector" and "color_selector" are?
they actually refer to selector.xml and color_selector.xml files inside drawable directory, you can see the content of them below :

what does the content of color_selector file mean? it says that the text color will be black in "selected" state, red in "pressed" state and white otherwise, and i reckon now you should be able to figure out what the content of selector file means.
here is the content of selector_s and selector_d :


as you might have noticed,I've also used "listSelector" attribute of our ListView to customize the behavior of the list when user is going through options in the list.
list_selector.xml file looks like this :













and here are all the drawable objects i used in this application if you wanna give it a try and see how easy it works ;)






















Source Click Here :

Android Selectors




GUI is always an important part of any application, because ordinary users dont know and don't care what's behind the scene; they want something easy to work with and nowadays attractive GUI is a must for most applications. although making an appealing and innovative interface needs something more than just programming skills and knowledge, every programmer should know how to customize different GUI components within whatever framework and environment they are working.
Today I'm gonna talk about one of the beautiful features of Android which gives you the ability to change the default behavior of GUI components.
when designing GUIs, most of the times you want to change the appearance of buttons, input Fields, menus and.... Android Selectors have been provided to solve all these kind of problems, they enable us to decide what to show and how to show based on different states of each components...for example you can tell a button to have black background color with red text color when it is in pressed state or whatever else.
In this post i will show you an example of customizing a ListView

which is gonna look like this :






It is nothing but a simple ListView... believe me, and here is the XML which is being used to create it









the code which I've used to populate the list :





ListView view = (ListView)findViewById(R.id.list);
view.setAdapter(new ArrayAdapter(this, R.layout.menu_item, ITEMS));
view.setOnItemClickListener(this);




and finally, here is the content of menu_item.xml file :




:


:






see? it's a simple, ordinary list, there is no secret here but a simple trick; I've used selectors for both background and text color for our TextView, what do you think "selector" and "color_selector" are?
they actually refer to selector.xml and color_selector.xml files inside drawable directory, you can see the content of them below :






:
:
:
:
:










:
:
:
:
:





what does the content of color_selector file mean? it says that the text color will be black in "selected" state, red in "pressed" state and white otherwise, and i reckon now you should be able to figure out what the content of selector file means.
here is the content of selector_s and selector_d :















as you might have noticed,I've also used "listSelector" attribute of our ListView to customize the behavior of the list when user is going through options in the list.
list_selector.xml file looks like this :













and here are all the drawable objects i used in this application if you wanna give it a try and see how easy it works ;)






















Source Click Here :

Aug 2, 2011

How to Know System Density And Screen Resoulation


how to Know System Density :
-----------------------

or low scale:0.75

for medium scale:1.0

for large scale:1.5

float scale; DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

scale =getApplicationContext().getResources().getDisplayMetrics().density;


how to screen resoulation :
==========================

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);

final int height = dm.heightPixels;
final int width = dm.widthPixels;



web site to know screen resoluation:
===========
http://www.whatismyscreenresolution.com/

Aug 1, 2011

Top Interview Tips

Ready aim hired

Perceptions about interviews usually depend on the interviewer's likeability and first impressions.

Right after a job interview, you could either be supremely confident or faintly worried. Either way, we feel pretty relieved when it is all over. Perceptions about interviews usually depend on the interviewer's likeability and first impressions. It is, therefore, important to remember some statutory courtesies in order to have a positive interaction and favourable result.

After an interview shoot a thank you email or letter
Many interviewees think that once the face-to-face interview is over, the interview process is complete. However, this is not the case. The job interview is just the beginning. Once the personal interview is done, the company mulls, evaluates and decides the best candidate who would best suit the job profile and company.

Therefore, it is a good idea to remain in touch with the interviewer and the company in general. One of the best ways to do so is to drop them a ?Thank You? note. If you have been in touch with company or interviewer via e-mail, then one should email such a note within 24 hours after the interview. Interviewers have short memories. So, this is your final chance to stand apart from all of the others who want the same position.

Follow up after the interview when there is no response
How long should you wait before you call the company or interviewer? Usually, if there is no response within sometime, you will start worrying about whether it is appropriate to call back and check hiring status.

When to call
Post-interview it is best to give a gap of two to three days before you make the first follow up call. One of the most important things to keep in mind during the call is that one should be succinct and brief. Another important aspect is to chalk out a time when to call. The best time to call the interviewer is after lunch or an hour before closing time. This will ensure that you have a comfortable time frame to speak to the interviewer.

Whom to call
Interviewees are sometimes confused about who to follow up with after the interview?the human resource team or the interviewer directly. This situation is more confusing if there was more than one interviewer. In such circumstances, it is best to first check with the human resource team on the hiring status.

What to say
Begin the conversation by thanking the person for the opportunity to interview with the company. Recap some of the conversational highlights and clarify any information you need to check on. Use the last paragraph as the chance to state, ?The job is a good fit for me because of XYZ, and my past experience in XYZ.?

Continue your job search
While waiting to hear from the company after the job interview, you should not ignore other interview calls because you are waiting to hear back from the current interview. Even if you are convinced that you have got the job, there can be many slips between the cup and the lip. It is also a good idea to critique your previous performance and use the experience to polish your interviewing skills.

Android Interview Questions And Answers


What is android?

Android is a stack of software for mobile devices which has Operating System, middleware and some key applications. The application executes within its own process and its own instance of Dalvik Virtual Machine. Many Virtual Machines run efficiently by a DVM device. DVM executes Java languages byte code which later transforms into .dex format files.


What is activity?
A single screen in
an application, with supporting Java code.

What is intent in Android?
A class (Intent) will describes what a caller desires to do. The caller will send this intent to Android's intent resolver, which finds the most suitable activity for the intent. E.g. opening
a PDF document is an intent, and the Adobe Reader apps will be the perfect activity for that intent(class).

What is a Sticky Intent?
sendStickyBroadcast() performs a sendBroadcast (Intent) known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver (BroadcastReceiver, IntentFilter). In all other ways, this behaves the same as sendBroadcast(Intent).

One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.

Is there anyway to determine if an Intent passed into a BroadcastReceiver's onReceive is the result of a sticky Boradcast Intent, or if it was just sent?

Example for sticky broadcast
When you call registerReceiver() for that action -- even with a null BroadcastReceiver -- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.

How the nine-patch Image different from a regular bitmap? or Different between nine-patch Image vs regular Bitmap Image
It is one of a resizable bitmap resource which is being used as backgrounds or other images on the device. The NinePatch class allows drawing a bitmap in nine sections. The four corners are unscaled; the middle of the image is scaled in both axes, the four edges are scaled into one axis.

What Programming languages does Android support for application development?
Android applications supports using Java Programming Language. which is coded in Java and complied using Android SDK.

What is a resource?
A user defined JSON, XML, bitmap, or other file, injected into the application build process, which can later be loaded from code.

How will you record a phone call in Android? or How to handle on Audio Stream for a call in Android?
Permissions.PROCESS_OUTGOING_CALLS: Will Allows an application to monitor, modify, or abort outgoing calls. So through that we can monitor thePhone calls.

What's the difference between class, file and activity in android?
Class - The Class file is complied from .java file. Android will use this .class file to produce the executable apk.
File - It is a block of resources, srbitrary information. It can be any file type.
Activity - An activity is the equivalent of a Frame/Window in GUI toolkits. It is not a file or a file type it is just a class that can be extended in Android for loading UI elements on view.

Does Android support the Bluetooth serial port profile?
A. Yes.


Can an application be started on powerup?
A. Yes.

What is APK format.
The APK file is compressed AndroidManifest.xml file with extension .apk, Which have application code (.dex files), resource files, and other files which is compressed into single .apk file.

How to Translate in android
The Google translator translates the data of one language into another language by using XMPP to transmit data. You can type the message in English and select the language which is understood by the citizens of the country in order to reach the message to the citizens.

What is an action?
A description of something that an Intent sender desires.

What are the advantages of Android?
The following are the advantages of Android:

* The customer will be benefited from wide range of mobile applications to choose, since the monopoly of wireless carriers like Orange and AT&T will be broken by Google Android.
* Features like weather details, live RSS feeds, opening screen, icon on the opening screen can be customized
* Innovative products like the location-aware services, location of a nearbyconvenience store etc., are some of the additive facilities in Android.

What is the TTL (Time to Live)? Why is it required?

TTL is a value in data packet of Internet Protocol. It communicates to the network router whether or not the packet should be in the network for too long or discarded. Usually, data packets might not be transmitted to their intended destination within a stipulated period of time. The TTL value is set by a system default value which is an 8-bit binary digit field in the header of the packet. The purpose of TTL is, it would specify certain time limit in seconds, for transmitting the packet header. When the time is exhausted, the packet would be discarded. Each router receives the subtracts count, when the packet is discarded, and when it becomes zero, the router detects the discarded packets and sends a message, Internet Control Message Protocol message back to the originating host.



How is nine-patch image different from a regular bitmap?

It is a resizable bitmap resource that can be used for backgrounds or other images on the device. The NinePatch class permits drawing a bitmap in nine sections. The four corners are unscaled; the four edges are scaled in one axis, and the middle is scaled in both axes.



Explain IP datagram, Fragmentation and MTU ?

IP datagram can be used to describe a portion of IP data. Each IP datagram has set of fields arranged in an order. The order is specific which helps to decode and read the stream easily. IP datagram has fields like Version, header length, Type of service, Total length, checksum, flag, protocol, Time to live, Identification, source and destination ip address, padding, options and payload.

MTU:- Maximum Transmission Unit is the size of the largest packet that a communication protocol can pass. The size can be fixed by some standard or decided at the time of connection

Fragmentation is a process of breaking the IP packets into smaller pieces. Fragmentation is needed when the datagram is larger than the MTU. Each fragment becomes a datagram in itself and transmitted independently from source. When received by destination they are reassembled.



Explain about the exceptions of Android?

The following are the exceptions that are supported by Android
* InflateException : When an error conditions are occurred, this exception is thrown
* Surface.OutOfResourceException: When a surface is not created or resized, this exception is thrown
* SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS
* WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.



Describe Android Application Architecture?

Android Application Architecture has the following components:

* Services ? like Network Operation

* Intent - To perform inter-communication between activities or services

* Resource Externalization - such as strings and graphics

* Notification signaling users - light, sound, icon, notification, dialog etc.

  • Content Providers - They share data between applications

What are the advantages of Android?

The following are the advantages of Android:

* The customer will be benefited from wide range of mobile applications to choose, since the monopoly of wireless carriers like AT&T and Orange will be broken by Google Android.

* Features like weather details, live RSS feeds, opening screen, icon on the opening screen can be customized

  • Innovative products like the location-aware services, location of a nearbyconvenience store etc., are some of the additive facilities in Android.

How to select more than one option from list in android xml file? Give an example.

Specify android id, layout height and width as depicted in the following example.



Explain about the exceptions of Android?

The following are the exceptions that are supported by Android

* InflateException : When an error conditions are occurred, this exception is thrown

* Surface.OutOfResourceException: When a surface is not created or resized, this exception is thrown

* SurfaceHolder.BadSurfaceTypeException: This exception is thrown from the lockCanvas() method, when invoked on a Surface whose is SURFACE_TYPE_PUSH_BUFFERS

  • WindowManager.BadTokenException: This exception is thrown at the time of trying to add view an invalid WindowManager.LayoutParamstoken.

What are the features of Android?

*Components can be reused and replaced by the application framework.

*Optimized DVM for mobile devices

*SQLite enables to store the data in a structured manner.

*Supports GSM telephone and Bluetooth, WiFi, 3G and EDGE technologies

*The development is a combination of a device emulator, debugging tools, memory profiling and plug-in for Eclipse IDE.



What are the differences between a domain and a workgroup?

In a domain, one or more computer can be a server to manage the network. On the other hand in a workgroup all computers are peers having no control on each other. In a domain, user doesn?t need an account to logon on a specific computer if an account is available on the domain. In a work group user needs to have an account for every computer.

In a domain, Computers can be on different local networks. In a work group all computers needs to be a part of the same local network.





What is needed to make a multiple choice list with a custom view for each row?

Multiple choice list can be viewed by making the CheckBox android:id value be “@android:id /text1". That is the ID used by Android for the CheckedTextView in simple_list_item_multiple_choice.



What are the dialog boxes that are supported in android? Explain.

Android supports 4 dialog boxes:

AlertDialog : An alert dialog box supports 0 to 3 buttons and a list of selectable elements, including check boxes and radio buttons. Among the other dialog boxes, the most suggested dialog box is the alert dialog box.

ProgressDialog: This dialog box displays a progress wheel or a progress bar. It is an extension of AlertDialog and supports adding buttons.

DatePickerDialog: This dialog box is used for selecting a date by the user.

TimePickerDialog: This dialog box is used for selecting time by the user.



How to Remove Desktop icons and Widgets?

Press and Hold the icon or widget. The phone will vibrate and on the bottom of the phone you will see an option to remove. While still holding the icon or widget drag it to the remove button. Once remove turns red drop the item and it is gone



Common Tricky questions

  • Remember that the GUI layer doesn't request data directly from the web; data is always loaded from a local database.

  • The service layer periodically updates the local database.

  • What is the risk in blocking the Main thread when performing a lengthy operation such as web access or heavy computation? Application_Not_Responding exception will be thrown which will crash and restart the application.

  • Why is List View not recommended to have active components? Clicking on the active text box will pop up the software keyboard but this will resize the list, removing focus from the clicked element.



For senior employees

Beyond a certain level of experience, the job interview questions cease to be "difference between abstract class and interface", and focus more on testing your technical acumen, collaboration and communication skills. A list of such questions, typically asked during interviews for senior positions is given below:

  • Explain the life cycle of an application development process you worked on previously.
    What the interviewer looks for is communication of requirements, planning, modeling, construction and deployment on the back end.

  • Here's a hypothetical project. Explain how you would go about it.
    They want to know how you would break your work down into tasks and how many weeks for each task. I'm really looking to find out about planning methods, their skill set and how quickly they can execute.

  • How do you respond to requirement changes in the middle of a cycle?

  • What type of methodology have you used in the past? What are its drawbacks?

  • What are different techniques for prototyping an application?
    Similar question: Do you feel there is value in wireframing an application? Why?

  • How do you manage conflicts in Web applications when there are different people managing data?

  • Tell me something you learned from a team member in the last year.

  • What software testing procedures have you used to perform a QA?

Once the coding skills verified. Sample I

· The Activity life cycle is must. Ask about the different phases of Activity Life cycle. For example: when and how the activity comes to foreground?

· Check the knowledge on AndroidManifest file, For example: Why do we need this file, What is the role of this file in Android app development.

· Different Kinds of Intents

· Ask about different Kinds of context

· Ask about different Storage Methods in android

· Kinds of Log debugger and Debugger Configuration

· How to debug the application on real device.

· How do you ensure that the app design will be consistent across the different screen resolutions

· Thread concepts also plus points as we deal with the treads more.

· Can you able to build custom views and how?

· How to create flexible layouts, For example to place English, Chinese fonts.

· What is localization and how to achieve?

· What are 9-patch images

· How to avoid ANR status

· How to do Memory management

· Ask about IPC

· What is onCreate(Bundle savedInstanceState), Have you used savedInstanceState when and why?

· To check how updated the person is just ask about what are Fragments in an Activity



If this is an Android specific job, just ask the obvious stuff. Sample II

  • Application lifecycle

  • When to use a service

  • How to use a broadcast receiver and register it both in the manifest and in code

  • Intent filters

  • Stuff about what manifest attributes and tags mean

  • The types of flags to run an application

    • FLAG_ACTIVITY_NEW_TASK

    • FLAG_ACTIVITY_CLEAR_TOP

    • etc

  • How to do data intensive calculations using threads

  • Passing large objects (that can't be passed via intents and shouldn't be serialized) via a service

  • Binding to a service and the service lifecycle

  • How to persist data (both savedInstanceState and more permanent ways)

Just go through http://developer.android.com/guide/topics/fundamentals.html and see what sounds like it's important. Hopefully you're an android developer and know what all those things are, otherwise you're just waiting your interviewee's time =P

But like @Mayra said. A lot of android can be picked up fairly quickly if they're experienced programmers. If you just ask android specific questions, you'll get people who started off with android and that could be bad.


.apk extension
The extension for an Android package file, which typically contains all of the files related to a single Android application. The file itself is a compressed collection of an AndroidManifest.xml file, application code (.dex files), resource files, and other files. A project is compiled into a single .apk file.
.dex extension
Android programs are compiled into .dex (Dalvik Executable) files, which are in turn zipped into a single .apk file on the device. .dex files can be created by automatically translating compiled applications written in the Java programming language.
Action
A description of something that an Intent sender wants done. An action is a string value assigned to an Intent. Action strings can be defined by Android or by a third-party developer. For example, android.intent.action.VIEW for a Web URL, or com.example.rumbler.SHAKE_PHONE for a custom application to vibrate the phone.

adb
Android Debug Bridge, a command-line debugging application shipped with the SDK. It provides tools to browse the device, copy tools on the device, and forward ports for debugging. See Using adb for more information.

Application
A collection of one or more activities, services, listeners, and intent receivers. An application has a single manifest, and is compiled into a single .apk file on the device.

Content Provider
A class built on ContentProvider that handles content query strings of a specific format to return data in a specific format. See Reading and writing data to a content provider for information on using content providers.
Content URI
A type of URI. See the URI entry.
Dalvik
The name of Android’s virtual machine. The Dalvik VM is an interpreter-only virtual machine that executes files in the Dalvik Executable (.dex) format, a format that is optimized for efficient storage and memory-mappable execution. The virtual machine is register-based, and it can run classes compiled by a Java language compiler that have been transformed into its native format using the included “dx” tool. The VM runs on top of Posix-compliant operating systems, which it relies on for underlying functionality (such as threading and low level memory management). The Dalvik core class library is intended to provide a familiar development base for those used to programming with Java Standard Edition, but it is geared specifically to the needs of a small mobile device.
DDMS
Dalvik Debug Monitor Service, a GUI debugging application shipped with the SDK. It provides screen capture, log dump, and process examination capabilities. See Using the Dalvik Debug Monitor Server to learn more about this program.
Drawable
A compiled visual resource that can be used as a background, title, or other part of the screen. It is compiled into an android.graphics.drawable subclass.
Intent
A class (Intent) that contains several fields describing what a caller would like to do. The caller sends this intent to Android’s intent resolver, which looks through the intent filters of all applications to find the activity most suited to handle this intent. Intent fields include the desired action, a category, a data string, the MIME type of the data, a handling class, and other restrictions.
Intent Filter
Activities and intent receivers include one or more filters in their manifest to describe what kinds of intents or messages they can handle or want to receive. An intent filter lists a set of requirements, such as data type, action requested, and URI format, that the Intent or message must fulfill. For Activities, Android searches for the Activity with the most closely matching valid match between the Intent and the activity filter. For messages, Android will forward a message to all receivers with matching intent filters.
Intent Receiver
An application class that listens for messages broadcast by callingContext.broadcastIntent(). For example code, see Listening for and broadcasting global messages.

Layout resource
An XML file that describes the layout of an Activity screen.
Manifest
An XML file associated with each Application that describes the various activies, intent filters, services, and other items that it exposes. See AndroidManifest.xml File Details.

Nine-patch / 9-patch / Ninepatch image
A resizeable bitmap resource that can be used for backgrounds or other images on the device. See Nine-Patch Stretchable Image for more information.
Query String
A type of URI. See the URI entry.
Resource
A user-supplied XML, bitmap, or other file, entered into an application build process, which can later be loaded from code. Android can accept resources of many types; see Resources for a full description. Application-defined resources should be stored in theres/ subfolders.
Service
A class that runs in the background to perform various persistent actions, such as playing music or monitoring network activity.
Theme
A set of properties (text size, background color, and so on) bundled together to define various default display settings. Android provides a few standard themes, listed in R.style (starting with “Theme_”).
URIs
Android uses URI strings both for requesting data (e.g., a list of contacts) and for requesting actions (e.g., opening a Web page in a browser). Both are valid URI strings, but have different values. All requests for data must start with the string “content://”. Action strings are valid URIs that can be handled appropriately by applications on the device; for example, a URI starting with “http://” will be handled by the browser

Q: Can I write code for Android using C/C++?
A:

Android applications are written using the Java programming language.

Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.

Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included “dx” tool.

Android only supports applications written using the Java programming language at this time.


Logic : Getting Random Numbers and Random Questions using Array List Class


getting Random Numbers :
=======================
public ArrayList getRandomList() {
Random rand = new Random();
ArrayList alist = new ArrayList();
while (alist.size() < 5) {
int v = rand.nextInt(5);
if (!alist.contains(v)) {
alist.add(v);
}
}
return alist;
}








Getting Random Questions from ArrayList :
-----------------------------------




public ArrayList getQuestions(int level, ArrayList listObj){
ArrayList listObj2=new ArrayList();
Random r=new Random();
while(listObj2.size()<=20)
{
int r1=r.nextInt(listObj.size());
ModuleQuesBean mq=listObj.get(r1);
int lid=Integer.parseInt(mq.getLid());
if(lid==level)
{
if(!listObj2.contains(mq));
{
listObj2.add(mq);
}
}
}
for(int i=0;i<10;i++)
{
Log.w(" array list values ",listObj2.get(i).getQuestionid()+"");
}
return listObj2;
}