Android Open Source - CustomersChoice Overwrite Variant Broad Cast Receiver






From Project

Back to project page CustomersChoice.

License

The source code is released under:

Apache License

If you think the Android project CustomersChoice 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 de.alosdev.android.customerschoice.broadcast;
//from   w  w  w  .j  a  v a2 s  .co  m
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import de.alosdev.android.customerschoice.CustomersChoice;
import de.alosdev.android.customerschoice.logger.Logger;


/**
 * This receiver can override the current variant, so you can define a a test case for your scenario.
 * <h1>Attention</h1>
 * Add also permissions to the broadcast receiver in the manifest, if you want to use it on a live application.
 * @author hhosgel
 */
public class OverwriteVariantBroadCastReceiver extends BroadcastReceiver {
  public static final String KEY_OVERWRITE_VARIANT = "OverWriteVariant";
  public static final String KEY_FORCE_VARIANT = "ForceVariant";

  @Override
  public void onReceive(Context context, Intent intent) {
    final String variantName = intent.getStringExtra(KEY_OVERWRITE_VARIANT);
    final int forceVariant = intent.getIntExtra(KEY_FORCE_VARIANT, 0);

    Logger log = CustomersChoice.getLogger();
    if ((null == variantName) || (variantName.length() < 1)) {
      log.w(CustomersChoice.TAG, "the sended Broadcast didn't contains a valid variant name: ", variantName);
      return;
    } else if (forceVariant < 0) {
      log.w(CustomersChoice.TAG, "the sended Broadcast must contain a forceVariant which is larger than -1.");
      return;
    }
    log.e(CustomersChoice.TAG, "set variant with ", variantName, " force value: ", forceVariant);

    CustomersChoice.forceVariant(context, variantName, forceVariant);
  }

}




Java Source Code List

de.alosdev.android.customerschoice.CustomersChoice.java
de.alosdev.android.customerschoice.VariantBuilder.java
de.alosdev.android.customerschoice.Variant.java
de.alosdev.android.customerschoice.broadcast.OverwriteVariantBroadCastReceiver.java
de.alosdev.android.customerschoice.demo.CustomersChoiceApplication.java
de.alosdev.android.customerschoice.demo.CustomersChoiceDemo.java
de.alosdev.android.customerschoice.demo.ShoppingCardActivity.java
de.alosdev.android.customerschoice.logger.AndroidLogger.java
de.alosdev.android.customerschoice.logger.ChainedLogger.java
de.alosdev.android.customerschoice.logger.Logger.java
de.alosdev.android.customerschoice.logger.NoLogger.java
de.alosdev.android.customerschoice.reporter.ChainedReporter.java
de.alosdev.android.customerschoice.reporter.LogReporter.java
de.alosdev.android.customerschoice.reporter.NoReporter.java
de.alosdev.android.customerschoice.reporter.Reporter.java