Example usage for android.content Context MODE_WORLD_READABLE

List of usage examples for android.content Context MODE_WORLD_READABLE

Introduction

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

Prototype

int MODE_WORLD_READABLE

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

Click Source Link

Document

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

Usage

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  ww w.  j  ava  2 s  . c  om*/
    }

    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  ww . java2  s .c om
 *  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:de.cortex_media.phonegap.mediaviewer.MediaViewer.java

private void copy(String fileFrom, String fileTo) throws IOException {
    InputStream in = this.cordova.getActivity().getAssets().open(fileFrom);
    FileOutputStream out = this.cordova.getActivity().openFileOutput(fileTo, Context.MODE_WORLD_READABLE);
    byte[] buf = new byte[1024];
    int len;//from ww  w . j  a  v a2  s .co  m
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

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();/*from ww w  .ja  va2  s.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();

}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void refreshNotification(Context context, boolean noTimeline) {
    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    //int[] unreadCounts = new int[] {4, 1, 2}; // for testing
    int[] unreadCounts = getUnreads(context);

    int timeline = unreadCounts[0];
    int realTimelineCount = timeline;

    // if they don't want that type of notification, simply set it to zero
    if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) {
        unreadCounts[0] = 0;/*from   w  ww . ja  va  2 s .co  m*/
    }
    if (!settings.mentionsNot) {
        unreadCounts[1] = 0;
    }
    if (!settings.dmsNot) {
        unreadCounts[2] = 0;
    }

    if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) {

    } else {
        Intent markRead = new Intent(context, MarkReadService.class);
        PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

        String shortText = getShortText(unreadCounts, context, currentAccount);
        String longText = getLongText(unreadCounts, context, currentAccount);
        // [0] is the full title and [1] is the screenname
        String[] title = getTitle(unreadCounts, context, currentAccount);
        boolean useExpanded = useExp(context);
        boolean addButton = addBtn(unreadCounts);

        if (title == null) {
            return;
        }

        Intent resultIntent;

        if (unreadCounts[1] != 0 && unreadCounts[0] == 0) {
            // it is a mention notification (could also have a direct message)
            resultIntent = new Intent(context, RedirectToMentions.class);
        } else {
            resultIntent = new Intent(context, MaterialMainActivity.class);
        }

        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

        NotificationCompat.Builder mBuilder;

        Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

        mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0])
                .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1]))
                .setContentIntent(resultPendingIntent).setAutoCancel(true)
                .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
                .setPriority(NotificationCompat.PRIORITY_HIGH);

        if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) {
            // inbox style notification for mentions
            mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // inbox style notification for direct messages
            mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else {
            // big text style for an unread count on timeline, mentions, and direct messages
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)));
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title[0], shortText);
        }

        // Light Flow notification
        sendToLightFlow(context, title[0], shortText);

        int homeTweets = unreadCounts[0];
        int mentionsTweets = unreadCounts[1];
        int dmTweets = unreadCounts[2];

        int newC = 0;

        if (homeTweets > 0) {
            newC++;
        }
        if (mentionsTweets > 0) {
            newC++;
        }
        if (dmTweets > 0) {
            newC++;
        }

        if (settings.notifications && newC > 0) {

            if (settings.vibrate) {
                mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
            }

            if (settings.sound) {
                try {
                    mBuilder.setSound(Uri.parse(settings.ringtone));
                } catch (Exception e) {
                    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                }
            }

            if (settings.led)
                mBuilder.setLights(0xFFFFFF, 1000, 1000);

            // Get an instance of the NotificationManager service
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

            if (addButton) { // the reply and read button should be shown

                Log.v("username_for_noti", title[1]);
                sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit();
                MentionsDataSource data = MentionsDataSource.getInstance(context);
                long id = data.getLastIds(currentAccount)[0];
                PendingIntent replyPending = PendingIntent.getActivity(context, 0, null, 0);
                sharedPrefs.edit().putLong("from_notification_long", id).commit();
                sharedPrefs.edit()
                        .putString("from_notification_text",
                                "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings))
                        .commit();

                // Create the remote input
                RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                        .setLabel("@" + title[1] + " ").build();

                // Create the notification action
                NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
                        replyPending).addRemoteInput(remoteInput).build();

                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read),
                        readPending);

                mBuilder.addAction(replyAction);
                mBuilder.addAction(action.build());
            }

            // Build the notification and issues it with notification manager.
            notificationManager.notify(1, mBuilder.build());

            // if we want to wake the screen on a new message
            if (settings.wakeScreen) {
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                        | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
                wakeLock.acquire(5000);
            }
        }

        // if there are unread tweets on the timeline, check them for favorite users
        if (settings.favoriteUserNotifications && realTimelineCount > 0) {
            favUsersNotification(currentAccount, context);
        }
    }

    try {

        ContentValues cv = new ContentValues();

        cv.put("tag", "com.daiv.android.twitter/com.daiv.android.twitter.ui.MainActivity");

        // add the direct messages and mentions
        cv.put("count", unreadCounts[1] + unreadCounts[2]);

        context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);

    } catch (IllegalArgumentException ex) {

        /* Fine, TeslaUnread is not installed. */

    } catch (Exception ex) {

        /* Some other error, possibly because the format
           of the ContentValues are incorrect.
                
        Log but do not crash over this. */

        ex.printStackTrace();

    }
}

