diff --git a/app/build.gradle b/app/build.gradle index 92d9a5c..2194944 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' apply plugin: "com.tencent.android.tpns" def appName() { - return "关怀系统OS" + return "AIOS系统" } def releaseTime() { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index deba34e..81d69e0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,7 +5,6 @@ android:sharedUserId="android.uid.system"> - @@ -13,6 +12,8 @@ + + @@ -61,7 +62,7 @@ + - + - + @@ -133,16 +135,16 @@ @@ -154,19 +156,16 @@ - - - + - + android:process=":remote" /> @@ -233,6 +232,7 @@ + + - + @@ -294,8 +295,10 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java b/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java new file mode 100644 index 0000000..5265a02 --- /dev/null +++ b/app/src/main/java/com/uiuios/aios/activity/ControlActivity.java @@ -0,0 +1,483 @@ +package com.uiuios.aios.activity; + +import android.bluetooth.BluetoothAdapter; +import android.bluetooth.BluetoothDevice; +import android.content.BroadcastReceiver; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.hardware.camera2.CameraAccessException; +import android.hardware.camera2.CameraCharacteristics; +import android.hardware.camera2.CameraManager; +import android.media.AudioManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.provider.Settings; +import android.util.Log; +import android.view.View; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; + +import com.baidu.location.BDAbstractLocationListener; +import com.baidu.location.BDLocation; +import com.baidu.location.LocationClient; +import com.uiuios.aios.R; +import com.uiuios.aios.manager.AmapManager; +import com.uiuios.aios.utils.BrightnessUtils; + +import java.util.Arrays; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class ControlActivity extends AppCompatActivity { + private static final String TAG = ControlActivity.class.getSimpleName(); + + @BindView(R.id.tv_wifi) + TextView tv_wifi; + @BindView(R.id.tv_wifi_ssid) + TextView tv_wifi_ssid; + @BindView(R.id.tv_bt) + TextView tv_bt; + @BindView(R.id.tv_bt_ssid) + TextView tv_bt_ssid; + + @BindView(R.id.tv_font_size) + TextView tv_font_size; + @BindView(R.id.seekBar) + SeekBar seekBar; + @BindView(R.id.seekbar_brightness) + SeekBar seekbar_brightness; + @BindView(R.id.seekbar_sound) + SeekBar seekbar_sound; + + @BindView(R.id.tv_sound) + TextView tv_sound; + + @BindView(R.id.tv_battery) + TextView tv_battery; + @BindView(R.id.tv_electricity) + TextView tv_electricity; + @BindView(R.id.tv_flashlight) + TextView tv_flashlight; + @BindView(R.id.tv_flashlight_switch) + TextView tv_flashlight_switch; + + @BindView(R.id.tv_brightness) + TextView tv_brightness; + @BindView(R.id.tv_location) + TextView tv_location; + + @BindView(R.id.cl_wifi) + ConstraintLayout cl_wifi; + @BindView(R.id.cl_bt) + ConstraintLayout cl_bt; + @BindView(R.id.cl_battery) + ConstraintLayout cl_battery; + @BindView(R.id.cl_flashlight) + ConstraintLayout cl_flashlight; + + + private ContentResolver crv; + private static final String ACTION_FLASHLIGHT_CHANGED = + "com.android.settings.flashlight.action.FLASHLIGHT_CHANGED"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_control); + ButterKnife.bind(this); + crv = getContentResolver(); + initView(); + } + + private void initView() { + getWifi(); + registerReceivers(); + getBluetooth(); + registerBluetoothReceiver(); + getFlashlight(); + getFontSize(); + getLocation(); + getBrightness(); + getSound(); + } + + private void getWifi() { + cl_wifi.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)); + } + }); + if (isWifiEnabled()) { + tv_wifi_ssid.setText(getSSID()); + cl_wifi.setBackground(getDrawable(R.drawable.control_background_item)); + } else { + tv_wifi_ssid.setText("未连接"); + cl_wifi.setBackground(getDrawable(R.drawable.control_background_item_dis)); + } + } + + public boolean isWifiEnabled() { + WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); + if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { + ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo wifiInfo = connManager + .getNetworkInfo(ConnectivityManager.TYPE_WIFI); + return wifiInfo.isConnected(); + } else { + return false; + } + } + + private WifiReceiver mWifiReceiver; + + private void registerReceivers() { + registerWiFiReceiver(); + } + + private void registerWiFiReceiver() { + if (mWifiReceiver == null) { + mWifiReceiver = new WifiReceiver(); + } + IntentFilter filter = new IntentFilter(); + filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.RSSI_CHANGED_ACTION); + filter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION); + filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); + filter.addAction(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION); + filter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION); + filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); + filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); + registerReceiver(mWifiReceiver, filter); + } + + public class WifiReceiver extends BroadcastReceiver { + private static final String TAG = "wifiReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + switch (intent.getAction()) { + case WifiManager.RSSI_CHANGED_ACTION: + Log.e(TAG, "wifi信号强度变化"); + break; + //wifi连接上与否 + case WifiManager.NETWORK_STATE_CHANGED_ACTION: + NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); + if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) { + Log.e(TAG, "wifi断开"); + tv_wifi_ssid.setText("未连接"); + cl_wifi.setBackground(getDrawable(R.drawable.control_background_item_dis)); + } else if (info.getState().equals(NetworkInfo.State.CONNECTED)) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + //获取当前wifi名称 + String newSSID = wifiInfo.getSSID(); + tv_wifi_ssid.setText(newSSID); + cl_wifi.setBackground(getDrawable(R.drawable.control_background_item)); + } + break; + //wifi打开与否 + case WifiManager.WIFI_STATE_CHANGED_ACTION: + int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED); + if (wifistate == WifiManager.WIFI_STATE_DISABLED) { + Log.e(TAG, "系统关闭wifi"); + tv_wifi_ssid.setText("关"); + cl_wifi.setBackground(getDrawable(R.drawable.control_background_item_dis)); + } else if (wifistate == WifiManager.WIFI_STATE_ENABLED) { + Log.e(TAG, "系统开启wifi"); + } + break; + default: + } + } + } + + /** + * 获取当前连接WIFI的SSID + */ + public String getSSID() { + WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); + if (wm != null) { + WifiInfo winfo = wm.getConnectionInfo(); + if (winfo != null) { + String s = winfo.getSSID(); + if (s.length() > 2 && s.charAt(0) == '"' && s.charAt(s.length() - 1) == '"') { + return s.substring(1, s.length() - 1); + } + } + } + return ""; + } + + private void getBluetooth() { + cl_bt.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS)); + } + }); + } + + private BluetoothMonitorReceiver bleListenerReceiver; + + private void registerBluetoothReceiver() { + bleListenerReceiver = new BluetoothMonitorReceiver(); + IntentFilter intentFilter = new IntentFilter(); + // 监视蓝牙关闭和打开的状态 + intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); + // 监视蓝牙设备与APP连接的状态 + intentFilter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); + intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); + // 注册广播 + registerReceiver(this.bleListenerReceiver, intentFilter); + } + + public class BluetoothMonitorReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action != null) { + switch (action) { + case BluetoothAdapter.ACTION_STATE_CHANGED: + int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0); + switch (blueState) { + case BluetoothAdapter.STATE_TURNING_ON: + tv_bt_ssid.setText("蓝牙正在打开"); + cl_bt.setBackground(getDrawable(R.drawable.control_background_item)); + break; + case BluetoothAdapter.STATE_ON: + tv_bt_ssid.setText("蓝牙已经打开"); + cl_bt.setBackground(getDrawable(R.drawable.control_background_item)); + break; + case BluetoothAdapter.STATE_TURNING_OFF: + tv_bt_ssid.setText("蓝牙正在关闭"); + cl_bt.setBackground(getDrawable(R.drawable.control_background_item)); + break; + case BluetoothAdapter.STATE_OFF: + tv_bt_ssid.setText("关"); + cl_bt.setBackground(getDrawable(R.drawable.control_background_item_dis)); + break; + default: + } + break; + case BluetoothDevice.ACTION_ACL_CONNECTED: + tv_bt_ssid.setText("蓝牙设备已连接"); + cl_bt.setBackground(getDrawable(R.drawable.control_background_item)); + break; + case BluetoothDevice.ACTION_ACL_DISCONNECTED: + tv_bt_ssid.setText("蓝牙设备已断开"); + cl_bt.setBackground(getDrawable(R.drawable.control_background_item_dis)); + break; + default: + } + + } + } + } + + private void getFlashlight() { + if (isFlashlightEnabled()) { + tv_flashlight_switch.setText("开"); + } else { + tv_flashlight_switch.setText("关"); + } + cl_flashlight.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isFlashlightEnabled()) { + Settings.Secure.putInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 0); + sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED)); + tv_flashlight_switch.setText("关"); + } else { + Settings.Secure.putInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 1); + sendBroadcast(new Intent(ACTION_FLASHLIGHT_CHANGED)); + tv_flashlight_switch.setText("开"); + } + } + }); + } + + + private boolean isFlashlightAvailable() { + int defaultAvailability = 0; + try { + // check if there is a flash unit + if (getCameraId(this) != null) { + defaultAvailability = 1; + } + } catch (CameraAccessException e) { + Log.e(TAG, "Error getting camera id.", e); + } + return Settings.Secure.getInt(crv, Settings.Secure.FLASHLIGHT_AVAILABLE, defaultAvailability) == 1; + } + + private static String getCameraId(Context context) throws CameraAccessException { + final CameraManager cameraManager = context.getSystemService(CameraManager.class); + final String[] ids = cameraManager.getCameraIdList(); + for (String id : ids) { + CameraCharacteristics c = cameraManager.getCameraCharacteristics(id); + Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); + Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING); + if (flashAvailable != null && flashAvailable + && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) { + return id; + } + } + return null; + } + + private boolean isFlashlightEnabled() { + return Settings.Secure.getInt(crv, Settings.Secure.FLASHLIGHT_ENABLED, 0) == 1; + } + + private void getFontSize() { + float fontScale = Settings.System.getFloat(crv, Settings.System.FONT_SCALE, 0.0f); + Log.e(TAG, "getHardware: fontScale = " + fontScale); + List mEntries = Arrays.asList(getResources().getStringArray(R.array.entries_font_size)); + List strEntryValues = Arrays.asList(getResources().getStringArray(R.array.entryvalues_font_size)); + String font_size; + int index = strEntryValues.indexOf(String.valueOf(fontScale)); + if (index == -1) { + font_size = "默认"; + } else { + font_size = mEntries.get(index); + } + tv_font_size.setText(font_size); + seekBar.setProgress(index); + seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + Settings.System.putFloat(crv, Settings.System.FONT_SCALE, Float.parseFloat(strEntryValues.get(i))); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + } + + private void getLocation() { + BDLocation bdLocation = AmapManager.getInstance().getNowMapLocation(); + if (bdLocation != null) { + if (bdLocation.getLocType() == BDLocation.TypeGpsLocation // GPS定位结果 + || bdLocation.getLocType() == BDLocation.TypeNetWorkLocation // 网络定位结果 + || bdLocation.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果 + tv_location.setText(bdLocation.getAddrStr()); + } else { + tv_location.setText("未知"); + } + } else { + tv_location.setText("定位失败"); + } + LocationClient locationClient = AmapManager.getInstance().getLocationClient(); + locationClient.stop(); + locationClient.start(); + locationClient.registerLocationListener(new BDAbstractLocationListener() { + @Override + public void onReceiveLocation(BDLocation bdLocation) { + switch (bdLocation.getLocType()) { + case BDLocation.TypeGpsLocation:// GPS定位结果 + case BDLocation.TypeNetWorkLocation:// 网络定位结果 + case BDLocation.TypeOffLineLocation:// 离线定位结果 + tv_location.setText(bdLocation.getAddrStr()); + break; + default: + tv_location.setText("定位失败"); + break; + } + } + }); + } + + private void getBrightness() { + seekbar_brightness.setMin(1); + seekbar_brightness.setMax(255); + //亮度 + int brightness = Settings.System.getInt(crv, Settings.System.SCREEN_BRIGHTNESS, 1); + seekbar_brightness.setProgress(brightness); + Log.e(TAG, "getHardware: brightness = " + brightness); + int gamma = BrightnessUtils.convertLinearToGamma(brightness, 1, 255); + Log.e(TAG, "getHardware: gamma = " + gamma); + long percentage = Math.round((((double) gamma / 65535) * 100f)); + tv_brightness.setText(percentage + "%"); + Log.e(TAG, "getHardware: percentage = " + percentage); + seekbar_brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + Settings.System.putInt(crv, Settings.System.SCREEN_BRIGHTNESS, i); + int gamma = BrightnessUtils.convertLinearToGamma(i, 1, 255); + long percentage = Math.round((((double) gamma / 65535) * 100f)); + tv_brightness.setText(percentage + "%"); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + } + + private AudioManager mAudioManager; + + private void getSound() { + mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); + //最大音量 + int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + seekbar_sound.setMax(maxVolume); + Log.e(TAG, "getHardware: maxVolume = " + maxVolume); + //音量 + int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); + seekbar_sound.setProgress(streamVolume); + Log.e(TAG, "getHardware: streamVolume = " + streamVolume); + int currentVolume = (int) (((double) streamVolume / (double) maxVolume) * 100f); + Log.e(TAG, "getHardware: currentVolume = " + currentVolume); + tv_sound.setText(currentVolume + "%"); + seekbar_sound.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + int volume = (int) (((double) i / (double) maxVolume) * 100f); + tv_sound.setText(volume + "%"); + mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0); + + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (mWifiReceiver != null) unregisterReceiver(mWifiReceiver); + } +} diff --git a/app/src/main/java/com/uiuios/aios/fragment/CustomFragment.java b/app/src/main/java/com/uiuios/aios/fragment/CustomFragment.java index e124b5a..21378d7 100644 --- a/app/src/main/java/com/uiuios/aios/fragment/CustomFragment.java +++ b/app/src/main/java/com/uiuios/aios/fragment/CustomFragment.java @@ -47,6 +47,7 @@ import com.qweather.sdk.view.QWeather; import com.tencent.mmkv.MMKV; import com.uiuios.aios.BuildConfig; import com.uiuios.aios.R; +import com.uiuios.aios.activity.ControlActivity; import com.uiuios.aios.activity.EmergencyActivity; import com.uiuios.aios.activity.alarm.AlarmClockActivity; import com.uiuios.aios.activity.code.HealthCodeActivity; @@ -113,9 +114,10 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt ConstraintLayout cl_ai; @BindView(R.id.cl_appstore) ConstraintLayout cl_appstore; -// @BindView(R.id.cl_exit) + // @BindView(R.id.cl_exit) // ConstraintLayout cl_exit; - + @BindView(R.id.cl_control) + ConstraintLayout cl_control; // @BindView(R.id.cl_battery) // ConstraintLayout cl_battery; @@ -464,6 +466,13 @@ public class CustomFragment extends Fragment implements NetworkUtils.OnNetworkSt // showPassword(); // } // }); + cl_control.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(mContext, ControlActivity.class)); + } + }); + refreshMemory(); } diff --git a/app/src/main/java/com/uiuios/aios/manager/AmapManager.java b/app/src/main/java/com/uiuios/aios/manager/AmapManager.java index 3e6670a..87f6c28 100644 --- a/app/src/main/java/com/uiuios/aios/manager/AmapManager.java +++ b/app/src/main/java/com/uiuios/aios/manager/AmapManager.java @@ -74,8 +74,13 @@ public class AmapManager { String aMapLocationjson = mMMKV.decodeString(AMAPLOCATION_JSON_KEY, ""); Type type = new TypeToken() { }.getType(); - BDLocation bdLocation = new Gson().fromJson(aMapLocationjson, type); - return bdLocation; + try { + BDLocation bdLocation = new Gson().fromJson(aMapLocationjson, type); + return bdLocation; + } catch (Exception e) { + Log.e(TAG, "getNowMapLocation: " + e.getMessage()); + return null; + } } return this.mLocation; } @@ -123,7 +128,7 @@ public class AmapManager { * 定位结果回调,重写onReceiveLocation方法,可以直接拷贝如下代码到自己工程中修改 * */ - private BDAbstractLocationListener mListener = new BDAbstractLocationListener() { + private BDAbstractLocationListener mListener = new BDAbstractLocationListener() { /** * 定位请求回调函数 diff --git a/app/src/main/java/com/uiuios/aios/utils/BrightnessUtils.java b/app/src/main/java/com/uiuios/aios/utils/BrightnessUtils.java new file mode 100644 index 0000000..27f4928 --- /dev/null +++ b/app/src/main/java/com/uiuios/aios/utils/BrightnessUtils.java @@ -0,0 +1,142 @@ + +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.uiuios.aios.utils; + +import android.util.MathUtils; + +public class BrightnessUtils { + + public static final int GAMMA_SPACE_MIN = 0; + public static final int GAMMA_SPACE_MAX = 65535; + + // Hybrid Log Gamma constant values + private static final float R = 0.5f; + private static final float A = 0.17883277f; + private static final float B = 0.28466892f; + private static final float C = 0.55991073f; + + /** + * A function for converting from the gamma space that the slider works in to the + * linear space that the setting works in. + *

