Esempio n. 1
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case MENU_PREFERENCES:
       MyStatus.getInstance()
           .getActivityLogger()
           .logAction(this, "onOptionsItemSelected", "MENU_PREFERENCES");
       Intent ig = new Intent(this, PreferencesActivity.class);
       startActivity(ig);
       return true;
     case MENU_ADMIN:
       MyStatus.getInstance()
           .getActivityLogger()
           .logAction(this, "onOptionsItemSelected", "MENU_ADMIN");
       String pw = mAdminPreferences.getString(AdminPreferencesActivity.KEY_ADMIN_PW, "");
       if ("".equalsIgnoreCase(pw)) {
         Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class);
         startActivity(i);
       } else {
         showDialog(PASSWORD_DIALOG);
         MyStatus.getInstance()
             .getActivityLogger()
             .logAction(this, "createAdminPasswordDialog", "show");
       }
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Esempio n. 2
0
 private void createErrorDialog(String errorMsg, final boolean shouldExit) {
   MyStatus.getInstance().getActivityLogger().logAction(this, "createErrorDialog", "show");
   mAlertDialog = new AlertDialog.Builder(this).create();
   mAlertDialog.setIcon(android.R.drawable.ic_dialog_info);
   mAlertDialog.setMessage(errorMsg);
   DialogInterface.OnClickListener errorListener =
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int i) {
           switch (i) {
             case DialogInterface.BUTTON1:
               MyStatus.getInstance()
                   .getActivityLogger()
                   .logAction(this, "createErrorDialog", shouldExit ? "exitApplication" : "OK");
               if (shouldExit) {
                 finish();
               }
               break;
           }
         }
       };
   mAlertDialog.setCancelable(false);
   mAlertDialog.setButton(getString(R.string.ok), errorListener);
   mAlertDialog.show();
 }
Esempio n. 3
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   MyStatus.getInstance().getActivityLogger().logAction(this, "onCreateOptionsMenu", "show");
   super.onCreateOptionsMenu(menu);
   menu.add(0, MENU_PREFERENCES, 0, getString(R.string.general_preferences))
       .setIcon(android.R.drawable.ic_menu_preferences);
   menu.add(0, MENU_ADMIN, 0, getString(R.string.admin_preferences))
       .setIcon(R.drawable.ic_menu_login);
   return true;
 }
Esempio n. 4
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. 5
0
  /** Stores the path of selected form and finishes. */
  @Override
  protected void onListItemClick(ListView listView, View view, int position, long id) {
    // get uri to form
    long idFormsTable = ((SimpleCursorAdapter) getListAdapter()).getItemId(position);
    Uri formUri = ContentUris.withAppendedId(FormsColumns.CONTENT_URI, idFormsTable);

    MyStatus.getInstance()
        .getActivityLogger()
        .logAction(this, "onListItemClick", formUri.toString());

    String action = getIntent().getAction();
    if (Intent.ACTION_PICK.equals(action)) {
      // caller is waiting on a picked form
      setResult(RESULT_OK, new Intent().setData(formUri));
    } else {
      // caller wants to view/edit a form, so launch formentryactivity
      startActivity(new Intent(Intent.ACTION_EDIT, formUri, this, FormEntryActivity.class));
    }

    finish();
  }
Esempio n. 6
0
 @Override
 protected void onStop() {
   MyStatus.getInstance().getActivityLogger().logOnStop(this);
   super.onStop();
 }
Esempio n. 7
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();
  }