Android Open Source - chat.android Service Other Activity






From Project

Back to project page chat.android.

License

The source code is released under:

GNU General Public License

If you think the Android project chat.android 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 org.chat.android;
/* w w  w.ja v  a  2  s  . co m*/
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.chat.android.models.Service;

import com.j256.ormlite.dao.Dao;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class ServiceOtherActivity extends BaseActivity {
  private int visitId = 0;
  private int hhId = 0;
  private List<Service> servicesList = new ArrayList<Service>();
  List<EditText> entry = new ArrayList<EditText>();
  
    @Override    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Context context = getApplicationContext();
        setContentView(R.layout.activity_service_other);

    Bundle b = getIntent().getExtras();
    visitId = b.getInt("visitId");
    hhId = b.getInt("hhId");
    String role = b.getString("role");
    int tag = b.getInt("serviceTag") - 1;        // "Other"
    
    String[] serviceNames = null;
    serviceNames = getResources().getStringArray(R.array.volunteer_service_type_names);
    TextView typeTitle = (TextView) findViewById(R.id.service_other_title_field);
    typeTitle.setText(serviceNames[tag]);
    
      List<TextView> title = new ArrayList<TextView>();
      title.add((TextView) findViewById(R.id.other_tv_1));
      title.add((TextView) findViewById(R.id.other_tv_2));
      title.add((TextView) findViewById(R.id.other_tv_3));
      title.add((TextView) findViewById(R.id.other_tv_4));
      title.add((TextView) findViewById(R.id.other_tv_5));
      title.add((TextView) findViewById(R.id.other_tv_6));
      title.add((TextView) findViewById(R.id.other_tv_7));
      title.add((TextView) findViewById(R.id.other_tv_8));
      title.add((TextView) findViewById(R.id.other_tv_9));
      title.add((TextView) findViewById(R.id.other_tv_10));

      entry.add((EditText) findViewById(R.id.other_et_1));
      entry.add((EditText) findViewById(R.id.other_et_2));
      entry.add((EditText) findViewById(R.id.other_et_3));
      entry.add((EditText) findViewById(R.id.other_et_4));
      entry.add((EditText) findViewById(R.id.other_et_5));
      entry.add((EditText) findViewById(R.id.other_et_6));
      entry.add((EditText) findViewById(R.id.other_et_7));
      entry.add((EditText) findViewById(R.id.other_et_8));
      entry.add((EditText) findViewById(R.id.other_et_9));
      entry.add((EditText) findViewById(R.id.other_et_10));
    
    // grab list of services to show, based on the service subtype - subtype should always be "Other"
    populateServicesList(role, "Other");
    
    // determine language from current tablet settings
    String lang = Locale.getDefault().getLanguage();
    
    // for each service in the serviceList, set up the tv and et UI elements 
    for (int i = 0; i < servicesList.size(); i++) {
      title.get(i).setText(servicesList.get(i).getName(lang));
      title.get(i).setVisibility(View.VISIBLE);
      entry.get(i).setHint(servicesList.get(i).getInstructions());
      entry.get(i).setTag(servicesList.get(i).getName("en"));
      entry.get(i).setVisibility(View.VISIBLE);
    }       
    }
    
    // used to generate the list of services for serviceDelivery
    private void populateServicesList(String role, String type) {
      List<Service> allServices = new ArrayList<Service>();
        try {
          Dao<Service, Integer> sDao = getHelper().getServicesDao();
      allServices = sDao.query(sDao.queryBuilder().prepare());
          for (Service s : allServices) {
          if (s.getRole().equals(role) && s.getType().equals(type)) {
            servicesList.add(s);
          }
          }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }        
    }
    
    public void selectServiceTargets(View v) {
      ArrayList<String> sNames = new ArrayList<String>();
      ArrayList<String> sAdInfo = new ArrayList<String>();
      // if entry box is visible and is not empty, add the service name to the array
      for (EditText et : entry) {
        if (et.getVisibility() == View.VISIBLE && et.getText().toString().trim().length() != 0) {
          sNames.add(et.getTag().toString());
          sAdInfo.add(et.getText().toString());
        }
      }
      
      // design has changed to only allow one service at a time to be committed. This is a mistake, and they'll figure that out eventually.
      // In the mean time, this is a yucky way of limiting this to one service (while still playing nice with serviceDeliveryActivity's current setup)
      if (sNames.size() > 1) {
        BaseActivity.toastHelper(this, "Please only fill in one service at a time");
      } else {
        Intent i = new Intent(ServiceOtherActivity.this, ServiceDeliveryActivity.class);
          Bundle b = new Bundle();
          b.putInt("visitId",visitId);
          b.putInt("hhId",hhId);
          //b.putStringArrayList("serviceNames", sNames);
          b.putString("serviceName",sNames.get(0));
          b.putBoolean("adInfoFlag",true);
          //b.putStringArrayList("serviceAdInfo", sAdInfo);
          b.putString("serviceAdInfo", sAdInfo.get(0));
          i.putExtras(b);
          startActivity(i);
      }
    }
    
    
}




