Rename SuwLib directories

Rename eclair-mr1 to gingerbread to reflect the min SDK version
change, and full-support to recyclerview to better reflect what's
inside the directory

Also added comments and applied style fixes to keep checkstyle happy.

Test: Existing tests pass
Change-Id: I20332f718f2aae04092d5e45de944b1efce1a596
This commit is contained in:
Maurice Lam 2017-03-28 12:48:40 -07:00
parent 9955331ed7
commit 83862bb595
90 changed files with 92 additions and 29 deletions

View file

@ -36,10 +36,10 @@ LOCAL_MANIFEST_FILE := main/AndroidManifest.xml
LOCAL_MODULE := setup-wizard-lib-gingerbread-compat
LOCAL_RESOURCE_DIR := \
$(LOCAL_PATH)/main/res \
$(LOCAL_PATH)/eclair-mr1/res \
$(LOCAL_PATH)/full-support/res
$(LOCAL_PATH)/gingerbread/res \
$(LOCAL_PATH)/recyclerview/res
LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := $(call all-java-files-under, main/src eclair-mr1/src full-support/src)
LOCAL_SRC_FILES := $(call all-java-files-under, main/src gingerbread/src recyclerview/src)
ifdef LOCAL_USE_AAPT2

View file

@ -31,8 +31,8 @@ endif
ifeq (,$(findstring setup-wizard-lib-gingerbread-compat,$(LOCAL_STATIC_JAVA_LIBRARIES)))
LOCAL_RESOURCE_DIR += \
$(suwlib_dir)/main/res \
$(suwlib_dir)/eclair-mr1/res \
$(suwlib_dir)/full-support/res
$(suwlib_dir)/gingerbread/res \
$(suwlib_dir)/recyclerview/res
LOCAL_AAPT_FLAGS += --extra-packages com.android.setupwizardlib
LOCAL_STATIC_JAVA_LIBRARIES += setup-wizard-lib-gingerbread-compat
endif

View file

Before

Width:  |  Height:  |  Size: 160 B

After

Width:  |  Height:  |  Size: 160 B

View file

Before

Width:  |  Height:  |  Size: 132 B

After

Width:  |  Height:  |  Size: 132 B

View file

Before

Width:  |  Height:  |  Size: 133 B

After

Width:  |  Height:  |  Size: 133 B

View file

Before

Width:  |  Height:  |  Size: 140 B

After

Width:  |  Height:  |  Size: 140 B

View file

Before

Width:  |  Height:  |  Size: 114 B

After

Width:  |  Height:  |  Size: 114 B

View file

Before

Width:  |  Height:  |  Size: 108 B

After

Width:  |  Height:  |  Size: 108 B

View file

Before

Width:  |  Height:  |  Size: 191 B

After

Width:  |  Height:  |  Size: 191 B

View file

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

View file

@ -33,17 +33,35 @@ import com.android.setupwizardlib.R;
*/
public class SwitchItem extends Item implements CompoundButton.OnCheckedChangeListener {
/**
* Listener for check state changes of this switch item.
*/
public interface OnCheckedChangeListener {
/**
* Callback when checked state of a {@link SwitchItem} is changed.
*
* @see #setOnCheckedChangeListener(OnCheckedChangeListener)
*/
void onCheckedChange(SwitchItem item, boolean isChecked);
}
private boolean mChecked = false;
private OnCheckedChangeListener mListener;
/**
* Creates a default switch item.
*/
public SwitchItem() {
super();
}
/**
* Creates a switch item. This constructor is used for inflation from XML.
*
* @param context The context which this item is inflated in.
* @param attrs The XML attributes defined on the item.
*/
public SwitchItem(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuwSwitchItem);
@ -51,6 +69,9 @@ public class SwitchItem extends Item implements CompoundButton.OnCheckedChangeLi
a.recycle();
}
/**
* Sets whether this item should be checked.
*/
public void setChecked(boolean checked) {
if (mChecked != checked) {
mChecked = checked;
@ -61,6 +82,9 @@ public class SwitchItem extends Item implements CompoundButton.OnCheckedChangeLi
}
}
/**
* @return True if this switch item is currently checked.
*/
public boolean isChecked() {
return mChecked;
}
@ -91,6 +115,10 @@ public class SwitchItem extends Item implements CompoundButton.OnCheckedChangeLi
switchView.setEnabled(isEnabled());
}
/**
* Sets a listener to listen for changes in checked state. This listener is invoked in both
* user toggling the switch and calls to {@link #setChecked(boolean)}.
*/
public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
mListener = listener;
}

View file

