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.utils.NotificationUtils.java

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

    SharedPreferences sharedPrefs = context.getSharedPreferences(
            "com.klinker.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 w w .  j a v a  2  s . c  om*/
    }
    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 if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // it is a direct message
            resultIntent = new Intent(context, RedirectToDMs.class);
        } else {
            resultIntent = new Intent(context, MainActivity.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
                Intent reply;
                if (unreadCounts[1] == 1) {
                    reply = new Intent(context, NotificationCompose.class);
                } else {
                    reply = new Intent(context, NotificationDMCompose.class);
                }

                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, reply, 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());
            } else { // otherwise, if they can use the expanded notifications, the popup button will be shown
                Intent popup = new Intent(context, RedirectToPopup.class);
                popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                popup.putExtra("from_notification", true);

                PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0);

                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
                        R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending);

                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.klinker.android.twitter/com.klinker.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.daiv.android.twitter.settings.SettingsActivityOld.java

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

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

    AppSettings.invalidate();/* w w w .j  a  v a  2 s  .  c om*/

    setUpTheme();

    setContentView(R.layout.settings_main);

    DrawerArrayAdapter.current = 0;

    linkItems = new String[] { getResources().getString(R.string.get_help_settings),
            getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new),
            getResources().getString(R.string.rate_it) };

    settingsItems = new String[] { getResources().getString(R.string.ui_settings),
            getResources().getString(R.string.timelines_settings),
            getResources().getString(R.string.sync_settings),
            getResources().getString(R.string.notification_settings),
            getResources().getString(R.string.browser_settings),
            getResources().getString(R.string.advanced_settings),
            getResources().getString(R.string.memory_manage) };

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

    if (sharedPrefs.getBoolean("version_1.20_1", true)) {
        // necessary because i didnt start out by using sets
        boolean led = sharedPrefs.getBoolean("led", true);
        boolean sound = sharedPrefs.getBoolean("sound", true);
        boolean vibrate = sharedPrefs.getBoolean("vibrate", true);
        boolean wakeScreen = sharedPrefs.getBoolean("wake", true);
        boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true);
        boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true);
        boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true);
        boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true);
        boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true);
        boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true);

        Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>());
        alert.clear();
        if (vibrate) {
            alert.add("1");
        }
        if (led) {
            alert.add("2");
        }
        if (wakeScreen) {
            alert.add("3");
        }
        if (sound) {
            alert.add("4");
        }
        sharedPrefs.edit().putStringSet("alert_types", alert).commit();

        Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>());
        timeline.clear();
        if (timelineNot) {
            timeline.add("1");
        }
        if (mentionsNot) {
            timeline.add("2");
        }
        if (dmsNot) {
            timeline.add("3");
        }
        sharedPrefs.edit().putStringSet("timeline_set", timeline).commit();

        Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>());
        interactions.clear();
        if (favoritesNot) {
            interactions.add("1");
        }
        if (retweetNot) {
            interactions.add("2");
        }
        if (followersNot) {
            interactions.add("3");
        }
        sharedPrefs.edit().putStringSet("interactions_set", interactions).commit();

        sharedPrefs.edit().putBoolean("version_1.20_1", false).commit();

        recreate();
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList);

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    otherList = (ListView) findViewById(R.id.other_list);
    settingsList = (ListView) findViewById(R.id.settings_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);

    // Set the adapter for the list view
    otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems))));
    settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems))));
    // Set the list's click listener
    settingsList.setOnItemClickListener(
            new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer));
    otherList.setOnItemClickListener(
            new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer));

    findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(true);
            settingsLinksActive = true;
            findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
        }
    });

    findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(false);
            settingsLinksActive = false;
            findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
        }
    });

    if (settingsLinksActive) {
        settingsList.setVisibility(View.VISIBLE);
        otherList.setVisibility(View.GONE);
        findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
    } else {
        settingsList.setVisibility(View.GONE);
        otherList.setVisibility(View.VISIBLE);
        findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
    }

    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            resource, /* nav drawer icon to replace 'Up' caret */
            R.string.app_name, /* "open drawer" description */
            R.string.app_name /* "close drawer" description */
    );

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            DrawerArrayAdapter.current = position;
            otherList.invalidateViews();
            settingsList.invalidateViews();
        }
    });

    if (!userKnows) {
        mDrawerLayout.openDrawer(mDrawer);
    }

    HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by);
    HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number);

    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

        String text = getResources().getString(R.string.created_by) + " daiv";
        String text2 = getResources().getString(R.string.version) + " " + versionName;
        createdBy.setText(text);
        versionNumber.setText(text2);
    } catch (Exception e) {
        String text = getResources().getString(R.string.created_by) + " daiv";
        String text2 = getResources().getString(R.string.version) + " 0.00";
        createdBy.setText(text);
        versionNumber.setText(text2);
    }

    LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/developer?id=daiv+Apps")));
        }
    });

    mDrawerLayout.openDrawer(Gravity.START);
}

From source file:com.klinker.android.twitter.settings.SettingsActivityOld.java

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

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

    AppSettings.invalidate();// ww  w. j  av a  2s .c om

    setUpTheme();

    setContentView(R.layout.settings_main);

    DrawerArrayAdapter.current = 0;

    linkItems = new String[] { getResources().getString(R.string.get_help_settings),
            getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new),
            getResources().getString(R.string.rate_it) };

    settingsItems = new String[] { getResources().getString(R.string.ui_settings),
            getResources().getString(R.string.timelines_settings),
            getResources().getString(R.string.sync_settings),
            getResources().getString(R.string.notification_settings),
            getResources().getString(R.string.browser_settings),
            getResources().getString(R.string.advanced_settings),
            getResources().getString(R.string.memory_manage) };

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

    if (sharedPrefs.getBoolean("version_1.20_1", true)) {
        // necessary because i didnt start out by using sets
        boolean led = sharedPrefs.getBoolean("led", true);
        boolean sound = sharedPrefs.getBoolean("sound", true);
        boolean vibrate = sharedPrefs.getBoolean("vibrate", true);
        boolean wakeScreen = sharedPrefs.getBoolean("wake", true);
        boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true);
        boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true);
        boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true);
        boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true);
        boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true);
        boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true);

        Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>());
        alert.clear();
        if (vibrate) {
            alert.add("1");
        }
        if (led) {
            alert.add("2");
        }
        if (wakeScreen) {
            alert.add("3");
        }
        if (sound) {
            alert.add("4");
        }
        sharedPrefs.edit().putStringSet("alert_types", alert).commit();

        Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>());
        timeline.clear();
        if (timelineNot) {
            timeline.add("1");
        }
        if (mentionsNot) {
            timeline.add("2");
        }
        if (dmsNot) {
            timeline.add("3");
        }
        sharedPrefs.edit().putStringSet("timeline_set", timeline).commit();

        Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>());
        interactions.clear();
        if (favoritesNot) {
            interactions.add("1");
        }
        if (retweetNot) {
            interactions.add("2");
        }
        if (followersNot) {
            interactions.add("3");
        }
        sharedPrefs.edit().putStringSet("interactions_set", interactions).commit();

        sharedPrefs.edit().putBoolean("version_1.20_1", false).commit();

        recreate();
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList);

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

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    otherList = (ListView) findViewById(R.id.other_list);
    settingsList = (ListView) findViewById(R.id.settings_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);

    // Set the adapter for the list view
    otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems))));
    settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems))));
    // Set the list's click listener
    settingsList.setOnItemClickListener(
            new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer));
    otherList.setOnItemClickListener(
            new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer));

    findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(true);
            settingsLinksActive = true;
            findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
        }
    });

    findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(false);
            settingsLinksActive = false;
            findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
        }
    });

    if (settingsLinksActive) {
        settingsList.setVisibility(View.VISIBLE);
        otherList.setVisibility(View.GONE);
        findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
    } else {
        settingsList.setVisibility(View.GONE);
        otherList.setVisibility(View.VISIBLE);
        findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
    }

    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            resource, /* nav drawer icon to replace 'Up' caret */
            R.string.app_name, /* "open drawer" description */
            R.string.app_name /* "close drawer" description */
    );

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            DrawerArrayAdapter.current = position;
            otherList.invalidateViews();
            settingsList.invalidateViews();
        }
    });

    if (!userKnows) {
        mDrawerLayout.openDrawer(mDrawer);
    }

    HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by);
    HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number);

    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

        String text = getResources().getString(R.string.created_by) + " Luke Klinker";
        String text2 = getResources().getString(R.string.version) + " " + versionName;
        createdBy.setText(text);
        versionNumber.setText(text2);
    } catch (Exception e) {
        String text = getResources().getString(R.string.created_by) + " Luke Klinker";
        String text2 = getResources().getString(R.string.version) + " 0.00";
        createdBy.setText(text);
        versionNumber.setText(text2);
    }

    LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/developer?id=Klinker+Apps")));
        }
    });

    mDrawerLayout.openDrawer(Gravity.START);
}

From source file:de.Maxr1998.xposed.maxlock.ui.LockFragment.java

@SuppressLint("WorldReadableFiles")
@Override//from   w ww.ja  v a  2 s . c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    // Preferences
    prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    prefsKey = getActivity().getSharedPreferences(Common.PREFS_KEY, Context.MODE_PRIVATE);
    prefsPerApp = getActivity().getSharedPreferences(Common.PREFS_PER_APP, Context.MODE_PRIVATE);
    //noinspection deprecation
    prefsTheme = getActivity().getSharedPreferences(Common.PREFS_THEME, Context.MODE_WORLD_READABLE);

    // Strings
    requestPkg = getArguments().getString(Common.INTENT_EXTRAS_PKG_NAME);

    if (prefsPerApp.contains(requestPkg))
        password = prefsPerApp.getString(requestPkg + Common.APP_KEY_PREFERENCE, null);
    else
        password = prefsKey.getString(Common.KEY_PREFERENCE, "");

    lockingType = prefsPerApp.getString(requestPkg, prefs.getString(Common.LOCKING_TYPE, ""));
}

From source file:com.dawsonloudon.videoplayer.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.getActivity().openFileOutput(fileTo, Context.MODE_WORLD_READABLE);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;// w w w.j  a  va 2s  .  co m
    while ((len = in.read(buf)) > 0)
        out.write(buf, 0, len);
    in.close();
    out.close();
}

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

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

    if (TestPullNotificationService.isRunning) {
        stopSelf();//from w w  w.  j av  a2 s .c o  m
        return;
    }

    TestPullNotificationService.isRunning = true;

    settings = AppSettings.getInstance(this);

    mCache = App.getInstance(this).getBitmapCache();

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

    showNotification = sharedPreferences.getBoolean("show_pull_notification", true);
    pullUnread = sharedPreferences.getInt("pull_unread", 0);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    Intent stop = new Intent(this, StopPull.class);
    PendingIntent stopPending = PendingIntent.getService(this, 0, stop, 0);

    String text;

    int count = 0;

    if (sharedPreferences.getBoolean("is_logged_in_1", false)) {
        count++;
    }
    if (sharedPreferences.getBoolean("is_logged_in_2", false)) {
        count++;
    }

    boolean multAcc = false;
    if (count == 2) {
        multAcc = true;
    }

    if (settings.liveStreaming && settings.timelineNot) {
        text = getResources().getString(R.string.new_tweets_upper) + ": " + pullUnread;
    } else {
        text = getResources().getString(R.string.listening_for_mentions) + "...";
    }

    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(android.R.color.transparent)
            .setContentTitle(getResources().getString(R.string.Test_pull)
                    + (multAcc ? " - @" + settings.myScreenName : ""))
            .setContentText(text).setOngoing(true)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_icon));

    if (getApplicationContext().getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.addAction(R.drawable.ic_cancel_dark,
                getApplicationContext().getResources().getString(R.string.stop), stopPending);
    }

    try {
        mBuilder.setWhen(0);
    } catch (Exception e) {
    }

    mBuilder.setContentIntent(pendingIntent);

    // priority flag is only available on api level 16 and above
    if (getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setPriority(Notification.PRIORITY_MIN);
    }

    mContext = getApplicationContext();

    IntentFilter filter = new IntentFilter();
    filter.addAction("com.daiv.android.twitter.STOP_PUSH");
    registerReceiver(stopPush, filter);

    filter = new IntentFilter();
    filter.addAction("com.daiv.android.twitter.START_PUSH");
    registerReceiver(startPush, filter);

    filter = new IntentFilter();
    filter.addAction("com.daiv.android.twitter.STOP_PUSH_SERVICE");
    registerReceiver(stopService, filter);

    if (settings.liveStreaming && settings.timelineNot) {
        filter = new IntentFilter();
        filter.addAction("com.daiv.android.twitter.UPDATE_NOTIF");
        registerReceiver(updateNotification, filter);

        filter = new IntentFilter();
        filter.addAction("com.daiv.android.twitter.NEW_TWEET");
        registerReceiver(updateNotification, filter);

        filter = new IntentFilter();
        filter.addAction("com.daiv.android.twitter.CLEAR_PULL_UNREAD");
        registerReceiver(clearPullUnread, filter);
    }

    Thread start = new Thread(new Runnable() {
        @Override
        public void run() {
            // get the ids of everyone you follow
            try {
                Log.v("getting_ids", "started getting ids, mine: " + settings.myId);
                Twitter twitter = Utils.getTwitter(mContext, settings);
                long currCursor = -1;
                IDs idObject;

                ids = new ArrayList<Long>();
                do {
                    idObject = twitter.getFriendsIDs(settings.myId, currCursor);

                    long[] lIds = idObject.getIDs();
                    for (int i = 0; i < lIds.length; i++) {
                        ids.add(lIds[i]);
                    }
                } while ((currCursor = idObject.getNextCursor()) != 0);
                ids.add(settings.myId);

                currCursor = -1;
                blockedIds = new ArrayList<Long>();
                do {
                    idObject = twitter.getBlocksIDs(currCursor);

                    long[] lIds = idObject.getIDs();
                    for (int i = 0; i < lIds.length; i++) {
                        blockedIds.add(lIds[i]);
                    }
                } while ((currCursor = idObject.getNextCursor()) != 0);

                idsLoaded = true;

                if (showNotification)
                    startForeground(FOREGROUND_SERVICE_ID, mBuilder.build());

                mContext.sendBroadcast(new Intent("com.daiv.android.twitter.START_PUSH"));
            } catch (Exception e) {
                e.printStackTrace();
                TestPullNotificationService.isRunning = false;

                pullUnread = 0;

                Thread stop = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        TestPullNotificationService.shuttingDown = true;
                        try {
                            //pushStream.removeListener(userStream);
                        } catch (Exception x) {

                        }
                        try {
                            pushStream.cleanUp();
                            pushStream.shutdown();
                            Log.v("twitter_stream_push", "stopping push notifications");
                        } catch (Exception e) {
                            // it isn't running
                            e.printStackTrace();
                            // try twice to shut it down i guess
                            try {
                                Thread.sleep(2000);
                                pushStream.cleanUp();
                                pushStream.shutdown();
                                Log.v("twitter_stream_push", "stopping push notifications");
                            } catch (Exception x) {
                                // it isn't running
                                x.printStackTrace();
                            }
                        }

                        TestPullNotificationService.shuttingDown = false;
                    }
                });

                stop.setPriority(Thread.MAX_PRIORITY);
                stop.start();

                stopSelf();
            } catch (OutOfMemoryError e) {
                TestPullNotificationService.isRunning = false;

                Thread stop = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        TestPullNotificationService.shuttingDown = true;
                        try {
                            //pushStream.removeListener(userStream);
                        } catch (Exception x) {

                        }
                        try {
                            pushStream.cleanUp();
                            pushStream.shutdown();
                            Log.v("twitter_stream_push", "stopping push notifications");
                        } catch (Exception e) {
                            // it isn't running
                            e.printStackTrace();
                            // try twice to shut it down i guess
                            try {
                                Thread.sleep(2000);
                                pushStream.cleanUp();
                                pushStream.shutdown();
                                Log.v("twitter_stream_push", "stopping push notifications");
                            } catch (Exception x) {
                                // it isn't running
                                x.printStackTrace();
                            }
                        }

                        TestPullNotificationService.shuttingDown = false;
                    }
                });

                stop.setPriority(Thread.MAX_PRIORITY);
                stop.start();

                pullUnread = 0;

                stopSelf();
            }

        }
    });

    start.setPriority(Thread.MAX_PRIORITY - 1);
    start.start();

}