From source file:com.littlepancake.glpk.HelpFragment.java

private void openGlpkPdf() {
    AssetManager assetManager = getActivity().getAssets();

    File file = new File(getActivity().getFilesDir(), glpkPdfName);

    if (!file.exists()) {
        InputStream in = null;/*from  w w  w. ja v  a2s  .co m*/
        OutputStream out = null;
        try {
            in = assetManager.open(glpkPdfName);
            /* Note that "MODE_WORLD_READABLE" is "dangerous". It seems the alternative is
             * for me to write a few hundred more lines of code or something. Guess I'll
             * remain dangerous for this app.
             * See:
             *  https://github.com/commonsguy/cw-omnibus/tree/master/ContentProvider/Files
             * for the proper, code-intensive way to handle this.
             */
            out = getActivity().openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
            byte[] buffer = new byte[buff_size];
            int read;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }
            in.close();
            out.flush();
            out.close();
            out = null;
            in = null;
        } catch (IOException e) {
            Log.e("tag", e.getMessage());
        }
    } else {
        //Log.d("tag", glpkPdfName+" already exists.");
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getActivity().getFilesDir() + "/" + glpkPdfName),
            "application/pdf");
    startActivity(intent);
}

From source file:com.simonmacdonald.corinthian.VideoPlayer.java

private void copy(String fileFrom, String fileTo) throws IOException {
    // get file to be copied from assets
    InputStream in = this.cordova.getActivity().getAssets().open(fileFrom);
    // get file where copied too, in internal storage.
    // must be MODE_WORLD_READABLE or Android can't play it
    FileOutputStream out = this.cordova.getContext().openFileOutput(fileTo, Context.MODE_WORLD_READABLE);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;/*ww  w .ja  v a 2s .com*/
    while ((len = in.read(buf)) > 0)
        out.write(buf, 0, len);
    in.close();
    out.close();
}

From source file:com.klinker.android.twitter.ui.search.SearchPager.java

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

    overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);

    try {/*  w ww . j a  v  a  2  s.c om*/
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore
    }

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

    try {
        searchQuery = getIntent().getStringExtra(SearchManager.QUERY);
    } catch (Exception e) {
        searchQuery = "";
    }

    if (searchQuery == null) {
        searchQuery = "";
    }

    handleIntent(getIntent());

    if (Build.VERSION.SDK_INT > 18 && settings.uiExtras
            && (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE
                    || getResources().getBoolean(R.bool.isTablet))) {
        translucent = true;
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        try {
            int immersive = android.provider.Settings.System.getInt(getContentResolver(), "immersive_mode");

            if (immersive == 1) {
                translucent = false;
            }
        } catch (Exception e) {
        }
    } else {
        translucent = false;
    }

    Utils.setUpTheme(context, settings);
    setContentView(R.layout.search_pager);

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.search));
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));

    View statusBar = findViewById(R.id.activity_status_bar);

    mViewPager = (ViewPager) findViewById(R.id.pager);

    if (translucent) {
        statusBar.setVisibility(View.VISIBLE);

        int statusBarHeight = Utils.getStatusBarHeight(context);

        LinearLayout.LayoutParams statusParams = (LinearLayout.LayoutParams) statusBar.getLayoutParams();
        statusParams.height = statusBarHeight;
        statusBar.setLayoutParams(statusParams);
    } else {
        mViewPager.setPadding(0, 0, 0, 0);
    }

    mSectionsPagerAdapter = new SearchPagerAdapter(getFragmentManager(), context, onlyStatus, onlyProfile,
            searchQuery, translucent);

    mViewPager.setAdapter(mSectionsPagerAdapter);

    mViewPager.setOffscreenPageLimit(3);

    if (settings.addonTheme) {
        PagerTitleStrip strip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
        strip.setBackgroundColor(settings.pagerTitleInt);
    }

    mViewPager.setCurrentItem(1);

    Utils.setActionBar(context, true);

    if (onlyProfile) {
        mViewPager.setCurrentItem(2);
    }
}

From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListAdapter.java

@SuppressLint("WorldReadableFiles")
public AppListAdapter(Fragment fragment, Context context) {
    mFragment = fragment;// w ww.j  a  va2s .  co  m
    mContext = context;
    mItemList = new ArrayList<>();
    //noinspection deprecation
    prefsPackages = mContext.getSharedPreferences(Common.PREFS_PACKAGES, Context.MODE_WORLD_READABLE);
    prefsPerApp = mContext.getSharedPreferences(Common.PREFS_PER_APP, Context.MODE_PRIVATE);
    mFilter = new MyFilter();
}

From source file:com.rong.xposed.headsoff.MainActivity.java

@SuppressLint("WorldReadableFiles")
@SuppressWarnings("deprecation")
private void prefsReload() {
    SharedPreferences prefs = getSharedPreferences(SettingValues.PREF_FILE, Context.MODE_WORLD_READABLE);
    bShowSystemApps = prefs.getBoolean(SettingValues.KEY_SHOW_SYS_APP, SettingValues.DEFAULT_SHOW_SYS_APP);
}