1 /* 2 * Copyright (C) 2016 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.sampleleanbacklauncher; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.os.Bundle; 22 23 import com.example.sampleleanbacklauncher.apps.AppFragment; 24 import com.example.sampleleanbacklauncher.search.SearchFragment; 25 26 public class LauncherActivity extends Activity { 27 private SystemUpdateChecker mSystemUpdateChecker; 28 private static final int SYSTEM_UPDATE_CHECKER_REQUEST = 0; 29 30 @Override onCreate(Bundle savedInstanceState)31 protected void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 34 setContentView(R.layout.launcher); 35 36 if (savedInstanceState == null) { 37 getFragmentManager().beginTransaction() 38 // Search row 39 .add(R.id.launcher_container, 40 SearchFragment.newInstance()) 41 // Apps row 42 .add(R.id.launcher_container, 43 AppFragment.newInstance(AppFragment.ROW_TYPE_APPS)) 44 // Games row 45 .add(R.id.launcher_container, 46 AppFragment.newInstance(AppFragment.ROW_TYPE_GAMES)) 47 // Settings row 48 .add(R.id.launcher_container, 49 AppFragment.newInstance(AppFragment.ROW_TYPE_SETTINGS)) 50 .commit(); 51 } 52 53 mSystemUpdateChecker = new SystemUpdateChecker(this); 54 } 55 56 @Override onResume()57 protected void onResume() { 58 super.onResume(); 59 findViewById(R.id.launcher_container).animate().alpha(1f); 60 61 Intent intent = mSystemUpdateChecker.getSystemUpdateCheckerIntent(); 62 if (intent != null) { 63 startActivityForResult(intent, SYSTEM_UPDATE_CHECKER_REQUEST); 64 } 65 } 66 67 @Override onPause()68 protected void onPause() { 69 super.onPause(); 70 findViewById(R.id.launcher_container).animate().alpha(0f); 71 } 72 73 @Override onActivityResult(int requestCode, int resultCode, Intent data)74 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 75 super.onActivityResult(requestCode, resultCode, data); 76 if (requestCode == SYSTEM_UPDATE_CHECKER_REQUEST && resultCode == RESULT_OK) { 77 mSystemUpdateChecker.onSystemUpdateCheckerComplete(); 78 } 79 } 80 } 81