Android Open Source - openhds-tablet Supervisor Main Activity






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.activity;
/*w w w .j  a v a  2s. c o  m*/
import java.net.URL;

import org.openhds.mobile.R;
import org.openhds.mobile.listener.CollectEntitiesListener;
import org.openhds.mobile.task.AbstractHttpTask.RequestContext;
import org.openhds.mobile.task.DownloadFormsTask;
import org.openhds.mobile.task.SyncFormsTask;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class SupervisorMainActivity extends AbstractActivity implements CollectEntitiesListener {
  
  private ProgressDialog dialog;
    private String url;
    private String username;
    private String password;
  private SharedPreferences settings;


  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.supervisor_main);

    Button downloadBtn = (Button) findViewById(R.id.download_btn);
    downloadBtn.setOnClickListener(new DownloadButtonListener());
    
    Button downloadExtraBtn = (Button) findViewById(R.id.downloadextra_btn);
    downloadExtraBtn.setOnClickListener(new DownloadExtraFormsButtonListener());


    Button viewFormBtn = (Button) findViewById(R.id.view_form_btn);
    viewFormBtn.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
        Intent intent = new Intent(getApplicationContext(),
            FormListActivity.class);
        setUsernameOnIntent(intent);
        startActivity(intent);
      }
    });

    Button logoutBtn = (Button) findViewById(R.id.logout_btn);
    logoutBtn.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        finish();
      }
    });
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.mainmenu, menu);
        super.onCreateOptionsMenu(menu);
        return true;
  }

    /**
     * Defining what happens when a main menu item is selected
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.configure_server:
            createPreferencesMenu();
            return true;
        case R.id.sync_database:
            createSyncDatabaseMenu();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    
    /**
     * Creates the 'Configure Server' option in the action menu.
     */
    private void createPreferencesMenu() {
        Intent i = new Intent(this, ServerPreferencesActivity.class);
        startActivity(i);
    }

    /**
     * Creates the 'Sync Database' option in the action menu.
     */
    private void createSyncDatabaseMenu() {
        Intent i = new Intent(this, SyncDatabaseActivity.class);
        startActivity(i);
    }

    
  private class DownloadButtonListener implements OnClickListener {
    public void onClick(View arg0) {
      dialog = ProgressDialog.show(SupervisorMainActivity.this, getString(R.string.working_lbl), getString(R.string.sprvmain_downlall_forms));
      URL parsedUrl = getServerUrl("/api/form/download");
      if (parsedUrl == null) {
        return;
      }

      RequestContext requestCtx = new RequestContext();
      requestCtx.url(parsedUrl).user(getUsernameFromIntent())
          .password(getPasswordFromIntent());

      DownloadFormsTask task = new DownloadFormsTask(requestCtx,
          new DownloadFormsTask.TaskListener() {
            public void onFailedAuthentication() {
              dialog.dismiss();
              showToastWithText(getString(R.string.sprvmain_failed_auth));
            }

            public void onFailure() {
              dialog.dismiss();
              showToastWithText(getString(R.string.sprvmain_failure));
            }

            public void onConnectionError() {
              dialog.dismiss();
              showToastWithText(getString(R.string.sprvmain_connection_error));
            }

            public void onConnectionTimeout() {
              dialog.dismiss();
              showToastWithText(getString(R.string.sprvmain_connection_timeout));
            }

            public void onSuccess() {
              dialog.dismiss();
              showToastWithText(getString(R.string.sprvmain_on_success));
            }

            public void onNoContent() {
              dialog.dismiss();
              showToastWithText(getString(R.string.sprvmain_no_content));              
            }
          }, getBaseContext());
      task.execute();
    }
  }
    
  private class DownloadExtraFormsButtonListener implements OnClickListener {
    public void onClick(View arg0) {
      dialog = ProgressDialog.show(SupervisorMainActivity.this, getString(R.string.working_lbl), getString(R.string.sprvmain_downl_extraforms));
            settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

      url = settings.getString(ServerPreferencesActivity.OPENHDS_KEY_SERVER, getString(R.string.default_openhdsserver));
      username = settings.getString(ServerPreferencesActivity.OPENHDS_KEY_USERNAME, getString(R.string.username));
      password = settings.getString(ServerPreferencesActivity.OPENHDS_KEY_PASSWORD, getString(R.string.password));
      
      

      SyncFormsTask task = new SyncFormsTask(url, username, password,
          dialog, getBaseContext(), SupervisorMainActivity.this);
      
      
      task.execute();
    }
  }

  public void collectionComplete(Boolean result) {
    if (result) 
      Toast.makeText(getApplicationContext(),  getString(R.string.sync_forms_successful), Toast.LENGTH_LONG).show();
    else 
      Toast.makeText(getApplicationContext(), getString(R.string.sync_forms_failure), Toast.LENGTH_LONG).show();
    dialog.dismiss();    
  }

}




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