public ProgressLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(attrs); }
private void hideEmptyView() { if (emptyStateRelativeLayout != null) { emptyStateRelativeLayout.setVisibility(GONE); //Restore the background color if not TRANSPARENT if (emptyStateBackgroundColor != Color.TRANSPARENT) { this.setBackgroundDrawable(currentBackground); } } }
hideLoadingView(); hideEmptyView(); hideErrorView(); setContentVisibility(true, skipIds); break; case LOADING: hideEmptyView(); hideErrorView(); setLoadingView(); setContentVisibility(false, skipIds); break; case EMPTY: hideLoadingView(); hideErrorView(); setEmptyView(); if (drawable != null) { emptyStateImageView.setImageDrawable(drawable); setContentVisibility(false, skipIds); break; case ERROR: hideLoadingView(); hideEmptyView(); setErrorView();
private void init(AttributeSet attrs) { inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressLayout); Resources res = getResources(); float scaleRatio = res.getDisplayMetrics().density; emptyStateImageHeight = (int) (typedArray.getDimension(R.styleable.ProgressLayout_emptyImageHeight, emptyStateImageHeight) / scaleRatio); emptyStateContentTextSize = (int) (typedArray.getDimension(R.styleable.ProgressLayout_emptyContentTextSize, emptyStateContentTextSize) / scaleRatio); emptyStateContentTextColor = typedArray.getColor(R.styleable.ProgressLayout_emptyContentTextColor, ContextCompat.getColor(getContext(), R.color.grey)); emptyStateBackgroundColor = typedArray.getColor(R.styleable.ProgressLayout_emptyBackgroundColor, Color.TRANSPARENT); errorStateContentTextSize = (int) (typedArray.getDimension(R.styleable.ProgressLayout_errorContentTextSize, errorStateContentTextSize) / scaleRatio); errorStateButtonTextSize = (int) (typedArray.getDimension(R.styleable.ProgressLayout_errorButtonTextSize, errorStateButtonTextSize) / scaleRatio); errorStateContentTextColor = typedArray.getColor(R.styleable.ProgressLayout_errorContentTextColor, ContextCompat.getColor(getContext(), R.color.grey)); errorStateButtonTextColor = typedArray.getColor(R.styleable.ProgressLayout_errorButtonTextColor, ContextCompat.getColor(getContext(), R.color.teal)); errorStateBackgroundColor = typedArray.getColor(R.styleable.ProgressLayout_errorBackgroundColor, Color.TRANSPARENT); currentBackground = this.getBackground();
private void setEmptyView() { if (emptyStateRelativeLayout == null) { view = inflater.inflate(R.layout.progress_empty_view, null); emptyStateRelativeLayout = (RelativeLayout) view.findViewById(R.id.emptyStateRelativeLayout); emptyStateRelativeLayout.setTag(TAG_EMPTY); emptyStateImageView = (ImageView) view.findViewById(R.id.emptyStateImageView); emptyStateContentTextView = (TextView) view.findViewById(R.id.emptyStateContentTextView); //Set empty state image width and height emptyStateImageView.getLayoutParams().width = emptyStateImageWidth; emptyStateImageView.getLayoutParams().height = emptyStateImageHeight; emptyStateImageView.requestLayout(); emptyStateContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, emptyStateContentTextSize); emptyStateContentTextView.setTextColor(emptyStateContentTextColor); //Set background color if not TRANSPARENT if (emptyStateBackgroundColor != Color.TRANSPARENT) { this.setBackgroundColor(emptyStateBackgroundColor); } layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.addRule(CENTER_IN_PARENT); addView(emptyStateRelativeLayout, layoutParams); } else { emptyStateRelativeLayout.setVisibility(VISIBLE); } }
private void setErrorView() { if (errorStateRelativeLayout == null) { view = inflater.inflate(R.layout.progress_error_view, null); errorStateRelativeLayout = (RelativeLayout) view.findViewById(R.id.errorStateRelativeLayout); errorStateRelativeLayout.setTag(TAG_ERROR); errorStateImageView = (ImageView) view.findViewById(R.id.errorStateImageView); errorStateContentTextView = (TextView) view.findViewById(R.id.errorStateContentTextView); errorStateButton = (Button) view.findViewById(R.id.errorStateButton); //Set error state image width and height errorStateImageView.getLayoutParams().width = errorStateImageWidth; errorStateImageView.getLayoutParams().height = errorStateImageHeight; errorStateImageView.requestLayout(); errorStateContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, errorStateContentTextSize); errorStateContentTextView.setTextColor(errorStateContentTextColor); errorStateButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, errorStateButtonTextSize); errorStateButton.setTextColor(errorStateButtonTextColor); //Set background color if not TRANSPARENT if (errorStateBackgroundColor != Color.TRANSPARENT) { this.setBackgroundColor(errorStateBackgroundColor); } layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.addRule(CENTER_IN_PARENT); addView(errorStateRelativeLayout, layoutParams); } else { errorStateRelativeLayout.setVisibility(VISIBLE); } }
private void setLoadingView() { if (loadingStateRelativeLayout == null) { view = inflater.inflate(R.layout.progress_loading_view, null); loadingStateRelativeLayout = (RelativeLayout) view.findViewById(R.id.loadingStateRelativeLayout); loadingStateRelativeLayout.setTag(TAG_LOADING); loadingStateProgressBar = (ProgressWheel) view.findViewById(R.id.loadingStateProgressBar); loadingStateProgressBar.getLayoutParams().width = loadingStateProgressBarRadius; loadingStateProgressBar.getLayoutParams().height = loadingStateProgressBarRadius; loadingStateProgressBar.setBarWidth(loadingStateProgressBarSpinWidth); if (loadingStateProgressBarColor != Color.TRANSPARENT) { loadingStateProgressBar.setBarColor(loadingStateProgressBarColor); } loadingStateProgressBar.requestLayout(); //Set background color if not TRANSPARENT if (loadingStateBackgroundColor != Color.TRANSPARENT) { this.setBackgroundColor(loadingStateBackgroundColor); } layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); layoutParams.addRule(CENTER_IN_PARENT); addView(loadingStateRelativeLayout, layoutParams); } else { loadingStateRelativeLayout.setVisibility(VISIBLE); } }
private void hideErrorView() { if (errorStateRelativeLayout != null) { errorStateRelativeLayout.setVisibility(GONE); //Restore the background color if not TRANSPARENT if (errorStateBackgroundColor != Color.TRANSPARENT) { this.setBackgroundDrawable(currentBackground); } } }
public ProgressLayout(Context context, AttributeSet attrs) { super(context, attrs); init(attrs); }
private void hideLoadingView() { if (loadingStateRelativeLayout != null) { loadingStateRelativeLayout.setVisibility(GONE); //Restore the background color if not TRANSPARENT if (loadingStateBackgroundColor != Color.TRANSPARENT) { this.setBackgroundDrawable(currentBackground); } } }