Android Open Source - Aether-s-Notebook-Android-Client Push Logger






From Project

Back to project page Aether-s-Notebook-Android-Client.

License

The source code is released under:

GNU General Public License

If you think the Android project Aether-s-Notebook-Android-Client 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 aethers.notebook.logger.managed;
//from  w w  w  .java2s .  co  m
import aethers.notebook.core.AethersNotebook;
import aethers.notebook.core.CoreService;
import aethers.notebook.core.LoggerService;

import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.telephony.TelephonyManager;

public abstract class PushLogger<T>
extends Service
implements Runnable
{    
    private final LoggerService.Stub loggerServiceStub = 
            new LoggerService.Stub()
            {
                @Override
                public void configure()
                throws RemoteException 
                {  
                    PushLogger.this.configure();
                }
        
                @Override
                public boolean isRunning() 
                throws RemoteException 
                {
                    synchronized(sync)
                    {
                        return running;
                    }
                }
        
                @Override
                public void start() 
                throws RemoteException 
                {
                    startService(new Intent(
                            PushLogger.this, 
                            PushLogger.this.getClass()));
                }
        
                @Override
                public void stop() 
                throws RemoteException 
                {
                    PushLogger.this.stopSelf();
                }       
            };
    
    private final ServiceConnection loggerConnection = 
            new ServiceConnection() 
            {   
                @Override
                public void onServiceDisconnected(ComponentName name)
                {
                    PushLogger.this.stopSelf();
                }
                
                @Override
                public void onServiceConnected(ComponentName name, IBinder service) 
                {
                    aethersNotebook = AethersNotebook.Stub.asInterface(service);
                    new Thread(PushLogger.this).start();
                }
            };
            
    private final Object sync = new Object();
    
    protected AethersNotebook aethersNotebook;
    
    protected TelephonyManager telephonyManager;
    
    private volatile boolean running = false;
        
    private Looper looper;
    
    @Override
    public IBinder onBind(Intent intent) 
    {
        return loggerServiceStub;
    }
    
    @Override
    public void onCreate() 
    {
        super.onCreate();
        telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
    }

    @Override
    public void onDestroy() 
    {
        super.onDestroy();
        synchronized(sync)
        {
            if(running)
            {
                running = false;
                unbindService(loggerConnection);
                if(looper != null)
                {
                    looper.quit();
                    looper = null;
                }
            }
        }
    }
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) 
    {      
        synchronized(sync)
        {
            if(running)
                return START_STICKY;
            running = bindService(
                    new Intent(this, CoreService.class),
                    loggerConnection, 
                    BIND_AUTO_CREATE);
        }
        
        return START_STICKY;
    }

    @Override
    public void run() 
    {
        Looper.prepare();
        looper = new Handler().getLooper();
        T t = preLogging();
        Looper.loop();
        postLogging(t);
    }
    
    protected T preLogging()
    {
        return null;
    }
    
    protected void postLogging(T t)
    {
        
    }
    
    protected void configure()
    {
        
    }
}




Java Source Code List

aethers.notebook.appender.managed.file.ConfigurationActivity.java
aethers.notebook.appender.managed.file.Configuration.java
aethers.notebook.appender.managed.file.FileAppender.java
aethers.notebook.appender.managed.uploader.ConfigurationActivity.java
aethers.notebook.appender.managed.uploader.Configuration.java
aethers.notebook.appender.managed.uploader.UploaderAppender.java
aethers.notebook.core.Action.java
aethers.notebook.core.AppenderServiceIdentifier.java
aethers.notebook.core.BootReceiver.java
aethers.notebook.core.ConfigurationTemplate.java
aethers.notebook.core.Configuration.java
aethers.notebook.core.CoreService.java
aethers.notebook.core.LoggerServiceIdentifier.java
aethers.notebook.core.TimeStamp.java
aethers.notebook.core.ui.ConfigurationActivity.java
aethers.notebook.core.ui.EditIntegerPreference.java
aethers.notebook.core.ui.IntegerPreferenceChangeListener.java
aethers.notebook.core.ui.NonPersistingButtonPreference.java
aethers.notebook.core.ui.PersistingButtonPreference.java
aethers.notebook.core.ui.filechooser.DirectoryChooser.java
aethers.notebook.core.ui.filechooser.FileChooser.java
aethers.notebook.core.ui.filechooser.FileListAdapter.java
aethers.notebook.logger.managed.PushLogger.java
aethers.notebook.logger.managed.celllocation.CellLocationLogger.java
aethers.notebook.logger.managed.dataconnectionstate.DataConnectionStateLogger.java
aethers.notebook.logger.managed.position.ConfigurationActivity.java
aethers.notebook.logger.managed.position.Configuration.java
aethers.notebook.logger.managed.position.PositionLogger.java
aethers.notebook.logger.managed.servicestate.ServiceStateLogger.java
aethers.notebook.logger.managed.signalstrength.SignalStrengthLogger.java
aethers.notebook.logger.managed.wifi.ConfigurationActivity.java
aethers.notebook.logger.managed.wifi.Configuration.java
aethers.notebook.logger.managed.wifi.WifiLogger.java
aethers.notebook.util.Logger.java