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.amazon.cordova.plugin.ADMMessageHandler.java

/**
 * Reads "shownotificationmessage" & "defaultnotificationmessage" config options
 * If this is first-time it saves them to sharedPreferences so they can be read
 * when app is forced-stop or killed/*from  w  w w .java  2 s.com*/
 */
public static void saveConfigOptions(Context context) {
    if (context != null && TextUtils.isEmpty(defaultOfflineMessage)) {
        // read config options from config.xml
        shouldShowOfflineMessage = ((CordovaActivity) context).getBooleanProperty(SHOW_MESSAGE_PREF, false);
        defaultOfflineMessage = ((CordovaActivity) context).getStringProperty(DEFAULT_MESSAGE_PREF, null);

        // save them to sharedPreferences if necessary
        SharedPreferences config = context.getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
        SharedPreferences.Editor editor = config.edit();
        editor.putBoolean(SHOW_MESSAGE_PREF, shouldShowOfflineMessage);
        editor.putString(DEFAULT_MESSAGE_PREF, defaultOfflineMessage);
        // save prefs to disk
        editor.commit();
    }

}

From source file:com.aegiswallet.utils.WalletUtils.java

public static String getBTCCurrencryValue(Context context, SharedPreferences prefs, BigDecimal amount) {
    String result = "";

    File file = context.getApplicationContext().getFileStreamPath(Constants.BLOCKCHAIN_CURRENCY_FILE_NAME);
    if (file.exists()) {
        JSONObject jsonObject = BasicUtils.parseJSONData(context, Constants.BLOCKCHAIN_CURRENCY_FILE_NAME);
        try {/*w  w  w  .ja  v a  2 s  .c  o m*/

            if (jsonObject != null) {

                JSONObject newObject = jsonObject
                        .getJSONObject(prefs.getString(Constants.CURRENCY_PREF_KEY, null));
                Double doubleVal = newObject.getDouble("last");
                BigDecimal decimal = BigDecimal.valueOf(doubleVal);

                result = newObject.getString("symbol")
                        + decimal.multiply(amount).setScale(2, RoundingMode.HALF_EVEN).toString();
            }
        } catch (JSONException e) {
            Log.e("Wallet Utils", "JSON Exception " + e.getMessage());
        }
    }

    return result;
}

From source file:com.aegiswallet.utils.WalletUtils.java

public static String getWalletCurrencyValue(Context context, SharedPreferences prefs, BigInteger balance) {
    String result = "";

    File file = context.getApplicationContext().getFileStreamPath(Constants.BLOCKCHAIN_CURRENCY_FILE_NAME);
    if (file.exists()) {
        JSONObject jsonObject = BasicUtils.parseJSONData(context, Constants.BLOCKCHAIN_CURRENCY_FILE_NAME);
        try {//  w w w.  j ava  2  s.  co  m

            String balanceInBTC = balance.toString();

            if (balance.longValue() > 0)
                balanceInBTC = BasicUtils.formatValue(balance, Constants.BTC_MAX_PRECISION, 0);
            BigDecimal formattedBalance = new BigDecimal(balanceInBTC);

            if (jsonObject != null) {

                JSONObject newObject = jsonObject
                        .getJSONObject(prefs.getString(Constants.CURRENCY_PREF_KEY, null));
                Double doubleVal = newObject.getDouble("last");
                BigDecimal decimal = BigDecimal.valueOf(doubleVal);

                result = newObject.getString("symbol")
                        + decimal.multiply(formattedBalance).setScale(2, RoundingMode.HALF_EVEN).toString();
            }
        } catch (JSONException e) {
            Log.e("Wallet Utils", "JSON Exception " + e.getMessage());
        }
    }

    return result;
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static boolean m932a(Context context) {
    DisplayMetrics displayMetrics = context.getApplicationContext().getResources().getDisplayMetrics();
    Display defaultDisplay = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    int width = defaultDisplay.getWidth();
    int height = defaultDisplay.getHeight();
    float f = displayMetrics.density;
    if (((float) width) / f < 600.0f || ((float) height) / f < 600.0f) {
        return false;
    }//from w  w  w .  j a  v a 2 s .c  o m
    return true;
}

From source file:com.psiphon3.psiphonlibrary.WebViewProxySettings.java

public static boolean setProxy(Context ctx, String host, int port) {
    UpstreamProxySettings.saveSystemProxySettings(ctx);

    boolean worked = false;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        worked = setWebkitProxyGingerbread(ctx, host, port);
    } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        worked = setWebkitProxyICS(ctx, host, port);
    } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
        worked = setWebkitProxyKitKat(ctx.getApplicationContext(), host, port);
    } else {/*www .  ja va 2  s .c  om*/
        worked = setWebkitProxyLollipop(ctx.getApplicationContext(), host, port);
    }

    return worked;
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static void deleteMediaFromTimeline(Context ctx, Long timeLine) {

    ArrayList<MessageObject> list = DataBasesAccess.getInstance(ctx.getApplicationContext())
            .MessagesDataBaseReadSelected(timeLine, null);

    for (int i = 0; i < list.size(); i++) {
        File toDeleteJpg = new File(
                FileUtils.getDir() + "/" + list.get(i).getLocalId() + ConstantKeys.EXTENSION_JPG);
        File toDelete3gp = new File(
                FileUtils.getDir() + "/" + list.get(i).getLocalId() + ConstantKeys.EXTENSION_3GP);
        if (toDeleteJpg.exists()) {
            toDeleteJpg.delete();// w ww .j  a v a 2s.co  m
            toDeleteJpg = null;
        }

        if (toDelete3gp.exists()) {
            toDelete3gp.delete();
            toDelete3gp = null;
        }

        DataBasesAccess.getInstance(ctx.getApplicationContext())
                .MessagesDataBaseDelete(list.get(i).getLocalId());
    }
}

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

public static void saveHostDeatils(Context context, String host) {
    if (host.contains(PROTOCOL_HTTP)) {
        String hostWithPort = host.substring(PROTOCOL_HTTP.length(), host.length());
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.IP,
                getHostFromUrl(hostWithPort));
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.PROTOCOL, PROTOCOL_HTTP);
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.PORT,
                getPortFromUrl(hostWithPort, PROTOCOL_HTTP));
    } else if (host.contains(PROTOCOL_HTTPS)) {
        String hostWithPort = host.substring(PROTOCOL_HTTPS.length(), host.length());
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.IP,
                getHostFromUrl(hostWithPort));
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.PROTOCOL,
                PROTOCOL_HTTPS);/*from   ww w  . j av a  2  s. c  o m*/
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.PORT,
                getPortFromUrl(hostWithPort, PROTOCOL_HTTPS));
    } else if (host.contains(COLON)) {
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.IP,
                getHostFromUrl(host));
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.PORT,
                getPortFromUrl(host, PROTOCOL_HTTP));
    } else {
        Preference.putString(context.getApplicationContext(), Constants.PreferenceFlag.IP, host);
    }
}

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

/**
 * This method is used to initiate the oauth client app unregister process.
 *
 * @param context Application context//from  w  w  w . jav  a  2 s  .  c  o m
 * @throws AndroidAgentException
 */
public static void unRegisterClientApp(Context context, APIResultCallBack apiCallBack)
        throws AndroidAgentException {
    String serverIP = Constants.DEFAULT_HOST;
    String prefIP = Preference.getString(context.getApplicationContext(), Constants.PreferenceFlag.IP);
    if (prefIP != null) {
        serverIP = prefIP;
    }
    if (serverIP != null && !serverIP.isEmpty()) {
        String applicationName = Preference.getString(context, Constants.CLIENT_NAME);
        String consumerKey = Preference.getString(context, Constants.CLIENT_ID);
        String userId = Preference.getString(context, Constants.USERNAME);

        if (applicationName != null && !applicationName.isEmpty() && consumerKey != null
                && !consumerKey.isEmpty() && userId != null && !userId.isEmpty()) {

            UnregisterProfile profile = new UnregisterProfile();
            profile.setApplicationName(applicationName);
            profile.setConsumerKey(consumerKey);
            profile.setUserId(userId);

            ServerConfig utils = new ServerConfig();
            utils.setServerIP(serverIP);

            DynamicClientManager dynamicClientManager = new DynamicClientManager();
            boolean isUnregistered = dynamicClientManager.unregisterClient(profile, utils, context,
                    apiCallBack);

            if (!isUnregistered) {
                Log.e(TAG, "Error occurred while removing the OAuth client app");
            }
        } else {
            Log.e(TAG, "Client credential is not available");
        }
    } else {
        Log.e(TAG, "There is no valid IP to contact the server");
    }
}

From source file:ru.appsm.inapphelp.IAHHelpDesk.java

/**
 *
 * Init./*  ww  w . j  a  v a 2  s. c  o m*/
 *
 * @param context
 * @param company
 * @param app_id
 * @param app_key
 */

public static void init(Context context, String company, String app_id, String app_key) {
    assert context != null : "Context cannot be null";
    assert company != null : "Company name cannot be null";
    assert app_id != null : "App id cannot be null";
    assert app_key != null : "App key cannot be null";

    synchronized (IAHHelpDesk.class) { // 1
        if (singletonInstance == null) // 2
        {
            singletonInstance = new IAHHelpDesk(context.getApplicationContext(), company, app_id, app_key);
            IAHSource iAHSource = IAHSource.getInstance(context.getApplicationContext());
        } else {
            Log.e(TAG, "Inapphelp has been already inited");
        }
    }
}

From source file:at.wada811.utils.CameraUtils.java

/**
 * ?????/*from   w  w  w. jav  a 2 s  . co  m*/
 * 
 * @param context
 * @return
 */
public static boolean hasFeatureCamera(Context context) {
    boolean hasCamera = false;
    if (PreferenceUtils.contains(context, PackageManager.FEATURE_CAMERA)) {
        hasCamera = PreferenceUtils.getBoolean(context, PackageManager.FEATURE_CAMERA, hasCamera);
    } else {
        PackageManager packageManager = context.getApplicationContext().getPackageManager();
        hasCamera = packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA);
        PreferenceUtils.putBoolean(context, PackageManager.FEATURE_CAMERA, hasCamera);
    }
    return hasCamera;
}