3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.fragments;
17 import android.content.Context;
18 import android.os.Bundle;
19 import android.support.v4.app.Fragment;
20 import android.view.KeyEvent;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.view.inputmethod.EditorInfo;
25 import android.view.inputmethod.InputMethodManager;
26 import android.widget.ArrayAdapter;
27 import android.widget.AutoCompleteTextView;
28 import android.widget.EditText;
29 import android.widget.Spinner;
30 import android.widget.TextView;
32 import de.dhbwloe.campusapp.CampusAppFragment;
33 import de.dhbwloe.campusapp.R;
34 import de.dhbwloe.campusapp.coursenames.CourseName;
37 * A simple {@link Fragment} subclass.
39 public class Settings extends CampusAppFragment {
40 private AutoCompleteTextView courseNameInput;
41 private Spinner mensaRoleInput;
44 // Required empty public constructor
49 public View onCreateView(LayoutInflater inflater, ViewGroup container,
50 Bundle savedInstanceState) {
51 oFragmentView = inflater.inflate(R.layout.fragment_settings, container, false);
53 courseNameInput = (AutoCompleteTextView) oFragmentView.findViewById(R.id.courseNameInput);
54 mensaRoleInput = (Spinner) oFragmentView.findViewById(R.id.mensaRoleInput);
56 courseNameInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
57 courseNameInput.setOnEditorActionListener(
58 new EditText.OnEditorActionListener() {
60 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
61 if (actionId == EditorInfo.IME_ACTION_SEARCH ||
62 actionId == EditorInfo.IME_ACTION_DONE ||
63 event.getAction() == KeyEvent.ACTION_DOWN &&
64 event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
66 InputMethodManager imm = (InputMethodManager)AppContext.getMainActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
67 imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
74 CourseName names[] = AppContext.getDatabaseManager().getCourseNames();
75 String courseNames[] = new String[names.length];
76 for(int i = 0; i < names.length; i++) {
77 courseNames[i] = names[i].getName();
80 ArrayAdapter<String> adapter = new ArrayAdapter<String>(AppContext.getMainActivity(), android.R.layout.simple_list_item_1, courseNames);
81 courseNameInput.setAdapter(adapter);
88 public void onStart() {
91 String courseName = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
92 if(courseName == null || courseName.isEmpty())
94 courseNameInput.setText(courseName);
96 String mensaRoleName = AppContext.getDatabaseManager().getRuntimeCache("MensaRole");
97 if (mensaRoleName == null || mensaRoleName.isEmpty())
99 int mensaRole = Integer.parseInt(mensaRoleName);
100 mensaRoleInput.setSelection(mensaRole);
104 public void onStop() {
106 boolean overrideNavigation = false;
108 String courseName = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
109 if (courseName == null || courseName.isEmpty())
112 String newCourseName = courseNameInput.getText().toString();
113 if(!courseName.equalsIgnoreCase(newCourseName)) {
114 AppContext.getDatabaseManager().setRuntimeCache("CourseName", newCourseName);
115 overrideNavigation = true;
118 String mensaRoleName = AppContext.getDatabaseManager().getRuntimeCache("MensaRole");
119 if (mensaRoleName == null || mensaRoleName.isEmpty())
121 String newMensaRoleName = Integer.toString(mensaRoleInput.getSelectedItemPosition());
122 if(!mensaRoleName.equalsIgnoreCase(newMensaRoleName)) {
123 AppContext.getDatabaseManager().setRuntimeCache("MensaRole", newMensaRoleName);
124 overrideNavigation = true;
127 if(overrideNavigation) {
128 AppContext.getNavigationManager().navigatePage("Splashscreen", null, false);