diff --git a/app/src/main/java/com/example/helponizer/Informaition.kt b/app/src/main/java/com/example/helponizer/Informaition.kt index 6510c06..79d159e 100644 --- a/app/src/main/java/com/example/helponizer/Informaition.kt +++ b/app/src/main/java/com/example/helponizer/Informaition.kt @@ -23,4 +23,9 @@ class Informaition : AppCompatActivity() { finish() } } + + override fun onResume() { + super.onResume() + TextSizeManager.applyTo(findViewById(R.id.main)) + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/helponizer/MainActivity.kt b/app/src/main/java/com/example/helponizer/MainActivity.kt index 791a596..690f514 100644 --- a/app/src/main/java/com/example/helponizer/MainActivity.kt +++ b/app/src/main/java/com/example/helponizer/MainActivity.kt @@ -43,4 +43,9 @@ class MainActivity : AppCompatActivity() { finish() } } + + override fun onResume() { + super.onResume() + TextSizeManager.applyTo(findViewById(R.id.main)) + } } diff --git a/app/src/main/java/com/example/helponizer/Raspisanie.kt b/app/src/main/java/com/example/helponizer/Raspisanie.kt index 7890061..0266e98 100644 --- a/app/src/main/java/com/example/helponizer/Raspisanie.kt +++ b/app/src/main/java/com/example/helponizer/Raspisanie.kt @@ -24,4 +24,9 @@ class Raspisanie : AppCompatActivity() { finish() } } + + override fun onResume() { + super.onResume() + TextSizeManager.applyTo(findViewById(R.id.main)) + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/helponizer/Settings.kt b/app/src/main/java/com/example/helponizer/Settings.kt index 9f4bd35..34bbccc 100644 --- a/app/src/main/java/com/example/helponizer/Settings.kt +++ b/app/src/main/java/com/example/helponizer/Settings.kt @@ -1,16 +1,17 @@ package com.example.helponizer import android.content.Intent +import android.media.MediaPlayer import android.os.Bundle import android.view.View import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat -import android.media.MediaPlayer class Settings : AppCompatActivity() { private var player: MediaPlayer? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() @@ -20,21 +21,37 @@ class Settings : AppCompatActivity() { v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) insets } + + findViewById(R.id.buttonSound).setOnClickListener { + player?.release() + player = MediaPlayer.create(this, R.raw.click) + player?.start() + } + + findViewById(R.id.buttonTextUp).setOnClickListener { + TextSizeManager.increase(this) + TextSizeManager.applyTo(findViewById(R.id.main)) + } + + findViewById(R.id.buttonTextDown).setOnClickListener { + TextSizeManager.decrease(this) + TextSizeManager.applyTo(findViewById(R.id.main)) + } + findViewById(R.id.buttonOnMain).setOnClickListener { startActivity(Intent(this, MainActivity::class.java)) finish() - findViewById(R.id.buttonSound).setOnClickListener { - player?.release() - player = MediaPlayer.create(this, R.raw.click) - player?.start() - - } } - } - override fun onDestroy(){ + + override fun onResume() { + super.onResume() + TextSizeManager.applyTo(findViewById(R.id.main)) + } + + override fun onDestroy() { player?.release() player = null super.onDestroy() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/helponizer/TextSizeManager.kt b/app/src/main/java/com/example/helponizer/TextSizeManager.kt new file mode 100644 index 0000000..2ef3308 --- /dev/null +++ b/app/src/main/java/com/example/helponizer/TextSizeManager.kt @@ -0,0 +1,60 @@ +package com.example.helponizer + +import android.content.Context +import android.util.TypedValue +import android.view.View +import android.view.ViewGroup +import android.widget.TextView + +object TextSizeManager { + private const val PREFS_NAME = "helponizer_prefs" + private const val KEY_SCALE = "text_scale" + private const val MIN_SCALE = 0.8f + private const val MAX_SCALE = 2.0f + private const val STEP = 0.1f + private const val TAG_ORIGINAL_SIZE = -0x54a1 // id для сохранения исходного размера + + private var scale: Float? = null + + fun getScale(context: Context): Float { + if (scale == null) { + val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + scale = prefs.getFloat(KEY_SCALE, 1f).coerceIn(MIN_SCALE, MAX_SCALE) + } + return scale!! + } + + fun increase(context: Context): Float = change(context, STEP) + + fun decrease(context: Context): Float = change(context, -STEP) + + private fun change(context: Context, delta: Float): Float { + val newScale = (getScale(context) + delta).coerceIn(MIN_SCALE, MAX_SCALE) + scale = newScale + context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + .edit() + .putFloat(KEY_SCALE, newScale) + .apply() + return newScale + } + + fun applyTo(root: View) { + applyToView(root, getScale(root.context)) + } + + private fun applyToView(view: View, scale: Float) { + if (view is TextView) { + val original = view.getTag(TAG_ORIGINAL_SIZE) as? Float + ?: view.textSize.also { view.setTag(TAG_ORIGINAL_SIZE, it) } + val target = original * scale + if (view.textSize != target) { + view.setTextSize(TypedValue.COMPLEX_UNIT_PX, target) + } + } + if (view is ViewGroup) { + for (i in 0 until view.childCount) { + applyToView(view.getChildAt(i), scale) + } + } + } +} diff --git a/app/src/main/java/com/example/helponizer/infoProgram.kt b/app/src/main/java/com/example/helponizer/infoProgram.kt index f53c05b..6e7ba4f 100644 --- a/app/src/main/java/com/example/helponizer/infoProgram.kt +++ b/app/src/main/java/com/example/helponizer/infoProgram.kt @@ -24,4 +24,9 @@ class infoProgram : AppCompatActivity() { finish() } } + + override fun onResume() { + super.onResume() + TextSizeManager.applyTo(findViewById(R.id.main)) + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 4976f55..f5b286f 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -7,7 +7,7 @@ android:layout_height="match_parent" android:background="@color/platine" android:fillViewport="true" - tools:context=".infoProgram"> + tools:context=".Settings"> @@ -38,7 +38,7 @@ android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="16dp" - android:text="Сменить палитру" + android:text="@string/settings_change_palette" android:textSize="15sp"/> "Приложение создано для помощи студентам \n в организации учебного процесса. Оно \nпозволяет просматривать расписание занятий \nи знакомиться с полезными рекомендациями \nпо обучению." "Разработчик:\nЧесаков Никита Сергеевич\nГруппа: ИСП-24/9\n\nГод разработки: 2026" + + Настройки + Сменить палитру + Воспроизвести звук + A+ Увеличить текст + A− Уменьшить текст + Включить уведомление + На главную