Android Open Source - AbLE Ab L E_ Annotation






From Project

Back to project page AbLE.

License

The source code is released under:

Apache License

If you think the Android project AbLE 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 2013 Phil Brown// w w  w .java  2  s  .  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 self.philbrown.AbLE.view;

import java.lang.ref.WeakReference;

import self.philbrown.AbLE.AbLEActivity;
import self.philbrown.AbLE.AbLEUtil;
import self.philbrown.AbLE.R;
import self.philbrown.AbLE.annotations.AnnotatedLayoutInflater;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

/**
 * This class provides a way for AbLE layouts to be enclosed within an XML file.
 * @author Phil Brown
 */
public class AbLE_Annotation extends FrameLayout
{
  /** The {@link View} that is created, and where child views are added */
  private View AbLE_View;

  /**
   * Constructor
   * @param context
   */
  public AbLE_Annotation(Context context) {
    this(context, null);
  }
  
  /**
   * Constructor
   * @param context
   * @param attrs
   */
  public AbLE_Annotation(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }
  
  /**
   * Constructor. This is also where the attributes are unpacked, and the AbLE layout is added as a
   * child view.
   * @param context
   * @param attrs
   * @param defStyle
   */
  public AbLE_Annotation(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AbLE);
    String clazz = a.getString(R.styleable.AbLE_AbLEclass);
    
    Drawable preview = a.getDrawable(R.styleable.AbLE_AbLEpreview);
    
    a.recycle();
    
    if (clazz != null)
    {
      if (this.isInEditMode())
      {
        //handle what to show in the layout editor.
        if (preview == null)
        {
          //default to a White background
          this.setBackgroundColor(Color.WHITE);
        }
        else
        {
          //set the preview to what the user specified
          this.setBackgroundDrawable(preview);
        }
      }
      else
      {
        try {
          Class<?> _class = Class.forName(clazz);
          if (context instanceof AbLEActivity)
          {
            AbLE_View = AnnotatedLayoutInflater.inflate((AbLEActivity) context, _class, null);
          }
          else
          {
            WeakReference<AbLEActivity> ref = AbLEActivity.obtain();
            AbLE_View = AnnotatedLayoutInflater.inflate(ref.get(), _class, null);
            ref = null;
          }
          ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
          AbLE_View.setLayoutParams(params);
          super.addView(AbLE_View);
        } catch (Throwable t) {
          AbLEUtil.err("Could not instantiate class %s.", clazz);
        }
      }
      
    }
    else
    {
      AbLEUtil.err("AbLE class must be specified!");
    }
  }

}




Java Source Code List

self.philbrown.AbLE.AbLEActivity.java
self.philbrown.AbLE.AbLEUtil.java
self.philbrown.AbLE.ActivityListener.java
self.philbrown.AbLETest.AbLETestActivity.java
self.philbrown.AbLETest.Controller.AbLETestController.java
self.philbrown.AbLETest.Controller.package-info.java
self.philbrown.AbLETest.layout.AbLETestLayout2.java
self.philbrown.AbLETest.layout.AbLETestLayout.java
self.philbrown.AbLETest.layout.package-info.java
self.philbrown.AbLETest.package-info.java
self.philbrown.AbLE.annotations.AbstractAnnotation.java
self.philbrown.AbLE.annotations.AbstractInvisible.java
self.philbrown.AbLE.annotations.AbstractLayoutAdapter.java
self.philbrown.AbLE.annotations.AnnotatedLayoutInflater.java
self.philbrown.AbLE.annotations.Binding.java
self.philbrown.AbLE.annotations.ClassAnnotationInflater.java
self.philbrown.AbLE.annotations.EmbedInflater.java
self.philbrown.AbLE.annotations.Embed.java
self.philbrown.AbLE.annotations.FieldAnnotationInflater.java
self.philbrown.AbLE.annotations.Getter.java
self.philbrown.AbLE.annotations.InstanceMethod.java
self.philbrown.AbLE.annotations.InvisibleInflater.java
self.philbrown.AbLE.annotations.Invisible.java
self.philbrown.AbLE.annotations.LayoutAdapterInflater.java
self.philbrown.AbLE.annotations.LayoutAdapter.java
self.philbrown.AbLE.annotations.LayoutInflater.java
self.philbrown.AbLE.annotations.Layout.java
self.philbrown.AbLE.annotations.MissingAnnotationException.java
self.philbrown.AbLE.annotations.ORIENTATION.java
self.philbrown.AbLE.annotations.Setter.java
self.philbrown.AbLE.annotations.Variable.java
self.philbrown.AbLE.annotations.XMLLayoutInflater.java
self.philbrown.AbLE.annotations.XMLLayout.java
self.philbrown.AbLE.annotations.package-info.java
self.philbrown.AbLE.model.Modified.java
self.philbrown.AbLE.model.package-info.java
self.philbrown.AbLE.view.AbLE_Annotation.java
self.philbrown.AbLE.view.package-info.java
self.philbrown.AbLE.package-info.java