在我的基本手电筒应用程序中,我有一个主表视图场景,链接到另外两个表视图场景,以设置亮度和亮度的值。时间。我有过渡工作,但我想知道一些事情。
答案 0 :(得分:0)
要对所选行执行操作,请使用委托方法
public class RouteMapActivity extends AppCompatActivity implements
LocationListener, OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener
{
private static final long MIN_DISTANCE_FOR_UPDATE = 10;
private static final int LOCATION_SETTINGS_REQUEST_CODE = 1;
private static final long MIN_TIME_FOR_UPDATE = 1000 * 60 * 2;
private static final LatLng latlngHiLiteMall = new LatLng(11.248823, 75.833760);
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 1000;
private boolean mRequestingLocationUpdates = false;
private LocationRequest mLocationRequest;
private static int UPDATE_INTERVAL = 10000;
private static int FATEST_INTERVAL = 5000; /
private static int DISPLACEMENT = 10;
boolean isGPSTrackingEnabled = false;
LatLng latLngMyLocation = null;
AlertDialog alertDlg;
GoogleApiClient googleApiClient;
LocationSettingsRequest.Builder builder;
double myLocLat, myLocLong;
LocationManager locationManager;
boolean isGPSEnabled = false;
boolean isNetworkEnabled = false;
ConnectionInfo connectionInfo;
private Location mLastLocation;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_route_map);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
connectionInfo = new ConnectionInfo(this);
Log.e("Rout Map.....","on Create....!");
if (checkPlayServices()) {
buildGoogleApiClient();
createLocationRequest();
}
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
setUpMapIfNeeded();
}
private void createLocationRequest() {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(UPDATE_INTERVAL);
mLocationRequest.setFastestInterval(FATEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setSmallestDisplacement(DISPLACEMENT);
}
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Toast.makeText(getApplicationContext(),
"This device is not supported.", Toast.LENGTH_LONG)
.show();
finish();
}
return false;
}
return true;
}
@Override
protected void onStart() {
super.onStart();
googleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if (googleApiClient.isConnected()) {
googleApiClient.disconnect();
}
}
protected synchronized void buildGoogleApiClient() {
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
protected void onResume() {
super.onResume();
checkPlayServices();
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled)
showAlertDialog();
if (googleApiClient.isConnected()) {
startLocationUpdates();
}
}
@Override
protected void onPause() {
super.onPause();
stopLocationUpdates();
}
private void togglePeriodicLocationUpdates() {
if (!mRequestingLocationUpdates) {
mRequestingLocationUpdates = true;
startLocationUpdates();
Log.d("TAG", "Periodic location updates started!");
} else {
mRequestingLocationUpdates = false;
stopLocationUpdates();
Log.d("TAG", "Periodic location updates stopped!");
}
}
private void stopLocationUpdates() {
LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
}
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, mLocationRequest, this);
}
private void setUpMapIfNeeded() {
if (mMap != null) {
return;
}
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
if (mMap == null) {
return;
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
@Override
public boolean onMyLocationButtonClick() {
if (!isGPSEnabled) {
Toast.makeText(RouteMapActivity.this, "GPS is disabled!", Toast.LENGTH_SHORT).show();
}
return false;
}
});
// Add a marker in Sydney and move the camera
mMap.addMarker(new MarkerOptions().position(latlngHiLiteMall).title("HiLite Mall"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlngHiLiteMall, 12));
//getMyCurrentLocation();
getMyLocation();
}
private void getMyLocation() {
mLastLocation = LocationServices.FusedLocationApi
.getLastLocation(googleApiClient);
if (mLastLocation != null) {
Log.d("NOT NULL", ">>>>>>>>>>>");
if (alertDlg != null && alertDlg.isShowing())
alertDlg.dismiss();
myLocLat = mLastLocation.getLatitude();
myLocLong = mLastLocation.getLongitude();
if (connectionInfo.isConnectingToInternet()) {
latLngMyLocation = new LatLng(myLocLat, myLocLong);
mMap.addMarker(new MarkerOptions().position(latLngMyLocation).title("My Loc"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLngMyLocation, 12));
new MapTask().execute();
} else {
Toast.makeText(this, "Enable Internet", Toast.LENGTH_SHORT).show();
}
Toast.makeText(RouteMapActivity.this, "G--" + myLocLat, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(RouteMapActivity.this, "Couldn't get the location. Make sure location is enabled on the device", Toast.LENGTH_SHORT).show();
}
}
private Location getLastKnownLocation() {
List<String> providers = locationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location l = locationManager.getLastKnownLocation(provider);
Log.d("last known location", "" + provider + " " + l);
if (l == null) {
continue;
}
if (bestLocation == null
|| l.getAccuracy() < bestLocation.getAccuracy())
{
Log.d("last known location", "" + provider + " " + l);
bestLocation = l;
}
}
if (bestLocation == null) {
return null;
}
return bestLocation;
}
private void showAlertDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Use Location?");
alertDialog.setMessage("Helps for find the route to HiLite Mall.");
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, LOCATION_SETTINGS_REQUEST_CODE);
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDlg = alertDialog.create();
alertDlg.show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == LOCATION_SETTINGS_REQUEST_CODE) {
Log.d("TAG", "Activity Result");
getMyLocation();
}
}
@Override
public void onConnected(Bundle connectionHint) {
getMyLocation();
if (mRequestingLocationUpdates) {
startLocationUpdates();
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i("API CLIENT", "Connection failed: ConnectionResult.getErrorCode() = " + result.getErrorCode());
}
@Override
public void onConnectionSuspended(int cause) {
Log.i("API CLIENT", "Connection suspended");
googleApiClient.connect();
}
@Override
public void onLocationChanged(Location location) {
Log.e("Location Changed.....","Location changed....!");
mLastLocation = location;
// Displaying the new location on UI
getMyLocation();
}
private class MapTask extends AsyncTask<Void, Void, PolylineOptions> {
@Override
protected PolylineOptions doInBackground(Void... params) {
GMapV2Direction md = new GMapV2Direction();
Document doc = md.getDocument(latLngMyLocation, latlngHiLiteMall, GMapV2Direction.MODE_DRIVING);
ArrayList<LatLng> directionPoint = md.getDirection(doc);
PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.RED);
for (int i = 0; i < directionPoint.size(); i++) {
rectLine.add(directionPoint.get(i));
}
return rectLine;
}
@Override
protected void onPostExecute(PolylineOptions rectLine) {
mMap.addPolyline(rectLine);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
要将值select传递给mainViewController,您必须在mainViewControlle中创建一个属性。通过导入mainViewController.h