@Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View view = inflater.inflate(R.layout.icon_fragment, container, false);
   Display display = getActivity().getWindowManager().getDefaultDisplay();
   Point size = new Point();
   display.getSize(size);
   int numOfRows = (int) (size.x / getResources().getDimension(R.dimen.size_of_grid_item));
   RecyclerView gridview = (RecyclerView) view.findViewById(R.id.icons_rv);
   GridLayoutManager layoutManager = new GridLayoutManager(view.getContext(), numOfRows);
   layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
   layoutManager.scrollToPosition(0);
   gridview.setLayoutManager(layoutManager);
   gridview.setHasFixedSize(true);
   gridview.addItemDecoration(new SpacesItemDecoration(10, 5));
   gridview.setAdapter(
       new IconsAdapter(view.getContext(), getArguments().getInt("iconsArrayId", 0)));
   return view;
 }
Ejemplo n.º 2
0
 @Override
 public void onListLoaded(String jsonResult) {
   try {
     if (jsonResult != null) {
       try {
         JSONObject jsonResponse = new JSONObject(jsonResult);
         JSONArray jsonMainNode = jsonResponse.optJSONArray("walls");
         for (int i = 0; i < jsonMainNode.length(); i++) {
           JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
           items.add(
               new WallpaperItem(
                   jsonChildNode.optString("name"),
                   jsonChildNode.optString("author"),
                   jsonChildNode.optString("url")));
         }
       } catch (JSONException e) {
         e.printStackTrace();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   RecyclerView gridview = (RecyclerView) findViewById(R.id.wall_rv);
   Display display = getWindowManager().getDefaultDisplay();
   Point size = new Point();
   display.getSize(size);
   (findViewById(R.id.progressBar_wall)).setVisibility(View.GONE);
   int numOfRows = (int) (size.x / getResources().getDimension(R.dimen.size_of_grid_item));
   GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
   layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
   layoutManager.scrollToPosition(0);
   gridview.setLayoutManager(layoutManager);
   gridview.setHasFixedSize(true);
   gridview.addItemDecoration(new SpacesItemDecoration(8, 2));
   gridview.setAdapter(new WallAdapter(this, items, display));
 }