• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.example.android.vdmdemo.host;
18 
19 import android.app.WallpaperManager;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.widget.FrameLayout;
23 import android.widget.GridView;
24 
25 import androidx.appcompat.app.AppCompatActivity;
26 import androidx.core.graphics.Insets;
27 import androidx.core.view.ViewCompat;
28 import androidx.core.view.WindowInsetsCompat;
29 
30 import dagger.hilt.android.AndroidEntryPoint;
31 
32 import javax.inject.Inject;
33 
34 /** Simple activity that can act as a home/launcher on a virtual device. */
35 @AndroidEntryPoint(AppCompatActivity.class)
36 public class CustomLauncherActivity extends Hilt_CustomLauncherActivity {
37 
38     @Inject PreferenceController mPreferenceController;
39 
40     @Override
onCreate(Bundle savedInstanceState)41     public void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         setContentView(R.layout.custom_launcher);
44 
45         GridView launcher = requireViewById(R.id.app_grid);
46         LauncherAdapter launcherAdapter = new LauncherAdapter(
47                 this, mPreferenceController, WallpaperManager.getInstance(this));
48         launcher.setAdapter(launcherAdapter);
49         launcher.setOnItemClickListener(
50                 (parent, v, position, id) -> {
51                     Intent intent = launcherAdapter.createPendingRemoteIntent(position);
52                     if (intent != null) {
53                         startActivity(intent);
54                     }
55                 });
56 
57         ViewCompat.setOnApplyWindowInsetsListener(launcher, (v, windowInsets) -> {
58             Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
59             FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) v.getLayoutParams();
60             lp.topMargin = insets.top;
61             lp.bottomMargin = insets.bottom;
62             v.setLayoutParams(lp);
63             return WindowInsetsCompat.CONSUMED;
64         });
65     }
66 
67     @Override
68     @SuppressWarnings("MissingSuperCall")
onBackPressed()69     public void onBackPressed() {
70         // Do nothing
71     }
72 }
73