Skip to content

Commit

Permalink
增加loadingview“
Browse files Browse the repository at this point in the history
  • Loading branch information
zjlong committed Jun 1, 2016
1 parent 99af799 commit c4edf23
Show file tree
Hide file tree
Showing 22 changed files with 175 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.widget.ImageView;

import com.android.core.ui.BaseActivity;
import com.android.core.util.StatusBarUtil;
import com.android.core.control.StatusBarUtil;
import com.zhoujinlong.R;
import com.zhoujinlong.util.AnimationUtil;

Expand Down
18 changes: 4 additions & 14 deletions app/src/main/java/com/zhoujinlong/ui/fragment/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.android.core.ui.BaseFragment;
import com.android.core.util.StatusBarUtil;
import com.android.core.control.XRecyclerViewControl;
import com.android.core.widget.CustomViewpager;
import com.android.core.widget.SpacesItemDecoration;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zhoujinlong.R;
import com.zhoujinlong.adapter.CustomViewPageAdapter;
Expand Down Expand Up @@ -49,7 +46,6 @@ protected int getLayoutResource() {

@Override
protected void onInitView() {
StatusBarUtil.setTransparent(getActivity());
}

@Override
Expand All @@ -70,15 +66,7 @@ public static List<Integer> getAdData() {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//分割线
mRecyclerView.addItemDecoration(new SpacesItemDecoration(1));
mRecyclerView.setLayoutManager(layoutManager);

mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
mRecyclerView.setArrowImageView(R.drawable.abc_icon_down_arrow);
XRecyclerViewControl.init().setLinearLayout(getActivity(), mRecyclerView);

View header = View.inflate(getActivity(), R.layout.abc_viewpager_view, null);
mViewpage = (CustomViewpager) header.findViewById(R.id.viewpager);
Expand Down Expand Up @@ -111,6 +99,7 @@ public void onLoadComplete() {
*/
@Override
public void onShowListData(Classify listData, boolean isMore) {
hideLoadingView();
if (listData.isStatus()) {
if (!isMore)
classifys.clear();
Expand All @@ -121,6 +110,7 @@ public void onShowListData(Classify listData, boolean isMore) {

@Override
public void onRefresh() {
showLoadingView();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.widget.ScrollView;

import com.android.core.ui.BaseFragment;
import com.android.core.util.StatusBarUtil;
import com.android.core.control.StatusBarUtil;
import com.zhoujinlong.R;

import butterknife.Bind;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/zhoujinlong/ui/widget/TitleBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.core.util.ScreenUtil;
import com.android.core.control.ScreenUtil;
import com.zhoujinlong.R;

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/abc_viewpager_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<com.android.core.widget.CustomViewpager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_height="140dp"
android:background="@color/abc_tab_text_normal" />
</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_compete_classitfy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ImageView
android:id="@+id/sv_classitfy_img"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_height="250dp"
android:background="@color/abc_theme_black_7f"
android:scaleType="centerCrop" />

Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
compile 'com.jcodecraeer:xrecyclerview:1.2.7'
compile 'com.jakewharton:butterknife:7.0.1'

// Glide
compile 'com.github.ybq:Android-SpinKit:1.0.1'
compile 'com.github.bumptech.glide:glide:3.7.0'

//squareup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.android.core.util;
package com.android.core.control;

import android.content.Context;
import android.content.Intent;
Expand All @@ -9,7 +9,7 @@
* @date: 2016-05-26 17:47
* @GitHub: https://github.com/meikoz
*/
public class MobileUtil {
public class MobileControl {
//调起拨号键
public static void startPanel(Context context, String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.android.core.util;
package com.android.core.control;

import android.content.Context;
import android.net.ConnectivityManager;
Expand All @@ -12,7 +12,7 @@
* @date: 2016-05-31 14:15
* @GitHub: https://github.com/meikoz
*/
public class NetWorkUtil {
public class NetWorkControl {

/**
* 检测网络是否连接
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.android.core.util;
package com.android.core.control;

import android.content.Context;
import android.content.res.TypedArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.android.core.util;
package com.android.core.control;

import android.annotation.TargetApi;
import android.app.Activity;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.android.core.control;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;

import com.android.core.R;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

/**
* @author: 蜡笔小新
* @date: 2016-06-01 17:42
* @GitHub: https://github.com/meikoz
*/
public class XRecyclerViewControl {
static XRecyclerViewControl ourInstance;

public XRecyclerViewControl() {

}

public static XRecyclerViewControl init() {
if (ourInstance == null)
ourInstance = new XRecyclerViewControl();
return ourInstance;
}


public void setLinearLayout(Context context, XRecyclerView mRecy) {
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

mRecy.setLayoutManager(layoutManager);
//设置分隔线
// mRecy.addItemDecoration(new SpacesItemDecoration(1));
mRecy.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
mRecy.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
mRecy.setArrowImageView(R.drawable.abc_icon_down_arrow);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.util.Log;

import com.android.core.MainApp;
import com.android.core.util.NetWorkUtil;
import com.android.core.control.NetWorkControl;

import java.io.IOException;

Expand All @@ -22,15 +22,15 @@ public class HttpCacheInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (!NetWorkUtil.isNetConnected(MainApp.getContext())) {
if (!NetWorkControl.isNetConnected(MainApp.getContext())) {
request = request.newBuilder()
.cacheControl(CacheControl.FORCE_CACHE)
.build();
Log.d("okhttp", "no network");
}

Response originalResponse = chain.proceed(request);
if (NetWorkUtil.isNetConnected(MainApp.getContext())) {
if (NetWorkControl.isNetConnected(MainApp.getContext())) {
//有网的时候读接口上的@Headers里的配置,你可以在这里进行统一的设置
String cacheControl = request.cacheControl().toString();
return originalResponse.newBuilder()
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/com/android/core/ui/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.Window;

import com.android.core.model.control.LogicProxy;
import com.android.core.widget.LoadingView;

import butterknife.ButterKnife;

Expand All @@ -16,12 +17,15 @@
*/
public abstract class BaseActivity extends Activity {

private LoadingView mLoadingView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(getLayoutResource());
ButterKnife.bind(this);
mLoadingView = new LoadingView(this);
onInitView();
onInitData();
}
Expand All @@ -44,6 +48,14 @@ public void startActivity(Intent intent) {
// 打开Activity动画
}

public void showLoadView() {
mLoadingView.show();
}

public void hideLoadView() {
mLoadingView.hide();
}

//获得该页面的实例
public <T> T getLogicImpl(Class cls, Object o) {
return LogicProxy.getInstance().bind(cls, o);
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/com/android/core/ui/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.ViewGroup;

import com.android.core.model.control.LogicProxy;
import com.android.core.widget.LoadingView;

import butterknife.ButterKnife;

Expand All @@ -18,13 +19,15 @@
*/
public abstract class BaseFragment extends Fragment {
protected View rootView;
private LoadingView mLoginView;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (rootView == null)
rootView = inflater.inflate(getLayoutResource(), container, false);
ButterKnife.bind(this, rootView);
mLoginView = new LoadingView(getActivity());
onInitView();
onInitData();
return rootView;
Expand All @@ -36,6 +39,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

protected abstract void onInitData();

public void showLoadingView() {
mLoginView.show();
}

public void hideLoadingView() {
mLoginView.hide();
}

//获得该页面的实例
public <T> T getLogicImpl(Class cls, Object o) {
return LogicProxy.getInstance().bind(cls, o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import com.android.core.R;
import com.android.core.iface.CustomInterface;
import com.android.core.util.ScreenUtil;
import com.android.core.control.ScreenUtil;

/**
* @author: 蜡笔小新
Expand Down
65 changes: 65 additions & 0 deletions core/src/main/java/com/android/core/widget/LoadingView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.android.core.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;

import com.android.core.R;
import com.github.ybq.android.spinkit.style.DoubleBounce;
/**
* @author: 蜡笔小新
* @date: 2016-06-01 17:58
* @GitHub: https://github.com/meikoz
*/
public class LoadingView extends Dialog implements View.OnClickListener {

int[] colors = new int[]{
android.graphics.Color.parseColor("#D55400"),
android.graphics.Color.parseColor("#2B3E51"),
android.graphics.Color.parseColor("#00BD9C"),
android.graphics.Color.parseColor("#227FBB"),
android.graphics.Color.parseColor("#7F8C8D"),
android.graphics.Color.parseColor("#FFCC5C"),
android.graphics.Color.parseColor("#D55400"),
android.graphics.Color.parseColor("#1AAF5D"),
};

public LoadingView(Context context) {
super(context, R.style.loading_dialog_style);
onInit();
}

private void onInit() {
View view = getLayoutInflater().inflate(R.layout.abc_view_loading, null);

ProgressBar mProgressBar = (ProgressBar) view.findViewById(R.id.progress);
DoubleBounce doubleBounce = new DoubleBounce();
doubleBounce.setBounds(0, 0,
100,
100);
doubleBounce.setColor(colors[7]);
mProgressBar.setIndeterminateDrawable(doubleBounce);

view.setOnClickListener(this);
setContentView(view);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}

@Override
public void onClick(View v) {
this.dismiss();
}

@Override
public void show() {
super.show();
}


@Override
public void dismiss() {
super.dismiss();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import android.widget.TextView;

import com.android.core.R;
import com.android.core.util.ScreenUtil;
import com.android.core.control.ScreenUtil;

import java.util.ArrayList;
import java.util.List;
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/res/layout/abc_view_loading.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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"
android:background="@color/abc_white">

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true" />

</RelativeLayout>
Loading

0 comments on commit c4edf23

Please sign in to comment.