• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CachePolicy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.parse.ParseQuery.CachePolicy的典型用法代码示例。如果您正苦于以下问题:Java CachePolicy类的具体用法?Java CachePolicy怎么用?Java CachePolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CachePolicy类属于com.parse.ParseQuery包,在下文中一共展示了CachePolicy类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: updateData

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
public void updateData() {
	ParseQuery<Task> query = ParseQuery.getQuery(Task.class);
	query.whereEqualTo("user", ParseUser.getCurrentUser());
	query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
	query.orderByDescending("createdAt");
	query.findInBackground(new FindCallback<Task>() {
		@Override
		public void done(List<Task> tasks, ParseException error) {
			if (tasks != null) {
				mAdapter.clear();
				for (int i = 0; i < tasks.size(); i++) {
					mAdapter.add(tasks.get(i));
				}
			}
		}
	});
}
 
开发者ID:bhavyanshu,项目名称:CheckIt_Android,代码行数:18,代码来源:MainActivity.java


示例2: updateData

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
public void updateData() {
	ParseQuery<Promo> query = ParseQuery.getQuery(Promo.class);
	query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
	query.orderByDescending("createdAt");
	query.findInBackground(new FindCallback<Promo>() {
		@Override
		public void done(List<Promo> promo, ParseException error) {
			if (promo != null) {
				mAdapter.clear();
				for (int i = 0; i < promo.size(); i++) {
					mAdapter.add(promo.get(i));
				}
			}
		}
	});
}
 
开发者ID:bhavyanshu,项目名称:CheckIt_Android,代码行数:17,代码来源:PromoActivity.java


示例3: getPhotosAndSetUpUI

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
/**
 * Called when the app starts.
 * 
 * Load all the available photos for the meme background,
 * then setup the rest of the photo-related UI.
 * 
 * You should:
 * - Set the allPhotos member variable to the photos retrieved from Parse
 * - Call setUpPhotoSelectorAndPreview(imageSelect, previewImage)
 * @param imageSelect
 * @param previewImage
 */
private void getPhotosAndSetUpUI(final Spinner imageSelect, final ParseImageView previewImage) {
  ParseQuery<ParseObject> query = ParseQuery.getQuery("Photo");
  query.addDescendingOrder("createdAt");
  query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
  query.findInBackground(new FindCallback<ParseObject>() {
    @Override
    public void done(List<ParseObject> photos, ParseException e) {
      if (e == null) {
        Log.d(TAG, "Retrived " + photos.size() + " photos");
        allPhotos = photos;
        setUpPhotoSelectorAndPreview(imageSelect, previewImage);
      } else {
        Log.d(TAG, "Error retrieving photos: " + e.getMessage());
      }
    }
  });
}
 
开发者ID:ixu,项目名称:wallet,代码行数:30,代码来源:MainActivity.java


示例4: createQuery

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
/**
 * Creates a query for talks with all the includes and cache policy set.
 */
private static ParseQuery<Talk> createQuery() {
    ParseQuery<Talk> query = new ParseQuery<>(Talk.class);
    query.include("speakers");
    query.include("room");
    query.include("slot");
    query.include("event");
    query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
    return query;
}
 
开发者ID:xebia,项目名称:event-schedule-android,代码行数:13,代码来源:Talk.java


示例5: getTodos

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
public void getTodos() {
	ParseQuery<ParseObject> itemQuery = ParseQuery.getQuery("todoItems");
	itemQuery.orderByDescending("itemPriority");
	itemQuery.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);

	itemQuery.findInBackground(new FindCallback<ParseObject>() {

		@Override
		public void done(List<ParseObject> items, ParseException e) {
			// TODO Auto-generated method stub
			if (mSwipeRefreshLayout.isRefreshing()) {
				mSwipeRefreshLayout.setRefreshing(false);
			}
			pItems = items;
			String[] todos = new String[pItems.size()];
			int i = 0;
			ArrayList<String> todo_items = new ArrayList<String>(); // very
																	// important
																	// line.
																	// Fixes
																	// issue
																	// with
																	// swipe
																	// to
																	// dismiss
			for (ParseObject obj : pItems) {
				todo_items.add(obj.getString("itemName"));
				todos[i] = obj.getString("itemName");
				i++;
			}
			mAdapter2 = new ListAdapter(ToDoListActivity.this,
					R.layout.list_item, todo_items);
			// mAdapter = new ArrayAdapter<String>(ToDoListActivity.this,
			// android.R.layout.simple_list_item_1,todo_items);
			todolist.setAdapter(mAdapter2);

		}
	});
}
 
开发者ID:Shivam101,项目名称:ToDoList,代码行数:40,代码来源:ToDoListActivity.java


示例6: clearCache

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
private void clearCache() {
	L.d("Clearing cache. Cache policy: %s", query.getCachePolicy().toString());
	cache = null;
	ParseQuery.clearAllCachedResults();
	createQuery();
	query.setCachePolicy(CachePolicy.NETWORK_ONLY);
	notifyDataSetChanged();
}
 
开发者ID:cloudinary,项目名称:cloudinary_android_parse_sample,代码行数:9,代码来源:ListPhotosActivity.java


