Commit 3bc7daa0 by gao.chao

loadingDialog

parent a85d15d4
...@@ -25,4 +25,5 @@ dependencies { ...@@ -25,4 +25,5 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api project(':fastDevelop')
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".TsetActviity"/>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package com.mayi.demo;
import android.view.View;
public class ItemBean {
private String text;
private View.OnClickListener clickListener;
public ItemBean(String text, View.OnClickListener clickListener) {
this.text = text;
this.clickListener = clickListener;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public View.OnClickListener getClickListener() {
return clickListener;
}
public void setClickListener(View.OnClickListener clickListener) {
this.clickListener = clickListener;
}
}
...@@ -2,13 +2,61 @@ package com.mayi.demo; ...@@ -2,13 +2,61 @@ package com.mayi.demo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class MainActivity extends AppCompatActivity { import com.mayi.fastdevelop.base.BaseActivity;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends BaseActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
RecyclerView listView = findViewById(R.id.list);
listView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
final List<ItemBean> list = new ArrayList<>();
list.add(new ItemBean("BaseActivity", new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoActivity(TsetActviity.class);
}
}));
listView.setAdapter(new RecyclerView.Adapter<MyViewHolder>() {
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new MyViewHolder(new Button(viewGroup.getContext()));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder viewHolder, int i) {
viewHolder.tv.setOnClickListener(list.get(i).getClickListener());
viewHolder.tv.setText(list.get(i).getText());
}
@Override
public int getItemCount() {
return list.size();
}
});
} }
class MyViewHolder extends RecyclerView.ViewHolder {
Button tv;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
tv = (Button) itemView;
}
}
} }
package com.mayi.demo;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.View;
import com.mayi.fastdevelop.base.BaseActivity;
public class TsetActviity extends BaseActivity {
private Handler handler;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_layout);
handler = new Handler();
findViewById(R.id.showLoading).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLoadingDialog();
handler.postDelayed(new Runnable() {
@Override
public void run() {
dismssLoadingDialog();
}
}, 4000);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/showLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示对话框"/>
</LinearLayout>
\ No newline at end of file
...@@ -25,9 +25,9 @@ android { ...@@ -25,9 +25,9 @@ android {
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0' api 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
......
package com.mayi.fastdevelop.base; package com.mayi.fastdevelop.base;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import com.mayi.fastdevelop.view.LoadingDialog;
public abstract class BaseActivity extends AppCompatActivity { public abstract class BaseActivity extends AppCompatActivity {
private Dialog dialog;
public void showLoadingDialog() { @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
} }
public void showLoadingDialog() {
if (dialog == null) {
dialog = LoadingDialog.init(this).show();
} else {
dialog.show();
}
}
public void dismssLoadingDialog() { public void dismssLoadingDialog() {
if (dialog != null) {
dialog.dismiss();
}
}
/**
* 跳转页面并结束当前页面
* @param activity
*/
public void gotoActivityAndFinish(Class activity) {
Intent intent = new Intent(this, activity);
startActivity(intent);
finish();
}
/**
* 跳转页面
* @param activity
*/
public void gotoActivity(Class activity) {
Intent intent = new Intent(this, activity);
startActivity(intent);
} }
/**
* 跳转页面并结束当前页面
* @param activity
*/
public void gotoActivityAndFinish(Class activity,Bundle bundle) {
Intent intent = new Intent(this, activity);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
/**
* 跳转页面
* @param activity
*/
public void gotoActivity(Class activity,Bundle bundle) {
Intent intent = new Intent(this, activity);
intent.putExtras(bundle);
startActivity(intent);
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
......
package com.mayi.fastdevelop.base; package com.mayi.fastdevelop.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
public abstract class BaseFragment extends Fragment{ public abstract class BaseFragment extends Fragment{
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().finish();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment