正在查看: St.John's v1.0.9 应用的 MapPlacePickerActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: St.John's v1.0.9 应用的 MapPlacePickerActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mcb.stjohnsemschool.activity;
import android.animation.Animator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.location.Location;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.common.api.ResolvableApiException;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResponse;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.libraries.places.api.Places;
import com.google.android.libraries.places.api.model.AutocompletePrediction;
import com.google.android.libraries.places.api.model.AutocompleteSessionToken;
import com.google.android.libraries.places.api.model.Place;
import com.google.android.libraries.places.api.net.FetchPlaceRequest;
import com.google.android.libraries.places.api.net.FetchPlaceResponse;
import com.google.android.libraries.places.api.net.FindAutocompletePredictionsRequest;
import com.google.android.libraries.places.api.net.FindAutocompletePredictionsResponse;
import com.google.android.libraries.places.api.net.PlacesClient;
import com.mancj.materialsearchbar.MaterialSearchBar;
import com.mancj.materialsearchbar.adapter.SuggestionsAdapter;
import com.mcb.stjohnsemschool.model.SavingResponseModel;
import com.mcb.stjohnsemschool.services.ApiClient;
import com.mcb.stjohnsemschool.services.ApiInterface;
import com.mcb.stjohnsemschool.utils.CustomButton;
import com.mcb.stjohnsemschool.utils.CustomTextView;
import com.mcb.stjohnsemschool.utils.FetchAddressIntentService;
import com.mcb.stjohnsemschool.utils.TransparentProgressDialog;
import com.mcb.stjohnsemschool.utils.Utility;
import com.skyfishjy.library.RippleBackground;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MapPlacePickerActivity extends AppCompatActivity implements OnMapReadyCallback {
private static final String TAG = "MapPlacePickerActivity";
private Activity activity;
private String addressOutput;
private int addressResultCode;
private Context context;
private LatLng currentMarkerPosition;
private boolean isSupportedArea;
private LocationCallback locationCallback;
private CustomTextView mDisplayAddressTextView;
private FusedLocationProviderClient mFusedLocationProviderClient;
private Location mLAstKnownLocation;
private GoogleMap mMap;
private ProgressBar mProgressBar;
private TransparentProgressDialog mProgressbar;
private ImageView mSmallPinIv;
private View mapView;
private MaterialSearchBar materialSearchBar;
private PlacesClient placesClient;
private List<AutocompletePrediction> predictionList;
private RippleBackground rippleBg;
private final float DEFAULT_ZOOM = 17.0f;
private String[] mSupportedArea = new String[0];
private String mLanguage = "en";
public native String PlacesAPIKey();
static {
System.loadLibrary("keys");
}
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_map_place_picker);
this.context = getApplicationContext();
this.activity = this;
this.mProgressbar = new TransparentProgressDialog(this.activity, R.drawable.spinner_loading_imag);
initViews();
initMapsAndPlaces();
}
private void initViews() {
this.materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
CustomButton findViewById = findViewById(R.id.submit_location_button);
this.rippleBg = findViewById(R.id.ripple_bg);
this.mDisplayAddressTextView = findViewById(R.id.tv_display_marker_location);
this.mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
this.mSmallPinIv = (ImageView) findViewById(R.id.small_pin);
final View findViewById2 = findViewById(R.id.ic_pin);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
MapPlacePickerActivity.this.revealView(findViewById2);
}
}, 1000L);
findViewById.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MapPlacePickerActivity.this.submitResultLocation();
}
});
}
private void initMapsAndPlaces() {
this.mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient((Activity) this);
Places.initialize(this, PlacesAPIKey());
this.placesClient = Places.createClient(this);
AutocompleteSessionToken newInstance = AutocompleteSessionToken.newInstance();
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
mapFragment.getMapAsync(this);
this.mapView = mapFragment.getView();
this.materialSearchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
@Override
public void onSearchStateChanged(boolean z) {
}
@Override
public void onSearchConfirmed(CharSequence charSequence) {
MapPlacePickerActivity.this.startSearch(charSequence.toString(), true, null, true);
}
@Override
public void onButtonClicked(int i) {
if (i == 3) {
MapPlacePickerActivity.this.materialSearchBar.disableSearch();
MapPlacePickerActivity.this.materialSearchBar.clearSuggestions();
}
}
});
this.materialSearchBar.addTextChangeListener(new AnonymousClass4(newInstance));
this.materialSearchBar.setSuggestionsClickListener(new AnonymousClass5());
}
class AnonymousClass4 implements TextWatcher {
final AutocompleteSessionToken val$token;
@Override
public void afterTextChanged(Editable editable) {
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
AnonymousClass4(AutocompleteSessionToken autocompleteSessionToken) {
this.val$token = autocompleteSessionToken;
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
MapPlacePickerActivity.this.placesClient.findAutocompletePredictions(FindAutocompletePredictionsRequest.builder().setSessionToken(this.val$token).setQuery(charSequence.toString()).build()).addOnCompleteListener(new OnCompleteListener<FindAutocompletePredictionsResponse>() {
@Override
public void onComplete(Task<FindAutocompletePredictionsResponse> task) {
if (!task.isSuccessful()) {
Log.i(MapPlacePickerActivity.TAG, "prediction fetching task unSuccessful");
return;
}
FindAutocompletePredictionsResponse result = task.getResult();
if (result != null) {
MapPlacePickerActivity.this.predictionList = result.getAutocompletePredictions();
ArrayList arrayList = new ArrayList();
for (int i4 = 0; i4 < MapPlacePickerActivity.this.predictionList.size(); i4++) {
arrayList.add(((AutocompletePrediction) MapPlacePickerActivity.this.predictionList.get(i4)).getFullText(null).toString());
}
MapPlacePickerActivity.this.materialSearchBar.updateLastSuggestions(arrayList);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (MapPlacePickerActivity.this.materialSearchBar.isSuggestionsVisible()) {
return;
}
MapPlacePickerActivity.this.materialSearchBar.showSuggestionsList();
}
}, 1000L);
}
}
});
}
}
class AnonymousClass5 implements SuggestionsAdapter.OnItemViewClickListener {
@Override
public void OnItemDeleteListener(int i, View view) {
}
AnonymousClass5() {
}
@Override
public void OnItemClickListener(int i, View view) {
if (i >= MapPlacePickerActivity.this.predictionList.size()) {
return;
}
AutocompletePrediction autocompletePrediction = (AutocompletePrediction) MapPlacePickerActivity.this.predictionList.get(i);
MapPlacePickerActivity.this.materialSearchBar.setText(MapPlacePickerActivity.this.materialSearchBar.getLastSuggestions().get(i).toString());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
MapPlacePickerActivity.this.materialSearchBar.clearSuggestions();
}
}, 1000L);
InputMethodManager inputMethodManager = (InputMethodManager) MapPlacePickerActivity.this.getSystemService("input_method");
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(MapPlacePickerActivity.this.materialSearchBar.getWindowToken(), 1);
}
MapPlacePickerActivity.this.placesClient.fetchPlace(FetchPlaceRequest.builder(autocompletePrediction.getPlaceId(), Arrays.asList(Place.Field.LAT_LNG, Place.Field.NAME, Place.Field.ADDRESS)).build()).addOnSuccessListener(new OnSuccessListener<FetchPlaceResponse>() {
@Override
public void onSuccess(FetchPlaceResponse fetchPlaceResponse) {
Place place = fetchPlaceResponse.getPlace();
Log.i(MapPlacePickerActivity.TAG, "place found " + place.getName() + place.getAddress());
LatLng latLng = place.getLatLng();
if (latLng != null) {
MapPlacePickerActivity.this.mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17.0f));
}
MapPlacePickerActivity.this.rippleBg.startRippleAnimation();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
MapPlacePickerActivity.this.rippleBg.stopRippleAnimation();
}
}, AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception exc) {
if (exc instanceof ApiException) {
ApiException apiException = (ApiException) exc;
apiException.printStackTrace();
int statusCode = apiException.getStatusCode();
Log.i(MapPlacePickerActivity.TAG, "place not found" + exc.getMessage());
Log.i(MapPlacePickerActivity.TAG, "status code : " + statusCode);
}
}
});
}
}
public void submitResultLocation() {
if (this.addressResultCode == 1 || !this.isSupportedArea) {
Toast.makeText((Context) this, (CharSequence) getString(R.string.failed_select_location), 0).show();
} else {
saveNearestLocation(this.addressOutput, this.currentMarkerPosition.latitude, this.currentMarkerPosition.longitude);
}
}
private void saveNearestLocation(String str, double d, double d2) {
ConnectivityManager connectivityManager = (ConnectivityManager) this.context.getSystemService("connectivity");
if (connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isAvailable() && connectivityManager.getActiveNetworkInfo().isConnected()) {
saveStudentNearestLocation(str, d, d2);
} else {
Toast.makeText(this.context, "Check your Network Connection", 0).show();
}
}
private void saveStudentNearestLocation(final String str, final double d, final double d2) {
TransparentProgressDialog transparentProgressDialog = this.mProgressbar;
if (transparentProgressDialog != null && !transparentProgressDialog.isShowing()) {
this.mProgressbar.show();
}
SharedPreferences sharedPreferences = this.context.getSharedPreferences("", 0);
final SharedPreferences.Editor edit = sharedPreferences.edit();
String string = sharedPreferences.getString("studentEnrollmentIdKey", "0");
HashMap hashMap = new HashMap();
hashMap.put("StudentEnrollmentID", string);
hashMap.put("NearestLocation", str);
hashMap.put("latitude", String.valueOf(d));
hashMap.put("longitude", String.valueOf(d2));
hashMap.put("apikey", Utility.getSchoolApiKey(this.context));
((ApiInterface) ApiClient.getClient1(this.context).create(ApiInterface.class)).SaveStudentNearestLocation(hashMap).enqueue(new Callback<SavingResponseModel>() {
public void onResponse(Call<SavingResponseModel> call, Response<SavingResponseModel> response) {
if (MapPlacePickerActivity.this.mProgressbar != null && MapPlacePickerActivity.this.mProgressbar.isShowing()) {
MapPlacePickerActivity.this.mProgressbar.dismiss();
}
if (response == null || response.body() == null) {
Utility.showAlertDialog(MapPlacePickerActivity.this.activity);
return;
}
SavingResponseModel savingResponseModel = (SavingResponseModel) response.body();
int intValue = savingResponseModel.getStatus().intValue();
String message = savingResponseModel.getMessage();
if (intValue != 1) {
Utility.showInfoDialog(MapPlacePickerActivity.this.activity, message);
return;
}
edit.putString("Current_Nearest_Location", str);
edit.putString("Current_Latitude", String.valueOf(d));
edit.putString("Current_Longitude", String.valueOf(d2));
edit.commit();
MapPlacePickerActivity.this.finish();
}
public void onFailure(Call<SavingResponseModel> call, Throwable th) {
if (MapPlacePickerActivity.this.mProgressbar != null && MapPlacePickerActivity.this.mProgressbar.isShowing()) {
MapPlacePickerActivity.this.mProgressbar.dismiss();
}
Utility.showAlertDialog(MapPlacePickerActivity.this.activity);
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.mMap = googleMap;
googleMap.setMyLocationEnabled(true);
this.mMap.getUiSettings().setMyLocationButtonEnabled(true);
this.mMap.getUiSettings().setCompassEnabled(false);
View view = this.mapView;
if (view != null && view.findViewById(Integer.parseInt("1")) != null) {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) ((View) this.mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2")).getLayoutParams();
layoutParams.addRule(10, 0);
layoutParams.addRule(12, -1);
layoutParams.setMargins(0, 0, 60, 500);
}
LocationRequest create = LocationRequest.create();
create.setInterval(1000L);
create.setFastestInterval(DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
create.setPriority(100);
Task<LocationSettingsResponse> checkLocationSettings = LocationServices.getSettingsClient((Activity) this).checkLocationSettings(new LocationSettingsRequest.Builder().addLocationRequest(create).build());
checkLocationSettings.addOnSuccessListener(new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
MapPlacePickerActivity.this.getDeviceLocation();
}
});
checkLocationSettings.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception exc) {
if (exc instanceof ResolvableApiException) {
try {
((ResolvableApiException) exc).startResolutionForResult(MapPlacePickerActivity.this, 51);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
});
this.mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
if (MapPlacePickerActivity.this.materialSearchBar.isSuggestionsVisible()) {
MapPlacePickerActivity.this.materialSearchBar.clearSuggestions();
}
if (!MapPlacePickerActivity.this.materialSearchBar.isSearchEnabled()) {
return false;
}
MapPlacePickerActivity.this.materialSearchBar.disableSearch();
return false;
}
});
this.mMap.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
@Override
public void onCameraIdle() {
MapPlacePickerActivity.this.mSmallPinIv.setVisibility(8);
MapPlacePickerActivity.this.mProgressBar.setVisibility(0);
Log.i(MapPlacePickerActivity.TAG, "changing address");
MapPlacePickerActivity.this.startIntentService();
}
});
}
protected void onActivityResult(int i, int i2, Intent intent) {
super.onActivityResult(i, i2, intent);
if (i == 51 && i2 == -1) {
getDeviceLocation();
}
}
public void getDeviceLocation() {
this.mFusedLocationProviderClient.getLastLocation().addOnCompleteListener(new OnCompleteListener<Location>() {
@Override
public void onComplete(Task<Location> task) {
if (task.isSuccessful()) {
MapPlacePickerActivity.this.mLAstKnownLocation = task.getResult();
if (MapPlacePickerActivity.this.mLAstKnownLocation != null) {
MapPlacePickerActivity.this.mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(MapPlacePickerActivity.this.mLAstKnownLocation.getLatitude(), MapPlacePickerActivity.this.mLAstKnownLocation.getLongitude()), 17.0f));
return;
}
LocationRequest create = LocationRequest.create();
create.setInterval(1000L);
create.setFastestInterval(DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
create.setPriority(100);
MapPlacePickerActivity.this.locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
if (locationResult == null) {
return;
}
MapPlacePickerActivity.this.mLAstKnownLocation = locationResult.getLastLocation();
MapPlacePickerActivity.this.mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(MapPlacePickerActivity.this.mLAstKnownLocation.getLatitude(), MapPlacePickerActivity.this.mLAstKnownLocation.getLongitude()), 17.0f));
MapPlacePickerActivity.this.mFusedLocationProviderClient.removeLocationUpdates(MapPlacePickerActivity.this.locationCallback);
}
};
MapPlacePickerActivity.this.mFusedLocationProviderClient.requestLocationUpdates(create, null);
return;
}
Toast.makeText((Context) MapPlacePickerActivity.this, (CharSequence) "Unable to get last location ", 0).show();
}
});
}
protected void startIntentService() {
this.currentMarkerPosition = this.mMap.getCameraPosition().target;
AddressResultReceiver addressResultReceiver = new AddressResultReceiver(new Handler());
Intent intent = new Intent((Context) this, (Class<?>) FetchAddressIntentService.class);
intent.putExtra("com.mcb.stjohnsemschool.activity.RECEIVER", addressResultReceiver);
intent.putExtra("com.mcb.stjohnsemschool.activity.LOCATION_lAT_EXTRA", this.currentMarkerPosition.latitude);
intent.putExtra("com.mcb.stjohnsemschool.activity.LOCATION_LNG_EXTRA", this.currentMarkerPosition.longitude);
intent.putExtra("com.mcb.stjohnsemschool.activity.LANGUAGE", this.mLanguage);
startService(intent);
}
public void updateUi() {
this.mDisplayAddressTextView.setVisibility(0);
this.mProgressBar.setVisibility(8);
this.mMap.clear();
int i = this.addressResultCode;
if (i != 0) {
if (i == 1) {
this.mSmallPinIv.setVisibility(8);
this.mDisplayAddressTextView.setText(this.addressOutput);
return;
}
return;
}
if (isSupportedArea(this.mSupportedArea)) {
String replace = this.addressOutput.replace("Unnamed Road,", "");
this.addressOutput = replace;
String replace2 = replace.replace("Unnamed Road،", "");
this.addressOutput = replace2;
this.addressOutput = replace2.replace("Unnamed Road New,", "");
this.mSmallPinIv.setVisibility(0);
this.isSupportedArea = true;
this.mDisplayAddressTextView.setText(this.addressOutput);
return;
}
this.mSmallPinIv.setVisibility(8);
this.isSupportedArea = false;
this.mDisplayAddressTextView.setText(getString(R.string.not_support_area));
}
private boolean isSupportedArea(String[] strArr) {
if (strArr.length == 0) {
return true;
}
for (String str : strArr) {
if (this.addressOutput.contains(str)) {
return true;
}
}
return false;
}
public void revealView(View view) {
int width = view.getWidth() / 2;
int height = view.getHeight() / 2;
Animator createCircularReveal = ViewAnimationUtils.createCircularReveal(view, width, height, BitmapDescriptorFactory.HUE_RED, (float) Math.hypot(width, height));
view.setVisibility(0);
createCircularReveal.start();
}
class AddressResultReceiver extends ResultReceiver {
public AddressResultReceiver(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int i, Bundle bundle) {
MapPlacePickerActivity.this.addressResultCode = i;
if (bundle == null) {
return;
}
MapPlacePickerActivity.this.addressOutput = bundle.getString("com.mcb.stjohnsemschool.activity.RESULT_DATA_KEY");
if (MapPlacePickerActivity.this.addressOutput == null) {
MapPlacePickerActivity.this.addressOutput = "";
}
MapPlacePickerActivity.this.updateUi();
}
}
}