Android Open Source - Langleo Main






From Project

Back to project page Langleo.

License

The source code is released under:

Apache License

If you think the Android project Langleo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.atteo.langleo_trial.activities;
//  ww w .ja va  2 s .c om
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.atteo.langleo_trial.Langleo;
import com.atteo.langleo_trial.LearningAlgorithm;
import com.atteo.langleo_trial.R;
import com.atteo.langleo_trial.views.NumberPicker;
import com.atteo.langleo_trial.views.SelectLimitDialog;
import com.atteo.silo.Silo;

public class Main extends Activity {
  private boolean forceStudy = false;

  private static final int DIALOG_SELECT_LIMIT = 0;
  private static final int DIALOG_WELCOME = 1;
  private static final int DIALOG_WELCOME2 = 2;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    if (!Silo.isOpened()) {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage(getString(R.string.database_error));
      builder.setNeutralButton(R.string.ok, null);
      AlertDialog alert = builder.create();
      alert.show();
    }

    TextView version = (TextView) findViewById(R.id.version_label);
    version.setText(Langleo.VERSION);

    Button button = (Button) findViewById(R.id.button_study);
    button.setOnClickListener(new OnClickListener() {
      public void onClick(View view) {
        study();
      }
    });

    button = (Button) findViewById(R.id.button_manage);
    button.setOnClickListener(new OnClickListener() {
      public void onClick(View view) {
        manageCollections();
      }
    });

    button = (Button) findViewById(R.id.button_preferences);
    button.setOnClickListener(new OnClickListener() {
      public void onClick(View view) {
        preferences();
      }
    });

    button = (Button) findViewById(R.id.button_help);
    button.setOnClickListener(new OnClickListener() {
      public void onClick(View view) {
        showHelp();
      }
    });

  }

  private boolean firstRun(SharedPreferences prefs) {
    boolean firstRun = prefs.getBoolean("first_run", true);
    if (firstRun) {
      Editor e = prefs.edit();
      e.putString("version", Langleo.VERSION);
      e.putBoolean("first_run", false);
      e.commit();
      showDialog(DIALOG_WELCOME);
    }
    return firstRun;
  }

  private void checkVersion(SharedPreferences prefs) {
    String version = prefs.getString("version", "");
    if (!version.equals(Langleo.VERSION)) {
      Editor e = prefs.edit();
      e.putString("version", Langleo.VERSION);
      e.commit();
      showUpdates();
    }
  }

  @Override
  protected void onStart() {
    super.onStart();
    SharedPreferences prefs = Langleo.getPreferences();

    if (!firstRun(prefs))
      checkVersion(prefs);

  }

  // Button handlers

  @Override
  protected Dialog onCreateDialog(int dialogId) {
    AlertDialog.Builder builder;
    AlertDialog alert;
    switch (dialogId) {
    case DIALOG_WELCOME:
      builder = new AlertDialog.Builder(this);
      builder.setTitle(R.string.welcome_title).setMessage(
          getString(R.string.welcome_message)).setCancelable(false)
          .setPositiveButton(getString(R.string.ok),
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                    int id) {
                  showDialog(DIALOG_WELCOME2);
                }
              });
      alert = builder.create();
      return alert;
    case DIALOG_WELCOME2:
      builder = new AlertDialog.Builder(this);
      builder.setTitle(R.string.welcome_title).setMessage(
          getString(R.string.welcome_message2)).setCancelable(false)
          .setPositiveButton(getString(R.string.ok),
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                    int id) {

                }
              });
      alert = builder.create();
      return alert;

    case DIALOG_SELECT_LIMIT:
      final Dialog limit_dialog = new SelectLimitDialog(this);
      Button b = (Button) limit_dialog
          .findViewById(R.id.increase_limit_dialog_ok);
      b.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          limit_dialog.dismiss();
          Intent intent = new Intent(Main.this, Study.class);
          NumberPicker np = (NumberPicker) limit_dialog
              .findViewById(R.id.increase_limit_dialog_picker);
          intent.putExtra("limit_increase", np.getCurrent());
          startActivity(intent);
          forceStudy = false;
        }
      });
      b = (Button) limit_dialog
          .findViewById(R.id.increase_limit_dialog_cancel);
      b.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          limit_dialog.dismiss();
        }
      });

      return limit_dialog;
    default:
      return null;
    }

  }

  private void study() {
    int a;
    if ((a = Langleo.getLearningAlgorithm().isQuestionWaiting()) != LearningAlgorithm.QUESTIONS_WAITING) {
      switch (a) {
      case LearningAlgorithm.NO_QUESTIONS:
        Toast.makeText(this, getString(R.string.no_words_to_study),
            Toast.LENGTH_LONG).show();
        break;
      case LearningAlgorithm.QUESTIONS_ANSWERED:
        Toast.makeText(this, getString(R.string.no_need_to_study_now),
            Toast.LENGTH_LONG).show();
        forceStudy = false;
        break;
      case LearningAlgorithm.QUESTIONS_ANSWERED_FORCEABLE:
        if (forceStudy) {
          showDialog(DIALOG_SELECT_LIMIT);
          return;
        }
        Toast.makeText(this, getString(R.string.no_need_to_study_now),
            Toast.LENGTH_LONG).show();
        Toast.makeText(this,
            getString(R.string.click_again_to_start_either_way),
            Toast.LENGTH_LONG).show();
        forceStudy = true;

        break;
      }

      return;
    }
    Intent intent = new Intent(this, Study.class);
    intent.putExtra("limit_increase", 0);
    startActivity(intent);
  }

  private void manageCollections() {
    Intent intent = new Intent(this, Collections.class);
    startActivity(intent);
  }

  private void preferences() {
    Intent intent = new Intent(this, Preferences.class);
    startActivity(intent);
  }

  private void showHelp() {
    Intent intent = new Intent(this, Help.class);
    intent.putExtra("part", "main");
    startActivity(intent);
  }

  private void showUpdates() {
    Intent intent = new Intent(this, Updates.class);
    startActivity(intent);
  }

}




