NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.dpapayas.cukur;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;

/**
* Created by dpapayas on 9/16/15.
*/

import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dpapayas.cukur.helper.APIList;
import com.dpapayas.cukur.helper.Constant;
import com.dpapayas.cukur.model.ShopModel;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class FindBarberActivity extends FragmentActivity implements GoogleMap.OnMyLocationChangeListener, View.OnClickListener {

GoogleMap googleMap;
double latitude = 0, longitude = 0;
List<ShopModel> orderStatusList;
double destlatitude, destlongitude;

RelativeLayout relMenuDesc, relMenuReview, relMenuQueue;
LinearLayout relDescription, relReview, relQueue;

TextView tvHarga, tvTitleCompany, tvAlamatCompany, listItem1, listItem2;

ArrayList<HashMap<String, String>> hashMapArrayList = new ArrayList<HashMap<String, String>>();

Button btnPilih;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (!isGooglePlayServicesAvailable()) {
finish();
}
setContentView(R.layout.layout_find_barber);

relMenuDesc = (RelativeLayout) findViewById(R.id.relMenuDesc);
relMenuReview = (RelativeLayout) findViewById(R.id.relMenuReview);
relMenuQueue = (RelativeLayout) findViewById(R.id.relMenuQueue);
relDescription = (LinearLayout) findViewById(R.id.relDescription);
relReview = (LinearLayout) findViewById(R.id.relReview);
relQueue = (LinearLayout)findViewById(R.id.relQueue);
tvTitleCompany = (TextView) findViewById(R.id.tvTitleCompany);
tvAlamatCompany = (TextView) findViewById(R.id.tvAlamatCompany);
listItem1 = (TextView) findViewById(R.id.listItem1);
listItem2 = (TextView) findViewById(R.id.listItem2);

relMenuDesc.setOnClickListener(this);
relMenuReview.setOnClickListener(this);
relMenuQueue.setOnClickListener(this);

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

if (status != ConnectionResult.SUCCESS) {

int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();

} else {

SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);

googleMap = fm.getMap();

ArrayList<Pair<Double, Double>> arrayListMaps = new ArrayList<>();
arrayListMaps.add(new Pair<Double, Double>(-8.698850, 115.177574));
arrayListMaps.add(new Pair<Double, Double>(-8.699868, 115.186501));

for (int i = 0; i < 2; i++) {
googleMap.addMarker(new MarkerOptions().position(new LatLng(arrayListMaps.get(i).first, arrayListMaps.get(i).second)).icon(BitmapDescriptorFactory.fromResource(R.drawable.lampu_merah2)).title("Barber " + i));
}

googleMap.setMyLocationEnabled(true);



googleMap.setOnMyLocationChangeListener(this);



}


}

private boolean isGooglePlayServicesAvailable() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (ConnectionResult.SUCCESS == status) {
return true;
} else {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
return false;
}
}

@Override
public void onMyLocationChange(Location location) {

if (latitude != 0 && longitude != 0) {

googleMap.clear();

latitude = location.getLatitude();

longitude = location.getLongitude();

LatLng latLng = new LatLng(latitude, longitude);

MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Current Location");

googleMap.addMarker(marker);

ArrayList<Pair<Double, Double>> arrayListMaps = new ArrayList<>();
arrayListMaps.add(new Pair<Double, Double>(-8.698850, 115.177574));
arrayListMaps.add(new Pair<Double, Double>(-8.699868, 115.186501));

for (int i = 0; i < 2; i++) {
googleMap.addMarker(new MarkerOptions().position(new LatLng(arrayListMaps.get(i).first, arrayListMaps.get(i).second)).icon(BitmapDescriptorFactory.fromResource(R.drawable.lampu_merah2)).title("Barber " + i));
}

// new GetMap().execute();

FindBarber();
} else {

googleMap.clear();

latitude = location.getLatitude();

longitude = location.getLongitude();



LatLng latLng = new LatLng(latitude, longitude);

MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Current Location");

googleMap.addMarker(marker);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

ArrayList<Pair<Double, Double>> arrayListMaps = new ArrayList<>();
arrayListMaps.add(new Pair<Double, Double>(-8.698850, 115.177574));
arrayListMaps.add(new Pair<Double, Double>(-8.699868, 115.186501));

for (int i = 0; i < 2; i++) {
googleMap.addMarker(new MarkerOptions().position(new LatLng(arrayListMaps.get(i).first, arrayListMaps.get(i).second)).icon(BitmapDescriptorFactory.fromResource(R.drawable.lampu_merah2)).title("Barber " + i));
}

// new GetMap().execute();

FindBarber();
}

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnPilih:

savePreferences("currentLatitude", String.valueOf(latitude));
savePreferences("currentLongitude", String.valueOf(longitude));
savePreferences("destLatitude", String.valueOf(destlatitude));
savePreferences("destLongitude", String.valueOf(destlongitude));

Intent intent = new Intent(FindBarberActivity.this, HairStyleActivity.class);
startActivity(intent);

break;

case R.id.relMenuDesc:

relMenuQueue.setBackground(getResources().getDrawable(R.drawable.border_white));
relMenuDesc.setBackground(getResources().getDrawable(R.drawable.border_grey));
relMenuReview.setBackground(getResources().getDrawable(R.drawable.border_white));

relDescription.setVisibility(View.VISIBLE);
relReview.setVisibility(View.INVISIBLE);
relQueue.setVisibility(View.INVISIBLE);


break;

case R.id.relMenuReview:

relMenuQueue.setBackground(getResources().getDrawable(R.drawable.border_white));
relMenuDesc.setBackground(getResources().getDrawable(R.drawable.border_white));
relMenuReview.setBackground(getResources().getDrawable(R.drawable.border_grey));

relDescription.setVisibility(View.INVISIBLE);
relReview.setVisibility(View.VISIBLE);
relQueue.setVisibility(View.INVISIBLE);

break;

case R.id.relMenuQueue:
relMenuQueue.setBackground(getResources().getDrawable(R.drawable.border_grey));
relMenuDesc.setBackground(getResources().getDrawable(R.drawable.border_white));
relMenuReview.setBackground(getResources().getDrawable(R.drawable.border_white));

relDescription.setVisibility(View.INVISIBLE);
relReview.setVisibility(View.INVISIBLE);
relQueue.setVisibility(View.VISIBLE);
break;
}
}

public void DeserializeJson(String json) {
JSONArray contacts = null;
try {
contacts = new JSONArray(json);
ArrayList<Pair<Double, Double>> arrayListMaps = new ArrayList<>();
arrayListMaps.add(new Pair<Double, Double>(-8.698850, 115.177574));
arrayListMaps.add(new Pair<Double, Double>(-8.699868, 115.186501));

for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);

String ShopName = c.getString("ShopName");
String EmailAddress = c.getString("EmailAddress");
String PhoneNumber = c.getString("PhoneNumber");
String addresses = c.getString("addresses");

JSONArray address = new JSONArray(addresses);

JSONObject cs = address.getJSONObject(0);

String AddressDesc = cs.getString("AddressDesc");
String Coordinate = cs.getString("Coordinate");

HashMap<String, String> map = new HashMap<String, String>();
map.put("ShopName", ShopName);
map.put("EmailAddress", EmailAddress);
map.put("PhoneNumber", PhoneNumber);
map.put("AddressDesc", AddressDesc);
map.put("Coordinate", Coordinate);

hashMapArrayList.add(map);

}

for (int i = 0; i < hashMapArrayList.size(); i++) {
String[] latlong = hashMapArrayList.get(i).get("Coordinate").split(", ");
destlatitude = Double.parseDouble(latlong[0]);
destlongitude = Double.parseDouble(latlong[1]);

googleMap.addMarker(new MarkerOptions().position(new LatLng(arrayListMaps.get(i).first, arrayListMaps.get(i).second)).icon(BitmapDescriptorFactory.fromResource(R.drawable.lampu_merah2)).title(hashMapArrayList.get(i).get("ShopName")));
}

// googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
// @Override
// public boolean onMarkerClick(Marker marker) {
// marker.getPosition();
// for (int i = 0; i < hashMapArrayList.size(); i++) {
// tvTitleCompany.setText(hashMapArrayList.get(i).get("ShopName"));
// tvAlamatCompany.setText(hashMapArrayList.get(i).get("AddressDesc"));
// listItem1.setText(hashMapArrayList.get(i).get("EmailAddress"));
// listItem2.setText(hashMapArrayList.get(i).get("PhoneNumber"));
//
// savePreferences("titleCompany", tvTitleCompany.getText().toString());
// }
// return false;
// }
// });
} catch (JSONException e) {
e.printStackTrace();
}
}

private void savePreferences(String key, String value) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
}

private void FindBarber() {

final RestAdapter restadapter = new RestAdapter.Builder().setEndpoint(Constant.ROOT_URL).build();

APIList orderStatusAPI = restadapter.create(APIList.class);

orderStatusAPI.getDataShop(

String.valueOf(latitude),
String.valueOf(longitude),
"100",

new Callback<Response>() {
@Override
public void success(Response result, Response response) {

BufferedReader reader = null;

String output = "";

try {

reader = new BufferedReader(new InputStreamReader(result.getBody().in()));

output = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}

// Toast.makeText(FindBarberActivity.this, output, Toast.LENGTH_LONG).show();

// getIdSaveToPreferences(output);

DeserializeJson(output);


}

@Override
public void failure(RetrofitError error) {
// Toast.makeText(FindBarberActivity.this, "", Toast.LENGTH_LONG).show();
}
}
);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.