Android Open Source - Icinga-Mobile Host Details Fragment






From Project

Back to project page Icinga-Mobile.

License

The source code is released under:

GNU General Public License

If you think the Android project Icinga-Mobile 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 mhst.dreamteam.UI;
/*from w  w w .  ja v a  2 s .  c o  m*/
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.Map;

import mhst.dreamteam.IcingaClient.Icinga.IcingaApi;
import mhst.dreamteam.IcingaClient.Icinga.IcingaApiConst;
import mhst.dreamteam.IcingaClient.Icinga.IcingaConst;
import mhst.dreamteam.IcingaClient.Icinga.IcingaUdt;
import mhst.dreamteam.IcingaClient.Interface.OnCompleteListener;
import mhst.dreamteam.IcingaClient.SessionMng.Session;
import mhst.dreamteam.R;

/**
 * Created by ltmp on 9/27/2014.
 */
public class HostDetailsFragment extends Fragment implements OnCompleteListener{
    private Context mContext;
    private Session currentSs;
    private ProgressDialog mProgress;
    private int numberOfProgress;

    private ArrayList<Map<String, Object>> mService;
    private ServicelistAdapter mListServiceAdapter;
    private String mRequest;
    private AlertDialog mDialog;

    private TextView tvTenHost;
    private TextView tvNextCheck;
    private TextView tvStatus ;
    private TextView tvStatusInformation ;
    private TextView tvPerformData ;
    private TextView tvCurrentAttempt ;
    private TextView tvLatency ;
    private TextView tvNextActive ;
    private TextView tvLastState ;
    private TextView tvFlapping ;
    private TextView tvDownTime ;
    private TextView tvLastUpDate ;
    private Switch swActiveCheck;
    private Switch swPassiveCheck ;
    private Switch swNotification ;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_host_details, container, false);
        // doan khai bao cu
        mContext = inflater.getContext();
        currentSs = Session.getInstance();
        numberOfProgress = 0;
        mProgress = new ProgressDialog(mContext);
        mProgress.setCancelable(false);
        mProgress.setMessage(mContext.getResources().getString(R.string.message_loading_data) + "...");
//
//        mService = new ArrayList<Map<String, Object>>();
//        ListView listService = (ListView) view.findViewById(R.id.lvListService);
//        mListServiceAdapter = new ServicelistAdapter(inflater, mService);
//        listService.setAdapter(mListServiceAdapter);

        ((Activity) mContext).setTitle("Host Details");
        // doan khai bao cu
        tvTenHost = (TextView) view.findViewById(R.id.tvTenHost);
        tvNextCheck = (TextView) view.findViewById(R.id.tvNextCheck);
        //tvStatus = (TextView) view.findViewById(R.id.tvStatus);
        tvStatusInformation = (TextView) view.findViewById(R.id.tvStatusInformation);
        tvPerformData = (TextView) view.findViewById(R.id.tvPerformData);
        tvCurrentAttempt = (TextView) view.findViewById(R.id.tvCurrentAttempt);
        tvLatency = (TextView) view.findViewById(R.id.tvLatency);
        tvNextActive = (TextView) view.findViewById(R.id.tvNextActive);
        tvLastState = (TextView) view.findViewById(R.id.tvLastState);
        tvFlapping = (TextView) view.findViewById(R.id.tvFlapping);
        tvDownTime = (TextView) view.findViewById(R.id.tvDownTime);
        tvLastUpDate = (TextView) view.findViewById(R.id.tvLastUpDate);
        swActiveCheck= (Switch) view.findViewById(R.id.swActiveCheck);
        swPassiveCheck = (Switch) view.findViewById(R.id.swPassiveCheck);
        swNotification = (Switch) view.findViewById(R.id.swNotification);
        // khai bao xong
        // Get argument
        Bundle arg = getArguments();
        String request;
        if (arg != null) {
            if ((request = arg.getString("HostId", null)) != null) {
                mRequest = IcingaUdt.getTemplate(IcingaUdt.ICINGA_TEMPLATE_MAINACTIVITY_HOST, 0, -1, request);
            }
        }

        updateList();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
        updateList();
    }

    public void updateList() {
        if (!currentSs.isInProgress() && !mProgress.isShowing()) {
            currentSs.isInProgress(true);
            mProgress.show();
        }
        numberOfProgress = 1;
        IcingaApi.get(this, mRequest);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void onComplete(Object obj, String sender) {
        if (obj != null) {
            if (!((ArrayList<Map<String, Object>>) obj).isEmpty()) {
                Map<String, Object> result = ((ArrayList<Map<String, Object>>) obj).get(0);
                String stt, sStatus = "";
                int nColor = Color.WHITE;
//            tvStatus.setText(stt);
                tvTenHost.setText((String) result.get(IcingaConst.HOST_NAME));
                stt = (String) result.get(IcingaConst.HOST_CURRENT_STATE);
                switch (Integer.parseInt(stt)) {
                    case IcingaApiConst.HOST_STATE_OK:
                        nColor = Color.GREEN;
                        sStatus = "UP";
                        break;
                    case IcingaApiConst.HOST_STATE_UNREACHABLE:
                        nColor = Color.ORANGE;
                        sStatus = "UNREACHABLE";
                        break;
                    case IcingaApiConst.HOST_STATE_DOWN:
                        nColor = Color.RED_DARK;
                        sStatus = "DOWN";
                        break;
                }
                tvStatusInformation.setTextColor(nColor);
                tvStatusInformation.setText(sStatus);
                tvPerformData.setText((String) result.get(IcingaConst.HOST_PERFDATA));
                tvCurrentAttempt.setText((String) result.get(IcingaConst.HOST_CURRENT_CHECK_ATTEMPT));
                tvLatency.setText((String) result.get(IcingaConst.HOST_LATENCY));
                tvNextActive.setText((String) result.get(IcingaConst.HOST_NEXT_CHECK));
                tvLastState.setText((String) result.get(IcingaConst.HOST_LAST_STATE_CHANGE));
                tvFlapping.setText((String) result.get(IcingaConst.HOST_IS_FLAPPING));
                tvDownTime.setText((String) result.get(IcingaConst.HOST_SCHEDULED_DOWNTIME_DEPTH));
                tvLastUpDate.setText((String) result.get(IcingaConst.HOST_STATUS_UPDATE_TIME));
            }
        }
        if (mProgress != null && mProgress.isShowing() && --numberOfProgress == 0) {
            mProgress.dismiss();
            currentSs.isInProgress(false);
        }
    }
}




Java Source Code List

mhst.dreamteam.ApplicationContext.java
mhst.dreamteam.ApplicationTest.java
mhst.dreamteam.ApplicationTest.java
mhst.dreamteam.MainActivity.java
mhst.dreamteam.IcingaClient.GlobalConfig.java
mhst.dreamteam.IcingaClient.GlobalConst.java
mhst.dreamteam.IcingaClient.Controller.NetControllerTest.java
mhst.dreamteam.IcingaClient.Controller.NetController.java
mhst.dreamteam.IcingaClient.Icinga.IcingaApiConst.java
mhst.dreamteam.IcingaClient.Icinga.IcingaApi.java
mhst.dreamteam.IcingaClient.Icinga.IcingaConst.java
mhst.dreamteam.IcingaClient.Icinga.IcingaExecutor.java
mhst.dreamteam.IcingaClient.Icinga.IcingaParam.java
mhst.dreamteam.IcingaClient.Icinga.IcingaUdt.java
mhst.dreamteam.IcingaClient.Icinga.package-info.java
mhst.dreamteam.IcingaClient.Interface.OnCompleteListener.java
mhst.dreamteam.IcingaClient.Interface.OnPieChartClickListener.java
mhst.dreamteam.IcingaClient.Json.JsonHelperTest.java
mhst.dreamteam.IcingaClient.Json.JsonHelper.java
mhst.dreamteam.IcingaClient.Misc.CookieMng.java
mhst.dreamteam.IcingaClient.Misc.CookieTest.java
mhst.dreamteam.IcingaClient.SessionMng.LogInTest.java
mhst.dreamteam.IcingaClient.SessionMng.Login.java
mhst.dreamteam.IcingaClient.SessionMng.Logout.java
mhst.dreamteam.IcingaClient.SessionMng.Session.java
mhst.dreamteam.IcingaService.ApplicationContext.java
mhst.dreamteam.IcingaService.DataUpdater.java
mhst.dreamteam.IcingaService.MessageReveicer.java
mhst.dreamteam.IcingaService.NotiBuilder.java
mhst.dreamteam.IcingaService.SQLHelper.java
mhst.dreamteam.IcingaService.SessionProvider.java
mhst.dreamteam.UI.Color.java
mhst.dreamteam.UI.GradientLine.java
mhst.dreamteam.UI.HostDetailsFragment.java
mhst.dreamteam.UI.HostlistAdapter.java
mhst.dreamteam.UI.HostlistFragment.java
mhst.dreamteam.UI.LoginActivity.java
mhst.dreamteam.UI.OverviewFragment.java
mhst.dreamteam.UI.PieGraph.java
mhst.dreamteam.UI.ProgressDialog.java
mhst.dreamteam.UI.ServiceDetailsFragment.java
mhst.dreamteam.UI.ServicelistAdapter.java
mhst.dreamteam.UI.ServicelistFragment.java
org.json.CDL.java
org.json.CookieList.java
org.json.Cookie.java
org.json.HTTPTokener.java
org.json.HTTP.java
org.json.JSONArray.java
org.json.JSONException.java
org.json.JSONML.java
org.json.JSONObject.java
org.json.JSONString.java
org.json.JSONStringer.java
org.json.JSONTokener.java
org.json.JSONWriter.java
org.json.Kim.java
org.json.Property.java
org.json.XMLTokener.java
org.json.XML.java
org.json.zip.BitInputStream.java
org.json.zip.BitOutputStream.java
org.json.zip.BitReader.java
org.json.zip.BitWriter.java
org.json.zip.Huff.java
org.json.zip.JSONzip.java
org.json.zip.Keep.java
org.json.zip.None.java
org.json.zip.PostMortem.java
org.json.zip.Unzipper.java
org.json.zip.Zipper.java