I've been developing my first android application over the last few days and I have finally entered the beta phase. Me and a few of my friends are soon going to try the application properly as it is supposed to be used.
I have tried to implement a password system, so that if the program leaks out during beta the rest of the beta testers wont be able to use it. To do this I have made an algorithm (I think thats what they call it) that will come up with a password based on the week number of the year. It isn't complex but I doubt anybody I know would be able to crack it.
Anyway, this activity is the .LAUNCHER and the .MAIN in the manifest, and I am developing for Android 2.1 (API 7). When it loads it creates an editText and a button. Basically when the button is pressed and the editText is equal to the answer to the algorithm it should open the main application. But it doesn't work.
I have used the debug tool in eclipse to check all the variables are correct and they all are but it doesn't want to work. Could anybody help me with this. My code is bellow.
import java.util.Calendar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.GetChars;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class ContactActivity extends Activity {
EditText Code; // prepare xml stuff
Button Go;
int Turns = 3; // turns in total
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkcode);
Go = (Button) findViewById(R.id.bGo); // link go button
Code = (EditText) findViewById(R.id.etCode); // link code to text box
Go.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String UserCode = (String)Code.getText().toString();
int WeekNo = Calendar.WEEK_OF_YEAR;
int Algorithm = WeekNo * 123 + WeekNo;
String Answer = Integer.toString(Algorithm);
if(UserCode == Answer){
Intent beginContact = new Intent("com.URS.Kalashnikov.MAINPAGE"); // set intent to switch to
// main activity
startActivity(beginContact); // start activity
} else {
Turns -= 1; // remove turns by one
if(Turns <= 0){
Context context = getApplicationContext();
CharSequence text = "Incorrect Code. No chances left";
// text for the toast
int duration = Toast.LENGTH_LONG; // toast length
Toast warning = Toast.makeText(context, text, duration); // prepare a toast
warning.show(); // show the toast
finish(); // kill the program if there is zero turns left
} else {
Code.setText("");
// make a toast
Context context = getApplicationContext();
CharSequence text = "Incorrect Code - Please try again. You have " + Turns + " chances left";
// text for the toast
int duration = Toast.LENGTH_LONG; // toast length
Toast warning = Toast.makeText(context, text, duration); // prepare a toast
warning.show(); // show the toast
}
}
}
});
}
}
There are some extra stuff that I haven't mentioned that is in my code, but you could probably figure it out.