Esempio n. 1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // must be at the beginning of any activity that can be called from an external intent
    try {
      MyStatus.createODKDirs();
    } catch (RuntimeException e) {
      createErrorDialog(e.getMessage(), EXIT);
      return;
    }

    setContentView(R.layout.chooser_list_layout);
    setTitle(getString(R.string.app_name) + " > " + getString(R.string.enter_data));

    String sortOrder = FormsColumns.DISPLAY_NAME + " ASC, " + FormsColumns.JR_VERSION + " DESC";
    Cursor c = managedQuery(FormsColumns.CONTENT_URI, null, null, null, sortOrder);

    String[] data =
        new String[] {
          FormsColumns.DISPLAY_NAME, FormsColumns.DISPLAY_SUBTEXT, FormsColumns.JR_VERSION
        };
    int[] view = new int[] {R.id.text1, R.id.text2, R.id.text3};

    // render total instance view
    SimpleCursorAdapter instances =
        new VersionHidingCursorAdapter(
            FormsColumns.JR_VERSION, this, R.layout.two_item, c, data, view);
    setListAdapter(instances);

    if (savedInstanceState != null && savedInstanceState.containsKey(syncMsgKey)) {
      TextView tv = (TextView) findViewById(R.id.status_text);
      tv.setText(savedInstanceState.getString(syncMsgKey));
    }

    // DiskSyncTask checks the disk for any forms not already in the content provider
    // that is, put here by dragging and dropping onto the SDCard
    mDiskSyncTask = (DiskSyncTask) getLastNonConfigurationInstance();
    if (mDiskSyncTask == null) {
      Log.i(t, "Starting new disk sync task");
      mDiskSyncTask = new DiskSyncTask();
      mDiskSyncTask.setDiskSyncListener(this);
      mDiskSyncTask.execute((Void[]) null);
    }
  }
Esempio n. 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // must be at the beginning of any activity that can be called from an
    // external intent
    Log.i(t, "Starting up, creating directories");
    try {
      MyStatus.createODKDirs();
    } catch (RuntimeException e) {
      createErrorDialog(e.getMessage(), EXIT);
      return;
    }

    setContentView(R.layout.main_menu);

    {
      // dynamically construct the "ODK Collect vA.B" string
      TextView mainMenuMessageLabel = (TextView) findViewById(R.id.main_menu_header);
      mainMenuMessageLabel.setText(MyStatus.getInstance().getVersionedAppName());
    }

    setTitle(getString(R.string.app_name) + " > " + getString(R.string.main_menu));

    File f = new File(MyStatus.ODK_ROOT + "/collect.settings");
    if (f.exists()) {
      boolean success = loadSharedPreferencesFromFile(f);
      if (success) {
        Toast.makeText(this, "Settings successfully loaded from file", Toast.LENGTH_LONG).show();
        f.delete();
      } else {
        Toast.makeText(
                this,
                "Sorry, settings file is corrupt and should be deleted or replaced",
                Toast.LENGTH_LONG)
            .show();
      }
    }

    mReviewSpacer = findViewById(R.id.review_spacer);
    mGetFormsSpacer = findViewById(R.id.get_forms_spacer);

    mAdminPreferences = this.getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0);

    // enter data button. expects a result.
    mEnterDataButton = (Button) findViewById(R.id.enter_data);
    mEnterDataButton.setText(getString(R.string.enter_data_button));
    mEnterDataButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            MyStatus.getInstance().getActivityLogger().logAction(this, "fillBlankForm", "click");
            Intent i = new Intent(getApplicationContext(), FormChooserList.class);
            startActivity(i);
          }
        });

    // review data button. expects a result.
    mReviewDataButton = (Button) findViewById(R.id.review_data);
    mReviewDataButton.setText(getString(R.string.review_data_button));
    mReviewDataButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            MyStatus.getInstance().getActivityLogger().logAction(this, "editSavedForm", "click");
            Intent i = new Intent(getApplicationContext(), InstanceChooserList.class);
            startActivity(i);
          }
        });

    // send data button. expects a result.
    mSendDataButton = (Button) findViewById(R.id.send_data);
    mSendDataButton.setText(getString(R.string.send_data_button));
    mSendDataButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            MyStatus.getInstance().getActivityLogger().logAction(this, "uploadForms", "click");
            Intent i = new Intent(getApplicationContext(), InstanceUploaderList.class);
            startActivity(i);
          }
        });

    // manage forms button. no result expected.
    mGetFormsButton = (Button) findViewById(R.id.get_forms);
    mGetFormsButton.setText(getString(R.string.get_forms));
    mGetFormsButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            MyStatus.getInstance()
                .getActivityLogger()
                .logAction(this, "downloadBlankForms", "click");
            Intent i = new Intent(getApplicationContext(), FormDownloadList.class);
            startActivity(i);
          }
        });

    // manage forms button. no result expected.
    mManageFilesButton = (Button) findViewById(R.id.manage_forms);
    mManageFilesButton.setText(getString(R.string.manage_files));
    mManageFilesButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            MyStatus.getInstance().getActivityLogger().logAction(this, "deleteSavedForms", "click");
            Intent i = new Intent(getApplicationContext(), FileManagerTabs.class);
            startActivity(i);
          }
        });

    // count for finalized instances
    String selection = InstanceColumns.STATUS + "=? or " + InstanceColumns.STATUS + "=?";
    String selectionArgs[] = {
      InstanceProviderAPI.STATUS_COMPLETE, InstanceProviderAPI.STATUS_SUBMISSION_FAILED
    };

    mFinalizedCursor =
        managedQuery(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null);
    startManagingCursor(mFinalizedCursor);
    mCompletedCount = mFinalizedCursor.getCount();
    mFinalizedCursor.registerContentObserver(mContentObserver);

    // count for finalized instances
    String selectionSaved = InstanceColumns.STATUS + "=?";
    String selectionArgsSaved[] = {InstanceProviderAPI.STATUS_INCOMPLETE};

    mSavedCursor =
        managedQuery(InstanceColumns.CONTENT_URI, null, selectionSaved, selectionArgsSaved, null);
    startManagingCursor(mSavedCursor);
    mSavedCount = mFinalizedCursor.getCount();
    // don't need to set a content observer because it can't change in the
    // background

    updateButtons();
  }