Back to project page Icinga-Mobile.
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.
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); } } }