本文整理匯總了Java中org.litepal.crud.DataSupport類的典型用法代碼示例。如果您正苦於以下問題:Java DataSupport類的具體用法?Java DataSupport怎麽用?Java DataSupport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataSupport類屬於org.litepal.crud包,在下文中一共展示了DataSupport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadData
import org.litepal.crud.DataSupport; //導入依賴的package包/類
@Override
protected void loadData() {
DataSupport.findAllAsync(HeWeatherCity.class).listen(new FindMultiCallback() {
@Override
public <T> void onFinish(List<T> t) {
List<HeWeatherCity> list = (List<HeWeatherCity>) t;
HashSet<String> provinces = new HashSet<>();
for (HeWeatherCity city : list) {
provinces.add(city.getProvinceZh());
}
List<String> provinceArray = new ArrayList<>(provinces);
List<SimpleItem> datas = new ArrayList<>();
for (String s : provinceArray) {
datas.add(new SimpleItem(s));
}
provinceAdapter.setNewData(datas);
}
});
}
示例2: recursiveSupportedGenericFields
import org.litepal.crud.DataSupport; //導入依賴的package包/類
private void recursiveSupportedGenericFields(Class<?> clazz, List<Field> supportedGenericFields) {
if (clazz == DataSupport.class || clazz == Object.class) {
return;
}
Field[] fields = clazz.getDeclaredFields();
if (fields != null && fields.length > 0) {
for (Field field : fields) {
Column annotation = field.getAnnotation(Column.class);
if (annotation != null && annotation.ignore()) {
continue;
}
int modifiers = field.getModifiers();
if (!Modifier.isStatic(modifiers) && isCollection(field.getType())) {
String genericTypeName = getGenericTypeName(field);
if (BaseUtility.isGenericTypeSupported(genericTypeName)) {
supportedGenericFields.add(field);
}
}
}
}
recursiveSupportedGenericFields(clazz.getSuperclass(), supportedGenericFields);
}
示例3: queryCities
import org.litepal.crud.DataSupport; //導入依賴的package包/類
/**
* 查詢選中省內所有的市,優先從數據庫查詢,如果沒有查詢到再去服務器上查詢
*/
private void queryCities() {
titleText.setText(selectedProvince.getProvinceName());
backButton.setVisibility(View.VISIBLE);
cityList = DataSupport.where("provinceid = ?", String.valueOf(selectedProvince.getId())).find(City.class);
if (cityList.size() > 0) {
dataList.clear();
for (City city : cityList) {
dataList.add(city.getCityName());
}
adapter.notifyDataSetChanged();
listView.setSelection(0);
currentLevel = LEVEL_CITY;
} else {
int provinceCode = selectedProvince.getProvinceCode();
String address = "http://guolin.tech/api/china/" + provinceCode;
queryFromServer(address, "city");
}
}
示例4: onClick
import org.litepal.crud.DataSupport; //導入依賴的package包/類
@Override
public void onClick(View view) {
int result = 0;
switch (view.getId()) {
case R.id.sum_btn1:
result = DataSupport.sum(Singer.class, "age", Integer.TYPE);
mResultText.setText(String.valueOf(result));
break;
case R.id.sum_btn2:
try {
result = DataSupport.where("age > ?", mAgeEdit.getText().toString()).sum(
Singer.class, "age", Integer.TYPE);
mResultText.setText(String.valueOf(result));
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
}
}
示例5: onClick
import org.litepal.crud.DataSupport; //導入依賴的package包/類
@Override
public void onClick(View view) {
double result = 0;
switch (view.getId()) {
case R.id.avg_btn1:
result = DataSupport.average(Singer.class, "age");
mResultText.setText(String.valueOf(result));
break;
case R.id.avg_btn2:
try {
result = DataSupport.where("age > ?", mAgeEdit.getText().toString()).average(
Singer.class, "age");
mResultText.setText(String.valueOf(result));
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
}
}
示例6: onClick
import org.litepal.crud.DataSupport; //導入依賴的package包/類
@Override
public void onClick(View view) {
int result = 0;
switch (view.getId()) {
case R.id.max_btn1:
result = DataSupport.max(Singer.class, "age", Integer.TYPE);
mResultText.setText(String.valueOf(result));
break;
case R.id.max_btn2:
try {
result = DataSupport.where("age < ?", mAgeEdit.getText().toString()).max(
Singer.class, "age", Integer.TYPE);
mResultText.setText(String.valueOf(result));
} catch (Exception e) {
e.printStackTrace();
}
break;
default:
}
}
示例7: onOptionsItemSelected
import org.litepal.crud.DataSupport; //導入依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_sync_calendar) {
allIntake = DataSupport.findAll(IntakeMoment.class);
getResultsFromApi(allIntake);
return true;
}
if (id == R.id.action_add_medicine) {
add_fab();
return true;
}
return super.onOptionsItemSelected(item);
}
示例8: queryBasicInfo
import org.litepal.crud.DataSupport; //導入依賴的package包/類
private void queryBasicInfo(){
factory.getBasicInfo(new Observer<BasicInfo>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(BasicInfo value) {
DataSupport.deleteAll(BasicInfo.class);
value.save();
setBasicInfo4View(value);
}
@Override
public void onError(Throwable e) {
if(e != null && !TextUtils.isEmpty(e.getMessage())) {
LogUtils.e(e.toString());
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onComplete() {
}
});
}
示例9: calculateMonthlyMoney
import org.litepal.crud.DataSupport; //導入依賴的package包/類
public void calculateMonthlyMoney(int type, IOItem ioItem) {
Sum sum = new Sum();
Sum tmpSum = new Sum();
String sumDate = formatSum.format(new Date());
int id = (int)((double)type / 2 + 2.5);
// 保證一定現有2號id,避免出現當月支出不更新的bug
if (!tmpSum.isThereASum(tmpSum.MONTHLY_COST))
tmpSum.saveSum(tmpSum, tmpSum.MONTHLY_COST, 0.0, 1, sumDate);
if (sum.isThereASum(id)) {
sum = DataSupport.find(Sum.class, id);
if (sum.getDate().equals(ioItem.getTimeStamp().substring(0, 8))) {
sum.calculateMoney(id, ioItem.getMoney(), type*type);
} else {
sum.saveSum(sum, id, ioItem.getMoney(), type*type, sumDate);
}
} else {
sum.saveSum(sum, id, ioItem.getMoney(), type*type, sumDate);
}
}
示例10: testSaveFastWithConstructors
import org.litepal.crud.DataSupport; //導入依賴的package包/類
public void testSaveFastWithConstructors() {
Computer computer = new Computer("asus", 699.00);
assertTrue(computer.saveFast());
Assert.assertTrue(isDataExists(getTableName(computer), computer.getId()));
Computer c = getComputer(computer.getId());
assertEquals("asus", c.getBrand());
assertEquals(699.00, c.getPrice());
Computer cc = DataSupport.find(Computer.class, computer.getId());
assertEquals("asus", cc.getBrand());
assertEquals(699.00, cc.getPrice());
Product p = new Product(null);
p.setBrand("apple");
p.setPrice(1222.33);
p.saveFast();
Product.find(Product.class, p.getId());
}
示例11: onCreate
import org.litepal.crud.DataSupport; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_intake);
ButterKnife.bind(this);
//setSupportActionBar(toolbar);
intakeID = getIntent().getLongExtra("intakeID",-1);
intakeMoment = DataSupport.find(IntakeMoment.class,intakeID);
medicine = DataSupport.find(Medicine.class,intakeMoment.getMedicineId());
RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.pill_placeholder);
requestOptions.error(R.drawable.pill_placeholder);
requestOptions.centerCrop();
String image_path= medicine.getImage();
Glide.with(this).setDefaultRequestOptions(requestOptions).load(image_path).into(imageView);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(medicine.getName());
imageView.setBackgroundColor(getResources().getColor(R.color.grey));
time_text.setText(String.format("%02d:%02d", intakeMoment.getStartDate().getHours(),intakeMoment.getStartDate().getMinutes()));
seekBar.setProgress(intakeMoment.getQuantity());
}
示例12: queryCities
import org.litepal.crud.DataSupport; //導入依賴的package包/類
/**
* 查詢選中省內所有的市,優先從數據庫查詢,如果沒有查詢到再去服務器上查詢。
*/
private void queryCities() {
titleText.setText(selectedProvince.getProvinceName());
backButton.setVisibility(View.VISIBLE);
cityList = DataSupport.where("provinceid = ?", String.valueOf(selectedProvince.getId())).find(City.class);
if (cityList.size() > 0) {
dataList.clear();
for (City city : cityList) {
dataList.add(city.getCityName());
}
adapter.notifyDataSetChanged();
listView.setSelection(0);
currentLevel = LEVEL_CITY;
} else {
int provinceCode = selectedProvince.getProvinceCode();
String address = "http://guolin.tech/api/china/" + provinceCode;
queryFromServer(address, "city");
}
}
示例13: testSaveInheritModels
import org.litepal.crud.DataSupport; //導入依賴的package包/類
public void testSaveInheritModels() {
WeChatMessage weChatMessage = new WeChatMessage();
weChatMessage.setFriend("Tom");
weChatMessage.setContent("Hello nice to meet you");
weChatMessage.setTitle("Greeting message");
weChatMessage.setType(1);
assertTrue(weChatMessage.save());
assertTrue(weChatMessage.getId() > 0);
WeChatMessage message1 = DataSupport.find(WeChatMessage.class, weChatMessage.getId());
assertEquals("Tom", message1.getFriend());
assertEquals("Hello nice to meet you", message1.getContent());
assertNull(message1.getTitle());
assertEquals(1, message1.getType());
WeiboMessage weiboMessage = new WeiboMessage();
weiboMessage.setType(2);
weiboMessage.setTitle("Following message");
weiboMessage.setContent("Something big happens");
weiboMessage.setFollower("Jimmy");
weiboMessage.setNumber(123456);
assertTrue(weiboMessage.saveFast());
assertTrue(weiboMessage.getId() > 0);
}
示例14: queryCounties
import org.litepal.crud.DataSupport; //導入依賴的package包/類
/**
* 1、查詢選中市所有的縣,優先從數據庫查詢,如果沒有查詢到,則到服務器去查詢
* 2、更新界麵
*/
private void queryCounties() {
titleText.setText(selectedCity.getCityName());
backButton.setVisibility(View.VISIBLE);
countyList = DataSupport.where("cityid = ?",String.valueOf(selectedCity.getId())).find(County.class);
if (countyList.size() > 0) {
dataList.clear();
for (County county : countyList) {
dataList.add(county.getCountyName());
}
adapter.notifyDataSetChanged();
listView.setSelection(0);
currentLevel = LEVEL_COUNTY;
} else {
int provinceCode = selectedProvince.getProvinceCode();
int cityCode = selectedCity.getCityCode();
String address = "http://guolin.tech/api/china/" + provinceCode + "/" + cityCode;
queryFromServer(address, "county");
}
}
示例15: queryProvinces
import org.litepal.crud.DataSupport; //導入依賴的package包/類
private void queryProvinces() {
titleText.setText("中國");
backButton.setVisibility(View.GONE);
provinceList = DataSupport.findAll(Province.class);
if (provinceList.size() > 0) {
dataList.clear();
for (Province province : provinceList) {
dataList.add(province.getProvinceName());
}
adapter.notifyDataSetChanged();
listView.setSelection(0);
currentLevel = LEVEL_PROVINCE;
} else {
String address = "http://guolin.tech/api/china";
queryFromServer(address, "province");
}
}