Guest User

Untitled

a guest
Mar 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.11 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. private DrawerLayout mDrawer ;
  3. private ActionBarDrawerToggle mToggle;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. mDrawer = (DrawerLayout) findViewById(R.id.drawer);
  10. mToggle = new ActionBarDrawerToggle(this,mDrawer,R.string.open,R.string.close);
  11. mDrawer.addDrawerListener(mToggle);
  12. NavigationView nvDrawer = (NavigationView) findViewById(R.id.nv);
  13. mToggle.syncState();
  14. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  15. setupDrawerContent(nvDrawer);
  16. }
  17.  
  18. @Override
  19. public boolean onOptionsItemSelected(MenuItem item) {
  20. if (mToggle.onOptionsItemSelected(item)){
  21. return true ;
  22. }
  23. return super.onOptionsItemSelected(item);
  24. }
  25.  
  26. public void selectItemDrawer(MenuItem menuItem){
  27. Fragment myFragment = null;
  28. Class fragmentclass;
  29. switch (menuItem.getItemId()){
  30. case R.id.drive:
  31. fragmentclass = Driving.class;
  32. break;
  33. case R.id.test:
  34. fragmentclass = Tests.class;
  35. break;
  36. case R.id.rules:
  37. fragmentclass = Rules.class;
  38. break;
  39. case R.id.sign:
  40. fragmentclass = Road.class;
  41. break;
  42. case R.id.faq:
  43. fragmentclass = faq.class;
  44. break;
  45. case R.id.like:
  46. fragmentclass = llike.class;
  47. break;
  48. default:
  49. fragmentclass = faq.class;
  50. }
  51. try {
  52. myFragment = (Fragment) fragmentclass.newInstance();
  53. }
  54. catch (Exception e) {
  55. e.printStackTrace();
  56. }
  57. FragmentManager fragmentManager = getSupportFragmentManager();
  58. fragmentManager.beginTransaction().replace(R.id.lt,myFragment).commit();
  59. menuItem.setChecked(true);
  60. setTitle(menuItem.getTitle());
  61. mDrawer.closeDrawers();
  62.  
  63.  
  64. }
  65. private void setupDrawerContent (NavigationView navigationView){
  66. navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
  67. @Override
  68. public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  69. selectItemDrawer(item);
  70.  
  71. return true;
  72. }
  73. });
  74. }
  75. }
  76. `
  77.  
  78. public class Tests extends Fragment {
  79. // TODO: Rename parameter arguments, choose names that match
  80. // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
  81. private static final String ARG_PARAM1 = "param1";
  82. private static final String ARG_PARAM2 = "param2";
  83.  
  84. // TODO: Rename and change types of parameters
  85. private String mParam1;
  86. private String mParam2;
  87.  
  88. private OnFragmentInteractionListener mListener;
  89.  
  90. public Tests() {
  91. // Required empty public constructor
  92. }
  93.  
  94. /**
  95. * Use this factory method to create a new instance of
  96. * this fragment using the provided parameters.
  97. *
  98. * @param param1 Parameter 1.
  99. * @param param2 Parameter 2.
  100. * @return A new instance of fragment Tests.
  101. */
  102. // TODO: Rename and change types and number of parameters
  103. public static Tests newInstance(String param1, String param2) {
  104. Tests fragment = new Tests();
  105. Bundle args = new Bundle();
  106. args.putString(ARG_PARAM1, param1);
  107. args.putString(ARG_PARAM2, param2);
  108. fragment.setArguments(args);
  109. return fragment;
  110. }
  111.  
  112. @Override
  113. public void onCreate(Bundle savedInstanceState) {
  114. super.onCreate(savedInstanceState);
  115. if (getArguments() != null) {
  116. mParam1 = getArguments().getString(ARG_PARAM1);
  117. mParam2 = getArguments().getString(ARG_PARAM2);
  118. }
  119. }
  120.  
  121. @Override
  122. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  123. Bundle savedInstanceState) {
  124. // Inflate the layout for this fragment
  125. View view = inflater.inflate(R.layout.fragment_tests, container, false);
  126. Button btnV = (Button) view.findViewById(R.id.Vehicle);
  127. Button btnM = (Button) view.findViewById(R.id.Bike);
  128. Button btnT = (Button) view.findViewById(R.id.Truck);
  129. btnV.setOnClickListener(new View.OnClickListener() {
  130.  
  131. @Override
  132. public void onClick(View v) {
  133. // TODO Auto-generated method stub
  134. Intent i = new Intent(getActivity(), VehicleActivity.class);
  135. startActivity(i);
  136. }
  137. });
  138.  
  139. btnM.setOnClickListener(new View.OnClickListener() {
  140.  
  141. @Override
  142. public void onClick(View v) {
  143. // TODO Auto-generated method stub
  144. Intent i = new Intent(getActivity(), MotorbikeActivity.class);
  145. startActivity(i);
  146. }
  147. });
  148.  
  149. btnT.setOnClickListener(new View.OnClickListener() {
  150.  
  151. @Override
  152. public void onClick(View v) {
  153. // TODO Auto-generated method stub
  154. Intent i = new Intent(getActivity(), TruckActivity.class);
  155. startActivity(i);
  156. }
  157. });
  158.  
  159.  
  160. return view;
  161.  
  162. }
  163.  
  164. // TODO: Rename method, update argument and hook method into UI event
  165. public void onButtonPressed(Uri uri) {
  166. if (mListener != null) {
  167. mListener.onFragmentInteraction(uri);
  168. }
  169. }
  170.  
  171. @Override
  172. public void onAttach(Context context) {
  173. super.onAttach(context);
  174.  
  175. }
  176.  
  177. @Override
  178. public void onDetach() {
  179. super.onDetach();
  180. mListener = null;
  181. }
  182.  
  183. /**
  184. * This interface must be implemented by activities that contain this
  185. * fragment to allow an interaction in this fragment to be communicated
  186. * to the activity and potentially other fragments contained in that
  187. * activity.
  188. * <p>
  189. * See the Android Training lesson <a href=
  190. * "http://developer.android.com/training/basics/fragments/communicating.html"
  191. * >Communicating with Other Fragments</a> for more information.
  192. */
  193. public interface OnFragmentInteractionListener {
  194. // TODO: Update argument type and name
  195. void onFragmentInteraction(Uri uri);
  196. }
  197. }
  198.  
  199. <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  200. xmlns:app="http://schemas.android.com/apk/res-auto"
  201. xmlns:tools="http://schemas.android.com/tools"
  202. android:id="@+id/drawer"
  203. android:layout_width="match_parent"
  204. android:layout_height="match_parent"
  205. tools:context="com.maiweb.mohammed.vayasa.MainActivity">
  206.  
  207. <RelativeLayout
  208. android:layout_width="match_parent"
  209. android:layout_height="match_parent"
  210. android:id="@+id/lt"
  211.  
  212.  
  213. >
  214.  
  215. <TextView
  216. android:id="@+id/textView2"
  217. android:layout_width="wrap_content"
  218. android:layout_height="wrap_content"
  219. android:fontFamily="cursive"
  220. android:text="About Us
  221. "
  222. android:textSize="36sp" />
  223.  
  224. <TextView
  225. android:id="@+id/textView6"
  226. android:layout_width="wrap_content"
  227. android:layout_height="wrap_content"
  228. android:layout_alignParentStart="true"
  229. android:layout_below="@+id/textView2"
  230. android:text="Vaya SA is an application that is aimed at providing a learner’s licence test simulation as well as providing you with names of accredited driving schools in your area."
  231. android:textStyle="bold" />
  232.  
  233. </RelativeLayout>
  234. <android.support.design.widget.NavigationView
  235. android:id="@+id/nv"
  236. app:headerLayout="@layout/header"
  237. android:layout_width="wrap_content"
  238. android:layout_height="match_parent"
  239. app:menu="@menu/drawermenu"
  240. android:layout_gravity="start"
  241.  
  242. >
  243.  
  244.  
  245.  
  246.  
  247. </android.support.design.widget.NavigationView>
  248.  
  249.  
  250.  
  251.  
  252. </android.support.v4.widget.DrawerLayout>
  253.  
  254. `<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  255. xmlns:tools="http://schemas.android.com/tools"
  256. android:layout_width="match_parent"
  257. android:layout_height="match_parent"
  258. tools:context="com.maiweb.mohammed.vayasa.Tests">
  259.  
  260.  
  261. <TextView
  262. android:id="@+id/textView"
  263. android:layout_width="wrap_content"
  264. android:layout_height="wrap_content"
  265. android:text="Please Choose the test you would like to take"
  266. android:textColor="#0000ff"
  267. android:textSize="40sp" />
  268.  
  269.  
  270. <Button
  271. android:id="@+id/Vehicle"
  272. android:layout_width="match_parent"
  273. android:layout_height="wrap_content"
  274. android:layout_alignStart="@+id/Bike"
  275. android:layout_below="@+id/Bike"
  276. android:layout_marginTop="15dp"
  277. android:background="@drawable/background_round_corner_button"
  278. android:text="Vehicle Test" />
  279.  
  280. <Button
  281. android:id="@+id/Bike"
  282. android:layout_width="match_parent"
  283. android:layout_height="wrap_content"
  284. android:layout_alignStart="@+id/Truck"
  285. android:layout_below="@+id/Truck"
  286. android:layout_marginTop="13dp"
  287. android:background="@drawable/background_round_corner_button"
  288. android:text="Motorbike Test" />
  289.  
  290. <Button
  291. android:id="@+id/Truck"
  292. android:layout_width="match_parent"
  293. android:layout_height="wrap_content"
  294. android:layout_alignParentEnd="true"
  295. android:layout_below="@+id/textView"
  296. android:layout_marginTop="68dp"
  297. android:background="@drawable/background_round_corner_button"
  298. android:text="Truck Test" />
  299.  
  300.  
  301. </RelativeLayout>
Add Comment
Please, Sign In to add comment