If you think the Android project JBoss-Admin-Android 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
/*
* JBoss Admin/*www.java2s.com*/
* Copyright 2013, Christos Vasilakis, and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package org.cvasilak.jboss.mobile.app.fragments;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.cvasilak.jboss.mobile.app.JBossAdminApplication;
import org.cvasilak.jboss.mobile.app.R;
import org.cvasilak.jboss.mobile.app.fragments.dialogs.ErrorDialogFragment;
import org.cvasilak.jboss.mobile.app.fragments.dialogs.ProgressDialogFragment;
import org.cvasilak.jboss.mobile.app.model.Metric;
import org.cvasilak.jboss.mobile.app.net.Callback;
import org.cvasilak.jboss.mobile.app.util.listview.adapters.MetricsAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
publicclass PropertiesViewFragment extends ListFragment {
privatestaticfinal String TAG = PropertiesViewFragment.class.getSimpleName();
private JBossAdminApplication application;
private List<Metric> properties;
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
application = (JBossAdminApplication) getActivity().getApplication();
properties = new ArrayList<Metric>();
setHasOptionsMenu(true);
refresh();
}
@Override
publicvoid onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ActionBar bar = ((ActionBarActivity) getActivity()).getSupportActionBar();
bar.setTitle(getString(R.string.properties));
setListAdapter(new MetricsAdapter(getActivity(), properties));
}
@Override
publicvoid onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_refresh, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.refresh) {
refresh();
return (true);
}
return (super.onOptionsItemSelected(item));
}
publicvoid refresh() {
ProgressDialogFragment.showDialog(getActivity(), R.string.queryingServer);
application.getOperationsManager().fetchPropertiesInformation(new Callback() {
@Override
publicvoid onSuccess(JsonElement reply) {
ProgressDialogFragment.dismissDialog(getActivity());
properties.clear();
JsonObject jsonObj = reply.getAsJsonObject();
for (Map.Entry<String, JsonElement> entry : jsonObj.entrySet()) {
Metric metric = new Metric();
metric.setName(entry.getKey());
metric.setValue(entry.getValue().toString());
properties.add(metric);
}
((ArrayAdapter) getListAdapter()).notifyDataSetChanged();
}
@Override
publicvoid onFailure(Exception e) {
ProgressDialogFragment.dismissDialog(getActivity());
ErrorDialogFragment.showDialog(getActivity(), e.getMessage());
}
});
}
}