-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
231 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
ext/src/main/java/com/lxj/xpopupext/adapter/ArrayWheelAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
ext/src/main/java/com/lxj/xpopupext/listener/CommonPickerListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.lxj.xpopupext.listener; | ||
|
||
public interface CommonPickerListener { | ||
void onItemSelected(int index, String data); | ||
} |
2 changes: 0 additions & 2 deletions
2
ext/src/main/java/com/lxj/xpopupext/listener/OnOptionsSelectListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package com.lxj.xpopupext.listener; | ||
|
||
import android.view.View; | ||
|
||
/** | ||
* Created by xiaosong on 2018/3/20. | ||
*/ | ||
|
124 changes: 124 additions & 0 deletions
124
ext/src/main/java/com/lxj/xpopupext/popup/CommonPickerPopup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.lxj.xpopupext.popup; | ||
|
||
import android.content.Context; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
import androidx.annotation.NonNull; | ||
|
||
import com.contrarywind.listener.OnItemSelectedListener; | ||
import com.contrarywind.view.WheelView; | ||
import com.lxj.xpopup.XPopup; | ||
import com.lxj.xpopup.core.BottomPopupView; | ||
import com.lxj.xpopupext.R; | ||
import com.lxj.xpopupext.adapter.ArrayWheelAdapter; | ||
import com.lxj.xpopupext.listener.CommonPickerListener; | ||
import com.lxj.xpopupext.listener.ISelectTimeCallback; | ||
import com.lxj.xpopupext.listener.TimePickerListener; | ||
import com.lxj.xpopupext.view.WheelTime; | ||
import java.text.ParseException; | ||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
|
||
public class CommonPickerPopup extends BottomPopupView { | ||
|
||
private int itemsVisibleCount = 7; | ||
private int itemTextSize = 18; | ||
public int dividerColor = 0xFFd5d5d5; //分割线的颜色 | ||
public float lineSpace = 2.4f; // 条目间距倍数 默认2 | ||
public int textColorOut = 0xFFa8a8a8; //分割线以外的文字颜色 | ||
public int textColorCenter = 0xFF2a2a2a; //分割线之间的文字颜色 | ||
private WheelView wheelView; | ||
public CommonPickerPopup(@NonNull Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
protected int getImplLayoutId() { | ||
return R.layout._xpopup_ext_common_picker; | ||
} | ||
|
||
@Override | ||
protected void onCreate() { | ||
super.onCreate(); | ||
wheelView = findViewById(R.id.commonWheel); | ||
findViewById(R.id.btnCancel).setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
dismiss(); | ||
} | ||
}); | ||
TextView btnConfirm = findViewById(R.id.btnConfirm); | ||
btnConfirm.setTextColor(XPopup.getPrimaryColor()); | ||
btnConfirm.setOnClickListener(new OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
int index = wheelView.getCurrentItem(); | ||
if(commonPickerListener!=null) commonPickerListener.onItemSelected(index, list.get(index)); | ||
dismiss(); | ||
} | ||
}); | ||
initWheelData(); | ||
} | ||
|
||
private void initWheelData() { | ||
wheelView.setItemsVisibleCount(itemsVisibleCount); | ||
wheelView.setAlphaGradient(true); | ||
wheelView.setTextSize(itemTextSize); | ||
wheelView.setCyclic(false); | ||
wheelView.setDividerColor(dividerColor); | ||
wheelView.setDividerType(WheelView.DividerType.FILL); | ||
wheelView.setLineSpacingMultiplier(lineSpace); | ||
wheelView.setTextColorOut(textColorOut); | ||
wheelView.setTextColorCenter(textColorCenter); | ||
wheelView.isCenterLabel(false); | ||
wheelView.setCurrentItem(currentItem); | ||
wheelView.setAdapter(new ArrayWheelAdapter<>(list)); | ||
wheelView.setOnItemSelectedListener(new OnItemSelectedListener() { | ||
@Override | ||
public void onItemSelected(int index) { | ||
} | ||
}); | ||
} | ||
private CommonPickerListener commonPickerListener; | ||
public CommonPickerPopup setCommonPickerListener(CommonPickerListener commonPickerListener){ | ||
this.commonPickerListener = commonPickerListener; | ||
return this; | ||
} | ||
public CommonPickerPopup setItemTextSize(int textSize){ | ||
this.itemTextSize = textSize; | ||
return this; | ||
} | ||
|
||
public CommonPickerPopup setItemsVisibleCount(int itemsVisibleCount){ | ||
this.itemsVisibleCount = itemsVisibleCount; | ||
return this; | ||
} | ||
public CommonPickerPopup setLineSpace(float lineSpace){ | ||
this.lineSpace = lineSpace; | ||
return this; | ||
} | ||
List<String> list = new ArrayList<>(); | ||
/** | ||
* 设置选项数据 | ||
*/ | ||
public CommonPickerPopup setPickerData(List<String> list) { | ||
this.list = list; | ||
return this; | ||
} | ||
|
||
int currentItem = 0; | ||
/** | ||
* 设置默认选中 | ||
*/ | ||
public CommonPickerPopup setCurrentItem(int currentItem) { | ||
this.currentItem = currentItem; | ||
return this; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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"> | ||
|
||
<LinearLayout | ||
android:background="#f5f5f5" | ||
android:orientation="horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="40dp"> | ||
|
||
<TextView | ||
android:id="@+id/btnCancel" | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:paddingLeft="15dp" | ||
android:paddingRight="10dp" | ||
android:text="@string/xpopup_cancel" | ||
android:textAllCaps="false" | ||
android:textColor="@color/_xpopup_dark_color" | ||
android:textSize="16sp" /> | ||
|
||
<Space | ||
android:layout_weight="1" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp"/> | ||
|
||
<TextView | ||
android:id="@+id/btnConfirm" | ||
android:gravity="center" | ||
android:paddingLeft="10dp" | ||
android:paddingRight="15dp" | ||
android:textColor="@color/_xpopup_dark_color" | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:text="@string/xpopup_ok" | ||
android:textAllCaps="false" | ||
android:textSize="16sp" /> | ||
</LinearLayout> | ||
|
||
|
||
<com.contrarywind.view.WheelView | ||
android:id="@+id/commonWheel" | ||
android:background="@android:color/white" | ||
android:gravity="center" | ||
android:minHeight="150dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
</LinearLayout> |