<commit_before>package com.chopping.application;

import com.android.volley.NetworkResponse;
import com.android.volley.VolleyError;
import com.chopping.R;
import com.chopping.net.NetworkUtils;
import com.squareup.otto.Subscribe;

import org.apache.http.HttpStatus;

import java.lang.ref.WeakReference;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;

/**
 * Error handling for components like Activity, Fragment, Service etc.
 *
 * @author <NAME>
 */
public final class ErrorHandling implements Animation.AnimationListener, View.OnClickListener {
	private WeakReference<View> mStickyBannerRef;
	private AnimationSet mAnim;
	private WeakReference<Context> mContextWeakReference;

	//------------------------------------------------
	//Subscribes, event-handlers
	//------------------------------------------------

	@Subscribe
	public void onVolleyError(VolleyError e) {
		if (e.networkResponse != null) {
			int statusCode = e.networkResponse.statusCode;
			LL.d(String.format("Error-Handling find abnormal status: %d", statusCode));
			if (statusCode != HttpStatus.SC_OK) {
				Context context = mContextWeakReference.get();
				if (context != null) {
					openStickyBanner(context, NetworkUtils.isAirplaneModeOn(context));
				}
			}
		} else {
			Context context = mContextWeakReference.get();
			if (context != null) {
				openStickyBanner(context, NetworkUtils.isAirplaneModeOn(context));
			}
		}
		setText(e.networkResponse);
	}

	//------------------------------------------------

	/**
	 * onCreate Called according to the life-cycle of component(Fragment, Activity, Service etc.).
	 *
	 * @param fragment
	 * 		A fragment if error is handled for fragment.
	 */
	public void onCreate(Fragment fragment) {
		onCreate(fragment.getActivity());
	}

	/**
	 * onCreate Called according to the life-cycle of component(Fragment, Activity, Service etc.).
	 *
	 * @param activity
	 * 		An activity if error is handled for activity.
	 */
	public void onCreate(Activity activity) {
		mContextWeakReference = new WeakReference<Context>(activity);
		View sticky = activity.findViewById(R.id.err_sticky_container);
		mStickyBannerRef = new WeakReference<View>(sticky);<commit_msg>Test context first before using while VolleyError coming.<commit_after>package com.chopping.application;

import com.android.volley.NetworkResponse;
import com.android.volley.VolleyError;
import com.chopping.R;
import com.chopping.net.NetworkUtils;
import com.squareup.otto.Subscribe;

import org.apache.http.HttpStatus;

import java.lang.ref.WeakReference;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.TextView;

/**
 * Error handling for components like Activity, Fragment, Service etc.
 *
 * @author <NAME>
 */
public final class ErrorHandling implements Animation.AnimationListener, View.OnClickListener {
	private WeakReference<View> mStickyBannerRef;
	private AnimationSet mAnim;
	private WeakReference<Context> mContextWeakReference;

	//------------------------------------------------
	//Subscribes, event-handlers
	//------------------------------------------------

	@Subscribe
	public void onVolleyError(VolleyError e) {
		Context context = mContextWeakReference.get();
		if (context != null) {
			if (e.networkResponse != null) {
				int statusCode = e.networkResponse.statusCode;
				LL.d(String.format("Error-Handling find abnormal status: %d", statusCode));
				if (statusCode != HttpStatus.SC_OK) {
					openStickyBanner(context, NetworkUtils.isAirplaneModeOn(context));

				}
			} else {
				openStickyBanner(context, NetworkUtils.isAirplaneModeOn(context));
			}
			setText(e.networkResponse);
		}
	}

	//------------------------------------------------

	/**
	 * onCreate Called according to the life-cycle of component(Fragment, Activity, Service etc.).
	 *
	 * @param fragment
	 * 		A fragment if error is handled for fragment.
	 */
	public void onCreate(Fragment fragment) {
		onCreate(fragment.getActivity());
	}

	/**
	 * onCreate Called according to the life-cycle of component(Fragment, Activity, Service etc.).
	 *
	 * @param activity
	 * 		An activity if error is handled for activity.
	 */
	public void onCreate(Activity activity) {
		mContextWeakReference = new WeakReference<Context>(activity);
		View sticky = activity.findViewById(R.id.err_sticky_container);
		mStickyBannerRef = new WeakReference<View>(sticky);
{'fraction_non_alphanumeric': 0.1589018302828619, 'fraction_numerical': 0.00041597337770382697, 'mean_word_length': 3.452777777777778, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3105867', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1293, 'n_words': 318}