• 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 package com.android.car.ui.paintbooth.appstyledview;
17 
18 import android.content.Context;
19 import android.content.res.Configuration;
20 import android.content.res.Resources;
21 import android.os.Bundle;
22 import android.view.ContextThemeWrapper;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.Window;
26 import android.widget.Button;
27 
28 import androidx.appcompat.app.AppCompatActivity;
29 
30 import com.android.car.ui.appstyledview.AppStyledDialogController;
31 import com.android.car.ui.appstyledview.AppStyledViewController.AppStyledViewNavIcon;
32 import com.android.car.ui.core.CarUi;
33 import com.android.car.ui.paintbooth.R;
34 import com.android.car.ui.toolbar.NavButtonMode;
35 import com.android.car.ui.toolbar.ToolbarController;
36 
37 /**
38  * Sample activity to show app styled Dialog fragment.
39  */
40 public class AppStyledViewSampleActivity extends AppCompatActivity {
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
46 
47         setContentView(R.layout.app_styled_view_sample_activity);
48 
49         ToolbarController toolbar = CarUi.requireToolbar(this);
50         toolbar.setTitle(getTitle());
51         toolbar.setNavButtonMode(NavButtonMode.BACK);
52         toolbar.setLogo(R.drawable.ic_launcher);
53 
54         AppStyledDialogController controller = new AppStyledDialogController(this);
55         int width = controller.getAppStyledViewDialogWidth();
56 
57         Resources resources = getResources();
58         Configuration config = resources.getConfiguration();
59 
60         config.smallestScreenWidthDp = width;
61         // fake the min screen size so resources load from the corresponding folders. For eg.
62         // layout-sw400dp
63         Context testContext = createConfigurationContext(config);
64 
65         Context contextThemeWrapper = new ContextThemeWrapper(testContext,
66                 R.style.AppStyledDialogThemeSample);
67 
68         View appStyledTestView = LayoutInflater.from(contextThemeWrapper)
69                 .inflate(R.layout.app_styled_view_test_sample, null, false);
70 
71         Button btn = findViewById(R.id.show_app_styled_fragment);
72         btn.setOnClickListener(v -> {
73             controller.setContentView(appStyledTestView);
74             controller.setNavIcon(AppStyledViewNavIcon.CLOSE);
75             controller.show();
76         });
77     }
78 }
79