Guest User

Untitled

a guest
May 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. package com.example.student.mysterygame;
  2.  
  3.  
  4.  
  5. public class logView extends Fragment implements AbsListView.OnItemClickListener {
  6.  
  7. AbsListView mListView;
  8. EditText testField;
  9.  
  10. String mmMessage;
  11. String name;
  12. String date;
  13.  
  14. boolean hasEnteredPassword;
  15.  
  16. public static ArrayAdapter<LogItems> mArrayAdapter;
  17. public static ArrayList<LogItems> mArrayList;
  18. private MainActivity mmActivity;
  19.  
  20.  
  21. public static logView newInstance() {
  22. logView fragment = new logView();;
  23.  
  24.  
  25.  
  26. return fragment;
  27. }
  28.  
  29. public logView() {
  30. // Required empty public constructor
  31. }
  32.  
  33.  
  34. @Override
  35. public void onCreate(Bundle savedInstanceState) {
  36. super.onCreate(savedInstanceState);
  37.  
  38. mArrayList = new ArrayList<LogItems>();
  39.  
  40. mArrayAdapter = new textLogAdpater(getActivity(), mArrayList);
  41.  
  42. }
  43.  
  44.  
  45. @Override
  46. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  47. Bundle savedInstanceState) {
  48.  
  49. // Inflate the layout for this fragment
  50. View view = inflater.inflate(R.layout.fragment_log_view, container, false);
  51. //testField.setOnEditorActionListener(new onEditorDoneInteraction());
  52.  
  53.  
  54. return view;
  55. }
  56.  
  57. @Override
  58. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  59. super.onViewCreated(view, savedInstanceState);
  60.  
  61. mListView = getView().findViewById(R.id.logView);
  62.  
  63. mListView.setAdapter(mArrayAdapter);
  64. mListView.setOnItemClickListener(this);
  65.  
  66. testField = getView().findViewById(R.id.editText);
  67. Button sendButton = getView().findViewById(R.id.sendButton);
  68.  
  69. mmActivity = new MainActivity();
  70.  
  71. name = "You";
  72. date = "09/05/2022";
  73.  
  74. sendButton.setOnClickListener(new View.OnClickListener() {
  75. @Override
  76. public void onClick(View view) {
  77.  
  78. Log.d("Send Button", "Creating a new Log Entry.");
  79.  
  80. mmMessage = String.valueOf(testField.getText());
  81.  
  82. LogItems newEntry = new LogItems(name, date, mmMessage);
  83.  
  84. mArrayAdapter.add(newEntry);
  85. mArrayAdapter.notifyDataSetChanged();
  86.  
  87.  
  88. if(!hasEnteredPassword){
  89.  
  90. if (Objects.equals(mmMessage, "Test")) {
  91. //UI response is granted
  92. populateLogOnStartWith("UI", "10/123/2018:", "Checking...");
  93. final Handler handler = new Handler();
  94. handler.postDelayed(new Runnable() {
  95. @Override
  96. public void run() {
  97. populateLogOnStartWith("UI", "10/123/2018:", "Access Granted");
  98. setFriend1Logs();
  99. }
  100. }, 1000);
  101.  
  102. hasEnteredPassword = true;
  103.  
  104. } else {
  105. populateLogOnStartWith("UI", "10/123/2018:", "checking...");
  106. final Handler handler = new Handler();
  107. handler.postDelayed(new Runnable() {
  108. @Override
  109. public void run() {
  110. populateLogOnStartWith("UI", "10/123/2018:", "Access denied! Try Again");
  111. }
  112. }, 1000);
  113.  
  114. //UI response is denied
  115.  
  116. }
  117. }
  118.  
  119. }
  120. });
  121.  
  122. /**
  123. * ALL POPULATION REQUESTS FOR THE LOG SHOULD BE PUT BELOW THIS COMMENT.
  124. */
  125.  
  126. Log.d("Log Population", "OnCreate called for LogPopulation");
  127. populateLogOnStartWith("UI", "10/11/2018:", "Connecting to Friend1 Phone....");
  128. populateLogOnStartWith("UI", "10/11/2018:", "Phone is now Connected");
  129. populateLogOnStartWith("UI", "10/123/2018:", "Enter Password to access phone:");
  130.  
  131.  
  132. }
  133.  
  134. public void setFriend1Logs() {
  135. Log.d("Log Population", "OnCreate called for LogPopulation");
  136. populateLogOnStartWith("UI", "10/11/2018:", "blah blah");
  137. populateLogOnStartWith("UI", "10/11/2018:", "Put Story here");
  138. populateLogOnStartWith("UI", "10/123/2018:", "I don't know what will come next");
  139.  
  140. }
  141.  
  142. private void populateLogOnStartWith(String name, String date, String entry) {
  143.  
  144. LogItems newEntry = new LogItems(name, date, entry);
  145. mArrayAdapter.add(newEntry);
  146. mArrayAdapter.notifyDataSetChanged();
  147. }
  148.  
  149. //---------------------------------------------Save Mechanics----------------------------------------
  150.  
  151.  
  152. @Override
  153. public void onSaveInstanceState(Bundle savedInstanceState) {
  154. super.onSaveInstanceState(savedInstanceState);
  155.  
  156.  
  157.  
  158.  
  159. }
  160.  
  161. @Override
  162. public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  163.  
  164. }
  165.  
  166. package com.example.student.mysterygame;
  167.  
  168. //This is a Data set class. This is used to set, store and call a Data Set. in this case
  169. //The data set contains the logName, logDate and lodEntry.
  170.  
  171. /**
  172. * There is no need to touch this class if you are not adding a data set. this can be ignored
  173. * for the most part.
  174. */
  175.  
  176. private String logName;
  177. private String logDate;
  178. private String logEntry;
  179.  
  180. public String getLogName(){return logName;}
  181. public String getLogDate(){return logDate;}
  182. public String getLogEntry(){return logEntry;}
  183.  
  184. public void setLogName(String LogName){this.logName = LogName;}
  185. public void setLogDate(String LogDate){this.logDate = LogDate;}
  186. public void setLogEntry(String logEntry){this.logEntry = logEntry;}
  187.  
  188. public LogItems(String name, String date, String logEntry){
  189.  
  190. this.logEntry = logEntry;
  191. this.logName = name;
  192. this.logDate = date;
  193. }
Add Comment
Please, Sign In to add comment