Monday 6 June 2011

Task Manager Activity.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:id="@+id/tasks_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/tasks"
    />
    <TextView
    android:id="@+id/tasks_list_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/tasks_title"
    android:layout_above="@+id/add_button" />
    <Botton
    android:id="@id/add_button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/add_task"
    android:layout_alignParentBottom="true"
    />
</RelativeLayout>



string.xml



<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My Task Manager</string>
    <string name="tasks">Tasks</string>
    <string name="add_task">ADD Task</string>
</resources>


ViewTaskActivity.java



package com.seyi.android.mytaskmanager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ViewTaskActivity extends Activity {
   
    private Button addButton;
private TextView taskText;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setUpViews();
    }

private void setUpViews() {

addButton=(Button)findViewById(R.id.add_button);
taskText=(TextView)findViewById(R.id.tasks_list_text);
addButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(ViewTaskActivity.this,AddTaskActivity.class);
startActivity(intent);
}

});
}
}



AddTaskActivity.java



package com.seyi.android.mytaskmanager;

import android.app.Activity;
import android.os.Bundle;

public class AddTaskActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.add_task);
}

}

add_task.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    </LinearLayout>

My Task Manager Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.seyi.android.mytaskmanager"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ViewTaskActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
<activity android:name=".ViewTaskActivity"
                  android:label="@string/app_name">
                  </activity>
                  
    </application>
</manifest>


Monday 4 April 2011

Green flash light activity

how to create a green flash  light activity 
This program creates a green flash light activities and a button. It switches between green flash light and red by clicking the button.

Steps

To create a green flash light activity you go to flash light activity à create activity à new class.

·        Type “green flash light activity” to name.
·        Type Android activity to super class.
Go to lay out and click create a new file then name it “green.xml”  Type in the code below :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="@color/green"
    >
<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/green"
    />
    <Button
    android:id="@+id/red_button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/red"
    />
</LinearLayout>


Green color should be define in color.xml. (  <color name="green">#FF00FF00</color>)

Go to green flashlight activity and override oncreate method{ sourceà overridemethodà oncreate(bundle). Then set the content view.

(setContentView(R.layout.green);)


Use intent in red flash activity. The purpose of this intent is to allow the activity to switch between red and green.

(public void onClick(View v) {
                  Intent intent = new Intent(MyRedFlaslightActivity.this,GreenFlashLightActivity.class);
                  startActivity(intent);
                                                                  )

Create the activity in the manifest cos android only recognize the activity designrd in the manifest. Design green flash light activity in the manifest.

(<activity android:name=".GreenFlashLightActivity" android:label="@string/app_name"/>)

To switch over to red light activity  by clicking a red button. You need to create a red button object in the  green light activity, but no need for intent because it’s just to end the program and not to switch within. (Button redButton = (Button)findViewById(R.id.red_button);
        redButton.setOnClickListener(new View.OnClickListener() {
                 
            @Override
                  public void onClick(View v) {
                  finish();
                                                                  )
Instead of intent  you use finish();

Then run




Sunday 3 April 2011

creating a button

How to create a button in android


  • Add a button to the main layout
  • Add the button to the activity
  • Label the button green
  • Add a click listener to the activity

Step 1

  1. open flash light activity
  2. click on R. @ the set  content view and press f3 (setContentView(R.layout.main);
go to the main view and right under label red put your code : (<Button
    android:id="@+id/green_button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
 android:text="@string/green"  )

(The “+” means that it’s the first time , I’m defining this id , so give me a new unique number identifier in the R-file.  Subsequently the + won’t be added if I need to put another id.)

(string name of green need to be created in string.xml to avoid error after typing the above code. (  <string name="green">Green</string>  )

3. Add a quick listener by going to myRedFlashLightActivity and type this code (Button greenButton = (Button)findViewById(R.id.green_button);
        greenButton.setOnClickListener(new View.OnClickListener() { ).

4. Run on emulator.


The outcome :








    


Monday 14 February 2011


THE TWITTER API METHODS

The API method currently maintained by twitter can be organize into the following group based on what they are used for :

Publishing : this include changing the content published to twitter.
The information stream : This include retrieving and managing content publish to twitter .
The follow network : this include managing the people that follw a user and whom a user is following.
Communication: this involve exchanging the direct message with other member
Member account: dealing with twitter account
Administration: it negotiates access to twitter API.
Search: involves looking for key words in twitter achieves

Publishing

This method can be us to publish content or remove it from twitter information system.
Post a tweet : this method adds a tweet to information  stream for  authenticared users . This is an update of a current member’s status:


to make this URL function authentication is requested. since it requires a change to the service data base , the POST method is is required to encapsulate the parameter data. When a posting of a tweet is successful, twitter returns XML containing information about the new update.

Delete a tweet:  status update can be deleted after  being posted. However , it can only be successful if the authenticated is also the author of the update to be removed.

https://twitter.com/statuses/destroy/id.xml

The id parameter is required to identify to which specific character update is to be deleted or destroyed. If the request  is successful , twitter returns the status object information.

The information stream of twitter: the collection of publish tweets create a flow of information in twitter . There is a public time line of update fed by all account that are not configured to be private and are therefore available for anyone to take a look at..

  •  Show a tweet : this helps to view details for a single status update.
https://twitter.com/statuses/show/id.xml
this can be changed to json by editing the URL and changing the .xml to .json.
Authentication is not required as long as the tweet is public. Authentication is required if the post is from a private authors.

View the public time line

This method returns 20 most recent status update from public account in twitter.  Authentication is not needed.

https://twitter.com/statuses/public_timeline.xml

View a friend time line:
A method of API to access recent tweet from a specific user. A friend time line method returns 20 most recent status update posted by authenticated user and the author that a user follows.

https://twitter.com/statuses/friends_timeline.xml

a successful request returns XML that is the same with the data returned by the view the public time line method. There are several optional parameters that can be used to filter the data that is returned. Three of this parameter are since, since_id, count. These will change the number of returned id by cutting out the older tweet. The since_id parameter identifies a specific status ID. The count parameter shows the number recent tweets to show.

View an individual time line   
This stream contain tweet that was published by a single author. it returns 20 most recent status update by authenticated user.

https://twitter.com/statuses/user_timeline/id.xml

Authentication is needed for this method.

View replies
Replies are status update that reference twitter member.
https://twitter.com/statuses/replies.xml


View favorite
 This returns 20 most recent favorite statuses for the authenticated users.
https://twitter.com/favorites/seyi.xml


Sunday 13 February 2011

HTTP STATUS CODES IN TWITTER

Status code is a series of information returned to client in HTTP request.  It is a series of three digit number used to communicate the type of success or failure encountered after making a request. The twitter API assigns special meaning to this code which describe specific outcome of method request.
Examples of codes:
200—OK
Success! The method request did what you expected it to do.
304—Not Modified
Nothing wrong, but nothing to report.
400—Bad Request
This can be caused by one of two things: either the request was formatted incorrectly
(missing required parameters, unknown method, etc.), or the rate limit has
been exceeded. Check the returned text for an explanation.
401—Not Authorized
The account (Twitter username or registered email address) or password you used
to authenticate to the API isn’t working. Check its accuracy and try again.
403—Forbidden
Twitter understood what you want to do, but won’t let you do it. Check the returned
text for an explanation.
404—Not Found
Probably caused by a typo or incorrect path to the API method you are requesting.
You might also get this error when trying to request a nonexistent user.
500—Internal Server Error

Status code helps in error handling.


REST

The design of twitter API uses the principle of Restful system. This is called representational state transfer. REST is an architectural design or style which can be employed to create a web service that focus on system resources. This also   involves how resource states are issued and sent over a HTTP by different client written in different languages.
Basic design principle involve in REST are usage of HTTP more explicitly , Stateless , expose directory  structure ( like URL) , transfer XML , Java Script object notation or both.

Explicit usage of HTTP method

One of the futures of a RESTful web service is a detailed application of HTTP method in a way that follows protocol as laid out by RFC 2616. twitter API permit 4 kind of  HTTP request.: GET , POST , DELETE and UPDATE.

GET
 The Get method accepts URL and uses it to retrieve something from another server after necessary processing is done. If the web server is PHP web page , the Get method will capture the HTML generated by the   PHP and not the PHP code itself. GET method is use to carry out query, in which the web server will process the query and produce the result with the issued query. GET is a method that must be free from side effect call idempotent, must not have side effect for performing Get operation , and must be cacheable.  
Example of twitter API that are accessed with GET methods:


https://twitter.com/direct_messages.xml
https://twitter.com/favorites.xml
https://twitter.com/followers/ids.xml
https://twitter.com/friends/ids.xml
https://twitter.com/friendships/exists.xml
https://twitter.com/help/test.xml
https://twitter.com/statuses/followers.xml
https://twitter.com/statuses/friends.xml
https://twitter.com/statuses/friends_timeline.xml
https://twitter.com/statuses/public_timeline.xml
https://twitter.com/statuses/replies.xml
https://twitter.com/statuses/show/id.xml
https://twitter.com/statuses/user_timeline.xml
https://twitter.com/users/show/id.xml

The following can be written in json by changing the XML extension to json.


POST
The POST method is required for API method that actually makes changes to twitter severs, rather than just retrieving data.  POST is use to establish a resources on a server. In twitter API the following method required POST request handling:

https://twitter.com/account/update_delivery_device.xml
https://twitter.com/account/update_location.xml
https://twitter.com/account/update_profile.xml
https://twitter.com/account/update_profile_colors.xml
https://twitter.com/account/update_profile_background_image.xml
https://twitter.com/account/update_profile_image.xml
https://twitter.com/blocks/create/id.xml
https://twitter.com/blocks/destroy/id.xml
https://twitter.com/direct_messages/destroy/id.xml
https://twitter.com/direct_messages/new.xml
https://twitter.com/favorites/create/id.xml

DELETE

The purpose of this type of HTTP call is to instruct the remote server to remove the requested URL resources. The DELETE method must be idempotent which means the request can be done in multiple times.

   https://twitter.com/blocks/destroy/id.xml
https://twitter.com/favorites/destroy/id.xml
https://twitter.com/friendships/destroy/id.xml
https://twitter.com/direct_messages/destroy/id.xml
https://twitter.com/statuses/destroy/id.xml

  





                            INTRODUCTION TO TWITTER AND TWEET


  Twitter is an example of a micro blog. Based on usage twitter can also be referred to as a short message service. Twitter is an online social network that is used to stay in touch with friends’ family members and coworker through computers and mobile phone. The interface of twitter allows users to post short message of about 140 characters that can be viewed by any other person that uses twitter. Twitter allows people to declare the people they interested in following and those people will be notified. The follower gets to see the message whenever the people they are following get to post anything.
            Twitter users are allowed to update directly and indirectly.  Direct post is when a user targets a specific person in her post. Indirect post is when an update is for anyone that feels like reading it. The term use for someone that has interest in the status of another is called follower.
             In most cases, there are two categories of twitter user. The first category is those that have a large number of followers that those they are following. The other category is those that follow more people that they follow than people following them. The number of friends might be used to know if a user is active or not.

What is tweet?

The message posted on twitter is called a tweet and the maximum tweet that is allowed is 140 characters. To receive or send a tweet, a user must open a free account with twitter.  Twitter can be use  as a blog  and be kept public meaning anyone can read all tweets kept public on personal twitter profile page of a user. Network of contracts can be built by inviting other twitter users to read tweets.
Limitation of tweets
A tweet can only contain 140 characters. Text are only allowed  but no pictures or videos are allowed. A picture or video or any multi media can only be included in a tweet indirectly. This is achieved by locating a web that can host the files and sending a message that contain the page address to twitter networks. Twitter changes all address that more than 30 characters into tiny URL. tiny URL  is  a URL shortening service that converts long URL into different short URL but can be redirected to the long URL which is the main address.

Web syndications used in twitter   

Web syndication is the gathering of application from one source and sending it out to different destinations. There are different syndication format used on the web but twitter is compatible with two of them. the two syndication employed by twitter are : really simple syndication , otherwise known as RSS and Atom format called Atom. Both format can be use to collect data from one source and then transfer it to another. Atom and RSS consist of a few lines of codes which can be embedded by a web based administrator into his or her own site’s code. Visitors can register to  this syndication service called the feed and get an update every time an administrator post any new materials on the web sever. Twitter uses these features to allow twitter members to post a message to a network of other twitter members and also allows twitter member to subscribe to other twitter members field.