Android Open Source - sms-smap-gateway Alarm Receiver






From Project

Back to project page sms-smap-gateway.

License

The source code is released under:

GNU General Public License

If you think the Android project sms-smap-gateway 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

/***
 * Copyright (c) 2011 CommonsWare, LLC//  w  w  w.j av  a 2s. c  o  m
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
 * applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */

package com.android.smap.commonsware.wakefull;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.XmlResourceParser;

import com.android.smap.commonsware.wakefull.WakefulIntentService.AlarmSheduleListener;

public class AlarmReceiver extends BroadcastReceiver {
  private static final String  WAKEFUL_META_DATA  = "com.commonsware.cwac.wakeful";

  @Override
  public void onReceive(Context ctxt, Intent intent) {
    AlarmSheduleListener listener = getListener(ctxt);

    if (listener != null) {
      if (intent.getAction() == null) {
        SharedPreferences prefs = ctxt.getSharedPreferences(
            WakefulIntentService.NAME, 0);

        prefs
            .edit()
            .putLong(WakefulIntentService.LAST_ALARM,
                System.currentTimeMillis())
            .commit();

        listener.sendWakefulWork(ctxt);
      }
      else {
        WakefulIntentService.scheduleAlarms(listener, ctxt, true);
      }
    }
  }

  @SuppressWarnings("unchecked")
  private WakefulIntentService.AlarmSheduleListener getListener(Context ctxt) {
    PackageManager pm = ctxt.getPackageManager();
    ComponentName cn = new ComponentName(ctxt, getClass());

    try {
      ActivityInfo ai = pm.getReceiverInfo(cn,
          PackageManager.GET_META_DATA);
      XmlResourceParser xpp = ai.loadXmlMetaData(pm,
          WAKEFUL_META_DATA);

      while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {
        if (xpp.getEventType() == XmlPullParser.START_TAG) {
          if (xpp.getName().equals("WakefulIntentService")) {
            String clsName = xpp
                .getAttributeValue(null, "listener");
            Class<AlarmSheduleListener> cls = (Class<AlarmSheduleListener>) Class
                .forName(clsName);

            return (cls.newInstance());
          }
        }

        xpp.next();
      }
    }
    catch (NameNotFoundException e) {
      throw new RuntimeException("Cannot find own info???", e);
    }
    catch (XmlPullParserException e) {
      throw new RuntimeException("Malformed metadata resource XML", e);
    }
    catch (IOException e) {
      throw new RuntimeException("Could not read resource XML", e);
    }
    catch (ClassNotFoundException e) {
      throw new RuntimeException("Listener class not found", e);
    }
    catch (IllegalAccessException e) {
      throw new RuntimeException(
          "Listener is not public or lacks public constructor", e);
    }
    catch (InstantiationException e) {
      throw new RuntimeException("Could not create instance of listener",
          e);
    }

    return (null);
  }
}




Java Source Code List

com.android.smap.AppConfig.java
com.android.smap.GatewayApp.java
com.android.smap.PhoneStateWrapper.java
com.android.smap.activities.BaseActivity.java
com.android.smap.activities.FragmentWrapperActivity.java
com.android.smap.activities.MainActivity.java
com.android.smap.adapters.MenuDrawerAdapter.java
com.android.smap.api.ApiConstants.java
com.android.smap.api.models.Gojo.java
com.android.smap.api.models.Node.java
com.android.smap.api.models.SmapException.java
com.android.smap.api.models.Status.java
com.android.smap.api.models.validator.ModelValidator.java
com.android.smap.api.models.validator.Required.java
com.android.smap.api.requests.ApiRequest.java
com.android.smap.api.requests.GojoRequest.java
com.android.smap.api.requests.StatusRequest.java
com.android.smap.commonsware.wakefull.AlarmReceiver.java
com.android.smap.commonsware.wakefull.WakefulIntentService.java
com.android.smap.controllers.ControllerErrorListener.java
com.android.smap.controllers.ControllerError.java
com.android.smap.controllers.ControllerFactory.java
com.android.smap.controllers.ControllerListener.java
com.android.smap.controllers.Controller.java
com.android.smap.controllers.EmailController.java
com.android.smap.controllers.GojoController.java
com.android.smap.controllers.UIPagingController.java
com.android.smap.controllers.UIRequestController.java
com.android.smap.fragments.BaseFragment.java
com.android.smap.fragments.HomeFragment.java
com.android.smap.models.MenuDrawerItem.java
com.android.smap.models.TextMessage.java
com.android.smap.samuel.Samuel.java
com.android.smap.sms.CellularModem.java
com.android.smap.sms.GatewayService.java
com.android.smap.sms.MonitorService.java
com.android.smap.sms.ScheduleMonitoringListener.java
com.android.smap.sms.ServiceRebooter.java
com.android.smap.ui.ArrayVelocAdapter.java
com.android.smap.ui.OnErrorTouchedListener.java
com.android.smap.ui.Operation.java
com.android.smap.ui.VelocAdapter.java
com.android.smap.ui.ViewBinder.java
com.android.smap.ui.ViewQuery.java
com.android.smap.ui.views.AnimatedNetworkImageView.java
com.android.smap.ui.views.ErrorView.java
com.android.smap.ui.views.FontableTextView.java
com.android.smap.utils.BitmapLruCache.java
com.android.smap.utils.MWAPNUtils.java
com.android.smap.utils.MWAnimUtil.java
com.android.smap.utils.MWAssetsUtils.java
com.android.smap.utils.MWConnectionUtils.java
com.android.smap.utils.MWEmailUtils.java
com.android.smap.utils.MWUiUtils.java
com.android.smap.utils.PreferenceWrapper.java
com.android.smap.utils.Refresher.java
com.android.smap.utils.UriBuilder.java