From source file:com.klinker.android.twitter.ui.drawer_activities.discover.trends.SearchedTrendsActivity.java

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

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

    try {/*  w ww  . ja v a  2 s.co  m*/
        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);

    if (settings.advanceWindowed) {
        setUpWindow();
    }

    Utils.setUpPopupTheme(context, settings);

    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.search));

    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));
        }
    }

    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());

    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
            final int lastItem = firstVisibleItem + visibleItemCount;
            if (lastItem == totalItemCount && canRefresh) {
                getMore();
            }
        }
    });

    spinner = (LinearLayout) findViewById(R.id.list_progress);
    spinner.setVisibility(View.GONE);

    Intent intent = getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

    }

    handleIntent(getIntent());

    Utils.setActionBar(context);

}

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

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

    if (TalonPullNotificationService.isRunning) {
        stopSelf();//from   www. j ava2  s.c o  m
        return;
    }

    TalonPullNotificationService.isRunning = true;

    settings = AppSettings.getInstance(this);

    mCache = App.getInstance(this).getBitmapCache();

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

    pullUnread = sharedPreferences.getInt("pull_unread", 0);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    Intent stop = new Intent(this, StopPull.class);
    PendingIntent stopPending = PendingIntent.getService(this, 0, stop, 0);

    Intent popup = new Intent(this, RedirectToPopup.class);
    popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    popup.putExtra("from_notification", true);
    PendingIntent popupPending = PendingIntent.getActivity(this, 0, popup, 0);

    Intent compose = new Intent(this, WidgetCompose.class);
    popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent composePending = PendingIntent.getActivity(this, 0, compose, 0);

    String text;

    int count = 0;

    if (sharedPreferences.getBoolean("is_logged_in_1", false)) {
        count++;
    }
    if (sharedPreferences.getBoolean("is_logged_in_2", false)) {
        count++;
    }

    boolean multAcc = false;
    if (count == 2) {
        multAcc = true;
    }

    if (settings.liveStreaming && settings.timelineNot) {
        text = getResources().getString(R.string.new_tweets_upper) + ": " + pullUnread;
    } else {
        text = getResources().getString(R.string.listening_for_mentions) + "...";
    }

    mBuilder = new NotificationCompat.Builder(this).setSmallIcon(android.R.color.transparent)
            .setContentTitle(getResources().getString(R.string.talon_pull)
                    + (multAcc ? " - @" + settings.myScreenName : ""))
            .setContentText(text).setOngoing(true)
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_icon));

    if (getApplicationContext().getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.addAction(R.drawable.ic_cancel_dark,
                getApplicationContext().getResources().getString(R.string.stop), stopPending);
        mBuilder.addAction(R.drawable.ic_popup, getResources().getString(R.string.popup), popupPending);
        mBuilder.addAction(R.drawable.ic_send_dark, getResources().getString(R.string.tweet), composePending);
    }

    try {
        mBuilder.setWhen(0);
    } catch (Exception e) {
    }

    mBuilder.setContentIntent(pendingIntent);

    // priority flag is only available on api level 16 and above
    if (getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setPriority(Notification.PRIORITY_MIN);
    }

    mContext = getApplicationContext();

    IntentFilter filter = new IntentFilter();
    filter.addAction("com.klinker.android.twitter.STOP_PUSH");
    registerReceiver(stopPush, filter);

    filter = new IntentFilter();
    filter.addAction("com.klinker.android.twitter.START_PUSH");
    registerReceiver(startPush, filter);

    filter = new IntentFilter();
    filter.addAction("com.klinker.android.twitter.STOP_PUSH_SERVICE");
    registerReceiver(stopService, filter);

    if (settings.liveStreaming && settings.timelineNot) {
        filter = new IntentFilter();
        filter.addAction("com.klinker.android.twitter.UPDATE_NOTIF");
        registerReceiver(updateNotification, filter);

        filter = new IntentFilter();
        filter.addAction("com.klinker.android.twitter.NEW_TWEET");
        registerReceiver(updateNotification, filter);

        filter = new IntentFilter();
        filter.addAction("com.klinker.android.twitter.CLEAR_PULL_UNREAD");
        registerReceiver(clearPullUnread, filter);
    }

    Thread start = new Thread(new Runnable() {
        @Override
        public void run() {
            // get the ids of everyone you follow
            try {
                Log.v("getting_ids", "started getting ids, mine: " + settings.myId);
                Twitter twitter = Utils.getTwitter(mContext, settings);
                long currCursor = -1;
                IDs idObject;
                int rep = 0;

                do {
                    idObject = twitter.getFriendsIDs(settings.myId, currCursor);

                    long[] lIds = idObject.getIDs();
                    ids = new ArrayList<Long>();
                    for (int i = 0; i < lIds.length; i++) {
                        ids.add(lIds[i]);
                    }

                    rep++;
                } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3);

                ids.add(settings.myId);

                idsLoaded = true;

                startForeground(FOREGROUND_SERVICE_ID, mBuilder.build());

                mContext.sendBroadcast(new Intent("com.klinker.android.twitter.START_PUSH"));
            } catch (Exception e) {
                e.printStackTrace();
                TalonPullNotificationService.isRunning = false;

                pullUnread = 0;

                Thread stop = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        TalonPullNotificationService.shuttingDown = true;
                        try {
                            //pushStream.removeListener(userStream);
                        } catch (Exception x) {

                        }
                        try {
                            pushStream.cleanUp();
                            pushStream.shutdown();
                            Log.v("twitter_stream_push", "stopping push notifications");
                        } catch (Exception e) {
                            // it isn't running
                            e.printStackTrace();
                            // try twice to shut it down i guess
                            try {
                                Thread.sleep(2000);
                                pushStream.cleanUp();
                                pushStream.shutdown();
                                Log.v("twitter_stream_push", "stopping push notifications");
                            } catch (Exception x) {
                                // it isn't running
                                x.printStackTrace();
                            }
                        }

                        TalonPullNotificationService.shuttingDown = false;
                    }
                });

                stop.setPriority(Thread.MAX_PRIORITY);
                stop.start();

                stopSelf();
            } catch (OutOfMemoryError e) {
                TalonPullNotificationService.isRunning = false;

                Thread stop = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        TalonPullNotificationService.shuttingDown = true;
                        try {
                            //pushStream.removeListener(userStream);
                        } catch (Exception x) {

                        }
                        try {
                            pushStream.cleanUp();
                            pushStream.shutdown();
                            Log.v("twitter_stream_push", "stopping push notifications");
                        } catch (Exception e) {
                            // it isn't running
                            e.printStackTrace();
                            // try twice to shut it down i guess
                            try {
                                Thread.sleep(2000);
                                pushStream.cleanUp();
                                pushStream.shutdown();
                                Log.v("twitter_stream_push", "stopping push notifications");
                            } catch (Exception x) {
                                // it isn't running
                                x.printStackTrace();
                            }
                        }

                        TalonPullNotificationService.shuttingDown = false;
                    }
                });

                stop.setPriority(Thread.MAX_PRIORITY);
                stop.start();

                pullUnread = 0;

                stopSelf();
            }

        }
    });

    start.setPriority(Thread.MAX_PRIORITY - 1);
    start.start();

}

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

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

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

    if (!file.exists()) {
        InputStream in = null;//from  w w w.  j a  v  a  2  s  . c  om
        OutputStream out = null;
        try {
            in = assetManager.open(gplv3FileName);
            /* 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);
                Log.d("tag", "Read and wrote " + read + " bytes.");
            }
            in.close();
            out.flush();
            out.close();
        } catch (IOException e) {
            Log.e("tag", e.getMessage());
        }
    } else {
        //Log.d("tag", gplv3FileName+" already exists.");
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getActivity().getFilesDir() + "/" + gplv3FileName),
            "text/plain");
    startActivity(intent);
}

From source file:com.mobshep.mobileshepherd.UDataLeakage.java

private void logDetails(String content) {
    // TODO Auto-generated method stub
    Date date = new Date();

    String filename = "LogFile" + date.toString();
    String EOL = System.getProperty("line.seperator");
    BufferedWriter writer = null;
    try {//  w w w  .  j  av  a 2  s  .  c o  m
        writer = new BufferedWriter(
                new OutputStreamWriter(openFileOutput(filename, Context.MODE_WORLD_READABLE)));
        writer.write(content + EOL);
        writer.write(date + EOL);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}