Example usage for com.google.gson GsonBuilder GsonBuilder

List of usage examples for com.google.gson GsonBuilder GsonBuilder

Introduction

In this page you can find the example usage for com.google.gson GsonBuilder GsonBuilder.

Prototype

public GsonBuilder() 

Source Link

Document

Creates a GsonBuilder instance that can be used to build Gson with various configuration settings.

Usage

From source file:ca.ualberta.cs.drivr.MapController.java

License:Apache License

/**
 * Passing in two points, json them to new request activity
 * @param pickupLatlng LatLng point//www  .  j a va2s  . c  o  m
 * @param destinationLatLng LatLng point
 */

public void createRequest(LatLng pickupLatlng, LatLng destinationLatLng) {

    ConcretePlace pickupPlace = markerGeocodePlace(pickupLatlng);
    ConcretePlace destinationPlace = markerGeocodePlace(destinationLatLng);

    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

    Intent intent = new Intent(mContext, NewRequestActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String concretePlaceJsonPick = gson.toJson(pickupPlace);
    String concretePlaceJsonDest = gson.toJson(destinationPlace);

    intent.putExtra(NewRequestActivity.EXTRA_PLACE, concretePlaceJsonDest);
    Log.i(TAG, "Place: " + destinationPlace.getName() + ", :" + destinationPlace.getLatLng());

    intent.putExtra("PICK_UP", concretePlaceJsonPick);
    Log.i(TAG, "Place: " + pickupPlace.getName() + ", :" + pickupPlace.getLatLng());

    mContext.startActivity(intent);

    // Request request = new Request(userManager.getUser(), new ConcretePlace(pickupAddress), new ConcretePlace(destinationAddress));
    //requestsListController.addRequest(request);

}

From source file:ca.ualberta.cs.drivr.NewRequestActivity.java

License:Apache License

/**
 * This method initializes the activity by deserializing the JSON given to it to get the
 * selected destination place and shows that place on the screen. Listeners are also setup for
 * UI elements./*from   w  w w  . j  av a 2  s.c o m*/
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_request);

    // Setup controllers
    requestsListController = new RequestsListController(userManager);

    // Get the intent arguments
    String destinationJson = getIntent().getStringExtra(EXTRA_PLACE);
    if (destinationJson != null) {
        Log.i(TAG, destinationJson);
        try {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            destinationPlace = gson.fromJson(destinationJson, ConcretePlace.class);
        } catch (JsonSyntaxException ex) {
            destinationPlace = null;
        }
    }

    String pickupJson = getIntent().getStringExtra("PICK_UP");
    if (pickupJson != null) {
        Log.i(TAG, pickupJson);
        try {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            sourcePlace = gson.fromJson(pickupJson, ConcretePlace.class);
        } catch (JsonSyntaxException ex) {
            sourcePlace = null;
        }
    }

    // Show the destination information
    updateDestinationPlace(destinationPlace);

    if (sourcePlace != null) {
        updateSourcePlace(sourcePlace);
        estimateFare(destinationPlace, sourcePlace);
    }

    // Setup listener for selecting a new destination
    final PlaceAutocompleteFragment destinationPAF = (PlaceAutocompleteFragment) getFragmentManager()
            .findFragmentById(R.id.new_request_place_dest_autocomplete);
    destinationPAF.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            updateDestinationPlace(place);
            estimateFare(sourcePlace, destinationPlace);
        }

        @Override
        public void onError(Status status) {
            // Do nothing
        }
    });

    // Setup listener for selecting a new source
    final PlaceAutocompleteFragment sourcePAF = (PlaceAutocompleteFragment) getFragmentManager()
            .findFragmentById(R.id.new_request_place_source_autocomplete);
    sourcePAF.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            updateSourcePlace(place);
            estimateFare(sourcePlace, destinationPlace);
        }

        @Override
        public void onError(Status status) {
            // Do nothing
        }
    });

    // Hide the source text until we put something there
    if (sourcePlace == null) {
        findViewById(R.id.new_request_place_source_name).setVisibility(View.GONE);
        findViewById(R.id.new_request_place_source_address).setVisibility(View.GONE);
    }

    // Setup listener for the create button
    final Button createButton = (Button) findViewById(R.id.new_request_create_button);
    createButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            generateRequest();
        }
    });

    // Setup listeners for changes to the fare
    final EditText fareEditText = (EditText) findViewById(R.id.new_request_fare_edit_text);
    fareEditText.addTextChangedListener(new MoneyTextWatcher(fareEditText));
}

From source file:ca.ualberta.cs.drivr.NewRequestActivity.java

License:Apache License

/**
 * Generates a item_request from the input data and places it in the requests list. A successful call
 * to this method will terminate the activity. An unsuccessful call to this method will display
 * a message on the screen to tell the user what went wrong.
 */// ww  w  .  ja va 2 s  .  com
private void generateRequest() {
    if (!placeHasCompleteInformation(sourcePlace)) {
        Toast.makeText(this, "The starting location is not set.", Toast.LENGTH_LONG).show();
        return;
    }
    if (!placeHasCompleteInformation(destinationPlace)) {
        Toast.makeText(this, "The destination location is not set.", Toast.LENGTH_LONG).show();
        return;
    }

    final EditText descriptionEditText = (EditText) findViewById(R.id.new_request_description_edit_text);
    final EditText fareEditText = (EditText) findViewById(R.id.new_request_fare_edit_text);

    final String description = descriptionEditText.getText().toString();
    final String fareString = fareEditText.getText().toString().replaceAll("[$,]", "");

    // Make the request and store it in the model
    User user = userManager.getUser();
    Request request = new Request(user, sourcePlace, destinationPlace);
    request.setDescription(description);
    request.setFareString(fareString);

    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
    String requestString = gson.toJson(request, Request.class);
    Intent intent = new Intent(NewRequestActivity.this, RequestActivity.class);
    intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString);
    intent.putExtra("UniqueID", "From_NewRequestActivity");
    // TODO startActivityForResult() confirm if user presses accept or deny
    // startActivityForResult(intent, );
    startActivity(intent);

    //userManager.getRequestsList().add(request);
    //userManager.notifyObservers();
    Log.i(TAG + "kjdfgkjdfhkhj", request.getRequestState().toString());
    //        requestsListController.addRequest(request);

    //        finish();
}

From source file:ca.ualberta.cs.drivr.RequestActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_request);

    // Get context
    mContext = getApplicationContext();/* w  ww . j a  v  a2  s  . c om*/

    // Get views
    routeText = (TextView) findViewById(R.id.request_route_text);
    fareText = (TextView) findViewById(R.id.request_fare_text);
    acceptButton = (TextView) findViewById(R.id.request_accept_text);
    declineButton = (TextView) findViewById(R.id.request_decline_text);
    buttonSeparator = findViewById(R.id.request_button_divider);

    // map = findViewById(R.id.request_map_fragment);

    String requestString = getIntent().getStringExtra(EXTRA_REQUEST);
    //        Gson gson = new Gson();
    //        ConcretePlace concretePlace = new ConcretePlace(place);
    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
    final Request request = gson.fromJson(requestString, Request.class);
    sourcePlace = request.getSourcePlace();
    destinationPlace = request.getDestinationPlace();

    fareText.setText("$" + request.getFareString());
    routeText.setText(request.getRoute());

    // TODO make a map with these points and the route between them
    mapFragment = (SupportMapFragment) this.getSupportFragmentManager()
            .findFragmentById(R.id.request_map_fragment);
    mapFragment.getMapAsync(this);

    Log.i("RequestActivity", "HIT");

    setupAcceptAndDeclineButtons(request.getRequestState(), userManager.getUserMode());

    acceptButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            RequestState state = request.getRequestState();
            if (state.equals(RequestState.CREATED)) {
                request.setRequestState(RequestState.PENDING);
                RequestsListController requestsListController = new RequestsListController(
                        UserManager.getInstance());
                requestsListController.addRequest(request);
                UserManager.getInstance().notifyObservers();
                ElasticSearchController.AddRequest addRequest = new ElasticSearchController.AddRequest();
                addRequest.execute(request);
            }
            RequestController requestController = new RequestController(userManager);
            if (requestController.canAcceptRequest(request, userManager.getUserMode())) {
                Log.i(TAG, "attempting to accept request");
                requestController.acceptRequest(request, getApplicationContext());
            } else if (requestController.canConfirmRequest(request, userManager.getUserMode())) {
                requestController.confirmRequest(request, getApplicationContext());
            } else if (requestController.canCompleteRequest(request, userManager.getUserMode())) {
                requestController.completeRequest(request, getApplicationContext());
            }

            Intent intent = new Intent(RequestActivity.this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

            Log.i("Request State:", request.getRequestState().toString());
        }
    });

    declineButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}

From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java

License:Apache License

/**
 * Called when the view holder is wants to bind the request at a certain position in the list.
 * @param viewHolder// w  w w  .j av  a  2  s .  c o  m
 * @param position
 */
@Override
public void onBindViewHolder(final RequestsListAdapter.ViewHolder viewHolder, final int position) {
    final Request request = requestsToDisplay.get(position);

    // Get the views to update
    final TextView otherUserNameTextView = viewHolder.otherUserNameTextView;
    final TextView descriptionTextView = viewHolder.descriptionTextView;
    final TextView fareTextView = viewHolder.fareTextView;
    final TextView routeTextView = viewHolder.routeTextView;
    final TextView statusTextView = viewHolder.statusTextView;
    final ImageView callImageView = viewHolder.callImageView;
    final ImageView emailImageView = viewHolder.emailImageView;
    final ImageView checkImageView = viewHolder.checkMarkImageView;
    final ImageView deleteImageView = viewHolder.xMarkImageView;

    // Todo Hide Image Views until correct Request State
    if (request.getRequestState() != RequestState.CONFIRMED) {
        checkImageView.setVisibility(View.INVISIBLE);
    }

    if (request.getRequestState() != RequestState.PENDING) {
        deleteImageView.setVisibility(View.INVISIBLE);
    }

    // Show the other person's name
    final DriversList drivers = request.getDrivers();

    // Get the username of the other user
    if (userManager.getUserMode() == UserMode.RIDER) {
        final String multipleDrivers = "Multiple Drivers Accepted";
        final String driverUsername = drivers.size() == 1 ? drivers.get(0).getUsername() : "No Driver Yet";
        otherUserNameTextView.setText(drivers.size() > 1 ? multipleDrivers : driverUsername);
    } else {
        otherUserNameTextView.setText(request.getRider().getUsername());
    }

    // If the request has a description, show it. Otherwise, hide te description
    if (Strings.isNullOrEmpty(request.getDescription()))
        descriptionTextView.setVisibility(View.GONE);
    else
        descriptionTextView.setText(request.getDescription());

    // Show the fare
    fareTextView.setText("$" + request.getFareString());

    // Show the route
    routeTextView.setText(request.getRoute());

    // Driver User
    otherUserNameTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String otherUsername = otherUserNameTextView.getText().toString();
            // there exists drivers
            if (otherUsername != "No Driver Yet") {
                if (otherUsername != "Multiple Drivers Accepted") {
                    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

                    ElasticSearch elasticSearch = new ElasticSearch(
                            UserManager.getInstance().getConnectivityManager());
                    User user = elasticSearch.loadUser(otherUsername);

                    String driverString = gson.toJson(user, User.class);
                    Intent intent = new Intent(context, DriverProfileActivity.class);
                    intent.putExtra(DriverProfileActivity.DRIVER, driverString);
                    context.startActivity(intent);
                } else {
                    startMultipleDriverIntent(request);
                }
            }
        }
    });

    routeTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            String requestString = gson.toJson(request, Request.class);
            Intent intent = new Intent(context, RequestActivity.class);
            intent.putExtra("UniqueID", "From_RequestListActivity");
            intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString);
            context.startActivity(intent);
        }
    });

    // Show the status text
    statusTextView.setText(request.getRequestState().toString());

    // Add a listener to the call image
    callImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver number available at this time", Toast.LENGTH_SHORT).show();

            }
            // Start Dialer
            else if (drivers.size() == 1) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                String number;
                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    number = drivers.get(0).getPhoneNumber();
                } else {
                    number = request.getRider().getPhoneNumber();
                }
                number = "tel:" + number;
                intent.setData(Uri.parse(number));
                if (ActivityCompat.checkSelfPermission(context,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                context.startActivity(intent);

            } else {

                startMultipleDriverIntent(request);
            }
        }
    });

    // Add a listener to the email image
    emailImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver email available at this time", Toast.LENGTH_SHORT).show();

            }
            //http://stackoverflow.com/questions/8701634/send-email-intent
            else if (drivers.size() == 1) {

                Intent intent = new Intent();
                ComponentName emailApp = intent.resolveActivity(context.getPackageManager());
                ComponentName unsupportedAction = ComponentName
                        .unflattenFromString("com.android.fallback/.Fallback");
                boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);
                String email;

                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    email = drivers.get(0).getEmail();
                } else {
                    email = request.getRider().getEmail();
                }
                String subject = "Drivr Request: " + request.getId();
                String body = "Drivr user " + drivers.get(0).getUsername();

                if (hasEmailApp) {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
                    context.startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
                } else {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
                }
            } else {
                startMultipleDriverIntent(request);

            }
        }
    });

    // Complete The Request
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, RequestCompletedActivity.class);
            intent.putExtra(RequestCompletedActivity.REQUEST_ID_EXTRA, request.getId());
            context.startActivity(intent);
        }
    });

    deleteImageView.setOnClickListener(new View.OnClickListener() {

        // Todo Delete the Request
        @Override
        public void onClick(View v) {
            v.getContext();
            ElasticSearch elasticSearch = new ElasticSearch(
                    (ConnectivityManager) v.getContext().getSystemService(Context.CONNECTIVITY_SERVICE));
            elasticSearch.deleteRequest(request.getId());
            UserManager userManager = UserManager.getInstance();
            userManager.getRequestsList().removeById(request);
            userManager.notifyObservers();
            requestsToDisplay.remove(request);
            notifyItemRemoved(viewHolder.getAdapterPosition());
        }
    });
}

