Search in sources :

Example 1 with SDK_INT

use of android.os.Build.VERSION.SDK_INT in project MaxLock by Maxr1998.

the class MaxLockPreferenceFragment method onLockscreenDismissed.

public void onLockscreenDismissed() {
    // Show changelog and rating dialog
    int lastVersionNumber = prefs.getInt(Common.LAST_VERSION_NUMBER, -1);
    if (BuildConfig.VERSION_CODE > lastVersionNumber) {
        // Don't show updated dialog on first start
        if (lastVersionNumber > 0)
            showUpdatedMessage();
        prefs.edit().putInt(Common.LAST_VERSION_NUMBER, BuildConfig.VERSION_CODE).apply();
    } else {
        if (isFirstPane() && allowRatingDialog()) {
            prefs.edit().putInt(Common.RATING_DIALOG_APP_OPENING_COUNTER, 0).putLong(Common.RATING_DIALOG_LAST_SHOWN, System.currentTimeMillis()).apply();
            @SuppressLint("InflateParams") View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_like_app, null);
            if (prefs.getBoolean(Common.DONATED, false)) {
                TextView dialogText = dialogView.findViewById(R.id.dialog_like_app_text);
                dialogText.setText(R.string.dialog_like_app_text_pro);
            }
            @SuppressWarnings("ResourceType") final CheckBox checkBox = dialogView.findViewById(R.id.dialog_cb_never_again);
            DialogInterface.OnClickListener onClickListener = (dialogInterface, i) -> {
                if (checkBox.isChecked()) {
                    prefs.edit().putBoolean(Common.RATING_DIALOG_SHOW_NEVER, true).apply();
                }
                switch(i) {
                    case BUTTON_NEUTRAL:
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID)));
                        } catch (ActivityNotFoundException e) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID)));
                        }
                        break;
                    case BUTTON_POSITIVE:
                        startActivity(new Intent(getActivity(), DonateActivity.class));
                        break;
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.dialog_like_app).setView(dialogView);
            if (!prefs.getBoolean(Common.DONATED, false))
                builder.setPositiveButton(R.string.dialog_button_donate, onClickListener);
            builder.setNeutralButton(R.string.dialog_button_rate, onClickListener).setNegativeButton(android.R.string.cancel, onClickListener).create().show();
        }
    }
    if (SDK_INT > Build.VERSION_CODES.O && ContextCompat.checkSelfPermission(getContext(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
        new AlertDialog.Builder(getActivity()).setMessage(R.string.dialog_need_storage_permission_oreo).setPositiveButton(android.R.string.ok, (dialog, which) -> ActivityCompat.requestPermissions(getActivity(), new String[] { READ_EXTERNAL_STORAGE }, 0)).setNegativeButton(android.R.string.cancel, null).show();
    }
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) BuildConfig(de.Maxr1998.xposed.maxlock.BuildConfig) Uri(android.net.Uri) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) LockPatternActivity(com.haibison.android.lockpattern.LockPatternActivity) ColorDrawable(android.graphics.drawable.ColorDrawable) PreferenceScreen(android.preference.PreferenceScreen) SDK_INT(android.os.Build.VERSION.SDK_INT) VisibleForTesting(android.support.annotation.VisibleForTesting) Util(de.Maxr1998.xposed.maxlock.util.Util) PreferenceFragmentCompat(android.support.v4.preference.PreferenceFragmentCompat) CheckBox(android.widget.CheckBox) MLImplementation(de.Maxr1998.xposed.maxlock.MLImplementation) WebViewClient(android.webkit.WebViewClient) View(android.view.View) BUTTON_NEUTRAL(android.content.DialogInterface.BUTTON_NEUTRAL) WebView(android.webkit.WebView) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) FileProvider.getUriForFile(android.support.v4.content.FileProvider.getUriForFile) PorterDuff(android.graphics.PorterDuff) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) IOUtils(org.apache.commons.io.IOUtils) ListPreference(android.preference.ListPreference) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) Snackbar(android.support.design.widget.Snackbar) SettingsActivity(de.Maxr1998.xposed.maxlock.ui.SettingsActivity) ZipOutputStream(java.util.zip.ZipOutputStream) Context(android.content.Context) PreferenceCategory(android.preference.PreferenceCategory) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) XmlRes(android.support.annotation.XmlRes) BufferedOutputStream(java.io.BufferedOutputStream) FingerprintManagerCompat(android.support.v4.hardware.fingerprint.FingerprintManagerCompat) SuppressLint(android.annotation.SuppressLint) KUtil(de.Maxr1998.xposed.maxlock.util.KUtil) Charset(java.nio.charset.Charset) DevicePolicyManager(android.app.admin.DevicePolicyManager) READ_EXTERNAL_STORAGE(android.Manifest.permission.READ_EXTERNAL_STORAGE) Toast(android.widget.Toast) Build(android.os.Build) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) DialogInterface(android.content.DialogInterface) BUTTON_POSITIVE(android.content.DialogInterface.BUTTON_POSITIVE) ImplementationPreference(de.Maxr1998.xposed.maxlock.preference.ImplementationPreference) MLPreferences(de.Maxr1998.xposed.maxlock.util.MLPreferences) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Common(de.Maxr1998.xposed.maxlock.Common) File(java.io.File) R(de.Maxr1998.xposed.maxlock.R) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) InputStream(java.io.InputStream) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) ActivityNotFoundException(android.content.ActivityNotFoundException) CheckBox(android.widget.CheckBox) SuppressLint(android.annotation.SuppressLint) TextView(android.widget.TextView)

