From 61e3e42d53e784ccba5d3ac5817ec4a49119fcc5 Mon Sep 17 00:00:00 2001 From: Naren Surampudi Date: Mon, 13 Feb 2017 20:36:42 +0530 Subject: [PATCH 1/3] Add files via upload --- .../src/main/res/layout/FirstRunActivity.java | 116 ++++++++++++++++++ .../main/res/layout/activity_first_run.xml | 10 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 source-code/app/src/main/res/layout/FirstRunActivity.java diff --git a/source-code/app/src/main/res/layout/FirstRunActivity.java b/source-code/app/src/main/res/layout/FirstRunActivity.java new file mode 100644 index 00000000..150f6058 --- /dev/null +++ b/source-code/app/src/main/res/layout/FirstRunActivity.java @@ -0,0 +1,116 @@ +package org.buildmlearn.toolkit.activity; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.AppCompatActivity; +import android.view.KeyEvent; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.EditText; +import android.widget.Button; + +import com.crashlytics.android.Crashlytics; + +import org.buildmlearn.toolkit.R; +import org.buildmlearn.toolkit.constant.Constants; + +import io.fabric.sdk.android.Fabric; + + +/** + * @brief Shown on application first launch. + */ +public class FirstRunActivity extends AppCompatActivity { + + private static final String FIRST_RUN = "first_run"; + + private EditText name; + private SharedPreferences prefs; + + /** + * {@inheritDoc} + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + Fabric.with(this, new Crashlytics()); + if (prefs.getBoolean(FIRST_RUN, false)) { + startActivity(new Intent(getApplicationContext(), HomeActivity.class)); + finish(); + } + setContentView(R.layout.activity_first_run); + + findViewById(R.id.focus_thief).clearFocus(); + Animation anim_bounceinup=AnimationUtils.loadAnimation(getBaseContext(),R.anim.bounceinup); + name = (EditText) findViewById(R.id.first_name); + Button button = (Button) findViewById(R.id.ok_button); + name.startAnimation(anim_bounceinup); + button.startAnimation(anim_bounceinup); + button.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + + if (name.getText().toString().equals("")) { + name.setError(getApplicationContext().getResources().getString(R.string.enter_name)); + } + else if(!Character.isLetterOrDigit(name.getText().toString().charAt(0))) + { + name.setError(getApplicationContext().getResources().getString(R.string.valid_msg)); + } + + + SharedPreferences.Editor editor = prefs.edit(); + + editor.putString(getString(R.string.key_user_name), name.getText().toString()); + editor.putBoolean(FIRST_RUN, true); + editor.apply(); + Intent intent = new Intent(getApplicationContext(), TutorialActivity.class); + intent.putExtra(Constants.START_ACTIVITY, true); + startActivity(intent); + finish(); + + } + }); + + name.setOnKeyListener(new View.OnKeyListener() { + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + if (event.getAction() == KeyEvent.ACTION_DOWN) { + switch (keyCode) { + case KeyEvent.KEYCODE_DPAD_CENTER: + case KeyEvent.KEYCODE_ENTER: + + if (name.getText().toString().equals("")) { + name.setError(getApplicationContext().getResources().getString(R.string.enter_name)); + return false; + } + else if(!Character.isLetterOrDigit(name.getText().toString().charAt(0))) + { + name.setError(getApplicationContext().getResources().getString(R.string.valid_msg)); + return false; + } + + + SharedPreferences.Editor editor = prefs.edit(); + + editor.putString(getString(R.string.key_user_name), name.getText().toString()); + editor.putBoolean(FIRST_RUN, true); + editor.apply(); + Intent intent = new Intent(getApplicationContext(), TutorialActivity.class); + intent.putExtra(Constants.START_ACTIVITY, true); + startActivity(intent); + finish(); + return true; + default: + break; + } + } + return false; + } + }); + } + +} diff --git a/source-code/app/src/main/res/layout/activity_first_run.xml b/source-code/app/src/main/res/layout/activity_first_run.xml index 884e9564..2025e549 100644 --- a/source-code/app/src/main/res/layout/activity_first_run.xml +++ b/source-code/app/src/main/res/layout/activity_first_run.xml @@ -18,7 +18,8 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" - android:orientation="vertical"> + android:orientation="vertical" + android:weightSum="1"> +