init commit
This commit is contained in:
39
Extensions/ISharedPreferencesEditor.cs
Normal file
39
Extensions/ISharedPreferencesEditor.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
|
||||
namespace SharedSettingsAbstraction.Extensions
|
||||
{
|
||||
public static class AndroidExtensions
|
||||
{
|
||||
public static void SaveObject ( this ISharedPreferencesEditor ed, string key, object value)
|
||||
{
|
||||
var refType = value.GetType();
|
||||
|
||||
if (refType == typeof(string))
|
||||
{
|
||||
ed.PutString(key,(String)value);
|
||||
}
|
||||
if (refType == typeof(bool))
|
||||
{
|
||||
ed.PutBoolean(key, (bool)value);
|
||||
}
|
||||
if (refType == typeof(int))
|
||||
{
|
||||
ed.PutInt(key, (int)value);
|
||||
}
|
||||
if (refType == typeof(float))
|
||||
{
|
||||
ed.PutFloat(key, (float)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Properties/AssemblyInfo.cs
Normal file
34
Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Android.App;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SharedSettingsAbstraction")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SharedSettingsAbstraction")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
// Add some common permissions, these can be removed if not needed
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
|
||||
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
|
||||
50
Resources/AboutResources.txt
Normal file
50
Resources/AboutResources.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
Images, layout descriptions, binary blobs and string dictionaries can be included
|
||||
in your application as resource files. Various Android APIs are designed to
|
||||
operate on the resource IDs instead of dealing with images, strings or binary blobs
|
||||
directly.
|
||||
|
||||
For example, a sample Android app that contains a user interface layout (main.xml),
|
||||
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
|
||||
would keep its resources in the "Resources" directory of the application:
|
||||
|
||||
Resources/
|
||||
drawable-hdpi/
|
||||
icon.png
|
||||
|
||||
drawable-ldpi/
|
||||
icon.png
|
||||
|
||||
drawable-mdpi/
|
||||
icon.png
|
||||
|
||||
layout/
|
||||
main.xml
|
||||
|
||||
values/
|
||||
strings.xml
|
||||
|
||||
In order to get the build system to recognize Android resources, set the build action to
|
||||
"AndroidResource". The native Android APIs do not operate directly with filenames, but
|
||||
instead operate on resource IDs. When you compile an Android application that uses resources,
|
||||
the build system will package the resources for distribution and generate a class called
|
||||
"Resource" that contains the tokens for each one of the resources included. For example,
|
||||
for the above Resources layout, this is what the Resource class would expose:
|
||||
|
||||
public class Resource {
|
||||
public class drawable {
|
||||
public const int icon = 0x123;
|
||||
}
|
||||
|
||||
public class layout {
|
||||
public const int main = 0x456;
|
||||
}
|
||||
|
||||
public class strings {
|
||||
public const int first_string = 0xabc;
|
||||
public const int second_string = 0xbcd;
|
||||
}
|
||||
}
|
||||
|
||||
You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
|
||||
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
|
||||
string in the dictionary file values/strings.xml.
|
||||
73
Resources/Resource.Designer.cs
generated
Normal file
73
Resources/Resource.Designer.cs
generated
Normal file
@@ -0,0 +1,73 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:2.0.50727.4952
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SharedSettingsAbstraction
|
||||
{
|
||||
|
||||
|
||||
public partial class Resource
|
||||
{
|
||||
|
||||
public partial class Attribute
|
||||
{
|
||||
|
||||
private Attribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Drawable
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f020000
|
||||
public const int Icon = 2130837504;
|
||||
|
||||
private Drawable()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Id
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f050000
|
||||
public const int MyButton = 2131034112;
|
||||
|
||||
private Id()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Layout
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f030000
|
||||
public const int Main = 2130903040;
|
||||
|
||||
private Layout()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public partial class String
|
||||
{
|
||||
|
||||
// aapt resource value: 0x7f040001
|
||||
public const int ApplicationName = 2130968577;
|
||||
|
||||
// aapt resource value: 0x7f040000
|
||||
public const int Hello = 2130968576;
|
||||
|
||||
private String()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
Resources/Values/Strings.xml
Normal file
5
Resources/Values/Strings.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="Hello">Hello World, Click Me!</string>
|
||||
<string name="ApplicationName">$projectname$</string>
|
||||
</resources>
|
||||
14
Setting/CastingSettingException.cs
Normal file
14
Setting/CastingSettingException.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace GravatarSyncro.Android.Client.Setting
|
||||
{
|
||||
class CastingSettingException : Exception
|
||||
{
|
||||
public CastingSettingException()
|
||||
: base("Error Casting Settings") { }
|
||||
}
|
||||
|
||||
}
|
||||
76
Setting/SettingsKey.cs
Normal file
76
Setting/SettingsKey.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Runtime;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using SharedSettingsAbstraction.Extensions;
|
||||
|
||||
namespace SharedSettingsAbstraction.Setting
|
||||
{
|
||||
/// <summary>
|
||||
/// Key Value Pair
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Value Type</typeparam>
|
||||
public class SettingsKey<T>
|
||||
{
|
||||
public string key { get; private set; }
|
||||
public T value { private get; private set; }
|
||||
public string Description { get; set; }
|
||||
public string Title { get; set; }
|
||||
private string _preferenceName;
|
||||
private T _defaultValue;
|
||||
public List<string> SpinnerOptions { get; set; }
|
||||
/// <summary>
|
||||
/// Setup key
|
||||
/// </summary>
|
||||
/// <param name="_key"></param>
|
||||
public SettingsKey(string _key, string preferenceName, T defaultValue)
|
||||
{
|
||||
key = _key;
|
||||
_preferenceName = preferenceName;
|
||||
_defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Setting, if it cannot find it or cast properly it will return default setting
|
||||
/// </summary>
|
||||
/// <param name="con">Context</param>
|
||||
/// <returns>SettingsKey<T></returns>
|
||||
public SettingsKey<T> getSetting(Context con )
|
||||
{
|
||||
var shared = con.GetSharedPreferences(_preferenceName, FileCreationMode.WorldReadable);
|
||||
try
|
||||
{
|
||||
value = (T)shared.All.Where(x => x.Key == key).FirstOrDefault().Value;
|
||||
if (value == null) SetSetting(con, _defaultValue);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
value = (T)_defaultValue;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// Set the setting with a new setting
|
||||
/// </summary>
|
||||
/// <param name="con"></param>
|
||||
/// <param name="val"></param>
|
||||
/// <returns></returns>
|
||||
public SettingsKey<T> SetSetting(Context con, T val)
|
||||
{
|
||||
var shared = con.GetSharedPreferences(_preferenceName, FileCreationMode.WorldWriteable);
|
||||
var edit = shared.Edit();
|
||||
edit.SaveObject(key, val);
|
||||
edit.Commit();
|
||||
value = val;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
64
SharedSettingsAbstraction.csproj
Normal file
64
SharedSettingsAbstraction.csproj
Normal file
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F8507427-451B-4B55-A5B5-52F1151324B3}</ProjectGuid>
|
||||
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SharedSettingsAbstraction</RootNamespace>
|
||||
<AssemblyName>SharedSettingsAbstraction</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
|
||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Mono.Android" />
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions\ISharedPreferencesEditor.cs" />
|
||||
<Compile Include="Resources\Resource.Designer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Setting\CastingSettingException.cs" />
|
||||
<Compile Include="Setting\SettingsKey.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\AboutResources.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\Values\Strings.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Reference in New Issue
Block a user