Android Open Source - openhds-tablet Selection Filter Fragment






From Project

Back to project page openhds-tablet.

License

The source code is released under:

OPENHDS PLATFORM OPENSOURCE LICENSE AGREEMENT Copyright (c) 2013 University of Southern Maine. All rights reserved. Redistribution and use in source and binary forms, with or without mo...

If you think the Android project openhds-tablet 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.openhds.mobile.fragment;
/*from ww w  .  j a v  a  2  s . co  m*/
import org.openhds.mobile.R;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;

public class SelectionFilterFragment extends Fragment implements OnClickListener {

    public interface Listener {
        void onSeeListHierarchy1();

        void onSeeListHierarchy2(String region);

        void onSeeListHierarchy3(String hierarchyExtId);

        void onSeeListHierarchy4(String subregion);

        void onSeeListLocation(String village);

        void onSearch(String location, String firstName, String lastName, String gender);
    }

    // keep track of the original values - these may be set by an activity
    // these will be used if user presses the 'clear' button
    private String hierarchy1 = "";
    private String hierarchy2 = "";
    private String hierarchy3 = "";
    private String hierarchy4 = "";
    private String location = "";

    private Button hierarchy1Btn, hierarchy2Btn, hierarchy3Btn, hierarchy4Btn, locationBtn;
    private TextView hierarchy1Txt, hierarchy2Txt, hierarchy3Txt, hierarchy4Txt, locationTxt, firstNameTxt,
            lastNameTxt;
    private RadioButton maleBtn, femaleBtn;
    private Button clearBtn, searchBtn;
    private Listener listener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.selection_filter, container, false);

        hierarchy1Btn = (Button) view.findViewById(R.id.hierarchy1_see_list);
        hierarchy1Btn.setOnClickListener(this);

        hierarchy2Btn = (Button) view.findViewById(R.id.hierarchy2_see_list);
        hierarchy2Btn.setOnClickListener(this);

        hierarchy3Btn = (Button) view.findViewById(R.id.hierarchy3_see_list);
        hierarchy3Btn.setOnClickListener(this);

        hierarchy4Btn = (Button) view.findViewById(R.id.hierarchy4_see_list);
        hierarchy4Btn.setOnClickListener(this);

        locationBtn = (Button) view.findViewById(R.id.location_see_list);
        locationBtn.setOnClickListener(this);
        

        clearBtn = (Button) view.findViewById(R.id.clearFilterBtn);
        clearBtn.setOnClickListener(this);

        searchBtn = (Button) view.findViewById(R.id.searchFilterBtn);
        searchBtn.setOnClickListener(this);

        hierarchy1Txt = (TextView) view.findViewById(R.id.hierarchy1Txt);
        hierarchy2Txt = (TextView) view.findViewById(R.id.hierarchy2Txt);
        hierarchy3Txt = (TextView) view.findViewById(R.id.hierarchy3Txt);
        hierarchy4Txt = (TextView) view.findViewById(R.id.hierarchy4Txt);
        locationTxt = (TextView) view.findViewById(R.id.locationTxt);
        firstNameTxt = (TextView) view.findViewById(R.id.firstNameTxt);
        lastNameTxt = (TextView) view.findViewById(R.id.lastNameTxt);

        maleBtn = (RadioButton) view.findViewById(R.id.maleBtn);
        femaleBtn = (RadioButton) view.findViewById(R.id.femaleBtn);

        return view;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        try {
            listener = (Listener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException("The activity must implement the " + Listener.class.getName() + " interface");
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.hierarchy1_see_list:
            listener.onSeeListHierarchy1();
            break;
        case R.id.hierarchy2_see_list:
            listener.onSeeListHierarchy2(hierarchy1Txt.getText().toString());
            break;
        case R.id.hierarchy3_see_list:
            listener.onSeeListHierarchy3(hierarchy2Txt.getText().toString());
            break;
        case R.id.hierarchy4_see_list:
            listener.onSeeListHierarchy4(hierarchy3Txt.getText().toString());
            break;
        case R.id.location_see_list:
            listener.onSeeListLocation(hierarchy4Txt.getText().toString());
            break;
        case R.id.searchFilterBtn:
            String gender = "";
            String loc = "";
            loc = locationTxt.getText().toString();
            if (maleBtn.isChecked() || femaleBtn.isChecked()) {
                gender = maleBtn.isChecked() ? "M" : "F";
            }
            listener.onSearch(loc, firstNameTxt.getText().toString(), lastNameTxt
                    .getText().toString(), gender);
            break;
        case R.id.clearFilterBtn:
            clear();
            break;
        }
    }

    private void clear() {
        hierarchy1Txt.setText(hierarchy1);
        hierarchy2Txt.setText(hierarchy2);
        hierarchy3Txt.setText(hierarchy3);
        hierarchy4Txt.setText(hierarchy4);
        locationTxt.setText(location);

        firstNameTxt.setText("");
        lastNameTxt.setText("");
        maleBtn.setChecked(false);
        femaleBtn.setChecked(false);
    }

    public void setHierarchy1(String region) {
        this.hierarchy1 = region;
        updateHierarchy1Text(region);
    }

    public void setHierarchy2(String subregion) {
        this.hierarchy2 = subregion;
        updateHierarchy2Text(subregion);
    }
    
    public void setHierarchy3(String hierarchy) {
        this.hierarchy3 = hierarchy;
        hierarchy3Txt.setText(hierarchy);
    }

    public void setHierarchy4(String village) {
        this.hierarchy4 = village;
        updateHierarchy4Text(village);
    }

    public void setLocation(String location) {
        this.location = location;
        updateLocationText(location);
    }

    public void updateHierarchy1Text(String text) {
        hierarchy1Txt.setText(text);
    }

    public void updateHierarchy2Text(String text) {
        hierarchy2Txt.setText(text);
    }

    public void updateHierarchy3Text(String text) {
        hierarchy3Txt.setText(text);
    }    
    
    public void updateHierarchy4Text(String text) {
        hierarchy4Txt.setText(text);
    }

    public void updateLocationText(String text) {
        locationTxt.setText(text);
    }
}




Java Source Code List

org.openhds.mobile.BadXmlException.java
org.openhds.mobile.Converter.java
org.openhds.mobile.FieldWorkerProvider.java
org.openhds.mobile.FormsProviderAPI.java
org.openhds.mobile.InstanceProviderAPI.java
org.openhds.mobile.OpenHDS.java
org.openhds.mobile.Queries.java
org.openhds.mobile.activity.AbstractActivity.java
org.openhds.mobile.activity.FieldWorkerLoginActivity.java
org.openhds.mobile.activity.FilterActivity.java
org.openhds.mobile.activity.FilterFormActivity.java
org.openhds.mobile.activity.FilterLocationActivity.java
org.openhds.mobile.activity.FilterVisitActivity.java
org.openhds.mobile.activity.FormListActivity.java
org.openhds.mobile.activity.FormViewActivity.java
org.openhds.mobile.activity.OpeningActivity.java
org.openhds.mobile.activity.ServerPreferencesActivity.java
org.openhds.mobile.activity.ShowMapActivity.java
org.openhds.mobile.activity.SupervisorLoginActivity.java
org.openhds.mobile.activity.SupervisorMainActivity.java
org.openhds.mobile.activity.SyncDatabaseActivity.java
org.openhds.mobile.activity.UpdateActivity.java
org.openhds.mobile.adapter.AdapterContent.java
org.openhds.mobile.adapter.MapAdapter.java
org.openhds.mobile.database.DatabaseAdapter.java
org.openhds.mobile.database.DeathUpdate.java
org.openhds.mobile.database.ExternalInMigrationUpdate.java
org.openhds.mobile.database.HouseholdUpdate.java
org.openhds.mobile.database.InternalInMigrationUpdate.java
org.openhds.mobile.database.LocationUpdate.java
org.openhds.mobile.database.MembershipUpdate.java
org.openhds.mobile.database.OutMigrationUpdate.java
org.openhds.mobile.database.PregnancyOutcomeUpdate.java
org.openhds.mobile.database.RelationshipUpdate.java
org.openhds.mobile.database.Updatable.java
org.openhds.mobile.database.VisitUpdate.java
org.openhds.mobile.fragment.EventFragment.java
org.openhds.mobile.fragment.ProgressFragment.java
org.openhds.mobile.fragment.SelectionFilterFragment.java
org.openhds.mobile.fragment.SelectionFilterLocFragment.java
org.openhds.mobile.fragment.SelectionFormFragment.java
org.openhds.mobile.fragment.SelectionFragment.java
org.openhds.mobile.fragment.ValueFormFragment.java
org.openhds.mobile.fragment.ValueFragment.java
org.openhds.mobile.fragment.ValueLocFragment.java
org.openhds.mobile.listener.CollectEntitiesListener.java
org.openhds.mobile.listener.OdkFormLoadListener.java
org.openhds.mobile.listener.RetrieveFieldWorkersListener.java
org.openhds.mobile.listener.TaskCompleteListener.java
org.openhds.mobile.listener.ValueSelectedListener.java
org.openhds.mobile.model.Child.java
org.openhds.mobile.model.FieldWorker.java
org.openhds.mobile.model.FilledForm.java
org.openhds.mobile.model.FilledParams.java
org.openhds.mobile.model.FormFiller.java
org.openhds.mobile.model.FormSubmissionRecord.java
org.openhds.mobile.model.FormXmlReader.java
org.openhds.mobile.model.Form.java
org.openhds.mobile.model.HierarchySelection.java
org.openhds.mobile.model.Individual.java
org.openhds.mobile.model.LocationHierarchy.java
org.openhds.mobile.model.LocationVisit.java
org.openhds.mobile.model.Location.java
org.openhds.mobile.model.Membership.java
org.openhds.mobile.model.PregnancyObservationUpdate.java
org.openhds.mobile.model.PregnancyOutcome.java
org.openhds.mobile.model.Relationship.java
org.openhds.mobile.model.Result.java
org.openhds.mobile.model.Round.java
org.openhds.mobile.model.SocialGroup.java
org.openhds.mobile.model.StateMachine.java
org.openhds.mobile.model.Supervisor.java
org.openhds.mobile.model.UpdateEvent.java
org.openhds.mobile.model.UpdateParams.java
org.openhds.mobile.model.UpdateStatus.java
org.openhds.mobile.model.Visit.java
org.openhds.mobile.provider.OpenHDSProvider.java
org.openhds.mobile.task.AbstractHttpTask.java
org.openhds.mobile.task.AuthenticateTask.java
org.openhds.mobile.task.DownloadFormsTask.java
org.openhds.mobile.task.FieldWorkerLoginTask.java
org.openhds.mobile.task.OdkFormLoadTask.java
org.openhds.mobile.task.OdkGeneratedFormLoadTask.java
org.openhds.mobile.task.SupervisorLoginTask.java
org.openhds.mobile.task.SyncEntitiesTask.java
org.openhds.mobile.task.SyncFormsTask.java
org.openhds.mobile.utilities.L.java
org.openhds.mobile.utilities.Logg.java
org.openhds.mobile.utilities.UrlUtils.java