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

Commit 92b3661a authored by George Lin's avatar George Lin
Browse files

Add clock custom fragment

Add clock custom fragment for customizing clock surface.
This is just an empty UI and in need to call clock face's API for the
content.
Design: http://shortn/_7RDNjpWEmS

Bug: 241966062
Test: https://screenshot.googleplex.com/AUX4So9hYia6SjD
Change-Id: Id3cc910a2b181e88a01dd2f4a4d00eb54de0b10c
parent c2414bf4
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
     Copyright (C) 2022 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.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="108dp">

    <FrameLayout
        android:id="@+id/section_header_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@+id/preview_card_container"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <include layout="@layout/section_header" />
    </FrameLayout>

    <FrameLayout
        android:id="@+id/preview_card_container"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constrainedHeight="true"
        app:layout_constraintBottom_toTopOf="@+id/clock_preview_card_list"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/section_header_container"
        android:paddingBottom="@dimen/preview_page_bottom_margin"
        android:paddingTop="@dimen/preview_page_top_margin"
        android:clipToPadding="false" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/clock_preview_card_list"
        android:layout_width="match_parent"
        android:layout_height="@dimen/options_container_height"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/preview_card_container"
        android:paddingHorizontal="@dimen/grid_options_container_horizontal_margin"
        android:scrollbars="horizontal"
        android:clipToPadding="false" />
</androidx.constraintlayout.widget.ConstraintLayout>
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.view.LayoutInflater;

import androidx.annotation.Nullable;

import com.android.customization.picker.clock.ClockCustomFragment;
import com.android.customization.picker.clock.ClockSectionView;
import com.android.wallpaper.R;
import com.android.wallpaper.config.Flags;
@@ -41,7 +42,10 @@ public class ClockSectionController implements CustomizationSectionController<Cl

    @Override
    public ClockSectionView createView(Context context) {
        return (ClockSectionView) LayoutInflater.from(context).inflate(R.layout.clock_section_view,
        ClockSectionView view = (ClockSectionView) LayoutInflater.from(context).inflate(
                R.layout.clock_section_view,
                null);
        view.setOnClickListener(v -> mNavigationController.navigateTo(new ClockCustomFragment()));
        return view;
    }
}
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */
package com.android.customization.model.clock.custom;

import com.android.customization.model.CustomizationManager;

import com.google.common.collect.Lists;

/**
 * {@link CustomizationManager} for clock faces.
 */
public class ClockCustomManager implements CustomizationManager<ClockOption> {
    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public void apply(ClockOption option, Callback callback) {
        // TODO(/b241966062) execute applying the clock when user selects a clock
    }

    @Override
    public void fetchOptions(OptionsFetchedListener<ClockOption> callback, boolean reload) {
        // TODO(/b241966062) fetch the real clock metadata from the ClockRegistry
        callback.onOptionsLoaded(
                Lists.newArrayList(new ClockOption(), new ClockOption(), new ClockOption(),
                        new ClockOption(), new ClockOption()));
    }
}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */
package com.android.customization.model.clock.custom;

import android.view.View;

import com.android.customization.model.CustomizationManager;
import com.android.customization.model.CustomizationOption;
import com.android.wallpaper.R;

/**
 * {@link CustomizationOption} for a clock face.
 */
public class ClockOption implements CustomizationOption<ClockOption> {

    @Override
    public String getTitle() {
        // TODO(/b241966062) use the title from the clock metadata
        return "title";
    }

    @Override
    public void bindThumbnailTile(View view) {
        // TODO(/b241966062) bind the thumbnail
    }

    @Override
    public boolean isActive(CustomizationManager<ClockOption> manager) {
        return false;
    }


    @Override
    public int getLayoutResId() {
        return R.layout.clock_option;
    }
}
+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */
package com.android.customization.picker.clock;

import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY;
import static com.android.wallpaper.widget.BottomActionBar.BottomAction.INFORMATION;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.android.customization.model.clock.custom.ClockCustomManager;
import com.android.customization.model.clock.custom.ClockOption;
import com.android.customization.widget.OptionSelectorController;
import com.android.wallpaper.R;
import com.android.wallpaper.picker.AppbarFragment;
import com.android.wallpaper.widget.BottomActionBar;

import com.google.common.collect.Lists;

/**
 * Fragment that contains the main UI for selecting and applying a custom clock.
 */
public class ClockCustomFragment extends AppbarFragment {

    OptionSelectorController<ClockOption> mClockSelectorController;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
            @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_clock_custom_picker, container, false);

        setUpToolbar(view);

        RecyclerView clockPreviewCardList = view.requireViewById(R.id.clock_preview_card_list);

        mClockSelectorController = new OptionSelectorController<>(clockPreviewCardList,
                Lists.newArrayList(new ClockOption(), new ClockOption(), new ClockOption(),
                        new ClockOption(), new ClockOption()), false,
                OptionSelectorController.CheckmarkStyle.CENTER_CHANGE_COLOR_WHEN_NOT_SELECTED);
        mClockSelectorController.initOptions(new ClockCustomManager());

        return view;
    }

    @Override
    public CharSequence getDefaultTitle() {
        return getString(R.string.clock_title);
    }

    @Override
    protected void onBottomActionBarReady(BottomActionBar bottomActionBar) {
        super.onBottomActionBarReady(bottomActionBar);
        bottomActionBar.showActionsOnly(INFORMATION, APPLY);
        bottomActionBar.show();
    }
}