Example usage for android.content Context MODE_WORLD_WRITEABLE

List of usage examples for android.content Context MODE_WORLD_WRITEABLE

Introduction

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

Prototype

int MODE_WORLD_WRITEABLE

To view the source code for android.content Context MODE_WORLD_WRITEABLE.

Click Source Link

Document

File creation mode: allow all other applications to have write access to the created file.

Usage

From source file:com.daiv.android.twitter.listeners.MainDrawerClickListener.java

public MainDrawerClickListener(Context context, NotificationDrawerLayout drawer, ViewPager viewPager) {
    this.context = context;
    this.drawer = drawer;
    this.viewPager = viewPager;
    this.noWait = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            || context.getResources().getBoolean(R.bool.isTablet);
    sharedPreferences = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    int currentAccount = sharedPreferences.getInt("current_account", 1);

    for (int i = 0; i < TimelinePagerAdapter.MAX_EXTRA_PAGES; i++) {
        String pageIdentifier = "account_" + currentAccount + "_page_" + (i + 1);
        int type = sharedPreferences.getInt(pageIdentifier, AppSettings.PAGE_TYPE_NONE);

        if (type != AppSettings.PAGE_TYPE_NONE) {
            swipablePages++;//from ww  w. j  a v a  2s  .c o m
        }
    }

    set = sharedPreferences.getStringSet("drawer_elements_shown_" + currentAccount, new HashSet<String>());
    shownElements = new String[set.size()];
    int i = 0;
    for (Object o : set.toArray()) {
        shownElements[i] = (String) o;
        i++;
    }
}

From source file:com.daiv.android.twitter.listeners.InteractionClickListener.java

public InteractionClickListener(Context context, NotificationDrawerLayout drawer, ViewPager viewPager) {
    this.context = context;
    this.drawer = drawer;
    this.viewPager = viewPager;

    sharedPreferences = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    int currentAccount = sharedPreferences.getInt("current_account", 1);

    for (int i = 0; i < TimelinePagerAdapter.MAX_EXTRA_PAGES; i++) {
        String pageIdentifier = "account_" + currentAccount + "_page_" + (i + 1);
        int type = sharedPreferences.getInt(pageIdentifier, AppSettings.PAGE_TYPE_NONE);

        if (type == AppSettings.PAGE_TYPE_MENTIONS) {
            mentionsPage = i;/*from ww  w  .j  a v  a2  s  .  co  m*/
        }
    }
}

From source file:com.daiv.android.twitter.services.WidgetRefreshService.java

@Override
public void onHandleIntent(Intent intent) {
    // it is refreshing elsewhere, so don't start
    if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning
            || !MainActivity.canSwitch) {
        return;/*  w  w w . j  a v  a 2  s . com*/
    }
    WidgetRefreshService.isRunning = true;
    sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setTicker(getResources().getString(R.string.refreshing) + "...")
            .setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(getResources().getString(R.string.refreshing_widget) + "...")
            .setProgress(100, 100, true)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark));

    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(6, mBuilder.build());

    Context context = getApplicationContext();

    AppSettings settings = AppSettings.getInstance(context);

    // if they have mobile data on and don't want to sync over mobile data
    if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
        return;
    }

    Twitter twitter = Utils.getTwitter(context, settings);

    HomeDataSource dataSource = HomeDataSource.getInstance(context);

    int currentAccount = sharedPrefs.getInt("current_account", 1);

    List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>();

    boolean foundStatus = false;

    Paging paging = new Paging(1, 200);

    long[] lastId;
    long id;
    try {
        lastId = dataSource.getLastIds(currentAccount);
        id = lastId[0];
    } catch (Exception e) {
        WidgetRefreshService.isRunning = false;
        return;
    }

    paging.setSinceId(id);

    for (int i = 0; i < settings.maxTweetsRefresh; i++) {
        try {
            if (!foundStatus) {
                paging.setPage(i + 1);
                List<Status> list = twitter.getHomeTimeline(paging);
                statuses.addAll(list);

                if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) {
                    Log.v("Test_inserting", "found status");
                    foundStatus = true;
                } else {
                    Log.v("Test_inserting", "haven't found status");
                    foundStatus = false;
                }
            }
        } catch (Exception e) {
            // the page doesn't exist
            foundStatus = true;
        } catch (OutOfMemoryError o) {
            // don't know why...
        }
    }

    Log.v("Test_pull", "got statuses, new = " + statuses.size());

    // hash set to remove duplicates I guess
    HashSet hs = new HashSet();
    hs.addAll(statuses);
    statuses.clear();
    statuses.addAll(hs);

    Log.v("Test_inserting", "tweets after hashset: " + statuses.size());

    lastId = dataSource.getLastIds(currentAccount);

    int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId);

    if (inserted > 0 && statuses.size() > 0) {
        sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit();
    }

    if (settings.preCacheImages) {
        startService(new Intent(this, PreCacheService.class));
    }

    context.sendBroadcast(new Intent("com.daiv.android.Test.UPDATE_WIDGET"));
    getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null);
    sharedPrefs.edit().putBoolean("refresh_me", true).commit();

    mNotificationManager.cancel(6);

    WidgetRefreshService.isRunning = false;
}

From source file:com.klinker.android.twitter.services.WidgetRefreshService.java

@Override
public void onHandleIntent(Intent intent) {
    // it is refreshing elsewhere, so don't start
    if (WidgetRefreshService.isRunning || TimelineRefreshService.isRunning || CatchupPull.isRunning
            || !MainActivity.canSwitch) {
        return;//  w ww  .  ja va 2  s . c  om
    }
    WidgetRefreshService.isRunning = true;
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_icon)
            .setTicker(getResources().getString(R.string.refreshing) + "...")
            .setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(getResources().getString(R.string.refreshing_widget) + "...")
            .setProgress(100, 100, true)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.drawer_sync_dark));

    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(6, mBuilder.build());

    Context context = getApplicationContext();

    AppSettings settings = AppSettings.getInstance(context);

    // if they have mobile data on and don't want to sync over mobile data
    if (Utils.getConnectionStatus(context) && !settings.syncMobile) {
        return;
    }

    Twitter twitter = Utils.getTwitter(context, settings);

    HomeDataSource dataSource = HomeDataSource.getInstance(context);

    int currentAccount = sharedPrefs.getInt("current_account", 1);

    List<twitter4j.Status> statuses = new ArrayList<twitter4j.Status>();

    boolean foundStatus = false;

    Paging paging = new Paging(1, 200);

    long[] lastId;
    long id;
    try {
        lastId = dataSource.getLastIds(currentAccount);
        id = lastId[0];
    } catch (Exception e) {
        WidgetRefreshService.isRunning = false;
        return;
    }

    paging.setSinceId(id);

    for (int i = 0; i < settings.maxTweetsRefresh; i++) {
        try {
            if (!foundStatus) {
                paging.setPage(i + 1);
                List<Status> list = twitter.getHomeTimeline(paging);
                statuses.addAll(list);

                if (statuses.size() <= 1 || statuses.get(statuses.size() - 1).getId() == lastId[0]) {
                    Log.v("talon_inserting", "found status");
                    foundStatus = true;
                } else {
                    Log.v("talon_inserting", "haven't found status");
                    foundStatus = false;
                }
            }
        } catch (Exception e) {
            // the page doesn't exist
            foundStatus = true;
        } catch (OutOfMemoryError o) {
            // don't know why...
        }
    }

    Log.v("talon_pull", "got statuses, new = " + statuses.size());

    // hash set to remove duplicates I guess
    HashSet hs = new HashSet();
    hs.addAll(statuses);
    statuses.clear();
    statuses.addAll(hs);

    Log.v("talon_inserting", "tweets after hashset: " + statuses.size());

    lastId = dataSource.getLastIds(currentAccount);

    int inserted = HomeDataSource.getInstance(context).insertTweets(statuses, currentAccount, lastId);

    if (inserted > 0 && statuses.size() > 0) {
        sharedPrefs.edit().putLong("account_" + currentAccount + "_lastid", statuses.get(0).getId()).commit();
    }

    if (settings.preCacheImages) {
        startService(new Intent(this, PreCacheService.class));
    }

    context.sendBroadcast(new Intent("com.klinker.android.talon.UPDATE_WIDGET"));
    getContentResolver().notifyChange(HomeContentProvider.CONTENT_URI, null);
    sharedPrefs.edit().putBoolean("refresh_me", true).commit();

    mNotificationManager.cancel(6);

    WidgetRefreshService.isRunning = false;
}

From source file:com.klinker.android.twitter.listeners.InteractionClickListener.java

public InteractionClickListener(Context context, NotificationDrawerLayout drawer, ViewPager viewPager) {
    this.context = context;
    this.drawer = drawer;
    this.viewPager = viewPager;

    sharedPreferences = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    int currentAccount = sharedPreferences.getInt("current_account", 1);

    int page1Type = sharedPreferences.getInt("account_" + currentAccount + "_page_1",
            AppSettings.PAGE_TYPE_NONE);
    int page2Type = sharedPreferences.getInt("account_" + currentAccount + "_page_2",
            AppSettings.PAGE_TYPE_NONE);

    if (page1Type != AppSettings.PAGE_TYPE_NONE) {
        extraPages++;/* w  ww. ja v a2  s  . com*/
    }

    if (page2Type != AppSettings.PAGE_TYPE_NONE) {
        extraPages++;
    }
}

From source file:org.cirrus.mobi.pegel.ListRiverFragment.java

public void onListItemClick(ListView parent, View v, int position, long id) {
    //delete preferences
    SharedPreferences settings = getActivity().getSharedPreferences("prefs", Context.MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor edit = settings.edit();
    edit.clear();/*from  www. j av  a2s . com*/
    edit.commit();

    showDetails(position);
}

From source file:org.cirrus.mobi.pegel.MeasurePointFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    PointStore ps = ((PegelApplication) getActivity().getApplication()).getPointStore();

    String[] plain_points = null;
    try {/*  w ww . ja  va 2  s .co  m*/
        entries = ps.getMeasurePoints(getActivity(), getArguments().getString("river"));
        plain_points = new String[entries.length];
        for (int i = 0; i < plain_points.length; i++) {
            plain_points[i] = entries[i].getPegelname();
        }

    } catch (Exception e) {
        //TODO: Error handling
    }
    setListAdapter(
            new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.SequenceTextView01, plain_points));

    getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    //check if we have a saved preference, then we jump to detailview already
    SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, Context.MODE_WORLD_WRITEABLE);
    String mpoint = settings.getString("mpoint", "");
    if (mpoint.length() > 0) {
        int pos = ((ArrayAdapter<String>) getListAdapter()).getPosition(mpoint);
        //         this.select(pos);
        getListView().setItemChecked(pos, true);
        this.setSelection(pos);
    }

}

From source file:com.klinker.android.twitter.listeners.MainDrawerClickListener.java

public MainDrawerClickListener(Context context, NotificationDrawerLayout drawer, ViewPager viewPager) {
    this.context = context;
    this.drawer = drawer;
    this.viewPager = viewPager;
    this.noWait = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            || context.getResources().getBoolean(R.bool.isTablet);
    sharedPreferences = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    int currentAccount = sharedPreferences.getInt("current_account", 1);

    int page1Type = sharedPreferences.getInt("account_" + currentAccount + "_page_1",
            AppSettings.PAGE_TYPE_NONE);
    int page2Type = sharedPreferences.getInt("account_" + currentAccount + "_page_2",
            AppSettings.PAGE_TYPE_NONE);

    if (page1Type != AppSettings.PAGE_TYPE_NONE) {
        extraPages++;/*from w  ww .j  a v  a2  s  .  co m*/
    }

    if (page2Type != AppSettings.PAGE_TYPE_NONE) {
        extraPages++;
    }

    Log.v("talon_lists", extraPages + " extra pages");

}

From source file:kr.co.bettersoft.checkmileage.activities.GCMIntentService.java

/**
 * onRegistered//from  w w w  .  ja va2 s  .  c o m
 *  gcm ?? ? ? ??
 *
 * @param context
 * @param registrationId
 * @return
 */
@Override
public void onRegistered(Context context, String registrationId) {
    Log.i(TAG, "Device registered: regId = " + registrationId);
    // prefs
    sharedPrefCustom = getSharedPreferences("MyCustomePref",
            Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
    savedGCMId = sharedPrefCustom.getString("savedGCMId", "");
    if (dontTwice) { //   .
        regIdGCM = registrationId;
        if (!(savedGCMId.equals(regIdGCM))) {
            SharedPreferences.Editor updatesavedGCMId = sharedPrefCustom.edit();
            updatesavedGCMId.putString("savedGCMId", regIdGCM); // GCM ID
            updatesavedGCMId.commit();
            new backgroundUpdateMyGCMtoServer().execute(); // ?  - ? GCM ?    
            localContext = context;
            localRegistrationId = registrationId;
            dontTwice = false;
        }
    }
}

From source file:com.klinker.android.twitter.ui.tweet_viewer.ViewRetweeters.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);

    context = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    settings = AppSettings.getInstance(this);

    setUpWindow();/* w  w w  .ja  v  a 2s.c  o m*/

    Utils.setUpPopupTheme(this, settings);

    actionBar = getActionBar();

    setContentView(R.layout.ptr_list_layout);

    mPullToRefreshLayout = (FullScreenSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    mPullToRefreshLayout.setOnRefreshListener(new FullScreenSwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            onRefreshStarted();
        }
    });

    if (settings.addonTheme) {
        mPullToRefreshLayout.setColorScheme(settings.accentInt, SwipeProgressBar.COLOR2, settings.accentInt,
                SwipeProgressBar.COLOR3);
    } else {
        if (settings.theme != AppSettings.THEME_LIGHT) {
            mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color),
                    SwipeProgressBar.COLOR2, context.getResources().getColor(R.color.app_color),
                    SwipeProgressBar.COLOR3);
        } else {
            mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color),
                    getResources().getColor(R.color.light_ptr_1),
                    context.getResources().getColor(R.color.app_color),
                    getResources().getColor(R.color.light_ptr_2));
        }
    }

    spinner = (LinearLayout) findViewById(R.id.list_progress);
    noContent = (LinearLayout) findViewById(R.id.no_content);

    listView = (AsyncListView) findViewById(R.id.listView);

    BitmapLruCache cache = App.getInstance(context).getBitmapCache();
    ArrayListLoader loader = new ArrayListLoader(cache, context);

    ItemManager.Builder builder = new ItemManager.Builder(loader);
    builder.setPreloadItemsEnabled(true).setPreloadItemsCount(50);
    builder.setThreadPoolSize(4);

    listView.setItemManager(builder.build());

    tweetId = getIntent().getLongExtra("id", 0);

    onRefreshStarted();

}