Skip to content

Commit

Permalink
解除SwipeBackFragment与SwipeBackActivity的耦合
Browse files Browse the repository at this point in the history
  • Loading branch information
YoKeyword committed May 18, 2017
1 parent 3745198 commit ac4240c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions swipeback/src/main/java/me/yokeyword/swipebackfragment/SwipeBackFragment.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package me.yokeyword.swipebackfragment;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
Expand All @@ -25,16 +23,12 @@ public class SwipeBackFragment extends Fragment {
private Animation mNoAnim;
boolean mLocking = false;

protected SwipeBackActivity _mActivity;
protected Activity _mActivity;

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof SwipeBackActivity) {
_mActivity = (SwipeBackActivity) activity;
} else {
throw new RuntimeException(activity.toString() + " must extends SwipeBackActivity");
}
_mActivity = activity;
}

@Override
Expand Down Expand Up @@ -105,7 +99,10 @@ private void initFragmentBackground(View view) {

private void setBackground(View view) {
if (view != null && view.getBackground() == null) {
int defaultBg = _mActivity.getDefaultFragmentBackground();
int defaultBg = 0;
if (_mActivity instanceof SwipeBackActivity) {
defaultBg = ((SwipeBackActivity) _mActivity).getDefaultFragmentBackground();
}
if (defaultBg == 0) {
int background = getWindowBackground();
view.setBackgroundResource(background);
Expand Down

0 comments on commit ac4240c

Please sign in to comment.