Skip to content

Commit

Permalink
修复bug,异常加固
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Nov 23, 2016
1 parent 83083be commit 677aec4
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ build/
local.properties
proguard/
*.log
*.apk
Binary file removed app-release.apk
Binary file not shown.
28 changes: 28 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ android {

}

tasks.all { task ->
def name = task.name;
if (name.contains("assemble") || name.contains("build")) {
task.doLast {
copyDebugApk();
}
}
}

def copyDebugApk() {
def debugOld = "${rootDir}/${project.name}/build/outputs/apk/app-debug.apk";
def debugNew = "${rootDir}/app-debug.apk";
def fis = new FileInputStream(debugOld);
def fos = new FileOutputStream(debugNew);
byte[] buffer = new byte[1024];
while (true) {
def len = fis.read(buffer);
if (len == -1) {
fis.close();
fos.flush();
fos.close();
break;
} else {
fos.write(buffer, 0, len);
}
}
}

dependencies {
compile 'com.alibaba:fastjson:1.1.54.android'
compile 'com.github.florent37:viewanimator:1.0.3'
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/cn/qqtheme/androidpicker/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void onOptionPicker(View view) {
"第一项", "第二项", "这是一个很长很长很长很长很长很长很长很长很长的很长很长的很长很长的项"
});
picker.setOffset(2);
picker.setSelectedIndex(1);
picker.setSelectedIndex(0);
picker.setTextSize(11);
picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {
@Override
Expand Down Expand Up @@ -225,6 +225,8 @@ public void onOptionPicked(int position, String option) {

public void onNumberPicker(View view) {
NumberPicker picker = new NumberPicker(this);
picker.setWidth(picker.getScreenWidthPixels() / 2);
picker.setLineVisible(false);
picker.setOffset(2);//偏移量
picker.setRange(145, 200, 1);//数字范围
picker.setSelectedItem(172);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ com.android.build.gradle.overridePathCheck=true
#android.useDeprecatedNdk=true

#下面定义一些常量供gradle脚本使用
VERSION_NAME=1.2.4
VERSION_NAME=1.2.4.20161123
VERSION_CODE=124
COMPILE_SDK_VERSION=23
MIN_SDK_VERSION=11
Expand Down
3 changes: 2 additions & 1 deletion installApk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# -r: replace existing application
# -d: allow version code downgrade

adb install -r -d ./app-release.apk
#adb install -r -d ./app-release.apk

adb install -r -d ./app-debug.apk
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public BasicPopup(Activity activity) {
popupDialog.setOnKeyListener(this);
}

public int getScreenWidthPixels() {
return screenWidthPixels;
}

public int getScreenHeightPixels() {
return screenHeightPixels;
}

/**
* 创建弹窗的内容视图
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ private void changeYearData() {
private int changeMonthData(int year) {
String preSelectMonth = months.size() > selectedMonthIndex ? months.get(selectedMonthIndex) : null;
months.clear();
if (startMonth < 1 || endMonth < 1 || startMonth > 12 || endMonth > 12) {
throw new IllegalArgumentException("month out of range [1-12]");
}
if (startMonth > endMonth) {
int tmp = startMonth;
startMonth = endMonth;
endMonth = tmp;
}
if (startYear == endYear) {
for (int i = startMonth; i <= endMonth; i++) {
months.add(DateUtils.fillZero(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
public class OptionPicker extends WheelPicker {
protected ArrayList<String> options = new ArrayList<String>();
private OnOptionPickListener onOptionPickListener;
private int selectedOption = 0;
private int selectedOptionIndex = 0;
private String label = "";

/**
* Instantiates a new Option picker.
*
* @param activity the activity
* @param options the options
*/
public OptionPicker(Activity activity, String[] options) {
super(activity);
this.options.addAll(Arrays.asList(options));
Expand All @@ -53,7 +47,7 @@ public void setLabel(String label) {
*/
public void setSelectedIndex(int index) {
if (index >= 0 && index < options.size()) {
selectedOption = index;
selectedOptionIndex = index;
}
}

Expand Down Expand Up @@ -93,11 +87,11 @@ protected View makeCenterView() {
if (!TextUtils.isEmpty(label)) {
labelView.setText(label);
}
optionView.setItems(options, selectedOption);
optionView.setItems(options, selectedOptionIndex);
optionView.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
selectedOption = selectedIndex;
selectedOptionIndex = selectedIndex;
}
});
return layout;
Expand All @@ -106,39 +100,20 @@ public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
@Override
public void onSubmit() {
if (onOptionPickListener != null) {
onOptionPickListener.onOptionPicked(selectedOption, options.get(selectedOption));
onOptionPickListener.onOptionPicked(selectedOptionIndex, options.get(selectedOptionIndex));
}
}

/**
* Gets selected option.
*
* @return the selected option
*/
public String getSelectedOption() {
return options.get(selectedOption);
return options.get(selectedOptionIndex);
}

/**
* Get the selected position.
*
* @return the selected position
*/
public int getSelectedPosition() {
return selectedOption;
return selectedOptionIndex;
}

/**
* The interface On option pick listener.
*/
public interface OnOptionPickListener {

/**
* On option picked.
*
* @param position the position you selected
* @param option the option
*/
void onOptionPicked(int position, String option);

}
Expand Down

0 comments on commit 677aec4

Please sign in to comment.