1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.car.rotaryplayground; 18 19 import android.graphics.Color; 20 import android.graphics.drawable.Drawable; 21 import android.os.Bundle; 22 import android.util.Log; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.view.ViewGroup; 26 27 import androidx.annotation.Nullable; 28 import androidx.fragment.app.Fragment; 29 30 import com.android.car.ui.utils.DirectManipulationHelper; 31 32 public class RotarySysUiDirectManipulationWidgets extends Fragment { 33 34 @Override onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)35 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, 36 @Nullable Bundle savedInstanceState) { 37 View view = inflater.inflate(R.layout.rotary_sys_ui_direct_manipulation, container, false); 38 39 View directManipulationSupportedSeekBar = view.findViewById( 40 R.id.direct_manipulation_supported_seek_bar); 41 DirectManipulationHelper.setSupportsDirectManipulation( 42 directManipulationSupportedSeekBar, true); 43 44 View directManipulationUnsupportedSeekBar = view.findViewById( 45 R.id.direct_manipulation_unsupported_seek_bar); 46 directManipulationUnsupportedSeekBar.setOnClickListener( 47 new ChangeBackgroundColorOnClickListener()); 48 49 View directManipulationSupportedRadialTimePickerView = view.findViewById( 50 R.id.direct_manipulation_supported_radial_time_picker); 51 DirectManipulationHelper.setSupportsDirectManipulation( 52 directManipulationSupportedRadialTimePickerView, true); 53 54 View directManipulationUnsupportedRadialTimePickerView = view.findViewById( 55 R.id.direct_manipulation_unsupported_radial_time_picker); 56 directManipulationUnsupportedRadialTimePickerView.setOnClickListener( 57 new ChangeBackgroundColorOnClickListener()); 58 59 return view; 60 } 61 62 /** 63 * An {@link android.view.View.OnClickListener} object that changes the background of the 64 * view it is registered on to {@link Color#BLUE} and back to whatever it was before on 65 * subsequent calls. This is just to demo doing something visually obvious in the UI. 66 */ 67 private static class ChangeBackgroundColorOnClickListener implements View.OnClickListener { 68 69 /** Just some random color to switch the background to for demo purposes. */ 70 private static final int ALTERNATIVE_BACKGROUND_COLOR = Color.BLUE; 71 72 /** 73 * The purpose of this boolean is to change color every other time {@link #onClick} is 74 * called. 75 */ 76 private boolean mFlipFlop = true; 77 78 @Override onClick(View v)79 public void onClick(View v) { 80 Log.d(L.TAG, 81 "Handling onClick for " + v + " and going " + (mFlipFlop ? "flip" : "flop")); 82 if (mFlipFlop) { 83 Log.d(L.TAG, "Background about to be overwritten: " + v.getBackground()); 84 v.setTag(R.id.saved_background_tag, v.getBackground()); 85 v.setBackgroundColor(ALTERNATIVE_BACKGROUND_COLOR); 86 } else { 87 Object savedBackground = v.getTag(R.id.saved_background_tag); 88 Log.d(L.TAG, "Restoring background: " + savedBackground); 89 v.setBackground((Drawable) savedBackground); 90 } 91 // Flip mode bit. 92 mFlipFlop = !mFlipFlop; 93 } 94 } 95 }