Android Open Source - FrameLite View Utils






From Project

Back to project page FrameLite.

License

The source code is released under:

GNU General Public License

If you think the Android project FrameLite 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 com.miku.framelite.utils;
//from   ww  w. j a va2  s . c om
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;

import com.miku.framelite.annotations.ViewInject;

/**
 * ??View????
 * 
 * @author xr.lee
 * 
 */
public class ViewUtils {
  /**
   * 
   * @param instance
   *            currentIntance of Using this method ???????????????
   * @param endClazz
   *            ?????????View???????????
   * @param view
   *            ?????view???????id,???????????instance???instance???activity?????
   * @param listener
   *            ??????
   */
  public static void bindViewIds(Object instance, Class<?> endClazz,
      View parentView, OnClickListener listener) {
    List<Field> fields = new ArrayList<Field>();
    Class<?> clazz = instance.getClass();
    while (!clazz.equals(endClazz)) {
      Field[] fs = clazz.getDeclaredFields();
      if (fs != null && fs.length > 0) {
        Collections.addAll(fields, fs);
      }
      clazz = clazz.getSuperclass();
    }
    Object obj2Search = parentView == null ? instance : parentView;
    for (Field field : fields) {
      try {
        field.setAccessible(true);
        if (field.get(instance) != null)
          continue;

        ViewInject viewInject = field.getAnnotation(ViewInject.class);
        if (viewInject != null) {
          int viewId = viewInject.id();
          View tempView = null;
          if (obj2Search instanceof View) {
            tempView = ((View) obj2Search).findViewById(viewId);
          } else if (obj2Search instanceof Activity) {
            tempView = ((Activity) obj2Search).findViewById(viewId);
          }
          field.set(instance, tempView);
          if (listener != null && viewInject.bindClick()) {
            Object obj = field.get(instance);
            if (obj instanceof View) {
              ((View) obj).setOnClickListener(listener);
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

}




Java Source Code List

com.miku.framelite.FrameApplication.java
com.miku.framelite.FrameBaseActivity.java
com.miku.framelite.FrameOrmBaseActivity.java
com.miku.framelite.adapter.FrameBaseAdapter.java
com.miku.framelite.annotations.ViewInject.java
com.miku.framelite.api.BaseRequest.java
com.miku.framelite.api.IRequest.java
com.miku.framelite.api.RetResult.java
com.miku.framelite.api.core.Executor.java
com.miku.framelite.api.database.AbstractDatabaseRequest.java
com.miku.framelite.api.database.AbstractOrmDatabaseRequest.java
com.miku.framelite.api.database.DatabaseQueryRequest.java
com.miku.framelite.api.database.DatabaseType.java
com.miku.framelite.api.http.AbstractHttpRequest.java
com.miku.framelite.api.http.HttpStringGetRequest.java
com.miku.framelite.api.http.HttpStringPostRequest.java
com.miku.framelite.api.http.HttpType.java
com.miku.framelite.api.webservice.AbstractWebServiceRequest.java
com.miku.framelite.api.webservice.WebServiceConnectionSE.java
com.miku.framelite.api.webservice.WebServiceHttpTransportSE.java
com.miku.framelite.api.webservice.WebServiceJsonRequest.java
com.miku.framelite.api.webservice.WebServiceStringRequest.java
com.miku.framelite.httpx.IDownloadHandler.java
com.miku.framelite.httpx.IHttpX.java
com.miku.framelite.httpx.core.DownloadHandler.java
com.miku.framelite.httpx.core.HttpX.java
com.miku.framelite.services.CrashHandler.java
com.miku.framelite.utils.BitmapUtils.java
com.miku.framelite.utils.DateUtils.java
com.miku.framelite.utils.DimensionUtils.java
com.miku.framelite.utils.EncryptionUtils.java
com.miku.framelite.utils.HttpUtils.java
com.miku.framelite.utils.Log.java
com.miku.framelite.utils.TelePhoneUtils.java
com.miku.framelite.utils.ViewUtils.java