From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java

License:Apache License

public void startMultipleDriverIntent(Request request) {
    Intent intent = new Intent(context, DisplayDriverListActivity.class);
    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
    String requestString = gson.toJson(request, Request.class);
    intent.putExtra("REQUEST", requestString);
    context.startActivity(intent);/*  w  w  w .j a va2  s. c  o m*/

}

From source file:ca.ualberta.cs.drivr.SearchRequestActivity.java

License:Apache License

/**
 * This method initializes the activity by deserializing the JSON given to it to get the
 * selected destination place and shows that place on the screen. Listeners are also setup for
 * UI elements./*  w ww  . j ava  2  s. co  m*/
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_request);

    // Setup controllers
    //        requestsListController = new RequestsListController(userManager);

    // Get the intent arguments
    String destinationJson = getIntent().getStringExtra(EXTRA_PLACE);
    if (!destinationJson.isEmpty()) {
        Log.i(TAG, destinationJson);
        try {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            searchPlace = gson.fromJson(destinationJson, ConcretePlace.class);
        } catch (JsonSyntaxException ex) {
            searchPlace = null;
        }

        // Show the destination information
        //        updateDestinationPlace(destinationPlace);
        updateSearchPlace(searchPlace);
    }

    keyword = getIntent().getStringExtra(EXTRA_KEYWORD);
    final EditText keywordEditText = (EditText) findViewById(R.id.keyword_search_edit_text);
    if (!keyword.isEmpty()) {
        //            keywordEditText.setText(keyword);
        TextView textView = (TextView) findViewById(R.id.search_keyword_name);
        textView.setText(keyword);

    }

    //        keywordEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    //            @Override
    //            public void onFocusChange(View v, boolean hasFocus) {
    //                if (!keywordEditText.getText().toString().isEmpty()) {
    //                    TextView textView = (TextView) findViewById(R.id.search_keyword_name);
    //                    textView.setText(keywordEditText.getText().toString());
    //                }
    //            }
    //        });

    keywordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                TextView textView = (TextView) findViewById(R.id.search_keyword_name);
                textView.setText(keywordEditText.getText().toString());
                keywordEditText.clearFocus();
            }
            return true;
        }
    });

    // Setup listener for selecting a new destination
    final PlaceAutocompleteFragment destinationPAF = (PlaceAutocompleteFragment) getFragmentManager()
            .findFragmentById(R.id.search_place_autocomplete);
    destinationPAF.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            updateSearchPlace(place);
            //                estimateFare(sourcePlace,destinationPlace);
        }

        @Override
        public void onError(Status status) {
            // Do nothing
        }
    });

    priceRangeBar = (RangeBar) findViewById(R.id.price_rangebar);
    pricePerRangeBar = (RangeBar) findViewById(R.id.priceper_rangebar);

    priceTextView = (TextView) findViewById(R.id.price_range_text);
    priceTextView.setText("Find Requests between $" + minPrice + " and $" + maxPrice);
    priceRangeBar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
        @Override
        public void onRangeChangeListener(RangeBar rangeBar, int leftPinIndex, int rightPinIndex,
                String leftPinValue, String rightPinValue) {
            minPrice = leftPinValue;
            maxPrice = rightPinValue;
            //                TextView textView = (TextView) findViewById(R.id.price_range_text);
            priceTextView.setText("Find Requests between $" + minPrice + " and $" + maxPrice);
        }
    });

    pricePerTextView = (TextView) findViewById(R.id.priceper_range_text);
    pricePerTextView.setText("Find Requests between $" + minPricePer + " and $" + maxPricePer + " per KM");
    pricePerRangeBar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
        @Override
        public void onRangeChangeListener(RangeBar rangeBar, int leftPinIndex, int rightPinIndex,
                String leftPinValue, String rightPinValue) {
            minPricePer = leftPinValue;
            maxPricePer = rightPinValue;
            //                TextView textView = (TextView) findViewById(R.id.priceper_range_text);
            pricePerTextView
                    .setText("Find Requests between $" + minPricePer + " and $" + maxPricePer + " per KM");
        }
    });

    //        // Setup listener for selecting a new source
    //        final PlaceAutocompleteFragment sourcePAF =
    //                (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.new_request_place_source_autocomplete);
    //        sourcePAF.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    //            @Override
    //            public void onPlaceSelected(Place place) {
    //                updateSourcePlace(place);
    //                estimateFare(sourcePlace,destinationPlace);
    //            }
    //
    //            @Override
    //            public void onError(Status status) {
    //                // Do nothing
    //            }
    //        });

    //        // Hide the source text until we put something there
    //        findViewById(R.id.new_request_place_source_name).setVisibility(View.GONE);
    //        findViewById(R.id.new_request_place_source_address).setVisibility(View.GONE);

    // Setup listener for the create button
    final Button createButton = (Button) findViewById(R.id.request_search_button);
    createButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //                generateRequest();
            searchRequest();
        }
    });

    //        // Setup listeners for changes to the fare
    //        final EditText fareEditText = (EditText) findViewById(R.id.new_request_fare_edit_text);
    //        fareEditText.addTextChangedListener(new MoneyTextWatcher(fareEditText));
}

