Skip to content

Commit

Permalink
add custom header and footer, custom animation
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Jan 29, 2016
1 parent 521c963 commit f07c39f
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package cn.qqtheme.androidpicker;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.Button;
import android.widget.TextView;

import com.github.florent37.viewanimator.AnimationListener;
import com.github.florent37.viewanimator.ViewAnimator;

import cn.qqtheme.framework.picker.OptionPicker;

/**
* 自定义顶部及底部
* <p/>
* Author:李玉江[QQ:1032694760]
* Email:[email protected]
* DateTime:2016/1/29 14:47
* Builder:Android Studio
*/
public class CustomHeaderAndFooterPicker extends OptionPicker {

public CustomHeaderAndFooterPicker(Activity activity) {
super(activity, new String[]{
"C/C++", "Java", "PHP", "Swift", "Node.js", "C#", "HTML5"
});
setTitleText("请选择你最擅长的语言");
setSelectedItem("PHP");
}

@Override
public void show() {
super.show();
ViewAnimator.animate(getRootView())
.duration(2000)
.interpolator(new AccelerateInterpolator())
.slideBottom()
.start();
}

@Override
public void dismiss() {
ViewAnimator.animate(getRootView())
.duration(1000)
.rollOut()
.onStop(new AnimationListener.Stop() {
@Override
public void onStop() {
CustomHeaderAndFooterPicker.super.dismiss();
}
})
.start();
}

@Nullable
@Override
protected View makeHeaderView() {
View view = LayoutInflater.from(activity).inflate(R.layout.picker_header, null);
TextView titleView = (TextView) view.findViewById(R.id.picker_title);
titleView.setText(titleText);
return view;
}

@Nullable
@Override
protected View makeFooterView() {
View view = LayoutInflater.from(activity).inflate(R.layout.picker_footer, null);
Button submitView = (Button) view.findViewById(R.id.picker_submit);
submitView.setText(submitText);
submitView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
onSubmit();
}
});
Button cancelView = (Button) view.findViewById(R.id.picker_cancel);
cancelView.setText(cancelText);
cancelView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
onCancel();
}
});
return view;
}

}
27 changes: 20 additions & 7 deletions app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cn.qqtheme.androidpicker;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.github.florent37.viewanimator.ViewAnimator;

import java.util.ArrayList;

Expand Down Expand Up @@ -59,6 +61,17 @@ public void onOptionPicked(String option) {
picker.show();
}

public void onAnimator(View view) {
CustomHeaderAndFooterPicker picker = new CustomHeaderAndFooterPicker(this);
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
@Override
public void onOptionPicked(String option) {
showToast(option);
}
});
picker.show();
}

public void onYearMonthDayPicker(View view) {
DatePicker picker = new DatePicker(this);
picker.setRange(2000, 2016);
Expand All @@ -73,7 +86,7 @@ public void onDatePicked(String year, String month, String day) {
}

public void onYearMonthPicker(View view) {
DatePicker picker = new DatePicker(this, DatePicker.Mode.YEAR_MONTH);
DatePicker picker = new DatePicker(this, DatePicker.YEAR_MONTH);
picker.setRange(1990, 2015);
picker.setOnDatePickListener(new DatePicker.OnYearMonthPickListener() {
@Override
Expand All @@ -85,7 +98,7 @@ public void onDatePicked(String year, String month) {
}

public void onMonthDayPicker(View view) {
DatePicker picker = new DatePicker(this, DatePicker.Mode.MONTH_DAY);
DatePicker picker = new DatePicker(this, DatePicker.MONTH_DAY);
picker.setOnDatePickListener(new DatePicker.OnMonthDayPickListener() {
@Override
public void onDatePicked(String month, String day) {
Expand All @@ -97,7 +110,7 @@ public void onDatePicked(String month, String day) {

public void onTimePicker(View view) {
//默认选中当前时间
TimePicker picker = new TimePicker(this);
TimePicker picker = new TimePicker(this, TimePicker.HOUR_OF_DAY);
picker.setTopLineVisible(false);
picker.setOnTimePickListener(new TimePicker.OnTimePickListener() {
@Override
Expand Down Expand Up @@ -219,11 +232,11 @@ public void onColorPicked(int pickedColor) {
}

public void onFilePicker(View view) {
FilePicker picker = new FilePicker(this);
//noinspection MissingPermission
FilePicker picker = new FilePicker(this, FilePicker.FILE);
picker.setShowHideDir(false);
picker.setRootPath(StorageUtils.getRootPath(this) + "Download/");
//picker.setAllowExtensions(new String[]{".apk"});
picker.setMode(FilePicker.Mode.File);
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
@Override
public void onFilePicked(String currentPath) {
Expand All @@ -234,8 +247,8 @@ public void onFilePicked(String currentPath) {
}

public void onDirPicker(View view) {
FilePicker picker = new FilePicker(this);
picker.setMode(FilePicker.Mode.Directory);
//noinspection MissingPermission
FilePicker picker = new FilePicker(this, FilePicker.DIRECTORY);
picker.setOnFilePickListener(new FilePicker.OnFilePickListener() {
@Override
public void onFilePicked(String currentPath) {
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onAnimationStyle"
android:text="窗口动画" />
android:text="窗口动画(基于XML)" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onAnimator"
android:text="窗口动画(基于Java)" />

<Button
android:layout_width="match_parent"
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/res/layout/picker_footer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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="wrap_content"
android:orientation="vertical">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="#FFEEEEEE" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal">

<Button
android:id="@+id/picker_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit" />

<Button
android:id="@+id/picker_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="cancel"
android:textColor="#FFFF0000" />

</LinearLayout>

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

<TextView
android:id="@+id/picker_title"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:text="New Text" />

</LinearLayout>
Binary file added screenshots/custom.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f07c39f

Please sign in to comment.