From da1f1aac7ae50b3609f44ebf7cf28dea0096bdcc Mon Sep 17 00:00:00 2001 From: michal_szwarc Date: Tue, 24 Mar 2015 06:56:31 +0100 Subject: [PATCH] Add new demo examples. Extra frames to add own content i preferences activity. --- library/src/main/AndroidManifest.xml | 4 +- .../materialsettings/MaterialSettings.java | 95 ++++++++++++++++++- .../MaterialSettingsItem.java | 17 +++- .../materialsettings/items/CheckboxItem.java | 15 ++- .../materialsettings/items/DividerItem.java | 8 +- .../materialsettings/items/HeaderItem.java | 8 +- .../materialsettings/items/SwitcherItem.java | 5 +- .../materialsettings/items/TextItem.java | 12 ++- .../storage/PreferencesStorageInterface.java | 12 ++- .../storage/SimpleStorageInterface.java | 14 ++- .../storage/StorageInterface.java | 8 +- .../views/CheckableLinearLayout.java | 2 +- .../src/main/res/layout/activity_settings.xml | 39 ++++++-- sampleapp/src/main/AndroidManifest.xml | 33 ++++--- .../wt/sampleapp/InflatingViewsActivity.java | 53 +++++++++++ .../java/com/wt/sampleapp/MainActivity.java | 10 +- .../java/com/wt/sampleapp/SampleDialog.java | 3 - .../com/wt/sampleapp/Settings1Activity.java | 12 +-- .../com/wt/sampleapp/Settings2Activity.java | 14 --- .../com/wt/sampleapp/Settings4Activity.java | 26 +++++ .../res/layout/activity_inflating_views.xml | 28 ++++++ .../src/main/res/layout/activity_main.xml | 21 +++- .../main/res/menu/menu_inflating_views.xml | 9 ++ .../src/main/res/values-w820dp/dimens.xml | 6 ++ sampleapp/src/main/res/values/strings.xml | 2 + 25 files changed, 376 insertions(+), 80 deletions(-) create mode 100644 sampleapp/src/main/java/com/wt/sampleapp/InflatingViewsActivity.java create mode 100644 sampleapp/src/main/java/com/wt/sampleapp/Settings4Activity.java create mode 100644 sampleapp/src/main/res/layout/activity_inflating_views.xml create mode 100644 sampleapp/src/main/res/menu/menu_inflating_views.xml create mode 100644 sampleapp/src/main/res/values-w820dp/dimens.xml diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 29e4796..af2d11a 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/library/src/main/java/com/kenumir/materialsettings/MaterialSettings.java b/library/src/main/java/com/kenumir/materialsettings/MaterialSettings.java index a7c68f5..07c48b7 100644 --- a/library/src/main/java/com/kenumir/materialsettings/MaterialSettings.java +++ b/library/src/main/java/com/kenumir/materialsettings/MaterialSettings.java @@ -1,39 +1,130 @@ package com.kenumir.materialsettings; import android.os.Bundle; -import android.os.PersistableBundle; import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.Toolbar; import android.view.View; +import android.widget.FrameLayout; import android.widget.LinearLayout; +import com.kenumir.materialsettings.storage.SimpleStorageInterface; import com.kenumir.materialsettings.storage.StorageInterface; import java.util.HashMap; +import java.util.Map; /** * Created by Kenumir on 2015-03-15. */ public abstract class MaterialSettings extends ActionBarActivity { + public static enum ContentFrames { + FRAME_TOP(0), + FRAME_TOP_INSIDE(1), + FRAME_BOTTOM(2), + FRAME_BOTTOM_INSIDE(3); + + private int id; + + ContentFrames(int idx) { + id = idx; + } + public int getValue() { + return this.id; + } + } + + private static String SAVE_PREFIX = "SSI_"; + private LinearLayout material_settings_content; private Toolbar toolbar; private StorageInterface mStorageInterface; private HashMap items; + private FrameLayout[] frames; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); - items = new HashMap(); + items = new HashMap<>(); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); material_settings_content = (LinearLayout) findViewById(R.id.material_settings_content); + frames = new FrameLayout[4]; + frames[0] = (FrameLayout) findViewById(R.id.material_settings_top_frame); + frames[1] = (FrameLayout) findViewById(R.id.material_settings_top_frame_inside); + frames[2] = (FrameLayout) findViewById(R.id.material_settings_bottom_frame_inside); + frames[3] = (FrameLayout) findViewById(R.id.material_settings_bottom_frame); mStorageInterface = initStorageInterface(); + + if (savedInstanceState != null) { + for(String key : savedInstanceState.keySet()) { + if (key.startsWith(SAVE_PREFIX)) { + String keyName = key.substring(SAVE_PREFIX.length()); + Object value = savedInstanceState.get(key); + //Log.i("tests", "k: " + key + " k2: " + keyName +", t=" + value.getClass().getName() + ", v=" + value); + if (value instanceof String) { + mStorageInterface.save(keyName, (String) value); + } else if (value instanceof Integer) { + mStorageInterface.save(keyName, (Integer) value); + } else if (value instanceof Float) { + mStorageInterface.save(keyName, (Float) value); + } else if (value instanceof Long) { + mStorageInterface.save(keyName, (Long) value); + } else if (value instanceof Boolean) { + mStorageInterface.save(keyName, (Boolean) value); + } else { + mStorageInterface.save(keyName, value.toString()); + } + } + } + } + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + StorageInterface si = getStorageInterface(); + if (si instanceof SimpleStorageInterface) { + saveAll(); + Map all = ((SimpleStorageInterface) si).getAll(); + if (all.size() > 0) { + // save to bundle + for(String key : all.keySet()) { + Object value = all.get(key); + if (value instanceof String) { + outState.putString(SAVE_PREFIX + key, (String) value); + } else if (value instanceof Integer) { + outState.putInt(SAVE_PREFIX + key, (Integer) value); + } else if (value instanceof Float) { + outState.putFloat(SAVE_PREFIX + key, (Float) value); + } else if (value instanceof Long) { + outState.putString(SAVE_PREFIX + key, (String) value); + } else if (value instanceof Boolean) { + outState.putBoolean(SAVE_PREFIX + key, (Boolean) value); + } else { + outState.putString(SAVE_PREFIX + key, value.toString()); + } + } + } + } + super.onSaveInstanceState(outState); + } + + public FrameLayout getContentFrame(ContentFrames frame) { + return frames[frame.getValue()]; + } + + /** + * save all settings values at StorageInterface + */ + public void saveAll() { + for(String key : items.keySet()) { + items.get(key).save(); + } } public void addItem(MaterialSettingsItem item) { diff --git a/library/src/main/java/com/kenumir/materialsettings/MaterialSettingsItem.java b/library/src/main/java/com/kenumir/materialsettings/MaterialSettingsItem.java index 2aaaef6..d3f0843 100644 --- a/library/src/main/java/com/kenumir/materialsettings/MaterialSettingsItem.java +++ b/library/src/main/java/com/kenumir/materialsettings/MaterialSettingsItem.java @@ -12,11 +12,14 @@ */ public abstract class MaterialSettingsItem { - protected MaterialSettings mContext; + protected Context mContext; + protected MaterialSettings mMaterialSettings; protected String name; - public MaterialSettingsItem(MaterialSettings ctx, String name) { + public MaterialSettingsItem(Context ctx, String name) { this.mContext = ctx; + if (ctx instanceof MaterialSettings) + this.mMaterialSettings = (MaterialSettings) ctx; this.name = name; } @@ -37,11 +40,19 @@ public View getView(ViewGroup parent) { return null; } + public void setMaterialSettings(MaterialSettings m) { + mMaterialSettings = m; + } + public StorageInterface getStorageInterface() { - return mContext.getStorageInterface(); + if (mMaterialSettings != null) + return mMaterialSettings.getStorageInterface(); + else + return null; } public abstract int getViewResource(); public abstract void setupView(View v); + public abstract void save(); } diff --git a/library/src/main/java/com/kenumir/materialsettings/items/CheckboxItem.java b/library/src/main/java/com/kenumir/materialsettings/items/CheckboxItem.java index ee1d390..b1ec41d 100644 --- a/library/src/main/java/com/kenumir/materialsettings/items/CheckboxItem.java +++ b/library/src/main/java/com/kenumir/materialsettings/items/CheckboxItem.java @@ -5,7 +5,6 @@ import android.widget.CompoundButton; import android.widget.TextView; -import com.kenumir.materialsettings.MaterialSettings; import com.kenumir.materialsettings.MaterialSettingsItem; import com.kenumir.materialsettings.R; import com.kenumir.materialsettings.views.CheckableLinearLayout; @@ -25,7 +24,7 @@ public static interface OnCheckedChangeListener { private CheckableLinearLayout mCheckableLinearLayout; private OnCheckedChangeListener mOnCheckedChangeListener; - public CheckboxItem(MaterialSettings ctx, String name) { + public CheckboxItem(Context ctx, String name) { super(ctx, name); } @@ -36,7 +35,8 @@ public int getViewResource() { @Override public void setupView(View v) { - checked = getStorageInterface().load(name, isDefaultValue()); + + checked = getStorageInterface() != null ? getStorageInterface().load(name, isDefaultValue()) : isDefaultValue(); mCheckableLinearLayout = (CheckableLinearLayout) v; titleView = (TextView) v.findViewById(R.id.material_dialog_item_title); subtitleView = (TextView) v.findViewById(R.id.material_dialog_item_subtitle); @@ -49,13 +49,19 @@ public void setupView(View v) { mCheckableLinearLayout.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mContext.getStorageInterface().save(name, isChecked); + save(); if (getOnCheckedChangeListener() != null) getOnCheckedChangeListener().onCheckedChange(CheckboxItem.this, isChecked); } }); } + @Override + public void save() { + if (getStorageInterface() != null) + getStorageInterface().save(name, isChecked()); + } + public CheckboxItem updateTitle(String newTitle) { if (titleView != null) titleView.setText(newTitle); @@ -89,6 +95,7 @@ public CheckboxItem setSubtitle(String subtitle) { } public boolean isChecked() { + //Log.d("tests", "C: " + name + "=" + mCheckableLinearLayout.isChecked()); return mCheckableLinearLayout.isChecked(); } diff --git a/library/src/main/java/com/kenumir/materialsettings/items/DividerItem.java b/library/src/main/java/com/kenumir/materialsettings/items/DividerItem.java index d3aac78..a38c424 100644 --- a/library/src/main/java/com/kenumir/materialsettings/items/DividerItem.java +++ b/library/src/main/java/com/kenumir/materialsettings/items/DividerItem.java @@ -3,7 +3,6 @@ import android.content.Context; import android.view.View; -import com.kenumir.materialsettings.MaterialSettings; import com.kenumir.materialsettings.MaterialSettingsItem; import com.kenumir.materialsettings.R; @@ -12,7 +11,7 @@ */ public class DividerItem extends MaterialSettingsItem { - public DividerItem(MaterialSettings ctx) { + public DividerItem(Context ctx) { super(ctx, null); } @@ -25,4 +24,9 @@ public int getViewResource() { public void setupView(View v) { } + + @Override + public void save() { + // NOP + } } diff --git a/library/src/main/java/com/kenumir/materialsettings/items/HeaderItem.java b/library/src/main/java/com/kenumir/materialsettings/items/HeaderItem.java index 6901804..1a9e977 100644 --- a/library/src/main/java/com/kenumir/materialsettings/items/HeaderItem.java +++ b/library/src/main/java/com/kenumir/materialsettings/items/HeaderItem.java @@ -4,7 +4,6 @@ import android.view.View; import android.widget.TextView; -import com.kenumir.materialsettings.MaterialSettings; import com.kenumir.materialsettings.MaterialSettingsItem; import com.kenumir.materialsettings.R; @@ -15,7 +14,7 @@ public class HeaderItem extends MaterialSettingsItem { private String title; - public HeaderItem(MaterialSettings ctx) { + public HeaderItem(Context ctx) { super(ctx, null); } @@ -29,6 +28,11 @@ public void setupView(View v) { ((TextView) v).setText(title); } + @Override + public void save() { + // NOP + } + public String getTitle() { return title; } diff --git a/library/src/main/java/com/kenumir/materialsettings/items/SwitcherItem.java b/library/src/main/java/com/kenumir/materialsettings/items/SwitcherItem.java index fde738f..1c65105 100644 --- a/library/src/main/java/com/kenumir/materialsettings/items/SwitcherItem.java +++ b/library/src/main/java/com/kenumir/materialsettings/items/SwitcherItem.java @@ -1,6 +1,7 @@ package com.kenumir.materialsettings.items; -import com.kenumir.materialsettings.MaterialSettings; +import android.content.Context; + import com.kenumir.materialsettings.R; /** @@ -8,7 +9,7 @@ */ public class SwitcherItem extends CheckboxItem { - public SwitcherItem(MaterialSettings ctx, String name) { + public SwitcherItem(Context ctx, String name) { super(ctx, name); } diff --git a/library/src/main/java/com/kenumir/materialsettings/items/TextItem.java b/library/src/main/java/com/kenumir/materialsettings/items/TextItem.java index 0c8a048..0fe003e 100644 --- a/library/src/main/java/com/kenumir/materialsettings/items/TextItem.java +++ b/library/src/main/java/com/kenumir/materialsettings/items/TextItem.java @@ -1,14 +1,11 @@ package com.kenumir.materialsettings.items; +import android.content.Context; import android.view.View; -import android.widget.CompoundButton; -import android.widget.LinearLayout; import android.widget.TextView; -import com.kenumir.materialsettings.MaterialSettings; import com.kenumir.materialsettings.MaterialSettingsItem; import com.kenumir.materialsettings.R; -import com.kenumir.materialsettings.views.CheckableLinearLayout; /** * Created by Kenumir on 2015-03-16. @@ -24,7 +21,7 @@ public static interface OnClickListener { private OnClickListener onclick; private TextView titleView, subtitleView; - public TextItem(MaterialSettings ctx, String name) { + public TextItem(Context ctx, String name) { super(ctx, name); } @@ -50,6 +47,11 @@ public void onClick(View v) { }); } + @Override + public void save() { + // NOP + } + public TextItem updateTitle(String newTitle) { if (titleView != null) titleView.setText(newTitle); diff --git a/library/src/main/java/com/kenumir/materialsettings/storage/PreferencesStorageInterface.java b/library/src/main/java/com/kenumir/materialsettings/storage/PreferencesStorageInterface.java index 2ba8d16..f1b8107 100644 --- a/library/src/main/java/com/kenumir/materialsettings/storage/PreferencesStorageInterface.java +++ b/library/src/main/java/com/kenumir/materialsettings/storage/PreferencesStorageInterface.java @@ -3,6 +3,8 @@ import android.content.Context; import android.content.SharedPreferences; +import java.util.Map; + /** * Created by Kenumir on 2015-03-18. */ @@ -15,12 +17,12 @@ public PreferencesStorageInterface(Context ctx) { } @Override - public void save(String key, boolean value) { + public void save(String key, Boolean value) { prefs.edit().putBoolean(key, value).apply(); } @Override - public boolean load(String key, boolean defaultValue) { + public boolean load(String key, Boolean defaultValue) { return prefs.getBoolean(key, defaultValue); } @@ -63,4 +65,10 @@ public void save(String key, Long value) { public Long load(String key, Long defaultValue) { return prefs.getLong(key, defaultValue); } + + @Override + public Map getAll() { + + return prefs.getAll(); + } } diff --git a/library/src/main/java/com/kenumir/materialsettings/storage/SimpleStorageInterface.java b/library/src/main/java/com/kenumir/materialsettings/storage/SimpleStorageInterface.java index 6718b3b..adc0fd3 100644 --- a/library/src/main/java/com/kenumir/materialsettings/storage/SimpleStorageInterface.java +++ b/library/src/main/java/com/kenumir/materialsettings/storage/SimpleStorageInterface.java @@ -1,25 +1,31 @@ package com.kenumir.materialsettings.storage; import java.util.HashMap; +import java.util.Map; /** * Created by Kenumir on 2015-03-16. */ public class SimpleStorageInterface extends StorageInterface { - private HashMap mem; + private HashMap mem = new HashMap<>(); public SimpleStorageInterface() { - mem = new HashMap(); + + } + + @Override + public Map getAll() { + return mem; } @Override - public void save(String key, boolean value) { + public void save(String key, Boolean value) { mem.put(key, Boolean.valueOf(value)); } @Override - public boolean load(String key, boolean defaultValue) { + public boolean load(String key, Boolean defaultValue) { if (mem.containsKey(key)) return (boolean) mem.get(key); return defaultValue; diff --git a/library/src/main/java/com/kenumir/materialsettings/storage/StorageInterface.java b/library/src/main/java/com/kenumir/materialsettings/storage/StorageInterface.java index 453ca04..33f35de 100644 --- a/library/src/main/java/com/kenumir/materialsettings/storage/StorageInterface.java +++ b/library/src/main/java/com/kenumir/materialsettings/storage/StorageInterface.java @@ -1,5 +1,7 @@ package com.kenumir.materialsettings.storage; +import java.util.Map; + /** * Created by Kenumir on 2015-03-16. */ @@ -7,8 +9,8 @@ public abstract class StorageInterface { public StorageInterface() {} - public abstract void save(String key, boolean value); - public abstract boolean load(String key, boolean defaultValue); + public abstract void save(String key, Boolean value); + public abstract boolean load(String key, Boolean defaultValue); public abstract void save(String key, String value); public abstract String load(String key, String defaultValue); @@ -22,4 +24,6 @@ public StorageInterface() {} public abstract void save(String key, Long value); public abstract Long load(String key, Long defaultValue); + public abstract Map getAll(); + } diff --git a/library/src/main/java/com/kenumir/materialsettings/views/CheckableLinearLayout.java b/library/src/main/java/com/kenumir/materialsettings/views/CheckableLinearLayout.java index b8695d1..d69a98d 100644 --- a/library/src/main/java/com/kenumir/materialsettings/views/CheckableLinearLayout.java +++ b/library/src/main/java/com/kenumir/materialsettings/views/CheckableLinearLayout.java @@ -83,7 +83,7 @@ public void setChecked(boolean checked) { refreshDrawableState(); - //Propagate to childs + //Propagate to child's final int count = getChildCount(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); diff --git a/library/src/main/res/layout/activity_settings.xml b/library/src/main/res/layout/activity_settings.xml index ade1071..787acd7 100644 --- a/library/src/main/res/layout/activity_settings.xml +++ b/library/src/main/res/layout/activity_settings.xml @@ -14,20 +14,47 @@ app:theme="?attr/msToolbarTheme" app:popupTheme="?attr/msToolbarThemePopup"/> + + + android:orientation="vertical"> + + + + + + + + + + \ No newline at end of file diff --git a/sampleapp/src/main/AndroidManifest.xml b/sampleapp/src/main/AndroidManifest.xml index 4f73417..c6b44f3 100644 --- a/sampleapp/src/main/AndroidManifest.xml +++ b/sampleapp/src/main/AndroidManifest.xml @@ -19,21 +19,28 @@ + + + + + + + + - - - - - - - diff --git a/sampleapp/src/main/java/com/wt/sampleapp/InflatingViewsActivity.java b/sampleapp/src/main/java/com/wt/sampleapp/InflatingViewsActivity.java new file mode 100644 index 0000000..806dd6c --- /dev/null +++ b/sampleapp/src/main/java/com/wt/sampleapp/InflatingViewsActivity.java @@ -0,0 +1,53 @@ +package com.wt.sampleapp; + +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.ViewGroup; + +import com.kenumir.materialsettings.items.SwitcherItem; +import com.kenumir.materialsettings.items.TextItem; + +public class InflatingViewsActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_inflating_views); + + ViewGroup content = (ViewGroup) findViewById(R.id.content); + + SwitcherItem item = new SwitcherItem(getBaseContext(), "key1"); + item.setTitle("Title of item "); + item.setSubtitle("Subtitle text"); + content.addView(item.getView(content)); + + TextItem item2 = new TextItem(getBaseContext(), "key2"); + item2.setTitle("Title of item - second line"); + item2.setSubtitle("Subtitle text"); + content.addView(item2.getView(content)); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_inflating_views, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/sampleapp/src/main/java/com/wt/sampleapp/MainActivity.java b/sampleapp/src/main/java/com/wt/sampleapp/MainActivity.java index aea61d4..e971a43 100644 --- a/sampleapp/src/main/java/com/wt/sampleapp/MainActivity.java +++ b/sampleapp/src/main/java/com/wt/sampleapp/MainActivity.java @@ -1,8 +1,8 @@ package com.wt.sampleapp; import android.content.Intent; -import android.support.v7.app.ActionBarActivity; import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -27,6 +27,14 @@ public void handleSettings3(View v) { startActivity(new Intent(this, Settings3Activity.class)); } + public void handleSettings4(View v) { + startActivity(new Intent(this, Settings4Activity.class)); + } + + public void handleSettings5(View v) { + startActivity(new Intent(this, InflatingViewsActivity.class)); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. diff --git a/sampleapp/src/main/java/com/wt/sampleapp/SampleDialog.java b/sampleapp/src/main/java/com/wt/sampleapp/SampleDialog.java index 858d3f0..1ef1219 100644 --- a/sampleapp/src/main/java/com/wt/sampleapp/SampleDialog.java +++ b/sampleapp/src/main/java/com/wt/sampleapp/SampleDialog.java @@ -1,13 +1,10 @@ package com.wt.sampleapp; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; -import android.os.ResultReceiver; import android.support.v4.app.DialogFragment; -import android.util.Log; /** * Created by Kenumir on 2015-03-18. diff --git a/sampleapp/src/main/java/com/wt/sampleapp/Settings1Activity.java b/sampleapp/src/main/java/com/wt/sampleapp/Settings1Activity.java index 0717d97..ef8a5fe 100644 --- a/sampleapp/src/main/java/com/wt/sampleapp/Settings1Activity.java +++ b/sampleapp/src/main/java/com/wt/sampleapp/Settings1Activity.java @@ -1,17 +1,8 @@ package com.wt.sampleapp; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Handler; -import android.os.ResultReceiver; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; -import android.view.View; -import android.widget.CompoundButton; import android.widget.Toast; import com.kenumir.materialsettings.MaterialSettings; @@ -21,7 +12,6 @@ import com.kenumir.materialsettings.items.SwitcherItem; import com.kenumir.materialsettings.items.TextItem; import com.kenumir.materialsettings.storage.PreferencesStorageInterface; -import com.kenumir.materialsettings.storage.SimpleStorageInterface; import com.kenumir.materialsettings.storage.StorageInterface; public class Settings1Activity extends MaterialSettings implements SampleDialog.OnDialogOkClick { @@ -44,7 +34,7 @@ public void onCheckedChange(CheckboxItem cbi, boolean isChecked) { addItem(new DividerItem(this)); addItem(new CheckboxItem(this, "key2").setTitle("Checkbox item 2").setSubtitle("Subtitle text 2 with long text and more txt and more and more ;-)").setDefaultValue(true)); addItem(new DividerItem(this)); - addItem(new CheckboxItem(this, "key1").setTitle("Checkbox item 3 - no subtitle")); + addItem(new CheckboxItem(this, "key1c").setTitle("Checkbox item 3 - no subtitle")); addItem(new DividerItem(this)); addItem(new TextItem(this, "key3").setTitle("Simple text item 1").setSubtitle("Subtitle of simple text item 1").setOnclick(new TextItem.OnClickListener() { @Override diff --git a/sampleapp/src/main/java/com/wt/sampleapp/Settings2Activity.java b/sampleapp/src/main/java/com/wt/sampleapp/Settings2Activity.java index c359823..bb11623 100644 --- a/sampleapp/src/main/java/com/wt/sampleapp/Settings2Activity.java +++ b/sampleapp/src/main/java/com/wt/sampleapp/Settings2Activity.java @@ -1,19 +1,5 @@ package com.wt.sampleapp; -import android.os.Bundle; -import android.os.Handler; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.Toast; - -import com.kenumir.materialsettings.MaterialSettings; -import com.kenumir.materialsettings.items.CheckboxItem; -import com.kenumir.materialsettings.items.DividerItem; -import com.kenumir.materialsettings.items.HeaderItem; -import com.kenumir.materialsettings.items.TextItem; -import com.kenumir.materialsettings.storage.PreferencesStorageInterface; -import com.kenumir.materialsettings.storage.StorageInterface; - public class Settings2Activity extends Settings1Activity { } diff --git a/sampleapp/src/main/java/com/wt/sampleapp/Settings4Activity.java b/sampleapp/src/main/java/com/wt/sampleapp/Settings4Activity.java new file mode 100644 index 0000000..3a8c76c --- /dev/null +++ b/sampleapp/src/main/java/com/wt/sampleapp/Settings4Activity.java @@ -0,0 +1,26 @@ +package com.wt.sampleapp; + +import android.os.Bundle; +import android.widget.TextView; + +import com.kenumir.materialsettings.storage.SimpleStorageInterface; +import com.kenumir.materialsettings.storage.StorageInterface; + +public class Settings4Activity extends Settings1Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setTitle("SimpleStorage"); + + TextView t = new TextView(this); + t.setText("Simple storage saves settings in memory. When activity is rotated all data is stored in onSaveInstanceState and restored in onCreate"); + t.setPadding(20, 20, 20, 20); + getContentFrame(ContentFrames.FRAME_TOP_INSIDE).addView(t); + } + + @Override + public StorageInterface initStorageInterface() { + return new SimpleStorageInterface(); + } + +} diff --git a/sampleapp/src/main/res/layout/activity_inflating_views.xml b/sampleapp/src/main/res/layout/activity_inflating_views.xml new file mode 100644 index 0000000..ed99fc6 --- /dev/null +++ b/sampleapp/src/main/res/layout/activity_inflating_views.xml @@ -0,0 +1,28 @@ + + + + + + + + + diff --git a/sampleapp/src/main/res/layout/activity_main.xml b/sampleapp/src/main/res/layout/activity_main.xml index b01f2dd..0971296 100644 --- a/sampleapp/src/main/res/layout/activity_main.xml +++ b/sampleapp/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ +