Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Tue Aug 08 08:49:24 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion '25.0.2'

defaultConfig {
minSdkVersion 20
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<application>

<activity
android:name="preference.internal.ListChooserActivity"
android:name="me.denley.wearpreferenceactivity.preference.internal.ListChooserActivity"
android:theme="@android:style/Theme.DeviceDefault"
/>

<activity
android:name="preference.internal.PreferenceScreenActivity"
android:name="me.denley.wearpreferenceactivity.preference.internal.PreferenceScreenActivity"
android:theme="@android:style/Theme.DeviceDefault"
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package preference;
package me.denley.wearpreferenceactivity.preference;;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.preference.PreferenceManager;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.util.AttributeSet;

import me.denley.wearpreferenceactivity.R;
import preference.internal.ListChooserActivity;
import me.denley.wearpreferenceactivity.preference.internal.ListChooserActivity;

/**
* A simple list preference type.
Expand All @@ -23,6 +24,9 @@ public class WearListPreference extends WearPreference {
private CharSequence[] entries, entryValues;
private int[] icons;
private boolean useEntryAsSummary = true;
@ColorRes
private int background;


public WearListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
Expand All @@ -40,6 +44,7 @@ public WearListPreference(Context context, AttributeSet attrs) {
TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ListPreference, 0, 0);
try {
useEntryAsSummary = array.getBoolean(R.styleable.ListPreference_wear_entryAsSummary, true);
background = array.getResourceId(R.styleable.ListPreference_wear_listBackground, -1);

if(array.hasValue(R.styleable.ListPreference_wear_entryIcons)) {
final int resId = array.getResourceId(R.styleable.ListPreference_wear_entryIcons, 0);
Expand Down Expand Up @@ -111,6 +116,8 @@ private CharSequence getCurrentEntry(@NonNull final Context context) {
getKey(),
super.getTitle(context).toString(),
super.getIcon(context),
super.getTintColor(context),
background,
entries,
entryValues,
icons,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package preference;
package me.denley.wearpreferenceactivity.preference;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import preference.internal.WearPreferenceItem;
import me.denley.wearpreferenceactivity.preference.internal.WearPreferenceItem;

/**
* This is the base class for all other preference types.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package preference;
package me.denley.wearpreferenceactivity.preference;

import android.os.Bundle;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.annotation.XmlRes;
import android.support.wearable.view.WearableListView;
Expand All @@ -10,10 +11,10 @@
import java.util.List;

import me.denley.wearpreferenceactivity.R;
import preference.internal.ListItemLayout;
import preference.internal.TitledWearActivity;
import preference.internal.WearPreferenceItem;
import preference.internal.WearPreferenceScreen;
import me.denley.wearpreferenceactivity.preference.internal.ListItemLayout;
import me.denley.wearpreferenceactivity.preference.internal.TitledWearActivity;
import me.denley.wearpreferenceactivity.preference.internal.WearPreferenceItem;
import me.denley.wearpreferenceactivity.preference.internal.WearPreferenceScreen;

/**
* An Activity that will show preferences items in a list.
Expand All @@ -24,6 +25,7 @@ public abstract class WearPreferenceActivity extends TitledWearActivity {

private WearableListView list;
private List<WearPreferenceItem> preferences = new ArrayList<>();
protected WearPreferenceScreen prefsRoot;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -46,17 +48,38 @@ protected void addPreferencesFromResource(@XmlRes int prefsResId) {
* @param parser A parser used to parse custom preference types
*/
protected void addPreferencesFromResource(@XmlRes int prefsResId, @NonNull XmlPreferenceParser parser) {
final WearPreferenceScreen prefsRoot = parser.parse(this, prefsResId);
addPreferencesFromPreferenceScreen(prefsRoot);
WearPreferenceScreen prefScr = parser.parse(this, prefsResId);
addPreferencesFromPreferenceScreen(prefScr);
}

/** DO NOT USE - For internal use only */
protected void addPreferencesFromPreferenceScreen(WearPreferenceScreen preferenceScreen){
prefsRoot = preferenceScreen;
addPreferences(preferenceScreen.getChildren());
}

private void addPreferences(List<WearPreferenceItem> newPreferences){
preferences = newPreferences;
setAdapter();
}

protected void readPreferencesFromResource(@XmlRes int prefsResId) {
XmlPreferenceParser parser = new XmlPreferenceParser();
prefsRoot = parser.parse(this, prefsResId);
preferences = prefsRoot.getChildren();
}

public void setScreenBackground(@ColorRes int color) {
if(color > 0) {
getWindow().getDecorView().setBackgroundColor(getColor(color));
}
}

public void setAdapter() {
if (prefsRoot != null && prefsRoot.getBackground() > 0) {
setScreenBackground(prefsRoot.getBackground());
}

list.setAdapter(new SettingsAdapter());

list.setClickListener(new WearableListView.ClickListener() {
Expand Down Expand Up @@ -91,4 +114,7 @@ private class SettingsAdapter extends WearableListView.Adapter {
}
}

public List<WearPreferenceItem> getPreferences() {
return preferences;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package preference;
package me.denley.wearpreferenceactivity.preference;

import android.content.Context;
import android.content.SharedPreferences;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package preference;
package me.denley.wearpreferenceactivity.preference;

import android.content.Context;
import android.content.res.XmlResourceParser;
Expand All @@ -13,7 +13,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import preference.internal.WearPreferenceScreen;
import me.denley.wearpreferenceactivity.preference.internal.WearPreferenceScreen;

/**
* Used to parse preferences xml files into an object model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package preference.internal;
package me.denley.wearpreferenceactivity.preference.internal;

import android.support.annotation.NonNull;
import android.support.wearable.view.CircledImageView;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package preference.internal;
package me.denley.wearpreferenceactivity.preference.internal;

import android.annotation.TargetApi;
import android.content.Context;
Expand All @@ -12,6 +12,7 @@

import me.denley.wearpreferenceactivity.R;


public class HeadingListView extends RelativeLayout implements WearableListView.OnScrollListener {

TextView heading;
Expand Down Expand Up @@ -44,6 +45,7 @@ public HeadingListView(final Context context, final AttributeSet attrs, final in
}

@Override public WindowInsets onApplyWindowInsets(final WindowInsets insets) {
heading.setTextColor(-1);
if(insets.isRound()) {
heading.setGravity(Gravity.CENTER_HORIZONTAL);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package preference.internal;
package me.denley.wearpreferenceactivity.preference.internal;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.wearable.view.WearableListView;
import android.view.ViewGroup;
Expand All @@ -13,15 +14,17 @@

public class ListChooserActivity extends TitledWearActivity implements WearableListView.ClickListener {

public static Intent createIntent(Context context, String key, String title, int icon,
CharSequence[] entries, CharSequence[] entryValues,
public static Intent createIntent(Context context, String key, String title, int icon, int tint,
int background, CharSequence[] entries, CharSequence[] entryValues,
int[] entryIcons,
int currentValue){

final Intent launcherIntent = new Intent(context, ListChooserActivity.class);
launcherIntent.putExtra(EXTRA_PREF_KEY, key);
launcherIntent.putExtra(EXTRA_TITLE, title);
launcherIntent.putExtra(EXTRA_ICON, icon);
launcherIntent.putExtra(EXTRA_BACKGROUND, background);
launcherIntent.putExtra(EXTRA_TINT, tint);
launcherIntent.putExtra(EXTRA_ENTRIES, entries);
launcherIntent.putExtra(EXTRA_ENTRY_VALUES, entryValues);
launcherIntent.putExtra(EXTRA_ENTRY_ICONS, entryIcons);
Expand All @@ -31,7 +34,9 @@ public static Intent createIntent(Context context, String key, String title, int

public static final String EXTRA_PREF_KEY = "key";
public static final String EXTRA_TITLE = "title";
public static final String EXTRA_BACKGROUND = "background";
public static final String EXTRA_ICON = "icon";
public static final String EXTRA_TINT = "tint";
public static final String EXTRA_ENTRIES = "entries";
public static final String EXTRA_ENTRY_VALUES = "values";
public static final String EXTRA_ENTRY_ICONS = "icons";
Expand All @@ -41,8 +46,11 @@ public static Intent createIntent(Context context, String key, String title, int

String key;
@DrawableRes private int icon;
@ColorRes
private int tint;
CharSequence[] entries;
CharSequence[] values;
@ColorRes private int background;
int[] icons;

@Override protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -52,6 +60,10 @@ public static Intent createIntent(Context context, String key, String title, int
loadIntentExtras();
checkRequiredExtras();

if(background > 0) {
getWindow().getDecorView().setBackgroundColor(getColor(background));
}

final WearableListView list = (WearableListView) findViewById(android.R.id.list);
list.setAdapter(new PreferenceEntriesAdapter());
list.scrollToPosition(getIntent().getIntExtra(EXTRA_CURRENT_VALUE, 0));
Expand All @@ -61,8 +73,9 @@ public static Intent createIntent(Context context, String key, String title, int
private void loadIntentExtras(){
key = getIntent().getStringExtra(EXTRA_PREF_KEY);
setTitle(getIntent().getStringExtra(EXTRA_TITLE));
background = getIntent().getIntExtra(EXTRA_BACKGROUND, -1);
icon = getIntent().getIntExtra(EXTRA_ICON, 0);
entries = getIntent().getCharSequenceArrayExtra(EXTRA_ENTRIES);
tint = getIntent().getIntExtra(EXTRA_TINT, 0); entries = getIntent().getCharSequenceArrayExtra(EXTRA_ENTRIES);
values = getIntent().getCharSequenceArrayExtra(EXTRA_ENTRY_VALUES);
icons = getIntent().getIntArrayExtra(EXTRA_ENTRY_ICONS);
}
Expand Down Expand Up @@ -99,8 +112,17 @@ public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int view

@Override public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
final ListItemLayout itemView = (ListItemLayout)holder.itemView;
itemView.bindView(icons != null ? icons[position] : icon, entries[position], null);
itemView.onNonCenterPosition(false);
if(icons != null) {
itemView.bindView(icons[position], entries[position], null, -1);
}
else {
if(tint > 0) {
itemView.bindView(icon, entries[position], null, tint);
}
else {
itemView.bindView(icon, entries[position], null, -1);
}
} itemView.onNonCenterPosition(false);
}

@Override public int getItemCount() {
Expand Down
Loading