第一次提交

This commit is contained in:
被淹死的鱼
2026-03-11 18:26:29 +08:00
commit cd3b53759e
8532 changed files with 522078 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.fengliyan.storage;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.caivideo.storage.test", appContext.getPackageName());
}
}

View File

@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fengliyan.storage" />

View File

@@ -0,0 +1,89 @@
package com.fengliyan.storage;
import android.content.Context;
import android.content.SharedPreferences;
import com.google.gson.Gson;
import java.lang.reflect.Type;
/**
* Created by abby on 2016/12/12.
*/
public class StorageManager {
private static StorageManager mInstance;
private SharedPreferences mSharedPreferences;
private Context mContext;
public static StorageManager getInstance(Context context) {
if (null == mInstance) {
mInstance = new StorageManager(context);
}
return mInstance;
}
private StorageManager(Context context) {
mContext = context;
mSharedPreferences = mContext.getSharedPreferences("MaleSocialBase", Context.MODE_PRIVATE);
}
public StorageManager getStorage(String name) {
mSharedPreferences = mContext.getSharedPreferences(name, Context.MODE_PRIVATE);
return this;
}
public void putString(String name, String data) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putString(name, data);
editor.commit();
}
public void putBean(String name, Object object) {
Gson gson = new Gson();
String toJson = gson.toJson(object);
putString(name, toJson);
}
public Object getBean(String name, Type classType) {
Gson gson = new Gson();
String fromJson = getString(name);
return gson.fromJson(fromJson, classType);
}
public String getString(String name) {
return mSharedPreferences.getString(name, null);
}
public void putInt(String name, int data) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(name, data);
editor.commit();
}
public int getInt(String name) {
return mSharedPreferences.getInt(name, -1);
}
public int getInt(String name, int def) {
return mSharedPreferences.getInt(name, def);
}
public void clear() {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.clear();
editor.commit();
}
public void putBoolean(String name, boolean data) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(name, data);
editor.commit();
}
public boolean getBoolean(String name, boolean dev) {
return mSharedPreferences.getBoolean(name, dev);
}
}

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Storage</string>
</resources>

View File

@@ -0,0 +1,17 @@
package com.fengliyan.storage;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}