Skip to content

Commit

Permalink
feat(design): add service and options
Browse files Browse the repository at this point in the history
implement inventory preference and global parameters preference

Signed-off-by: Rafa Hernandez <[email protected]>
  • Loading branch information
rafaelje authored and ajsb85 committed Mar 26, 2018
1 parent 28dd850 commit 550a892
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion app/src/main/java/org/flyve/inventory/agent/FragmentHome.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.flyve.inventory.agent;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -47,15 +51,55 @@
public class FragmentHome extends Fragment {

private ArrayList<HomeSchema> arrHome;
private Intent mServiceIntent;

private void doBindService() {
// Establish a connection with the service. We use an explicit
// class name because we want a specific service implementation that
// we know will be running in our own process (and thus won't be
// supporting component replacement by other applications).
InventoryService inventoryService = new InventoryService();
mServiceIntent = new Intent(FragmentHome.this.getContext(), inventoryService.getClass());

if (!isMyServiceRunning(inventoryService.getClass())) {
ComponentName result = FragmentHome.this.getActivity().startService(mServiceIntent);

if (result != null) {
FlyveLog.log(this, " Agent started ", Log.INFO);
} else {
FlyveLog.log(this, " Agent fail", Log.ERROR);
}
} else {
FlyveLog.log(this, " Agent already started ", Log.ERROR);
}
}

/**
* Check if the service is running
* @param serviceClass Class
* @return boolean
*/
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) FragmentHome.this.getActivity().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.fragment_home, null);

doBindService();

arrHome = new ArrayList<>();

arrHome.add(new HomeSchema("1", getString(R.string.AccueilInventoryTitle)));
arrHome.add(new HomeSchema("2", getString(R.string.AccueilInventoryTitle), getString(R.string.AccueilInventorySummaryOn), false));
arrHome.add(new HomeSchema("3", getString(R.string.AccueilInventoryRun), getString(R.string.AccueilInventoryRunSummary)));
arrHome.add(new HomeSchema("4", getString(R.string.AccueilInventoryShow), getString(R.string.AccueilInventoryShowSummary)));
arrHome.add(new HomeSchema("5", getString(R.string.AccueilInventoryParam), getString(R.string.AccueilInventoryParamSummary)));
Expand All @@ -68,6 +112,16 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
HomeSchema homeSchema = arrHome.get(i);

if(homeSchema.getId().equals("7")) {
Intent miIntent = new Intent(FragmentHome.this.getContext(), GlobalParametersPreference.class);
FragmentHome.this.startActivity(miIntent);
}

if(homeSchema.getId().equals("5")) {
Intent miIntent = new Intent(FragmentHome.this.getContext(), InventoryParametersPreference.class);
FragmentHome.this.startActivity(miIntent);
}

// Show my inventory
if(homeSchema.getId().equals("4")) {
Intent miIntent = new Intent(FragmentHome.this.getContext(), InventoryActivity.class);
Expand Down

0 comments on commit 550a892

Please sign in to comment.