Thursday, November 24, 2011

Android Quick Action Bar

Android  Quick Action Bar

Quick Actions are basically actions/functions in a popup bar that are triggered by specific visual elements/buttons/items on the screen. Quick Actions are used to display contextual actions typically used in list views but not limited to it. You can imagine a phone-book or contact list on the phone. Now, there are certain set of actions that will be common to all contacts in the views like; make a call, send message, edit contact or may be even transfer files by  Email, Bluetooth etc. Basically these functions that are common to items in a context can be put in the Quick Action bar. This way the screen is uncluttered and simple and more importantly we needn’t sacrifice on the actions needed.


DOWNLOAD SOURCE CODE

Screen Shot :



Create Actionable Items:
The below code snippet is used to create an actionable item i.e. the actions you would want to place in the quick action bar. Creating an actionable item involves specifying the title, setting an icon that represents the item which will help you relate to the action, and finally set a Listener for the action. The term itself is self-explanatory. Yes, it is used to determine the action to be performed when clicked or pressed. As far as the icon /image goes, it can be easily set by referring to it from the resources as is the case with any external resource set in android which you would aware of, I am most certain.

final QuickActionIcons edit = new QuickActionIcons();;
 edit.setTitle("Edit");
 edit.setIcon(getResources().getDrawable(R.drawable.edit));
 edit.setOnClickListener(new OnClickListener()
 {
 public void onClick(View v)
 {
// add u r action
 }

 });]

Create Quick Action Dialog:

This part is even simpler. Like in this example, when an item in the list view is clicked / pressed, a new quick action bar/dialog is created. Then all the actionable items that you have created in the previous step are appended one by one to the quick action bar. After this you simply have to specify the animation style i.e. how do you want the dialog to be displayed on screen.

resultPane.setOnItemClickListener(new OnItemClickListener()
    {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
      QuickActionBar qab = new QuickActionBar(view);

      qab.addItem(edit);
      qab.addItem(call);
      qab.addItem(send_data);
      qab.setAnimationStyle(QuickActionBar.GROW_FROM_LEFT);

      qab.show();
    }
    });








Tuesday, November 22, 2011

Adobe Flex alert dialog example in android

Adobe Flex alert dialog example in android


ex code :

 <fx:Declarations>
        <fx:Component className="AlertMsg">
            <s:SkinnablePopUpContainer  x="200" y="300">
                <s:TitleWindow   title="Vijaykumar" click="close()" >
                    <s:VGroup horizontalAlign="center"
                              paddingTop="12"
                              paddingBottom="12"
                              paddingLeft="12"
                              paddingRight="12"
                              gap="8"
                              width="100%">
                        <s:Label
                                 paddingBottom="20" 
                                 fontWeight="bold"
                                 color="#000000"
                                 text="Please enter username and password!"/>
                        <s:Button width="50%" height="100%" label="OK" click="close()"/>
                    </s:VGroup>
                </s:TitleWindow>
            </s:SkinnablePopUpContainer>
        </fx:Component>
 </fx:Declarations>


Tuesday, November 15, 2011

Android Turn screen on, When receving notification.

 Android Turn screen on, When receving  notification.

WindowManager.LayoutParams winParams =  getWindow().getAttributes();
    winParams.flags |= (WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    getWindow().setAttributes(winParams);

Sorting an Array and ArrayList in Android

 Sorting an ArrayList  in Android 
in this method for sorting names or contact list in alphabetical order

ArrayList<User> res = new ArrayList<User>();
res.add(…);
res.add(…);
Comparator<User> comperator = new Comparator<User>() {
@Override
public int compare(User object1, User object2) {
return object1.name.compareToIgnoreCase(object2.name);
}
};
Collections.sort(res, comperator);


Sorting an Array in Android


User[] res = new User[];
res.add(…);
res.add(…);
Comparator<User> comperator = new Comparator<User>() {
@Override
public int compare(User object1, User object2) {
return object1.name.compareToIgnoreCase(object2.name);
}
};
Array.sort(res, comperator);

Monday, November 14, 2011

How to check screen off mode in android ?

 How to check screen off mode in android ?

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
         boolean isScreenOn = pm.isScreenOn();

Friday, November 11, 2011

Android Cloud to Device Messaging(C2DM) Tutorial

                               Android Cloud to Device Messaging(C2DM) Tutorial  

This tutorial is for getting started with Android Cloud to Device Messaging (C2DM) on Android. In the iOS world it is knows as “push notifications”.

This feature will definitely help developers and their apps to streamline and optimize the data transfers. This would mean that apps now do not have to poll their servers at regular intervals to check for updates. The servers will be able to send updates (like Push Notifications) to the devices and makes it easier for mobile applications to sync data with servers.


There are many different ways of accomplishing the same thing(polling,constant server connections,SMS messages).

C2DM Alternatives:

Polling: The application itself would periodically poll your servers to check for new messages. You would need to implement everything from queuing messages to writing the polling code. Alerts are no good if they’re delayed due to a low polling period but the more frequently you poll, the more the battery is going to die.

SMS: Android can intercept SMS messages and you could include a payload to tell the application what to do. But then why not just use SMS in the first place? SMS is costly.

Persistent Connection: This would solve the problem of periodic polling but would destroy the battery life.
                                                   Cloud to device messaging   

“Android Cloud to Device Messaging (C2DM) is a service that helps developers send data from servers to their applications on Android devices. The service provides a simple, lightweight mechanism that servers can use to tell mobile applications to contact the server directly, to fetch updated application or user data. The C2DM service handles all aspects of queueing of messages and delivery to the target application running on the target device.”

It is a server push service provided by Google so that 3rd party applications can push messages to their applications on android devices.
Here are a few basic things to know about C2DM:

    It requires Android 2.2; C2DM uses Google services which are present on any device running the Android Market.
    It uses existing connections for Google services. This requires the users to sign into their Google account on Android.
    It allows 3rd party servers to send lightweight data messages to their apps. The C2DM service is not designed for pushing a lot of user content; rather it should be used like a “tickle”, to tell the app that there is new data on the server, so the app can fetch it.
    An application doesn’t need to be running to receive data messages. The system will wake up the app via an Intent broadcast when the the data message arrives, so long as the app is set up with the proper Intent Receiver and permissions.
    No user interface is required for receiving the data messages. The app can post a notification (or display other UI) if it desires.




Check out this may be help you

Related Posts Plugin for WordPress, Blogger...