Android Open Source - SenqmAndroid Main Activity






From Project

Back to project page SenqmAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project SenqmAndroid 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  2014 Alban GRUIN/* www .j a  va  2s.  c  om*/
 *
 *      This file is part of SenqmAndroid.
 *
 *      SenqmAndroid 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.
 *
 *      SenqmAndroid 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 SenqmAndroid.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.agrn.senqm;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import com.agrn.senqm.database.DatabaseHelper;
import com.agrn.senqm.database.entities.Computer;
import com.agrn.senqm.network.service.ConnectionManagerService;
import com.agrn.senqm.network.service.ConnectionManagerServiceBoundListener;
import com.agrn.senqm.network.service.ConnectionManagerServiceConnection;

import java.util.ArrayList;
import java.util.HashMap;

public class MainActivity extends Activity implements ConnectionManagerServiceBoundListener
{
    private ConnectionManagerService connectionManagerService;
    private ConnectionManagerServiceConnection serviceConnection;

    private ListView listView;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        listView = (ListView) findViewById(R.id.computerListView);
        setupAdapter();

        serviceConnection = new ConnectionManagerServiceConnection(this);
    }

    @Override
    public void onStart()
    {
        super.onStart();

        Intent intent = new Intent(this, ConnectionManagerService.class);
        if(!ConnectionManagerService.isRunning())
            startService(intent);

        bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
    }

    @Override
    public void onStop()
    {
        super.onStop();

        if (connectionManagerService == null)
            return;

        int connectionCount = connectionManagerService.connectionCount();
        unbindService(serviceConnection);

        if(connectionCount == 0)
        {
            Intent intent = new Intent(this, ConnectionManagerService.class);
            stopService(intent);
        }
    }

    @Override
    public void onServiceBound(ConnectionManagerService service)
    {
        connectionManagerService = service;
    }

    private ArrayList<HashMap<String, String>> getComputerInfoList(ArrayList<Computer> computerList)
    {
        ArrayList<HashMap<String, String>> computerInfoList = new ArrayList<>();

        for(Computer computer: computerList)
        {
            HashMap<String, String> element = new HashMap<>();
            element.put("text1", computer.getComputerName());
            element.put("text2", computer.getAddress());

            computerInfoList.add(element);
        }

        return computerInfoList;
    }

    private void setupAdapter()
    {
        DatabaseHelper database = DatabaseHelper.getInstance(this);
        ArrayList<HashMap<String, String>> computerInfoList = getComputerInfoList(database.getComputerList());

        ListAdapter listAdapter = new SimpleAdapter(this, computerInfoList, android.R.layout.simple_list_item_2,
                new String[] { "text1", "text2" }, new int[] { android.R.id.text1, android.R.id.text2 });
        listView.setAdapter(listAdapter);
    }
}




Java Source Code List

com.agrn.senqm.MainActivity.java
com.agrn.senqm.database.DatabaseHelper.java
com.agrn.senqm.database.entities.Computer.java
com.agrn.senqm.network.Message.java
com.agrn.senqm.network.WifiLockContainer.java
com.agrn.senqm.network.connection.ConnectionHandler.java
com.agrn.senqm.network.connection.Connection.java
com.agrn.senqm.network.service.ConnectionManagerServiceBoundListener.java
com.agrn.senqm.network.service.ConnectionManagerServiceConnection.java
com.agrn.senqm.network.service.ConnectionManagerService.java
com.agrn.senqm.telephony.PhoneBroadcaster.java
com.agrn.senqm.telephony.sms.SMSBroadcaster.java
com.agrn.senqm.telephony.sms.SendSMS.java