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.anjlab.android.iab.v3.BillingProcessor.java

public BillingProcessor(Context context, String licenseKey, IBillingHandler handler) {
    super(context);
    signatureBase64 = licenseKey;/*from   w  w  w . j  a v a2  s . co m*/
    eventHandler = handler;
    contextPackageName = context.getApplicationContext().getPackageName();
    cachedProducts = new BillingCache(context, MANAGED_PRODUCTS_CACHE_KEY);
    cachedSubscriptions = new BillingCache(context, SUBSCRIPTIONS_CACHE_KEY);
    bindPlayServices();
}

From source file:com.leo.cattle.data.net.RestApiImpl.java

/**
 * Constructor of the class//from w w w. j  a va  2  s  .c  o m
 *
 * @param context {@link android.content.Context}.
 * @param userEntityJsonMapper {@link UserEntityJsonMapper}.
 */
public RestApiImpl(Context context, UserEntityJsonMapper userEntityJsonMapper,
        ChatSessionEntityJsonMapper sessionEntityJsonMapper) {
    if (context == null || userEntityJsonMapper == null || sessionEntityJsonMapper == null) {
        throw new IllegalArgumentException("The constructor parameters cannot be null!!!");
    }
    this.context = context.getApplicationContext();
    this.userEntityJsonMapper = userEntityJsonMapper;
    this.sessionEntityJsonMapper = sessionEntityJsonMapper;
}

From source file:com.kakao.helper.SharedPreferencesCache.java

public SharedPreferencesCache(Context context, final String cacheName) {
    Utility.notNull(context, "context");
    Utility.notNull(cacheName, "cacheName");

    Context applicationContext = context.getApplicationContext();
    context = applicationContext != null ? applicationContext : context;
    this.file = context.getSharedPreferences(cacheName, Context.MODE_PRIVATE);
}

From source file:org.wso2.iot.agent.services.MessageProcessor.java

/**
 * Local notification message handler.//  w  ww . j  a va2  s  . c o  m
 *
 * @param context Context of the application.
 */
public MessageProcessor(Context context) {
    this.context = context;

    deviceId = Preference.getString(context, Constants.PreferenceFlag.DEVICE_ID_PREFERENCE_KEY);
    operationProcessor = new OperationProcessor(context.getApplicationContext());
    mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

    if (deviceId == null) {
        DeviceInfo deviceInfo = new DeviceInfo(context.getApplicationContext());
        deviceId = deviceInfo.getDeviceId();
        Preference.putString(context, Constants.PreferenceFlag.DEVICE_ID_PREFERENCE_KEY, deviceId);
    }
}

From source file:com.clarionmedia.jockey.authentication.impl.appengine.AppEngineAuthenticator.java

public AppEngineAuthenticator(Context context, Account account, AbstractHttpClient httpClient, String url,
        Activity promptActivity) {//w  w  w  . j  a  v a  2 s  .  co  m
    mAccount = account;
    mAccountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    mUrl = url;
    mHttpClient = httpClient;
    mPromptActivity = promptActivity;
    mContext = context.getApplicationContext();
    mAuthTokenCallback = new AppEngineAuthTokenCallback();
}

From source file:com.apptentive.android.sdk.Apptentive.java

private synchronized static void asyncFetchConversationToken(final Context context) {
    Thread thread = new Thread() {
        @Override//from w  ww.  java2  s . co m
        public void run() {
            fetchConversationToken(context);
        }
    };
    Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable throwable) {
            Log.w("Caught UncaughtException in thread \"%s\"", throwable, thread.getName());
            MetricModule.sendError(context.getApplicationContext(), throwable, null, null);
        }
    };
    thread.setUncaughtExceptionHandler(handler);
    thread.setName("Apptentive-FetchConversationToken");
    thread.start();
}

From source file:com.apptentive.android.sdk.Apptentive.java

private static void asyncFetchAppConfiguration(final Context context) {
    Thread thread = new Thread() {
        public void run() {
            fetchAppConfiguration(context, GlobalInfo.isAppDebuggable);
        }/*  ww w .  j a  v  a2s  . c  om*/
    };
    Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable throwable) {
            Log.e("Caught UncaughtException in thread \"%s\"", throwable, thread.getName());
            MetricModule.sendError(context.getApplicationContext(), throwable, null, null);
        }
    };
    thread.setUncaughtExceptionHandler(handler);
    thread.setName("Apptentive-FetchAppConfiguration");
    thread.start();
}

From source file:com.mindprotectionkit.freephone.signaling.SignalingSocket.java

public SignalingSocket(Context context, String host, int port, String localNumber, String password,
        OtpCounterProvider counterProvider) throws SignalingException {
    try {/*ww  w .j ava2  s  .com*/
        this.context = context.getApplicationContext();
        this.connectionAttemptComplete = false;
        this.signalingHost = host;
        this.signalingPort = port;
        this.socket = constructSSLSocket(context, signalingHost, signalingPort);
        this.outputStream = this.socket.getOutputStream();
        this.lineReader = new LineReader(socket.getInputStream());
        this.localNumber = PhoneNumberFormatter.formatNumber(context, localNumber);
        this.password = password;
        this.counterProvider = counterProvider;
    } catch (IOException ioe) {
        throw new SignalingException(ioe);
    }
}

From source file:mobisocial.socialkit.musubi.Musubi.java

public Musubi(Context context) {
    mContext = context.getApplicationContext();
    if (context instanceof Activity) {
        setDataFromIntent(((Activity) context).getIntent());
    }/*from ww w . j  ava  2 s  . c om*/
    mContentProviderThread = new ContentProviderThread();
    mContentProviderThread.start();
    if (mContentProviderThread.mHandler == null) {
        synchronized (this) {
            while (mContentProviderThread.mHandler == null) {
                try {
                    wait();
                } catch (InterruptedException e) {
                    continue;
                }
            }
        }
    }

    mContactUpdateObserver = new ContentObserver(mContentProviderThread.mHandler) {
        @Override
        public void onChange(boolean selfChange) {
            sUserCache.clear();
        }
    };
    mContext.getContentResolver().registerContentObserver(CONTACTS_URI, true, mContactUpdateObserver);
}

From source file:info.papdt.blacklight.support.Utility.java

public static void changeLanguage(Context context, int lang) {
    String language = null;//from   w w  w  . ja va 2s  . c o m
    String country = null;

    switch (lang) {
    case LANG_ZH_HANS:
        language = "zh";
        country = "CN";
        break;
    case LANG_ZH_HANT:
        language = "zh";
        country = "TW";
        break;
    case LANG_EN_US:
        language = "en";
        country = "US";
        break;
    case LANG_SYS:
        break;
    default:
        throw new IllegalStateException("But I can not speak this language!");
    }
    Locale locale = (language == null) ? Locale.getDefault() : new Locale(language, country);
    Configuration conf = context.getResources().getConfiguration();
    conf.locale = locale;
    context.getApplicationContext().getResources().updateConfiguration(conf,
            context.getResources().getDisplayMetrics());
}