Android Open Source - bv-android-sdk Grid Activity






From Project

Back to project page bv-android-sdk.

License

The source code is released under:

Apache License

If you think the Android project bv-android-sdk 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 (c) 2012 Chute Corporation
//w w  w. ja  va  2s . c o  m
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package com.chute.android.photopickerplus.app;

import android.app.Activity;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import com.chute.android.photopickerplus.R;
import com.chute.android.photopickerplus.adapter.PhotoSelectCursorAdapter;
import com.chute.android.photopickerplus.adapter.PhotosAdapter;
import com.chute.android.photopickerplus.dao.MediaDAO;
import com.chute.android.photopickerplus.util.AppUtil;
import com.chute.android.photopickerplus.util.NotificationUtil;
import com.chute.android.photopickerplus.util.intent.IntentUtil;
import com.chute.android.photopickerplus.util.intent.PhotosIntentWrapper;
import com.chute.sdk.api.GCHttpCallback;
import com.chute.sdk.api.account.GCAccounts;
import com.chute.sdk.collections.GCAccountMediaCollection;
import com.chute.sdk.model.GCHttpRequestParameters;

public class GridActivity extends Activity {

  public static final String TAG = GridActivity.class.getSimpleName();

  private GridView grid;
  private PhotoSelectCursorAdapter cursorAdapter;
  private PhotosAdapter socialAdapter;
  private PhotosIntentWrapper wrapper;
  private TextView selectPhotos;
  private View emptyView;

  private String accountId;
  private String albumId;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.photos_select);

    selectPhotos = (TextView) findViewById(R.id.txt_select_photos);
    grid = (GridView) findViewById(R.id.gridView);
    emptyView = findViewById(R.id.empty_view_layout);
    grid.setEmptyView(emptyView);

    wrapper = new PhotosIntentWrapper(getIntent());

    Button ok = (Button) findViewById(R.id.btnOk);
    ok.setOnClickListener(new OkClickListener());
    Button cancel = (Button) findViewById(R.id.btnCancel);
    cancel.setOnClickListener(new CancelClickListener());

    if ((wrapper.getFilterType() == PhotosIntentWrapper.TYPE_ALL_PHOTOS)
        || (wrapper.getFilterType() == PhotosIntentWrapper.TYPE_CAMERA_ROLL)) {
      new LoadCursorTask().execute();
    } else if (wrapper.getFilterType() == PhotosIntentWrapper.TYPE_SOCIAL_PHOTOS) {
      accountId = wrapper.getAccountId();
      albumId = wrapper.getAlbumId();
      GCAccounts.objectMedia(getApplicationContext(), accountId, albumId,
          new PhotoListCallback()).executeAsync();
    }

  }

  private class LoadCursorTask extends AsyncTask<Void, Void, Cursor> {

    @Override
    protected Cursor doInBackground(final Void... arg0) {
      if (wrapper.getFilterType() == PhotosIntentWrapper.TYPE_ALL_PHOTOS) {
        return MediaDAO.getAllMediaPhotos(getApplicationContext());
      } else if (wrapper.getFilterType() == PhotosIntentWrapper.TYPE_CAMERA_ROLL) {
        return MediaDAO.getCameraPhotos(getApplicationContext());
      } else {
        return null;
      }
    }

    @Override
    protected void onPostExecute(final Cursor result) {
      super.onPostExecute(result);
      if (result == null) {
        return;
      }
      cursorAdapter = new PhotoSelectCursorAdapter(GridActivity.this,
          result);
      grid.setAdapter(cursorAdapter);

      if (cursorAdapter.getCount() == 0) {
        emptyView.setVisibility(View.GONE);
      }

      if (wrapper.getIsMultiPicker() == true) {
        selectPhotos.setText(getApplicationContext().getResources()
            .getString(R.string.select_photos));
        grid.setOnItemClickListener(new OnMultiSelectGridItemClickListener());
      } else {
        selectPhotos.setText(getApplicationContext().getResources()
            .getString(R.string.select_a_photo));
        grid.setOnItemClickListener(new OnSingleSelectGridItemClickListener());
      }
      NotificationUtil.showPhotosAdapterToast(getApplicationContext(),
          cursorAdapter.getCount());
    }
  }

  private final class OnMultiSelectGridItemClickListener implements
      OnItemClickListener {

    @Override
    public void onItemClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
      cursorAdapter.toggleTick(position);
    }
  }

  private final class OnSingleSelectGridItemClickListener implements
      OnItemClickListener {

    @Override
    public void onItemClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
      IntentUtil.deliverDataToInitialActivity(GridActivity.this,
          AppUtil.getMediaModel(cursorAdapter.getItem(position)),
          wrapper.getChuteId());
      setResult(RESULT_OK);
      finish();
    }
  }

  private final class CancelClickListener implements OnClickListener {

    @Override
    public void onClick(View v) {
      finish();
    }

  }

  private final class PhotoListCallback implements
      GCHttpCallback<GCAccountMediaCollection> {

    @Override
    public void onSuccess(GCAccountMediaCollection responseData) {
      socialAdapter = new PhotosAdapter(GridActivity.this, responseData);
      grid.setAdapter(socialAdapter);

      if (socialAdapter.getCount() == 0) {
        emptyView.setVisibility(View.GONE);
      }

      if (wrapper.getIsMultiPicker() == true) {
        selectPhotos.setText(getApplicationContext().getResources()
            .getString(R.string.select_photos));
        grid.setOnItemClickListener(new OnMultiGridItemClickListener());
      } else {
        selectPhotos.setText(getApplicationContext().getResources()
            .getString(R.string.select_a_photo));
        grid.setOnItemClickListener(new OnSingleGridItemClickListener());
      }
      NotificationUtil.showPhotosAdapterToast(getApplicationContext(),
          socialAdapter.getCount());
    }

    @Override
    public void onHttpException(GCHttpRequestParameters params,
        Throwable exception) {
      NotificationUtil
          .makeConnectionProblemToast(getApplicationContext());
      toggleEmptyViewErrorMessage();
    }

    @Override
    public void onHttpError(int responseCode, String statusMessage) {
      NotificationUtil.makeServerErrorToast(getApplicationContext());
      toggleEmptyViewErrorMessage();
    }

    @Override
    public void onParserException(int responseCode, Throwable exception) {
      NotificationUtil.makeParserErrorToast(getApplicationContext());
      toggleEmptyViewErrorMessage();
    }

    public void toggleEmptyViewErrorMessage() {
      findViewById(R.id.empty_view_layout).setVisibility(View.GONE);
    }
  }

  private final class OnSingleGridItemClickListener implements
      OnItemClickListener {

    @Override
    public void onItemClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
      IntentUtil.deliverDataToInitialActivity(GridActivity.this,
          socialAdapter.getItem(position), wrapper.getChuteId());
      setResult(RESULT_OK);
      finish();
    }
  }

  private final class OnMultiGridItemClickListener implements
      OnItemClickListener {

    @Override
    public void onItemClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
      socialAdapter.toggleTick(position);
    }
  }

  private final class OkClickListener implements OnClickListener {

    @Override
    public void onClick(View v) {
      if (wrapper.getFilterType() == PhotosIntentWrapper.TYPE_SOCIAL_PHOTOS) {
        IntentUtil.deliverDataToInitialActivity(GridActivity.this,
            socialAdapter.getPhotoCollection(), null, null,
            wrapper.getChuteId());
        setResult(RESULT_OK);
      } else if ((wrapper.getFilterType() == PhotosIntentWrapper.TYPE_ALL_PHOTOS)
          || (wrapper.getFilterType() == PhotosIntentWrapper.TYPE_CAMERA_ROLL)) {
        IntentUtil.deliverDataToInitialActivity(GridActivity.this,
            AppUtil.getPhotoCollection(cursorAdapter
                .getSelectedFilePaths()), null, null, wrapper
                .getChuteId());
        setResult(RESULT_OK);
      }
      finish();
    }
  }
}




Java Source Code List

