Esempio n. 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_showcase_layout);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Back");
    databaseManager = new DatabaseManager(this);
    apiRequests = new ApiRequests();

    setButtons();

    switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);

    // get the intent
    Intent intent = getIntent();

    word = new Word();
    mainText = (TextView) findViewById(R.id.word_showcase_text);
    descriptionText = (TextView) findViewById(R.id.word_showcase_description_text);

    /*caller used for identifying what activity called this so
    the back button goes to the right place
     */
    caller = intent.getStringExtra("parent");

    // if the parent was the OCR activity, get the OCR result and display the text
    if (caller.equals("OCR")) {
      word.setText(getOCRText());
      Log.d(DolchListActivity.TAG, word.getText());
      mainText.setText(word.getText());
    }
    // if parent was vocab builder set text to the passed in word in the intent
    else if (caller.equals("vocab")) {
      word.setText(intent.getStringExtra("word"));
      mainText.setText(word.getText());
    } else {
      // else get word from intent extra
      word.setText(intent.getStringExtra("word"));
      mainText.setText(word.getText());
    }

    // getting word status to set favourite star to checked/unchecked
    try {
      if (databaseManager.wordSaved(word.getText())) {
        starCheckBox.setChecked(true);
      } else {
        starCheckBox.setChecked(false);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    // if no description leave blank
    descriptionText.setText("");

    new getWordThread().execute();
  }
Esempio n. 2
0
 /*Removes the word from local Database. If the user is logged in and network available
 removes from remote database also
 */
 public void removeWord() {
   databaseManager.removeWord(word.getText());
   if (apiRequests.isUserLoggedIn(getApplicationContext())) {
     if (isNetworkAvailable()) {
       new FavouriteThread(this, word, "remove").execute();
     }
   }
 }
Esempio n. 3
0
  // handle button clicks
  @Override
  public void onClick(View view) {

    if (isSpeaking) {
      ttsHelper.stopSpeaking();
    }

    switch (view.getId()) {
      case R.id.word_showcase_play_button:
        currentSpeakingView = mainText;
        ttsHelper.say(mainText.getText().toString());

        break;

      case R.id.word_showcase_stop_button:
        currentSpeakingView = descriptionText;
        ttsHelper.stopSpeaking();

        break;

      case R.id.word_showcase_play_description_button:
        currentSpeakingView = descriptionText;
        ttsHelper.say(descriptionText.getText().toString());
        break;

      case R.id.favourite_star_checkbox_word_showcase:
        // save word if star not checked and vice versa
        if (starCheckBox.isChecked()) {
          saveWord();
        } else {
          removeWord();
        }
    }
    try {
      // if word already saved or not mark the star accordingly
      if (databaseManager.wordSaved(word.getText())) {
        starCheckBox.setChecked(true);
      } else {
        starCheckBox.setChecked(false);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }