Android Open Source - Rhybudd View Zenoss Device List Activity






From Project

Back to project page Rhybudd.

License

The source code is released under:

GNU General Public License

If you think the Android project Rhybudd 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

/*
 * Copyright (C) 2013 - Gareth Llewellyn
 *//from w  ww  . j  a va 2s .com
 * This file is part of Rhybudd - http://blog.NetworksAreMadeOfString.co.uk/Rhybudd/
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>
 */
package net.networksaremadeofstring.rhybudd;

import android.app.ActionBar;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.bugsense.trace.BugSenseHandler;
import java.util.ArrayList;

import static android.nfc.NdefRecord.createMime;


public class ViewZenossDeviceListActivity extends FragmentActivity implements ViewZenossDeviceListFragment.Callbacks, NfcAdapter.CreateNdefMessageCallback
{
    private boolean mTwoPane;
    String selectedDevice = "";
    String selectedUID = "";
    final static int LAUNCHDETAILACTIVITY = 2;
    ActionBar ab;
    NfcAdapter mNfcAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        BugSenseHandler.initAndStartSession(ViewZenossDeviceListActivity.this, "44a76a8c");

        setContentView(R.layout.view_zenoss_device_list);


        try
        {
            // Check for available NFC Adapter
            mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

            if (null != mNfcAdapter)
            {
                // Register callback
                mNfcAdapter.setNdefPushMessageCallback(this, this);
            }
        }
        catch(Exception e)
        {
            BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "NFC", e);
        }

        ab = getActionBar();
        ab.setTitle("Rhybudd");
        ab.setSubtitle("Zenoss Infrastructure Details");
        ab.setDisplayHomeAsUpEnabled(true);

        if (findViewById(R.id.device_detail_container) != null)
        {
            mTwoPane = true;

            // In two-pane mode, list items should be given the
            // 'activated' state when touched.
            ((ViewZenossDeviceListFragment) getSupportFragmentManager().findFragmentById(R.id.device_list)).setActivateOnItemClick(true);

            if(savedInstanceState == null)
            {
                DeviceListWelcomeFragment fragment = new DeviceListWelcomeFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.device_detail_container, fragment).commit();
            }
        }
     }


    @Override
    public NdefMessage createNdefMessage(NfcEvent nfcEvent)
    {
        try
        {
            String UID = selectedUID.replace("/zport/dmd/Devices/","");

            //UID = DeviceIDs.get(mViewPager.getCurrentItem());

            NdefMessage msg = new NdefMessage(
                    new NdefRecord[] { createMime(
                            "application/vnd.net.networksaremadeofstring.rhybudd.devicepage", UID.getBytes())
                            //,NdefRecord.createApplicationRecord("com.example.android.beam")
                    });
            return msg;
        }
        catch (Exception e)
        {
            e.printStackTrace();
            BugSenseHandler.sendExceptionMessage("ViewZenossDeviceActivity","processIntent",e);
            return null;
        }
    }

    /*@Override
    public void onItemSelected(ZenossDevice ZenossDevice)*/
    @Override
    public void onItemSelected(ZenossDevice device, ArrayList<String> DeviceNames, ArrayList<String> DeviceIDs)
    {
        selectedUID = device.getuid();
        selectedDevice = device.getname();
        //Log.e("selectedUID", selectedUID);
        if (mTwoPane)
        {
            // In two-pane mode, show the detail view in this activity by
            // adding or replacing the detail fragment using a
            // fragment transaction.
            Bundle arguments = new Bundle();
            arguments.putString(ViewZenossDeviceFragment.ARG_HOSTNAME, selectedDevice);
            arguments.putString(ViewZenossDeviceFragment.ARG_UID, selectedUID);
            arguments.putBoolean(ViewZenossDeviceFragment.ARG_2PANE, true);
            arguments.putStringArrayList(ViewZenossDeviceFragment.ARG_DEVICENAMES,DeviceNames);
            arguments.putStringArrayList(ViewZenossDeviceFragment.ARG_DEVICEIDS,DeviceIDs);


            ViewZenossDeviceFragment fragment = new ViewZenossDeviceFragment();
            fragment.setArguments(arguments);
            getSupportFragmentManager().beginTransaction().replace(R.id.device_detail_container, fragment).commit();
            ab.setSubtitle("Viewing " + selectedDevice);

        }
        else
        {
            // In single-pane mode, simply start the detail activity
            // for the selected item ID.
            Intent detailIntent = new Intent(this, ViewZenossDeviceActivity.class);
            detailIntent.putExtra(ViewZenossDeviceFragment.ARG_HOSTNAME, selectedDevice);
            detailIntent.putExtra(ViewZenossDeviceFragment.ARG_UID, selectedUID);
            detailIntent.putExtra(ViewZenossDeviceFragment.ARG_2PANE, false);
            detailIntent.putStringArrayListExtra(ViewZenossDeviceFragment.ARG_DEVICENAMES,DeviceNames);
            detailIntent.putStringArrayListExtra(ViewZenossDeviceFragment.ARG_DEVICEIDS,DeviceIDs);
            startActivityForResult(detailIntent,LAUNCHDETAILACTIVITY);
        }
    }

    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.devices, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
            case android.R.id.home:
            {
                finish();
                return true;
            }

            case R.id.search:
            {
                onSearchRequested();
                return true;
            }

            case R.id.adddevice:
            {
                try
                {
                    if (mTwoPane)
                    {
                        AddDeviceFragment fragment = new AddDeviceFragment();
                        getSupportFragmentManager().beginTransaction().replace(R.id.device_detail_container, fragment).commit();
                        ab.setSubtitle(getString(R.string.AddDeviceTitle));
                    }
                    else
                    {
                        Intent AddDeviceIntent = new Intent(ViewZenossDeviceListActivity.this, AddDeviceActivity.class);
                        //Not strictly required because we can get the activity to do it for us
                        AddDeviceIntent.putExtra(AddDeviceFragment.TWOPANEINDICATOR,false);
                        this.startActivity(AddDeviceIntent);
                    }
                    return true;
                }
                catch (Exception e)
                {
                    BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListActivity","adddevice",e);
                    return false;
                }
            }

            case R.id.refresh:
            {
                try
                {
                    ViewZenossDeviceListFragment fragment = (ViewZenossDeviceListFragment) getSupportFragmentManager().findFragmentById(R.id.device_list);
                    fragment.Refresh();
                    return true;
                }
                catch (Exception e)
                {
                    BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListActivity","refresh",e);
                    return false;
                }
            }

        }
        return false;
    }
}




