Android Open Source - android-project Running Listener Impl






From Project

Back to project page android-project.

License

The source code is released under:

GNU General Public License

If you think the Android project android-project listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package pl.wroc.pwr.patryk;
/*www .  j ava2  s.co m*/
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.widget.TextView;

public class RunningListenerImpl implements RunningListener {

  private MainActivity activity;
  private TextView textViewStatus;
  
  public RunningListenerImpl(MainActivity activity) {
    super();
    this.activity = activity;
  }

  @Override
  public void onRunningChange(boolean running) {
    if(textViewStatus == null)
      textViewStatus = (TextView) activity.findViewById(R.id.textview_status);
    
    if (running) {
      activity.locationManger = (LocationManager) activity.getSystemService( Context.LOCATION_SERVICE );

        if ( !activity.locationManger.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            buildAlertMessageNoGps();
        } else {
          textViewStatus.setText(R.string.status_working);
        }
    }else {
      textViewStatus.setText(R.string.status_off);
    }
  }
  
  

  private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(
        "Your GPS seems to be disabled, do you want to enable it?")
        .setCancelable(false)
        .setPositiveButton("Yes",
            new DialogInterface.OnClickListener() {
              public void onClick(
                  final DialogInterface dialog,
                  final int id) {
                activity.startActivityForResult(
                    new Intent(
                        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                    MainActivity.LOCATION_SETTINGS_REQUEST_CODE);
                // startActivity(new
                // Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
              }
            })
        .setNegativeButton("No",
            new DialogInterface.OnClickListener() {
              public void onClick(
                  final DialogInterface dialog,
                  final int id) {
                dialog.cancel();
              }
            });
    final AlertDialog alert = builder.create();
    alert.show();
  }
}




Java Source Code List

pl.wroc.pwr.patryk.Coordinate.java
pl.wroc.pwr.patryk.CoordinatesDataSource.java
pl.wroc.pwr.patryk.MainActivity.java
pl.wroc.pwr.patryk.MyArrayAdapter.java
pl.wroc.pwr.patryk.MyLocationListener.java
pl.wroc.pwr.patryk.MySQLiteHelper.java
pl.wroc.pwr.patryk.RunningChangeEvent.java
pl.wroc.pwr.patryk.RunningListenerImpl.java
pl.wroc.pwr.patryk.RunningListener.java