diff --git a/src/main/java/com/owncloud/android/authentication/PassCodeManager.java b/src/main/java/com/owncloud/android/authentication/PassCodeManager.java index bf2270f86e..53d6ff5cc6 100644 --- a/src/main/java/com/owncloud/android/authentication/PassCodeManager.java +++ b/src/main/java/com/owncloud/android/authentication/PassCodeManager.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.PowerManager; +import android.view.Window; import android.view.WindowManager; import com.owncloud.android.MainApp; @@ -67,10 +68,13 @@ public class PassCodeManager { private PassCodeManager() {} public void onActivityCreated(Activity activity) { - if (passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) { - activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); - } else { - activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + Window window = activity.getWindow(); + if (window != null) { + if (passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) { + window.addFlags(WindowManager.LayoutParams.FLAG_SECURE); + } else { + window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE); + } } } diff --git a/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java b/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java index 9e80fee2bb..931f1d3ab6 100644 --- a/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java +++ b/src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java @@ -69,7 +69,10 @@ public class ExternalSiteWebView extends FileActivity { showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR); // show progress - getWindow().requestFeature(Window.FEATURE_PROGRESS); + Window window = getWindow(); + if (window != null) { + window.requestFeature(Window.FEATURE_PROGRESS); + } super.onCreate(savedInstanceState); setContentView(R.layout.externalsite_webview); diff --git a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java index aa5cd9dc59..6dcc7865d3 100644 --- a/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java @@ -34,6 +34,7 @@ import android.text.TextWatcher; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; +import android.view.Window; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; @@ -99,8 +100,7 @@ public class PassCodeActivity extends AppCompatActivity { mPassCodeEditTexts[0].setTextColor(elementColor); mPassCodeEditTexts[0].getBackground().setColorFilter(elementColor, PorterDuff.Mode.SRC_ATOP); mPassCodeEditTexts[0].requestFocus(); - getWindow().setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); - + mPassCodeEditTexts[1] = findViewById(R.id.txt1); mPassCodeEditTexts[1].setTextColor(elementColor); mPassCodeEditTexts[1].getBackground().setColorFilter(elementColor, PorterDuff.Mode.SRC_ATOP); @@ -113,6 +113,11 @@ public class PassCodeActivity extends AppCompatActivity { mPassCodeEditTexts[3].setTextColor(elementColor); mPassCodeEditTexts[3].getBackground().setColorFilter(elementColor, PorterDuff.Mode.SRC_ATOP); + Window window = getWindow(); + if (window != null) { + window.setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } + if (ACTION_CHECK.equals(getIntent().getAction())) { /// this is a pass code request; the user has to input the right value mPassCodeHdr.setText(R.string.pass_code_enter_pass_code); diff --git a/src/main/java/com/owncloud/android/ui/activity/Preferences.java b/src/main/java/com/owncloud/android/ui/activity/Preferences.java index b1fdef81ac..eaabc40987 100644 --- a/src/main/java/com/owncloud/android/ui/activity/Preferences.java +++ b/src/main/java/com/owncloud/android/ui/activity/Preferences.java @@ -55,6 +55,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.webkit.URLUtil; import com.owncloud.android.BuildConfig; @@ -767,25 +768,29 @@ public class Preferences extends PreferenceActivity private void setupActionBar() { ActionBar actionBar = getDelegate().getSupportActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - ThemeUtils.setColoredTitle(actionBar, getString(R.string.actionbar_settings), this); - actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor(this))); - getWindow().getDecorView().setBackgroundDrawable(new ColorDrawable(ResourcesCompat - .getColor(getResources(), R.color.background_color, null))); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - getWindow().setStatusBarColor(ThemeUtils.primaryDarkColor(this)); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + ThemeUtils.setColoredTitle(actionBar, getString(R.string.actionbar_settings), this); + actionBar.setBackgroundDrawable(new ColorDrawable(ThemeUtils.primaryColor(this))); + + Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back); + actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this))); } - Drawable backArrow = getResources().getDrawable(R.drawable.ic_arrow_back); - actionBar.setHomeAsUpIndicator(ThemeUtils.tintDrawable(backArrow, ThemeUtils.fontColor(this))); + Window window = getWindow(); + if (window != null) { + window.getDecorView().setBackgroundDrawable(new ColorDrawable(ResourcesCompat + .getColor(getResources(), R.color.background_color, null))); - // For adding content description tag to a title field in the action bar - int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android"); - View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId); - if (actionBarTitleView != null) { // it's null in Android 2.x - getWindow().getDecorView().findViewById(actionBarTitleId). - setContentDescription(getString(R.string.actionbar_settings)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + window.setStatusBarColor(ThemeUtils.primaryDarkColor(this)); + } + + // For adding content description tag to a title field in the action bar + int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android"); + window.getDecorView().findViewById(actionBarTitleId). + setContentDescription(getString(R.string.actionbar_settings)); } } diff --git a/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.java index 05012b12c5..504cf51304 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.java @@ -29,6 +29,7 @@ import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; +import android.view.Window; import android.view.WindowManager.LayoutParams; import android.widget.EditText; import android.widget.TextView; @@ -105,7 +106,12 @@ public class CreateFolderDialogFragment .setTitle(ThemeUtils.getColoredTitle(getResources().getString(R.string.uploader_info_dirname), accentColor)); Dialog d = builder.create(); - d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + + Window window = d.getWindow(); + if (window != null) { + window.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } + return d; } diff --git a/src/main/java/com/owncloud/android/ui/dialog/CredentialsDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/CredentialsDialogFragment.java index 2fd4d775e1..809581a90e 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/CredentialsDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/CredentialsDialogFragment.java @@ -26,6 +26,7 @@ import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog.Builder; import android.text.InputType; +import android.view.Window; import android.view.WindowManager.LayoutParams; import android.webkit.HttpAuthHandler; import android.webkit.WebView; @@ -104,7 +105,12 @@ public class CredentialsDialogFragment extends DialogFragment .setNegativeButton(R.string.common_cancel, this); Dialog d = authDialog.create(); - d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + + Window window = d.getWindow(); + if (window != null) { + window.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } + return d; } diff --git a/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java index 9f2beb805a..5f13556ce3 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java @@ -35,6 +35,7 @@ import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; +import android.view.Window; import android.view.WindowManager.LayoutParams; import android.widget.EditText; import android.widget.TextView; @@ -119,7 +120,12 @@ public class RenameFileDialogFragment .setTitle(ThemeUtils.getColoredTitle(getResources().getString(R.string.rename_dialog_title), accentColor)); Dialog d = builder.create(); - d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + + Window window = d.getWindow(); + if (window != null) { + window.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } + return d; } diff --git a/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java b/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java index 55aa75fb3a..130ae7f259 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java @@ -32,6 +32,7 @@ import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView; @@ -118,7 +119,12 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo .setNeutralButton(R.string.common_delete, this) .setTitle(R.string.share_link_password_title); Dialog d = builder.create(); - d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + + Window window = d.getWindow(); + if (window != null) { + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } + return d; } diff --git a/src/main/java/com/owncloud/android/utils/ThemeUtils.java b/src/main/java/com/owncloud/android/utils/ThemeUtils.java index 82bddfe2c3..41bef373b4 100644 --- a/src/main/java/com/owncloud/android/utils/ThemeUtils.java +++ b/src/main/java/com/owncloud/android/utils/ThemeUtils.java @@ -46,6 +46,7 @@ import android.support.v7.widget.AppCompatCheckBox; import android.support.v7.widget.SwitchCompat; import android.text.Html; import android.text.Spanned; +import android.view.Window; import android.widget.ImageButton; import android.widget.ProgressBar; import android.widget.SeekBar; @@ -314,8 +315,9 @@ public class ThemeUtils { * @param color the color */ public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt int color) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - fragmentActivity.getWindow().setStatusBarColor(color); + Window window = fragmentActivity.getWindow(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && window != null) { + window.setStatusBarColor(color); } } @@ -414,4 +416,4 @@ public class ThemeUtils { return new OCCapability(); } } -} \ No newline at end of file +}