+ * The gamma space effectively provides us a way to make linear changes to the slider that + * result in linear changes in perception. If we made changes to the slider in the linear space + * then we'd see an approximately logarithmic change in perception (c.f. Fechner's Law). + *

+ * Internally, this implements the Hybrid Log Gamma electro-optical transfer function, which is + * a slight improvement to the typical gamma transfer function for displays whose max + * brightness exceeds the 120 nit reference point, but doesn't set a specific reference + * brightness like the PQ function does. + *

+ * Note that this transfer function is only valid if the display's backlight value is a linear + * control. If it's calibrated to be something non-linear, then a different transfer function + * should be used. + * + * @param val The slider value. + * @param min The minimum acceptable value for the setting. + * @param max The maximum acceptable value for the setting. + * @return The corresponding setting value. + */ + public static final int convertGammaToLinear(int val, int min, int max) { + final float normalizedVal = MathUtils.norm(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, val); + final float ret; + if (normalizedVal <= R) { + ret = MathUtils.sq(normalizedVal / R); + } else { + ret = MathUtils.exp((normalizedVal - C) / A) + B; + } + + // HLG is normalized to the range [0, 12], so we need to re-normalize to the range [0, 1] + // in order to derive the correct setting value. + return Math.round(MathUtils.lerp(min, max, ret / 12)); + } + + /** + * Version of {@link #convertGammaToLinear} that takes and returns float values. + * TODO(flc): refactor Android Auto to use float version + * + * @param val The slider value. + * @param min The minimum acceptable value for the setting. + * @param max The maximum acceptable value for the setting. + * @return The corresponding setting value. + */ + public static final float convertGammaToLinearFloat(int val, float min, float max) { + final float normalizedVal = MathUtils.norm(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, val); + final float ret; + if (normalizedVal <= R) { + ret = MathUtils.sq(normalizedVal / R); + } else { + ret = MathUtils.exp((normalizedVal - C) / A) + B; + } + + // HLG is normalized to the range [0, 12], ensure that value is within that range, + // it shouldn't be out of bounds. + final float normalizedRet = MathUtils.constrain(ret, 0, 12); + + // Re-normalize to the range [0, 1] + // in order to derive the correct setting value. + return MathUtils.lerp(min, max, normalizedRet / 12); + } + + /** + * A function for converting from the linear space that the setting works in to the + * gamma space that the slider works in. + *

+ * The gamma space effectively provides us a way to make linear changes to the slider that + * result in linear changes in perception. If we made changes to the slider in the linear space + * then we'd see an approximately logarithmic change in perception (c.f. Fechner's Law). + *

+ * Internally, this implements the Hybrid Log Gamma opto-electronic transfer function, which is + * a slight improvement to the typical gamma transfer function for displays whose max + * brightness exceeds the 120 nit reference point, but doesn't set a specific reference + * brightness like the PQ function does. + *

+ * Note that this transfer function is only valid if the display's backlight value is a linear + * control. If it's calibrated to be something non-linear, then a different transfer function + * should be used. + * + * @param val The brightness setting value. + * @param min The minimum acceptable value for the setting. + * @param max The maximum acceptable value for the setting. + * @return The corresponding slider value + */ + public static final int convertLinearToGamma(int val, int min, int max) { + return convertLinearToGammaFloat((float) val, (float) min, (float) max); + } + + /** + * Version of {@link #convertLinearToGamma} that takes float values. + * TODO: brightnessfloat merge with above method(?) + * + * @param val The brightness setting value. + * @param min The minimum acceptable value for the setting. + * @param max The maximum acceptable value for the setting. + * @return The corresponding slider value + */ + public static final int convertLinearToGammaFloat(float val, float min, float max) { + // For some reason, HLG normalizes to the range [0, 12] rather than [0, 1] + final float normalizedVal = MathUtils.norm(min, max, val) * 12; + final float ret; + if (normalizedVal <= 1f) { + ret = MathUtils.sqrt(normalizedVal) * R; + } else { + ret = A * MathUtils.log(normalizedVal - B) + C; + } + + return Math.round(MathUtils.lerp(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, ret)); + } +} diff --git a/app/src/main/res/drawable-hdpi/battery1.png b/app/src/main/res/drawable-hdpi/battery1.png new file mode 100644 index 0000000..678ead2 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/battery1.png differ diff --git a/app/src/main/res/drawable-hdpi/battery2.png b/app/src/main/res/drawable-hdpi/battery2.png new file mode 100644 index 0000000..93a1dfd Binary files /dev/null and b/app/src/main/res/drawable-hdpi/battery2.png differ diff --git a/app/src/main/res/drawable-hdpi/bluetooth1.png b/app/src/main/res/drawable-hdpi/bluetooth1.png new file mode 100644 index 0000000..19f12dc Binary files /dev/null and b/app/src/main/res/drawable-hdpi/bluetooth1.png differ diff --git a/app/src/main/res/drawable-hdpi/bluetooth2.png b/app/src/main/res/drawable-hdpi/bluetooth2.png new file mode 100644 index 0000000..db1cd87 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/bluetooth2.png differ diff --git a/app/src/main/res/drawable-hdpi/brightness1.png b/app/src/main/res/drawable-hdpi/brightness1.png new file mode 100644 index 0000000..8cf154d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/brightness1.png differ diff --git a/app/src/main/res/drawable-hdpi/brightness2.png b/app/src/main/res/drawable-hdpi/brightness2.png new file mode 100644 index 0000000..ae00154 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/brightness2.png differ diff --git a/app/src/main/res/drawable-hdpi/control_background.png b/app/src/main/res/drawable-hdpi/control_background.png new file mode 100644 index 0000000..1d32e71 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/control_background.png differ diff --git a/app/src/main/res/drawable-hdpi/flashlight1.png b/app/src/main/res/drawable-hdpi/flashlight1.png new file mode 100644 index 0000000..967f575 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/flashlight1.png differ diff --git a/app/src/main/res/drawable-hdpi/flashlight2.png b/app/src/main/res/drawable-hdpi/flashlight2.png new file mode 100644 index 0000000..2deef5f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/flashlight2.png differ diff --git a/app/src/main/res/drawable-hdpi/position.png b/app/src/main/res/drawable-hdpi/position.png new file mode 100644 index 0000000..2d118c5 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/position.png differ diff --git a/app/src/main/res/drawable-hdpi/sound1.png b/app/src/main/res/drawable-hdpi/sound1.png new file mode 100644 index 0000000..56091c3 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/sound1.png differ diff --git a/app/src/main/res/drawable-hdpi/sound2.png b/app/src/main/res/drawable-hdpi/sound2.png new file mode 100644 index 0000000..6e70b6f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/sound2.png differ diff --git a/app/src/main/res/drawable-hdpi/wifi1.png b/app/src/main/res/drawable-hdpi/wifi1.png new file mode 100644 index 0000000..13babc2 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wifi1.png differ diff --git a/app/src/main/res/drawable-hdpi/wifi2.png b/app/src/main/res/drawable-hdpi/wifi2.png new file mode 100644 index 0000000..2a0cd7b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/wifi2.png differ diff --git a/app/src/main/res/drawable/control_background_item.xml b/app/src/main/res/drawable/control_background_item.xml new file mode 100644 index 0000000..4768312 --- /dev/null +++ b/app/src/main/res/drawable/control_background_item.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/control_background_item_dis.xml b/app/src/main/res/drawable/control_background_item_dis.xml new file mode 100644 index 0000000..3eef4ea --- /dev/null +++ b/app/src/main/res/drawable/control_background_item_dis.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/fragment_custom.xml b/app/src/main/res/layout-land/fragment_custom.xml index e5d1cc1..a236841 100644 --- a/app/src/main/res/layout-land/fragment_custom.xml +++ b/app/src/main/res/layout-land/fragment_custom.xml @@ -462,6 +462,43 @@ app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + diff --git a/app/src/main/res/layout-port/fragment_custom.xml b/app/src/main/res/layout-port/fragment_custom.xml index efab550..98bfd31 100644 --- a/app/src/main/res/layout-port/fragment_custom.xml +++ b/app/src/main/res/layout-port/fragment_custom.xml @@ -74,8 +74,8 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/dp_4" android:text="位置" - android:textSize="@dimen/sp_18" android:textColor="@color/white" + android:textSize="@dimen/sp_18" android:textStyle="bold" app:layout_constraintStart_toStartOf="@+id/tv_temp" app:layout_constraintTop_toBottomOf="@+id/tv_temp" /> @@ -130,8 +130,8 @@ - - - - - - - - - + + + + + + + + + @@ -198,12 +198,12 @@ @@ -257,10 +257,10 @@ android:layout_height="wrap_content" android:layout_marginStart="@dimen/dp_8" android:text="一键加速" - android:visibility="gone" android:textColor="@color/lightGray" android:textSize="@dimen/sp_17" android:textStyle="bold" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -269,26 +269,26 @@ - - - - - - - - - - - + + + + + + + + + + + - + android:orientation="vertical"> - + - + - + - - - - - - - - - - + - - - - - - - - - - - - - + - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_control.xml b/app/src/main/res/layout/activity_control.xml new file mode 100644 index 0000000..530eb7b --- /dev/null +++ b/app/src/main/res/layout/activity_control.xml @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 1a49501..3541eef 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -16,4 +16,16 @@ + + 0.85 + 1.0 + 1.15 + 1.30 + + + "小" + "默认" + "大" + "最大" + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 7e87a94..70b7022 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ include ':app', ':niceimageview' -rootProject.name='UIUIOS关怀系统' \ No newline at end of file +rootProject.name='AIOS系统' \ No newline at end of file