Example usage for android.app Activity getFilesDir

List of usage examples for android.app Activity getFilesDir

Introduction

In this page you can find the example usage for android.app Activity getFilesDir.

Prototype

@Override
    public File getFilesDir() 

Source Link

Usage

From source file:com.akoscz.youtube.YouTubeFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    // initialize our etag cache for this playlist
    File cacheFile = new File(activity.getFilesDir(), YOUTUBE_PLAYLIST);
    mEtagCache = EtagCache.create(cacheFile, EtagCache.FIVE_MB);
}

From source file:com.clearner.youtube.YouTubeFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    // initialize our etag cache for this playlist
    File cacheFile = new File(activity.getFilesDir(), PLAYLIST_KEY);
    mEtagCache = EtagCache.create(cacheFile, EtagCache.FIVE_MB);
}

From source file:com.nextgis.mobile.fragment.SettingsFragment.java

protected static void resetSettings(Activity activity) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
    SharedPreferences.Editor editor = preferences.edit();
    editor.remove(SettingsConstantsUI.KEY_PREF_THEME);
    editor.remove(SettingsConstantsUI.KEY_PREF_COMPASS_TRUE_NORTH);
    editor.remove(SettingsConstantsUI.KEY_PREF_COMPASS_MAGNETIC);
    editor.remove(SettingsConstantsUI.KEY_PREF_COMPASS_KEEP_SCREEN);
    editor.remove(SettingsConstantsUI.KEY_PREF_COMPASS_VIBRATE);
    editor.remove(SettingsConstantsUI.KEY_PREF_SHOW_STATUS_PANEL);
    editor.remove(SettingsConstantsUI.KEY_PREF_SHOW_CURRENT_LOC);
    editor.remove(AppSettingsConstants.KEY_PREF_SHOW_COMPASS);
    editor.remove(SettingsConstantsUI.KEY_PREF_KEEPSCREENON);
    editor.remove(SettingsConstantsUI.KEY_PREF_COORD_FORMAT);
    editor.remove(AppSettingsConstants.KEY_PREF_SHOW_ZOOM_CONTROLS);
    editor.remove(SettingsConstantsUI.KEY_PREF_LOCATION_SOURCE);
    editor.remove(SettingsConstantsUI.KEY_PREF_LOCATION_MIN_TIME);
    editor.remove(SettingsConstantsUI.KEY_PREF_LOCATION_MIN_DISTANCE);
    editor.remove(SettingsConstantsUI.KEY_PREF_LOCATION_ACCURATE_COUNT);
    editor.remove(SettingsConstantsUI.KEY_PREF_TRACKS_SOURCE);
    editor.remove(SettingsConstantsUI.KEY_PREF_TRACKS_MIN_TIME);
    editor.remove(SettingsConstantsUI.KEY_PREF_TRACKS_MIN_DISTANCE);
    editor.remove(SettingsConstantsUI.KEY_PREF_TRACK_RESTORE);
    editor.remove(AppSettingsConstants.KEY_PREF_SHOW_MEASURING);
    editor.remove(AppSettingsConstants.KEY_PREF_SHOW_SCALE_RULER);
    editor.remove(SettingsConstantsUI.KEY_PREF_SHOW_GEO_DIALOG);
    editor.remove(AppSettingsConstants.KEY_PREF_GA);

    File defaultPath = activity.getExternalFilesDir(SettingsConstantsUI.KEY_PREF_MAP);
    if (defaultPath == null) {
        defaultPath = new File(activity.getFilesDir(), SettingsConstantsUI.KEY_PREF_MAP);
    }/*from  w w w  . ja va2s  .  c o m*/

    editor.putString(SettingsConstantsUI.KEY_PREF_MAP_PATH, defaultPath.getPath());
    editor.apply();

    PreferenceManager.setDefaultValues(activity, R.xml.preferences_general, true);

    //        moveMap(activity, defaultPath);
}

