Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2aa5a7d3 authored by Maurice Lam's avatar Maurice Lam Committed by Android (Google) Code Review
Browse files

Merge "Allow remote views to be used in Tiles"

parents 424476ae fc972a75
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2016 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.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorControlHighlight">
    <item android:drawable="?android:attr/colorBackground"/>
</ripple>
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2017 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.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:background="@drawable/selectable_card"
    android:clickable="true"
    android:elevation="2dp"
    android:focusable="true"
    android:minHeight="@dimen/dashboard_tile_minimum_height" />
+22 −7
Original line number Diff line number Diff line
@@ -237,6 +237,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
                        mDashboardData.getItemEntityByPosition(position));
                break;
            case R.layout.suggestion_tile:
            case R.layout.suggestion_tile_card:
                final Tile suggestion = (Tile) mDashboardData.getItemEntityByPosition(position);
                final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
                        mContext, suggestion);
@@ -247,7 +248,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
                    mSuggestionsShownLogged.add(suggestionId);
                }
                onBindTile(holder, suggestion);
                holder.itemView.setOnClickListener(v -> {
                View clickHandler = holder.itemView;
                // If a view with @android:id/primary is defined, use that as the click handler
                // instead.
                final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
                if (primaryAction != null) {
                    clickHandler = primaryAction;
                    // set the item view to disabled to remove any touch effects
                    holder.itemView.setEnabled(false);
                }
                clickHandler.setOnClickListener(v -> {
                    mMetricsFeatureProvider.action(mContext,
                            MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId);
                    ((SettingsActivity) mContext).startSuggestion(suggestion.intent);
@@ -405,6 +415,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
    }

    private void onBindTile(DashboardItemHolder holder, Tile tile) {
        if (tile.remoteViews != null) {
            final ViewGroup itemView = (ViewGroup) holder.itemView;
            itemView.addView(tile.remoteViews.apply(itemView.getContext(), itemView));
        } else {
            holder.icon.setImageDrawable(mCache.getIcon(tile.icon));
            holder.title.setText(tile.title);
            if (!TextUtils.isEmpty(tile.summary)) {
@@ -414,6 +428,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
                holder.summary.setVisibility(View.GONE);
            }
        }
    }

    private void onBindCategory(DashboardItemHolder holder, DashboardCategory category) {
        holder.title.setText(category.title);
+7 −1
Original line number Diff line number Diff line
@@ -218,7 +218,13 @@ public class DashboardData {
     */
    private void countSuggestion(Tile tile, boolean add) {
        if (add) {
            mItems.add(new Item(tile, R.layout.suggestion_tile, Objects.hash(tile.title), false));
            mItems.add(new Item(
                    tile,
                    tile.remoteViews != null
                            ? R.layout.suggestion_tile_card
                            : R.layout.suggestion_tile,
                    Objects.hash(tile.title),
                    false));
        }
        mId++;
    }
+3 −1
Original line number Diff line number Diff line
@@ -65,7 +65,9 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback

    @Override
    public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        if (viewHolder.getItemViewType() == R.layout.suggestion_tile) {
        final int layoutId = viewHolder.getItemViewType();
        if (layoutId == R.layout.suggestion_tile
                || layoutId == R.layout.suggestion_tile_card) {
            // Only return swipe direction for suggestion tiles. All other types are not swipeable.
            return super.getSwipeDirs(recyclerView, viewHolder);
        }
Loading