Skip to content

Commit

Permalink
支持同时操作多个Loading
Browse files Browse the repository at this point in the history
  • Loading branch information
xiandanin committed Aug 16, 2016
1 parent c96c024 commit 266cef5
Show file tree
Hide file tree
Showing 16 changed files with 354 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
1 change: 1 addition & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</intent-filter>
</activity>
<activity android:name=".ExampleActivity"/>
<activity android:name=".MutiFragmentActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_example);
lv= (ListView) this.findViewById(R.id.lv);

LoadingBar.show(getWindow().getDecorView());
final LoadingBar loadingBar = LoadingBar.show(getWindow().getDecorView());

lv.postDelayed(new Runnable() {
@Override
public void run() {
lv.setAdapter(new ArrayAdapter<String>(ExampleActivity.this,android.R.layout.simple_list_item_1,testData()));
LoadingBar.hide();
loadingBar.cancel();
}
},2000);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class MainActivity extends AppCompatActivity {
View frameLayout;
LoadingBar loadingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -22,23 +23,23 @@ protected void onCreate(Bundle savedInstanceState) {
* @param v
*/
public void showLoading(View v){
LoadingBar.show(frameLayout);
loadingBar=LoadingBar.show(frameLayout);
}

/**
* 显示自定义样式Loading
* @param v
*/
public void showCustomLoading(View v){
LoadingBar.show(frameLayout,View.inflate(this,R.layout.custom_loading,null),null);
loadingBar=LoadingBar.show(frameLayout,View.inflate(this,R.layout.custom_loading,null),null);
}

/**
* 带有点击事件Loading
* @param v
*/
public void showClickLoading(View v){
LoadingBar.show(frameLayout, View.inflate(this, R.layout.custom_error, null), new View.OnClickListener() {
loadingBar=LoadingBar.show(frameLayout, View.inflate(this, R.layout.custom_error, null), new View.OnClickListener() {
@Override
public void onClick(View v) {
//在这里处理点击LoadingBar后的要做的操作
Expand All @@ -52,9 +53,19 @@ public void onClick(View v) {
* @param v
*/
public void hideLoading(View v){
LoadingBar.hide();
loadingBar.cancel();
}

/**
* 多Fragment显示Loading
* @param v
*/
public void multiLoading(View v){
startActivity(new Intent(this,MutiFragmentActivity.class));
}



@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_MENU){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dyhdyh.loadingbar.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

import com.dyhdyh.loadingbar.example.fragment.ContentFragment;

import java.util.ArrayList;
import java.util.List;

/**
* author dengyuhan
* created 2016/8/16 9:41
*/
public class MutiFragmentActivity extends FragmentActivity{
private String[] title= new String[]{"新闻", "图片", "视频"};
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_muti);

List<Fragment> fragments=new ArrayList<>();
for (int i = 0; i <title.length ; i++) {
Fragment fragment=new ContentFragment();
Bundle bundle = new Bundle();
bundle.putString("title",title[i]);
fragment.setArguments(bundle);
fragments.add(fragment);
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment1,fragments.get(0));
transaction.replace(R.id.fragment2,fragments.get(1));
transaction.replace(R.id.fragment3,fragments.get(2));
transaction.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.dyhdyh.loadingbar.example.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dyhdyh.loadingbar.example.R;
import com.dyhdyh.widget.loadingbar.LoadingBar;

import java.util.Random;

/**
* author dengyuhan
* created 2016/8/16 9:44
*/
public class ContentFragment extends Fragment{
private Handler handler=new Handler();
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
String title=getArguments().getString("title");
View layout = inflater.inflate(R.layout.fragment_content, null);
TextView tv= (TextView) layout.findViewById(R.id.tv);
tv.setText(title);
Random random=new Random();
layout.setBackgroundColor(Color.rgb(random.nextInt(255),random.nextInt(255),random.nextInt(255)));
return layout;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

request();
}

/**
* 模拟请求
*/
public void request(){
final LoadingBar loadingBar = LoadingBar.show(getView());
Random random=new Random();
int nextInt = random.nextInt(3000);
handler.postDelayed(new Runnable() {
@Override
public void run() {
loadingBar.cancel();
}
},nextInt);
}
}
1 change: 1 addition & 0 deletions example/src/main/res/layout/activity_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
Expand Down
6 changes: 6 additions & 0 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<Button
android:onClick="multiLoading"
android:text="多Fragment显示Loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
Expand Down
28 changes: 28 additions & 0 deletions example/src/main/res/layout/activity_muti.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/fragment1"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">

</FrameLayout>
<FrameLayout
android:id="@+id/fragment2"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">

</FrameLayout>
<FrameLayout
android:id="@+id/fragment3"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent">

</FrameLayout>

</LinearLayout>
12 changes: 12 additions & 0 deletions example/src/main/res/layout/fragment_content.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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">

<TextView
android:textColor="@android:color/white"
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
80 changes: 80 additions & 0 deletions loadingbar/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

version = "1.2"

android {
compileSdkVersion 23
Expand All @@ -21,3 +25,79 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

def siteUrl = 'https://github.com/dengyuhan/LoadingBar'
def gitUrl = 'https://github.com/dengyuhan/LoadingBar.git'
group = "com.dyhdyh.loadingbar"


install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name '灵活显示和隐藏Loading的组件' //项目描述
url siteUrl
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'dengyuhan' //填写开发者的一些基本信息
name 'dengyuhan' //填写开发者的一些基本信息
email '22309946@qq.com' //填写开发者的一些基本信息
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
javadoc {
options{
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/8/docs/api"
}
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
name = "LoadingBar"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
Loading

0 comments on commit 266cef5

Please sign in to comment.