Skip to content

Commit

Permalink
gmail
Browse files Browse the repository at this point in the history
  • Loading branch information
nizarattack committed Mar 20, 2012
1 parent 8f2971c commit 5a5c1ed
Show file tree
Hide file tree
Showing 16 changed files with 808 additions and 2 deletions.
6 changes: 5 additions & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
</activity>
<activity android:name=".XMPPClient"/>
<activity android:name=".view.ym.BuddyListActivity"/>
<activity android:name=".view.ym.MessageListActivity"/>
<activity android:name=".view.ym.LoginActivity" />
<activity android:name=".view.ym.MessageListActivity"/>
<activity android:name=".view.gmail.LoginActivity"/>
<activity android:name=".view.gmail.ContactListActivity" />
<activity android:name=".view.gmail.ChatActivity" />
<service android:enabled="true" android:name=".view.gmail.NChatService" />
<service android:enabled="true" android:name=".view.ym.YmsgService" />
</application>

Expand Down
Binary file added res/drawable/available.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/busy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable/idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions res/layout/chat_gmail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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">

<TextView android:id="@+id/chatMessages"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:clickable="false" android:layout_weight="90" android:background="#FFFFFF" />

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:gravity="bottom" android:layout_height="wrap_content"
android:layout_weight="10" android:paddingTop="5dp">

<Button android:id="@+id/btnSend" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:layout_gravity="center_horizontal" android:text="@string/send"
android:layout_alignParentRight="true" android:layout_marginRight="5dp" />

<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textSize="15dp"
android:gravity="center_vertical|left" android:id="@+id/txfMessage"
android:editable="true" android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" android:layout_toLeftOf="@id/btnSend" />



</RelativeLayout>
</LinearLayout>
27 changes: 27 additions & 0 deletions res/layout/list_item_gmail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout android:id="@+id/tableLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:stretchColumns="1">

<TableRow android:layout_marginTop="5dp">
<ImageView android:layout_height="60dp" android:id="@+id/imgContact"
android:layout_width="60dp"></ImageView>

<LinearLayout android:id="@+id/linearLayout2"
android:layout_height="60dp" android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_marginLeft="10dp">
<TextView android:text="TextView" android:id="@+id/txtName"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:textSize="20dp"></TextView>
<TextView android:text="TextView" android:id="@+id/txtStatus"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"></TextView>
</LinearLayout>

</TableRow>


</TableLayout>

30 changes: 30 additions & 0 deletions res/layout/login_gmail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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="top" android:background="#FFFFFF">

<ImageView android:layout_height="85dp"
android:layout_width="180dp" android:clickable="false"
android:id="@+id/imageHeader" android:src="@drawable/gtalk_logo"
android:scaleType="fitXY"></ImageView>

<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">

<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textSize="15dp"
android:gravity="center_vertical|left" android:id="@+id/txfUser" android:editable="true"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp" />

<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textSize="15dp"
android:gravity="center_vertical|left" android:id="@+id/txfPassword"
android:editable="true" android:password="true"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp" />

<Button android:id="@+id/btnLogin" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:layout_gravity="center_horizontal" android:text="@string/login" />
</LinearLayout>
</LinearLayout>
18 changes: 18 additions & 0 deletions res/layout/main_gmail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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:background="#FFFFFF">
<ImageView android:layout_height="55dp"
android:layout_width="120dp" android:clickable="false"
android:id="@+id/imageHeader" android:src="@drawable/gtalk_logo"
android:scaleType="fitXY"></ImageView>
<ListView android:layout_height="fill_parent"
android:id="@+id/listViewContacts"
android:layout_width="fill_parent"
android:clickable="true"
android:layout_marginTop="10dip"
android:cacheColorHint="#00000000" >
</ListView>
</LinearLayout>
92 changes: 92 additions & 0 deletions src/com/chatmessenger/android/gmail/ConnectionHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.chatmessenger.android.gmail;

import java.util.ArrayList;
import java.util.Collection;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;

import com.chatmessenger.android.R;

import android.content.res.Resources;

public class ConnectionHelper {

static XMPPConnection conn = new XMPPConnection(new ConnectionConfiguration(
"talk.google.com", 5222, "google.com"));

static Roster roster;

public static void connect() throws XMPPException {
conn.connect();
}

public static XMPPConnection getConnection() {
return conn;
}

public static void login(String user, String pass) throws XMPPException {
conn.login(user, pass);
roster = conn.getRoster();
}

public static Roster getRoster() {
return roster;
}

public static ArrayList<Contact> getContactList(Resources res) {
ArrayList<Contact> contactList = new ArrayList<Contact>();
Collection<RosterEntry> rosterCollection = roster.getEntries();
Presence presence;
for (RosterEntry re : rosterCollection) {
presence = roster.getPresence(re.getUser());
if (presence.isAvailable()) {
Contact c = new Contact();
if(re.getName() == null || re.getName().trim().equals(""))
c.setName(re.getUser());
else
c.setName(re.getName());
c.setStatus(presence.getStatus());
c.setRosterEntry(re);
if (presence.getMode() == null)
c.setImage(res.getDrawable(R.drawable.available));
else if (presence.getMode().equals(Presence.Mode.chat))
c.setImage(res.getDrawable(R.drawable.available));
else if (presence.getMode().equals(Presence.Mode.away)
|| presence.getMode().equals(Presence.Mode.xa))
c.setImage(res.getDrawable(R.drawable.idle));
else if (presence.getMode().equals(Presence.Mode.dnd))
c.setImage(res.getDrawable(R.drawable.busy));
else
c.setImage(res.getDrawable(R.drawable.available));
contactList.add(c);
}
}
return contactList;
}

public static ArrayList<Contact> getContactList() {
ArrayList<Contact> contactList = new ArrayList<Contact>();
Collection<RosterEntry> rosterCollection = roster.getEntries();
Presence presence;
for (RosterEntry re : rosterCollection) {
presence = roster.getPresence(re.getUser());
if (presence.isAvailable()) {
Contact c = new Contact();
if(re.getName() == null || re.getName().trim().equals(""))
c.setName(re.getUser());
else
c.setName(re.getName());
c.setStatus(presence.getStatus());
c.setRosterEntry(re);
contactList.add(c);
}
}
return contactList;
}

}
41 changes: 41 additions & 0 deletions src/com/chatmessenger/android/gmail/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.chatmessenger.android.gmail;

import org.jivesoftware.smack.RosterEntry;

import android.graphics.drawable.Drawable;

public class Contact {

private String name;
private String status;
private Drawable image;
private RosterEntry rosterEntry;


public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Drawable getImage() {
return image;
}
public void setImage(Drawable image) {
this.image = image;
}
public RosterEntry getRosterEntry() {
return rosterEntry;
}
public void setRosterEntry(RosterEntry rosterEntry) {
this.rosterEntry = rosterEntry;
}


}
46 changes: 46 additions & 0 deletions src/com/chatmessenger/android/gmail/ContactArrayAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.chatmessenger.android.gmail;

import android.widget.ArrayAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;

import com.chatmessenger.android.R;

public class ContactArrayAdapter extends ArrayAdapter<Contact>
{
private int resource;

public ContactArrayAdapter(Context paramContext, int paramInt, List<Contact> paramList)
{
super(paramContext, paramInt, paramList);
this.resource = paramInt;
}

public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
{
Contact localContact = (Contact)getItem(paramInt);
LinearLayout localLinearLayout;
localLinearLayout = new LinearLayout(getContext());
((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(this.resource, localLinearLayout, true);
TextView localTextView1 = (TextView)localLinearLayout.findViewById(R.id.txtName);
TextView localTextView2 = (TextView)localLinearLayout.findViewById(R.id.txtStatus);
ImageView localImageView = (ImageView)localLinearLayout.findViewById(R.id.imgContact);
localTextView1.setText(localContact.getName());
localTextView2.setText(localContact.getStatus());
localImageView.setImageDrawable(localContact.getImage());
return localLinearLayout;






}
}
3 changes: 2 additions & 1 deletion src/com/chatmessenger/android/view/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.chatmessenger.android.R;
import com.chatmessenger.android.XMPPClient;
import com.chatmessenger.android.view.gmail.LoginActivity;
import com.chatmessenger.android.view.ym.BuddyListActivity;

import android.app.Activity;
Expand Down Expand Up @@ -30,7 +31,7 @@ public void onClickFacebook(View v){
}

public void onClickGtalk(View v){
Intent intent = new Intent(HomeActivity.this, XMPPClient.class);
Intent intent = new Intent(HomeActivity.this, LoginActivity.class);
startActivity(intent);
}
}
Loading

0 comments on commit 5a5c1ed

Please sign in to comment.