+/* FirstRun.java
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package de.dhbwloe.campusapp.fragments;
-
-
+import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
import android.widget.Button;
+import android.widget.EditText;
import de.dhbwloe.campusapp.CampusAppFragment;
import de.dhbwloe.campusapp.R;
+import de.dhbwloe.campusapp.coursenames.CourseName;
/**
* A simple {@link Fragment} subclass.
*/
public class FirstRun extends CampusAppFragment {
+ private View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_first_run, container, false);
+ view = inflater.inflate(R.layout.fragment_first_run, container, false);
AppContext.setTitle("Campus App");
+ final FirstRun that = this;
Button startAppBtn = (Button)view.findViewById(R.id.startAppBtn);
startAppBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", "1");
- AppContext.getNavigationManager().navigatePage("SplashScreen", null, false);
+ that.startApp();
+ }
+ });
+
+ Button courseSendBtn = (Button)view.findViewById(R.id.courseSubmitBtn);
+ courseSendBtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if(that.setCourse())
+ that.startApp();
}
});
+ AutoCompleteTextView courseInput = (AutoCompleteTextView )view.findViewById(R.id.courseInput);
+ CourseName names[] = AppContext.getDatabaseManager().getCourseNames();
+ String courseNames[] = new String[names.length];
+ for(int i = 0; i < names.length; i++) {
+ courseNames[i] = names[i].getName();
+ }
+
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(AppContext.getMainActivity(), android.R.layout.simple_list_item_1, courseNames);
+ courseInput.setAdapter(adapter);
+
return view;
}
+ private void startApp() {
+ AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", "1");
+ AppContext.getNavigationManager().navigatePage("SplashScreen", null, false);
+
+ InputMethodManager imm = (InputMethodManager)AppContext.getMainActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+
+ private boolean setCourse() {
+ AutoCompleteTextView courseInput = (AutoCompleteTextView )view.findViewById(R.id.courseInput);
+ String courseName = courseInput.getText().toString();
+ if(courseName.length() <= 3)
+ return false;
+
+ AppContext.getDatabaseManager().setRuntimeCache("CourseName", courseName);
+ return true;
+ }
+
}