Exemplo n.º 1
0
 private void handleActivityNotFound(String fileType) {
   if (fileType.startsWith(FileMetadata.FILE_TYPE_AUDIO)) {
     searchMarket(
         "com.clov4r.android.nil",
         R.string.search_market_audio_title,
         R.string.search_market_audio); // $NON-NLS-1$
   } else if (fileType.equals(FileMetadata.FILE_TYPE_PDF)) {
     searchMarket(
         "com.adobe.reader",
         R.string.search_market_pdf_title,
         R.string.search_market_pdf); // $NON-NLS-1$
   } else if (AndroidUtilities.indexOf(FileMetadata.MS_FILETYPES, fileType) >= 0) {
     searchMarket(
         "com.dataviz.docstogo",
         R.string.search_market_ms_title,
         R.string.search_market_ms); // $NON-NLS-1$
   } else {
     DialogUtilities.okDialog(
         activity,
         activity.getString(R.string.file_type_unhandled_title),
         0,
         activity.getString(R.string.file_type_unhandled),
         null);
   }
 }
Exemplo n.º 2
0
  /**
   * Deal with a synchronization exception. If requested, will show an error to the user (unless
   * synchronization is happening in background)
   *
   * @param context
   * @param tag error tag
   * @param e exception
   * @param showError whether to display a dialog
   */
  protected void handleException(String tag, Exception e, boolean displayError) {
    // TODO: When Crittercism supports it, report error to them
    final Context context = ContextManager.getContext();
    getUtilities().setLastError(e.toString());

    String message = null;

    // occurs when application was closed
    if (e instanceof IllegalStateException) {
      exceptionService.reportError(tag + "-caught", e); // $NON-NLS-1$
    }

    // occurs when network error
    else if (e instanceof IOException) {
      exceptionService.reportError(tag + "-io", e); // $NON-NLS-1$
      message = context.getString(R.string.SyP_ioerror);
    }

    // unhandled error
    else {
      message = context.getString(R.string.DLG_error, e.toString());
      exceptionService.reportError(tag + "-unhandled", e); // $NON-NLS-1$
    }

    if (displayError && context instanceof Activity && message != null) {
      DialogUtilities.okDialog((Activity) context, message, null);
    }
  }
Exemplo n.º 3
0
 public static void handleSQLiteError(Context context, final SQLiteException e) {
   if (context instanceof Activity) {
     Activity activity = (Activity) context;
     DialogUtilities.okDialog(
         activity,
         activity.getString(R.string.DB_corrupted_title),
         0,
         activity.getString(R.string.DB_corrupted_body));
   }
   e.printStackTrace();
 }
Exemplo n.º 4
0
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setTheme(android.R.style.Theme_Dialog);

      tag = getIntent().getStringExtra(TAG);
      if (tag == null) {
        finish();
        return;
      }
      DependencyInjectionService.getInstance().inject(this);

      TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT);
      if (tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0) {
        DialogUtilities.okDialog(
            this, getString(R.string.actfm_tag_operation_disabled), getCancelListener());
        return;
      }
      showDialog();
    }
Exemplo n.º 5
0
  private void onVoiceInputStatusChanged(final Preference preference, boolean newValue) {
    if (!newValue) return;

    final Resources r = getResources();
    if (!VoiceRecognizer.voiceInputAvailable(this)) {
      if (AndroidUtilities.getSdkVersion() > 6) {
        DialogUtilities.okCancelDialog(
            this,
            r.getString(R.string.EPr_voiceInputInstall_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                voiceInputAssistant.showVoiceInputMarketSearch(
                    new OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog1, int which1) {
                        ((CheckBoxPreference) preference).setChecked(false);
                      }
                    });
              }
            },
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      } else {
        DialogUtilities.okDialog(
            this,
            r.getString(R.string.EPr_voiceInputUnavailable_dlg),
            new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog1, int which1) {
                ((CheckBoxPreference) preference).setChecked(false);
              }
            });
      }
    }
  }
Exemplo n.º 6
0
  public void showVoiceInputMarketSearch(DialogInterface.OnClickListener onFail) {
    String packageName;
    if (AndroidUtilities.getSdkVersion() <= 7) {
      packageName = "com.google.android.voicesearch.x";
    } else {
      packageName = "com.google.android.voicesearch";
    }

    // User wants to install voice search, take them to the market
    Intent marketIntent = Constants.MARKET_STRATEGY.generateMarketLink(packageName);
    if (activity != null) {
      try {
        if (marketIntent == null) {
          throw new ActivityNotFoundException("No market link supplied"); // $NON-NLS-1$
        }
        activity.startActivity(marketIntent);
      } catch (ActivityNotFoundException ane) {
        DialogUtilities.okDialog(
            activity, activity.getString(R.string.EPr_marketUnavailable_dlg), onFail);
      }
    }
  }
Exemplo n.º 7
0
  /**
   * Save sharing settings
   *
   * @param toast toast to show after saving is finished
   * @return false if login is required & save should be halted
   */
  @SuppressWarnings("nls")
  public boolean saveSharingSettings(String toast) {
    if (task == null) return false;

    saveToast = toast;
    boolean dirty = false;
    try {
      JSONObject userJson = null;
      TextView assignedView = null;
      if (assignedCustom.getVisibility() == View.VISIBLE) {
        userJson = PeopleContainer.createUserJson(assignedCustom);
        assignedView = assignedCustom;
      } else if (assignedSpinner.getSelectedItem() != null) {
        userJson = ((AssignedToUser) assignedSpinner.getSelectedItem()).user;
      }

      if (userJson != null && userJson.optString("email").indexOf('@') == -1) {
        throw new ParseSharedException(
            assignedView,
            activity.getString(R.string.actfm_EPA_invalid_email, userJson.optString("email")));
      }

      if (userJson == null || userJson.optLong("id", -1) == 0) {
        dirty = task.getValue(Task.USER_ID) == 0L ? dirty : true;
        task.setValue(Task.USER_ID, 0L);
        if (!TextUtils.isEmpty(task.getValue(Task.USER))) task.setValue(Task.USER, "{}");
      } else {
        String user = userJson.toString();

        long taskUserId = -1;
        String taskUserEmail = "";
        try {
          JSONObject taskUser = new JSONObject(task.getValue(Task.USER));
          taskUserId = taskUser.optLong("id", -1);
          taskUserEmail = taskUser.optString("email");
        } catch (JSONException e) {
          // sad times
        }
        long userId = userJson.optLong("id", -1);
        String userEmail = userJson.optString("email");

        boolean match = (userId == taskUserId && userId != -1);
        match = match || (userEmail.equals(taskUserEmail) && !TextUtils.isEmpty(userEmail));

        dirty = match ? dirty : true;
        task.setValue(Task.USER_ID, userJson.optLong("id", -1));
        task.setValue(Task.USER, user);
      }

      JSONObject sharedWith = parseSharedWithAndTags();
      dirty = dirty || sharedWith.has("p");
      if (!TextUtils.isEmpty(task.getValue(Task.SHARED_WITH)) || sharedWith.length() != 0)
        task.setValue(Task.SHARED_WITH, sharedWith.toString());

      if (dirty) taskService.save(task);

      if (dirty && !actFmPreferenceService.isLoggedIn()) {
        activity.startActivityForResult(
            new Intent(activity, ActFmLoginActivity.class), loginRequestCode);
        return false;
      }

      if (dirty) shareTask(sharedWith);
      else showSaveToast();

      return true;
    } catch (JSONException e) {
      exceptionService.displayAndReportError(activity, "save-people", e);
    } catch (ParseSharedException e) {
      if (e.view != null) {
        e.view.setTextColor(Color.RED);
        e.view.requestFocus();
      }
      DialogUtilities.okDialog(activity, e.message, null);
    }
    return false;
  }