Android Open Source - droidfad Droid Fad






From Project

Back to project page droidfad.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions...

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

/**
 * /*from   w  w  w  . ja  va  2 s  .  c  om*/
 */
package com.droidfad;

import java.io.File;
import java.lang.Thread.UncaughtExceptionHandler;

import android.content.Context;
import android.util.Log;

import com.droidfad.classloading.AndroidClazzFinder;
import com.droidfad.classloading.ClazzFinder;
import com.droidfad.iframework.data.IContextProvider;
import com.droidfad.iframework.data.IData;
import com.droidfad.iframework.data.IDataUser;
import com.droidfad.iframework.service.IService;
import com.droidfad.log.ILog;
import com.droidfad.log.LogWrapperAndroid;
import com.droidfad.persistency.Persistency;
import com.droidfad.service.ServiceAdministrator;
import com.droidfad.util.LogWrapper;

/**
Copyright 2014 Jens Glufke

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.
 */
public class DroidFad implements IContextProvider {

  /**
   * enum that defines if internal or external memory should be used
   * for persistency
   */
  public enum MemoryType { internal, external }  

  /**
   * a wrapper class to access class Persistency directly
   */
  static class PersistencyWrapper extends Persistency {
    static void setPersistencyPath(String pPath) {
      File lRootPath = new File(pPath);
      if(lRootPath.isFile()) {
        throw new IllegalArgumentException("persistency root path must not be an existing file:" + pPath);
      }
      Persistency.setRootDir(pPath);
    }
  }
  /**
   * helper class to register services at this
   *
   * @author base
   * copyright Jens Glufke, Germany mailto:jglufke@gmx.de
   *
   */
  public static class RegisterService implements IDataUser {

    /* (non-Javadoc)
     * @see com.yaffa.iframework.service.IServiceUser#registerService(com.yaffa.iframework.service.IService)
     */
    @Override
    public synchronized void registerService(IService pService) {
      if(pService instanceof IData) {
        data = (IData) pService;
      }
    }
  }

  private static final String LOGTAG = DroidFad.class.getSimpleName();

  private volatile static AndroidClazzFinder androidClazzFinder = null;
  private volatile static ILog               logger             = null;

  private static ServiceAdministrator serviceAdministrator;
  private static Context  context;
  private static IData    data = null;
  private static UncaughtExceptionHandler uncaughtExceptionHandler;

  /**
   * this class also implements the service IContextProvider.
   * Thus, it has to implement the default constructor as every service
   */
  public DroidFad() {}
  /**
   * initialize the framework. Very first method of the framework
   * that has to be called at all. Internal memory is used for persistency
   *
   * @param pContext
   *
   */
  public synchronized static void init(Context pContext) {

    init(pContext, MemoryType.internal);

  }
  /**
   * initialize the framework. Very first method of the framework
   * that has to be called at all
   *
   * @param pContext
   *
   */
  public synchronized static void init(Context pContext, MemoryType pMemoryType) {

    if(pContext == null) {
      throw new IllegalArgumentException("parameter pContext must not be null");
    }
    if(pMemoryType == null) {
      throw new IllegalArgumentException("parameter pMemoryType must not be null");
    }

    String lPersistencyRootPath = null;
    switch(pMemoryType) {
    case external:
      lPersistencyRootPath = pContext.getExternalFilesDir(null).getAbsolutePath();
      break;
    case internal:
      lPersistencyRootPath = pContext.getFilesDir().getAbsolutePath();
      break;
    default:
      throw new IllegalArgumentException("not handled memory type:" + pMemoryType);
    }
    PersistencyWrapper.setPersistencyPath(lPersistencyRootPath);

    /**
     * take care that init method is only processed once
     */
    context = pContext;

    if(logger == null) {
      logger = new LogWrapperAndroid();
      LogWrapper.setLogImpl(logger);
      uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
      Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());


      LogWrapper.i(LOGTAG, "============================================");
      LogWrapper.i(LOGTAG, "init =======================================");
      LogWrapper.i(LOGTAG, "============================================");

    }
    if(androidClazzFinder == null) {
      androidClazzFinder = new AndroidClazzFinder(pContext);
      ClazzFinder.setClazzFinder(androidClazzFinder);
    }
    if(serviceAdministrator == null) {
      serviceAdministrator = ServiceAdministrator.getInstance();
      serviceAdministrator.registerServices();
    }
    data.init();
  }
  /* (non-Javadoc)
   * @see com.droidfad.iframework.data.IContextProvider#getActivity()
   */
  @Override
  public Context getContext() {
    return context;
  }

  public static class CustomExceptionHandler implements Thread.UncaughtExceptionHandler {
    ;
    /* (non-Javadoc)
     * @see java.lang.Thread.UncaughtExceptionHandler#uncaughtException(java.lang.Thread, java.lang.Throwable)
     */
    @Override
    public void uncaughtException(Thread pThread, Throwable pEx) {
      Log.e("UNCAUGHT", pEx.getMessage(), pEx);
      if(uncaughtExceptionHandler != null) {
        uncaughtExceptionHandler.uncaughtException(pThread, pEx);
      }
    }
  }
}




Java Source Code List

com.droidfad.DroidFad.java
com.droidfad.alarm.AAlarmWorker.java
com.droidfad.classloading.AndroidClazzFinder.java
com.droidfad.data.SystemUtil.java
com.droidfad.eula.EULA.java
com.droidfad.iframework.data.IActivityProviderUser.java
com.droidfad.iframework.data.IContextProvider.java
com.droidfad.log.LogWrapperAndroid.java
com.droidfad.view.DFColor.java
com.droidfad.view.DateAndTimePickerDialog.java
com.droidfad.view.DatePickerDialogExt.java
com.droidfad.view.Editor.java
com.droidfad.view.FancyButton.java
com.droidfad.view.FancyDrawer.java
com.droidfad.view.FancyTextView.java
com.droidfad.view.IEditorListener.java
com.droidfad.view.LicenseViewer.java
com.droidfad.view.ObjectSelector.java
com.droidfad.view.TableViewExtra.java
com.droidfad.view.TimePickerDialogExt.java