Raff Tsai | 3515bc7 | 2018-06-19 17:25:31 +0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.settings; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.Fragment; |
| 21 | import android.app.FragmentManager; |
| 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | import android.os.Bundle; |
| 25 | import android.util.FeatureFlagUtils; |
| 26 | |
| 27 | import com.android.settings.core.FeatureFlags; |
| 28 | import com.android.settings.homepage.HomepageFragment; |
| 29 | import com.android.settingslib.drawer.SettingsDrawerActivity; |
| 30 | |
| 31 | public 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 | } |