List of usage examples for android.content Context MODE_WORLD_WRITEABLE
int MODE_WORLD_WRITEABLE
To view the source code for android.content Context MODE_WORLD_WRITEABLE.
Click Source Link
From source file:org.cirrus.mobi.pegel.PegelFragmentsActivity.java
/** Called when the activity is first created. */ @Override/*from w w w . j a v a 2s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.fragment_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //check if we have a saved preference, then we jump to detailview already SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_WORLD_WRITEABLE); String river = settings.getString("river", ""); if (!findViewById(R.id.ListRiverFragment).isShown()) { if (this.lrf == null) { if (river.length() > 0) { //saved preferences, show details String pnr = settings.getString("pnr", ""); String mpoint = settings.getString("mpoint", ""); lrf = ListRiverFragment.getInstance(river, mpoint, pnr); showTabs(pnr, river, mpoint); } else { lrf = ListRiverFragment.getInstance(null, null, null); } if (lrf != null) getSupportFragmentManager().beginTransaction().replace(R.id.ListRiverFragment, lrf).commit(); } } this.pa = (PegelApplication) getApplication(); pa.trackPageView("/PegelFragmentsActivity"); try { this.app_ver = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { this.app_ver = "unknown"; } }
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;//www. j av a 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:org.cirrus.mobi.pegel.MeasurePointFragment.java
private void select(int position) { getListView().setItemChecked(position, true); /** save settings */ SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, Context.MODE_WORLD_WRITEABLE); SharedPreferences.Editor editor = settings.edit(); editor.putString("river", getArguments().getString("river")); editor.putString("pnr", this.entries[position].getPegelnummer()); editor.putString("mpoint", this.entries[position].getPegelname()); editor.commit();//from w w w . j a v a 2s . com if (position != mCurCheckPosition) { ((PegelFragmentsActivity) getActivity()).showDetails(this.entries[position].getPegelnummer(), getArguments().getString("river"), this.entries[position].getPegelname()); mCurCheckPosition = position; } }
From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java
private void recent() { LayoutInflater inflater = getActivity().getLayoutInflater(); SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE); for (int i = 1; i <= 5; i++) { Location location = new Location("POINT_LOCATION"); String address = prefs.getString(POINT_ADDRESS_KEY + i, ""); location.setLatitude(0);/* w w w. ja va 2 s. c o m*/ location.setLongitude(0); if (prefs.contains(POINT_LATITUDE_KEY + i)) { location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + i, 0)); } if (prefs.contains(POINT_LONGITUDE_KEY + i)) { location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + i, 0)); } LinearLayout RecentParent = (LinearLayout) V.findViewById(R.id.group_recent); View Recent = inflater.inflate(R.layout.saved_item, null); Recent.setOnClickListener(this); CharSequence name; if (!address.equals("")) { name = address; ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF); ((CompoundButton) Recent.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this); } else { name = "No Recent Alarms"; ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDD999999); Recent.findViewById(R.id.saveCB).setEnabled(false); } ((TextView) Recent.findViewById(R.id.savedLabel)).setText(name); ((TextView) Recent.findViewById(R.id.savedLabel)).setTextSize(14); Recent.findViewById(R.id.saveCB).setTag(i); Recent.setId(i); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); RecentParent.setLayoutParams(params); RecentParent.addView(Recent); } }
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 {/*from w w w. j av 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: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;/* w ww .java 2s. 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();// ww w. j a v a 2s. c o m 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:edu.ucla.cs.nopainnogame.WatchActivity.java
public void setTvTime(int newTime, String userName) { String filename = userName + "_tvtime"; FileOutputStream fos;/*from w w w . j a v a 2s .co m*/ try { fos = openFileOutput(filename, Context.MODE_WORLD_WRITEABLE); fos.write(newTime); fos.close(); } catch (FileNotFoundException fe) { System.err.println("Error: User file not found."); fe.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
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();/*from ww w .j av a 2 s.c o m*/ 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:com.daiv.android.twitter.services.TestPullNotificationService.java
@Override public void onCreate() { super.onCreate(); if (TestPullNotificationService.isRunning) { stopSelf();/* www . j a va 2s .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(); }