Example usage for android.content Context getApplicationContext

List of usage examples for android.content Context getApplicationContext

Introduction

In this page you can find the example usage for android.content Context getApplicationContext.

Prototype

public abstract Context getApplicationContext();

Source Link

Document

Return the context of the single, global Application object of the current process.

Usage

From source file:com.ryan.ryanreader.cache.CacheManager.java

public static synchronized CacheManager getInstance(final Context context) {
    if (singleton == null)
        singleton = new CacheManager(context.getApplicationContext());
    return singleton;
}

From source file:com.odoo.core.service.OSyncAdapter.java

public static Odoo createOdooInstance(Context context, OUser user) {
    try {/*from   w  ww. j a  va 2s.  c  o m*/
        App app = (App) context.getApplicationContext();
        Odoo odoo = app.getOdoo(user);
        if (odoo == null) {
            if (user.isOAauthLogin()) {
                odoo = new Odoo(context, user.getInstanceUrl(), user.isAllowSelfSignedSSL());
                OdooInstance instance = new OdooInstance();
                instance.setInstanceUrl(user.getInstanceUrl());
                instance.setDatabaseName(user.getInstanceDatabase());
                instance.setClientId(user.getClientId());
                odoo.oauth_authenticate(instance, user.getUsername(), user.getPassword());
            } else {
                odoo = new Odoo(context, user.getHost(), user.isAllowSelfSignedSSL());
                odoo.authenticate(user.getUsername(), user.getPassword(), user.getDatabase());
            }
            app.setOdoo(odoo, user);

            ResCompany company = new ResCompany(context, user);
            if (company.count("id = ? ", new String[] { user.getCompany_id() }) <= 0) {
                ODataRow company_details = new ODataRow();
                company_details.put("id", user.getCompany_id());
                company.quickCreateRecord(company_details);
            }

        }
        return odoo;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.yanzhenjie.nohttp.NoHttp.java

/**
 * Initialize NoHttp, should invoke on {@link android.app.Application#onCreate()}.
 *
 * @param context {@link Context}.//from  w  w  w.j  a va 2s .c o m
 * @param config  {@link }.
 */
public static void initialize(Context context, Config config) {
    if (sContext == null) {
        sContext = context.getApplicationContext();
        instance = new NoHttp(config == null ? new Config() : config);
    }
}

From source file:com.trk.aboutme.facebook.Settings.java

/**
 * Manually publish install attribution to the Facebook graph.  Internally handles tracking repeat calls to prevent
 * multiple installs being published to the graph.
 * @param context the current Context//from  w ww  .  java 2s.  c om
 * @param applicationId the fb application being published.
 * @param callback a callback to invoke with a Response object, carrying the server response, or an error.
 */
public static void publishInstallAsync(final Context context, final String applicationId,
        final Request.Callback callback) {
    // grab the application context ahead of time, since we will return to the caller immediately.
    final Context applicationContext = context.getApplicationContext();
    Settings.getExecutor().execute(new Runnable() {
        @Override
        public void run() {
            final Response response = Settings.publishInstallAndWaitForResponse(applicationContext,
                    applicationId);
            if (callback != null) {
                // invoke the callback on the main thread.
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        callback.onCompleted(response);
                    }
                });
            }
        }
    });
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

public static File getSharedPreferencesFile(Context mContext) {
    File appData = mContext.getFilesDir().getParentFile();
    String packageName = mContext.getApplicationContext().getPackageName();
    File prefsPath = new File(appData + System.getProperty("file.separator") + "shared_prefs"
            + System.getProperty("file.separator") + packageName + "_preferences.xml");
    return prefsPath;
}

From source file:fr.cph.chicago.util.Util.java

public static void trackAction(@NonNull final Context context, final int category, final int action,
        final String label, final int value) {
    new Thread(() -> {
        final Tracker tracker = App.getTracker(context.getApplicationContext());
        tracker.send(new HitBuilders.EventBuilder().setCategory(context.getString(category))
                .setAction(context.getString(action)).setLabel(label).setValue(value).build());
    }).start();/* w ww.  ja  v a2s .  c  o  m*/
}

From source file:com.android.incallui.ContactInfoCache.java

public static synchronized ContactInfoCache getInstance(Context mContext) {
    if (sCache == null) {
        sCache = new ContactInfoCache(mContext.getApplicationContext());
    }/*  ww  w.  ja va  2  s  . c  o  m*/
    return sCache;
}

From source file:org.wso2.emm.agent.utils.CommonUtils.java

/**
 *   Get installed package list of applications in device by user
 * @param context Context object/*w  ww . j a  v a  2s.c o  m*/
 * @return list of installed app packages
 */
public static List<String> getInstalledAppPackagesByUser(Context context) {
    return new ApplicationManager(context.getApplicationContext()).getInstalledAppsByUser();
}

From source file:org.wso2.emm.agent.utils.CommonUtils.java

/**
 * Get package list of applications that are not system apps
 *
 * @param context Context object//from  w  ww.ja  v  a2 s.c  o m
 * @return list of package list that are not system apps
 */
public static List<String> getAppsOfUser(Context context) {
    return new ApplicationManager(context.getApplicationContext()).getAppsOfUser();
}

From source file:com.tealeaf.plugin.PluginEvent.java

public static void init(Context context) {
    if (initialized) {
        return;/*  ww  w .  j a v  a 2s  .  com*/
    }
    initialized = true;
    ArrayList<String> classNames = new ArrayList<String>();

    try {
        String apkName = null;

        try {
            apkName = context.getPackageManager()
                    .getApplicationInfo(context.getApplicationContext().getPackageName(), 0).sourceDir;
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        DexFile dexFile = new DexFile(new File(apkName));
        Enumeration<String> enumeration = dexFile.entries();

        int pluginsPackageStrLen = PLUGINS_PACKAGE_NAME.length();

        while (enumeration.hasMoreElements()) {
            String className = enumeration.nextElement();

            if (className.length() < pluginsPackageStrLen)
                continue;

            if (!className.contains("$")) {
                if (className.subSequence(0, pluginsPackageStrLen).equals(PLUGINS_PACKAGE_NAME)) {
                    classNames.add(className);
                }
            }
        }
    } catch (IOException e) {
        logger.log(e);
    }

    if (classNames.size() > 0) {
        String[] classNamesArr = new String[classNames.size()];
        classNames.toArray(classNamesArr);

        for (String name : classNamesArr) {
            try {
                Class objcls = Class.forName(name);

                if (IPlugin.class.isAssignableFrom(objcls)) {
                    Object instance = objcls.newInstance();

                    if (instance != null) {
                        logger.log("{plugins} Instantiated:", name);
                        classMap.put(name, instance);
                    } else {
                        logger.log("{plugins} WARNING: Class not found:", name);
                    }
                } else {
                    logger.log("{plugins} Ignoring class that does not derive from IPlugin:", name);
                }
            } catch (ClassNotFoundException e) {
                logger.log("{plugins} WARNING: Class not found:", name);
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
    }
}