Search in sources :

Example 1 with AppearanceFragment

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));
        }
    }
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) Arrays(java.util.Arrays) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) StartMenuService(com.farmerbb.taskbar.service.StartMenuService) Uri(android.net.Uri) Intent(android.content.Intent) FragmentTransaction(android.app.FragmentTransaction) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) NotificationService(com.farmerbb.taskbar.service.NotificationService) StartTaskbarActivity(com.farmerbb.taskbar.activity.StartTaskbarActivity) PackageInfo(android.content.pm.PackageInfo) IconCache(com.farmerbb.taskbar.util.IconCache) AboutFragment(com.farmerbb.taskbar.fragment.AboutFragment) Icon(android.graphics.drawable.Icon) Build(android.os.Build) ActionBar(android.support.v7.app.ActionBar) LauncherHelper(com.farmerbb.taskbar.util.LauncherHelper) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) IntentFilter(android.content.IntentFilter) U(com.farmerbb.taskbar.util.U) SwitchCompat(android.support.v7.widget.SwitchCompat) AppearanceFragment(com.farmerbb.taskbar.fragment.AppearanceFragment) BroadcastReceiver(android.content.BroadcastReceiver) ShortcutManager(android.content.pm.ShortcutManager) AppCompatActivity(android.support.v7.app.AppCompatActivity) FreeformHackHelper(com.farmerbb.taskbar.util.FreeformHackHelper) File(java.io.File) AlertDialog(android.app.AlertDialog) TaskbarService(com.farmerbb.taskbar.service.TaskbarService) SharedPreferences(android.content.SharedPreferences) DashboardService(com.farmerbb.taskbar.service.DashboardService) ActivityNotFoundException(android.content.ActivityNotFoundException) KeyboardShortcutActivity(com.farmerbb.taskbar.activity.KeyboardShortcutActivity) ShortcutActivity(com.farmerbb.taskbar.activity.ShortcutActivity) HomeActivity(com.farmerbb.taskbar.activity.HomeActivity) ImportSettingsActivity(com.farmerbb.taskbar.activity.ImportSettingsActivity) AboutFragment(com.farmerbb.taskbar.fragment.AboutFragment) ShortcutInfo(android.content.pm.ShortcutInfo) SharedPreferences(android.content.SharedPreferences) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) AppearanceFragment(com.farmerbb.taskbar.fragment.AppearanceFragment) ActivityNotFoundException(android.content.ActivityNotFoundException) ActionBar(android.support.v7.app.ActionBar)

Aggregations

AlertDialog (android.app.AlertDialog)1 FragmentTransaction (android.app.FragmentTransaction)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 ShortcutManager (android.content.pm.ShortcutManager)1 Icon (android.graphics.drawable.Icon)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 ActionBar (android.support.v7.app.ActionBar)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1