Android Open Source - GridListViewAdapters Base List Grid Activity






From Project

Back to project page GridListViewAdapters.

License

The source code is released under:

Apache License

If you think the Android project GridListViewAdapters listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright 2014-present Biraj Patel//from w w w  .  ja  v  a  2  s.co  m
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package com.birin.listgridadapter.base;

import java.util.ArrayList;

import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

import com.birin.gridlistviewadapters.utils.PositionCalculator;
import com.birin.gridlistviewadaptersdemo.R;
import com.birin.gridlistviewadaptersdemo.common.Constants;
import com.birin.listgridadapter.datasetup.Employee;
import com.birin.listgridadapter.datasetup.RetainedDataFragment;
import com.birin.listgridadapter.datasetup.RetainedDataFragment.DummyDataGeneratorCallback;

public class BaseListGridActivity extends Activity implements
    DummyDataGeneratorCallback {

  protected ListView listView;
  protected BaseEmployeeListGridAdapter gridAdapter;
  protected RetainedDataFragment dataRetainingFragment;
  protected LayoutInflater inflater;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    inflater = LayoutInflater.from(getApplicationContext());
    setContentView(R.layout.activity_main);
    loadRetainedFragment();
    listView = (ListView) findViewById(R.id.list_view);
    gridAdapter = getListAdapter();
    bindAdapterToList();
    addItemsInGrid(dataRetainingFragment.getListData());
  }

  protected BaseEmployeeListGridAdapter getListAdapter() {
    return new BaseEmployeeListGridAdapter(getApplicationContext(),
        getMaxCardsInRow());
  }

  protected void bindAdapterToList() {
    listView.setAdapter(gridAdapter);
  }

  private void loadRetainedFragment() {
    FragmentManager fm = getFragmentManager();
    dataRetainingFragment = (RetainedDataFragment) fm
        .findFragmentByTag(Constants.TAG_RETAINED_FRAGMENT);

    // If the Fragment is non-null, then it is currently being
    // retained across a configuration
    // changgenerateSomeDummyDataAndAddToList();e.
    if (dataRetainingFragment == null) {
      dataRetainingFragment = getRetainedDataFragment();
      fm.beginTransaction()
          .add(dataRetainingFragment, Constants.TAG_RETAINED_FRAGMENT)
          .commit();
    }
  }

  protected RetainedDataFragment getRetainedDataFragment() {
    return new RetainedDataFragment();
  }

  protected int getMaxCardsInRow() {
    return PositionCalculator.getMaxCardsFor(getCurrentOrientation(),
        Constants.MAX_CARDS_INFO);
  }

  protected int getCurrentOrientation() {
    return getResources().getConfiguration().orientation;
  }

  @Override
  public void onNewDummyDataGenerated(ArrayList<Employee> newDataList) {
    addItemsInGrid(newDataList);
  }

  protected void addItemsInGrid(ArrayList<Employee> newDataList) {
    if (null != newDataList && newDataList.isEmpty() == false) {
      findViewById(R.id.place_holder_text).setVisibility(View.GONE);
      listView.setVisibility(View.VISIBLE);
      gridAdapter.addItemsInGrid(newDataList);
    }
  }

  @Override
  public void onDataGeneratorTaskExecuting() {

  }

  @Override
  public void onDataGeneratorTaskCancelled() {

  }

}




Java Source Code List

com.birin.cursorgridadapter.base.BaseCursorGridActivity.java
com.birin.cursorgridadapter.base.BaseEmployeeCursorGridAdapter.java
com.birin.cursorgridadapter.datasetup.CursorRetainingFragment.java
com.birin.cursorgridadapter.datasetup.TestContentProviderSqlHelper.java
com.birin.cursorgridadapter.datasetup.TestContentProvider.java
com.birin.cursorgridadapter.demo1.FixedCursorItems.java
com.birin.cursorgridadapter.demo2.CardClickHandlingEmployeeCursorGridAdapter.java
com.birin.cursorgridadapter.demo2.CardClickHandlingFixedCursorItems.java
com.birin.cursorgridadapter.demo3.ChildAndCardClickHandlingEmployeeCursorGridAdapter.java
com.birin.cursorgridadapter.demo3.ChildAndCardClickHandlingFixedCursorItems.java
com.birin.cursorgridadapter.demo4.FixedCursorItemsRotationSupport.java
com.birin.cursorgridadapter.demo5.UnlimitedCursorItemsRotationSupportAutoLoadMore.java
com.birin.cursorgridadapter.demo6.UnlimitedCursorItemsRotationClickToLoadMore.java
com.birin.gridlistviewadapters.BaseGridAdapter.java
com.birin.gridlistviewadapters.Card.java
com.birin.gridlistviewadapters.CursorFilter.java
com.birin.gridlistviewadapters.CursorGridAdapter.java
com.birin.gridlistviewadapters.ListGridAdapter.java
com.birin.gridlistviewadapters.RowViewHolder.java
com.birin.gridlistviewadapters.dataholders.CardDataHolder.java
com.birin.gridlistviewadapters.dataholders.CardPositionInfo.java
com.birin.gridlistviewadapters.dataholders.RowDataHolder.java
com.birin.gridlistviewadapters.utils.ChildViewsClickHandler.java
com.birin.gridlistviewadapters.utils.GridDataStructure.java
com.birin.gridlistviewadapters.utils.MaxCardsInfo.java
com.birin.gridlistviewadapters.utils.OnLoadMoreRequestListener.java
com.birin.gridlistviewadapters.utils.PositionCalculator.java
com.birin.gridlistviewadapters.utils.ViewHolderPositionTagger.java
com.birin.gridlistviewadaptersdemo.BaseDemoMenuList.java
com.birin.gridlistviewadaptersdemo.CursorDataDemos.java
com.birin.gridlistviewadaptersdemo.JavaUtilListDataDemos.java
com.birin.gridlistviewadaptersdemo.ParentDemoMenuList.java
com.birin.gridlistviewadaptersdemo.common.CharacterDrawable.java
com.birin.gridlistviewadaptersdemo.common.Constants.java
com.birin.gridlistviewadaptersdemo.common.EmployeeCardViewHolder.java
com.birin.gridlistviewadaptersdemo.common.RandomInfoGenerator.java
com.birin.listgridadapter.base.BaseEmployeeListGridAdapter.java
com.birin.listgridadapter.base.BaseListGridActivity.java
com.birin.listgridadapter.datasetup.Employee.java
com.birin.listgridadapter.datasetup.RetainedDataFragment.java
com.birin.listgridadapter.demo1.SimplestListGridAdapterUsageDemoActivity.java
com.birin.listgridadapter.demo2.FixedListItems.java
com.birin.listgridadapter.demo3.CardClickHandlingEmployeeListGridAdapter.java
com.birin.listgridadapter.demo3.CardClickHandlingFixedListItems.java
com.birin.listgridadapter.demo4.ChildAndCardClickHandlingEmployeeListGridAdapter.java
com.birin.listgridadapter.demo4.ChildAndCardClickHandlingFixedListItems.java
com.birin.listgridadapter.demo5.FixedListItemsRotationSupport.java
com.birin.listgridadapter.demo6.UnlimitedListItemsRotationSupportAutoLoadMore.java
com.birin.listgridadapter.demo7.UnlimitedListItemsRotationSupportAutoLoadMoreMax100Items.java
com.birin.listgridadapter.demo8.UnlimitedListItemsRotationSupportClickToLoadMore.java