예제 #1
0
  /**
   * 描述:修改数据.
   *
   * @param <T> the generic type
   * @param storageQuery 条件实体
   * @param dao 实现AbDBDaoImpl的Dao
   * @param paramDataInsertListener 返回监听器
   */
  public <T> void deleteData(
      final AbStorageQuery storageQuery,
      final AbDBDaoImpl<T> dao,
      final AbDataOperationListener paramDataInsertListener) {

    AbTaskItem item = new AbTaskItem();
    item.callback =
        new AbTaskCallback() {

          @Override
          public void update() {
            if (retValue >= 0) {
              if (paramDataInsertListener != null) {
                paramDataInsertListener.onSuccess(retValue);
              }
            } else {
              if (paramDataInsertListener != null) {
                paramDataInsertListener.onFailure(errorCode101, errorMessage101);
              }
            }
          }

          @Override
          public void get() {
            // 执行插入
            // (1)获取数据库
            dao.startWritableDatabase(false);
            // (2)执行
            retValue = dao.delete(storageQuery.getWhereClause(), storageQuery.getWhereArgs());
            // (3)关闭数据库
            dao.closeDatabase(false);
          }
        };
    mAbTaskQueue.execute(item);
  }
예제 #2
0
 /**
  * 描述:获取存储实例.
  *
  * @param context the context
  * @return single instance of AbSqliteStorage
  */
 public static AbSqliteStorage getInstance(Context context) {
   mContext = context;
   if (null == mSqliteStorage) {
     mSqliteStorage = new AbSqliteStorage(context);
   }
   // 用队列避免并发访问数据库问题
   mAbTaskQueue = AbTaskQueue.getInstance();
   return mSqliteStorage;
 }
예제 #3
0
  /**
   * Find data.
   *
   * @param <T> 描述:查询数据
   * @param storageQuery the storage query
   * @param dao 实现AbDBDaoImpl的Dao
   * @param paramDataInsertListener 返回监听器
   */
  public <T> void findData(
      final AbStorageQuery storageQuery,
      final AbDBDaoImpl<T> dao,
      final AbDataInfoListener paramDataInsertListener) {

    final AbTaskItem item = new AbTaskItem();
    item.callback =
        new AbTaskListCallback() {

          @Override
          public void update(List<?> paramList) {
            if (paramDataInsertListener != null) {
              paramDataInsertListener.onSuccess(paramList);
            }
          }

          @Override
          public void get() {
            List<?> list = null;
            // 执行插入
            // (1)获取数据库
            dao.startReadableDatabase(false);
            // (2)执行
            if (storageQuery.getLimit() != -1 && storageQuery.getOffset() != -1) {
              list =
                  dao.queryList(
                      null,
                      storageQuery.getWhereClause(),
                      storageQuery.getWhereArgs(),
                      storageQuery.getGroupBy(),
                      storageQuery.getHaving(),
                      storageQuery.getOrderBy()
                          + " limit "
                          + storageQuery.getLimit()
                          + " offset "
                          + storageQuery.getOffset(),
                      null);
            } else {
              list =
                  dao.queryList(
                      null,
                      storageQuery.getWhereClause(),
                      storageQuery.getWhereArgs(),
                      storageQuery.getGroupBy(),
                      storageQuery.getHaving(),
                      storageQuery.getOrderBy(),
                      null);
            }
            // (3)关闭数据库
            dao.closeDatabase(false);

            // 设置返回结果
            item.setResult(list);
          }
        };
    mAbTaskQueue.execute(item);
  }
예제 #4
0
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mActivity = this.getActivity();
    application = (MyApplication) mActivity.getApplication();

    View view = inflater.inflate(R.layout.pull_list, null);
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i3/13215035600700175/T1C2mzXthaXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i2/13215025617307680/T1AQqAXqpeXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i1/13215035569460099/T16GuzXs0cXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i2/13215023694438773/T1lImmXElhXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i3/13215023521330093/T1BWuzXrhcXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i4/13215035563144015/T1Q.eyXsldXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mPhotoList.add(
        "http://img01.taobaocdn.com/bao/uploaded/i3/13215023749568975/T1UKWCXvpXXXXXXXXX_!!0-item_pic.jpg_230x230.jpg");
    mAbTaskQueue = AbTaskQueue.getInstance();
    // 获取ListView对象
    mAbPullListView = (AbPullListView) view.findViewById(R.id.mListView);

    // ListView数据
    list = new ArrayList<Map<String, Object>>();

    // 使用自定义的Adapter
    myListViewAdapter =
        new ImageListAdapter(
            mActivity,
            list,
            R.layout.list_items,
            new String[] {"itemsIcon", "itemsTitle", "itemsText"},
            new int[] {R.id.itemsIcon, R.id.itemsTitle, R.id.itemsText});
    mAbPullListView.setAdapter(myListViewAdapter);
    // item被点击事件
    mAbPullListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {}
        });

    return view;
  }
