Advertisement
cristi9512

Untitled

Mar 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.70 KB | None | 0 0
  1. //// Receiver Activity
  2.  
  3. package com.example.cristinica.foodhelper;
  4.  
  5. import android.net.Uri;
  6. import android.support.v4.view.ViewPager;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9.  
  10. public class ReceiverActivity extends AppCompatActivity implements AskForFood.OnFragmentInteractionListener, SearchFood.OnFragmentInteractionListener {
  11. ViewPager view_pager;
  12. ReceivrPageAdapter adapter;
  13. public static SlidingTabLayout tabs;
  14. CharSequence Titles[] = {"Evenimente", "Adauga"};
  15. int Numboftabs = 2;
  16.  
  17. @Override
  18. protected void onCreate(Bundle savedInstanceState) {
  19. super.onCreate(savedInstanceState);
  20. setContentView(R.layout.activity_receiver);
  21.  
  22. /// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
  23. adapter = new ReceivrPageAdapter(getSupportFragmentManager(), Titles, Numboftabs);
  24.  
  25. // Assigning ViewPager View and setting the adapter
  26. view_pager = (ViewPager) findViewById(R.id.view_pagerHome);
  27. view_pager.setAdapter(adapter);
  28. //seteaza cate pagini vor fi retinute! daca vrem sa avem refresh de fiecare data trebuie setata la 0
  29. view_pager.setOffscreenPageLimit(2);
  30.  
  31.  
  32. // Assiging the Sliding Tab Layout View
  33. tabs = (SlidingTabLayout) findViewById(R.id.tabsHome);
  34. tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
  35. tabs.setCustomTabView(R.layout.custom_tab, 0);
  36. // Setting Custom Color for the Scroll bar indicator of the Tab View
  37. tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
  38. @Override
  39. public int getIndicatorColor(int position) {
  40. return getResources().getColor(R.color.white);
  41. }
  42. });
  43.  
  44. // Setting the ViewPager For the SlidingTabsLayout
  45. tabs.setViewPager(view_pager);
  46.  
  47.  
  48. }
  49.  
  50.  
  51. @Override
  52. public void onFragmentInteraction(Uri uri) {
  53.  
  54. }
  55. }
  56.  
  57.  
  58.  
  59. //// ReceivrPageAdapter
  60.  
  61.  
  62. package com.example.cristinica.foodhelper;
  63.  
  64. import android.support.v4.app.Fragment;
  65. import android.support.v4.app.FragmentManager;
  66. import android.support.v4.app.FragmentStatePagerAdapter;
  67.  
  68. /**
  69. * Created by cristi.nica on 3/24/2018.
  70. */
  71.  
  72. public class ReceivrPageAdapter extends FragmentStatePagerAdapter {
  73.  
  74. private int[] imageResId = {
  75.  
  76. };
  77. private static final String[] CONTENT = new String[] { "SEARCH", "ASK"};
  78. CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
  79. int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
  80.  
  81.  
  82. // Build a Constructor and assign the passed Values to appropriate values in the class
  83. public ReceivrPageAdapter(FragmentManager fm, CharSequence mTitles[], int mNumbOfTabsumb) {
  84. super(fm);
  85.  
  86. this.Titles = mTitles;
  87. this.NumbOfTabs = mNumbOfTabsumb;
  88.  
  89. }
  90.  
  91. //This method return the fragment for the every position in the View Pager
  92. @Override
  93. public Fragment getItem(int position) {
  94. if (position == 0) // if the position is 0 we are returning the First tab
  95. {
  96. SearchFood tab1 = new SearchFood();
  97. return tab1;
  98. }
  99. if (position == 1) // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab
  100. {
  101. AskForFood tab2 = new AskForFood();
  102. return tab2;
  103. }
  104.  
  105. return null;
  106.  
  107.  
  108. }
  109.  
  110. // This method return the titles for the Tabs in the Tab Strip
  111.  
  112.  
  113. @Override
  114. public CharSequence getPageTitle(int position) {
  115.  
  116.  
  117. return CONTENT[position % CONTENT.length].toUpperCase();
  118. }
  119.  
  120. // This method return the Number of tabs for the tabs Strip
  121.  
  122. @Override
  123. public int getCount() {
  124. return NumbOfTabs;
  125. }
  126. }
  127.  
  128.  
  129.  
  130. /// REGISTER
  131.  
  132. package com.example.cristinica.foodhelper;
  133.  
  134.  
  135. import android.annotation.SuppressLint;
  136. import android.content.Context;
  137. import android.content.Intent;
  138. import android.content.SharedPreferences;
  139. import android.os.AsyncTask;
  140. import android.os.Bundle;
  141. import android.support.v7.app.AppCompatActivity;
  142. import android.util.Log;
  143. import android.view.View;
  144. import android.widget.Button;
  145. import android.widget.EditText;
  146.  
  147. import com.example.cristinica.foodhelper.apiConnector.RegisterApi;
  148. import com.example.cristinica.foodhelper.models.LoginModel;
  149.  
  150. import com.example.cristinica.foodhelper.models.RegisterModel;
  151. import com.google.gson.Gson;
  152. import com.google.gson.reflect.TypeToken;
  153.  
  154. import java.util.ArrayList;
  155.  
  156. public class Register extends AppCompatActivity {
  157.  
  158. @Override
  159. protected void onCreate(Bundle savedInstanceState) {
  160. super.onCreate(savedInstanceState);
  161. setContentView(R.layout.activity_register);
  162. final EditText companyName = findViewById(R.id.firstName);
  163. final EditText companyMail = findViewById(R.id.email);
  164. final EditText pass = findViewById(R.id.password);
  165.  
  166. Button register = findViewById(R.id.register2);
  167. SharedPreferences sharedPreferences = Register.this.getSharedPreferences("type", Context
  168. .MODE_PRIVATE);
  169. //final SharedPreferences.Editor editor = sharedPreferences.edit();
  170. final int type = sharedPreferences.getInt("type", -1);
  171.  
  172. if (type == 0) {
  173. register.setBackgroundDrawable(getResources().getDrawable(R.drawable.round));
  174. } else if (type == 1) {
  175. register.setBackgroundDrawable(getResources().getDrawable(R.drawable.round2));
  176. } else {
  177. }
  178.  
  179.  
  180. register.setOnClickListener(new View.OnClickListener() {
  181. @Override
  182. public void onClick(View view) {
  183. @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
  184. RegisterModel registerModel = new RegisterModel();
  185.  
  186. @Override
  187. protected Void doInBackground(Void... params) {
  188. String s = RegisterApi.register(companyMail.getText().toString(), companyName.getText().toString(), pass.getText().toString(), 1);
  189. Log.v("am primit", s);
  190. Gson g = new Gson();
  191. registerModel = g.fromJson(s, RegisterModel.class);
  192. return null;
  193. }
  194.  
  195. protected void onPostExecute(Void param) {
  196. if (registerModel.status.equals("ok")) {
  197. if (type == 0) {
  198. Intent intent = new Intent(Register.this, GiverActivity.class);
  199. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  200. startActivity(intent);
  201. } else if (type == 1) {
  202. Intent intent = new Intent(Register.this, ReceiverActivity.class);
  203. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  204. startActivity(intent);
  205. }
  206. } else {
  207.  
  208. }
  209. }
  210.  
  211. };
  212. task.execute();
  213. }
  214. });
  215. }
  216. }
  217.  
  218.  
  219.  
  220. ////// SearchFood
  221. package com.example.cristinica.foodhelper;
  222.  
  223. /**
  224. * Created by cristi.nica on 3/24/2018.
  225. */
  226.  
  227. import android.annotation.SuppressLint;
  228. import android.content.Context;
  229. import android.net.Uri;
  230. import android.os.AsyncTask;
  231. import android.os.Bundle;
  232. import android.support.v4.app.Fragment;
  233. import android.support.v4.widget.SwipeRefreshLayout;
  234. import android.support.v7.widget.DefaultItemAnimator;
  235. import android.support.v7.widget.LinearLayoutManager;
  236. import android.support.v7.widget.RecyclerView;
  237. import android.view.LayoutInflater;
  238. import android.view.View;
  239. import android.view.ViewGroup;
  240.  
  241. import com.example.cristinica.foodhelper.models.Companys;
  242.  
  243. import java.util.ArrayList;
  244.  
  245.  
  246. /**
  247. * A simple {@link Fragment} subclass.
  248. * Activities that contain this fragment must implement the
  249. * {@link FoodFragment.OnFragmentInteractionListener} interface
  250. * to handle interaction events.
  251. * Use the {@link FoodFragment#newInstance} factory method to
  252. * create an instance of this fragment.
  253. */
  254.  
  255.  
  256. public class SearchFood extends Fragment {
  257.  
  258. private RecyclerView.LayoutManager layoutManager;
  259. SwipeRefreshLayout swipeRefreshLayout;
  260. CustomAdapter adapter;
  261. RecyclerView recyclerView;
  262. View view;
  263. static public ArrayList<Companys> events = new ArrayList<Companys>();
  264.  
  265. // TODO: Rename parameter arguments, choose names that match
  266. // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
  267. private static final String ARG_PARAM1 = "param1";
  268. private static final String ARG_PARAM2 = "param2";
  269.  
  270. // TODO: Rename and change types of parameters
  271. private String mParam1;
  272. private String mParam2;
  273.  
  274. private OnFragmentInteractionListener mListener;
  275.  
  276. public SearchFood() {
  277. // Required empty public constructor
  278. }
  279.  
  280. /**
  281. * Use this factory method to create a new instance of
  282. * this fragment using the provided parameters.
  283. *
  284. * @param param1 Parameter 1.
  285. * @param param2 Parameter 2.
  286. * @return A new instance of fragment FoodFragment.
  287. */
  288. // TODO: Rename and change types and number of parameters
  289. public static FoodFragment newInstance(String param1, String param2) {
  290. FoodFragment fragment = new FoodFragment();
  291. Bundle args = new Bundle();
  292. args.putString(ARG_PARAM1, param1);
  293. args.putString(ARG_PARAM2, param2);
  294. fragment.setArguments(args);
  295. return fragment;
  296. }
  297.  
  298. @Override
  299. public void onCreate(Bundle savedInstanceState) {
  300. super.onCreate(savedInstanceState);
  301. if (getArguments() != null) {
  302. mParam1 = getArguments().getString(ARG_PARAM1);
  303. mParam2 = getArguments().getString(ARG_PARAM2);
  304. }
  305. }
  306.  
  307. @Override
  308. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  309. Bundle savedInstanceState) {
  310. // Inflate the layout for this fragment
  311. view = inflater.inflate(R.layout.fragment_search_food, container, false);
  312. recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
  313. swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
  314.  
  315. Companys companys1 = new Companys();
  316. companys1.loginModel.adresa="test";
  317. companys1.loginModel.telefon="test";
  318. companys1.loginModel.nume="test";
  319. companys1.loginModel.nume_reprezentant="test";
  320.  
  321. Companys companys2 = new Companys();
  322. companys2.loginModel.adresa="test";
  323. companys2.loginModel.telefon="test";
  324. companys2.loginModel.nume="test";
  325. companys2.loginModel.nume_reprezentant="test";
  326. ArrayList<Companys> arr = new ArrayList<>();
  327. arr.add(companys1);
  328. arr.add(companys2);
  329.  
  330.  
  331.  
  332. recyclerView.setHasFixedSize(true);
  333.  
  334. layoutManager = new LinearLayoutManager(getContext());
  335. recyclerView.setLayoutManager(layoutManager);
  336. recyclerView.setItemAnimator(new DefaultItemAnimator());
  337.  
  338.  
  339. // removedItems = new ArrayList<Integer>();
  340.  
  341. adapter = new CustomAdapter(arr);
  342. recyclerView.setAdapter(adapter);
  343.  
  344.  
  345.  
  346. @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
  347.  
  348.  
  349. @Override
  350. protected Void doInBackground(Void... params) {
  351. /* String s = ApiConnectionGetEvents.getEvents();
  352.  
  353. Log.v("am primit la get Events", s);
  354. Gson g = new Gson();
  355. events = g.fromJson(s, new TypeToken<ArrayList<Event>>(){}.getType());*/
  356.  
  357.  
  358. return null;
  359. }
  360.  
  361. @Override
  362. protected void onPostExecute(Void aVoid) {
  363.  
  364. /*super.onPostExecute(aVoid);
  365.  
  366. Log.v("lista mea",events.get(0).toString());
  367. recyclerView.setHasFixedSize(true);
  368.  
  369. layoutManager = new LinearLayoutManager(getContext());
  370. recyclerView.setLayoutManager(layoutManager);
  371. recyclerView.setItemAnimator(new DefaultItemAnimator());*/
  372.  
  373.  
  374. // removedItems = new ArrayList<Integer>();
  375.  
  376. // adapter = new CustomAdapter(events);
  377. // recyclerView.setAdapter(adapter);
  378.  
  379. }
  380. };
  381.  
  382. // task.execute();
  383.  
  384.  
  385. swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  386. @Override
  387. public void onRefresh() {
  388.  
  389. }
  390. });
  391.  
  392. return view;
  393.  
  394. }
  395.  
  396. // TODO: Rename method, update argument and hook method into UI event
  397. public void onButtonPressed(Uri uri) {
  398. if (mListener != null) {
  399. mListener.onFragmentInteraction(uri);
  400. }
  401. }
  402.  
  403. @Override
  404. public void onAttach(Context context) {
  405. super.onAttach(context);
  406. if (context instanceof OnFragmentInteractionListener) {
  407. mListener = (OnFragmentInteractionListener) context;
  408. } else {
  409. throw new RuntimeException(context.toString()
  410. + " must implement OnFragmentInteractionListener");
  411. }
  412. }
  413.  
  414. @Override
  415. public void onDetach() {
  416. super.onDetach();
  417. mListener = null;
  418. }
  419.  
  420. /**
  421. * This interface must be implemented by activities that contain this
  422. * fragment to allow an interaction in this fragment to be communicated
  423. * to the activity and potentially other fragments contained in that
  424. * activity.
  425. * <p>
  426. * See the Android Training lesson <a href=
  427. * "http://developer.android.com/training/basics/fragments/communicating.html"
  428. * >Communicating with Other Fragments</a> for more information.
  429. */
  430. public interface OnFragmentInteractionListener {
  431. // TODO: Update argument type and name
  432. void onFragmentInteraction(Uri uri);
  433. }
  434. }
  435.  
  436.  
  437. ///// SettingsActivity
  438.  
  439. package com.example.cristinica.foodhelper;
  440.  
  441. import android.support.v7.app.AppCompatActivity;
  442. import android.os.Bundle;
  443.  
  444. public class SettingsActivity extends AppCompatActivity {
  445.  
  446. @Override
  447. protected void onCreate(Bundle savedInstanceState) {
  448. super.onCreate(savedInstanceState);
  449. setContentView(R.layout.activity_settings);
  450. }
  451. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement