MainActivity.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package de.tudarmstadt.informatik.hostage.ui;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import android.app.Activity;
  5. import android.app.ActivityManager;
  6. import android.app.ActivityManager.RunningServiceInfo;
  7. import android.content.BroadcastReceiver;
  8. import android.content.ComponentName;
  9. import android.content.Context;
  10. import android.content.Intent;
  11. import android.content.IntentFilter;
  12. import android.content.ServiceConnection;
  13. import android.content.SharedPreferences;
  14. import android.content.SharedPreferences.Editor;
  15. import android.net.ConnectivityManager;
  16. import android.os.Bundle;
  17. import android.os.IBinder;
  18. import android.support.v4.content.LocalBroadcastManager;
  19. import android.view.GestureDetector;
  20. import android.view.GestureDetector.SimpleOnGestureListener;
  21. import android.view.Menu;
  22. import android.view.MenuItem;
  23. import android.view.MotionEvent;
  24. import android.view.View;
  25. import android.view.View.OnTouchListener;
  26. import android.view.animation.Animation;
  27. import android.view.animation.AnimationUtils;
  28. import android.widget.AdapterView;
  29. import android.widget.AdapterView.OnItemClickListener;
  30. import android.widget.CheckBox;
  31. import android.widget.ImageView;
  32. import android.widget.ListView;
  33. import android.widget.TextView;
  34. import android.widget.Toast;
  35. import android.widget.ToggleButton;
  36. import android.widget.ViewAnimator;
  37. import de.tudarmstadt.informatik.hostage.HoneyService;
  38. import de.tudarmstadt.informatik.hostage.HoneyService.LocalBinder;
  39. import de.tudarmstadt.informatik.hostage.R;
  40. import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
  41. import de.tudarmstadt.informatik.hostage.logging.Logger;
  42. import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
  43. /**
  44. * MainActivity is the central activity for the GUI of the application.
  45. * MainActivity is launched when the application is first started.
  46. * It shows the user: <br>
  47. * - information about the network<br>
  48. * - light indicators for recorded attacks on each protocol<br>
  49. * - amount of attacks on each protocols<br>
  50. * The user can start and stop services.
  51. * @author Mihai Plasoianu
  52. * @author Lars Pandikow
  53. * @author Wulf Pfeiffer
  54. */
  55. public class MainActivity extends Activity {
  56. // String constants for whole application
  57. /**
  58. * Used for Broadcast between service and GUI. String: "de.tudarmstadt.informatik.hostage.BROADCAST"
  59. */
  60. public static final String BROADCAST = "de.tudarmstadt.informatik.hostage.BROADCAST";
  61. /**
  62. * Used to store session related data in a SharedPrefereces. String: "de.tudarmstadt.informatik.hostage.SESSION_DATA"
  63. */
  64. public static final String SESSION_DATA = "de.tudarmstadt.informatik.hostage.SESSION_DATA";
  65. public static final String LISTENER = "_LISTENER";
  66. public static final String HANDLER_COUNT = "_HANDLER_COUNT";
  67. public static final String SSID = "SSID";
  68. public static final String BSSID = "BSSID";
  69. public static final String INTERNAL_IP = "INTERNAL_IP";
  70. public static final String EXTERNAL_IP = "EXTERNAL_IP";
  71. /**
  72. * Integer representing a grey light.
  73. */
  74. public static final int LIGHT_GREY = 0x01;
  75. /**
  76. * Integer representing a green light.
  77. */
  78. public static final int LIGHT_GREEN = 0x02;
  79. /**
  80. * Integer representing a red light.
  81. */
  82. public static final int LIGHT_RED = 0x03;
  83. /**
  84. * Integer representing a yellow light.
  85. */
  86. public static final int LIGHT_YELLOW = 0x04;
  87. private static Context context;
  88. private HoneyService mService;
  89. private boolean serviceBound;
  90. private SharedPreferences pref;
  91. private Editor editor;
  92. private Logger logger;
  93. // variables for the swipe animation
  94. private ViewAnimator viewAnimator;
  95. private GestureDetector gestureDetector;
  96. private Animation animFlipInLR;
  97. private Animation animFlipOutLR;
  98. private Animation animFlipInRL;
  99. private Animation animFlipOutRL;
  100. private ListView listView;
  101. private ListViewAdapter adapter;
  102. private String protocolClicked;
  103. @Override
  104. protected void onCreate(Bundle savedInstanceState) {
  105. super.onCreate(savedInstanceState);
  106. MainActivity.context = getApplicationContext(); //set context
  107. setContentView(R.layout.activity_main);
  108. // Create dynamic view elements
  109. initViewAnimator();
  110. initListView();
  111. // Initialize Class variables
  112. pref = getSharedPreferences(MainActivity.SESSION_DATA, Context.MODE_PRIVATE);
  113. logger = new SQLLogger(this);
  114. editor = pref.edit();
  115. }
  116. @Override
  117. public boolean onCreateOptionsMenu(Menu menu) {
  118. getMenuInflater().inflate(R.menu.main, menu);
  119. return true;
  120. }
  121. @Override
  122. public boolean onOptionsItemSelected(MenuItem item) {
  123. // Handle item selection
  124. switch (item.getItemId()) {
  125. case R.id.action_settings:
  126. startActivity(new Intent(this, SettingsActivity.class));
  127. break;
  128. case R.id.action_about:
  129. startActivity(new Intent(this, AboutActivity.class));
  130. break;
  131. default:
  132. }
  133. return super.onOptionsItemSelected(item);
  134. }
  135. @Override
  136. protected void onStart() {
  137. super.onStart();
  138. //Register Broadcast Receiver
  139. registerReceiver();
  140. registerNetReceiver();
  141. // Bind service if running, else check for connection change and delete sessionData
  142. if (isServiceRunning()) {
  143. bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
  144. } else {
  145. String bssid_old = pref.getString(MainActivity.BSSID, "");
  146. String bssid_new = HelperUtils.getBSSID(this);
  147. if(bssid_new == null || !bssid_new.equals(bssid_old)){
  148. deleteSessionData();
  149. }
  150. }
  151. // Update UI
  152. updateUI();
  153. updateConnectionInfo();
  154. }
  155. @Override
  156. protected void onStop() {
  157. //Unbind running service
  158. if (isServiceRunning()) {
  159. unbindService(mConnection);
  160. }
  161. // Unregister Broadcast Receiver
  162. unregisterNetReceiver();
  163. unregisterReceiver();
  164. super.onStop();
  165. }
  166. @Override
  167. protected void onDestroy(){
  168. super.onDestroy();
  169. // If service not running delete session data
  170. if(!isServiceRunning()){
  171. deleteSessionData();
  172. }
  173. }
  174. /**
  175. * Called when User presses on/off button.
  176. * @param view
  177. */
  178. public void buttonOnOffClick(View view) {
  179. if (((ToggleButton) view).isChecked()) {
  180. if (isParanoid()) {
  181. protocolClicked = "PANIC";
  182. } else {
  183. protocolClicked = "SMB";
  184. }
  185. startAndBind();
  186. } else {
  187. mService.stopListeners();
  188. stopAndUnbind();
  189. }
  190. }
  191. /**
  192. * Starts the ViewLog activity, when the Button is pressed.
  193. * @see ViewLog
  194. * @param view View elements which triggers the method call.
  195. */
  196. public void showLog(View view){
  197. startActivity(new Intent(this, ViewLog.class));
  198. }
  199. /**
  200. * If mobile phone is connected to a wireless network starts the background service ands binds itself to it.
  201. * Else notifies the user that service could not be started.
  202. */
  203. private void startAndBind() {
  204. if(HelperUtils.getBSSID(this) != null){
  205. startService(getServiceIntent());
  206. bindService();
  207. } else{
  208. ToggleButton button = (ToggleButton) findViewById(R.id.toggleButtonOnOff);
  209. button.setChecked(false);
  210. Toast.makeText(getApplicationContext(), "To start a service, first connect to a wireless network.", Toast.LENGTH_SHORT).show();
  211. }
  212. }
  213. /**
  214. * Binds service to Activity
  215. * @see HoneyService
  216. */
  217. private void bindService(){
  218. bindService(getServiceIntent(), mConnection, BIND_AUTO_CREATE);
  219. serviceBound = true;
  220. }
  221. /**
  222. * Stops service and unbinds it.
  223. * @see HoneyService
  224. */
  225. private void stopAndUnbind() {
  226. unbindService();
  227. stopService(getServiceIntent());
  228. }
  229. /**
  230. * Unbinds service.
  231. * @see HoneyService
  232. */
  233. private void unbindService(){
  234. unbindService(mConnection);
  235. serviceBound = false;
  236. }
  237. /**
  238. * Connection to bind the background service
  239. * @see HoneyService
  240. */
  241. private ServiceConnection mConnection = new ServiceConnection() {
  242. /**
  243. * After the service is bound, check which has been clicked and start it.
  244. * @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName)
  245. */
  246. @Override
  247. public void onServiceConnected(ComponentName name, IBinder service) {
  248. mService = ((LocalBinder) service).getService();
  249. if(protocolClicked != null && protocolClicked.equals("PANIC")){
  250. mService.startListeners();
  251. }else if (protocolClicked != null){
  252. mService.toggleListener(protocolClicked);
  253. }
  254. protocolClicked = null;
  255. }
  256. /**
  257. * After the service is unbound, delete reference.
  258. * @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
  259. */
  260. @Override
  261. public void onServiceDisconnected(ComponentName name) {
  262. mService = null;
  263. }
  264. };
  265. /**
  266. * Returns an intent to start HoneyService.
  267. * @return An Intent to start HoneyService
  268. */
  269. private Intent getServiceIntent() {
  270. return new Intent(this, HoneyService.class);
  271. }
  272. /**
  273. * Checks if user selected paranoid mode.
  274. * @return True when paranoid mode is selected, else returns false.
  275. */
  276. private boolean isParanoid() {
  277. return ((CheckBox) findViewById(R.id.checkBoxParanoid)).isChecked();
  278. }
  279. /**
  280. * Initializes the ListView. Creating its contents dynamic from protocol res/values/protocols.xml
  281. */
  282. private void initListView() {
  283. ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
  284. for (String protocol : getResources().getStringArray(R.array.protocols)) {
  285. HashMap<String, String> d = new HashMap<String, String>();
  286. d.put("light", String.valueOf(R.drawable.light_grey));
  287. d.put("protocol", protocol);
  288. d.put("connections", "-");
  289. data.add(d);
  290. }
  291. listView = (ListView) findViewById(R.id.listViewProtocols);
  292. adapter = new ListViewAdapter(getLayoutInflater(), data);
  293. listView.setAdapter(adapter);
  294. listView.setOnTouchListener(new OnTouchListener() {
  295. @Override
  296. public boolean onTouch(View v, MotionEvent event) {
  297. return gestureDetector.onTouchEvent(event);
  298. }
  299. });
  300. listView.setOnItemClickListener(new OnItemClickListener() {
  301. @Override
  302. public void onItemClick(AdapterView<?> parent, View view,
  303. int position, long id) {
  304. String protocolName = (String) ((HashMap<?, ?>) adapter
  305. .getItem(position)).get("protocol");
  306. if (isServiceRunning()) {
  307. mService.toggleListener(protocolName);
  308. if(!mService.hasRunningListeners()){
  309. stopAndUnbind();
  310. }
  311. }else{
  312. protocolClicked = protocolName;
  313. startAndBind();
  314. }
  315. }
  316. });
  317. }
  318. /**
  319. * Checks if a {@link HoneyService} instance is running.
  320. * @return True if {@link HoneyService} is running, else false.
  321. */
  322. private boolean isServiceRunning() {
  323. ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  324. for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
  325. if (service.service.getClassName().equals(HoneyService.class.getName())) {
  326. return true;
  327. }
  328. }
  329. return false;
  330. }
  331. /**
  332. * Deletes all session related Data.
  333. */
  334. private void deleteSessionData(){
  335. editor.clear();
  336. editor.commit();
  337. }
  338. /**
  339. * Register broadcast receiver for custom broadcast.
  340. * @see #BROADCAST
  341. */
  342. private void registerReceiver() {
  343. LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
  344. new IntentFilter(BROADCAST));
  345. }
  346. /**
  347. * Unregisters broadcast receiver for custom broadcast.
  348. * @see #BROADCAST
  349. */
  350. private void unregisterReceiver() {
  351. LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
  352. }
  353. /**
  354. * Receiver for custom broadcast.
  355. * @see #BROADCAST
  356. */
  357. private BroadcastReceiver mReceiver = new BroadcastReceiver() {
  358. @Override
  359. public void onReceive(Context context, Intent intent) {
  360. // Update user interface.
  361. updateUI();
  362. }
  363. };
  364. /**
  365. * Register broadcast receiver for network state changes.
  366. * @see ConnectivityManager#CONNECTIVITY_ACTION
  367. */
  368. private void registerNetReceiver() {
  369. IntentFilter intent = new IntentFilter();
  370. intent.addAction(ConnectivityManager.CONNECTIVITY_ACTION); //"android.net.conn.CONNECTIVITY_CHANGE"
  371. registerReceiver(netReceiver, intent);
  372. }
  373. /**
  374. * Unregister broadcast receiver for network state changes.
  375. */
  376. private void unregisterNetReceiver() {
  377. unregisterReceiver(netReceiver);
  378. }
  379. /**
  380. * Receiver for network state change events.
  381. */
  382. private BroadcastReceiver netReceiver = new BroadcastReceiver() {
  383. @Override
  384. public void onReceive(Context context, Intent intent) {
  385. String bssid_old = pref.getString(BSSID, "");
  386. String bssid_new = HelperUtils.getBSSID(context);
  387. if ((bssid_new == null || !bssid_new.equals(bssid_old)) && serviceBound) {
  388. Toast.makeText(getApplicationContext(),"Connection changed! Services stopped!", Toast.LENGTH_LONG).show();
  389. unbindService();
  390. }
  391. updateConnectionInfo();
  392. }
  393. };
  394. /**
  395. * Updates Information shown by the GUI.
  396. */
  397. private void updateUI() {
  398. boolean activeListeners = false;
  399. boolean activeHandlers = false;
  400. boolean yellowLight = false;
  401. //Check for all protocols if listeners are active and attacks have been recorded
  402. //Update protocol lights and connection information.
  403. for(String protocol : getResources().getStringArray(R.array.protocols)){
  404. //Check if protocol is active
  405. if(pref.getBoolean(protocol + LISTENER, false)){
  406. activeListeners = true;
  407. int handlerCount = pref.getInt(protocol + HANDLER_COUNT, 0);
  408. //Check if attacks have been recorded in this session.
  409. if(handlerCount > 0){
  410. activeHandlers = true;
  411. updateProtocolLight(LIGHT_RED, protocol);
  412. updateProtocolConnections(handlerCount, protocol);
  413. } else{
  414. //Check if the bssid of the wireless network has already been recorded as infected.
  415. if(logger.bssidSeen(protocol, HelperUtils.getBSSID(getApplicationContext()))){
  416. updateProtocolLight(LIGHT_YELLOW, protocol);
  417. yellowLight = true;
  418. } else{
  419. updateProtocolLight(LIGHT_GREEN, protocol);
  420. }
  421. updateProtocolConnections(0, protocol);
  422. }
  423. }else{
  424. updateProtocolLight(LIGHT_GREY, protocol);
  425. }
  426. }
  427. //Update the big attack indicator.
  428. if (activeListeners) {
  429. if (activeHandlers) {
  430. updateStatusLight(LIGHT_RED);
  431. } else {
  432. if(yellowLight){
  433. updateStatusLight(LIGHT_YELLOW);
  434. } else {
  435. updateStatusLight(LIGHT_GREEN);
  436. }
  437. }
  438. ((ToggleButton) findViewById(R.id.toggleButtonOnOff))
  439. .setChecked(true);
  440. findViewById(R.id.checkBoxParanoid).setEnabled(false);
  441. } else {
  442. updateStatusLight(LIGHT_GREY);
  443. ((ToggleButton) findViewById(R.id.toggleButtonOnOff))
  444. .setChecked(false);
  445. findViewById(R.id.checkBoxParanoid).setEnabled(true);
  446. }
  447. }
  448. /**
  449. * Sets the big light indicator.
  450. * @param light Integer code to set the light color.
  451. * @see #LIGHT_GREY
  452. * @see #LIGHT_GREEN
  453. * @see #LIGHT_RED
  454. * @see #LIGHT_YELLOW
  455. */
  456. private void updateStatusLight(int light) {
  457. switch (light) {
  458. case LIGHT_GREY:
  459. ((ImageView) findViewById(R.id.imageViewLight))
  460. .setImageResource(R.drawable.light_grey_large);
  461. break;
  462. case LIGHT_GREEN:
  463. ((ImageView) findViewById(R.id.imageViewLight))
  464. .setImageResource(R.drawable.light_green_large);
  465. break;
  466. case LIGHT_RED:
  467. ((ImageView) findViewById(R.id.imageViewLight))
  468. .setImageResource(R.drawable.light_red_large);
  469. break;
  470. case LIGHT_YELLOW:
  471. ((ImageView) findViewById(R.id.imageViewLight))
  472. .setImageResource(R.drawable.light_yellow_large);
  473. break;
  474. }
  475. }
  476. /**
  477. * Sets the light indicator for a given protocol.
  478. * @param light Integer code to set the light color.
  479. * @param protocolName Name of the protocol which should be updated.
  480. */
  481. private void updateProtocolLight(int light, String protocolName) {
  482. for (int i = 0; i < adapter.getCount(); ++i) {
  483. HashMap<String, String> d = (HashMap<String, String>) adapter
  484. .getItem(i);
  485. if (d.get("protocol").equals(protocolName)) {
  486. switch (light) {
  487. case LIGHT_GREY:
  488. d.put("light", String.valueOf(R.drawable.light_grey));
  489. d.put("connections", "-");
  490. break;
  491. case LIGHT_GREEN:
  492. d.put("light", String.valueOf(R.drawable.light_green));
  493. break;
  494. case LIGHT_RED:
  495. d.put("light", String.valueOf(R.drawable.light_red));
  496. break;
  497. case LIGHT_YELLOW:
  498. d.put("light", String.valueOf(R.drawable.light_yellow));
  499. break;
  500. }
  501. }
  502. }
  503. adapter.notifyDataSetChanged();
  504. }
  505. /**
  506. * Sets the connections count for a given protocol.
  507. * @param connections New value for recorded connections.
  508. * @param protocolName Name of the protocol which should be updated.
  509. */
  510. private void updateProtocolConnections(int connections, String protocolName) {
  511. for (int i = 0; i < adapter.getCount(); ++i) {
  512. HashMap<String, String> d = ((HashMap<String, String>) adapter
  513. .getItem(i));
  514. if (d.get("protocol").equals(protocolName)) {
  515. d.put("connections", String.valueOf(connections));
  516. }
  517. }
  518. adapter.notifyDataSetChanged();
  519. }
  520. /**
  521. * Gets Information about connection state and updates the GUI.
  522. */
  523. private void updateConnectionInfo() {
  524. /*
  525. final Context context = this;
  526. new Thread(new Runnable() {
  527. public void run() {
  528. */
  529. //Get text fields
  530. TextView ssidView = (TextView) findViewById(R.id.textViewSSIDValue);
  531. TextView bssidView = (TextView) findViewById(R.id.textViewBSSIDValue);
  532. TextView internalIPView = (TextView) findViewById(R.id.textViewInternalIPValue);
  533. TextView externalIPView = (TextView) findViewById(R.id.textViewExternalIPValue);
  534. /*
  535. ssidView.setText("Loading...");
  536. bssidView.setText("Loading...");
  537. internalIPView.setText("Loading...");
  538. externalIPView.setText("Loading...");
  539. */
  540. //Update the connection information
  541. HelperUtils.updateConnectionInfo(context);
  542. //Get connection information
  543. String ssid = pref.getString(SSID, "-");
  544. String bssid = pref.getString(BSSID, "-");
  545. String internalIP = pref.getString(INTERNAL_IP, "-");
  546. String externalIP = pref.getString(EXTERNAL_IP, "-");
  547. //Set text fields
  548. if (ssid != null)
  549. ssidView.setText(ssid);
  550. else
  551. ssidView.setText("-");
  552. if (bssid != null)
  553. bssidView.setText(bssid);
  554. else
  555. bssidView.setText("-");
  556. if (internalIP != null)
  557. internalIPView.setText(internalIP);
  558. else
  559. internalIPView.setText("-");
  560. if (externalIP != null)
  561. externalIPView.setText(externalIP);
  562. else
  563. externalIPView.setText("-");
  564. /* }
  565. }).start();
  566. */
  567. }
  568. /*############# Help functions for animation ##################*/
  569. @Override
  570. public boolean onTouchEvent(MotionEvent event) {
  571. return gestureDetector.onTouchEvent(event);
  572. }
  573. /**
  574. * Initializes variables for screen animation
  575. */
  576. private void initViewAnimator() {
  577. viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator);
  578. gestureDetector = new GestureDetector(this, simpleOnGestureListener);
  579. animFlipInLR = AnimationUtils.loadAnimation(this,
  580. R.anim.in_left_to_right);
  581. animFlipOutLR = AnimationUtils.loadAnimation(this,
  582. R.anim.out_left_to_right);
  583. animFlipInRL = AnimationUtils.loadAnimation(this,
  584. R.anim.in_right_to_left);
  585. animFlipOutRL = AnimationUtils.loadAnimation(this,
  586. R.anim.out_right_to_left);
  587. }
  588. /**
  589. * Called when a swipe to the Left is registered.
  590. */
  591. private void swipeRightToLeft() {
  592. if (viewAnimator.getDisplayedChild() == 0) {
  593. viewAnimator.setInAnimation(animFlipInRL);
  594. viewAnimator.setOutAnimation(animFlipOutRL);
  595. viewAnimator.setDisplayedChild(1);
  596. }
  597. }
  598. /**
  599. * Called when a swipe to the Right is registered.
  600. */
  601. private void swipeLeftToRight() {
  602. if (viewAnimator.getDisplayedChild() == 1) {
  603. viewAnimator.setInAnimation(animFlipInLR);
  604. viewAnimator.setOutAnimation(animFlipOutLR);
  605. viewAnimator.setDisplayedChild(0);
  606. }
  607. }
  608. SimpleOnGestureListener simpleOnGestureListener = new SimpleOnGestureListener() {
  609. @Override
  610. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  611. float velocityY) {
  612. float sensitvity = 50;
  613. if ((e1.getX() - e2.getX()) > sensitvity) {
  614. swipeRightToLeft();
  615. } else if ((e2.getX() - e1.getX()) > sensitvity) {
  616. swipeLeftToRight();
  617. }
  618. return true;
  619. }
  620. };
  621. /**
  622. * Returns the context of the App.
  623. * @return context.
  624. */
  625. public static Context getContext() {
  626. return MainActivity.context;
  627. }
  628. }