浏览代码

音量和亮度

losion.liu@sikey.com.cn 6 月之前
父节点
当前提交
e89701698f

+ 64 - 19
app/src/main/java/com/xplora/xpsettings/Activity/ChangeProgressActivity.java

@@ -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);

+ 6 - 0
app/src/main/java/com/xplora/xpsettings/Data/DataManager.java

@@ -327,6 +327,12 @@ public class DataManager extends Application {
         }
     }
 
+    public static void setAllVolume(int value) {
+        DataManager.setMediaVolume(value);
+        DataManager.setCallVolume(value);
+        DataManager.setSystemVolume(value);
+    }
+
     public static List<Locale> getSupportLocale(Context context) {
         List<LocalePicker.LocaleInfo> locales = LocalePicker.getAllAssetLocales(context, false);
         List<Locale> localeStrings = new ArrayList<Locale>();

二进制
app/src/main/res/drawable/bright_0.png


二进制
app/src/main/res/drawable/bright_20.png


二进制
app/src/main/res/drawable/bright_40.png


二进制
app/src/main/res/drawable/bright_60.png


二进制
app/src/main/res/drawable/bright_80.png


+ 0 - 1
app/src/main/res/layout/activity_change_progress.xml

@@ -22,7 +22,6 @@
         android:id="@+id/icon"
         android:layout_width="75dp"
         android:layout_height="75dp"
-        android:background="@drawable/voice_0"
         android:layout_centerInParent="true" />
 
     <LinearLayout

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -15,4 +15,5 @@
     <color name="xp_item_highlight">#99FFFFFF</color>
     <color name="sk_gray">#303030</color>
     <color name="sk_green">#08A243</color>
+    <color name="sk_yellow">#FFC01F</color>
 </resources>