Example 2 with SDK_INT

use of android.os.Build.VERSION.SDK_INT in project AmazeFileManager by TeamAmaze.

the class MainActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initialisePreferences();
    initializeInteractiveShell();
    dataUtils.registerOnDataChangedListener(this);
    CustomSshJConfig.init();
    AppConfig.setActivityContext(con);
    setContentView(R.layout.main_toolbar);
    appbar = new AppBar(this, getPrefs(), queue -> {
        if (!queue.isEmpty()) {
            mainActivityHelper.search(getPrefs(), queue);
        }
    });
    initialiseViews();
    tabHandler = new TabHandler(this);
    utilsHandler = AppConfig.getInstance().getUtilsHandler();
    cloudHandler = new CloudHandler(this);
    mainActivityHelper = new MainActivityHelper(this);
    // TODO: 7/12/2017 not init when actionIntent != null
    initialiseFab();
    if (CloudSheetFragment.isCloudProviderAvailable(this)) {
        getSupportLoaderManager().initLoader(REQUEST_CODE_CLOUD_LIST_KEYS, null, this);
    }
    path = getIntent().getStringExtra("path");
    openProcesses = getIntent().getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false);
    intent = getIntent();
    if (intent.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<HybridFileParcelable> failedOps = intent.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, this);
        }
    }
    checkForExternalIntent(intent);
    if (savedInstanceState != null) {
        drawer.setSomethingSelected(savedInstanceState.getBoolean(KEY_DRAWER_SELECTED));
    }
    // setting window background color instead of each item, in order to reduce pixel overdraw
    if (getAppTheme().equals(AppTheme.LIGHT)) {
        /*if(Main.IS_LIST)
                getWindow().setBackgroundDrawableResource(android.R.color.white);
            else
                getWindow().setBackgroundDrawableResource(R.color.grid_background_light);
            */
        getWindow().setBackgroundDrawableResource(android.R.color.white);
    } else if (getAppTheme().equals(AppTheme.BLACK)) {
        getWindow().setBackgroundDrawableResource(android.R.color.black);
    } else {
        getWindow().setBackgroundDrawableResource(R.color.holo_dark_background);
    }
    /*findViewById(R.id.drawer_buttton).setOnClickListener(new ImageView.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mDrawerLayout.isOpen(mDrawerLinear)) {
                    mDrawerLayout.close(mDrawerLinear);
                } else mDrawerLayout.openDrawer(mDrawerLinear);
            }
        });*/
    drawer.setDrawerIndicatorEnabled();
    // recents header color implementation
    if (SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze", ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(), getColorPreference().getColor(ColorUsage.getPrimary(MainActivity.currentTab)));
        setTaskDescription(taskDescription);
    }
    if (!getBoolean(PREFERENCE_BOOKMARKS_ADDED)) {
        utilsHandler.addCommonBookmarks();
        getPrefs().edit().putBoolean(PREFERENCE_BOOKMARKS_ADDED, true).commit();
    }
    AppConfig.runInBackground(new AppConfig.CustomAsyncCallbacks() {

        @Override
        public <E> E doInBackground() {
            dataUtils.setHiddenFiles(utilsHandler.getHiddenFilesConcurrentRadixTree());
            dataUtils.setHistory(utilsHandler.getHistoryLinkedList());
            dataUtils.setGridfiles(utilsHandler.getGridViewList());
            dataUtils.setListfiles(utilsHandler.getListViewList());
            dataUtils.setBooks(utilsHandler.getBookmarksList());
            ArrayList<String[]> servers = new ArrayList<String[]>();
            servers.addAll(utilsHandler.getSmbList());
            servers.addAll(utilsHandler.getSftpList());
            dataUtils.setServers(servers);
            return null;
        }

        @Override
        public Void onPostExecute(Object result) {
            drawer.refreshDrawer();
            if (savedInstanceState == null) {
                if (openProcesses) {
                    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                    transaction.replace(R.id.content_frame, new ProcessViewerFragment(), KEY_INTENT_PROCESS_VIEWER);
                    // transaction.addToBackStack(null);
                    drawer.setSomethingSelected(true);
                    openProcesses = false;
                    // title.setText(utils.getString(con, R.string.process_viewer));
                    // Commit the transaction
                    transaction.commit();
                    supportInvalidateOptionsMenu();
                } else if (intent.getAction() != null && intent.getAction().equals(TileService.ACTION_QS_TILE_PREFERENCES)) {
                    // tile preferences, open ftp fragment
                    FragmentTransaction transaction2 = getSupportFragmentManager().beginTransaction();
                    transaction2.replace(R.id.content_frame, new FTPServerFragment());
                    appBarLayout.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
                    drawer.setSomethingSelected(true);
                    drawer.deselectEverything();
                    transaction2.commit();
                } else {
                    if (path != null && path.length() > 0) {
                        HybridFile file = new HybridFile(OpenMode.UNKNOWN, path);
                        file.generateMode(MainActivity.this);
                        if (file.isDirectory(MainActivity.this))
                            goToMain(path);
                        else {
                            goToMain(null);
                            FileUtils.openFile(new File(path), MainActivity.this, getPrefs());
                        }
                    } else {
                        goToMain(null);
                    }
                }
            } else {
                pasteHelper = savedInstanceState.getParcelable(PASTEHELPER_BUNDLE);
                oppathe = savedInstanceState.getString(KEY_OPERATION_PATH);
                oppathe1 = savedInstanceState.getString(KEY_OPERATED_ON_PATH);
                oparrayList = savedInstanceState.getParcelableArrayList(KEY_OPERATIONS_PATH_LIST);
                operation = savedInstanceState.getInt(KEY_OPERATION);
            // mainFragment = (Main) savedInstanceState.getParcelable("main_fragment");
            }
            return null;
        }

        @Override
        public Void onPreExecute() {
            return null;
        }

        @Override
        public Void publishResult(Object... result) {
            return null;
        }

        @Override
        public <T> T[] params() {
            return null;
        }
    });
}
Also used : AppBar(com.amaze.filemanager.ui.views.appbar.AppBar) Arrays(java.util.Arrays) Bundle(android.os.Bundle) AppConfig(com.amaze.filemanager.utils.application.AppConfig) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ColorDrawable(android.graphics.drawable.ColorDrawable) SDK_INT(android.os.Build.VERSION.SDK_INT) AppTheme(com.amaze.filemanager.utils.theme.AppTheme) Handler(android.os.Handler) CryptHandler(com.amaze.filemanager.database.CryptHandler) ParseException(com.cloudrail.si.exceptions.ParseException) Shell(eu.chainfire.libsuperuser.Shell) PREFERENCE_SHOW_HIDDENFILES(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES) OnRequestPermissionsResultCallback(android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback) SshConnectionPool(com.amaze.filemanager.filesystem.ssh.SshConnectionPool) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) PREFERENCE_VIEW(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_VIEW) FABsMenu(jahirfiquitiva.libs.fabsmenu.FABsMenu) CloudPluginException(com.amaze.filemanager.exceptions.CloudPluginException) SmbConnectionListener(com.amaze.filemanager.ui.dialogs.SmbConnectDialog.SmbConnectionListener) R(com.amaze.filemanager.R) Snackbar(android.support.design.widget.Snackbar) CloudStorage(com.cloudrail.si.interfaces.CloudStorage) Environment(android.os.Environment) SftpConnectDialog(com.amaze.filemanager.ui.dialogs.SftpConnectDialog) DataChangeListener(com.amaze.filemanager.utils.DataUtils.DataChangeListener) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) NonNull(android.support.annotation.NonNull) CompressedExplorerFragment(com.amaze.filemanager.fragments.CompressedExplorerFragment) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) ArrayList(java.util.ArrayList) TileService(android.service.quicksettings.TileService) RenameBookmark(com.amaze.filemanager.ui.dialogs.RenameBookmark) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DataUtils(com.amaze.filemanager.utils.DataUtils) PreferenceUtils(com.amaze.filemanager.utils.PreferenceUtils) Menu(android.view.Menu) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) TextUtils(android.text.TextUtils) AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException) File(java.io.File) Utils(com.amaze.filemanager.utils.Utils) RingtoneManager(android.media.RingtoneManager) Configuration(android.content.res.Configuration) Box(com.cloudrail.si.services.Box) LinearLayout(android.widget.LinearLayout) BookSorter(com.amaze.filemanager.utils.BookSorter) PreferencesConstants(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) RootHelper(com.amaze.filemanager.filesystem.RootHelper) Drawer(com.amaze.filemanager.ui.views.drawer.Drawer) CopyService(com.amaze.filemanager.asynchronous.services.CopyService) ContentResolver(android.content.ContentResolver) CloudContract(com.amaze.filemanager.database.CloudContract) PasteHelper(com.amaze.filemanager.filesystem.PasteHelper) View(android.view.View) UsbManager(android.hardware.usb.UsbManager) GoogleDrive(com.cloudrail.si.services.GoogleDrive) LoaderManager(android.support.v4.app.LoaderManager) SmbConnectDialog(com.amaze.filemanager.ui.dialogs.SmbConnectDialog) TitleFAB(jahirfiquitiva.libs.fabsmenu.TitleFAB) AsyncTask(android.os.AsyncTask) OTGUtil(com.amaze.filemanager.utils.OTGUtil) CloudConnectionCallbacks(com.amaze.filemanager.fragments.CloudSheetFragment.CloudConnectionCallbacks) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) CloudRail(com.cloudrail.si.CloudRail) List(java.util.List) PrepareCopyTask(com.amaze.filemanager.asynchronous.asynctasks.PrepareCopyTask) CloudHandler(com.amaze.filemanager.database.CloudHandler) Pattern(java.util.regex.Pattern) PREFERENCE_COLORED_NAVIGATION(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_COLORED_NAVIGATION) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Tab(com.amaze.filemanager.database.models.Tab) Window(android.view.Window) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActivityManager(android.app.ActivityManager) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) TabFragment(com.amaze.filemanager.fragments.TabFragment) KeyEvent(android.view.KeyEvent) HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) FABsMenuListener(jahirfiquitiva.libs.fabsmenu.FABsMenuListener) UtilsHandler(com.amaze.filemanager.database.UtilsHandler) Intent(android.content.Intent) CursorLoader(android.support.v4.content.CursorLoader) TabHandler(com.amaze.filemanager.database.TabHandler) MenuItem(android.view.MenuItem) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) ServiceWatcherUtil(com.amaze.filemanager.utils.ServiceWatcherUtil) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) Build(android.os.Build) Cursor(android.database.Cursor) CloudEntry(com.amaze.filemanager.database.models.CloudEntry) Loader(android.support.v4.content.Loader) CustomSshJConfig(com.amaze.filemanager.filesystem.ssh.CustomSshJConfig) PREFERENCE_BOOKMARKS_ADDED(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_BOOKMARKS_ADDED) DialogAction(com.afollestad.materialdialogs.DialogAction) BookmarkCallback(com.amaze.filemanager.ui.dialogs.RenameBookmark.BookmarkCallback) OneDrive(com.cloudrail.si.services.OneDrive) Dropbox(com.cloudrail.si.services.Dropbox) MoveFiles(com.amaze.filemanager.asynchronous.asynctasks.MoveFiles) SearchWorkerFragment(com.amaze.filemanager.fragments.SearchWorkerFragment) HandlerThread(android.os.HandlerThread) PREFERENCE_NEED_TO_SET_HOME(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_NEED_TO_SET_HOME) FileUtils(com.amaze.filemanager.utils.files.FileUtils) CloudSheetFragment(com.amaze.filemanager.fragments.CloudSheetFragment) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) OpenMode(com.amaze.filemanager.utils.OpenMode) Collections(java.util.Collections) ContentUris(android.content.ContentUris) FileUtil(com.amaze.filemanager.filesystem.FileUtil) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) PREFERENCE_NEED_TO_SET_HOME(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants.PREFERENCE_NEED_TO_SET_HOME) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager) MainActivityHelper(com.amaze.filemanager.utils.MainActivityHelper) FragmentTransaction(android.support.v4.app.FragmentTransaction) AppBar(com.amaze.filemanager.ui.views.appbar.AppBar) AppConfig(com.amaze.filemanager.utils.application.AppConfig) CloudHandler(com.amaze.filemanager.database.CloudHandler) FTPServerFragment(com.amaze.filemanager.fragments.FTPServerFragment) TabHandler(com.amaze.filemanager.database.TabHandler) ProcessViewerFragment(com.amaze.filemanager.fragments.ProcessViewerFragment) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) HybridFile(com.amaze.filemanager.filesystem.HybridFile)

Example 3 with SDK_INT

use of android.os.Build.VERSION.SDK_INT in project MaxLock by Maxr1998.

the class MaxLockPreferenceFragment method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference.getKey() == null) {
        return false;
    }
    switch(screen) {
        case MAIN:
            switch(preference.getKey()) {
                case Common.ML_IMPLEMENTATION:
                    AlertDialog implementation = new AlertDialog.Builder(getContext()).setTitle(preference.getTitle()).setView(MLImplementation.createImplementationDialog(getContext())).setNegativeButton(android.R.string.ok, null).setOnDismissListener(dialog -> updateImplementationStatus()).create();
                    implementation.show();
                    return true;
                case Common.LOCKING_TYPE_SETTINGS:
                    launchFragment(this, Screen.TYPE.getScreen(), true);
                    return true;
                case Common.LOCKING_UI_SETTINGS:
                    launchFragment(this, Screen.UI.getScreen(), true);
                    return true;
                case Common.LOCKING_OPTIONS:
                    launchFragment(this, Screen.OPTIONS.getScreen(), true);
                    return true;
                case Common.IMOD_OPTIONS:
                    launchFragment(this, Screen.IMOD.getScreen(), true);
                    return true;
                case Common.CHOOSE_APPS:
                    launchFragment(this, new AppListFragment(), true);
                    return true;
                case Common.HIDE_APP_FROM_LAUNCHER:
                    TwoStatePreference hideApp = (TwoStatePreference) preference;
                    if (hideApp.isChecked()) {
                        Toast.makeText(getActivity(), R.string.reboot_required, Toast.LENGTH_SHORT).show();
                        ComponentName componentName = new ComponentName(getActivity(), "de.Maxr1998.xposed.maxlock.Main");
                        getActivity().getPackageManager().setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                    } else {
                        ComponentName componentName = new ComponentName(getActivity(), "de.Maxr1998.xposed.maxlock.Main");
                        getActivity().getPackageManager().setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    }
                    return true;
                case Common.USE_DARK_STYLE:
                case Common.USE_AMOLED_BLACK:
                case Common.ENABLE_PRO:
                    getActivity().recreate();
                    return true;
                case Common.ABOUT:
                    launchFragment(this, Screen.ABOUT.getScreen(), true);
                    return true;
                case Common.DONATE:
                    startActivity(new Intent(getActivity(), DonateActivity.class));
                    return true;
                case Common.UNINSTALL:
                    if (!((SettingsActivity) getActivity()).isDeviceAdminActive()) {
                        Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
                        intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, ((SettingsActivity) getActivity()).deviceAdmin);
                        startActivity(intent);
                    } else {
                        ((SettingsActivity) getActivity()).getDevicePolicyManager().removeActiveAdmin(((SettingsActivity) getActivity()).deviceAdmin);
                        preference.setTitle(R.string.pref_prevent_uninstall);
                        preference.setSummary(R.string.pref_prevent_uninstall_summary);
                        Intent uninstall = new Intent(Intent.ACTION_DELETE);
                        uninstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        uninstall.setData(Uri.parse("package:de.Maxr1998.xposed.maxlock"));
                        startActivity(uninstall);
                    }
                    return true;
                case Common.SEND_FEEDBACK:
                    File tempDirectory = new File(getActivity().getCacheDir(), "feedback-cache");
                    try {
                        // Obtain data
                        FileUtils.copyDirectoryToDirectory(new File(Util.dataDir(getActivity()), "shared_prefs"), tempDirectory);
                        FileUtils.writeStringToFile(new File(tempDirectory, "device-info.txt"), "App Version: " + BuildConfig.VERSION_NAME + "\n\n" + "Device: " + Build.MANUFACTURER + " " + Build.MODEL + " (" + Build.PRODUCT + ")\n" + "API: " + SDK_INT + ", Fingerprint: " + Build.FINGERPRINT, Charset.forName("UTF-8"));
                        Process process = Runtime.getRuntime().exec("logcat -d");
                        FileUtils.copyInputStreamToFile(process.getInputStream(), new File(tempDirectory, "logcat.txt"));
                        try {
                            String xposedDir = SDK_INT >= Build.VERSION_CODES.N ? "/data/user_de/0/" + Common.XPOSED_PACKAGE_NAME : getActivity().getPackageManager().getApplicationInfo(Common.XPOSED_PACKAGE_NAME, 0).dataDir;
                            File xposedLog = new File(xposedDir + "/log", "error.log");
                            if (xposedLog.exists())
                                FileUtils.copyFileToDirectory(xposedLog, tempDirectory);
                        } catch (PackageManager.NameNotFoundException e) {
                            e.printStackTrace();
                        }
                        // Create zip
                        File zipFile = new File(getActivity().getCacheDir() + File.separator + "export", "report.zip");
                        zipFile.getParentFile().mkdir();
                        FileUtils.deleteQuietly(zipFile);
                        ZipOutputStream stream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile)));
                        Util.writeDirectoryToZip(tempDirectory, stream);
                        stream.close();
                        FileUtils.deleteQuietly(tempDirectory);
                        Util.checkForStoragePermission(this, BUG_REPORT_STORAGE_PERMISSION_REQUEST_CODE, R.string.dialog_storage_permission_bug_report);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    return true;
            }
            break;
        case TYPE:
            switch(preference.getKey()) {
                case Common.LOCKING_TYPE_PASSWORD:
                    Util.setPassword(getActivity(), null);
                    return true;
                case Common.LOCKING_TYPE_PIN:
                    LockSetupFragment lsp = new LockSetupFragment();
                    Bundle b1 = new Bundle(1);
                    b1.putString(Common.LOCKING_TYPE, Common.LOCKING_TYPE_PIN);
                    lsp.setArguments(b1);
                    launchFragment(this, lsp, false);
                    return true;
                case Common.LOCKING_TYPE_KNOCK_CODE:
                    LockSetupFragment lsk = new LockSetupFragment();
                    Bundle b2 = new Bundle(1);
                    b2.putString(Common.LOCKING_TYPE, Common.LOCKING_TYPE_KNOCK_CODE);
                    lsk.setArguments(b2);
                    launchFragment(this, lsk, false);
                    return true;
                case Common.LOCKING_TYPE_PATTERN:
                    Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN, null, getActivity(), LockPatternActivity.class);
                    startActivityForResult(intent, KUtil.getPatternCode(-1));
                    return true;
            }
            break;
        case OPTIONS:
            switch(preference.getKey()) {
                case Common.VIEW_LOGS:
                    launchFragment(this, new LogViewerFragment(), false);
                    return true;
            }
            break;
        case ABOUT:
            switch(preference.getKey()) {
                case Common.SHOW_CHANGELOG:
                    showChangelog();
                    return true;
                case Common.VISIT_WEBSITE:
                    CustomTabsIntent devWebsite = new CustomTabsIntent.Builder(((SettingsActivity) getActivity()).getSession()).setShowTitle(true).enableUrlBarHiding().setToolbarColor(Color.parseColor("#ffc107")).build();
                    devWebsite.launchUrl(getActivity(), Common.MAXR1998_URI);
                    return true;
                case Common.TECHNOSPARKS_PROFILE:
                    CustomTabsIntent technosparksSite = new CustomTabsIntent.Builder(((SettingsActivity) getActivity()).getSession()).setShowTitle(true).enableUrlBarHiding().setToolbarColor(Color.parseColor("#6d993f")).build();
                    technosparksSite.launchUrl(getActivity(), Common.TECHNO_SPARKS_URI);
                    return true;
            }
            break;
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) BuildConfig(de.Maxr1998.xposed.maxlock.BuildConfig) Uri(android.net.Uri) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) LockPatternActivity(com.haibison.android.lockpattern.LockPatternActivity) ColorDrawable(android.graphics.drawable.ColorDrawable) PreferenceScreen(android.preference.PreferenceScreen) SDK_INT(android.os.Build.VERSION.SDK_INT) VisibleForTesting(android.support.annotation.VisibleForTesting) Util(de.Maxr1998.xposed.maxlock.util.Util) PreferenceFragmentCompat(android.support.v4.preference.PreferenceFragmentCompat) CheckBox(android.widget.CheckBox) MLImplementation(de.Maxr1998.xposed.maxlock.MLImplementation) WebViewClient(android.webkit.WebViewClient) View(android.view.View) BUTTON_NEUTRAL(android.content.DialogInterface.BUTTON_NEUTRAL) WebView(android.webkit.WebView) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) FileProvider.getUriForFile(android.support.v4.content.FileProvider.getUriForFile) PorterDuff(android.graphics.PorterDuff) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) IOUtils(org.apache.commons.io.IOUtils) ListPreference(android.preference.ListPreference) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) Snackbar(android.support.design.widget.Snackbar) SettingsActivity(de.Maxr1998.xposed.maxlock.ui.SettingsActivity) ZipOutputStream(java.util.zip.ZipOutputStream) Context(android.content.Context) PreferenceCategory(android.preference.PreferenceCategory) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) XmlRes(android.support.annotation.XmlRes) BufferedOutputStream(java.io.BufferedOutputStream) FingerprintManagerCompat(android.support.v4.hardware.fingerprint.FingerprintManagerCompat) SuppressLint(android.annotation.SuppressLint) KUtil(de.Maxr1998.xposed.maxlock.util.KUtil) Charset(java.nio.charset.Charset) DevicePolicyManager(android.app.admin.DevicePolicyManager) READ_EXTERNAL_STORAGE(android.Manifest.permission.READ_EXTERNAL_STORAGE) Toast(android.widget.Toast) Build(android.os.Build) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) DialogInterface(android.content.DialogInterface) BUTTON_POSITIVE(android.content.DialogInterface.BUTTON_POSITIVE) ImplementationPreference(de.Maxr1998.xposed.maxlock.preference.ImplementationPreference) MLPreferences(de.Maxr1998.xposed.maxlock.util.MLPreferences) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Common(de.Maxr1998.xposed.maxlock.Common) File(java.io.File) R(de.Maxr1998.xposed.maxlock.R) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) InputStream(java.io.InputStream) TwoStatePreference(android.preference.TwoStatePreference) Bundle(android.os.Bundle) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) IOException(java.io.IOException) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PackageManager(android.content.pm.PackageManager) ZipOutputStream(java.util.zip.ZipOutputStream) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) FileOutputStream(java.io.FileOutputStream) ComponentName(android.content.ComponentName) FileProvider.getUriForFile(android.support.v4.content.FileProvider.getUriForFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

Activity (android.app.Activity)3 Context (android.content.Context)3 Intent (android.content.Intent)3 PackageManager (android.content.pm.PackageManager)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Uri (android.net.Uri)3 Build (android.os.Build)3 SDK_INT (android.os.Build.VERSION.SDK_INT)3 Bundle (android.os.Bundle)3 NonNull (android.support.annotation.NonNull)3 Snackbar (android.support.design.widget.Snackbar)3 Fragment (android.support.v4.app.Fragment)3 FragmentTransaction (android.support.v4.app.FragmentTransaction)3 READ_EXTERNAL_STORAGE (android.Manifest.permission.READ_EXTERNAL_STORAGE)2 SuppressLint (android.annotation.SuppressLint)2 DevicePolicyManager (android.app.admin.DevicePolicyManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ComponentName (android.content.ComponentName)2 DialogInterface (android.content.DialogInterface)2 BUTTON_NEUTRAL (android.content.DialogInterface.BUTTON_NEUTRAL)2