Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //// Receiver Activity
- package com.example.cristinica.foodhelper;
- import android.net.Uri;
- import android.support.v4.view.ViewPager;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- public class ReceiverActivity extends AppCompatActivity implements AskForFood.OnFragmentInteractionListener, SearchFood.OnFragmentInteractionListener {
- ViewPager view_pager;
- ReceivrPageAdapter adapter;
- public static SlidingTabLayout tabs;
- CharSequence Titles[] = {"Evenimente", "Adauga"};
- int Numboftabs = 2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_receiver);
- /// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
- adapter = new ReceivrPageAdapter(getSupportFragmentManager(), Titles, Numboftabs);
- // Assigning ViewPager View and setting the adapter
- view_pager = (ViewPager) findViewById(R.id.view_pagerHome);
- view_pager.setAdapter(adapter);
- //seteaza cate pagini vor fi retinute! daca vrem sa avem refresh de fiecare data trebuie setata la 0
- view_pager.setOffscreenPageLimit(2);
- // Assiging the Sliding Tab Layout View
- tabs = (SlidingTabLayout) findViewById(R.id.tabsHome);
- tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width
- tabs.setCustomTabView(R.layout.custom_tab, 0);
- // Setting Custom Color for the Scroll bar indicator of the Tab View
- tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
- @Override
- public int getIndicatorColor(int position) {
- return getResources().getColor(R.color.white);
- }
- });
- // Setting the ViewPager For the SlidingTabsLayout
- tabs.setViewPager(view_pager);
- }
- @Override
- public void onFragmentInteraction(Uri uri) {
- }
- }
- //// ReceivrPageAdapter
- package com.example.cristinica.foodhelper;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.app.FragmentStatePagerAdapter;
- /**
- * Created by cristi.nica on 3/24/2018.
- */
- public class ReceivrPageAdapter extends FragmentStatePagerAdapter {
- private int[] imageResId = {
- };
- private static final String[] CONTENT = new String[] { "SEARCH", "ASK"};
- CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created
- int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created
- // Build a Constructor and assign the passed Values to appropriate values in the class
- public ReceivrPageAdapter(FragmentManager fm, CharSequence mTitles[], int mNumbOfTabsumb) {
- super(fm);
- this.Titles = mTitles;
- this.NumbOfTabs = mNumbOfTabsumb;
- }
- //This method return the fragment for the every position in the View Pager
- @Override
- public Fragment getItem(int position) {
- if (position == 0) // if the position is 0 we are returning the First tab
- {
- SearchFood tab1 = new SearchFood();
- return tab1;
- }
- 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
- {
- AskForFood tab2 = new AskForFood();
- return tab2;
- }
- return null;
- }
- // This method return the titles for the Tabs in the Tab Strip
- @Override
- public CharSequence getPageTitle(int position) {
- return CONTENT[position % CONTENT.length].toUpperCase();
- }
- // This method return the Number of tabs for the tabs Strip
- @Override
- public int getCount() {
- return NumbOfTabs;
- }
- }
- /// REGISTER
- package com.example.cristinica.foodhelper;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import com.example.cristinica.foodhelper.apiConnector.RegisterApi;
- import com.example.cristinica.foodhelper.models.LoginModel;
- import com.example.cristinica.foodhelper.models.RegisterModel;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import java.util.ArrayList;
- public class Register extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- final EditText companyName = findViewById(R.id.firstName);
- final EditText companyMail = findViewById(R.id.email);
- final EditText pass = findViewById(R.id.password);
- Button register = findViewById(R.id.register2);
- SharedPreferences sharedPreferences = Register.this.getSharedPreferences("type", Context
- .MODE_PRIVATE);
- //final SharedPreferences.Editor editor = sharedPreferences.edit();
- final int type = sharedPreferences.getInt("type", -1);
- if (type == 0) {
- register.setBackgroundDrawable(getResources().getDrawable(R.drawable.round));
- } else if (type == 1) {
- register.setBackgroundDrawable(getResources().getDrawable(R.drawable.round2));
- } else {
- }
- register.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
- RegisterModel registerModel = new RegisterModel();
- @Override
- protected Void doInBackground(Void... params) {
- String s = RegisterApi.register(companyMail.getText().toString(), companyName.getText().toString(), pass.getText().toString(), 1);
- Log.v("am primit", s);
- Gson g = new Gson();
- registerModel = g.fromJson(s, RegisterModel.class);
- return null;
- }
- protected void onPostExecute(Void param) {
- if (registerModel.status.equals("ok")) {
- if (type == 0) {
- Intent intent = new Intent(Register.this, GiverActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- } else if (type == 1) {
- Intent intent = new Intent(Register.this, ReceiverActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- }
- } else {
- }
- }
- };
- task.execute();
- }
- });
- }
- }
- ////// SearchFood
- package com.example.cristinica.foodhelper;
- /**
- * Created by cristi.nica on 3/24/2018.
- */
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.net.Uri;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v4.widget.SwipeRefreshLayout;
- import android.support.v7.widget.DefaultItemAnimator;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import com.example.cristinica.foodhelper.models.Companys;
- import java.util.ArrayList;
- /**
- * A simple {@link Fragment} subclass.
- * Activities that contain this fragment must implement the
- * {@link FoodFragment.OnFragmentInteractionListener} interface
- * to handle interaction events.
- * Use the {@link FoodFragment#newInstance} factory method to
- * create an instance of this fragment.
- */
- public class SearchFood extends Fragment {
- private RecyclerView.LayoutManager layoutManager;
- SwipeRefreshLayout swipeRefreshLayout;
- CustomAdapter adapter;
- RecyclerView recyclerView;
- View view;
- static public ArrayList<Companys> events = new ArrayList<Companys>();
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
- // TODO: Rename and change types of parameters
- private String mParam1;
- private String mParam2;
- private OnFragmentInteractionListener mListener;
- public SearchFood() {
- // Required empty public constructor
- }
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment FoodFragment.
- */
- // TODO: Rename and change types and number of parameters
- public static FoodFragment newInstance(String param1, String param2) {
- FoodFragment fragment = new FoodFragment();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- view = inflater.inflate(R.layout.fragment_search_food, container, false);
- recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
- swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
- Companys companys1 = new Companys();
- companys1.loginModel.adresa="test";
- companys1.loginModel.telefon="test";
- companys1.loginModel.nume="test";
- companys1.loginModel.nume_reprezentant="test";
- Companys companys2 = new Companys();
- companys2.loginModel.adresa="test";
- companys2.loginModel.telefon="test";
- companys2.loginModel.nume="test";
- companys2.loginModel.nume_reprezentant="test";
- ArrayList<Companys> arr = new ArrayList<>();
- arr.add(companys1);
- arr.add(companys2);
- recyclerView.setHasFixedSize(true);
- layoutManager = new LinearLayoutManager(getContext());
- recyclerView.setLayoutManager(layoutManager);
- recyclerView.setItemAnimator(new DefaultItemAnimator());
- // removedItems = new ArrayList<Integer>();
- adapter = new CustomAdapter(arr);
- recyclerView.setAdapter(adapter);
- @SuppressLint("StaticFieldLeak") AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- /* String s = ApiConnectionGetEvents.getEvents();
- Log.v("am primit la get Events", s);
- Gson g = new Gson();
- events = g.fromJson(s, new TypeToken<ArrayList<Event>>(){}.getType());*/
- return null;
- }
- @Override
- protected void onPostExecute(Void aVoid) {
- /*super.onPostExecute(aVoid);
- Log.v("lista mea",events.get(0).toString());
- recyclerView.setHasFixedSize(true);
- layoutManager = new LinearLayoutManager(getContext());
- recyclerView.setLayoutManager(layoutManager);
- recyclerView.setItemAnimator(new DefaultItemAnimator());*/
- // removedItems = new ArrayList<Integer>();
- // adapter = new CustomAdapter(events);
- // recyclerView.setAdapter(adapter);
- }
- };
- // task.execute();
- swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- }
- });
- return view;
- }
- // TODO: Rename method, update argument and hook method into UI event
- public void onButtonPressed(Uri uri) {
- if (mListener != null) {
- mListener.onFragmentInteraction(uri);
- }
- }
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
- if (context instanceof OnFragmentInteractionListener) {
- mListener = (OnFragmentInteractionListener) context;
- } else {
- throw new RuntimeException(context.toString()
- + " must implement OnFragmentInteractionListener");
- }
- }
- @Override
- public void onDetach() {
- super.onDetach();
- mListener = null;
- }
- /**
- * This interface must be implemented by activities that contain this
- * fragment to allow an interaction in this fragment to be communicated
- * to the activity and potentially other fragments contained in that
- * activity.
- * <p>
- * See the Android Training lesson <a href=
- * "http://developer.android.com/training/basics/fragments/communicating.html"
- * >Communicating with Other Fragments</a> for more information.
- */
- public interface OnFragmentInteractionListener {
- // TODO: Update argument type and name
- void onFragmentInteraction(Uri uri);
- }
- }
- ///// SettingsActivity
- package com.example.cristinica.foodhelper;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- public class SettingsActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_settings);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement