Android Open Source - socialcde4android Services Adapter






From Project

Back to project page socialcde4android.

License

The source code is released under:

MIT License

If you think the Android project socialcde4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.uniba.socialcde4android.adapters;
/*  ww w  .j  a va  2s  .  c  om*/
import java.util.Locale;

import com.nostra13.universalimageloader.core.ImageLoader;

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.TextView;

import it.uniba.socialcde4android.R;
import it.uniba.socialcde4android.shared.library.WService;
import it.uniba.socialcde4android.shared.library.WUser;


public class ServicesAdapter extends ArrayAdapter<WService>{

  private Context context;
   private int num_service;
  private static final int TYPE_MAX_COUNT = 5;
  public static final int TYPE_AVATAR = 0;
  public static final int TYPE_TITLE = 1;
  public static final int TYPE_SERVICE = 2;
  public static final int TYPE_TITLE_SETTING = 3;
  public static final int TYPE_SETTING = 4;

  private LayoutInflater infalInflater;
  private String name;
  private String avatar_address;
  private int post;
  private int following;
  private int followers;
  private String proxy;
  private static final String[] SETTINGS = { "Choose Avatar", "Change Password", "Exit"};
  //save an image without spaces in the name and all lowercase
  private ImageLoader imageloader;



  public ServicesAdapter(Context context, int resource, WService[] wservice, WUser wuser, String proxy_string ) {
    super(context, resource, wservice);

    this.context = context;
    num_service = wservice.length;
    name = wuser.getUsername();
    avatar_address = wuser.getAvatar();
    post = wuser.getStatuses();
    following = wuser.getFollowings();
    followers = wuser.getFollowers();
    this.proxy = proxy_string;

    infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageloader = ConfiguratedImageLoader.getImageLoader(context);

  }

  public int getCount() {
    return num_service+3+SETTINGS.length;
  }
  
  
  
  @Override
  public int getViewTypeCount() {
    return TYPE_MAX_COUNT;
  }

  
  
//  public int getServiceTypeID(){
//    return TYPE_SERVICE;
//  }
  
  @Override
  public int getItemViewType(int position) {
    if (position == 0) return TYPE_AVATAR;
    else if (position == 1) return TYPE_TITLE;
    else if (position <= 1+this.num_service)return TYPE_SERVICE;
    else if (position == 2+this.num_service ) return this.TYPE_TITLE_SETTING;
    else return this.TYPE_SETTING;
  }

  

  
  @Override
  public View getView(int position, View rowView, ViewGroup parent) 
  {
    
    int type = getItemViewType(position);
    
      switch (type) {
      case TYPE_AVATAR:
        if (rowView == null)   rowView = infalInflater.inflate(R.layout.drawer_avatar_item, null);
        TextView textViewAvatar = (TextView) rowView.findViewById(R.id.textViewdrawerAVATAR);
        textViewAvatar.setText(name);
        ImageView imageviewAvatar = (ImageView) rowView.findViewById(R.id.imageViewdrawerAVATAR); 
        if (avatar_address != null){
          imageloader.displayImage(avatar_address, imageviewAvatar);

        }
        TextView textViewAvatarPost = (TextView) rowView.findViewById(R.id.textViewAvatarPost);
        textViewAvatarPost.setText("Posts: "+post);
        TextView textViewAvatarFollowing = (TextView) rowView.findViewById(R.id.textViewAvatarFollowing);
        textViewAvatarFollowing.setText("Following: "+following);
        TextView textViewAvatarFollowers = (TextView) rowView.findViewById(R.id.textViewAvatarFollwers);
        textViewAvatarFollowers.setText("Followers: "+followers);
        break;

//      case TYPE_LOGOUT:
//        if (rowView == null)   rowView = infalInflater.inflate(R.layout.logout_item, null);
//        break;
        

      case TYPE_TITLE_SETTING:
        if (rowView == null)   rowView = infalInflater.inflate(R.layout.drawer_settings_title, null);
        break;

      case TYPE_SERVICE:
        WService wservice = (WService) ServicesAdapter.this.getItem(position-2);
        if (rowView == null)   rowView = infalInflater.inflate(R.layout.drawer_item, null);
        TextView textViewService = (TextView) rowView.findViewById(R.id.textViewdrawer);
        textViewService.setText(wservice.getName());
        ImageView imageviewStatusDot = (ImageView) rowView.findViewById(R.id.imageViewStausDot); 
        if (wservice.isRegistered()){
          imageviewStatusDot.setImageResource(getContext().getResources().getIdentifier("it.uniba.socialcde4android:drawable/"+"greendot",null,null));
        }else{
          imageviewStatusDot.setImageResource(getContext().getResources().getIdentifier("it.uniba.socialcde4android:drawable/"+"greydot",null,null));
        }
        ImageView imageviewService = (ImageView) rowView.findViewById(R.id.imageViewdrawer); 
        imageloader.displayImage(proxy+wservice.getImage(), imageviewService);


        break;
      case TYPE_TITLE:
        if (rowView == null)   rowView = infalInflater.inflate(R.layout.drawer_services_title, null);
        break;
        
      case TYPE_SETTING:
        String setting_name = SETTINGS[position - 3 - this.num_service];
        if (rowView == null)   rowView = infalInflater.inflate(R.layout.drawer_settings_item, null);

        TextView textViewSettings = (TextView) rowView.findViewById(R.id.textViewdrawerSetting);
        textViewSettings.setText(setting_name);
        
        ImageView imageviewSettins = (ImageView) rowView.findViewById(R.id.imageViewdrawerSetting); 
        String imagename = setting_name.toLowerCase(Locale.ENGLISH).replaceAll("\\s","");
        Log.i("adapter",imagename);
        imageviewSettins.setImageResource(getContext().getResources()
            .getIdentifier("it.uniba.socialcde4android:drawable/"+imagename,null,null));

      }

    

  
    return rowView;
  }
}




Java Source Code List

it.uniba.socialcde4android.activity.HomeActivity.java
it.uniba.socialcde4android.activity.LoginActivity.java
it.uniba.socialcde4android.activity.RegistrationActivity.java
it.uniba.socialcde4android.activity.WebViewActivity.java
it.uniba.socialcde4android.adapters.ConfiguratedImageLoader.java
it.uniba.socialcde4android.adapters.FeaturesAdapter.java
it.uniba.socialcde4android.adapters.ServicesAdapter.java
it.uniba.socialcde4android.adapters.SquareImageView.java
it.uniba.socialcde4android.adapters.TimeLineAdapter.java
it.uniba.socialcde4android.adapters.UserAvatarsAdapter.java
it.uniba.socialcde4android.adapters.UsersAdapter.java
it.uniba.socialcde4android.config.Config.java
it.uniba.socialcde4android.costants.Consts.java
it.uniba.socialcde4android.costants.Error_consts.java
it.uniba.socialcde4android.costants.Services_id.java
it.uniba.socialcde4android.data.operation.Authorize_Operation.java
it.uniba.socialcde4android.data.operation.ChangePasswordWithPassword_Operation.java
it.uniba.socialcde4android.data.operation.GetAvailableAvatars_Operation.java
it.uniba.socialcde4android.data.operation.GetColleagueProfile_Operation.java
it.uniba.socialcde4android.data.operation.GetFeatures_Operation.java
it.uniba.socialcde4android.data.operation.GetFriends_Operation.java
it.uniba.socialcde4android.data.operation.GetHideSettings_Operation.java
it.uniba.socialcde4android.data.operation.GetOAuthData_Operation.java
it.uniba.socialcde4android.data.operation.GetUser_Operation.java
it.uniba.socialcde4android.data.operation.IsUsernameAvailable_Operation.java
it.uniba.socialcde4android.data.operation.IsWebServiceRunning_Operation.java
it.uniba.socialcde4android.data.operation.RecordService_Operation.java
it.uniba.socialcde4android.data.operation.RetrieveServices_Operation.java
it.uniba.socialcde4android.data.operation.SendTFSpost_Operation.java
it.uniba.socialcde4android.data.operation.SetActiveFeatures_Operation.java
it.uniba.socialcde4android.data.operation.SetAvatar_Operation.java
it.uniba.socialcde4android.data.operation.SetFollowed_Operation.java
it.uniba.socialcde4android.data.operation.SetHideSettings_Operation.java
it.uniba.socialcde4android.data.operation.SubscribeUser_Operation.java
it.uniba.socialcde4android.data.operation.UnregisterService_Operation.java
it.uniba.socialcde4android.data.requestmanager.SocialCDERequestFactory.java
it.uniba.socialcde4android.data.requestmanager.SocialCDERequestManager.java
it.uniba.socialcde4android.data.service.SocialCDERequestService.java
it.uniba.socialcde4android.dialogs.ChangePasswordDialog.java
it.uniba.socialcde4android.dialogs.ChooseAvatarDialog.java
it.uniba.socialcde4android.dialogs.HideUnhideDialog.java
it.uniba.socialcde4android.dialogs.NoNetworkDialog.java
it.uniba.socialcde4android.dialogs.SetServiceFeaturesDialog.java
it.uniba.socialcde4android.dialogs.TFSAuthDialog.java
it.uniba.socialcde4android.fragments.TimeLine_AbstractFragment.java
it.uniba.socialcde4android.fragments.TimeLine_Fragment.java
it.uniba.socialcde4android.fragments.WUserColleagueProfile_Fragment.java
it.uniba.socialcde4android.fragments.WUserProfile_Fragment.java
it.uniba.socialcde4android.preferences.Preferences.java
it.uniba.socialcde4android.shared.library.JsonDateDeserializer.java
it.uniba.socialcde4android.shared.library.WFeature.java
it.uniba.socialcde4android.shared.library.WHidden.java
it.uniba.socialcde4android.shared.library.WOAuthData.java
it.uniba.socialcde4android.shared.library.WPost.java
it.uniba.socialcde4android.shared.library.WService.java
it.uniba.socialcde4android.shared.library.WUser.java
it.uniba.socialcde4android.utility.ScreenUtility.java