diff options
Diffstat (limited to 'src/com/android/tv/ui/sidepanel/Item.java')
-rw-r--r-- | src/com/android/tv/ui/sidepanel/Item.java | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/src/com/android/tv/ui/sidepanel/Item.java b/src/com/android/tv/ui/sidepanel/Item.java index 53238fd7..da9b39b0 100644 --- a/src/com/android/tv/ui/sidepanel/Item.java +++ b/src/com/android/tv/ui/sidepanel/Item.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Android Open Source Project + * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,73 @@ package com.android.tv.ui.sidepanel; import android.view.View; +import android.view.ViewGroup; public abstract class Item { + private View mItemView; + private boolean mEnabled = true; + + public void setEnabled(boolean enabled) { + if (mEnabled != enabled) { + mEnabled = enabled; + if (mItemView != null) { + setEnabledInternal(mItemView, enabled); + } + } + } + + /** + * Returns whether this item is enabled. + */ + public boolean isEnabled() { + return mEnabled; + } + + public final void notifyUpdated() { + if (mItemView != null) { + onUpdate(); + } + } + protected abstract int getResourceId(); - protected void bind(@SuppressWarnings("unused") View view) { } - protected void unbind() { } - protected void onSelected() { } - protected void onFocused() { } -}
\ No newline at end of file + + protected void onBind(View view) { + mItemView = view; + } + + protected void onUnbind() { + mItemView = null; + } + + /** + * Called after onBind is called and when {@link #notifyUpdated} is called. + * {@link #notifyUpdated} is usually called by {@link SideFragment#notifyItemChanged} and + * {@link SideFragment#notifyItemsChanged}. + */ + protected void onUpdate() { + setEnabledInternal(mItemView, mEnabled); + } + + protected abstract void onSelected(); + + protected void onFocused() { + } + + /** + * Returns true if the item is bound, i.e., onBind is called. + */ + protected boolean isBound() { + return mItemView != null; + } + + private void setEnabledInternal(View view, boolean enabled) { + view.setEnabled(enabled); + if (view instanceof ViewGroup) { + ViewGroup parent = (ViewGroup) view; + int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; ++i) { + setEnabledInternal(parent.getChildAt(i), enabled); + } + } + } +} |