1 /*
2  * Copyright (C) 2019 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 package android.car.cluster;
17 
18 import static android.car.media.CarMediaManager.MEDIA_SOURCE_MODE_PLAYBACK;
19 
20 import android.os.Bundle;
21 import android.util.Size;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.ImageView;
26 import android.widget.SeekBar;
27 import android.widget.TextView;
28 
29 import androidx.annotation.NonNull;
30 import androidx.annotation.Nullable;
31 import androidx.fragment.app.Fragment;
32 import androidx.fragment.app.FragmentActivity;
33 import androidx.lifecycle.ViewModelProviders;
34 
35 import com.android.car.media.common.MetadataController;
36 import com.android.car.media.common.playback.PlaybackViewModel;
37 import com.android.car.media.common.source.MediaSourceViewModel;
38 
39 import com.bumptech.glide.request.target.Target;
40 
41 /**
42  * Displays information on the current media item selected.
43  */
44 public class MusicFragment extends Fragment {
45     private static final String TAG = "MusicFragment";
46 
MusicFragment()47     public MusicFragment() {
48         // Required empty public constructor
49     }
50 
51     @Nullable
52     @Override
onCreateView(@onNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)53     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
54             Bundle savedInstanceState) {
55         FragmentActivity activity = requireActivity();
56         PlaybackViewModel playbackViewModel =
57                 PlaybackViewModel.get(activity.getApplication(), MEDIA_SOURCE_MODE_PLAYBACK);
58         MediaSourceViewModel mMediaSourceViewModel = MediaSourceViewModel.get(
59                 activity.getApplication(), MEDIA_SOURCE_MODE_PLAYBACK);
60 
61         MusicFragmentViewModel innerViewModel = ViewModelProviders.of(activity).get(
62                 MusicFragmentViewModel.class);
63         innerViewModel.init(mMediaSourceViewModel);
64 
65         View view = inflater.inflate(R.layout.fragment_music, container, false);
66 
67         TextView appName = view.findViewById(R.id.app_name);
68         innerViewModel.getAppName().observe(getViewLifecycleOwner(), appName::setText);
69 
70         ImageView appIcon = view.findViewById(R.id.app_icon);
71         innerViewModel.getAppIcon().observe(getViewLifecycleOwner(), appIcon::setImageBitmap);
72 
73         TextView title = view.findViewById(R.id.title);
74         TextView subtitle = view.findViewById(R.id.subtitle);
75         SeekBar seekBar = view.findViewById(R.id.seek_bar);
76         TextView time = view.findViewById(R.id.time);
77         TextView timeSeparator = view.findViewById(R.id.time_separator);
78         TextView trackLength = view.findViewById(R.id.track_length);
79 
80         ImageView albumIcon = view.findViewById(R.id.album_art);
81 
82         int artSize = view.getContext().getResources().getDimensionPixelSize(
83                 R.dimen.playback_album_art_size_normal);
84 
85         new MetadataController(
86             getViewLifecycleOwner(),
87             playbackViewModel,
88             title,
89             subtitle,
90             null,
91             null,
92             time,
93             timeSeparator,
94             trackLength,
95             seekBar,
96             albumIcon,
97             new Size(artSize, artSize)
98         );
99 
100         return view;
101     }
102 }
103