@ -26,6 +26,10 @@ import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.widget.Button;
/**
* Button for navigation bar, which includes tinting of its compound drawables to be used for dark
* and light themes.
*/
public class NavigationBarButton extends Button {
public NavigationBarButton(Context context) {
@ -120,7 +124,7 @@ public class NavigationBarButton extends Button {
private ColorStateList mTintList = null;
public TintedDrawable(Drawable wrapped) {
TintedDrawable(Drawable wrapped) {
super(new Drawable[] { wrapped });
}

View file

@ -116,7 +116,7 @@
<dimen name="suw_items_preferred_height">56dp</dimen>
<!-- Navigation bar -->
<!-- TODO: Move this dimen to eclair-mr1, or see if it should be in platform style as well -->
<!-- TODO: Move this dimen to gingerbread, or see if it should be in platform style as well -->
<dimen name="suw_navbar_button_drawable_padding" tools:ignore="UnusedResources">6dp</dimen>
<dimen name="suw_navbar_button_padding_sides">10dp</dimen>
<dimen name="suw_navbar_height">56dp</dimen>

View file

@ -42,6 +42,10 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration {
/* static section */
/**
* An interface to be implemented by a {@link RecyclerView.ViewHolder} which controls whether
* dividers should be shown above and below that item.
*/
public interface DividedViewHolder {
/**

View file

@ -59,8 +59,7 @@ import com.android.setupwizardlib.template.RecyclerMixin;
* }</pre>
*
* <p />Fragments using this layout <em>must</em> delegate {@code onCreateRecyclerView} to the
* implementation in this class:
* {@link #onCreateRecyclerView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)}
* implementation in this class: {@link #onCreateRecyclerView}
*/
public class SetupWizardPreferenceLayout extends SetupWizardRecyclerLayout {

View file

@ -27,7 +27,7 @@ class ItemViewHolder extends RecyclerView.ViewHolder
private boolean mIsEnabled;
private IItem mItem;
public ItemViewHolder(View itemView) {
ItemViewHolder(View itemView) {
super(itemView);
}

View file

@ -46,7 +46,16 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
*/
public static final String TAG_NO_BACKGROUND = "noBackground";
/**
* Listener for item selection in this adapter.
*/
public interface OnItemSelectedListener {
/**
* Called when an item in this adapter is clicked.
*
* @param item The Item corresponding to the position being clicked.
*/
void onItemSelected(IItem item);
}
@ -58,6 +67,11 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
mItemHierarchy.registerObserver(this);
}
/**
* Gets the item at the given position.
*
* @see ItemHierarchy#getItemAt(int)
*/
public IItem getItem(int position) {
return mItemHierarchy.getItemAt(position);
}
@ -177,14 +191,27 @@ public class RecyclerItemAdapter extends RecyclerView.Adapter<ItemViewHolder>
notifyItemRangeRemoved(positionStart, itemCount);
}
/**
* Find an item hierarchy within the root hierarchy.
*
* @see ItemHierarchy#findItemById(int)
*/
public ItemHierarchy findItemById(int id) {
return mItemHierarchy.findItemById(id);
}
/**
* Gets the root item hierarchy in this adapter.
*/
public ItemHierarchy getRootItemHierarchy() {
return mItemHierarchy;
}
/**
* Sets the listener to listen for when user clicks on a item.
*
* @see OnItemSelectedListener
*/
public void setOnItemSelectedListener(OnItemSelectedListener listener) {
mListener = listener;
}

View file

@ -16,7 +16,6 @@
package com.android.setupwizardlib.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
@ -41,7 +40,7 @@ public class HeaderRecyclerView extends RecyclerView {
private static class HeaderViewHolder extends ViewHolder
implements DividerItemDecoration.DividedViewHolder {
public HeaderViewHolder(View itemView) {
HeaderViewHolder(View itemView) {
super(itemView);
}
@ -119,23 +118,18 @@ public class HeaderRecyclerView extends RecyclerView {
setHasStableIds(mAdapter.hasStableIds());
}
@SuppressLint("InlinedApi") // MATCH_PARENT is the same constant as FILL_PARENT available
// on earlier versions.
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
/*
* Returning the same view (mHeader) results in crash ".. but view is not a real child."
* The framework creates more than one instance of header because of "disappear"
* animations applied on the header and this necessitates creation of another headerview
* to use after the animation. We work around this restriction by returning an empty
* framelayout to which the header is attached using #onBindViewHolder method.
*/
// Returning the same view (mHeader) results in crash ".. but view is not a real child."
// The framework creates more than one instance of header because of "disappear"
// animations applied on the header and this necessitates creation of another header
// view to use after the animation. We work around this restriction by returning an
// empty FrameLayout to which the header is attached using #onBindViewHolder method.
if (viewType == HEADER_VIEW_TYPE) {
FrameLayout frameLayout = new FrameLayout(parent.getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT
);
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
frameLayout.setLayoutParams(params);
return new HeaderViewHolder(frameLayout);
} else {

View file

@ -79,6 +79,10 @@ public class StickyHeaderRecyclerView extends HeaderRecyclerView {
}
}
/**
* Call this method when the "sticky" view has changed, so this view can update its internal
* states as well.
*/
public void updateStickyView() {
final View header = getHeader();
if (header != null) {

View file

@ -63,8 +63,8 @@ android {
}
gingerbreadCompat {
java.srcDirs = ['eclair-mr1/src', 'full-support/src']
res.srcDirs = ['eclair-mr1/res', 'full-support/res']
java.srcDirs = ['gingerbread/src', 'recyclerview/src']
res.srcDirs = ['gingerbread/res', 'recyclerview/res']
}
}
}

View file

@ -25,8 +25,11 @@ android.sourceSets {
}
androidTestGingerbreadCompat {
java.srcDirs = ['full-support/test/instrumentation/src', 'eclair-mr1/test/instrumentation/src']
res.srcDirs = ['full-support/test/instrumentation/res']
java.srcDirs = [
'gingerbread/test/instrumentation/src',
'recyclerview/test/instrumentation/src'
]
res.srcDirs = ['recyclerview/test/instrumentation/res']
}
test {
@ -43,7 +46,7 @@ android.sourceSets {
}
testGingerbreadCompat {
java.srcDirs = ['eclair-mr1/test/robotest/src', 'full-support/test/robotest/src']
java.srcDirs = ['gingerbread/test/robotest/src', 'recyclerview/test/robotest/src']
}
}
android.defaultConfig.testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"