From source file:org.apache.cordova.file.FileUtils.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.filesystems = new ArrayList<Filesystem>();

    String tempRoot = null;//from   w  ww  . j av  a2s  .co  m
    String persistentRoot = null;

    Activity activity = cordova.getActivity();
    String packageName = activity.getPackageName();

    String location = preferences.getString("androidpersistentfilelocation", "internal");

    tempRoot = activity.getCacheDir().getAbsolutePath();
    if ("internal".equalsIgnoreCase(location)) {
        persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
        this.configured = true;
    } else if ("compatibility".equalsIgnoreCase(location)) {
        /*
         *  Fall-back to compatibility mode -- this is the logic implemented in
         *  earlier versions of this plugin, and should be maintained here so
         *  that apps which were originally deployed with older versions of the
         *  plugin can continue to provide access to files stored under those
         *  versions.
         */
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
            tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
                    + packageName + "/cache/";
        } else {
            persistentRoot = "/data/data/" + packageName;
        }
        this.configured = true;
    }

    if (this.configured) {
        // Create the directories if they don't exist.
        File tmpRootFile = new File(tempRoot);
        File persistentRootFile = new File(persistentRoot);
        tmpRootFile.mkdirs();
        persistentRootFile.mkdirs();

        // Register initial filesystems
        // Note: The temporary and persistent filesystems need to be the first two
        // registered, so that they will match window.TEMPORARY and window.PERSISTENT,
        // per spec.
        this.registerFilesystem(
                new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile));
        this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(),
                webView.getResourceApi(), persistentRootFile));
        this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi()));
        this.registerFilesystem(
                new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi()));

        registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity));

        // Initialize static plugin reference for deprecated getEntry method
        if (filePlugin == null) {
            FileUtils.filePlugin = this;
        }
    } else {
        Log.e(LOG_TAG,
                "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
        activity.finish();
    }
}

From source file:com.remobile.file.FileUtils.java

public void initialize() {
    this.filesystems = new ArrayList<Filesystem>();

    String tempRoot = null;//w  w  w  . j  a va  2  s.  c  o  m
    String persistentRoot = null;

    Activity activity = cordova.getActivity();
    String packageName = activity.getPackageName();

    String location = "internal";

    tempRoot = activity.getCacheDir().getAbsolutePath();
    if ("internal".equalsIgnoreCase(location)) {
        persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
        this.configured = true;
    } else if ("compatibility".equalsIgnoreCase(location)) {
        /*
         *  Fall-back to compatibility mode -- this is the logic implemented in
         *  earlier versions of this plugin, and should be maintained here so
         *  that apps which were originally deployed with older versions of the
         *  plugin can continue to provide access to files stored under those
         *  versions.
         */
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
            tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
                    + packageName + "/cache/";
        } else {
            persistentRoot = "/data/data/" + packageName;
        }
        this.configured = true;
    }

    if (this.configured) {
        // Create the directories if they don't exist.
        File tmpRootFile = new File(tempRoot);
        File persistentRootFile = new File(persistentRoot);
        tmpRootFile.mkdirs();
        persistentRootFile.mkdirs();

        // Register initial filesystems
        // Note: The temporary and persistent filesystems need to be the first two
        // registered, so that they will match window.TEMPORARY and window.PERSISTENT,
        // per spec.
        this.registerFilesystem(
                new LocalFilesystem("temporary", this.getContext(), this.getResourceApi(), tmpRootFile));
        this.registerFilesystem(new LocalFilesystem("persistent", this.getContext(), this.getResourceApi(),
                persistentRootFile));
        this.registerFilesystem(new ContentFilesystem(this.getContext(), this.getResourceApi()));
        this.registerFilesystem(new AssetFilesystem(this.getContext().getAssets(), this.getResourceApi()));

        registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity));

        // Initialize static plugin reference for deprecated getEntry method
        if (filePlugin == null) {
            FileUtils.filePlugin = this;
        }
    } else {
        Log.e(LOG_TAG,
                "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
        activity.finish();
    }
}

From source file:com.creativtrendz.folio.ui.FolioWebViewScroll.java

@SuppressLint("NewApi")
protected void setGeolocationDatabasePath() {
    final Activity activity;

    if (mFragment != null && mFragment.get() != null && Build.VERSION.SDK_INT >= 11
            && mFragment.get().getActivity() != null) {
        activity = mFragment.get().getActivity();
    } else if (mActivity != null && mActivity.get() != null) {
        activity = mActivity.get();/*from  w  w  w .  ja  v a  2 s  .c o  m*/
    } else {
        return;
    }

    getSettings().setGeolocationDatabasePath(activity.getFilesDir().getPath());
}