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.GridView; 23 24 import androidx.appcompat.app.AppCompatActivity; 25 import androidx.core.view.WindowCompat; 26 import androidx.core.view.WindowInsetsCompat; 27 import androidx.core.view.WindowInsetsControllerCompat; 28 29 import dagger.hilt.android.AndroidEntryPoint; 30 31 /** Simple activity that can act as a home/launcher on a virtual device. */ 32 @AndroidEntryPoint(AppCompatActivity.class) 33 public class CustomLauncherActivity extends Hilt_CustomLauncherActivity { 34 35 @Override onCreate(Bundle savedInstanceState)36 public void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 setContentView(R.layout.custom_launcher); 39 40 WindowInsetsControllerCompat windowInsetsController = 41 WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView()); 42 windowInsetsController.setSystemBarsBehavior( 43 WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); 44 windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); 45 46 GridView launcher = requireViewById(R.id.app_grid); 47 LauncherAdapter launcherAdapter = 48 new LauncherAdapter(getPackageManager(), WallpaperManager.getInstance(this)); 49 launcher.setAdapter(launcherAdapter); 50 launcher.setOnItemClickListener( 51 (parent, v, position, id) -> { 52 Intent intent = launcherAdapter.createPendingRemoteIntent(position); 53 if (intent != null) { 54 startActivity(intent); 55 } 56 }); 57 } 58 59 @Override 60 @SuppressWarnings("MissingSuperCall") onBackPressed()61 public void onBackPressed() { 62 // Do nothing 63 } 64 } 65