commit 129e8c9c0fcbc0092320e9230f9da16ee0befd0e Author: spike Date: Wed Nov 30 00:10:29 2011 +0100 initial commit diff --git a/LeWebConnect2011/.classpath b/LeWebConnect2011/.classpath new file mode 100644 index 0000000..a4f1e40 --- /dev/null +++ b/LeWebConnect2011/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/LeWebConnect2011/.gitignore b/LeWebConnect2011/.gitignore new file mode 100644 index 0000000..a22392a --- /dev/null +++ b/LeWebConnect2011/.gitignore @@ -0,0 +1,2 @@ +/bin +/gen diff --git a/LeWebConnect2011/.project b/LeWebConnect2011/.project new file mode 100644 index 0000000..d8a78c0 --- /dev/null +++ b/LeWebConnect2011/.project @@ -0,0 +1,33 @@ + + + LeWebConnect2011 + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/LeWebConnect2011/.settings/org.eclipse.jdt.core.prefs b/LeWebConnect2011/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..efeb3d5 --- /dev/null +++ b/LeWebConnect2011/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Tue Nov 29 22:35:36 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/LeWebConnect2011/AndroidManifest.xml b/LeWebConnect2011/AndroidManifest.xml new file mode 100644 index 0000000..fd030a6 --- /dev/null +++ b/LeWebConnect2011/AndroidManifest.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/proguard.cfg b/LeWebConnect2011/proguard.cfg new file mode 100644 index 0000000..b1cdf17 --- /dev/null +++ b/LeWebConnect2011/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native ; +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public (android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/LeWebConnect2011/project.properties b/LeWebConnect2011/project.properties new file mode 100644 index 0000000..f049142 --- /dev/null +++ b/LeWebConnect2011/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-10 diff --git a/LeWebConnect2011/res/drawable-hdpi/fb.png b/LeWebConnect2011/res/drawable-hdpi/fb.png new file mode 100644 index 0000000..ea17459 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/fb.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_launcher.png b/LeWebConnect2011/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..8074c4c Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_launcher.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites.xml b/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites.xml new file mode 100644 index 0000000..53e4df2 --- /dev/null +++ b/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites_dark.png b/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites_dark.png new file mode 100644 index 0000000..5064df4 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites_dark.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites_light.png b/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites_light.png new file mode 100644 index 0000000..eda45eb Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_tab_favorites_light.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents.xml b/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents.xml new file mode 100644 index 0000000..f72b0b3 --- /dev/null +++ b/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents_dark.png b/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents_dark.png new file mode 100644 index 0000000..b4addca Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents_dark.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents_light.png b/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents_light.png new file mode 100644 index 0000000..4c71404 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_tab_perticipents_light.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_search.xml b/LeWebConnect2011/res/drawable-hdpi/ic_tab_search.xml new file mode 100644 index 0000000..dee1901 --- /dev/null +++ b/LeWebConnect2011/res/drawable-hdpi/ic_tab_search.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_search_dark.png b/LeWebConnect2011/res/drawable-hdpi/ic_tab_search_dark.png new file mode 100644 index 0000000..2e79f84 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_tab_search_dark.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/ic_tab_search_light.png b/LeWebConnect2011/res/drawable-hdpi/ic_tab_search_light.png new file mode 100644 index 0000000..d44cd20 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/ic_tab_search_light.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/linkedin.png b/LeWebConnect2011/res/drawable-hdpi/linkedin.png new file mode 100644 index 0000000..58e3316 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/linkedin.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/no_all.png b/LeWebConnect2011/res/drawable-hdpi/no_all.png new file mode 100644 index 0000000..1a6a8fb Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/no_all.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/no_fb.png b/LeWebConnect2011/res/drawable-hdpi/no_fb.png new file mode 100644 index 0000000..a1b994f Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/no_fb.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/no_linkedin.png b/LeWebConnect2011/res/drawable-hdpi/no_linkedin.png new file mode 100644 index 0000000..d331f38 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/no_linkedin.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/no_twitter.png b/LeWebConnect2011/res/drawable-hdpi/no_twitter.png new file mode 100644 index 0000000..2712f01 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/no_twitter.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/social_all.png b/LeWebConnect2011/res/drawable-hdpi/social_all.png new file mode 100644 index 0000000..6e64205 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/social_all.png differ diff --git a/LeWebConnect2011/res/drawable-hdpi/twitter.png b/LeWebConnect2011/res/drawable-hdpi/twitter.png new file mode 100644 index 0000000..28bf698 Binary files /dev/null and b/LeWebConnect2011/res/drawable-hdpi/twitter.png differ diff --git a/LeWebConnect2011/res/drawable-ldpi/ic_launcher.png b/LeWebConnect2011/res/drawable-ldpi/ic_launcher.png new file mode 100644 index 0000000..1095584 Binary files /dev/null and b/LeWebConnect2011/res/drawable-ldpi/ic_launcher.png differ diff --git a/LeWebConnect2011/res/drawable-mdpi/ic_launcher.png b/LeWebConnect2011/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..a07c69f Binary files /dev/null and b/LeWebConnect2011/res/drawable-mdpi/ic_launcher.png differ diff --git a/LeWebConnect2011/res/layout/main.xml b/LeWebConnect2011/res/layout/main.xml new file mode 100644 index 0000000..a51c7c7 --- /dev/null +++ b/LeWebConnect2011/res/layout/main.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/layout/mainxml b/LeWebConnect2011/res/layout/mainxml new file mode 100644 index 0000000..a51c7c7 --- /dev/null +++ b/LeWebConnect2011/res/layout/mainxml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/layout/perticipents.xml b/LeWebConnect2011/res/layout/perticipents.xml new file mode 100644 index 0000000..7d31d93 --- /dev/null +++ b/LeWebConnect2011/res/layout/perticipents.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/layout/rowlayout.xml b/LeWebConnect2011/res/layout/rowlayout.xml new file mode 100644 index 0000000..a0b3945 --- /dev/null +++ b/LeWebConnect2011/res/layout/rowlayout.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/menu/attendies.xml b/LeWebConnect2011/res/menu/attendies.xml new file mode 100644 index 0000000..9391bc1 --- /dev/null +++ b/LeWebConnect2011/res/menu/attendies.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/LeWebConnect2011/res/values/strings.xml b/LeWebConnect2011/res/values/strings.xml new file mode 100644 index 0000000..bd499ba --- /dev/null +++ b/LeWebConnect2011/res/values/strings.xml @@ -0,0 +1,10 @@ + + + Hello World, LeWebConnectActivity! + LeWebConnect + Type in a persone or a company name + By Name + By Company + By Country + + \ No newline at end of file diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/Attendee.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/Attendee.java new file mode 100644 index 0000000..4113e04 --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/Attendee.java @@ -0,0 +1,134 @@ +package com.thinkit.lewebconnect; + +import java.util.Comparator; + +public class Attendee{ + private int id; + private String fname; + private String lname; + private String company; + private String twitter; + private String url; + private String linkedin; + private String facebook; + private String country; + + public Attendee() + { + + } + + public Attendee(int id) + { + this.id = id; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFname() { + return fname; + } + + public void setFname(String fname) { + this.fname = fname; + } + + public String getLname() { + return lname; + } + + public void setLname(String lname) { + this.lname = lname; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getTwitter() { + return twitter; + } + + public void setTwitter(String twitter) { + this.twitter = twitter; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getLinkedin() { + return linkedin; + } + + public void setLinkedin(String linkedin) { + this.linkedin = linkedin; + } + + public String getFacebook() { + return facebook; + } + + public void setFacebook(String facebook) { + this.facebook = facebook; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + @Override public String toString() { + return new String(getFname() + " " + getLname()); + + } + + static public class LeWebByLnameComparator implements Comparator + { + + public int compare(Attendee lhs, Attendee rhs) { + // TODO Auto-generated method stub + return lhs.getLname().compareToIgnoreCase(rhs.getLname()); + } + + } + + static public class LeWebByCompanyComparator implements Comparator + { + + public int compare(Attendee lhs, Attendee rhs) { + // TODO Auto-generated method stub + return lhs.getCompany().compareToIgnoreCase(rhs.getCompany()); + } + + } + + static public class LeWebByCountryComparator implements Comparator + { + + public int compare(Attendee lhs, Attendee rhs) { + // TODO Auto-generated method stub + return lhs.getCountry().compareToIgnoreCase(rhs.getCountry()); + } + + } +} + + diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/LeWebAdapter.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/LeWebAdapter.java new file mode 100644 index 0000000..08e168d --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/LeWebAdapter.java @@ -0,0 +1,458 @@ +package com.thinkit.lewebconnect; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.SectionIndexer; +import android.widget.TextView; + +public class LeWebAdapter extends ArrayAdapter { + + private final Context context; + private ArrayList users; + + /** + * Lock used to modify the content of {@link #mObjects}. Any write operation + * performed on the array should be synchronized on this lock. This lock is also + * used by the filter (see {@link #getFilter()} to make a synchronized copy of + * the original array of data. + */ + private final Object mLock = new Object(); + + private ArrayList originalUsers; + private LeWebFilter filter; + + + private boolean mNotifyOnChange = true; + + private HashMap alphaIndexer; + private String[] sections = new String[0]; + + + private boolean enableSections; + private boolean companySections; + private boolean countrySections; + + + public LeWebAdapter(Context context, ArrayList users, + boolean enableSections, boolean companySections, boolean countrySections) { + super(context, R.layout.rowlayout, users); + + Log.d("LeWebAdapter", "LeWebAdapter constructor"); + this.context = context; + this.users = users; + this.filter = new LeWebFilter(); + this.enableSections = enableSections; + this.companySections = companySections; + this.countrySections = countrySections; + + + if(enableSections) + { +// Log.d("LeWebAdapter", "Sections enabled"); +// alphaIndexer = new HashMap(); +// String firstChar; +// for(int i = users.size() - 1; i >= 0; i--) +// { +// Attendee element = users.get(i); +// if (countrySections) +// firstChar = element.getCountry().substring(0, 1).toUpperCase(); +// else if (companySections) +// { +// Log.d("Sections", "Enabling company section, getting first letter"); +// firstChar = element.getCompany().substring(0, 1).toUpperCase(); +// } +// else +// firstChar = element.getLname().substring(0, 1).toUpperCase(); +// +// if(firstChar.charAt(0) > 'Z' || firstChar.charAt(0) < 'A') +// firstChar = "A"; +// +// alphaIndexer.put(firstChar, i); +// } +// +// Set keys = alphaIndexer.keySet(); +//// Log.d("LeWebAdapter", keys.toString()); +// Iterator it = keys.iterator(); +// ArrayList keyList = new ArrayList(); +// +// while(it.hasNext()) +// keyList.add(it.next()); +// +// Collections.sort(keyList); +// sections = new String[keyList.size()]; +// keyList.toArray(sections); +//// Log.d("LeWebAdapter", keyList.toString()); +//// Log.d("LeWebAdapter", alphaIndexer.toString()); + buildHashIndexer(); + buildSections(); + } + } + + public void buildSections() { + + Set keys = alphaIndexer.keySet(); + Iterator it = keys.iterator(); + ArrayList keyList = new ArrayList(); + + while(it.hasNext()) + keyList.add(it.next()); + + Collections.sort(keyList); + sections = new String[keyList.size()]; + keyList.toArray(sections); + } + + public void buildHashIndexer() + { + try { +// Log.d("LeWebAdapter", "Building hashindexer"); + alphaIndexer = new HashMap(); + String firstChar; + for(int i = users.size() - 1; i >= 0; i--) + { + Attendee element = users.get(i); + if (countrySections) + firstChar = element.getCountry().substring(0, 1).toUpperCase(); + else if (companySections) + { + Log.d("Sections", "Enabling company section, getting first letter"); + firstChar = element.getCompany().substring(0, 1).toUpperCase(); + } + else + firstChar = element.getLname().substring(0, 1).toUpperCase(); + + if(firstChar.charAt(0) > 'Z' || firstChar.charAt(0) < 'A') + firstChar = "A"; + + alphaIndexer.put(firstChar, i); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + @Override + public void notifyDataSetChanged(){ + if (enableSections) + { + Log.d("notifyDataSetChanged", "..."); + buildHashIndexer(); + buildSections(); + } + super.notifyDataSetChanged(); + mNotifyOnChange = true; + } + + @Override + public void notifyDataSetInvalidated() + { + if(enableSections) + { + Log.d("notifyDataSetInvalidated", "..."); + + buildHashIndexer(); + buildSections(); + super.notifyDataSetInvalidated(); + } + } + + public void setNotifyOnChange(boolean notifyOnChange){ + mNotifyOnChange = notifyOnChange; + + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View rowview = inflater.inflate(R.layout.rowlayout, parent, false); + //Log.d("getView", "Making row ...."); + try { + Attendee user = users.get(position); + if (user != null) + { + TextView name_text = (TextView) rowview.findViewById(R.id.name_text); + TextView company = (TextView) rowview.findViewById(R.id.company_text); + TextView country = (TextView) rowview.findViewById(R.id.country_text); + if (name_text != null) + name_text.setText(user.getLname() + " " + user.getFname()); + if (company != null) + company.setText(user.getCompany()); + if (country != null) + country.setText(user.getCountry()); + ImageView imageView = (ImageView) rowview.findViewById(R.id.icons); + setImage(imageView, user); +// imageView.setVisibility(View.GONE); + + if(enableSections && getSectionForPosition(position) != getSectionForPosition(position - 1)) + { +// Log.d("getView", "Setting Header ........ " + String.valueOf(position)); + TextView h = (TextView) rowview.findViewById(R.id.header); + h.setText(sections[getSectionForPosition(position)]); + h.setVisibility(View.VISIBLE); + } + else + { + TextView h = (TextView) rowview.findViewById(R.id.header); + h.setVisibility(View.GONE); + } + } + + + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + return rowview; + } + + + private void setImage(ImageView imageView, Attendee user) { + // TODO Auto-generated method stub + boolean facebook = false; + boolean twitter = false; + boolean linkedin = false; + if ( user.getFacebook() != null && !user.getFacebook().equals("null") && !user.getFacebook().isEmpty()) + facebook = true; + if ( user.getLinkedin() != null && !user.getLinkedin().equals("null") && !user.getLinkedin().isEmpty()) + linkedin = true; + if ( user.getTwitter() != null && !user.getTwitter().equals("null") && !user.getTwitter().isEmpty()) + twitter = true; + + if (facebook && twitter && linkedin) + imageView.setImageResource(R.drawable.social_all); + else if (facebook && twitter) + imageView.setImageResource(R.drawable.no_linkedin); + else if (facebook && linkedin) + imageView.setImageResource(R.drawable.no_twitter); + else if (twitter && linkedin) + imageView.setImageResource(R.drawable.no_fb); + else if (twitter) + imageView.setImageResource(R.drawable.twitter); + else if (facebook) + imageView.setImageResource(R.drawable.fb); + else if (linkedin) + imageView.setImageResource(R.drawable.linkedin); + else + imageView.setImageResource(R.drawable.no_all); + } + + @Override + public int getCount(){ + return this.users.size(); + } + + + public int getPositionForSection(int section) + { + try { + if(!enableSections) return 0; + if (section == sections.length) + section--; + String letter = sections[section]; + + return alphaIndexer.get(letter); + } catch (Exception e) { + // TODO: handle exception + Log.d("getPositionForSection", String.valueOf(section)); + Log.d("getPositionForSection", "alphaindexer: " + alphaIndexer.toString()); + Log.d("getPositionForSection", "sections: " + getSections()); + //e.printStackTrace(); + } + return 0; + } + + public int getSectionForPosition(int position) + { +// Log.d("getSectionForPosition", "recievied position : " + String.valueOf(position)); + if(!enableSections) return 0; + int prevIndex = 0; +// for(int i = 0; i < sections.length; i++) +// { +// if(getPositionForSection(i) > position && prevIndex <= position) +// { +// prevIndex = i ; +// break; +// } +// prevIndex = i; +// } + + int i = 0; + while (i < sections.length) { +// Log.d("i", "------------>" + String.valueOf(i)); +// Log.d("sectionsLength", "------------>" + String.valueOf(sections.length)); + if (getPositionForSection(i) > position && prevIndex <= position) + { + prevIndex = i; + break; + } + prevIndex = i; + i++; + } + + prevIndex--; +// Log.d("getSectionForPosition", "Returning : " + String.valueOf(prevIndex)); + return prevIndex; + } + + public Object[] getSections() + { + return sections; + } + + @Override + public android.widget.Filter getFilter() + { + if(filter == null) + filter = new LeWebFilter(); + return filter; + } + + + // Currently filters only by Lname + private class LeWebFilter extends android.widget.Filter + { + @Override + protected FilterResults performFiltering(CharSequence constraint) { + // NOTE: this function is *always* called from a background thread, and + // not the UI thread. + Log.d("Filter", "Filter ....."); + + FilterResults results = new FilterResults(); + + + if (originalUsers == null) { + synchronized (mLock) { + originalUsers = new ArrayList(users); + } + } + if (constraint == null || constraint.length() == 0) { + synchronized (mLock) { + ArrayList list = new ArrayList(originalUsers); + results.values = list; + results.count = list.size(); + } + } else { + try { + String constraintStr = constraint.toString().toLowerCase(); + final ArrayList values = originalUsers; + final int count = values.size(); + + final ArrayList newValues = new ArrayList(); + + for (int i = 0; i < count; i++) { + final Attendee value = values.get(i); + final String valueText; + if (companySections) + { + valueText = value.getCompany().toLowerCase(); + } + else if (countrySections){ + valueText = value.getCountry().toLowerCase(); + } + else { + valueText = value.getLname().toLowerCase(); + } + + // First match against the whole, non-splitted value + if (valueText.startsWith(constraintStr)) { + newValues.add(value); + } else { + final String[] words = valueText.split(" "); + final int wordCount = words.length; + + for (int k = 0; k < wordCount; k++) { + if (words[k].startsWith(constraintStr)) { + newValues.add(value); + break; + } + } + } + } + + results.values = newValues; + results.count = newValues.size(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + return results; + } +// constraint = constraint.toString().toLowerCase(); +// if(constraint != null && constraint.toString().length() > 0) +// { +// Log.d("Filter", "constraint not null with value <" + constraint.toString() + ">"); +// ArrayList filt = new ArrayList(); +// ArrayList lItems = new ArrayList(); +// synchronized (this) +// { +// lItems.addAll(users); +// } +// for(int i = 0, l = lItems.size(); i < l; i++) +// { +// Attendee m = lItems.get(i); +// if (countrySections && m.getCountry().toLowerCase().contains(constraint)) +// filt.add(m); +// else if (companySections && m.getCompany().toLowerCase().contains(constraint)) +// filt.add(m); +// else if (m.getLname().toLowerCase().contains(constraint)) +// filt.add(m); +// } +// result.count = filt.size(); +// result.values = filt; +// } +//// else if (constraint == null || constraint.length() == 0) +//// { +//// ArrayList list = new ArrayList(originalUsers); +//// result.values=list; +//// result.count = list.size(); +//// } +// else +// { +// synchronized(this) +// { +// result.values = users; +// result.count = users.size(); +// } +// } +// return result; + + @SuppressWarnings("unchecked") + protected void publishResults(CharSequence constraint, FilterResults results) { + // NOTE: this function is *always* called from the UI thread. + users = (ArrayList)results.values; + if (results.count > 0) { +// buildHashIndexer(); +// buildSections(); + notifyDataSetChanged(); + } else { +// buildHashIndexer(); +// buildSections(); + notifyDataSetInvalidated(); + } +// notifyDataSetChanged(); +// clear(); +// for(int i = 0, l = originalUsers.size(); i < l; i++) +// add(originalUsers.get(i)); +// notifyDataSetInvalidated(); + } + + + } +} \ No newline at end of file diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/LeWebConnect.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/LeWebConnect.java new file mode 100644 index 0000000..3b9d7e4 --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/LeWebConnect.java @@ -0,0 +1,53 @@ +package com.thinkit.lewebconnect; + +import android.app.TabActivity; +import android.content.Intent; +import android.content.res.Resources; +import android.os.Bundle; +import android.util.Log; +import android.widget.TabHost; +import android.widget.TextView; + +public class LeWebConnect extends TabActivity{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + try { + Resources res = getResources(); // Resource object to get Drawables + TabHost tabHost = getTabHost(); // The activity TabHost + TabHost.TabSpec spec; // Resusable TabSpec for each tab + Intent intent; // Reusable Intent for each tab + // Create an Intent to launch an Activity for the tab (to be reused) + intent = new Intent().setClass(this, Perticipents.class); + // Initialize a TabSpec for each tab and add it to the TabHost + spec = tabHost + .newTabSpec("perticipents") + .setIndicator("", + res.getDrawable(R.drawable.ic_tab_perticipents)) + .setContent(intent); + tabHost.addTab(spec); + // Do the same for the other tabs + intent = new Intent().setClass(this, Search.class); + spec = tabHost + .newTabSpec("search") + .setIndicator("", res.getDrawable(R.drawable.ic_tab_search)) + .setContent(intent); + tabHost.addTab(spec); + intent = new Intent().setClass(this, Likes.class); + spec = tabHost + .newTabSpec("likes") + .setIndicator("", + res.getDrawable(R.drawable.ic_tab_favorites)) + .setContent(intent); + tabHost.addTab(spec); + tabHost.setCurrentTab(0); + } catch (Exception e) { + // TODO: handle exception + Log.d("Error", e.toString()); + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/Likes.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/Likes.java new file mode 100644 index 0000000..508fc37 --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/Likes.java @@ -0,0 +1,13 @@ +package com.thinkit.lewebconnect; + +import android.app.Activity; +import android.os.Bundle; + +public class Likes extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + } +} \ No newline at end of file diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/Perticipents.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/Perticipents.java new file mode 100644 index 0000000..623a1f6 --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/Perticipents.java @@ -0,0 +1,214 @@ +package com.thinkit.lewebconnect; + + +import java.util.ArrayList; +import java.util.Collections; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.thinkit.lewebconnect.Attendee.LeWebByCompanyComparator; +import com.thinkit.lewebconnect.Attendee.LeWebByCountryComparator; +import com.thinkit.lewebconnect.Attendee.LeWebByLnameComparator; + +import android.app.ListActivity; +import android.content.Context; +import android.os.Bundle; +import android.sax.Element; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.Adapter; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.Filterable; +import android.widget.ListView; +import android.widget.Toast; + + + +public class Perticipents extends ListActivity { + /** Called when the activity is first created. */ + + private static String TAG = "Perticipents"; + private ArrayList users; + private EditText filterText = null; + ArrayAdapter adapter = null; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + + String xml; + xml = XMLfunctions.getXML(); + Document doc = XMLfunctions.XMLfromString(xml); + int numResults = XMLfunctions.numResults(doc); + //Log.d(TAG, "numResults length: " + String.valueOf(numResults)); + + if((numResults <= 0)) { + Toast.makeText(this, "Please make sure connection is available !", Toast.LENGTH_LONG).show(); + finish(); + } + + + NodeList nodes = doc.getElementsByTagName("user"); + try { + users = new ArrayList(); + //fill in the list items from the XML document + for (int i = 0; i < nodes.getLength(); i++) { + Node e = (Node)nodes.item(i); + users.add(NodeToAttendee(e)); + } + Collections.sort(users, new LeWebByLnameComparator()); + + + + setContentView(R.layout.perticipents); + filterText= (EditText) findViewById(R.building_list.search_box); + filterText.addTextChangedListener(filterTextWatcher); + + + ListView lv = getListView(); + lv.setFastScrollEnabled(true); + lv.setTextFilterEnabled(false); + + adapter = new LeWebAdapter(this, users, true, false, false); + + + setListAdapter(adapter); + + + + + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + } + } + + + private TextWatcher filterTextWatcher = new TextWatcher() { + public void afterTextChanged(Editable s) { + } + + public void beforeTextChanged(CharSequence s, int start, int count, + int after) { + } + + @SuppressWarnings("unchecked") + public void onTextChanged(CharSequence s, int start, int before, + int count) { + ListView lv = getListView(); + Log.d("onTextChanged", s.toString()); + Log.d("getCount", String.valueOf(lv.getAdapter().getCount())); + adapter = (ArrayAdapter) lv.getAdapter(); + adapter.getFilter().filter(s); + Log.d("getCount", String.valueOf(lv.getAdapter().getCount())); + } + }; + + + + @Override + protected void onDestroy() { + super.onDestroy(); + filterText.removeTextChangedListener(filterTextWatcher); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // TODO Auto-generated method stub + MenuInflater infalter = getMenuInflater(); + infalter.inflate(R.menu.attendies, menu); + return super.onCreateOptionsMenu(menu); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // TODO Auto-generated method stub + switch (item.getItemId()) { + case R.id.by_name: + { + try { + Collections.sort(users, new LeWebByLnameComparator()); + adapter = new LeWebAdapter(this, users, true, false, false); + ListView lv = getListView(); + lv.setTextFilterEnabled(false); + lv.setAdapter(adapter); + lv.refreshDrawableState(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Toast.makeText(this, "Filtering by Name!", Toast.LENGTH_LONG).show(); + break; + } + case R.id.by_country: + { + try { + Collections.sort(users, new LeWebByCountryComparator()); + adapter = new LeWebAdapter(this, users, true, false, true); + ListView lv = getListView(); + lv.setTextFilterEnabled(false); + lv.setAdapter(adapter); + lv.refreshDrawableState(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Toast.makeText(this, "Filtered by country.", Toast.LENGTH_LONG).show(); + break; + } + + case R.id.by_company: + { + try { + Collections.sort(users, new LeWebByCompanyComparator()); + adapter = new LeWebAdapter(this, users, true, true, false); + ListView lv = getListView(); + lv.setTextFilterEnabled(false); + lv.setAdapter(adapter); + lv.refreshDrawableState(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Toast.makeText(this, "Filtered by company.", Toast.LENGTH_LONG).show(); + break; + } + } + return super.onOptionsItemSelected(item); + } + + + public Attendee NodeToAttendee(Node userNode) + { + NamedNodeMap attrs = userNode.getAttributes(); + String fname = attrs.getNamedItem("fname").getTextContent(); + String lname = attrs.getNamedItem("lname").getTextContent(); + String company = attrs.getNamedItem("company").getTextContent(); + String country = attrs.getNamedItem("country").getTextContent(); + String facebook = attrs.getNamedItem("facebook").getTextContent(); + String twitter = attrs.getNamedItem("twitter").getTextContent(); + + Attendee user = new Attendee(); + user.setFname(fname); + user.setLname(lname); + user.setCompany(company); + user.setCountry(country); + user.setFacebook(facebook); + user.setTwitter(twitter); + return user; + } + } \ No newline at end of file diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/Search.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/Search.java new file mode 100644 index 0000000..202c1d9 --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/Search.java @@ -0,0 +1,15 @@ +package com.thinkit.lewebconnect; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +public class Search extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + TextView textview = new TextView(this); + textview.setText("search view"); + setContentView(textview); } +} \ No newline at end of file diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/WebService.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/WebService.java new file mode 100644 index 0000000..4253d70 --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/WebService.java @@ -0,0 +1,46 @@ +package com.thinkit.lewebconnect; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import android.content.Context; +import android.util.Log; + +public class WebService { + static String XML_DB_URL = "http://leweb.i-think-it.com/get/"; + static private String FILENAME = "leweb.xml"; + private int bufsize = 1024; + private Context context; + + public WebService(Context appcontext) + { + Log.d("WebService", "starting web service constructor"); + this.context = appcontext; + } + + + public void GetRemoteDB() throws IOException + { + Log.d("WebService", "inside getremote"); + URL url = new URL(XML_DB_URL); + InputStream input = url.openStream(); + Log.d("WebService", "Opened remote streamm starting download"); + try { + FileOutputStream output = context.openFileOutput(FILENAME, Context.MODE_PRIVATE); + try { + byte[] buffer = new byte[bufsize]; + int bytesRead = 0; + while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) { + Log.d("WebService", new String(buffer, 0, bufsize)); + output.write(buffer, 0, buffer.length); + } + } finally { + output.close(); + } + } finally { + input.close(); + } + } +} diff --git a/LeWebConnect2011/src/com/thinkit/lewebconnect/XMLfunctions.java b/LeWebConnect2011/src/com/thinkit/lewebconnect/XMLfunctions.java new file mode 100644 index 0000000..d24308c --- /dev/null +++ b/LeWebConnect2011/src/com/thinkit/lewebconnect/XMLfunctions.java @@ -0,0 +1,117 @@ +package com.thinkit.lewebconnect; + +import java.io.IOException; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import android.util.Log; + + +public class XMLfunctions { + + public final static Document XMLfromString(String xml){ + + Document doc = null; + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + try { + + DocumentBuilder db = dbf.newDocumentBuilder(); + + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(xml)); + doc = db.parse(is); + + } catch (ParserConfigurationException e) { + System.out.println("XML parse error: " + e.getMessage()); + return null; + } catch (SAXException e) { + System.out.println("Wrong XML file structure: " + e.getMessage()); + return null; + } catch (IOException e) { + System.out.println("I/O exeption: " + e.getMessage()); + return null; + } + + return doc; + + } + + /** Returns element value + * @param elem element (it is XML tag) + * @return Element value otherwise empty String + */ + public final static String getElementValue( Node elem ) { + Node kid; + if( elem != null){ + if (elem.hasChildNodes()){ + for( kid = elem.getFirstChild(); kid != null; kid = kid.getNextSibling() ){ + if( kid.getNodeType() == Node.TEXT_NODE ){ + return kid.getNodeValue(); + } + } + } + } + return ""; + } + + public static String getXML(){ + String line = null; + + try { + + DefaultHttpClient httpClient = new DefaultHttpClient(); + HttpGet get = new HttpGet(WebService.XML_DB_URL); + + HttpResponse httpResponse = httpClient.execute(get); + HttpEntity httpEntity = httpResponse.getEntity(); + line = EntityUtils.toString(httpEntity); + + } catch (UnsupportedEncodingException e) { + line = "Can't connect to server"; + } catch (MalformedURLException e) { + line = "Can't connect to server"; + } catch (IOException e) { + line = "Can't connect to server"; + } + + return line; + + } + + public static int numResults(Document doc){ + NodeList results; + try { + results = doc.getElementsByTagName("user"); + //Log.d("XMLFunctions", results.toString()); + return results.getLength(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return 0; + } + + public static String getValue(Element item, String str) { + NodeList n = item.getElementsByTagName(str); + return XMLfunctions.getElementValue(n.item(0)); + } +}