List of usage examples for android.content Context MODE_WORLD_READABLE
int MODE_WORLD_READABLE
To view the source code for android.content Context MODE_WORLD_READABLE.
Click Source Link
From source file:com.heyzap.http.SDKCookieStore.java
/** * Construct a persistent cookie store.//from ww w. j av a 2 s. co m */ public SDKCookieStore(Context context) { cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE); cookies = new ConcurrentHashMap<String, Cookie>(); this.context = context; addCookies(HeyzapCookies.getCookie(context)); }
From source file:es.deustotech.piramide.utils.tts.TextToSpeechWeb.java
private static synchronized void speech(final Context context, final String text, final String language) { executor.submit(new Runnable() { @Override/*from w w w . j a va 2 s . co m*/ public void run() { try { final String encodedUrl = Constants.URL + language + "&q=" + URLEncoder.encode(text, Encoding.UTF_8.name()); final DefaultHttpClient client = new DefaultHttpClient(); HttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.content-charset", "UTF-8"); client.setParams(params); final FileOutputStream fos = context.openFileOutput(Constants.MP3_FILE, Context.MODE_WORLD_READABLE); try { try { final HttpResponse response = client.execute(new HttpGet(encodedUrl)); downloadFile(response, fos); } finally { fos.close(); } final String filePath = context.getFilesDir().getAbsolutePath() + "/" + Constants.MP3_FILE; final MediaPlayer player = MediaPlayer.create(context.getApplicationContext(), Uri.fromFile(new File(filePath))); player.start(); Thread.sleep(player.getDuration()); while (player.isPlaying()) { Thread.sleep(100); } player.stop(); } finally { context.deleteFile(Constants.MP3_FILE); } } catch (InterruptedException ie) { // ok } catch (Exception e) { e.printStackTrace(); } } }); }
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 www . ja va2s .c om } } 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;// ww w . ja v a2 s . c o m } } }
From source file:Main.java
static void createOptOut(Context context, boolean optedOut) { FileOutputStream stream = null; try {/*from w w w . ja v a 2s .co m*/ stream = context.openFileOutput(QCMEASUREMENT_OPTOUT_STRING, Context.MODE_WORLD_WRITEABLE | Context.MODE_WORLD_READABLE); stream.write(optedOut ? 1 : 0); } catch (Exception ignored) { } finally { try { if (stream != null) { stream.close(); } } catch (IOException ignored) { } } }
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;/*from ww w .jav 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;//from w w w . j av a 2 s .c o m } 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++;/*from w ww .j a v a2 s. co m*/ } if (page2Type != AppSettings.PAGE_TYPE_NONE) { extraPages++; } }
From source file:org.godotengine.godot.Utils.java
public static String readFromFile(String fPath, Context context) { StringBuilder returnString = new StringBuilder(); String fileName = fPath;/*from ww w . j ava 2 s . c om*/ if (fPath.startsWith("res://")) { fileName = fileName.replaceFirst("res://", ""); } InputStream fIn = null; InputStreamReader isr = null; BufferedReader input = null; try { fIn = context.getResources().getAssets().open(fileName, Context.MODE_WORLD_READABLE); isr = new InputStreamReader(fIn); input = new BufferedReader(isr); String line = ""; while ((line = input.readLine()) != null) { returnString.append(line); } } catch (Exception e) { e.getMessage(); } finally { try { if (isr != null) { isr.close(); } if (fIn != null) { fIn.close(); } if (input != null) { input.close(); } } catch (Exception e2) { e2.getMessage(); } } return returnString.toString(); }
From source file:de.theknut.xposedgelsettings.ui.MainActivity.java
@SuppressWarnings("deprecation") @Override/* w ww . jav a 2 s. co m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = CommonUI.CONTEXT = mActivity = CommonUI.ACTIVITY = this; if (getSharedPreferences(Common.PREFERENCES_NAME, Context.MODE_WORLD_READABLE) .getBoolean("forceenglishlocale", false)) { Resources res = mContext.getResources(); Configuration conf = res.getConfiguration(); conf.locale = new Locale(Locale.US.getDisplayLanguage().toLowerCase()); res.updateConfiguration(conf, res.getDisplayMetrics()); } mTitle = mDrawerTitle = getTitle(); mFragmentTitles = getResources().getStringArray(R.array.fragmenttitles_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerLayout.getRootView().setBackgroundColor(CommonUI.UIColor); getActionBar().setBackgroundDrawable(new ColorDrawable(CommonUI.UIColor)); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mFragmentTitles)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); mDrawerLayout.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getRepeatCount() != 0) return false; if (!mDrawerLayout.isDrawerOpen(Gravity.LEFT)) { if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) { mDrawerLayout.openDrawer(Gravity.LEFT); return true; } } else { if (keyCode == KeyEvent.KEYCODE_BACK) { MainActivity.this.finish(); return true; } else if (keyCode == KeyEvent.KEYCODE_MENU) { mDrawerLayout.closeDrawer(Gravity.LEFT); return true; } } return false; } }); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); getActionBar().setBackgroundDrawable(new ColorDrawable(CommonUI.UIColor)); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); SharedPreferences prefs = getSharedPreferences(Common.PREFERENCES_NAME, Context.MODE_WORLD_READABLE); CommonUI.NO_BACKGROUND_IMAGE = prefs.getBoolean("nobackgroundimage", false); CommonUI.AUTO_BLUR_IMAGE = prefs.getBoolean("autoblurimage", false); if (savedInstanceState == null) { Intent i = getIntent(); if (i != null && i.hasExtra("fragment")) { if (i.getStringExtra("fragment").equals("badges")) { selectItem(6); } } else { selectItem(0); } } }