diff options
Diffstat (limited to 'src/com/android/customization/picker/clock/ui/fragment')
| -rw-r--r-- | src/com/android/customization/picker/clock/ui/fragment/ClockCustomDemoFragment.kt | 93 | ||||
| -rw-r--r-- | src/com/android/customization/picker/clock/ui/fragment/ClockSettingsFragment.kt | 135 |
2 files changed, 228 insertions, 0 deletions
diff --git a/src/com/android/customization/picker/clock/ui/fragment/ClockCustomDemoFragment.kt b/src/com/android/customization/picker/clock/ui/fragment/ClockCustomDemoFragment.kt new file mode 100644 index 00000000..7e53ac44 --- /dev/null +++ b/src/com/android/customization/picker/clock/ui/fragment/ClockCustomDemoFragment.kt @@ -0,0 +1,93 @@ +package com.android.customization.picker.clock.ui.fragment + +import android.content.Context +import android.os.Bundle +import android.util.TypedValue +import android.view.ContextThemeWrapper +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.ViewGroup.LayoutParams.MATCH_PARENT +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT +import android.widget.FrameLayout +import android.widget.TextView +import android.widget.Toast +import androidx.core.view.setPadding +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.android.customization.module.ThemePickerInjector +import com.android.internal.annotations.VisibleForTesting +import com.android.systemui.plugins.ClockMetadata +import com.android.systemui.shared.clocks.ClockRegistry +import com.android.wallpaper.R +import com.android.wallpaper.module.InjectorProvider +import com.android.wallpaper.picker.AppbarFragment + +class ClockCustomDemoFragment : AppbarFragment() { + @VisibleForTesting lateinit var recyclerView: RecyclerView + @VisibleForTesting lateinit var clockRegistry: ClockRegistry + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val view = inflater.inflate(R.layout.fragment_clock_custom_picker_demo, container, false) + setUpToolbar(view) + clockRegistry = + (InjectorProvider.getInjector() as ThemePickerInjector).getClockRegistry( + requireContext() + ) + val listInUse = clockRegistry.getClocks().filter { "NOT_IN_USE" !in it.clockId } + + recyclerView = view.requireViewById(R.id.clock_preview_card_list_demo) + recyclerView.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) + recyclerView.adapter = + ClockRecyclerAdapter(listInUse, requireContext()) { + clockRegistry.currentClockId = it.clockId + Toast.makeText(context, "${it.name} selected", Toast.LENGTH_SHORT).show() + } + return view + } + + override fun getDefaultTitle(): CharSequence { + return getString(R.string.clock_title) + } + + internal class ClockRecyclerAdapter( + val list: List<ClockMetadata>, + val context: Context, + val onClockSelected: (ClockMetadata) -> Unit + ) : RecyclerView.Adapter<ClockRecyclerAdapter.ViewHolder>() { + class ViewHolder(val view: View, val textView: TextView, val onItemClicked: (Int) -> Unit) : + RecyclerView.ViewHolder(view) { + init { + itemView.setOnClickListener { onItemClicked(absoluteAdapterPosition) } + } + } + + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder { + val rootView = FrameLayout(viewGroup.context) + val textView = + TextView(ContextThemeWrapper(viewGroup.context, R.style.SectionTitleTextStyle)) + textView.setPadding(ITEM_PADDING) + rootView.addView(textView) + val outValue = TypedValue() + context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true) + rootView.setBackgroundResource(outValue.resourceId) + val lp = RecyclerView.LayoutParams(MATCH_PARENT, WRAP_CONTENT) + rootView.layoutParams = lp + return ViewHolder(rootView, textView) { onClockSelected(list[it]) } + } + + override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { + viewHolder.textView.text = list[position].name + } + + override fun getItemCount() = list.size + + companion object { + val ITEM_PADDING = 40 + } + } +} diff --git a/src/com/android/customization/picker/clock/ui/fragment/ClockSettingsFragment.kt b/src/com/android/customization/picker/clock/ui/fragment/ClockSettingsFragment.kt new file mode 100644 index 00000000..c5cde530 --- /dev/null +++ b/src/com/android/customization/picker/clock/ui/fragment/ClockSettingsFragment.kt @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2023 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.ui.fragment + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.cardview.widget.CardView +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.get +import com.android.customization.module.ThemePickerInjector +import com.android.customization.picker.clock.ui.binder.ClockSettingsBinder +import com.android.systemui.shared.clocks.shared.model.ClockPreviewConstants +import com.android.wallpaper.R +import com.android.wallpaper.module.InjectorProvider +import com.android.wallpaper.picker.AppbarFragment +import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder +import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel +import com.android.wallpaper.util.PreviewUtils +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.suspendCancellableCoroutine + +@OptIn(ExperimentalCoroutinesApi::class) +class ClockSettingsFragment : AppbarFragment() { + companion object { + const val DESTINATION_ID = "clock_settings" + + @JvmStatic + fun newInstance(): ClockSettingsFragment { + return ClockSettingsFragment() + } + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + val view = + inflater.inflate( + R.layout.fragment_clock_settings, + container, + false, + ) + setUpToolbar(view) + + val context = requireContext() + val activity = requireActivity() + val injector = InjectorProvider.getInjector() as ThemePickerInjector + + val lockScreenView: CardView = view.requireViewById(R.id.lock_preview) + val colorViewModel = injector.getWallpaperColorsViewModel() + val displayUtils = injector.getDisplayUtils(context) + ScreenPreviewBinder.bind( + activity = activity, + previewView = lockScreenView, + viewModel = + ScreenPreviewViewModel( + previewUtils = + PreviewUtils( + context = context, + authority = + resources.getString( + R.string.lock_screen_preview_provider_authority, + ), + ), + wallpaperInfoProvider = { + suspendCancellableCoroutine { continuation -> + injector + .getCurrentWallpaperInfoFactory(context) + .createCurrentWallpaperInfos( + { homeWallpaper, lockWallpaper, _ -> + continuation.resume( + homeWallpaper ?: lockWallpaper, + null, + ) + }, + /* forceRefresh= */ true, + ) + } + }, + onWallpaperColorChanged = { colors -> + colorViewModel.setLockWallpaperColors(colors) + }, + initialExtrasProvider = { + Bundle().apply { + // Hide the clock from the system UI rendered preview so we can + // place the carousel on top of it. + putBoolean( + ClockPreviewConstants.KEY_HIDE_CLOCK, + true, + ) + } + }, + ), + lifecycleOwner = this, + offsetToStart = displayUtils.isSingleDisplayOrUnfoldedHorizontalHinge(activity), + ) + .show() + + ClockSettingsBinder.bind( + view, + ViewModelProvider( + requireActivity(), + injector.getClockSettingsViewModelFactory( + context, + injector.getWallpaperColorsViewModel(), + ), + ) + .get(), + injector.getClockViewFactory(activity), + this@ClockSettingsFragment, + ) + + return view + } + + override fun getDefaultTitle(): CharSequence { + return requireContext().getString(R.string.clock_settings_title) + } +} |
