blob: 7eda621ea43281190fd710a51f5ec74b6b52d6b5 [file] [log] [blame]
Raff Tsai3515bc72018-06-19 17:25:31 +08001/*
2 * Copyright (C) 2018 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
17package com.android.settings;
18
19import android.app.Activity;
20import android.app.Fragment;
21import android.app.FragmentManager;
22import android.content.Context;
23import android.content.Intent;
24import android.os.Bundle;
25import android.util.FeatureFlagUtils;
26
27import com.android.settings.core.FeatureFlags;
28import com.android.settings.homepage.HomepageFragment;
29import com.android.settingslib.drawer.SettingsDrawerActivity;
30
31public class SettingsHomepageActivity extends SettingsDrawerActivity {
32
33 @Override
34 protected void onCreate(Bundle savedInstanceState) {
35 super.onCreate(savedInstanceState);
36
37 if (!isDynamicHomepageEnabled(this)) {
38 final Intent settings = new Intent();
39 settings.setAction("android.settings.SETTINGS");
40 startActivity(settings);
41 finish();
42 }
43 setContentView(R.layout.settings_homepage);
44 switchToFragment(this, R.id.main_content, HomepageFragment.class.getName());
45 }
46
47 public static boolean isDynamicHomepageEnabled(Context context) {
48 return FeatureFlagUtils.isEnabled(context, FeatureFlags.DYNAMIC_HOMEPAGE);
49 }
50
51 /**
52 * Switch to a specific Fragment
53 */
54 public static void switchToFragment(Activity activity, int id, String fragmentName) {
55 final Fragment f = Fragment.instantiate(activity, fragmentName, null /* args */);
56
57 FragmentManager manager = activity.getFragmentManager();
58 manager.beginTransaction().replace(id, f).commitAllowingStateLoss();
59 manager.executePendingTransactions();
60 }
61}