示例7: setUp

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
  super.setUp();

  // Register a mock cachedQueryController, the controller maintain a cache list and return
  // results based on query state's CachePolicy
  ParseQueryController queryController = mock(ParseQueryController.class);
  Answer<Task<List<ParseObject>>> queryAnswer = new Answer<Task<List<ParseObject>>>() {
    private List<ParseObject> cachedThings = new ArrayList<>();

    @Override
    public Task<List<ParseObject>> answer(InvocationOnMock invocation) throws Throwable {
      ParseQuery.State state = (ParseQuery.State) invocation.getArguments()[0];
      int start = state.skip();
      // The default value of limit in ParseQuery is -1.
      int end = state.limit() > 0 ?
          Math.min(state.skip() + state.limit(), TOTAL_THINGS) : TOTAL_THINGS;
      List<ParseObject> things;
      if (state.cachePolicy() == CachePolicy.CACHE_ONLY) {
        try {
          things = new ArrayList<>(cachedThings.subList(start, end));
        } catch (IndexOutOfBoundsException e) {
          // Cache miss, throw exception
          return Task.forError(
              new ParseException(ParseException.CACHE_MISS, "results not cached"));
        }
      } else {
        things = new ArrayList<>(savedThings.subList(start, end));
        // Update cache
        for (int i = start; i < end; i++) {
          if (i < cachedThings.size()) {
            cachedThings.set(i, savedThings.get(i));
          } else {
            cachedThings.add(i, savedThings.get(i));
          }
        }
      }
      return Task.forResult(things);
    }
  };
  when(queryController.findAsync(any(ParseQuery.State.class), any(ParseUser.class), any(Task.class)))
      .thenAnswer(queryAnswer);
  ParseCorePlugins.getInstance().registerQueryController(queryController);

  // Register a mock currentUserController to make getSessionToken work
  ParseCurrentUserController currentUserController = mock(ParseCurrentUserController.class);
  when(currentUserController.getAsync()).thenReturn(Task.forResult(mock(ParseUser.class)));
  when(currentUserController.getCurrentSessionTokenAsync())
      .thenReturn(Task.<String>forResult(null));
  ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);

  ParseObject.registerSubclass(Thing.class);
  // Make test data set
  for (int i = 0; i < TOTAL_THINGS; i++) {
    ParseObject thing = ParseObject.create("Thing");
    thing.put("aValue", i * 10);
    thing.put("name", "Thing " + i);
    thing.setObjectId(String.valueOf(i));
    savedThings.add(thing);
  }
}
 
开发者ID:LibertACAO,项目名称:libertacao-android,代码行数:62,代码来源:ParseQueryAdapterTest.java


示例8: testLoadObjectsWithCacheThenNetworkQueryAndPagination

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
public void testLoadObjectsWithCacheThenNetworkQueryAndPagination() throws Exception {
  QueryFactory<Thing> factory = new QueryFactory<Thing>() {
    @Override
    public ParseQuery<Thing> create() {
      ParseQuery<Thing> query = new ParseQuery<Thing>(Thing.class);
      query.setCachePolicy(CachePolicy.CACHE_THEN_NETWORK);
      return query;
    }
  };

  final ParseQueryAdapter<Thing> adapter = new ParseQueryAdapter<>(activity, factory);
  final int pageSize = 5;
  adapter.setObjectsPerPage(pageSize);
  adapter.setPaginationEnabled(true);
  final Capture<Integer> timesThrough = new Capture<>(0);
  final Semaphore done = new Semaphore(0);
  adapter.addOnQueryLoadListener(new OnQueryLoadListener<Thing>() {
    @Override
    public void onLoading() {
    }

    @Override
    public void onLoaded(List<Thing> objects, Exception e) {
      if (e != null) {
        return;
      }

      switch (timesThrough.get()) {
      case 0:
        // Network callback for first page
        assertEquals(pageSize, objects.size());
        assertEquals(pageSize + 1, adapter.getCount());
        adapter.loadNextPage();
        break;
      case 1:
        // Network callback for second page
        assertEquals(TOTAL_THINGS - pageSize, objects.size());
        assertEquals(TOTAL_THINGS, adapter.getCount());
        adapter.loadObjects();
        break;
      case 2:
        // Cache callback for first page
        assertEquals(pageSize, objects.size());
        assertEquals(pageSize + 1, adapter.getCount());
        break;
      case 3:
        // Network callback for first page
        assertEquals(pageSize, objects.size());
        assertEquals(pageSize + 1, adapter.getCount());
        adapter.loadNextPage();
        break;
      case 4:
        // Cache callback for second page
        assertEquals(TOTAL_THINGS - pageSize, objects.size());
        assertEquals(TOTAL_THINGS, adapter.getCount());
        break;
      case 5:
        // Network callback for second page
        assertEquals(TOTAL_THINGS - pageSize, objects.size());
        assertEquals(TOTAL_THINGS, adapter.getCount());
        done.release();
        break;
      }
      timesThrough.set(timesThrough.get() + 1);
    }
  });

  adapter.loadObjects();

  // Make sure we assert in callback is executed
  assertTrue(done.tryAcquire(10, TimeUnit.SECONDS));
}
 
开发者ID:LibertACAO,项目名称:libertacao-android,代码行数:73,代码来源:ParseQueryAdapterTest.java


示例9: createQuery

import com.parse.ParseQuery.CachePolicy; //导入依赖的package包/类
private void createQuery() {
	// Parse: Create a query for model Photo and set caching options
	query = ParseQuery.getQuery(Constants.PARSE_MODEL);
	query.setCachePolicy(CachePolicy.CACHE_ELSE_NETWORK);
}
 
开发者ID:cloudinary,项目名称:cloudinary_android_parse_sample,代码行数:6,代码来源:ListPhotosActivity.java



注:本文中的com.parse.ParseQuery.CachePolicy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ISO9796d1Encoding类代码示例发布时间:2022-05-23
下一篇:
Java ExceptionConstants类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap