Android Open Source - jogjakota-perizinan Status View






From Project

Back to project page jogjakota-perizinan.

License

The source code is released under:

MIT License

If you think the Android project jogjakota-perizinan 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 id.go.jogjakota.perizinan;
//  w w  w.  j  av a  2  s  .co m
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by akhyar
 */
public class StatusView extends FrameLayout {
    public static final String DEFAULT_ERROR = "Gagal memuat data";
    public static final String DEFAULT_EMPTY = "No data available";

    @InjectView(R.id.statusMessage)
    TextView mStatusMessage;
    @InjectView(R.id.exceptionMessage)
    TextView mExceptionMessage;
    @InjectView(R.id.messageArea)
    LinearLayout mMessageArea;
    @InjectView(R.id.progress)
    ProgressBar mProgress;

    private OnRefreshListener mOnRefreshListener;

    public StatusView(Context context) {
        super(context);
        init(context);
    }

    public StatusView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public StatusView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.view_status, this, true);
        ButterKnife.inject(this, this);

        setClickable(true);
        showMessage(DEFAULT_ERROR);
        hide();
    }

    public String getStatusMessage() {
        return mStatusMessage.getText().toString();
    }

    public void setStatusMessage(String statusMessage) {
        mStatusMessage.setText(statusMessage);
    }

    public String getExceptionMessage() {
        return mExceptionMessage.getText().toString();
    }

    public void setExceptionMessage(String message) {
        mExceptionMessage.setVisibility(TextUtils.isEmpty(message) ? GONE : VISIBLE);
        mExceptionMessage.setText(message);
    }

    @Override
    public boolean performClick() {
        if (mOnRefreshListener != null) {
            mOnRefreshListener.onRefresh(this);
            showProgress();
        }

        return super.performClick();
    }

    public void showMessage(String message) {
        showMessage(message, null);
    }

    public void showMessage(String message, Throwable error) {
        setStatusMessage(message);
        setExceptionMessage(error == null ? null : error.getMessage());
        hideProgress();
        show();
    }

    public void showProgress() {
        mProgress.setVisibility(VISIBLE);
        mMessageArea.setVisibility(GONE);
        show();
    }

    private void hideProgress() {
        mProgress.setVisibility(GONE);
        mMessageArea.setVisibility(VISIBLE);
    }

    private void show() {
        setVisibility(VISIBLE);
    }

    public void hide() {
        setVisibility(View.GONE);
    }

    public OnRefreshListener getOnRefreshListener() {
        return mOnRefreshListener;
    }

    public void setOnRefreshListener(OnRefreshListener onRefreshListener) {
        mOnRefreshListener = onRefreshListener;
    }

    public static interface OnRefreshListener {
        public void onRefresh(StatusView statusView);
    }
}




Java Source Code List

id.go.jogjakota.perizinan.ApplicationTest.java
id.go.jogjakota.perizinan.BaseActivity.java
id.go.jogjakota.perizinan.BaseApp.java
id.go.jogjakota.perizinan.LoginActivity.java
id.go.jogjakota.perizinan.MainActivity.java
id.go.jogjakota.perizinan.PermitDetailActivity.java
id.go.jogjakota.perizinan.PermitFormActivity.java
id.go.jogjakota.perizinan.PermitListActivity.java
id.go.jogjakota.perizinan.PermitTypeListActivity.java
id.go.jogjakota.perizinan.RegisterActivity.java
id.go.jogjakota.perizinan.SplashActivity.java
id.go.jogjakota.perizinan.StatusView.java
id.go.jogjakota.perizinan.Tag.java
id.go.jogjakota.perizinan.Transition.java
id.go.jogjakota.perizinan.TwoLineViewHolder.java
id.go.jogjakota.perizinan.data.Dummies.java
id.go.jogjakota.perizinan.data.PermitDB.java
id.go.jogjakota.perizinan.data.PermitTypes.java
id.go.jogjakota.perizinan.data.Session.java
id.go.jogjakota.perizinan.data.UserDB.java
id.go.jogjakota.perizinan.domain.PermitType.java
id.go.jogjakota.perizinan.domain.Permit.java
id.go.jogjakota.perizinan.domain.User.java