Android Open Source - geocamMobileForAndroid Foreground Tracker






From Project

Back to project page geocamMobileForAndroid.

License

The source code is released under:

NASA OPEN SOURCE AGREEMENT VERSION 1.3 THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE, REPRODUCTION, DISTRIBUTION, MODIFICATION AND REDISTRIBUTION OF CERTAIN COMPUTER SOFTWARE ORI...

If you think the Android project geocamMobileForAndroid 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

// __BEGIN_LICENSE__
// Copyright (C) 2008-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__
// www . j  av  a2  s  .c  om
package gov.nasa.arc.geocam.geocam.util;

import java.lang.ref.WeakReference;

import gov.nasa.arc.geocam.geocam.GeoCamService;
import gov.nasa.arc.geocam.geocam.IGeoCamService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class ForegroundTracker {
  private static final String TAG = "ForegroundTracker";
  
  private WeakReference<Context> mContext;

    private IGeoCamService mService;
    private boolean mServiceBound = false;

    private ServiceConnection mServiceConn = new ServiceConnection() {

        public void onServiceConnected(ComponentName name, IBinder service) {
            Log.d(TAG, "Connected to GeoCam Service");
            mService = IGeoCamService.Stub.asInterface(service);
            mServiceBound = true;
            
            reallyForeground();
    }

        public void onServiceDisconnected(ComponentName name) {
            Log.d(TAG, "Disconnected from GeoCam Service");
            mService = null;
            mServiceBound = false;
        }        
    };
  
  public ForegroundTracker(Context ctx) {
    mContext = new WeakReference<Context>(ctx);
  }
  
  public void foreground() {
    if (!mServiceBound)
      mServiceBound = mContext.get().bindService(
          new Intent(mContext.get(), GeoCamService.class), 
          mServiceConn, Context.BIND_AUTO_CREATE);
    else
      reallyForeground();
  }
  
  private void reallyForeground() {
    if (!mServiceBound || mService == null) {
      Log.w(TAG, "Trying to foreground, but no service!");
      return;
    }
    
        try {
          mService.applicationVisible();
        } catch (RemoteException e) {
          Log.d(TAG, "Error trying to set application visible");
        }
  }
  
  public void background() {
    if (!mServiceBound || mService == null) {
      Log.w(TAG, "Trying to background, but no service!");
      return; 
    }

    try {
      mService.applicationInvisible();
    } catch (RemoteException e) {
      Log.d(TAG, "Error trying to set application invisible");
    }
    
    mContext.get().unbindService(mServiceConn);
    mService = null;
    mServiceBound = false;
  }
}




Java Source Code List

gov.nasa.arc.geocam.geocam.AuthorizeUserActivity.java
gov.nasa.arc.geocam.geocam.CameraActivity.java
gov.nasa.arc.geocam.geocam.CameraPreviewActivity.java
gov.nasa.arc.geocam.geocam.DisableSSLCertificateCheckUtil.java
gov.nasa.arc.geocam.geocam.FireIconActivity.java
gov.nasa.arc.geocam.geocam.GalleryActivity.java
gov.nasa.arc.geocam.geocam.GeoCamDbAdapter.java
gov.nasa.arc.geocam.geocam.GeoCamMobile.java
gov.nasa.arc.geocam.geocam.GeoCamService.java
gov.nasa.arc.geocam.geocam.GpsDbAdapter.java
gov.nasa.arc.geocam.geocam.GpxWriter.java
gov.nasa.arc.geocam.geocam.HttpPost.java
gov.nasa.arc.geocam.geocam.SettingsActivity.java
gov.nasa.arc.geocam.geocam.TrackMapActivity.java
gov.nasa.arc.geocam.geocam.TrackSaveActivity.java
gov.nasa.arc.geocam.geocam.UploadPhotosActivity.java
gov.nasa.arc.geocam.geocam.util.ForegroundTracker.java
gov.nasa.arc.geocam.geocam.util.Reflect.java
org.xmlBlaster.util.Base64.java