Эх сурвалжийг харах

getWindow(): The current window, or null if the activity is not visual.

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 7 жил өмнө
parent
commit
d996b0d0e8

+ 6 - 4
src/main/java/com/owncloud/android/authentication/PassCodeManager.java

@@ -67,10 +67,12 @@ 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);
+        if (activity.getWindow() != null) {
+            if (passCodeIsEnabled() || deviceCredentialsAreEnabled(activity)) {
+                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
+            } else {
+                activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
+            }
         }
     }
 

+ 3 - 1
src/main/java/com/owncloud/android/ui/activity/ExternalSiteWebView.java

@@ -69,7 +69,9 @@ public class ExternalSiteWebView extends FileActivity {
         showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR);
 
         // show progress
-        getWindow().requestFeature(Window.FEATURE_PROGRESS);
+        if (getWindow() != null) {
+            getWindow().requestFeature(Window.FEATURE_PROGRESS);
+        }
 
         super.onCreate(savedInstanceState);
         setContentView(R.layout.externalsite_webview);

+ 4 - 0
src/main/java/com/owncloud/android/ui/activity/PassCodeActivity.java

@@ -113,6 +113,10 @@ public class PassCodeActivity extends AppCompatActivity {
         mPassCodeEditTexts[3].setTextColor(elementColor);
         mPassCodeEditTexts[3].getBackground().setColorFilter(elementColor, PorterDuff.Mode.SRC_ATOP);
 
+        if (getWindow() != null) {
+            getWindow().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);

+ 22 - 16
src/main/java/com/owncloud/android/ui/activity/Preferences.java

@@ -767,25 +767,31 @@ 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)));
+        if (getWindow() != null) {
+            getWindow().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) {
+                getWindow().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");
+            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));
+            }
         }
     }
 

+ 5 - 1
src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.java

@@ -105,7 +105,11 @@ 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);
+
+        if (d.getWindow() != null) {
+            d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+        }
+        
         return d;
     }    
     

+ 5 - 1
src/main/java/com/owncloud/android/ui/dialog/CredentialsDialogFragment.java

@@ -104,7 +104,11 @@ public class CredentialsDialogFragment extends DialogFragment
                 .setNegativeButton(R.string.common_cancel, this);
 
         Dialog d = authDialog.create();
-        d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+
+        if (d.getWindow() != null) {
+            d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+        }
+        
         return d;
     }
 

+ 5 - 1
src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.java

@@ -119,7 +119,11 @@ 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);
+
+        if (d.getWindow() != null) {
+            d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+        }
+        
         return d;
     }    
 

+ 5 - 1
src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java

@@ -118,7 +118,11 @@ 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);
+
+        if (d.getWindow() != null) {
+            d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
+        }
+        
         return d;
     }
 

+ 3 - 1
src/main/java/com/owncloud/android/utils/ThemeUtils.java

@@ -315,7 +315,9 @@ public class ThemeUtils {
      */
     public static void colorStatusBar(FragmentActivity fragmentActivity, @ColorInt int color) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-            fragmentActivity.getWindow().setStatusBarColor(color);
+            if (fragmentActivity.getWindow() != null) {
+                fragmentActivity.getWindow().setStatusBarColor(color);
+            }
         }
     }