• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.chassis.car.ui.sharedlibrary.appstyleview;
18 
19 import android.content.Context;
20 import android.view.Gravity;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.WindowManager.LayoutParams;
24 import android.widget.ImageView;
25 import android.widget.ScrollView;
26 
27 import com.android.car.ui.sharedlibrary.oemapis.appstyledview.AppStyledViewControllerOEMV1;
28 
29 import com.chassis.car.ui.sharedlibrary.R;
30 
31 /**
32  * The OEM implementation for {@link AppStyledViewControllerOEMV1} for a AppStyledView.
33  */
34 public class AppStyleViewControllerImpl implements AppStyledViewControllerOEMV1 {
35 
36     private final Context mContext;
37     private View mAppStyleView;
38     private int mNavIcon;
39     private Runnable mCloseListener = null;
40 
AppStyleViewControllerImpl(Context context)41     public AppStyleViewControllerImpl(Context context) {
42         mContext = context;
43     }
44 
45     @Override
getAppStyledView(View content)46     public View getAppStyledView(View content) {
47         LayoutInflater inflater = LayoutInflater.from(mContext);
48         mAppStyleView = inflater.inflate(R.layout.app_styled_view, null, false);
49 
50         ScrollView scrollview = mAppStyleView.findViewById(R.id.app_styled_content);
51         scrollview.addView(content);
52 
53         ImageView navIcon = mAppStyleView.findViewById(R.id.app_styled_view_icon_close);
54         if (mNavIcon == 0) {
55             navIcon.setImageResource(R.drawable.icon_back);
56         } else if (mNavIcon == 1) {
57             navIcon.setImageResource(R.drawable.icon_close);
58         } else {
59             navIcon.setImageResource(R.drawable.icon_close);
60         }
61 
62         if (mCloseListener != null) {
63             navIcon.setOnClickListener((v) -> {
64                 mCloseListener.run();
65             });
66         }
67 
68         return mAppStyleView;
69     }
70 
71     @Override
setOnCloseClickListener(Runnable listener)72     public void setOnCloseClickListener(Runnable listener) {
73         mCloseListener = listener;
74     }
75 
76     @Override
setNavIcon(int navIcon)77     public void setNavIcon(int navIcon) {
78         mNavIcon = navIcon;
79     }
80 
81     @Override
getDialogWindowLayoutParam(LayoutParams params)82     public LayoutParams getDialogWindowLayoutParam(LayoutParams params) {
83         params.width = Math.round(
84                 mContext.getResources().getDimension(R.dimen.app_styled_dialog_width));
85         params.height = Math.round(
86                 mContext.getResources().getDimension(R.dimen.app_styled_dialog_height));
87         params.gravity = Gravity.TOP | Gravity.START;
88         params.x = Math.round(
89                 mContext.getResources().getDimension(R.dimen.app_styled_dialog_position_x));
90         params.y = Math.round(
91                 mContext.getResources().getDimension(R.dimen.app_styled_dialog_position_y));
92         return params;
93     }
94 }
95