Search in sources :

Example 46 with Context

use of android.content.Context in project robospice by stephanenicolas.

the class SpiceManager method bindToService.

private void bindToService() {
    Context context = getContextReference();
    if (context == null || requestQueue.isEmpty() && isStopped) {
        // fix issue 246.
        return;
    }
    lockAcquireService.lock();
    lockSendRequestsToService.lock();
    try {
        if (spiceService == null) {
            final Intent intentService = new Intent(context, spiceServiceClass);
            Ln.v("Binding to service.");
            spiceServiceConnection = new SpiceServiceConnection();
            boolean bound = context.getApplicationContext().bindService(intentService, spiceServiceConnection, Context.BIND_AUTO_CREATE);
            if (!bound) {
                Ln.v("Binding to service failed.");
            } else {
                Ln.v("Binding to service succeeded.");
            }
        }
    } catch (Exception t) {
        // this should not happen in apps, but can happen during tests.
        Ln.d(t, "Binding to service failed.");
        Ln.d("Context is" + context);
        Ln.d("ApplicationContext is " + context.getApplicationContext());
    } finally {
        lockSendRequestsToService.unlock();
        lockAcquireService.unlock();
    }
}
Also used : Context(android.content.Context) Intent(android.content.Intent) CacheSavingException(com.octo.android.robospice.persistence.exception.CacheSavingException) CacheLoadingException(com.octo.android.robospice.persistence.exception.CacheLoadingException) CacheCreationException(com.octo.android.robospice.persistence.exception.CacheCreationException)

Example 47 with Context

use of android.content.Context in project jpHolo by teusink.

the class FileUtils method requestAllPaths.

private JSONObject requestAllPaths() throws JSONException {
    Context context = cordova.getActivity();
    JSONObject ret = new JSONObject();
    ret.put("applicationDirectory", "file:///android_asset/");
    ret.put("applicationStorageDirectory", toDirUrl(context.getFilesDir().getParentFile()));
    ret.put("dataDirectory", toDirUrl(context.getFilesDir()));
    ret.put("cacheDirectory", toDirUrl(context.getCacheDir()));
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        try {
            ret.put("externalApplicationStorageDirectory", toDirUrl(context.getExternalFilesDir(null).getParentFile()));
            ret.put("externalDataDirectory", toDirUrl(context.getExternalFilesDir(null)));
            ret.put("externalCacheDirectory", toDirUrl(context.getExternalCacheDir()));
            ret.put("externalRootDirectory", toDirUrl(Environment.getExternalStorageDirectory()));
        } catch (NullPointerException e) {
            /* If external storage is unavailable, context.getExternal* returns null */
            Log.d(LOG_TAG, "Unable to access these paths, most liklely due to USB storage");
        }
    }
    return ret;
}
Also used : Context(android.content.Context) CallbackContext(org.apache.cordova.CallbackContext) JSONObject(org.json.JSONObject)

Example 48 with Context

use of android.content.Context in project jpHolo by teusink.

the class FileUtils method getAvailableFileSystems.

protected HashMap<String, String> getAvailableFileSystems(Activity activity) {
    Context context = activity.getApplicationContext();
    HashMap<String, String> availableFileSystems = new HashMap<String, String>();
    availableFileSystems.put("files", context.getFilesDir().getAbsolutePath());
    availableFileSystems.put("documents", new File(context.getFilesDir(), "Documents").getAbsolutePath());
    availableFileSystems.put("cache", context.getCacheDir().getAbsolutePath());
    availableFileSystems.put("root", "/");
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        try {
            availableFileSystems.put("files-external", context.getExternalFilesDir(null).getAbsolutePath());
            availableFileSystems.put("sdcard", Environment.getExternalStorageDirectory().getAbsolutePath());
            availableFileSystems.put("cache-external", context.getExternalCacheDir().getAbsolutePath());
        } catch (NullPointerException e) {
            Log.d(LOG_TAG, "External storage unavailable, check to see if USB Mass Storage Mode is on");
        }
    }
    return availableFileSystems;
}
Also used : Context(android.content.Context) CallbackContext(org.apache.cordova.CallbackContext) HashMap(java.util.HashMap) File(java.io.File)

Example 49 with Context

use of android.content.Context in project cordova-android-chromeview by thedracle.

the class CordovaWebView method setup.

/**
     * Initialize webview.
     */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void setup() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    this.requestFocusFromTouch();
    // Enable JavaScript
    ChromeSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2)
    try {
        Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class });
        String manufacturer = android.os.Build.MANUFACTURER;
        Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB && android.os.Build.MANUFACTURER.contains("HTC")) {
            gingerbread_getMethod.invoke(settings, true);
        }
    } catch (NoSuchMethodException e) {
        Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
        Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
        Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }
    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    // while we do this
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
        Level16Apis.enableUniversalAccess(settings);
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);
    settings.setGeolocationDatabasePath(databasePath);
    // Enable DOM storage
    settings.setDomStorageEnabled(true);
    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);
    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    String pathToCache = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setAppCachePath(pathToCache);
    settings.setAppCacheEnabled(true);
    // Fix for CB-1405
    // Google issue 4641
    this.updateUserAgentString();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                updateUserAgentString();
            }
        };
        this.cordova.getActivity().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
    pluginManager = new PluginManager(this, this.cordova);
    jsMessageQueue = new NativeToJsMessageQueue(this, cordova);
    exposedJsApi = new ExposedJsApi(pluginManager, jsMessageQueue);
    exposeJsInterface();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) Method(java.lang.reflect.Method) BroadcastReceiver(android.content.BroadcastReceiver) InvocationTargetException(java.lang.reflect.InvocationTargetException) ChromeSettings(us.costan.chrome.ChromeSettings) PluginManager(org.apache.cordova.api.PluginManager) SuppressLint(android.annotation.SuppressLint)

Example 50 with Context

use of android.content.Context in project glimmr by brk3.

the class SettingsFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (Constants.KEY_INTERVALS_LIST_PREFERENCE.equals(key)) {
        updateIntervalSummary();
        WakefulIntentService.scheduleAlarms(new AppListener(), getActivity(), false);
    } else if (Constants.KEY_ENABLE_NOTIFICATIONS.equals(key)) {
        boolean enableNotifications = sharedPreferences.getBoolean(Constants.KEY_ENABLE_NOTIFICATIONS, false);
        if (!enableNotifications) {
            if (BuildConfig.DEBUG)
                Log.d(TAG, "Cancelling alarms");
            AppService.cancelAlarms(getActivity());
        } else {
            WakefulIntentService.scheduleAlarms(new AppListener(), getActivity(), false);
        }
    } else if (Constants.KEY_INITIAL_TAB_LIST_PREFERENCE.equals(key)) {
        updateInitialTabSummary();
    } else if (Constants.KEY_SLIDESHOW_INTERVAL.equals(key)) {
        updateSlideshowIntervalSummary();
    } else if (Constants.KEY_HIGH_QUALITY_THUMBNAILS.equals(key)) {
        /* Restart the main activity to clear the memory cache */
        Context baseContext = getActivity().getBaseContext();
        Intent i = baseContext.getPackageManager().getLaunchIntentForPackage(baseContext.getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
    }
}
Also used : Context(android.content.Context) Intent(android.content.Intent) AppListener(com.bourke.glimmr.services.AppListener)

Aggregations

Context (android.content.Context)3233 Intent (android.content.Intent)676 View (android.view.View)400 Test (org.junit.Test)346 BroadcastReceiver (android.content.BroadcastReceiver)338 IntentFilter (android.content.IntentFilter)301 TextView (android.widget.TextView)258 Resources (android.content.res.Resources)226 PendingIntent (android.app.PendingIntent)188 PackageManager (android.content.pm.PackageManager)164 File (java.io.File)156 IOException (java.io.IOException)150 LayoutInflater (android.view.LayoutInflater)139 ImageView (android.widget.ImageView)135 Drawable (android.graphics.drawable.Drawable)128 Uri (android.net.Uri)115 RemoteException (android.os.RemoteException)102 ArrayList (java.util.ArrayList)102 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)101 Bundle (android.os.Bundle)95