com.bazaarvoice.BazaarException.java
com.bazaarvoice.BazaarParams.java
com.bazaarvoice.BazaarRequest.java
com.bazaarvoice.DisplayParams.java
com.bazaarvoice.Media.java
com.bazaarvoice.OnBazaarResponse.java
com.bazaarvoice.SubmissionMediaParams.java
com.bazaarvoice.SubmissionParams.java
com.bazaarvoice.example.browseproducts.BazaarFunctions.java
com.bazaarvoice.example.browseproducts.BazaarProduct.java
com.bazaarvoice.example.browseproducts.BazaarReview.java
com.bazaarvoice.example.browseproducts.BazaarUIThreadResponse.java
com.bazaarvoice.example.browseproducts.ImageDownloader.java
com.bazaarvoice.example.browseproducts.MainActivity.java
com.bazaarvoice.example.browseproducts.OnImageDownloadComplete.java
com.bazaarvoice.example.browseproducts.ProductAdapter.java
com.bazaarvoice.example.browseproducts.ProductsActivity.java
com.bazaarvoice.example.browseproducts.ReviewAdapter.java
com.bazaarvoice.example.browseproducts.ReviewDisplayActivity.java
com.bazaarvoice.example.browseproducts.ReviewsActivity.java
com.bazaarvoice.example.reviewsubmission.BazaarFunctions.java
com.bazaarvoice.example.reviewsubmission.BazaarReview.java
com.bazaarvoice.example.reviewsubmission.CameraUtils.java
com.bazaarvoice.example.reviewsubmission.ImageDownloader.java
com.bazaarvoice.example.reviewsubmission.MainActivity.java
com.bazaarvoice.example.reviewsubmission.OnImageDownloadComplete.java
com.bazaarvoice.example.reviewsubmission.OnImageUploadComplete.java
com.bazaarvoice.example.reviewsubmission.RatingActivity.java
com.bazaarvoice.example.reviewsubmission.RatingPreviewActivity.java
com.bazaarvoice.example.reviewsubmission.ReviewSubmissionApp.java
com.bazaarvoice.intentexample.BazaarFunctions.java
com.bazaarvoice.intentexample.BazaarUIThreadResponse.java
com.bazaarvoice.intentexample.CameraUtils.java
com.bazaarvoice.intentexample.MainActivity.java
com.bazaarvoice.types.Action.java
com.bazaarvoice.types.ApiVersion.java
com.bazaarvoice.types.Equality.java
com.bazaarvoice.types.FeedbackContentType.java
com.bazaarvoice.types.FeedbackType.java
com.bazaarvoice.types.FeedbackVoteType.java
com.bazaarvoice.types.IncludeStatsType.java
com.bazaarvoice.types.IncludeType.java
com.bazaarvoice.types.MediaParamsContentType.java
com.bazaarvoice.types.RequestType.java
com.chute.android.photopickerplus.adapter.AlbumsAdapter.java
com.chute.android.photopickerplus.adapter.PhotoSelectCursorAdapter.java
com.chute.android.photopickerplus.adapter.PhotosAdapter.java
com.chute.android.photopickerplus.app.AlbumsActivity.java
com.chute.android.photopickerplus.app.ChooseServiceActivity.java
com.chute.android.photopickerplus.app.GridActivity.java
com.chute.android.photopickerplus.app.PhotoPickerPlusApp.java
com.chute.android.photopickerplus.dao.MediaDAO.java
com.chute.android.photopickerplus.util.AppUtil.java
com.chute.android.photopickerplus.util.Constants.java
com.chute.android.photopickerplus.util.NotificationUtil.java
com.chute.android.photopickerplus.util.intent.AlbumsActivityIntentWrapper.java
com.chute.android.photopickerplus.util.intent.IntentUtil.java
com.chute.android.photopickerplus.util.intent.IntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotoActivityIntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotoPickerPlusIntentWrapper.java
com.chute.android.photopickerplus.util.intent.PhotosIntentWrapper.java
com.example.productwidgetexample.BazaarFunctions.java
com.example.productwidgetexample.BazaarProduct.java
com.example.productwidgetexample.BazaarReview.java
com.example.productwidgetexample.BazaarUIThreadResponse.java
com.example.productwidgetexample.ImageDownloader.java
com.example.productwidgetexample.OnImageDownloadComplete.java
com.example.productwidgetexample.ProductWidgetProvider.java
com.example.productwidgetexample.ReviewAdapter.java
com.example.productwidgetexample.ReviewsActivity.java