// isfirst=false;//everytime you must findViewById otherwise you will get error: // requestLayout() improperly called by android.widget.TextView{52e78b8c V.ED.... ......ID 240,0-516,100 #7f100083 app:id/name} during layout: running second layout pass
2015年5月20日 星期三
running second layout pass
W/View﹕ requestLayout() improperly called by android.widget.TextView{52fa954c V.ED.... ......ID 240,0-378,100 #7f100083 app:id/name} during layout: running second layout pass
2015年5月5日 星期二
robolectric
https://github.com/robolectric/deckard-gradle/blob/master/build.gradle
http://robolectric.org/getting-started/
http://robolectric.org/getting-started/
2015年5月2日 星期六
自訂 Annotation 型態 限制
http://openhome.cc/Gossip/Java/CustomizeAnnotation.html
在定義標註時,可使用
例如想將
在定義標註時,可使用
java.lang.annotation.Target限定標註使用位置,限定時可指定java.lang.annotation.ElementType的列舉值:package java.lang.annotation;
public enum ElementType {
TYPE, // 用於類別、介面、列舉等
FIELD, // 用於資料成員
METHOD, // 用於方法
PARAMETER, // 用於方法上的參數
CONSTRUCTOR, // 用於建構式
LOCAL_VARIABLE, // 用於區域變數
ANNOTATION_TYPE, // 用於標註型態
PACKAGE, // 適用套件
TYPE_PARAMETER, // 用於泛型宣告,JDK8新增
TYPE_USE // 用於各種型態,JDK8新增
}@Test8限定只能用於方法:package cc.openhome;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target({ElementType.METHOD})
public @interface Test8 {}
StockWheelAdapter extends AbstractWheelTextAdapter
package suntone.lfo.com.suntonehelper.adapter; import android.content.Context; import com.lfo.suntone.db.Stock;import com.lfo.suntone.db.Stocktype; import java.lang.reflect.InvocationTargetException;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Iterator;import java.util.List; import kankan.wheel.widget.WheelView;import kankan.wheel.widget.adapters.AbstractWheelTextAdapter;import suntone.lfo.com.suntonehelper.tool.Utils;import suntone.lfo.com.suntonehelper.tool.WarehouseTool; /** * Created by user on 2015/4/27. */public class StockWheelAdapter extends AbstractWheelTextAdapter { private List<Stock> list; private List<Stock> originList; private List<Stock> filtlist; private Context context; private WheelView thiswheelView; protected StockWheelAdapter(Context context) { super(context); } public StockWheelAdapter(Context context, List list,WheelView thiswheelView) { super(context); this.context = context; this.list=new ArrayList(); originList=new ArrayList<>(); filtlist=new ArrayList<>(); this.list = list; this.thiswheelView=thiswheelView; this.originList.addAll(list); thiswheelView.setVisibleItems(list.size()); } public Boolean isListNullOrEmpty(){ if(this.list==null){ return true; } if(this.list.isEmpty()){ return true; } return false; } public Stock getSelected(WheelView v) { if(list.isEmpty()){ Utils.instance.logClaz(this,"getSelected() list.isEmpty"); return null; } if(list.size()==v.getCurrentItem()){ Utils.instance.logClaz(this,"getSelected() v.getCurrentItem():"+v.getCurrentItem()+",list.size():"+list.size()); return null; } return list.get(v.getCurrentItem()); } public int getSelectedId(WheelView v) { return list.get(v.getCurrentItem()).getId(); } @Override protected CharSequence getItemText(int index) { Stock stock = list.get(index); if (stock == null) { return ""; } Stocktype stocktype = WarehouseTool.instance.getStocktype(context, stock); if (stocktype == null) { return ""; } return stocktype.getName(); } public void clearAndFilterBystocktype(String methodname, int id) { this.list.clear(); this.list.addAll(originList); filterBystocktype(methodname, id); } public void filterBystocktype(String methodname, int id) { this. filtlist.clear(); List stocktypelist = WarehouseTool.instance.getListInStorage(context, Stocktype.class); // ArrayList flist=new ArrayList(this.list); Iterator< Stock> iter = this.list.iterator(); while (iter.hasNext()) { Stock t=iter.next(); int filterid = -1; Stocktype stocktypeOfStock = WarehouseTool.instance.getStocktypeInList(context, t, stocktypelist); if (stocktypeOfStock == null) { continue; } //example: filterid= stocktype.getCategoryId(); try { filterid = (int) Stocktype.class.getDeclaredMethod(methodname).invoke(stocktypeOfStock); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } if (filterid == id) { filtlist.add(t); } } changeList(filtlist); } public void filter(String methodname, int id) { this. filtlist.clear(); Iterator< Stock> iter = this.list.iterator(); while (iter.hasNext()) { Stock t=iter.next(); int inlistid = -1; try { inlistid = (int) Stock.class.getDeclaredMethod(methodname).invoke(t); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } if (inlistid == id) { filtlist.add(t); } } changeList(filtlist); } public void clearAndFilterOriginList(String methodname, int id) { this.list.clear(); this.list.addAll(originList); this.notifyDataChangedEvent(); filtlist.clear(); filter(methodname, id); } public void changeList(List list) { this.list.clear(); this.list.addAll(list); thiswheelView.invalidateWheel(true);//把CACHE清除 以免殘留 thiswheelView.setVisibleItems(list.size()); this.notifyDataChangedEvent(); } @Override public int getItemsCount() { if (list == null) { return 0; } return list.size(); } }
2015年5月1日 星期五
json 多形 抽象類別Polymorphic Deserialization
package com.lfo.vo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.lfo.suntone.db.CanGetName;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = As.PROPERTY, property = "@class")
@JsonSubTypes({
@Type(value = CommercialOutput.class, name = "CommercialOutput"),
@Type(value = ConsumptionOfRawMaterials.class, name = "ConsumptionOfRawMaterials") ,
@Type(value = ConsumptionOfWrapper.class, name = "ConsumptionOfWrapper") ,
@Type(value = SellingOut.class, name = "SellingOut")
})
public abstract class ManageItemOperationText implements CanGetName {
/*
產出商品commercial output
消耗原料consumption of raw materials
包裝消耗consumption of wrapper
賣出產品 selling-out
*/
//private int id=0;
//private String name="";
public String commercialOutput=" 產出商品";
public String consumptionOfRawMaterials="消耗原料";
public String consumptionOfWrapper="包裝消耗";
public String sellingOut="賣出產品";
/*
public Integer getId() {
return id;
}
public String getName() {
return name;
}
*/
}
package com.lfo.vo;
public class CommercialOutput extends ManageItemOperationText {
private int id=0;
private String name=super.commercialOutput;//"產出商品";
@Override
public String getName() {
return this.name;
}
@Override
public Integer getId() {
return this.id;
}
}
http://wiki.fasterxml.com/JacksonPolymorphicDeserialization
http://codelife.me/blog/2012/11/03/jackson-polymorphic-deserialization/
https://nickebbitt.wordpress.com/2014/01/31/handling-polymorphic-types-using-jackson-framework-for-json/
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.lfo.suntone.db.CanGetName;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = As.PROPERTY, property = "@class")
@JsonSubTypes({
@Type(value = CommercialOutput.class, name = "CommercialOutput"),
@Type(value = ConsumptionOfRawMaterials.class, name = "ConsumptionOfRawMaterials") ,
@Type(value = ConsumptionOfWrapper.class, name = "ConsumptionOfWrapper") ,
@Type(value = SellingOut.class, name = "SellingOut")
})
public abstract class ManageItemOperationText implements CanGetName {
/*
產出商品commercial output
消耗原料consumption of raw materials
包裝消耗consumption of wrapper
賣出產品 selling-out
*/
//private int id=0;
//private String name="";
public String commercialOutput=" 產出商品";
public String consumptionOfRawMaterials="消耗原料";
public String consumptionOfWrapper="包裝消耗";
public String sellingOut="賣出產品";
/*
public Integer getId() {
return id;
}
public String getName() {
return name;
}
*/
}
package com.lfo.vo;
public class CommercialOutput extends ManageItemOperationText {
private int id=0;
private String name=super.commercialOutput;//"產出商品";
@Override
public String getName() {
return this.name;
}
@Override
public Integer getId() {
return this.id;
}
}
http://wiki.fasterxml.com/JacksonPolymorphicDeserialization
http://codelife.me/blog/2012/11/03/jackson-polymorphic-deserialization/
https://nickebbitt.wordpress.com/2014/01/31/handling-polymorphic-types-using-jackson-framework-for-json/
訂閱:
意見 (Atom)