App.java 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Odoo, Open Source Management Solution
  3. * Copyright (C) 2012-today Odoo SA (<http:www.odoo.com>)
  4. * <p/>
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version
  9. * <p/>
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details
  14. * <p/>
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http:www.gnu.org/licenses/>
  17. * <p/>
  18. * Created on 17/12/14 6:06 PM
  19. */
  20. package com.odoo;
  21. import android.app.Application;
  22. import android.content.Context;
  23. import android.content.pm.PackageManager;
  24. import android.net.ConnectivityManager;
  25. import android.net.NetworkInfo;
  26. import com.odoo.datas.OConstants;
  27. import java.util.HashMap;
  28. import odoo.Odoo;
  29. import odoo.helper.OUser;
  30. public class App extends Application {
  31. public static final String TAG = App.class.getSimpleName();
  32. public static String APPLICATION_ID;
  33. public static String APPLICATION_NAME;
  34. private static HashMap<String, Odoo> mOdooInstances = new HashMap<>();
  35. @Override
  36. public void onCreate() {
  37. super.onCreate();
  38. App.APPLICATION_ID= getPackageName();
  39. App.APPLICATION_NAME = getPackageManager().getApplicationLabel(getApplicationInfo()).toString();
  40. Odoo.REQUEST_TIMEOUT_MS = OConstants.RPC_REQUEST_TIME_OUT;
  41. Odoo.DEFAULT_MAX_RETRIES = OConstants.RPC_REQUEST_RETRIES;
  42. }
  43. public Odoo getOdoo(OUser user) {
  44. if (mOdooInstances.containsKey(user.getAndroidName())) {
  45. return mOdooInstances.get(user.getAndroidName());
  46. }
  47. return null;
  48. }
  49. public void setOdoo(Odoo odoo, OUser user) {
  50. if (user != null)
  51. mOdooInstances.put(user.getAndroidName(), odoo);
  52. }
  53. /**
  54. * Checks for network availability
  55. *
  56. * @return true, if network available
  57. */
  58. public boolean inNetwork() {
  59. boolean isConnected = false;
  60. ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  61. NetworkInfo nInfo = manager.getActiveNetworkInfo();
  62. if (nInfo != null && nInfo.isConnectedOrConnecting()) {
  63. isConnected = true;
  64. }
  65. return isConnected;
  66. }
  67. /**
  68. * Checks for installed application
  69. *
  70. * @param appPackage
  71. * @return true, if application installed on device
  72. */
  73. public boolean appInstalled(String appPackage) {
  74. boolean mInstalled = false;
  75. try {
  76. PackageManager mPackage = getPackageManager();
  77. mPackage.getPackageInfo(appPackage, PackageManager.GET_ACTIVITIES);
  78. mInstalled = true;
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. }
  82. return mInstalled;
  83. }
  84. }