Java Code Examples for android.support.v4.app.FragmentActivity#getSharedPreferences()
The following examples show how to use
android.support.v4.app.FragmentActivity#getSharedPreferences() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DashboardFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void saveCachedDashboardList(String rootNodeStr) throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("dashboard_list_str", rootNodeStr); editor.apply(); }
Example 2
Source File: DashboardFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private String getCachedDashboardList() throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); return sharedPreferences.getString("dashboard_list_str", null); }
Example 3
Source File: AnnouncementListFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void saveCachedAnnouncementsList(String rootNodeStr) throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("announcement_list_str", rootNodeStr); editor.apply(); }
Example 4
Source File: AnnouncementListFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private String getCachedAnnouncementsList() throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); return sharedPreferences.getString("announcement_list_str", null); }
Example 5
Source File: CourseListFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void saveCachedCourseList(String rootNodeStr) throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("course_list_str", rootNodeStr); editor.apply(); }
Example 6
Source File: CourseListFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private String getCachedCourseList() throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); return sharedPreferences.getString("course_list_str", null); }
Example 7
Source File: CourseListFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void updateAdapter(String rootNodeStr, boolean showAnimation) { Node rootNode = Utils.stringToNode(rootNodeStr); if (rootNode != null) { FragmentActivity fa = getActivity(); if (fa == null) { return; } SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedCourseList", Context.MODE_PRIVATE); Set<String> hset = sharedPreferences.getStringSet("key", null); if (hset == null) hset = new HashSet<>(); ArrayList<CourseInfo> courses_list = new ArrayList<>(); NodeList nCoursesList = rootNode.getFirstChild().getChildNodes(); for (int temp = 0; temp < nCoursesList.getLength(); temp++) { CourseInfo ci = new CourseInfo((Element) nCoursesList.item(temp)); if (hset.contains(ci.getRawCourseName())) ci.setPinned(1); courses_list.add(ci); } adapter.updateList(courses_list); // 显示课程列表的fancy的动画 if (showAnimation) mRecyclerView.scheduleLayoutAnimation(); if (showLongPressHintFlag) showLongPressHint(); } }
Example 8
Source File: AnnouncementBodyFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void saveCachedAnnouncementsList(String rootNodeStr) throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("announcement_list_str", rootNodeStr); editor.apply(); }
Example 9
Source File: AnnouncementBodyFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private String getCachedAnnouncementsList() throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); return sharedPreferences.getString("announcement_list_str", null); }
Example 10
Source File: MyGradeFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void saveCachedCourseList(String rootNodeStr) throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("course_list_str", rootNodeStr); editor.apply(); }
Example 11
Source File: MyGradeFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private String getCachedCourseList() throws Exception { FragmentActivity fa = getActivity(); if (fa == null) { throw new Exception("Unknown Error: Null getActivity()!"); } SharedPreferences sharedPreferences = fa.getSharedPreferences("cached_xml", Context.MODE_PRIVATE); return sharedPreferences.getString("course_list_str", null); }
Example 12
Source File: MyGradeFragment.java From PKUCourses with GNU General Public License v3.0 | 5 votes |
private void updateAdapter(String rootNodeStr, boolean showAnimation) { Node rootNode = Utils.stringToNode(rootNodeStr); if (rootNode != null) { FragmentActivity fa = getActivity(); if (fa == null) { return; } SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedCourseList", Context.MODE_PRIVATE); Set<String> hset = sharedPreferences.getStringSet("key", null); if (hset == null) hset = new HashSet<>(); ArrayList<CourseInfo> courses_list = new ArrayList<>(); NodeList nCoursesList = rootNode.getFirstChild().getChildNodes(); for (int temp = 0; temp < nCoursesList.getLength(); temp++) { CourseInfo ci = new CourseInfo((Element) nCoursesList.item(temp)); if (hset.contains(ci.getRawCourseName())) ci.setPinned(1); courses_list.add(ci); } adapter.updateList(courses_list); // 显示课程列表的fancy的动画 if (showAnimation) mRecyclerView.scheduleLayoutAnimation(); if (showLongPressHintFlag) showLongPressHint(); } }
Example 13
Source File: LoadWebData.java From minx with MIT License | 5 votes |
public LoadWebData(String search_url, FragmentActivity activity) { super(); this.search_url = search_url; this.activity = activity; progressViewLoading = (ProgressWheel) (activity).findViewById(R.id.progressViewLoading); title_txt = (FontText) (activity).findViewById(R.id.title_txt); body_txt = (FontText) (activity).findViewById(R.id.body_txt); btn_view_links = (Button) (activity).findViewById(R.id.btn_view_links); mainActivity=(MainActivity)activity; sharedPrefs=activity.getResources().getString(R.string.sharedPrefs); sharedPreferences=activity.getSharedPreferences(sharedPrefs, Context.MODE_PRIVATE); editor=sharedPreferences.edit(); }
Example 14
Source File: CourseListFragment.java From PKUCourses with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.fragment_course_list, container, false); // 查找xml文件中的对象并保存进Java变量 mRecyclerView = linearLayout.findViewById(R.id.recycler_courses); mCourseListSwipeContainer = linearLayout.findViewById(R.id.course_list_swipe_container); // 设置动画 LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_animation_fall_down); mCourseListSwipeContainer.setLayoutAnimation(animation); // 设置刷新的监听类为此类(监听函数onRefresh) mCourseListSwipeContainer.setOnRefreshListener(this); mCourseListSwipeContainer.setColorSchemeColors(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorAccent)); FragmentActivity fa = getActivity(); // 为了消除编译器Warning,需要判断一下是不是null,其实这基本上不可能出现null if (fa == null) { return linearLayout; } // 将读取已置顶课程列表的SharedPreferences传递给CourseListRecyclerViewAdapter SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedCourseList", Context.MODE_PRIVATE); adapter = new CourseListRecyclerViewAdapter(new ArrayList<CourseInfo>(), sharedPreferences, this); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.setAdapter(adapter); try { String cachedCourseList = getCachedCourseList(); if (cachedCourseList == null) throw new Exception(); updateAdapter(cachedCourseList, false); } catch (Exception e) { // 显示Loading的小动画,并在后台读取课程列表 showLoading(true); mLoadingTask = new CoursesLoadingTask(); mLoadingTask.execute((Void) null); } return linearLayout; }
Example 15
Source File: MyGradeFragment.java From PKUCourses with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.fragment_course_list, container, false); // 查找xml文件中的对象并保存进Java变量 mRecyclerView = linearLayout.findViewById(R.id.recycler_courses); mCourseListSwipeContainer = linearLayout.findViewById(R.id.course_list_swipe_container); // 设置动画 LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(getContext(), R.anim.layout_animation_fall_down); mCourseListSwipeContainer.setLayoutAnimation(animation); // 设置刷新的监听类为此类(监听函数onRefresh) mCourseListSwipeContainer.setOnRefreshListener(this); mCourseListSwipeContainer.setColorSchemeColors(getResources().getColor(R.color.colorPrimary), getResources().getColor(R.color.colorAccent)); FragmentActivity fa = getActivity(); // 为了消除编译器Warning,需要判断一下是不是null,其实这基本上不可能出现null if (fa == null) { return linearLayout; } // 将读取已置顶课程列表的SharedPreferences传递给CourseListRecyclerViewAdapter SharedPreferences sharedPreferences = fa.getSharedPreferences("pinnedCourseList", Context.MODE_PRIVATE); adapter = new MyGradeListRecyclerViewAdapter(new ArrayList<CourseInfo>(), sharedPreferences, this); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.setAdapter(adapter); try { String cachedCourseList = getCachedCourseList(); if (cachedCourseList == null) throw new Exception(); updateAdapter(cachedCourseList, false); } catch (Exception e) { // 显示Loading的小动画,并在后台读取课程列表 showLoading(true); mLoadingTask = new CoursesLoadingTask(); mLoadingTask.execute((Void) null); } return linearLayout; }