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();
}
}
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;
}
});
}
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);
}
Aggregations