Android Open Source - BodhiTimer Schedule Client






From Project

Back to project page BodhiTimer.

License

The source code is released under:

GNU General Public License

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

/*
    This file is part of Bodhi Timer.//  w w w  . ja  va 2  s . c o  m

    Bodhi Timer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Bodhi Timer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Bodhi Timer.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.yuttadhammo.BodhiTimer.Service;

import java.util.Calendar;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

/**
 * This is our service client, it is the 'middle-man' between the
 * service and any activity that wants to connect to the service
 *
 * @author paul.blundell
 */
public class ScheduleClient {

    // The hook into our service
    private ScheduleService mBoundService;
    // The context to start the service in
    private Context mContext;
    // A flag if we are connected to the service or not
    private boolean mIsBound;

    public ScheduleClient(Context context) {
        mContext = context;
    }

    /**
     * Call this to connect your activity to your service
     */
    public void doBindService() {
        // Establish a connection with our service
        mContext.bindService(new Intent(mContext, ScheduleService.class), mConnection, Context.BIND_AUTO_CREATE);
        mIsBound = true;
    }

    /**
     * When you attempt to connect to the service, this connection will be called with the result.
     * If we have successfully connected we instantiate our service object so that we can call methods on it.
     */
    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            // This is called when the connection with our service has been established,
            // giving us the service object we can use to interact with our service.
            mBoundService = ((ScheduleService.ServiceBinder) service).getService();
        }

        public void onServiceDisconnected(ComponentName className) {
            mBoundService = null;
        }
    };

    /**
     * Tell our service to set an alarm for the given date
     * @param time time to set service for
     */
    public void setAlarmForNotification(int time){
        if(mBoundService == null)
            return;

        mBoundService.setAlarm(time);
    }

    /**
     * When you have finished with the service call this method to stop it
     * releasing your connection and resources
     */
    public void doUnbindService() {
        if (mIsBound) {
            // Detach our existing connection.
            mContext.unbindService(mConnection);
            mIsBound = false;
        }
    }
}




Java Source Code List

org.yuttadhammo.BodhiTimer.ANumberPicker.java
org.yuttadhammo.BodhiTimer.NNumberPicker.java
org.yuttadhammo.BodhiTimer.TTSService.java
org.yuttadhammo.BodhiTimer.TimerActivity.java
org.yuttadhammo.BodhiTimer.TimerPrefActivity.java
org.yuttadhammo.BodhiTimer.TimerReceiver.java
org.yuttadhammo.BodhiTimer.TimerUtils.java
org.yuttadhammo.BodhiTimer.VolumePreference.java
org.yuttadhammo.BodhiTimer.Animation.BodhiLeaf.java
org.yuttadhammo.BodhiTimer.Animation.CircleAnimation.java
org.yuttadhammo.BodhiTimer.Animation.TimerAnimation.java
org.yuttadhammo.BodhiTimer.Service.AlarmTask.java
org.yuttadhammo.BodhiTimer.Service.ScheduleClient.java
org.yuttadhammo.BodhiTimer.Service.ScheduleService.java
org.yuttadhammo.BodhiTimer.widget.AppWidgetConfigure.java
org.yuttadhammo.BodhiTimer.widget.BodhiAppWidgetProvider.java