1 /* Copyright 2020 Braden Farmer
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 package com.farmerbb.taskbar.fragment;
18 import android.annotation.TargetApi;
19 import android.content.ActivityNotFoundException;
20 import android.content.Intent;
21 import android.content.SharedPreferences;
22 import android.os.Bundle;
23 import android.preference.Preference;
25 import androidx.appcompat.app.ActionBar;
26 import androidx.appcompat.app.AppCompatActivity;
28 import com.farmerbb.taskbar.R;
29 import com.farmerbb.taskbar.util.U;
31 public class DesktopModeFragment extends SettingsFragment {
34 public void onCreate(Bundle savedInstanceState) {
35 finishedLoadingPrefs = false;
37 super.onCreate(savedInstanceState);
40 addPreferencesFromResource(R.xml.tb_pref_desktop_mode);
42 // Set OnClickListeners for certain preferences
43 findPreference("set_as_default").setOnPreferenceClickListener(this);
45 SharedPreferences pref = U.getSharedPreferences(getActivity());
46 if(pref.getBoolean("launcher", false))
47 findPreference("desktop_mode").setEnabled(false);
49 bindPreferenceSummaryToValue(findPreference("desktop_mode"));
51 finishedLoadingPrefs = true;
55 public void onActivityCreated(Bundle savedInstanceState) {
56 super.onActivityCreated(savedInstanceState);
58 AppCompatActivity activity = (AppCompatActivity) getActivity();
59 activity.setTitle(R.string.tb_pref_header_desktop_mode);
60 ActionBar actionBar = activity.getSupportActionBar();
62 actionBar.setDisplayHomeAsUpEnabled(true);
67 public boolean onPreferenceClick(final Preference p) {
68 final SharedPreferences pref = U.getSharedPreferences(getActivity());
71 case "set_as_default":
72 Intent intent = new Intent();
73 intent.setAction(Intent.ACTION_MAIN);
74 intent.addCategory(Intent.CATEGORY_SECONDARY_HOME);
77 startActivity(intent);
78 } catch (Exception e) { /* Gracefully fail */ }
83 return super.onPreferenceClick(p);