Android Open Source - bv-android-sdk Rating Preview 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

package com.bazaarvoice.example.reviewsubmission;
//from   w  w w. j a  v a 2 s  . c o  m
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.Html;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.ViewAnimator;

/**
 * RatingPreviewActivity.java <br>
 * ReviewSubmissionExample<br>
 * 
 * This is a simple display showing the user that their review has been
 * submitted and what it looks like. There is a simple "Thank You" animation as
 * well.
 * 
 * <p>
 * Created on 6/29/12. Copyright (c) 2012 BazaarVoice. All rights reserved.
 * 
 * @author Bazaarvoice Engineering
 */
public class RatingPreviewActivity extends Activity {

  private ViewAnimator thankYou;

  /**
   * Called when the activity is first created. All of this activity's
   * information is sent over in an Intent, so it must be unpacked.
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.preview);
    CameraUtils.clearPhotos();

    Intent myIntent = getIntent();
    initializeViews(myIntent);
  }

  /**
   * Changes the action of the back button to restart the app. We don't want
   * the user to be able to go back to the submission form after submitting.
   */
  @Override
  public void onBackPressed() {
    Intent i = getBaseContext().getPackageManager()
        .getLaunchIntentForPackage(getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
  }

  /**
   * Sets up the UI elements and listeners.
   * 
   * @param myIntent
   *            the intent that launched this activity
   */
  private void initializeViews(Intent myIntent) {
    thankYou = (ViewAnimator) findViewById(R.id.thankYou);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(2000);
    thankYou.setInAnimation(animation);
    animation = new AlphaAnimation(1.0f, 0.0f);
    animation.setDuration(2000);
    thankYou.setOutAnimation(animation);
    thankYou.setAnimateFirstView(true);
    thankYou.setDisplayedChild(0);
    setAnimationTimer(1, 4000);

    TextView reviewTitle = (TextView) findViewById(R.id.reviewTitle);
    TextView reviewNickname = (TextView) findViewById(R.id.reviewNickname);
    TextView reviewText = (TextView) findViewById(R.id.reviewText);
    RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
    ImageView reviewPhoto = (ImageView) findViewById(R.id.reviewPhoto);

    reviewTitle.setText(myIntent.getStringExtra("reviewTitle"));
    reviewNickname.setText(Html.fromHtml("By <b>"
        + myIntent.getStringExtra("reviewNickname") + "</b> "));
    reviewText.setText(myIntent.getStringExtra("reviewText"));
    ratingBar.setRating(myIntent.getIntExtra("reviewRating", 3));
    byte[] byteArray = myIntent.getByteArrayExtra("displayImage");
    reviewPhoto.setImageBitmap(BitmapFactory.decodeByteArray(byteArray, 0,
        byteArray.length));
  }

  /**
   * Sets a timer to transition to a child of the ViewAnimator after a certain
   * delay.
   * 
   * @param childNum
   *            the child we want to transition to
   * @param delay
   *            the delay in milliseconds before firing
   */
  private void setAnimationTimer(final int childNum, int delay) {
    TimerTask task = new TimerTask() {

      @Override
      public void run() {
        runOnUiThread(new Runnable() {

          @Override
          public void run() {
            thankYou.setDisplayedChild(childNum);
          }

        });
      }

    };
    Timer timer = new Timer();
    timer.schedule(task, delay);
  }

}




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