Skip to content

Commit

Permalink
取消对fragment的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshuisheng committed Dec 23, 2016
1 parent bd3e33f commit f2e1664
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 26 deletions.
6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.hss01248.pagestate.demo;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.hss01248.pagestate.PageListener;
import com.hss01248.pagestate.PageManager;

import java.util.Random;
Expand All @@ -21,7 +19,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

PageManager.initInApp(getApplicationContext());
PageManager.initInApp(getApplicationContext(),R.layout.pager_empty,R.layout.pager_loading,R.layout.pager_error);


pageStateManager = PageManager.init(this, "空空快快快快快快快快快快快快",true,new Runnable() {
@Override
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/layout/pager_empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/empty_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:src="@drawable/ic_empty_page" />
<TextView
android:id="@+id/tv_msg_empty"
android:layout_below="@id/empty_icon"
android:layout_marginTop="15dp"
android:textSize="15sp"
android:layout_centerHorizontal="true"
android:text="咦...没有任何内容,先去逛逛别的吧"
android:textColor="#666666"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


</RelativeLayout>
46 changes: 46 additions & 0 deletions app/src/main/res/layout/pager_error.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout

android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:src="@drawable/ic_error_page" />

<TextView
android:id="@+id/tv_msg_error"
android:text="来到一个没有网络的异次元"
android:textColor="#333333"
android:textSize="13sp"
android:gravity="center"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/error_btn_retry"
android:layout_width="wrap_content"
android:layout_height="34dp"
android:gravity="center"

android:background="@drawable/selector_btn_bg"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:text="加载失败,点击重试"
android:textColor="#ff717171"
android:textSize="14sp" />
</LinearLayout>

</RelativeLayout>
29 changes: 29 additions & 0 deletions app/src/main/res/layout/pager_loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<ProgressBar
android:id="@+id/progressbar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/progressstyleshape"
android:indeterminateDuration="1200"
android:indeterminateBehavior="repeat"
/>

<TextView
android:text="加载中..."
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/progressbar"
android:textSize="16sp"
android:textColor="#333333"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />



</RelativeLayout>
38 changes: 22 additions & 16 deletions lib/src/main/java/com/hss01248/pagestate/PageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void initInApp(Context appContext,int layoutIdOfEmpty,int layoutId

/**
*
* @param container 必须为activity,fragment或者view.如果是view,则该view对象必须有parent
* @param container 必须为activity或者view.如果是view,则该view对象必须有parent
* @param retryAction 点击重试的动作,注意,只需要关注有网络的情况,无网络状态时已经封装好:弹出对话框询问用户是否去设置网络
* @param isShowLoadingOrContent 第一次是显示loading(true)还是content(false)
* @return 当前页面的状态管理器
Expand Down Expand Up @@ -272,36 +272,42 @@ public void setRetryEvent(View retryView)
};


public PageManager(Object activityOrFragmentOrView, PageListener listener)
public PageManager(Object activityOrView, PageListener listener)
{
if (listener == null) listener = DEFAULT_LISTENER;

ViewGroup contentParent = null;
Context context;
if (activityOrFragmentOrView instanceof Activity)
{
Activity activity = (Activity) activityOrFragmentOrView;
if (activityOrView instanceof Activity) {
Activity activity = (Activity) activityOrView;
context = activity;
contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
} else if (activityOrFragmentOrView instanceof Fragment)
{
Fragment fragment = (Fragment) activityOrFragmentOrView;
} else if (activityOrView instanceof Fragment) {

Fragment fragment = (Fragment) activityOrView;
context = fragment.getActivity();
contentParent = (ViewGroup) (fragment.getView().getParent());
} else if (activityOrFragmentOrView instanceof View)
{
View view = (View) activityOrFragmentOrView;

throw new IllegalArgumentException("the support for fragment has been canceled,please use give me a view object which has a parent");

} else if (activityOrView instanceof View) {
View view = (View) activityOrView;
contentParent = (ViewGroup) (view.getParent());
if(contentParent == null){
throw new IllegalArgumentException("the view must already has a parent ");
}
context = view.getContext();
} else{
throw new IllegalArgumentException("the container's type must be Fragment or Activity or a view which already has a parent ");
throw new IllegalArgumentException("the container's type must be Fragment or Activity or a view ");
}


int childCount = contentParent.getChildCount();
//get contentParent
int index = 0;
View oldContent;
if (activityOrFragmentOrView instanceof View){
oldContent = (View) activityOrFragmentOrView;
if (activityOrView instanceof View){
oldContent = (View) activityOrView;
for (int i = 0; i < childCount; i++)
{
if (contentParent.getChildAt(i) == oldContent)
Expand Down Expand Up @@ -388,9 +394,9 @@ private void setupRetryLayout(PageListener listener, PageLayout loadingAndRetryL
}
}

public static PageManager generate(Object activityOrFragment, PageListener listener)
public static PageManager generate(Object activityOrView, PageListener listener)
{
return new PageManager(activityOrFragment, listener);
return new PageManager(activityOrView, listener);
}


Expand Down

0 comments on commit f2e1664

Please sign in to comment.