Java Source Code List

org.chat.android.BaseActivity.java
org.chat.android.CHADelivery.java
org.chat.android.CHAOverviewActivity.java
org.chat.android.CHASelectChildActivity.java
org.chat.android.CHASelectChildAdapter.java
org.chat.android.ChatUtil.java
org.chat.android.ClientsAdapter.java
org.chat.android.DatabaseHelper.java
org.chat.android.GPSTracker.java
org.chat.android.HealthDeliveryActivity.java
org.chat.android.HealthDetailsActivity.java
org.chat.android.HealthOverviewActivity.java
org.chat.android.HealthOverviewRecordActivity.java
org.chat.android.HomeActivity.java
org.chat.android.ImmunizationsReceivedActivity.java
org.chat.android.ImmunizationsSummaryActivity.java
org.chat.android.LoginActivity.java
org.chat.android.Mail.java
org.chat.android.ModelHelper.java
org.chat.android.MyApplication.java
org.chat.android.ResourcesActivity.java
org.chat.android.RestoreVisitActivity.java
org.chat.android.ServiceDeliveryActivity.java
org.chat.android.ServiceDeliveryAdapter.java
org.chat.android.ServiceDetailsActivity.java
org.chat.android.ServiceOtherActivity.java
org.chat.android.ServiceOverviewActivity.java
org.chat.android.ServicesAdapter.java
org.chat.android.SetupDB.java
org.chat.android.SetupVisitActivity.java
org.chat.android.SyncResourcesActivity.java
org.chat.android.Auth.AccountGeneral.java
org.chat.android.Auth.AuthenticatorService.java
org.chat.android.Auth.Authenticator.java
org.chat.android.Auth.ChatAuthServerAuthenticate.java
org.chat.android.Auth.MainActivity.java
org.chat.android.Auth.ServerAuthenticate.java
org.chat.android.Sync.StubProvider.java
org.chat.android.Sync.SyncAdapter.java
org.chat.android.Sync.SyncService.java
org.chat.android.Sync.provider.ChatContentProvider.java
org.chat.android.models.Attendance.java
org.chat.android.models.CHAAccessed.java
org.chat.android.models.Client.java
org.chat.android.models.HealthPage.java
org.chat.android.models.HealthSelectRecorded.java
org.chat.android.models.HealthSelect.java
org.chat.android.models.HealthTheme.java
org.chat.android.models.HealthTopicAccessed.java
org.chat.android.models.HealthTopic.java
org.chat.android.models.Household.java
org.chat.android.models.PageAssessment1.java
org.chat.android.models.PageSelect1.java
org.chat.android.models.PageText1.java
org.chat.android.models.PageVideo1.java
org.chat.android.models.ResourceAccessed.java
org.chat.android.models.Resource.java
org.chat.android.models.Role.java
org.chat.android.models.ServiceAccessed.java
org.chat.android.models.Service.java
org.chat.android.models.TopicVideo.java
org.chat.android.models.Util.java
org.chat.android.models.VaccineRecorded.java
org.chat.android.models.Vaccine.java
org.chat.android.models.VideoAccessed.java
org.chat.android.models.Video.java
org.chat.android.models.Visit.java
org.chat.android.models.Worker.java
org.chat.android.pages.Assessment1Fragment.java
org.chat.android.pages.BaseFragment.java
org.chat.android.pages.ReferralFragment.java
org.chat.android.pages.Select1Fragment.java
org.chat.android.pages.Text1Fragment.java
org.chat.android.pages.Video1Fragment.java