|
@@ -23,11 +23,12 @@ import java.util.Map;
|
|
|
|
|
|
public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
int mViewType = 0;
|
|
|
- int curValue = 0;
|
|
|
- int maxValue = 100;
|
|
|
int minValue = 0;
|
|
|
- int[] mDisplayArray = {20, 40, 60, 80, 100};
|
|
|
- int[] mVoiceArray = {0, 30, 60, 100};
|
|
|
+ int maxValue = 100;
|
|
|
+ int[] mBrightnessLevels = {20, 40, 60, 80, 100};
|
|
|
+ int[] mVoiceLevels = {0, 30, 60, 100};
|
|
|
+ int[] mCurLevels;
|
|
|
+ int mCurLevel = 0;
|
|
|
|
|
|
private ImageView mIcon = null;
|
|
|
private ImageView mSubButton = null;
|
|
@@ -40,6 +41,9 @@ public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
setContentView(R.layout.activity_change_progress);
|
|
|
initDatas();
|
|
|
initView();
|
|
|
+ initTitle();
|
|
|
+ changeImage();
|
|
|
+ changeProgress();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -47,19 +51,44 @@ public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
super.onNewIntent(intent);
|
|
|
initDatas();
|
|
|
initView();
|
|
|
+ initTitle();
|
|
|
+ changeImage();
|
|
|
+ changeProgress();
|
|
|
}
|
|
|
|
|
|
private void initDatas() {
|
|
|
+ int curValue = 0;
|
|
|
mViewType = getIntent().getIntExtra(Constant.INTENT_VIEW_TYPE, 0);
|
|
|
if (mViewType == 3) {
|
|
|
curValue = DataManager.getBrightness();
|
|
|
+ minValue = 0;
|
|
|
+ maxValue = 100;
|
|
|
+ mCurLevels = mBrightnessLevels;
|
|
|
} else {
|
|
|
- Map map = DataManager.getVolume(mViewType);
|
|
|
- curValue = (int) map.get("cur");
|
|
|
- maxValue = (int) map.get("max");
|
|
|
- minValue = (int) map.get("min");
|
|
|
+ Map map = DataManager.getVolume(0);
|
|
|
+ curValue = (int)map.get("cur");
|
|
|
+ maxValue = (int)map.get("max");
|
|
|
+ minValue = (int)map.get("min");
|
|
|
+ mCurLevels = mVoiceLevels;
|
|
|
}
|
|
|
- Log.d(TAG, "initData: curValue: " + curValue + " maxValue: " + maxValue + " minValue: " + minValue);
|
|
|
+ mCurLevel = initLevel(curValue);
|
|
|
+ Log.d(TAG, "initData: curLevel: " + mCurLevel + " curValue: " + curValue + " maxValue: " + maxValue + " minValue: " + minValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int initLevel(int curValue) {
|
|
|
+ int per = (int)((curValue / (float) maxValue) * 100);
|
|
|
+ for (int i = 0; i < mCurLevels.length; i++) {
|
|
|
+ if (per <= mCurLevels[i]) {
|
|
|
+ mCurLevel = i;
|
|
|
+ return mCurLevel;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mCurLevels.length - 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int exchangeSystemValue() {
|
|
|
+ int value = mCurLevels[mCurLevel];
|
|
|
+ return (int)((value / 100.0) * maxValue);
|
|
|
}
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
@@ -70,9 +99,6 @@ public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
mAddButton = findViewById(R.id.addButton);
|
|
|
mSubButton.setOnClickListener( v -> clickSubButton());
|
|
|
mAddButton.setOnClickListener( v -> clickAddButton());
|
|
|
- initTitle();
|
|
|
- changeImage();
|
|
|
- changeProgress();
|
|
|
}
|
|
|
|
|
|
private void initTitle() {
|
|
@@ -94,27 +120,46 @@ public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
if (mIcon == null)
|
|
|
return;
|
|
|
if (mViewType == 3) {
|
|
|
- int imageId = ResUtils.getImageId("ic_seekbar_", mViewType);
|
|
|
+ int imageId = ResUtils.getImageId("bright_", mCurLevels[mCurLevel]);
|
|
|
mIcon.setImageResource(imageId);
|
|
|
} else {
|
|
|
- int index = curValue <= 0 ? 0 : 2;
|
|
|
- int imageId = ResUtils.getImageId("ic_seekbar_", index);
|
|
|
+ int imageId = ResUtils.getImageId("voice_", mCurLevels[mCurLevel]);
|
|
|
mIcon.setImageResource(imageId);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("SetTextI18n")
|
|
|
private void changeProgress() {
|
|
|
-
|
|
|
+ mProgressText.setText(mCurLevels[mCurLevel] + "%");
|
|
|
+ mProgressText.setTextColor(mViewType == 3 ? getColor(R.color.sk_yellow) : getColor(R.color.sk_green));
|
|
|
+ mSubButton.setEnabled(mCurLevel > 0);
|
|
|
+ mAddButton.setEnabled(mCurLevel < mCurLevels.length-1);
|
|
|
}
|
|
|
|
|
|
private void clickSubButton() {
|
|
|
-
|
|
|
+ mCurLevel = Math.max(mCurLevel-1, 0);
|
|
|
+ changeImage();
|
|
|
+ changeProgress();
|
|
|
+ syncSystem();
|
|
|
}
|
|
|
|
|
|
private void clickAddButton() {
|
|
|
+ mCurLevel = Math.min(mCurLevel+1, mCurLevels.length-1);
|
|
|
+ changeImage();
|
|
|
+ changeProgress();
|
|
|
+ syncSystem();
|
|
|
+ }
|
|
|
|
|
|
+ public void syncSystem() {
|
|
|
+ int value = exchangeSystemValue();
|
|
|
+ if (mViewType == 3) {
|
|
|
+ DataManager.setBrightness(value);
|
|
|
+ } else {
|
|
|
+ DataManager.setAllVolume(value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// /*
|
|
|
// * SeekBar滚动时的回调函数
|
|
|
// */
|
|
@@ -127,7 +172,7 @@ public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
// }
|
|
|
// Log.d(TAG, "onProgressChanged: mViewType:" + mViewType + " progress: " + progress);
|
|
|
//
|
|
|
-// curValue = progress;
|
|
|
+// mCurLevel = progress;
|
|
|
// if (mViewType == 3) {
|
|
|
// DataManager.setBrightness(progress);
|
|
|
// } else {
|
|
@@ -136,7 +181,7 @@ public class ChangeProgressActivity extends BaseActionActivity {
|
|
|
//
|
|
|
// changeImage();
|
|
|
//
|
|
|
-// int value = mViewType == 3 ? curValue : (curValue * 100 / maxValue);
|
|
|
+// int value = mViewType == 3 ? mCurLevel : (mCurLevel * 100 / maxValue);
|
|
|
// Intent intent = new Intent();
|
|
|
// intent.putExtra(Constant.INTENT_VIEW_TYPE, mViewType);
|
|
|
// intent.putExtra(Constant.INTENT_RESULT_VALUE, value);
|