|
@@ -7,23 +7,28 @@ import java.util.List;
|
|
|
import android.app.ActionBar;
|
|
|
import android.app.Activity;
|
|
|
import android.app.ActivityManager;
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.app.Fragment;
|
|
|
import android.app.FragmentManager;
|
|
|
import android.app.FragmentTransaction;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
|
+import android.content.SharedPreferences;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.content.res.Configuration;
|
|
|
import android.content.res.TypedArray;
|
|
|
+import android.net.Uri;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
|
import android.support.v4.app.ActionBarDrawerToggle;
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
+import android.text.Html;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.KeyEvent;
|
|
@@ -52,6 +57,8 @@ import de.tudarmstadt.informatik.hostage.ui2.fragment.opengl.ThreatIndicatorGLRe
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.model.DrawerListItem;
|
|
|
|
|
|
/**
|
|
|
+ * Manages the whole application, and should act like an singleton.
|
|
|
+ *
|
|
|
* @author Alexander Brakowski
|
|
|
* @created 12.01.14 23:24
|
|
|
*/
|
|
@@ -61,40 +68,61 @@ public class MainActivity extends Activity {
|
|
|
/** singleton instance of the MainActivity **/
|
|
|
private static MainActivity sInstance = null;
|
|
|
|
|
|
+ /**
|
|
|
+ * The currently displayed fragment
|
|
|
+ */
|
|
|
public Fragment mDisplayedFragment;
|
|
|
|
|
|
+ /**
|
|
|
+ * Holds the Hostage Service
|
|
|
+ */
|
|
|
public Hostage mHoneyService;
|
|
|
|
|
|
+ /**
|
|
|
+ * Manages the navigation drawer
|
|
|
+ */
|
|
|
private DrawerLayout mDrawerLayout;
|
|
|
|
|
|
+ /**
|
|
|
+ * Contains the listview to be displayed in the navigation drawer
|
|
|
+ */
|
|
|
private ListView mDrawerList;
|
|
|
|
|
|
+ /**
|
|
|
+ * Holds the toggler for the navigation drawer in the action bar
|
|
|
+ */
|
|
|
private ActionBarDrawerToggle mDrawerToggle;
|
|
|
|
|
|
+ /**
|
|
|
+ * The text that should be displayed in the drawer toggle
|
|
|
+ */
|
|
|
private CharSequence mDrawerTitle;
|
|
|
|
|
|
+ /**
|
|
|
+ * The text that should be displayed in the action bar
|
|
|
+ */
|
|
|
private CharSequence mTitle;
|
|
|
|
|
|
- private MainMenuItem mSelectedMenuItem = null;
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Holds the list, that should be displayed in the listview of the navigation drawer
|
|
|
+ */
|
|
|
private ArrayList<DrawerListItem> mDrawerItems;
|
|
|
|
|
|
+ /**
|
|
|
+ * Hold the state of the Hostage service
|
|
|
+ */
|
|
|
private boolean mServiceBound = false;
|
|
|
|
|
|
- private ProfileManager mProfileManager;
|
|
|
-
|
|
|
- private Fragment rootFragment;
|
|
|
-
|
|
|
/**
|
|
|
* Connection to bind the background service
|
|
|
- *
|
|
|
+ *
|
|
|
* @see de.tudarmstadt.informatik.hostage.Hostage
|
|
|
*/
|
|
|
private ServiceConnection mConnection = new ServiceConnection() {
|
|
|
/**
|
|
|
* After the service is bound, check which has been clicked and start
|
|
|
* it.
|
|
|
- *
|
|
|
+ *
|
|
|
* @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName,
|
|
|
* android.os.IBinder)
|
|
|
*/
|
|
@@ -106,7 +134,7 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
/**
|
|
|
* After the service is unbound, delete reference.
|
|
|
- *
|
|
|
+ *
|
|
|
* @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
|
|
|
*/
|
|
|
@Override
|
|
@@ -117,66 +145,103 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
};
|
|
|
|
|
|
- private HashMap<String, Boolean> mAttacksOnProtocol = new HashMap<String, Boolean>();
|
|
|
+ /**
|
|
|
+ * Holds an profile manager instance
|
|
|
+ */
|
|
|
+ private ProfileManager mProfileManager;
|
|
|
|
|
|
+ /**
|
|
|
+ * Holds the root fragment for our hierarchical fragment navigation
|
|
|
+ */
|
|
|
+ private Fragment rootFragment;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Indicates if the warning, that the application will be closed, when pressing back again
|
|
|
+ */
|
|
|
private boolean mCloseWarning = false;
|
|
|
|
|
|
+ /**
|
|
|
+ * Hold the shared preferences for the app
|
|
|
+ */
|
|
|
+ private SharedPreferences mSharedPreferences;
|
|
|
+
|
|
|
/**
|
|
|
* Retrieve the singleton latest instance of the activity
|
|
|
- *
|
|
|
+ *
|
|
|
* @return MainActivity - the singleton instance
|
|
|
*/
|
|
|
public static MainActivity getInstance() {
|
|
|
- assert (sInstance != null);
|
|
|
return sInstance;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Retrieves the context of the application
|
|
|
+ *
|
|
|
+ * @return the context
|
|
|
+ */
|
|
|
public static Context getContext() {
|
|
|
return MainActivity.context;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public void onStart() {
|
|
|
super.onStart();
|
|
|
|
|
|
- registerReceiver();
|
|
|
-
|
|
|
if (isServiceRunning()) {
|
|
|
this.bindService();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public void onStop() {
|
|
|
this.unbindService();
|
|
|
super.onStop();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
+ // make the main activity an singleton
|
|
|
sInstance = this;
|
|
|
+
|
|
|
+ // sets the static context reference to the application context
|
|
|
MainActivity.context = getApplicationContext();
|
|
|
|
|
|
setContentView(R.layout.activity_drawer_main);
|
|
|
-
|
|
|
mProfileManager = ProfileManager.getInstance();
|
|
|
|
|
|
+ // init threat indicator animation
|
|
|
ThreatIndicatorGLRenderer.assets = getAssets();
|
|
|
ThreatIndicatorGLRenderer.setThreatLevel(ThreatIndicatorGLRenderer.ThreatLevel.NOT_MONITORING);
|
|
|
+
|
|
|
// set background color
|
|
|
TypedArray arr = getTheme().obtainStyledAttributes(new int[] { android.R.color.background_light });
|
|
|
ThreatIndicatorGLRenderer.setBackgroundColor(arr.getColor(0, 0xFFFFFF));
|
|
|
arr.recycle();
|
|
|
|
|
|
+ // configures the action bar
|
|
|
ActionBar actionBar = getActionBar();
|
|
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
|
|
|
+ actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
+ actionBar.setHomeButtonEnabled(true);
|
|
|
+ actionBar.setDisplayShowHomeEnabled(true);
|
|
|
|
|
|
+ // sets the drawer and action title to the application title
|
|
|
mTitle = mDrawerTitle = getTitle();
|
|
|
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
|
|
mDrawerList = (ListView) findViewById(R.id.left_drawer);
|
|
|
|
|
|
+ // propagates the navigation drawer with items
|
|
|
mDrawerItems = new ArrayList<DrawerListItem>();
|
|
|
mDrawerItems.add(new DrawerListItem(R.string.drawer_overview, R.drawable.ic_menu_home));
|
|
|
mDrawerItems.add(new DrawerListItem(R.string.drawer_threat_map, R.drawable.ic_menu_mapmode));
|
|
@@ -185,6 +250,7 @@ public class MainActivity extends Activity {
|
|
|
mDrawerItems.add(new DrawerListItem(R.string.drawer_services, R.drawable.ic_menu_set_as));
|
|
|
mDrawerItems.add(new DrawerListItem(R.string.drawer_profile_manager, R.drawable.ic_menu_allfriends));
|
|
|
mDrawerItems.add(new DrawerListItem(R.string.drawer_settings, R.drawable.ic_menu_preferences));
|
|
|
+ mDrawerItems.add(new DrawerListItem(R.string.drawer_help, R.drawable.ic_menu_help));
|
|
|
mDrawerItems.add(new DrawerListItem(R.string.drawer_app_info, R.drawable.ic_menu_info_details));
|
|
|
|
|
|
DrawerListAdapter listAdapter = new DrawerListAdapter(this, mDrawerItems);
|
|
@@ -192,18 +258,15 @@ public class MainActivity extends Activity {
|
|
|
mDrawerList.setAdapter(listAdapter);
|
|
|
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
|
|
|
|
|
|
- getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
- getActionBar().setHomeButtonEnabled(true);
|
|
|
- getActionBar().setDisplayShowHomeEnabled(true);
|
|
|
-
|
|
|
+ // configures the navigation drawer
|
|
|
mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
|
|
|
- mDrawerLayout, /* DrawerLayout object */
|
|
|
- R.drawable.ic_navigation_drawer, /*
|
|
|
- * nav drawer image to replace 'Up'
|
|
|
- * caret
|
|
|
- */
|
|
|
- R.string.drawer_open, /* "open drawer" description for accessibility */
|
|
|
- R.string.drawer_close /* "close drawer" description for accessibility */
|
|
|
+ mDrawerLayout, /* DrawerLayout object */
|
|
|
+ R.drawable.ic_navigation_drawer, /*
|
|
|
+ * nav drawer image to replace 'Up'
|
|
|
+ * caret
|
|
|
+ */
|
|
|
+ R.string.drawer_open, /* "open drawer" description for accessibility */
|
|
|
+ R.string.drawer_close /* "close drawer" description for accessibility */
|
|
|
) {
|
|
|
public void onDrawerClosed(View view) {
|
|
|
getActionBar().setTitle(mTitle);
|
|
@@ -217,45 +280,66 @@ public class MainActivity extends Activity {
|
|
|
// onPrepareOptionsMenu()
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
mDrawerLayout.setDrawerListener(mDrawerToggle);
|
|
|
|
|
|
+ // start the hostage service
|
|
|
startAndBind();
|
|
|
|
|
|
- if (savedInstanceState == null) {
|
|
|
- // on first time display view for first nav item
|
|
|
- displayView(0);
|
|
|
- }
|
|
|
- }
|
|
|
+ mSharedPreferences = getSharedPreferences(getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE);
|
|
|
|
|
|
- private void registerReceiver() {
|
|
|
- LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter(getString(R.string.broadcast)));
|
|
|
- }
|
|
|
+ if(mSharedPreferences.getBoolean("isFirstRun", true)){
|
|
|
|
|
|
- private void unregisterReceiver() {
|
|
|
- LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
|
|
- }
|
|
|
+ // opens navigation drawer if first run
|
|
|
+ mDrawerLayout.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mDrawerLayout.openDrawer(Gravity.LEFT);
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
|
|
|
- private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
- @Override
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
- Bundle extras = intent.getExtras();
|
|
|
+ onFirstRun();
|
|
|
+ }
|
|
|
|
|
|
- String sender = extras.getString("SENDER");
|
|
|
- String[] values = extras.getStringArray("VALUES");
|
|
|
|
|
|
- if (sender.equals(Hostage.class.getName()) && values[0].equals(getString(R.string.broadcast_started))) {
|
|
|
- mAttacksOnProtocol.put(values[1], true);
|
|
|
- }
|
|
|
+ if (savedInstanceState == null) {
|
|
|
+ // on first time display view for first nav item
|
|
|
+ displayView(0);
|
|
|
}
|
|
|
- };
|
|
|
-
|
|
|
- public boolean hasProtocolAttacks(String protocol) {
|
|
|
- if (!mAttacksOnProtocol.containsKey(protocol))
|
|
|
- return false;
|
|
|
+ }
|
|
|
|
|
|
- return mAttacksOnProtocol.get(protocol);
|
|
|
+ /**
|
|
|
+ * Displays the disclaimer on first run of the application
|
|
|
+ */
|
|
|
+ private void onFirstRun(){
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
+ builder.setMessage(Html.fromHtml(getString(R.string.hostage_disclaimer)))
|
|
|
+ .setCancelable(false)
|
|
|
+ .setPositiveButton(getString(R.string.agree), new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
+ // and, if the user accept, you can execute something like this:
|
|
|
+ // We need an Editor object to make preference changes.
|
|
|
+ // All objects are from android.context.Context
|
|
|
+ SharedPreferences.Editor editor = mSharedPreferences.edit();
|
|
|
+ editor.putBoolean("isFirstRun", false);
|
|
|
+ // Commit the edits!
|
|
|
+ editor.commit();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setNegativeButton(getString(R.string.disagree), new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog, int id) {
|
|
|
+ getHostageService().stopListeners();
|
|
|
+ stopAndUnbind();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ AlertDialog alert = builder.create();
|
|
|
+ alert.show();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Starts the hostage service and binds this activity to the service
|
|
|
+ */
|
|
|
public void startAndBind() {
|
|
|
if (!isServiceRunning()) {
|
|
|
startService(getServiceIntent());
|
|
@@ -264,6 +348,9 @@ public class MainActivity extends Activity {
|
|
|
bindService();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Stops the hostage service and unbinds from the service
|
|
|
+ */
|
|
|
public void stopAndUnbind() {
|
|
|
if (mHoneyService != null) {
|
|
|
unbindService();
|
|
@@ -272,6 +359,9 @@ public class MainActivity extends Activity {
|
|
|
stopService(getServiceIntent());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Unbindes the activity from the service
|
|
|
+ */
|
|
|
public void unbindService() {
|
|
|
try {
|
|
|
unbindService(mConnection);
|
|
@@ -280,17 +370,20 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Binds the activity to the service
|
|
|
+ */
|
|
|
public void bindService() {
|
|
|
- mAttacksOnProtocol.clear();
|
|
|
bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
|
|
|
// mServiceBound = true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
- // Unregister Broadcast Receiver
|
|
|
- unregisterReceiver();
|
|
|
|
|
|
// Unbind running service
|
|
|
if (!mHoneyService.hasRunningListeners()) {
|
|
@@ -298,22 +391,9 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- super.onResume();
|
|
|
-
|
|
|
- String action = getIntent().getAction();
|
|
|
-
|
|
|
- if (action != null && action.equals("SHOW_HOME")) {
|
|
|
- /*if (this.mDisplayedFragment != null && !this.mDisplayedFragment.getClass().equals(HomeFragment.class)) {
|
|
|
- getFragmentManager().popBackStackImmediate(HomeFragment.class.getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
|
- displayView(MainMenuItem.HOME.getValue());
|
|
|
-
|
|
|
- getIntent().setAction(null);
|
|
|
- }*/
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
// toggle nav drawer on selecting action bar app icon/title
|
|
@@ -330,6 +410,9 @@ public class MainActivity extends Activity {
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Navigates up to the parent fragment of the current fragment
|
|
|
+ */
|
|
|
public void navigateBack(){
|
|
|
if (!(this.mDisplayedFragment instanceof UpNavigatibleFragment)) {
|
|
|
mDrawerToggle.setDrawerIndicatorEnabled(true);
|
|
@@ -349,6 +432,9 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public void setTitle(CharSequence title) {
|
|
|
mTitle = title;
|
|
@@ -359,7 +445,6 @@ public class MainActivity extends Activity {
|
|
|
* When using the ActionBarDrawerToggle, you must call it during
|
|
|
* onPostCreate() and onConfigurationChanged()...
|
|
|
*/
|
|
|
-
|
|
|
@Override
|
|
|
protected void onPostCreate(Bundle savedInstanceState) {
|
|
|
super.onPostCreate(savedInstanceState);
|
|
@@ -367,6 +452,9 @@ public class MainActivity extends Activity {
|
|
|
mDrawerToggle.syncState();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
super.onConfigurationChanged(newConfig);
|
|
@@ -374,22 +462,29 @@ public class MainActivity extends Activity {
|
|
|
mDrawerToggle.onConfigurationChanged(newConfig);
|
|
|
}
|
|
|
|
|
|
- public Fragment getCurrentFragment() {
|
|
|
- return this.mDisplayedFragment;
|
|
|
- }
|
|
|
-
|
|
|
- public void setDrawerIndicatorEnabled(boolean val) {
|
|
|
- mDrawerToggle.setDrawerIndicatorEnabled(val);
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Displays the view for the given navigation index
|
|
|
+ *
|
|
|
+ * @param position the index of the navigation item
|
|
|
+ */
|
|
|
public void displayView(int position) {
|
|
|
MainMenuItem menuItemPosition = MainMenuItem.create(position);
|
|
|
|
|
|
+ // close the drawer if the to be displayed fragment is already being displayed
|
|
|
if (this.mDisplayedFragment != null && this.mDisplayedFragment.getClass() == menuItemPosition.getKlass()) {
|
|
|
mDrawerLayout.closeDrawer(mDrawerList);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // open help video list when pressing help navigation item
|
|
|
+ if(menuItemPosition == MainMenuItem.HELP){
|
|
|
+ Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
+ intent.setData(Uri.parse("https://www.youtube.com/playlist?list=PLJyUmtMldh3s1XtRfE4YFaQ8ME7xjf7Gx"));
|
|
|
+ startActivity(intent);
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
Fragment fragment = null;
|
|
|
|
|
|
try {
|
|
@@ -405,15 +500,7 @@ public class MainActivity extends Activity {
|
|
|
rootFragment = fragment;
|
|
|
}
|
|
|
|
|
|
- boolean isFirst = getFragmentManager().getBackStackEntryCount() == 0;
|
|
|
-
|
|
|
- //getFragmentManager().popBackStackImmediate(HomeFragment.class.getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
|
|
- // update selected item and title, then close the drawer if needed
|
|
|
- //if(!(fragment instanceof HomeFragment) || isFirst) {
|
|
|
- injectFragment(fragment);// , false, menuItemPosition);
|
|
|
- //} else {
|
|
|
- // injectFragment(rootFragment);
|
|
|
- //}
|
|
|
+ injectFragment(fragment);
|
|
|
|
|
|
mDrawerList.setItemChecked(position, true);
|
|
|
mDrawerList.setSelection(position);
|
|
@@ -423,14 +510,15 @@ public class MainActivity extends Activity {
|
|
|
mDrawerLayout.closeDrawer(mDrawerList);
|
|
|
}
|
|
|
|
|
|
- public void injectFragment(Fragment fragment, boolean enableBack) {
|
|
|
- injectFragment(fragment);
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Injects an given fragment into the application content view
|
|
|
+ *
|
|
|
+ * @param fragment the fragment to inject
|
|
|
+ */
|
|
|
public void injectFragment(Fragment fragment) {
|
|
|
this.mCloseWarning = false;
|
|
|
|
|
|
- // set orientation fixed to portrait in home fragment
|
|
|
+ // set the action bar up navigation according to the nature of the given fragment
|
|
|
if (fragment instanceof UpNavigatibleFragment) {
|
|
|
UpNavigatibleFragment upFrag = (UpNavigatibleFragment) fragment;
|
|
|
if (upFrag.getUpFragment() == null) {
|
|
@@ -443,6 +531,7 @@ public class MainActivity extends Activity {
|
|
|
|
|
|
configureFragment(fragment);
|
|
|
|
|
|
+ // exchange the existing fragment with the given one
|
|
|
FragmentManager fragmentManager = getFragmentManager();
|
|
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
|
|
fragmentTransaction.replace(R.id.content_frame, fragment, fragment.getClass().getName());
|
|
@@ -454,10 +543,16 @@ public class MainActivity extends Activity {
|
|
|
this.mDisplayedFragment = fragment;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void configureFragment() {
|
|
|
configureFragment(this.mDisplayedFragment);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Configures the given fragment, e.g. fixing the screen orientation
|
|
|
+ *
|
|
|
+ * @param fragment the fragment to configure
|
|
|
+ */
|
|
|
private void configureFragment(Fragment fragment) {
|
|
|
if (fragment == null)
|
|
|
return;
|
|
@@ -475,6 +570,9 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
if (mDisplayedFragment instanceof HomeFragment) {
|
|
@@ -502,6 +600,9 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public boolean onKeyDown(int keycode, KeyEvent e) {
|
|
|
switch (keycode) {
|
|
@@ -519,22 +620,46 @@ public class MainActivity extends Activity {
|
|
|
return super.onKeyDown(keycode, e);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Create a new intent intented for binding the hostage service to the activity
|
|
|
+ *
|
|
|
+ * @return the new service intent
|
|
|
+ */
|
|
|
public Intent getServiceIntent() {
|
|
|
return new Intent(this, Hostage.class);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Retrieves the currently displayed fragment
|
|
|
+ *
|
|
|
+ * @return the current fragment
|
|
|
+ */
|
|
|
public Fragment getDisplayedFragment() {
|
|
|
return this.mDisplayedFragment;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Retrieves the Hostage service instance
|
|
|
+ * @return hostage service
|
|
|
+ */
|
|
|
public Hostage getHostageService() {
|
|
|
return this.mHoneyService;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Checks if the hostage service is bound to the activity
|
|
|
+ * @return true, if bound
|
|
|
+ * false, otherwise
|
|
|
+ */
|
|
|
public boolean isServiceBound() {
|
|
|
return this.mServiceBound;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Checks whether the hostage service is running
|
|
|
+ * @return true, if running
|
|
|
+ * false, otherwise
|
|
|
+ */
|
|
|
public boolean isServiceRunning() {
|
|
|
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
@@ -545,8 +670,14 @@ public class MainActivity extends Activity {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Start the monitoring of the given protocols in the hostage service
|
|
|
+ *
|
|
|
+ * @param protocols the protocols to start
|
|
|
+ */
|
|
|
public void startMonitorServices(List<String> protocols){
|
|
|
for(String protocol: protocols){
|
|
|
+ // if the given protocol is ghost start a listener for every defined port for ghost
|
|
|
if(protocol.equals("GHOST")){
|
|
|
if(mProfileManager.getCurrentActivatedProfile() != null){
|
|
|
Profile profile = mProfileManager.getCurrentActivatedProfile();
|
|
@@ -562,6 +693,9 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Holds the index of the navigation items in an enum and also a reference to an Fragment class for each item
|
|
|
+ */
|
|
|
public enum MainMenuItem {
|
|
|
HOME(0, HomeFragment.class),
|
|
|
THREAT_MAP(1, ThreatMapFragment.class),
|
|
@@ -570,7 +704,8 @@ public class MainActivity extends Activity {
|
|
|
SERVICES(4, ServicesFragment.class),
|
|
|
PROFILE_MANAGER(5, ProfileManagerFragment.class),
|
|
|
SETTINGS(6, SettingsFragment.class),
|
|
|
- APPLICATION_INFO(7, AboutFragment.class);
|
|
|
+ HELP(7, Class.class),
|
|
|
+ APPLICATION_INFO(8, AboutFragment.class);
|
|
|
|
|
|
private int value;
|
|
|
private Class<?> klass;
|
|
@@ -603,6 +738,9 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The listener for the navigation drawer items.
|
|
|
+ */
|
|
|
private class DrawerItemClickListener implements ListView.OnItemClickListener {
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
displayView(position);
|