Advertisement
jielin8

Untitled

Oct 24th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.89 KB | None | 0 0
  1. package com.idejie.android.quiz.fragments;
  2.  
  3.  
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.support.v4.app.Fragment;
  7.  
  8. import android.support.v7.widget.DividerItemDecoration;
  9. import android.support.v7.widget.LinearLayoutManager;
  10. import android.support.v7.widget.RecyclerView;
  11. import android.util.Log;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.ViewGroup;
  15.  
  16. import com.idejie.android.quiz.DetailActivity;
  17. import com.idejie.android.quiz.R;
  18. import com.idejie.android.quiz.adapters.LessonAdapter;
  19. import com.idejie.android.quiz.models.Lesson;
  20.  
  21. import java.util.ArrayList;
  22. import java.util.List;
  23.  
  24.  
  25. public class LessonFragment extends Fragment {
  26.  
  27. private static final String ARG_COLUMN_COUNT = "column-count";
  28. private RecyclerView recyclerView ;
  29. private LessonAdapter adapter;
  30.  
  31. public LessonFragment() {
  32. }
  33.  
  34.  
  35. @SuppressWarnings("unused")
  36. public static LessonFragment newInstance(int columnCount) {
  37. LessonFragment fragment = new LessonFragment();
  38. Bundle args = new Bundle();
  39. args.putInt(ARG_COLUMN_COUNT, columnCount);
  40. fragment.setArguments(args);
  41. return fragment;
  42. }
  43.  
  44.  
  45. @Override
  46. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  47. Bundle savedInstanceState) {
  48. View view = inflater.inflate(R.layout.fragment_lesson, container, false);
  49. recyclerView = view.findViewById(R.id.lessons_list);
  50. List<Lesson> lessons = getLessons();
  51. adapter = new LessonAdapter(getActivity(), lessons, new LessonAdapter.OnItemClickCallback<Lesson>() {
  52. @Override
  53. public void onClick(View view, Lesson info) {
  54. Log.d("#Quiz","####"+info.lesson_name);
  55. Intent intent = new Intent();
  56. Bundle bundle = new Bundle();
  57. bundle.putString("title",info.lesson_name);
  58. bundle.putString("content",info.lesson_content);
  59. intent.putExtras(bundle);
  60. intent.setClass(getActivity(),DetailActivity.class);
  61. startActivity(intent);
  62. }
  63. });
  64. recyclerView.setLayoutManager(new LinearLayoutManager(this.getContext()));
  65. recyclerView.setAdapter(adapter);
  66. recyclerView.addItemDecoration(new DividerItemDecoration(this.getActivity(),DividerItemDecoration.VERTICAL));
  67. return view;
  68. }
  69.  
  70. public static List<Lesson> getLessons() {
  71. List<Lesson> rets=new ArrayList<>();
  72. Lesson lesson1 = new Lesson(0,
  73. "Content Providers: Introduction",
  74. "https://www.tutorialspoint.com/android/images/content1.jpg",
  75. "What is a Content Provider and why do we use them?\n" +
  76. "Content providers act as a layer between the DataBase and the activity\n" +
  77. "\n" +
  78. "•They manage access to a structured set of data\n" +
  79. "\n" +
  80. "•Content Providers serve as a good abstraction layer between the data source and UI code. The can add data validation, modify how data is stored whilst the UI code remains unaffected)\n" +
  81. "\n" +
  82. "Content Providers manage a shared set of app data. We can store the data in the file system, an SQLite database, on the web, or any other persistent storage location our app can access.\n " +
  83. "\n" +
  84. "Through the content provider, other apps can query or even modify the data. \n" +
  85. "\n" +
  86. "E.g. The Android system provides a content provider that manages the user's contact information. As such, any app with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.\n" +
  87. "\n" +
  88. "Content providers are also useful for reading and writing data that is private to your app and not shared. E.g. The Note Pad sample app uses a content provider to save notes." );
  89. rets.add(lesson1);
  90. Lesson lesson2 = new Lesson(1,
  91. "Content Providers: Accessing a C.P. ",
  92. "https://developer.android.com/guide/topics/providers/images/content-provider-tech-stack.png",
  93. "How to access a content provider?" +
  94. "\n" +
  95. "When you want to access data in a content provider, you use the ContentResolver object in your application to communicate with the provider as a client.\n" +
  96. "\n" +
  97. "The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider. The provider object receives data requests from clients, performs the requested action, and returns the results. \n" +
  98. "\n" +
  99. "This object has methods that call identically-named methods in the provider object, an instance of one of the concrete subclasses of ContentProvider. TheContentResolver methods provide the basic \"CRUD\" (create, retrieve, update, and delete) functions of persistent storage.\n" +
  100. "\n" +
  101. "A common pattern for accessing a ContentProvider from your UI uses a CursorLoader to run an asynchronous query in the background. The Activity or Fragment in your UI call a CursorLoader to the query, which in turn gets the ContentProvider using the ContentResolver. \n" +
  102. "\n" +
  103. "This allows the UI to continue to be available to the user while the query is running. This pattern involves the interaction of a number of different objects, as well as the underlying storage mechanism.\n" +
  104. "");
  105. rets.add(lesson2);
  106. Lesson lesson3 = new Lesson(2,
  107. "Content Providers: Steps to Create a C.P.",
  108. "http://designbyark.com/wp-content/uploads/2017/03/1-1024x576.png",
  109. "There are a number of simple steps involved to create your own content provider\n" +
  110. "First of all you need to create a Content Provider class that extends the ContentProviderbaseclass.\n" +
  111. "\n" +
  112. "Second, you need to define your content provider URI address which will be used to access the content.\n"+
  113. "\n" +
  114. "Next you will need to create your own database to keep the content. Usually, Android uses SQLite database and framework needs to override onCreate() method which will use SQLite Open Helper method to create or open the provider's database. \n" +
  115. "" +
  116. "When your application is launched, the onCreate() handler of each of its Content Providers is called on the main application thread.\n" +
  117. "\n" +
  118. "Next you will have to implement Content Provider queries to perform different database specific operations. \n"+
  119. "\n" +
  120. "Finally register your Content Provider in your activity file using <provider> tag. \n" +
  121. "\n" +
  122. "onCreate() This method is called when the provider is started. \n"+
  123. "\n" +
  124. "query() This method receives a request from a client. The result is returned as a Cursor object. \n" +
  125. "\n" +
  126. "insert()This method inserts a new record into the content provider.\n" +
  127. "\n" +
  128. "delete() This method deletes an existing record from the content provider.\n " +
  129. "\n" +
  130. "update() This method updates an existing record from the content provider. \n" +
  131. "\n" +
  132. "getType() This method returns the MIME type of the data at the given URI.\n" +
  133. "\n" +
  134.  
  135. "*");
  136. rets.add(lesson3);
  137. Lesson lesson4= new Lesson(3,
  138. "Content Providers: Relationship with DB ",
  139. "https://static.thenounproject.com/png/996048-200.png",
  140. "How are Content Providers related to SQLite?\n" +
  141. "\n" +
  142. "\n" +
  143. "Content providers let you centralize content in one place and have many different applications access it as needed. \n" +
  144. "\n" +
  145. "A content provider behaves very much like a database where you can query it, edit its content, as well as add or delete content using insert(), update(), delete(), and query() methods. In most cases this data is stored in an SQlite database.\n\n" +
  146. "\n" +
  147. "");
  148.  
  149. rets.add(lesson4);
  150. Lesson lesson5 = new Lesson(4,
  151. "Content Providers: Examples",
  152. " https://developer.android.com/guide/topics/providers/images/content-provider-migration.png",
  153. "Here are some Diagrams with Examples\n" +
  154. "\n" +
  155. "" );
  156. rets.add(lesson5);
  157. Lesson lesson6 = new Lesson(5,
  158. "SQLite: Introduction",
  159. "https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/SQLite370.svg/1200px-SQLite370.svg.png",
  160. "SQLite is a software library which provides a simple relational database management system that stores data in a local persistent storage on a device.\n" +
  161. "\n" +
  162. "It is the most widely deployed database in the world with several high-profile projects including being used by Airbus in their A350 aircraft projects, and Apple in their iMessage system.\n" +
  163. "\n" +
  164. "Android includes a public domain database engine called SQLite. Unlike traditional database management systems such as SQL Server or Oracle, SQLite is completely self-contained, meaning that is does not require a separate server to operate.\n" +
  165. "\n" +
  166. "When an application uses SQLite, the integration works with functional and direct calls made to a file holding the data such as the SQLite Database instead of communicating through an interface of a port or socket. \n" +
  167. "\n" +
  168. "This makes SQLite extremely agile and efficient.\n" +
  169. "\n" +
  170. "SQLite can be integrated in file based scenarios - when the entire database resides in a single file on the disk, making it an extremely portable and lightweight solution.\n" +
  171. "Despite the omission of some standard SQL features such as Right, Outer Join etc, it retains many of the same features, providing ease to those who are familiar with SQL. \n" +
  172. "Consequently, it serves as an appropriate means to conduct testing during the development phase of applications.\n" +
  173. "\n" +
  174. "\n" +
  175. "\n" +
  176. "There are a few important use cases for SQLite. \n" +
  177. "Embedded Applications:\n" +
  178. "Applications, such as mobile, television and camera apps along with gaming consoles all prioritise portability, and do not require future expansion. They will benefit from the use of SQLite as it provides fast and reliable data services to applications.\n"+
  179. "\n" +
  180. "Disk Access Replacement:\n" +
  181. "In many cases, applications that need to read/write files to disk directly can benefit from switching to SQLite for additional functionality and simplicity that comes from using the Structured Query Language(SQL).\n" +
  182. "\n" +
  183. "Testing:\n" +
  184. "It is an overkill for a large portion of applications to use an additional process for testing the business-logic (i.e. the application’s main purpose: functionality).\n" +
  185. "");
  186.  
  187. rets.add(lesson6);
  188. Lesson lesson7 = new Lesson(6,
  189. "SQLite: Features",
  190. "https://lh3.googleusercontent.com/ilhhAWDJ3xE6FzhMJ5Bob9m2qwjZIkcb_p9VCumnpmAUWGJCo_vYgFUSR3Cvw3GFtjYaBckAa07s8S7x9veT_qL_dmci9D29yxSrAjwJf9AOGFgEt5EkKeSzSqWMGkqHn6LrJau4SYHKEkvrHTJ8A8Ru4gZ2ijxp6zwQUaPURAObKIsptwHUCAd0F4FH60ntEFjvKrVdVABjBCLaaZRwmJkaWrvQauvpZph-ST7-9E04mwfuWdkQha3aG8YiJ9V4HqoS7CB8GSAGbthfMa2nL4ofzY5hAjQYOIKx7FDjP_n7zqw_WHBYJOkgOPsj3AYmAeIq9Z7DG_y4A0woCKlTvMhHFegC76jx_E2GMtUmQScCeSQBFV66C7ijcpoDc8uNJzWL_qgFRs36RCxjbhrGD1_ptd_ypOZfj2J2YC98NPk6KCLTjYBX__0knd0VYnbayjXr8h2eTnvD_DZ_nRLPG23Snc07FDuZJRXdbDwj-VUoqhT6v81FkJ83O1zqzPw1bQ9oMDMr4AaV9rqtyXObEKt2dXPtwgqkrflV2Mm1vEdpNY7CEPZcGYwFWHoB67R0IpMiKwwEtzrD37pB42jcjyV644Kn2Nvfq1S6v9DvGaOA8lXwFiRhBFCxTspqMdCB=s512-no",
  191. "SQLite is self-contained, server-less, does not need configuration and transactional.\n" +
  192. "\n" +
  193. "Self Contained:\n" +
  194. "SQLite is self-contained means it requires minimal support from the operating system or external library. This makes SQLite usable in any environments especially in embedded devices like iPhones, Android phones, game consoles, handheld media players, etc.\n" +
  195. "\n" +
  196. "Self Contained:\n" +
  197. "As SQL does not need configurations, and due to the serverless architecture, you don’t need to “install” SQLite before using it. There is no server process that needs to be configured, started, and stopped.\n" +
  198. "\n" +
  199. "Transactional:\n" +
  200. "SQlite is a transactional database that all changes and queries are atomic, consistent, isolated, and durable (ACID).\n" +
  201. "\n" +
  202. "SQLite guarantees all the transactions are ACID compliant even if the transaction is interrupted by program crash, operation system dump, or power failure to the computer" +
  203.  
  204. "");
  205.  
  206. rets.add(lesson7);
  207. Lesson lesson8 = new Lesson(7,
  208. "SQLite: Usage ",
  209. "https://lh3.googleusercontent.com/0C_x2gHakix1qE9febLxUhWCzFJ0Yr2LF-FuHX_yonYYzTanze85GLKjysKM3Ar-SjF1ind5Uj9kpUgPvSYfNU1_u85Up2Wnf4JKNrcUb_5WOuJNBrOgnbGXhzj8E1YZQwsbrQy-abmtun87luxX2vzLIF_lqb7uUh0gCC0iFUToz1y1J-_nc0FrNQKzfhXAY6din4TV70fFLQjkPcTQXpTRx2zkCLpsGmKgpNoN4crFo7HRnuHEf22yLNcGvLjgoLI6_ns5TXGlwgx6akMHdWnZusYRIgOPawA_569AetptDHeVSp-hkR2ZVknUsfObn7xnzPiq1sAjACzyMfvQUTvvQYhmXFVRYIkYoahhZjejSIm8-kc_oKCmXEmZoYHrrK6LPsDBc1CSLYhpaEeP77v_yFo_xkzTPyFtLRzymnkmHlpYCCR6cv_T_d0nOrmr5aYbLZFtHIX8jxDE8SArzDsZafBaFzT796QEEhkam3y3Q9yf92BJlp8oAJnZlfw33x9f-3PnDDGd34f3rHPqRJsanCXaZuBx9ZEnL10xc_Kv2ZXv92ihLC97uJJSxyMChlo8cKZ50IvRPANnOhcC_nGpRBJtme4PT8iiss-MnrkgYREDSTXrRPL71rWBsNCJ=s512-no",
  210. "How should we use the features of SQLite?\n" +
  211. "\n" +
  212. "SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC,ODBC etc.\n" +
  213. "\n" +
  214. "•The main package is android.database.sqlite that contains the classes to manage your own databases. \n" +
  215. "\n" +
  216. "In order to create a database you just need to call this method openOrCreateDatabase with your database name and mode as a parameter. It returns an instance of SQLite database which you have to receive in your own object. \n" +
  217. "\n" +
  218. "SQLite SELECT statement is used to fetch the data from a SQLite database table which returns data in the form of a result table. These result tables are also called result sets.\n" +
  219. "\n" +
  220. "SQLite INSERT INTO Statement is used to add new rows of data into a table in the database.\n" +
  221. "\n" +
  222. "SQLite UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows, otherwise all the rows would be updated.\n" +
  223. "\n" +
  224. "SQLite DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete the selected rows, otherwise all the records would be deleted.\n" +
  225. "\n" +
  226. " ");
  227. rets.add(lesson8);
  228. return rets;
  229.  
  230.  
  231. }
  232.  
  233.  
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement