use of com.farmerbb.taskbar.fragment.AppearanceFragment in project Taskbar by farmerbb.
the class MainActivity method proceedWithAppLaunch.
private void proceedWithAppLaunch(Bundle savedInstanceState) {
setContentView(R.layout.main);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setCustomView(R.layout.switch_layout);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
}
theSwitch = U.findViewById(this, R.id.the_switch);
if (theSwitch != null) {
final SharedPreferences pref = U.getSharedPreferences(this);
theSwitch.setChecked(pref.getBoolean("taskbar_active", false));
theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
if (b) {
if (U.canDrawOverlays(this)) {
boolean firstRun = pref.getBoolean("first_run", true);
startTaskbarService();
if (firstRun)
U.showRecentAppsDialog(this);
} else {
U.showPermissionDialog(this);
compoundButton.setChecked(false);
}
} else
stopTaskbarService();
});
}
if (savedInstanceState == null) {
if (!getIntent().hasExtra("theme_change"))
getFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit();
else
getFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit();
}
if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
final SharedPreferences pref = U.getSharedPreferences(this);
if (!pref.getBoolean("dont_show_uninstall_dialog", false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message).setPositiveButton(R.string.action_uninstall, (dialog, which) -> {
pref.edit().putBoolean("uninstall_dialog_shown", true).apply();
try {
startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
} catch (ActivityNotFoundException e) {
/* Gracefully fail */
}
});
if (pref.getBoolean("uninstall_dialog_shown", false))
builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit().putBoolean("dont_show_uninstall_dialog", true).apply());
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
}
if (!pref.getBoolean("uninstall_dialog_shown", false)) {
if (theSwitch != null)
theSwitch.setChecked(false);
SharedPreferences.Editor editor = pref.edit();
String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID);
if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
editor.putString("icon_pack", BuildConfig.APPLICATION_ID);
} else {
U.refreshPinnedIcons(this);
}
editor.putBoolean("first_run", true);
editor.apply();
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.getDynamicShortcuts().size() == 0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, StartTaskbarActivity.class);
intent.putExtra("is_launching_shortcut", true);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar").setShortLabel(getString(R.string.start_taskbar)).setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent).build();
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.setClass(this, ShortcutActivity.class);
intent2.putExtra("is_launching_shortcut", true);
ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode").setShortLabel(getString(R.string.pref_header_freeform)).setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform)).setIntent(intent2).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
}
}
}
Aggregations