From source file:ca.ualberta.cs.drivr.SearchRequestActivity.java

License:Apache License

private void searchRequest() {
    //        Log.i(TAG, minPricePer);
    SearchRequest searchRequest = new SearchRequest(minPrice, maxPrice, minPricePer, maxPricePer, searchPlace,
            keyword);/*from w w  w .ja  v  a  2 s.c  o m*/

    //        ConcretePlace concretePlace = new ConcreteP;
    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
    //        Intent intent = new Intent(MainActivity.this, NewRequestActivity.class);
    String searchRequestJson = gson.toJson(searchRequest);

    SearchRequest newSearchRequest = gson.fromJson(searchRequestJson, SearchRequest.class);
    Intent intent = new Intent(SearchRequestActivity.this, SearchRequestsListActivity.class);
    intent.putExtra(SearchRequestsListActivity.EXTRA_SEARCH_REQUEST, searchRequestJson);
    //            Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng());
    startActivity(intent);

    finish();
}

From source file:ca.ualberta.cs.drivr.SearchRequestsListActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_requests_list);

    // Setup the RecyclerView
    RecyclerView requestsListRecyclerView = (RecyclerView) findViewById(R.id.requests_list_recycler);
    RequestsListAdapter adapter;//  www. j  a v  a2 s .  c om
    String searchRequestJson = getIntent().getStringExtra(EXTRA_SEARCH_REQUEST);
    try {
        Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
        searchRequest = gson.fromJson(searchRequestJson, SearchRequest.class);
    } catch (JsonSyntaxException ex) {
        Log.i(TAG, "json error");
    }

    adapter = new RequestsListAdapter(this, searchRequest.getRequests(getApplicationContext()), userManager);

    requestsListRecyclerView.setAdapter(adapter);
    requestsListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}

From source file:ca.ualberta.cs.drivr.UserManager.java

License:Apache License

private static void loadUser() {
    try {/*from   www  .ja va 2s.c  om*/
        if (instance == null)
            instance = new UserManager();
        FileInputStream fis = App.getContext().openFileInput(SAVE_FILENAME_USER);
        BufferedReader in = new BufferedReader(new InputStreamReader(fis));
        Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
        instance.user = gson.fromJson(in, User.class);
        if (instance == null)
            throw new FileNotFoundException();
    } catch (FileNotFoundException e) {
        instance.user = new User();
    }
}