예제 #5
0
  /**
   * 描述:插入数据.
   *
   * @param <T> the generic type
   * @param entity 实体类 设置了对象关系映射
   * @param dao 实现AbDBDaoImpl的Dao
   * @param paramDataInsertListener 返回监听器
   */
  public <T> void insertData(
      final T entity,
      final AbDBDaoImpl<T> dao,
      final AbDataInsertListener paramDataInsertListener) {

    if (entity != null) {

      AbTaskItem item = new AbTaskItem();
      item.callback =
          new AbTaskCallback() {

            @Override
            public void update() {
              if (retValue >= 0) {
                if (paramDataInsertListener != null) {
                  paramDataInsertListener.onSuccess(retValue);
                }
              } else {
                if (paramDataInsertListener != null) {
                  paramDataInsertListener.onFailure(errorCode101, errorMessage101);
                }
              }
            }

            @Override
            public void get() {
              // 执行插入
              // (1)获取数据库
              dao.startWritableDatabase(false);
              // (2)执行
              retValue = dao.insert(entity);
              // (3)关闭数据库
              dao.closeDatabase(false);
            }
          };
      mAbTaskQueue.execute(item);

    } else {
      if (paramDataInsertListener != null) {
        paramDataInsertListener.onFailure(errorCode100, errorMessage100);
      }
    }
  }
예제 #6
0
  @Override
  public void onStart() {
    super.onStart();
    // 定义两种查询的事件
    final AbTaskItem item1 = new AbTaskItem();
    item1.callback =
        new AbTaskCallback() {

          @Override
          public void update() {
            list.clear();
            if (newList != null && newList.size() > 0) {
              list.addAll(newList);
              myListViewAdapter.notifyDataSetChanged();
              newList.clear();
            }
            mAbPullListView.stopRefresh();
          }

          @Override
          public void get() {
            try {
              Thread.sleep(1000);
              currentPage = 1;
              newList = new ArrayList<Map<String, Object>>();
              Map<String, Object> map = null;

              for (int i = 0; i < 10; i++) {
                map = new HashMap<String, Object>();
                map.put("itemsIcon", mPhotoList.get(new Random().nextInt(mPhotoList.size())));
                map.put("itemsTitle", "item" + i);
                map.put("itemsText", "item..." + i);
                newList.add(map);
              }
            } catch (Exception e) {
            }
          };
        };

    final AbTaskItem item2 = new AbTaskItem();
    item2.callback =
        new AbTaskCallback() {

          @Override
          public void update() {
            if (newList != null && newList.size() > 0) {
              list.addAll(newList);
              myListViewAdapter.notifyDataSetChanged();
              newList.clear();
              mAbPullListView.stopLoadMore(true);
            } else {
              // 没有新数据了
              mAbPullListView.stopLoadMore(false);
            }
          }

          @Override
          public void get() {
            try {
              currentPage++;
              Thread.sleep(1000);
              newList = new ArrayList<Map<String, Object>>();
              Map<String, Object> map = null;

              for (int i = 0; i < 10; i++) {
                map = new HashMap<String, Object>();
                map.put("itemsIcon", mPhotoList.get(new Random().nextInt(mPhotoList.size())));
                map.put("itemsTitle", "item上拉" + i);
                map.put("itemsText", "item上拉..." + i);
                newList.add(map);
              }
            } catch (Exception e) {
              currentPage--;
              newList.clear();
            }
          };
        };

    mAbPullListView.setAbOnListViewListener(
        new AbOnListViewListener() {

          @Override
          public void onRefresh() {
            mAbTaskQueue.execute(item1);
          }

          @Override
          public void onLoadMore() {
            mAbTaskQueue.execute(item2);
          }
        });

    // 第一次下载数据
    mAbTaskQueue.execute(item1);
  }
예제 #7
0
 /** 描述:释放存储实例. */
 public void release() {
   if (mAbTaskQueue != null) {
     mAbTaskQueue.quit();
   }
 }