Android Open Source - android-memorytrainer Check Last Number Activity






From Project

Back to project page android-memorytrainer.

License

The source code is released under:

GNU General Public License

If you think the Android project android-memorytrainer 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 org.hoffimar.android.memorytrainer;
/*from   w w w  . j  a  v  a 2 s . c o  m*/
import java.util.HashMap;
import java.util.Map;

import com.flurry.android.FlurryAgent;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CheckLastNumberActivity extends Activity {

  private EditText inputNumber;
  private Button verifyNumberButton;
  private TextView resultView;
  private TextView yourInputView;
  private TextView lastNumberView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.check_number);

    inputNumber = (EditText) findViewById(R.id.EditTextInputNumberFromMemory);
    inputNumber.setInputType(InputType.TYPE_CLASS_PHONE);
    resultView = (TextView) findViewById(R.id.TextViewNumberVerification);
    yourInputView = (TextView) findViewById(R.id.NumberVerificationInput);
    lastNumberView = (TextView) findViewById(R.id.NumberVerificationLastNumber);
    
    
    verifyNumberButton = (Button) findViewById(R.id.ButtonVerifyNumber);
    verifyNumberButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        SharedPreferences settings = getSharedPreferences(Overview.PREFS_NAME, 0);
        String lastNumber = settings.getString("lastNumber", "");
        String numberUserInput = inputNumber.getText().toString();
        
        DbAdapter mDbHelper;
        mDbHelper = new DbAdapter(getApplicationContext());
        mDbHelper.open();
        
        boolean isInputCorrect = lastNumber.equals(numberUserInput.replace(" ", ""));
        if (isInputCorrect){
          resultView.setText(R.string.result_number_right);
          mDbHelper.createStatsItem(lastNumber, true);
        } else {
          StringBuilder sb = new StringBuilder(50);
          sb.append(getString(R.string.result_number_wrong));
          sb.append("\n\n");
          if (lastNumber.length() != numberUserInput.length()){
            sb.append(getString(R.string.check_number_wrong_length));
            sb.append("\n");
            sb.append(getString(R.string.check_number_last_number_label) + ": " + lastNumber.length() + "\n");
            sb.append(getString(R.string.check_number_your_input_label) + ": " + numberUserInput.length());
            sb.append("\n\n");
          }
          
          
//          sb.append(getString(R.string.check_number_last_number_label) + ": " + lastNumber + "\n");
//          sb.append(getString(R.string.check_number_your_input_label) + ": " + numberUserInput);
          
          findViewById(R.id.NumberVerificationInputLabel).setVisibility(View.VISIBLE);
          findViewById(R.id.NumberVerificationLastNumberLabel).setVisibility(View.VISIBLE);
          
          yourInputView.setText(numberUserInput);
          lastNumberView.setText(lastNumber);
          
          resultView.setText(sb.toString());
          mDbHelper.createStatsItem(lastNumber, false);
        }
        
        mDbHelper.close();
        
        
        Map<String, String> map = new HashMap<String, String>();
        map.put("input correct?", Boolean.toString(isInputCorrect));
        FlurryAgent.onEvent(Constants.FLURRY_EVENTID_CHECK_NUMBER_BUTTON, map);
        
      }
    });
  }

  @Override
  protected void onStart() {
    super.onStart();
    FlurryAgent.onStartSession(this, Constants.FLURRY_ID);
  }

  @Override
  protected void onStop() {
    super.onStop();
    FlurryAgent.onEndSession(this);
  }

}




Java Source Code List

org.hoffimar.android.memorytrainer.AboutActivity.java
org.hoffimar.android.memorytrainer.CheckLastNumberActivity.java
org.hoffimar.android.memorytrainer.Constants.java
org.hoffimar.android.memorytrainer.DbAdapter.java
org.hoffimar.android.memorytrainer.EditItemActivity.java
org.hoffimar.android.memorytrainer.EditPreferencesActivity.java
org.hoffimar.android.memorytrainer.GenerateNumberActivity.java
org.hoffimar.android.memorytrainer.InformationActivity.java
org.hoffimar.android.memorytrainer.ListHundredActivity.java
org.hoffimar.android.memorytrainer.MaintainListActivity.java
org.hoffimar.android.memorytrainer.Overview.java
org.hoffimar.android.memorytrainer.StatisticsOverviewActivity.java
org.hoffimar.android.memorytrainer.TreeListActivity.java
org.hoffimar.android.memorytrainer.TreeListGenerateActivity.java
org.hoffimar.android.memorytrainer.TreeListVerifyActivity.java
org.hoffimar.android.memorytrainer.model.CellEntry.java
org.hoffimar.android.memorytrainer.model.CellFeed.java
org.hoffimar.android.memorytrainer.model.Cell.java
org.hoffimar.android.memorytrainer.model.Content.java
org.hoffimar.android.memorytrainer.model.Entry.java
org.hoffimar.android.memorytrainer.model.Feed.java
org.hoffimar.android.memorytrainer.model.Link.java
org.hoffimar.android.memorytrainer.model.SpreadsheetEntry.java
org.hoffimar.android.memorytrainer.model.UserFeed.java
org.hoffimar.android.memorytrainer.model.WorksheetEntry.java
org.hoffimar.android.memorytrainer.model.WorksheetsFeed.java