Java Source Code List

com.atteo.langleo_trial.CollectionProgress.java
com.atteo.langleo_trial.ImportData.java
com.atteo.langleo_trial.ImportFile.java
com.atteo.langleo_trial.Langleo.java
com.atteo.langleo_trial.LearningAlgorithm.java
com.atteo.langleo_trial.TaskInfo.java
com.atteo.langleo_trial.TaskManager.java
com.atteo.langleo_trial.activities.Collections.java
com.atteo.langleo_trial.activities.Download.java
com.atteo.langleo_trial.activities.EditCollection.java
com.atteo.langleo_trial.activities.EditList.java
com.atteo.langleo_trial.activities.EditWord.java
com.atteo.langleo_trial.activities.Help.java
com.atteo.langleo_trial.activities.ImportFromFile.java
com.atteo.langleo_trial.activities.Lists.java
com.atteo.langleo_trial.activities.Main.java
com.atteo.langleo_trial.activities.Preferences.java
com.atteo.langleo_trial.activities.SelectFile.java
com.atteo.langleo_trial.activities.SelectList.java
com.atteo.langleo_trial.activities.StackDetails.java
com.atteo.langleo_trial.activities.Study.java
com.atteo.langleo_trial.activities.Updates.java
com.atteo.langleo_trial.activities.Words.java
com.atteo.langleo_trial.algorithms.Olli.java
com.atteo.langleo_trial.models.Collection.java
com.atteo.langleo_trial.models.Language.java
com.atteo.langleo_trial.models.List.java
com.atteo.langleo_trial.models.OlliAnswer.java
com.atteo.langleo_trial.models.OlliFactor.java
com.atteo.langleo_trial.models.Question.java
com.atteo.langleo_trial.models.StudyDay.java
com.atteo.langleo_trial.models.StudySession.java
com.atteo.langleo_trial.models.Word.java
com.atteo.langleo_trial.util.BetterAsyncTask.java
com.atteo.langleo_trial.util.ProgressHandler.java
com.atteo.langleo_trial.views.MainMenuButton.java
com.atteo.langleo_trial.views.NumberPickerButton.java
com.atteo.langleo_trial.views.NumberPicker.java
com.atteo.langleo_trial.views.SelectLimitDialog.java