Skip to content

Commit

Permalink
依赖包。粒子分离
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyGhostz committed Mar 22, 2018
1 parent 8ccae2d commit a5326a1
Show file tree
Hide file tree
Showing 38 changed files with 2,097 additions and 189 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:recyclerview-v7:26+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile project(':customdialoglib')
testCompile 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,183 @@
package com.example.happyghost.dialogpackage;

import android.app.Activity;
import android.content.DialogInterface;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
import com.example.happyghost.dialogpackage.adapter.CustomItemDecoration;
import com.example.happyghost.dialogpackage.adapter.MyAdapter;
import com.zcp.customdialoglib.CustomDialog;
import com.zcp.customdialoglib.dialoglist.ListDialogAdapter;
import com.zcp.customdialoglib.utils.DialogPakageUtils;

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

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private RecyclerView listView;
private LinearLayoutManager layoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}

private void initView() {
Button button = (Button) findViewById(R.id.main_btn);
Button progressButton = (Button) findViewById(R.id.main_btn_progress);
Button bottomButton = (Button) findViewById(R.id.main_btn_bottom);
Button downloadButton = (Button) findViewById(R.id.main_btn_download);
Button listButton = (Button) findViewById(R.id.main_btn_list);
Button advertiseButton = (Button) findViewById(R.id.main_btn_advertise);
button.setOnClickListener(this);
progressButton.setOnClickListener(this);
bottomButton.setOnClickListener(this);
downloadButton.setOnClickListener(this);
listButton.setOnClickListener(this);
advertiseButton.setOnClickListener(this);
}

@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.main_btn:
DialogPakageUtils.getDefaultDialog(getSupportFragmentManager(), "0", "提示", "世界正在爆炸,请上天!",false, "否", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}, "是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(MainActivity.this,"上天完成!",Toast.LENGTH_SHORT).show();
}
});
break;
case R.id.main_btn_progress:
final CustomDialog customDialog = DialogPakageUtils.creatProdressDialog(getSupportFragmentManager(),
"1", R.layout.custom_dialog_progressbar,
getWidthScrreen(this) / 4, 0.5f);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
customDialog.dismiss();
}
}, 5000);
break;
case R.id.main_btn_bottom:
CustomDialog bottomDialog = DialogPakageUtils.creatBottomDialog(getSupportFragmentManager(), "2", R.layout.custom_dialog_bottom,
Gravity.BOTTOM, R.style.MyDialogAnimation_Translate_bottom, getWidthScrreen(this), 0, 0.2f,true);
bottomDialog.setOnBindViewListener(new CustomDialog.OnBindViewListener() {
@Override
public void getBindView(View view) {
final LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.custom_ll_bottom);
int childCount = linearLayout.getChildCount();
for (int i = 0; i < childCount; i++) {
final int finalI = i;
linearLayout.getChildAt(i).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,finalI+"finalI",Toast.LENGTH_SHORT).show();
}
});
}
}
});
break;
case R.id.main_btn_download:
final CustomDialog dialogView =DialogPakageUtils.creatDownLoadInfoDialog(getSupportFragmentManager(), "3",
R.layout.custom_dialog_download,R.style.MyDialogAnimation_Translate_bottom,getWidthScrreen(this),0,0.2f,false);
dialogView.setOnBindViewListener(new CustomDialog.OnBindViewListener() {
@Override
public void getBindView(View view) {
final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.custom_pb_downlaod);
final TextView textView = (TextView) view.findViewById(R.id.custom_tv_download);
progressBar.setMax(100);
CountDownTimer downTimer = new CountDownTimer(10000,1000) {
@Override
public void onTick(long l) {
progressBar.setProgress((10000/100-(int)l/100));
textView.setText((10000/100-(int)l/100)+"%");
}

@Override
public void onFinish() {
Toast.makeText(MainActivity.this, "下载完成!", Toast.LENGTH_SHORT).show();
progressBar.setProgress(100);
dialogView.dismiss();
}
}.start();

}
});
break;
case R.id.main_btn_list:
List<String> dataList = new ArrayList();
for (int i = 0; i < 20; i++) {
dataList.add("这是第"+i+"条数据!");
}
listView = new RecyclerView(MainActivity.this);
layoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false);
listView.setLayoutManager(layoutManager);
listView.addItemDecoration(new CustomItemDecoration(MainActivity.this,LinearLayoutManager.VERTICAL));
MyAdapter myAdapter = new MyAdapter(R.layout.custom_dialog_list_item);
myAdapter.setData(dataList);
final CustomDialog dialog = DialogPakageUtils.creatListDialog(getSupportFragmentManager(), "4", listView, myAdapter,
getWidthScrreen(this), getHeightScrreen(this) / 3,R.style.MyDialogAnimation_Translate_Left,Gravity.BOTTOM, false);
myAdapter.setOnItemClickListener(new ListDialogAdapter.OnItemClickListener() {
@Override
public void onItemClick(ListDialogAdapter adapter, View view, int position) {
String item = (String) adapter.getItem(position);
Toast.makeText(MainActivity.this,"点击了:"+item,Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
break;
case R.id.main_btn_advertise:
final CustomDialog advertisedialog = DialogPakageUtils.creatAdvertiseDialog(getSupportFragmentManager(), "5", R.layout.custom_dialog_advertise,
R.style.MyDialogAnimation_Rotate, getWidthScrreen(this), 0, 0.5f, true);
advertisedialog.setOnBindViewListener(new CustomDialog.OnBindViewListener() {
@Override
public void getBindView(View view) {
ImageView imageView = (ImageView) view.findViewById(R.id.custon_iv_advertise_cancel);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
advertisedialog.dismiss();
}
});
}
});
break;
}
}
public static int getHeightScrreen(Activity activity){
DisplayMetrics outMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int heightPixels = outMetrics.heightPixels;
return heightPixels;
}
public static int getWidthScrreen(Activity activity){
DisplayMetrics outMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int widthPixels = outMetrics.widthPixels;
return widthPixels;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.example.happyghost.dialogpackage.adapter;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
* @author Zhao Chenping
* @creat 2018/3/20.
* @description
*/

public class CustomItemDecoration extends RecyclerView.ItemDecoration {
private int[] ATTRS = new int[]{android.R.attr.listDivider};
private Drawable mDivider;
private int mOrientation;

public CustomItemDecoration(Context context,int orientation){
TypedArray typedArray = context.obtainStyledAttributes(ATTRS);
mDivider = typedArray.getDrawable(0);
typedArray.recycle();
setOrientation(orientation);
}

private void setOrientation(int orientation) {
if(orientation!= LinearLayoutManager.HORIZONTAL&&orientation!=LinearLayoutManager.VERTICAL){
throw new IllegalArgumentException("not init orientation");
}
mOrientation = orientation;
}

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDraw(c, parent, state);
if(mOrientation == LinearLayoutManager.HORIZONTAL){
drawVerticalLine(c,parent);
}else if(mOrientation == LinearLayoutManager.VERTICAL){
drawHorizontalLine(c,parent);
}
}

private void drawHorizontalLine(Canvas canvas, RecyclerView recyclerView) {
int left = recyclerView.getPaddingLeft();
int right = recyclerView.getWidth() - recyclerView.getPaddingRight();
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View childAt = recyclerView.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) childAt.getLayoutParams();
int top = childAt.getBottom()+layoutParams.bottomMargin;
int bottom = top + mDivider.getIntrinsicHeight();
mDivider.setBounds(left,top,right,bottom);
mDivider.draw(canvas);
}
}

private void drawVerticalLine(Canvas canvas, RecyclerView recyclerView) {
int top = recyclerView.getPaddingTop();
int bottom = recyclerView.getHeight() - recyclerView.getPaddingBottom();
int childCount = recyclerView.getChildCount();
for (int i = 0; i < childCount; i++) {
View childView = recyclerView.getChildAt(i);
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)childView.getLayoutParams();
int left = childView.getRight() + layoutParams.rightMargin;
int right = left+mDivider.getIntrinsicWidth();
mDivider.setBounds(left,top,right,bottom);
mDivider.draw(canvas);
}
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if(mOrientation==LinearLayoutManager.VERTICAL){
outRect.set(0,0,0,mDivider.getIntrinsicHeight());
}else if(mOrientation==LinearLayoutManager.HORIZONTAL){
outRect.set(0,00,mDivider.getIntrinsicWidth(),0);
}
}

public void setDividerDrawable(Drawable drawable){
this.mDivider = drawable;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.happyghost.dialogpackage.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.example.happyghost.dialogpackage.R;
import com.zcp.customdialoglib.dialoglist.BaseDialogViewHolder;
import com.zcp.customdialoglib.dialoglist.ListDialogAdapter;

import java.util.List;

/**
* @author Zhao Chenping
* @creat 2018/3/19.
* @description
*/

public class MyAdapter extends ListDialogAdapter<String,BaseDialogViewHolder> {

public MyAdapter(@LayoutRes int layoutResId, @Nullable List<String> data) {
super(layoutResId, data);
}
public MyAdapter(@LayoutRes int layoutResId) {
super(layoutResId);
}

@Override
protected void convert(BaseDialogViewHolder holder, final String s) {
holder.setText(R.id.custon_tv_item,s);
// view.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Toast.makeText(mContext,"点击了:"+s,Toast.LENGTH_SHORT).show();
// }
// });
}
}

This file was deleted.

Loading

0 comments on commit a5326a1

Please sign in to comment.