Java Source Code List

net.networksaremadeofstring.rhybudd.AddDeviceActivity.java
net.networksaremadeofstring.rhybudd.AddDeviceFragment.java
net.networksaremadeofstring.rhybudd.AuthenticatorService.java
net.networksaremadeofstring.rhybudd.Authenticator.java
net.networksaremadeofstring.rhybudd.CoreSettingsFragment.java
net.networksaremadeofstring.rhybudd.DeviceListWelcomeFragment.java
net.networksaremadeofstring.rhybudd.DeviceList.java
net.networksaremadeofstring.rhybudd.DiagnosticActivity.java
net.networksaremadeofstring.rhybudd.EventsListWelcomeFragment.java
net.networksaremadeofstring.rhybudd.FirstRunSettings.java
net.networksaremadeofstring.rhybudd.GCMIntentService.java
net.networksaremadeofstring.rhybudd.ManageDatabase.java
net.networksaremadeofstring.rhybudd.ManageUpdate.java
net.networksaremadeofstring.rhybudd.MassAcknowledgeReceiver.java
net.networksaremadeofstring.rhybudd.Notifications.java
net.networksaremadeofstring.rhybudd.PushConfigActivity.java
net.networksaremadeofstring.rhybudd.PushSettingsFragment.java
net.networksaremadeofstring.rhybudd.RhybuddBackupAgent.java
net.networksaremadeofstring.rhybudd.RhybuddDataSource.java
net.networksaremadeofstring.rhybudd.RhybuddDock.java
net.networksaremadeofstring.rhybudd.RhybuddDream.java
net.networksaremadeofstring.rhybudd.RhybuddHandlers.java
net.networksaremadeofstring.rhybudd.RhybuddHome.java
net.networksaremadeofstring.rhybudd.RhybuddOpenHelper.java
net.networksaremadeofstring.rhybudd.Search.java
net.networksaremadeofstring.rhybudd.SettingsFragment.java
net.networksaremadeofstring.rhybudd.StubProvider.java
net.networksaremadeofstring.rhybudd.SwipeDismissListViewTouchListener.java
net.networksaremadeofstring.rhybudd.SwipeDismissTouchListener.java
net.networksaremadeofstring.rhybudd.SyncAdapter.java
net.networksaremadeofstring.rhybudd.SyncService.java
net.networksaremadeofstring.rhybudd.TrustAllManager.java
net.networksaremadeofstring.rhybudd.TrustAllSSLSocketFactory.java
net.networksaremadeofstring.rhybudd.URLDrawable.java
net.networksaremadeofstring.rhybudd.URLImageParser.java
net.networksaremadeofstring.rhybudd.ViewEventFragment.java
net.networksaremadeofstring.rhybudd.ViewZenossDeviceActivity.java
net.networksaremadeofstring.rhybudd.ViewZenossDeviceFragment.java
net.networksaremadeofstring.rhybudd.ViewZenossDeviceListActivity.java
net.networksaremadeofstring.rhybudd.ViewZenossDeviceListFragment.java
net.networksaremadeofstring.rhybudd.ViewZenossDevice.java
net.networksaremadeofstring.rhybudd.ViewZenossEventActivity.java
net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java
net.networksaremadeofstring.rhybudd.ViewZenossEvent.java
net.networksaremadeofstring.rhybudd.ViewZenossEventsListActivity.java
net.networksaremadeofstring.rhybudd.ViewZenossEventsListFragment.java
net.networksaremadeofstring.rhybudd.ViewZenossGroupsActivity.java
net.networksaremadeofstring.rhybudd.ViewZenossGroupsFragment.java
net.networksaremadeofstring.rhybudd.WriteNFCActivity.java
net.networksaremadeofstring.rhybudd.ZaasSettingsFragment.java
net.networksaremadeofstring.rhybudd.ZenPack.java
net.networksaremadeofstring.rhybudd.ZenossAPICore.java
net.networksaremadeofstring.rhybudd.ZenossAPIZaas.java
net.networksaremadeofstring.rhybudd.ZenossAPI.java
net.networksaremadeofstring.rhybudd.ZenossAPIv2.java
net.networksaremadeofstring.rhybudd.ZenossCredentials.java
net.networksaremadeofstring.rhybudd.ZenossDeviceAdaptor.java
net.networksaremadeofstring.rhybudd.ZenossDevice.java
net.networksaremadeofstring.rhybudd.ZenossEvent.java
net.networksaremadeofstring.rhybudd.ZenossEventsAdaptor.java
net.networksaremadeofstring.rhybudd.ZenossGCMBroadcastReceiver.java
net.networksaremadeofstring.rhybudd.ZenossGroupsGridAdapter.java
net.networksaremadeofstring.rhybudd.ZenossPoller.java
net.networksaremadeofstring.rhybudd.ZenossSearchAdaptor.java
net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
net.networksaremadeofstring.rhybudd.ZenossWidget.java