From 46b8faa360ea613de3ce6584daff68901cb2b1b4 Mon Sep 17 00:00:00 2001 From: oboard Date: Sun, 29 Dec 2024 13:03:04 +0800 Subject: [PATCH] upgrade: gradle version --- .gitignore | 18 + app/build.gradle | 31 ++ app/proguard-rules.pro | 17 + app/src/main/AndroidManifest.xml | 26 ++ .../main/java/com/oboard/ts/MainActivity.java | 340 ++++++++++++++++++ app/src/main/res/anim/side_down_in.xml | 6 + app/src/main/res/anim/side_down_out.xml | 6 + app/src/main/res/drawable/a.png | Bin 0 -> 867 bytes app/src/main/res/drawable/b.png | Bin 0 -> 530 bytes app/src/main/res/drawable/background.xml | 6 + app/src/main/res/drawable/dropbar.xml | 5 + app/src/main/res/drawable/selectground.xml | 5 + app/src/main/res/layout/main.xml | 122 +++++++ app/src/main/res/mipmap/i.png | Bin 0 -> 8977 bytes app/src/main/res/values-v21/colors.xml | 9 + app/src/main/res/values-v21/styles.xml | 14 + app/src/main/res/values-zh/strings.xml | 10 + app/src/main/res/values/strings.xml | 10 + app/src/main/res/values/styles.xml | 6 + build.gradle | 22 ++ gradle/wrapper/gradle-wrapper.properties | 7 + settings.gradle | 1 + 22 files changed, 661 insertions(+) create mode 100644 .gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/oboard/ts/MainActivity.java create mode 100644 app/src/main/res/anim/side_down_in.xml create mode 100644 app/src/main/res/anim/side_down_out.xml create mode 100644 app/src/main/res/drawable/a.png create mode 100644 app/src/main/res/drawable/b.png create mode 100644 app/src/main/res/drawable/background.xml create mode 100644 app/src/main/res/drawable/dropbar.xml create mode 100644 app/src/main/res/drawable/selectground.xml create mode 100644 app/src/main/res/layout/main.xml create mode 100644 app/src/main/res/mipmap/i.png create mode 100644 app/src/main/res/values-v21/colors.xml create mode 100644 app/src/main/res/values-v21/styles.xml create mode 100644 app/src/main/res/values-zh/strings.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77a66a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +build + +.DS_Store +.idea + +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..aed36d5 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.oboard.ts' + compileSdk 34 + + defaultConfig { + applicationId "com.oboard.ts" + minSdk 21 + targetSdk 34 + versionCode 11 + versionName "1.6.1" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..233bad2 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\tools\adt-bundle-windows-x86_64-20131030\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..74a83ad --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/oboard/ts/MainActivity.java b/app/src/main/java/com/oboard/ts/MainActivity.java new file mode 100644 index 0000000..e07ee71 --- /dev/null +++ b/app/src/main/java/com/oboard/ts/MainActivity.java @@ -0,0 +1,340 @@ +package com.oboard.ts; + +import android.animation.ValueAnimator; +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Configuration; +import android.graphics.BitmapFactory; +import android.graphics.drawable.Icon; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; +import android.media.AudioManager; +import android.os.Build; +import android.os.Bundle; +import android.os.PowerManager; +import android.view.KeyEvent; +import android.view.View; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.Switch; + +import java.util.Timer; +import java.util.TimerTask; + +public class MainActivity extends Activity implements SensorEventListener { + AudioManager audioManager; + SensorManager sensorManager; + PowerManager.WakeLock mWakeLock; + PowerManager mPowerManager; + + Switch cb;//传感开关 + Timer mTimer;//timer + TimerTask mTimerTask;//timertask + int mMode; + String mName = ""; + View ii; + SeekBar mVolumeBar; + Sensor mSensor;//传感器 + LinearLayout ll; + + int maxVolume, systemVolume; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + overridePendingTransition(R.anim.side_down_in, R.anim.side_down_out); + + setContentView(R.layout.main); + + ii = findViewById(R.id.i); + cb = findViewById(R.id.mainCheckBox1); + mVolumeBar = findViewById(R.id.mainSeekBar1); + ll = findViewById(R.id.mainLinearLayout); + + cb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { + @SuppressLint("InvalidWakeLockTag") + public void onCheckedChanged(CompoundButton view, boolean state) { + if (state) { + sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); + mSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); + + //息屏设置 + mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); + mWakeLock = mPowerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, ""); + + //注册传感器,先判断有没有传感器 + if (mSensor != null) + sensorManager.registerListener(MainActivity.this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); + } else { + //传感器取消监听 + sensorManager.unregisterListener(MainActivity.this); + //释放息屏 + if (mWakeLock.isHeld()) + mWakeLock.release(); + mWakeLock = null; + mPowerManager = null; + } + } + }); + + audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); + refreshVolume(); + mVolumeBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar sb, int p, boolean b) { + systemVolume = p; + audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, systemVolume, 0); + } + + public void onStartTrackingTouch(SeekBar sb) { + } + + public void onStopTrackingTouch(SeekBar sb) { + } + }); + + mTimer = new Timer(); + mTimerTask = new TimerTask() { + public void run() { + audioManager.setMode(mMode); + audioManager.setSpeakerphoneOn(false); + // 设置为通话状态 + setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); + + } + }; + mTimer.schedule(this.mTimerTask, 0, 1000); + + mName = getResources().getString(R.string.a); + setNotification(); + } + + public void refreshVolume() { + //获取系统的最大声音 + maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); + //获取系统当前的声音 + systemVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); + + //设置最大值 + mVolumeBar.setMax(maxVolume); + //设置为系统现在的音量 + mVolumeBar.setProgress(systemVolume); + } + + @Override + protected void onResume() { + super.onResume(); + overridePendingTransition(R.anim.side_down_in, R.anim.side_down_out); + } + + @Override + public void onAccuracyChanged(Sensor p1, int p2) { + //不能删,删了报错! + } + + /** + * 传感器变化 + */ + @Override + public void onSensorChanged(SensorEvent event) { + if (event.values[0] == 0.0) { + //贴近手机 + //关闭屏幕 + if (!mWakeLock.isHeld()) + mWakeLock.acquire(10 * 60 * 1000L /*10 minutes*/); + + } else { + //离开手机 + //唤醒设备 + if (mWakeLock.isHeld()) + mWakeLock.release(); + } + } + /* + int num = -1; + @Override + protected void onNewIntent(Intent intent) { + if (intent.getStringExtra("i") != null) { + ((View)mVolumeBar.getParent()).setVisibility(View.GONE); + String[] n = new String[] { + getResources().getString(R.string.a), + getResources().getString(R.string.b), + getResources().getString(R.string.c) + }; + + new AlertDialog.Builder(this) + .setTitle("EarPlay") + .setIcon(R.mipmap.i) + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + if (num >= 0) + onModeChange(new int[] {0, 3, 2, 1}[num]); + onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); + } + }) + .setNegativeButton("取消", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + onKeyDown(KeyEvent.KEYCODE_BACK, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); + } + }) + .setSingleChoiceItems(n, new int[] {0, 3, 2, 1}[mMode], new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + num = which; + } + }) + .create().show(); + + } else { + ((View)mVolumeBar.getParent()).setVisibility(View.VISIBLE); + } + + super.onNewIntent(intent); + } + */ + + @Override + protected void onDestroy() { + + cancelNotification(); + super.onDestroy(); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + switch (keyCode) { + case KeyEvent.KEYCODE_VOLUME_UP: + audioManager.adjustStreamVolume( + AudioManager.STREAM_MUSIC, + AudioManager.ADJUST_RAISE, + AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI); + refreshVolume(); + return true; + case KeyEvent.KEYCODE_VOLUME_DOWN: + audioManager.adjustStreamVolume( + AudioManager.STREAM_MUSIC, + AudioManager.ADJUST_LOWER, + AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI); + refreshVolume(); + return true; + default: + break; + } + + if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { + finish(); + } + return super.onKeyDown(keyCode, event); + } + + public void finish(View v) { + overridePendingTransition(R.anim.side_down_in, R.anim.side_down_out); + moveTaskToBack(true); + } + + public void onModeChange(View v) { + onModeChange(Integer.parseInt(v.getTag().toString())); + } + + public void onModeChange(int i) { + if (mMode == i) + return; + mMode = i;//储存模式 + int[] y = new int[]{0, 3, 2, 1}; + mName = new String[]{ + getResources().getString(R.string.a), + getResources().getString(R.string.b), + getResources().getString(R.string.c) + }[y[i]]; + mbar(ii.getHeight() * y[i]);//指示条 + cancelNotification();//删除通知 + setNotification();//显示通知 + } + + public void mbar(float y) { + //1.设置属性的初始值和结束值 + final ValueAnimator mAnimator = ValueAnimator.ofFloat(ii.getY(), y); + //2.为目标对象的属性变化设置监听器 + mAnimator.addUpdateListener(animation -> ii.setY((float) animation.getAnimatedValue())); + //3.设置动画的持续时间 + mAnimator.setDuration(250) + .start(); + } + + // 添加常驻通知 + public void setNotification() { + NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra("i", "i"); + PendingIntent contextIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE); + + Notification.Builder nb = new Notification.Builder(this); + nb.setSmallIcon(R.mipmap.i) + .setOngoing(true) + .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.i)) + .setContentIntent(contextIntent) + .setContentTitle("切换声音输出") + .setContentText("当前" + mName) + .setVisibility(Notification.VISIBILITY_PUBLIC); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (mName.equals(getResources().getString(R.string.a))) { + nb.setSmallIcon(Icon.createWithResource(this, R.drawable.b)); + } else { + nb.setSmallIcon(Icon.createWithResource(this, R.drawable.a)); + } + } + //设置消息属性 + //必须设置的属性:小图标 标题 内容 + notificationManager.notify(0, nb.build()); + } + + + public void about(View view) { + new AlertDialog.Builder(this) + .setTitle("关于") + .setMessage("谢谢您对本软件的支持 \n\n开发者\n 一块小板子 2232442466 \n鸣谢\n 小青光 1664147500") + .setPositiveButton("确定", null) + .setNegativeButton("不确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + finish(); + } + }) + .create().show(); + } + + // 取消通知 + public void cancelNotification() { + NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + notificationManager.cancel(0); + } + + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams(); + // Checks the orientation of the screen + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + lp.weight = 1.0f; + } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { + lp.weight = 0.0f; + } + ll.setLayoutParams(lp); + } + + +} diff --git a/app/src/main/res/anim/side_down_in.xml b/app/src/main/res/anim/side_down_in.xml new file mode 100644 index 0000000..c9521d3 --- /dev/null +++ b/app/src/main/res/anim/side_down_in.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/anim/side_down_out.xml b/app/src/main/res/anim/side_down_out.xml new file mode 100644 index 0000000..285dc5c --- /dev/null +++ b/app/src/main/res/anim/side_down_out.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/drawable/a.png b/app/src/main/res/drawable/a.png new file mode 100644 index 0000000000000000000000000000000000000000..08a2a06f26f6cfa84fda76ab46d9a72c7eed31f1 GIT binary patch literal 867 zcmV-p1DyPcP)XM9s2~(NQ=?#|VBAzi#ZXEkE;OZD>3d;(_qdtD zFf;j}uEhWHeEk3C9L~8H{_C)tIie`KYi4FfmY0{W{~G}rW^~ToS|}900sdTDTbph+ zn;Y}<^P>|J6OS2V9#YjwAQ6!jRediE!wZ`U+l4QX-=li)#zoA;K-Yz0ftLpb@n!es>H1>P%&jM4xi7dc4A=iK#Dsq}H0 zrqjT8B62*6qC?w`NL3Guh)3kw&4gQ^;N@1I{?T|GXGv=;-H zJUctPTSOjK)%7q8&lHQrN#KF;@$oCIR_lDL)%vZ~YMpJj+h4D&tPJdZKL##2j^kab zdPzhy%d&e^)mUpUh{zsQeKHKg_qQYM#lVPyAh-s+0qnKbE_FJcb>N7qrXq5(R;w)z zD{RLC0BM>wRrOO~%{iBaVR+73dk9z+k#Zczi#rwAv=ZlB-Z{4c=nY#GMf%hp!$jH%NUmV9vaU3u8^9+4Wx2(vRlfa^?z8c5z z7fF(QJ~lS?jH*5XoZ4{*n;{5-Yu@|kL}V0b7Yc<$Ro?~v$g=FU{`gIQw5`x?w|^)W ti)Vm6s+x$%Y4810<#PGQo8kMP;~#5ETMb#A7_R^T002ovPDHLkV1kHAm3sgH literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/b.png b/app/src/main/res/drawable/b.png new file mode 100644 index 0000000000000000000000000000000000000000..270f9fcb0956d434ade23786f7e7caa0a99be3e4 GIT binary patch literal 530 zcmV+t0`2{YP)R(xF@1rK8X0 zN(43biEItDp4-2olx)Fd>yV)k0``(F4IU$iEnb(STrPKKJI$E4NS~g*_d`O*0r#3C zDKo6KuK>Iy`JggD zVO799z$pNTNHcGcY-ab|7En(CXL%#DR=+iXWYZW^bIu*$`c({_a|gzlTIM9n14Lw1 zYdrvP>708GU=zS*I=|Ff4@6|ODr1pn`ciAXE+QWqjm9wmjK|}rBtHV!n%7(i@ZMi2 zrDhp_i{#O0G@7P$m}{AN?=On7N`E*>lI)7en_O5x@>-9GT#+0^QS`OyB=;)SUxJ9E Uf#&x8F8}}l07*qoM6N<$f*PgoT>t<8 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/background.xml b/app/src/main/res/drawable/background.xml new file mode 100644 index 0000000..04b550b --- /dev/null +++ b/app/src/main/res/drawable/background.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/drawable/dropbar.xml b/app/src/main/res/drawable/dropbar.xml new file mode 100644 index 0000000..1b01060 --- /dev/null +++ b/app/src/main/res/drawable/dropbar.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/selectground.xml b/app/src/main/res/drawable/selectground.xml new file mode 100644 index 0000000..3d8f9ff --- /dev/null +++ b/app/src/main/res/drawable/selectground.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/main.xml b/app/src/main/res/layout/main.xml new file mode 100644 index 0000000..d7ed825 --- /dev/null +++ b/app/src/main/res/layout/main.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + +