@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
      Log.i(AnkiDroidApp.TAG, "CardBrowser - onBackPressed()");
      if (mSearchEditText.getText().length() == 0
          && !mShowOnlyMarSus
          && mSelectedTags.size() == 0) {
        setResult(RESULT_OK);
        finish();
        if (Integer.valueOf(android.os.Build.VERSION.SDK) > 4) {
          ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.RIGHT);
        }
      } else {
        mSearchEditText.setText("");
        mSearchEditText.setHint(R.string.downloaddeck_search);
        mSelectedTags.clear();
        mCards.clear();
        mCards.addAll(mAllCards);
        updateList();
      }
      return true;
    }

    return super.onKeyDown(keyCode, event);
  }
Esempio n. 2
0
 private void closeCardBrowser(int result) {
   setResult(result);
   finish();
   if (UIUtils.getApiLevel() > 4) {
     ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
   }
 }
Esempio n. 3
0
 private void enableActivityAnimation(int animation) {
   if (animationDisabled()) {
     disableActivityAnimation();
   } else {
     ActivityTransitionAnimation.slide(this, animation);
   }
 }
Esempio n. 4
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case MENU_UNDO:
        // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UNDO, mUndoRedoHandler, new
        // DeckTask.TaskData(0, mDeck, 0,
        // true));
        return true;

      case MENU_ADD_NOTE:
        Intent intent = new Intent(CardBrowser.this, CardEditor.class);
        intent.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_ADD);
        startActivityForResult(intent, ADD_NOTE);
        if (UIUtils.getApiLevel() > 4) {
          ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
        }
        return true;

      case MENU_SHOW_MARKED:
        mShowOnlyMarSus = true;
        mSearchEditText.setHint(R.string.card_browser_show_marked);
        mCards.clear();
        for (int i = 0; i < mAllCards.size(); i++) {
          int flags = Integer.parseInt(mAllCards.get(i).get("flags"));
          if (flags == 2 || flags == 3) {
            mCards.add(mAllCards.get(i));
          }
        }
        updateList();
        return true;

      case MENU_SELECT_SUSPENDED:
        mShowOnlyMarSus = true;
        mSearchEditText.setHint(R.string.card_browser_show_suspended);
        mCards.clear();
        for (int i = 0; i < mAllCards.size(); i++) {
          int flags = Integer.parseInt(mAllCards.get(i).get("flags"));
          if (flags == 1 || flags == 3) {
            mCards.add(mAllCards.get(i));
          }
        }
        updateList();
        return true;

      case MENU_SELECT_TAG:
        showDialog(DIALOG_TAGS);
        return true;

      case MENU_CHANGE_ORDER:
        showDialog(DIALOG_ORDER);
        return true;

      case MENU_FIELD:
        showDialog(DIALOG_FIELD);
        return true;
    }

    return false;
  }
Esempio n. 5
0
 private void closePreferences() {
   finish();
   if (AnkiDroidApp.SDK_VERSION > 4) {
     ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
   }
   if (mCol != null) {
     mCol.save();
   }
 }
Esempio n. 6
0
 private void closeWithResult() {
   if (mPreferenceChanged) {
     setResult(RESULT_OK);
   } else {
     setResult(RESULT_CANCELED);
   }
   finish();
   ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
 }
Esempio n. 7
0
 private void closeFeedback() {
   if (getIntent().getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR) {
     setResult(DeckPicker.RESULT_DB_ERROR);
   } else {
     setResult(RESULT_OK);
   }
   finish();
   if (AnkiDroidApp.SDK_VERSION > 4) {
     ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.LEFT);
   }
 }
Esempio n. 8
0
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
     Log.i(AnkiDroidApp.TAG, "DeckOptions - onBackPressed()");
     finish();
     if (AnkiDroidApp.SDK_VERSION > 4) {
       ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.FADE);
     }
     return true;
   }
   return super.onKeyDown(keyCode, event);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case MENU_UNDO:
       DeckTask.launchDeckTask(
           DeckTask.TASK_TYPE_UNDO, mUndoRedoHandler, new DeckTask.TaskData(0, mDeck, 0, true));
       return true;
     case MENU_REDO:
       DeckTask.launchDeckTask(
           DeckTask.TASK_TYPE_REDO, mUndoRedoHandler, new DeckTask.TaskData(0, mDeck, 0, true));
       return true;
     case MENU_ADD_FACT:
       startActivityForResult(new Intent(CardBrowser.this, FactAdder.class), ADD_FACT);
       if (Integer.valueOf(android.os.Build.VERSION.SDK) > 4) {
         ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
       }
       return true;
     case MENU_SHOW_MARKED:
       mShowOnlyMarSus = true;
       mSearchEditText.setHint(R.string.card_browser_show_marked);
       mCards.clear();
       for (int i = 0; i < mAllCards.size(); i++) {
         if ((mAllCards
                         .get(i)
                         .get("question")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1
                 || mAllCards
                         .get(i)
                         .get("answer")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1)
             && mAllCards.get(i).get("marSus").subSequence(0, 1).equals("1")) {
           mCards.add(mAllCards.get(i));
         }
       }
       updateList();
       return true;
     case MENU_SELECT_SUSPENDED:
       mShowOnlyMarSus = true;
       mSearchEditText.setHint(R.string.card_browser_show_suspended);
       mCards.clear();
       for (int i = 0; i < mAllCards.size(); i++) {
         if ((mAllCards
                         .get(i)
                         .get("question")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1
                 || mAllCards
                         .get(i)
                         .get("answer")
                         .toLowerCase()
                         .indexOf(mSearchEditText.getText().toString().toLowerCase())
                     != -1)
             && mAllCards.get(i).get("marSus").subSequence(1, 2).equals("1")) {
           mCards.add(mAllCards.get(i));
         }
       }
       updateList();
       return true;
     case MENU_SELECT_TAG:
       recreateTagsDialog();
       mTagsDialog.show();
       return true;
     case MENU_CHANGE_ORDER:
       showDialog(DIALOG_ORDER);
       return true;
   }
   return false;
 }
Esempio n. 10
0
 private void disableActivityAnimation() {
   ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.NONE);
 }
Esempio n. 11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    Resources res = getResources();

    Context context = getBaseContext();
    SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context);
    mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK);

    mNonce = UUID.randomUUID().getMostSignificantBits();
    mFeedbackUrl = res.getString(R.string.feedback_post_url);
    mErrorUrl = res.getString(R.string.error_post_url);
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    mPostingFeedback = false;
    initAllAlertDialogs();

    getErrorFiles();
    Intent i = getIntent();
    mAllowFeedback =
        (i.hasExtra("request")
                && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK
                    || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR))
            || mReportErrorMode.equals(REPORT_ASK);
    if (!mAllowFeedback) {
      if (mReportErrorMode.equals(REPORT_ALWAYS)) { // Always report
        try {
          String feedback = "Automatically sent";
          Connection.sendFeedback(
              mSendListener,
              new Payload(
                  new Object[] {
                    mFeedbackUrl, mErrorUrl, feedback, mErrorReports, mNonce, getApplication(), true
                  }));
          if (mErrorReports.size() > 0) {
            mPostingFeedback = true;
          }
          if (feedback.length() > 0) {
            mPostingFeedback = true;
          }
        } catch (Exception e) {
          Log.e(AnkiDroidApp.TAG, e.toString());
        }
        finish();
        if (AnkiDroidApp.SDK_VERSION > 4) {
          ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
        }
        return;
      } else if (mReportErrorMode.equals(REPORT_NEVER)) { // Never report
        deleteFiles(false, false);
        finish();
        if (AnkiDroidApp.SDK_VERSION > 4) {
          ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
        }
        return;
      }
    }

    View mainView = getLayoutInflater().inflate(R.layout.feedback, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer));
    Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList));

    Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
    Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
    Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
    mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText);
    mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList);

    mErrorAdapter =
        new SimpleAdapter(
            this,
            mErrorReports,
            R.layout.error_item,
            new String[] {"name", "state", "result"},
            new int[] {R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status});
    mErrorAdapter.setViewBinder(
        new SimpleAdapter.ViewBinder() {
          @Override
          public boolean setViewValue(View view, Object arg1, String text) {
            switch (view.getId()) {
              case R.id.error_item_progress:
                if (text.equals(STATE_UPLOADING)) {
                  view.setVisibility(View.VISIBLE);
                } else {
                  view.setVisibility(View.GONE);
                }
                return true;
              case R.id.error_item_status:
                if (text.length() == 0) {
                  view.setVisibility(View.GONE);
                  return true;
                } else {
                  view.setVisibility(View.VISIBLE);
                  return false;
                }
            }
            return false;
          }
        });

    btnClearAll.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            deleteFiles(false, false);
            refreshErrorListView();
            refreshInterface();
          }
        });

    mLvErrorList.setAdapter(mErrorAdapter);

    btnSend.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!mPostingFeedback) {
              String feedback = mEtFeedbackText.getText().toString();
              Connection.sendFeedback(
                  mSendListener,
                  new Payload(
                      new Object[] {
                        mFeedbackUrl,
                        mErrorUrl,
                        feedback,
                        mErrorReports,
                        mNonce,
                        getApplication(),
                        false
                      }));
              if (mErrorReports.size() > 0) {
                mPostingFeedback = true;
              }
              if (feedback.length() > 0) {
                mPostingFeedback = true;
              }
              refreshInterface();
            }
          }
        });

    btnKeepLatest.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            deleteFiles(false, true);
            refreshErrorListView();
            refreshInterface();
          }
        });

    refreshInterface();

    getWindow()
        .setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  }