# PrefCompat **Repository Path**: HarmonyOS-tpc/PrefCompat ## Basic Information - **Project Name**: PrefCompat - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-09-17 - **Last Updated**: 2023-04-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## PrefCompat ## Introduction PrefCompat is a wrapper over the Preferences class in open harmony. It supports storing objects other than the standard primitives while decreasing the boiler plate code. It also enables listening for changes on specific keys on a Preferences with RxJava support. ## Usage instructions First initialize the PrefCompat library in your MainAbility class. public class MainAbility extends Ability { @Override public void onStart(Intent intent) { super.onStart(intent); Pref.init(this); super.setMainRoute(MainAbilitySlice.class.getName()); } } ``` Then, use the Pref class to store and access data in Preferences. public class MainAbilitySlice extends AbilitySlice { @Override public void onCreate(Bundle inState) { // Default Preferences Pref.putString("name", "Tushar"); Pref.putDouble("weight", 79.24); Pref.putObject("dependents", new Dependent("Radhika", 62.24)); Double weight = Pref.getDouble("weight"); Dependent mom = Pref.getObject("dependents", Dependent.class); // Named SharedPreferences can also be used Pref.from("Scores").putIntList("level_1", [60, 20, 80, 25, 30]); List scores = Pref.from("Scores").getIntList("level_1"); } } ## Installation instruction 1.For using PrefCompat module in sample app,include the below library dependency: Add the dependencies in entry/build.gradle as below : dependencies { implementation project(path: ':PrefCompat') } 2. Using the PrefCompat har, make sure to add PrefCompat.har file in the entry/libs folder and add the below dependency in build.gradle. Modify the dependencies in the entry/build.gradle file. dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) } 3. For using PrefCompat from a remote repository in separate application, add the below dependency in entry/build.gradle file. Modify entry build.gradle as below : ```gradle dependencies { implementation 'io.openharmony.tpc.thirdlib:PrefCompat:1.0.0' } ``` ## License Copyright 2015 - 2016 Tushar Acharya. Licensed under the Apache License, Version 2.0;