diff --git a/app/.gitignore b/app/.gitignore deleted file mode 100644 index 3543521..0000000 --- a/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/app/build.gradle b/app/build.gradle index b67ac91..07ae2be 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,13 +14,13 @@ android { } } compileSdkVersion 29 - buildToolsVersion "29.0.0" + buildToolsVersion "29.0.2" defaultConfig { applicationId "soheilkd.BurninWiper" - minSdkVersion 16 + minSdkVersion 17 targetSdkVersion 29 - versionCode 18 - versionName "1.07.1" + versionCode 24 + versionName "1.1" } buildTypes { release { @@ -35,11 +35,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0-rc01' - implementation 'androidx.core:core-ktx:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' - implementation 'com.google.android.material:material:1.1.0-alpha09' implementation 'com.android.billingclient:billing:2.0.1' - implementation 'androidx.preference:preference:1.1.0-rc01' + implementation 'androidx.preference:preference:1.1.0' + implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.17' + implementation 'com.google.android.material:material:1.1.0-alpha10' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1b90011..9e79e8f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,9 +1,11 @@ + xmlns:tools="http://schemas.android.com/tools" + package="soheilkd.BurninWiper"> + + + - - + + - - + - + android:screenOrientation="portrait" /> - + android:screenOrientation="portrait" + android:theme="@style/FullscreenTheme" /> + \ No newline at end of file diff --git a/app/src/main/java/soheilkd/burninwiper/AnimActivity.kt b/app/src/main/java/soheilkd/burninwiper/AnimActivity.kt new file mode 100644 index 0000000..fa6f7c2 --- /dev/null +++ b/app/src/main/java/soheilkd/burninwiper/AnimActivity.kt @@ -0,0 +1,68 @@ +package soheilkd.BurninWiper + +import android.os.Bundle +import android.os.SystemClock +import android.util.DisplayMetrics +import android.view.ViewGroup +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity + +import kotlinx.android.synthetic.main.activity_anim.* +import pl.droidsonroids.gif.GifImageView +import kotlin.math.roundToInt + +class AnimActivity : AppCompatActivity() { + private val gifViews = arrayListOf() + private val gifs = arrayOf( + R.drawable.gif_0, + R.drawable.gif_1, + R.drawable.gif_2, + R.drawable.gif_3, + R.drawable.gif_4, + R.drawable.gif_5, + R.drawable.gif_6, + R.drawable.gif_7 + ) + private var animThread = Thread(Runnable { + while (true) { + for (gif in gifs) { + for (view in gifViews) { + runOnUiThread { view.setImageResource(gif) } + } + SystemClock.sleep(20000) + } + } + }) + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_anim) + anim_grid.setOnClickListener { finish() } + + Helper.makeImmersive(window, anim_grid) + if (intent.getBooleanExtra("IsChecking", false)) + return + loadViews() + animThread.start() + Helper.setTimer(intent.getIntExtra("TimerIndex", 0)) { finish() } + Toast.makeText(this, "Cautious: Device may heat up after a while", Toast.LENGTH_LONG).show() + } + + private fun loadViews() { + val metrics = DisplayMetrics() + windowManager.defaultDisplay.getMetrics(metrics) + + anim_grid.columnCount = (metrics.widthPixels / metrics.density / 75).roundToInt() + 1 + anim_grid.rowCount = (metrics.heightPixels / metrics.density / 75).roundToInt() + 1 + val dps = (75 * metrics.scaledDensity + 0.5f).toInt() + for (i in 0..anim_grid.columnCount * anim_grid.rowCount) { + val view = GifImageView(this) + view.layoutParams = ViewGroup.LayoutParams(dps, dps) + view.setOnClickListener { finish() } + gifViews.add(view) + } + for (view in gifViews) { + anim_grid.addView(view) + } + } +} diff --git a/app/src/main/java/soheilkd/burninwiper/ColorActivity.kt b/app/src/main/java/soheilkd/burninwiper/ColorActivity.kt index 42cc0e7..af4390b 100644 --- a/app/src/main/java/soheilkd/burninwiper/ColorActivity.kt +++ b/app/src/main/java/soheilkd/burninwiper/ColorActivity.kt @@ -1,101 +1,53 @@ package soheilkd.BurninWiper -import android.graphics.Color import android.graphics.drawable.ColorDrawable -import android.os.AsyncTask -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.SystemClock -import android.util.Log -import androidx.preference.PreferenceManager -import android.view.View +import androidx.appcompat.app.AppCompatActivity import kotlinx.android.synthetic.main.activity_color.* -import java.util.* -import kotlin.concurrent.timerTask class ColorActivity : AppCompatActivity() { private var currentColors: Array = arrayOf() - private var shutdownTimer = Timer() private var colorThread = Thread(Runnable { while(true){ for(color in currentColors){ - runOnUiThread { ColorFrameLayout.background = color } + runOnUiThread { color_layout.background = color } SystemClock.sleep(1250) } } }) - private fun getColorArrayById(id: Int): Array{ - return when (id){ - R.id.modeRadioButton1 -> getColorArray(0) - R.id.modeRadioButton2 -> getColorArray(1) - R.id.modeRadioButton3 -> getColorArray(2) - else -> getColorArray(-1) - } - } - private fun getColorArray(index: Int): Array{ - val white by lazy { ColorDrawable(Color.WHITE) } - val red by lazy { ColorDrawable(Color.RED) } - val green by lazy { ColorDrawable(Color.GREEN) } - val blue by lazy { ColorDrawable(Color.BLUE) } - val black by lazy { ColorDrawable(Color.BLACK) } - val gray by lazy { ColorDrawable(Color.DKGRAY) } - - return when (index){ - 0 -> arrayOf(white, red, green, blue, black) - 1 -> arrayOf(white, black) - 2 -> arrayOf(white) - else -> arrayOf(gray) - } - } - private fun start(){ - makeAppImmersive() + Helper.makeImmersive(window, color_layout) applyPreferences() colorThread.start() } - private fun makeAppImmersive(){ - window.setFlags(128, 128) - ColorFrameLayout.systemUiVisibility = - View.SYSTEM_UI_FLAG_LOW_PROFILE or - View.SYSTEM_UI_FLAG_FULLSCREEN or - View.SYSTEM_UI_FLAG_LAYOUT_STABLE or - View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or - View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + + //Check if application is launched by app shortcuts + private fun checkFromShortcut(): Boolean { + if (intent.action?.startsWith("soheilkd.BurninWiper.") == true) { + currentColors = Helper.getColorArray( + when (intent.action?.takeLast(4)) { + "run1" -> 0 + "run2" -> 1 + "run3" -> 2 + else -> -1 + } + ) + return true + } + return false } + private fun applyPreferences(){ - if (intent.getBooleanExtra("burninwiper.ischecking", false)){ - currentColors = getColorArray(-1) + if (intent.getBooleanExtra("IsChecking", false)) { + currentColors = Helper.getColorArray(-1) return } - //The comparisions to true are for casting the Boolean? expressions to Boolean - if (intent.action?.startsWith("soheilkd.BurninWiper.") == true){ - if (intent.action?.endsWith("runfirstmode") == true) - currentColors = getColorArray(0) - else if (intent.action?.endsWith("runsecondmode") == true) - currentColors = getColorArray(1) - else - currentColors = getColorArray(2) - } - if (currentColors.count() == 0) - currentColors = getColorArrayById(intent.getIntExtra("burninwiper.colormode", 0)) - setShutdownTimer(intent.getIntExtra("burninwiper.timerindex", 0)) - } - private fun setShutdownTimer(index: Int){ - val timerTask = timerTask { - finish() - } - fun minToMs(m: Int): Long {return m*60L*1000} - when(index) { - 1 -> shutdownTimer.schedule(timerTask, minToMs(5)) - 2 -> shutdownTimer.schedule(timerTask, minToMs(10)) - 3 -> shutdownTimer.schedule(timerTask, minToMs(20)) - 4 -> shutdownTimer.schedule(timerTask, minToMs(30)) - 5 -> shutdownTimer.schedule(timerTask, minToMs(60)) - 6 -> shutdownTimer.schedule(timerTask, minToMs(120)) - 7 -> shutdownTimer.schedule(timerTask, minToMs(180)) - } + if (!checkFromShortcut()) + currentColors = Helper.getColorArrayById(intent.getIntExtra("ColorMode", 0)) + + Helper.setTimer(intent.getIntExtra("TimerIndex", 0)) { finish() } } override fun onCreate(savedInstanceState: Bundle?) { @@ -103,7 +55,7 @@ class ColorActivity : AppCompatActivity() { setContentView(R.layout.activity_color) - ColorFrameLayout.setOnTouchListener{ _, _ -> + color_layout.setOnTouchListener { _, _ -> finish() true } diff --git a/app/src/main/java/soheilkd/burninwiper/DonationActivity.kt b/app/src/main/java/soheilkd/burninwiper/DonationActivity.kt index bf2d986..c443ca3 100644 --- a/app/src/main/java/soheilkd/burninwiper/DonationActivity.kt +++ b/app/src/main/java/soheilkd/burninwiper/DonationActivity.kt @@ -2,15 +2,13 @@ package soheilkd.BurninWiper import android.annotation.SuppressLint import android.os.Bundle +import android.util.TypedValue import android.widget.Button import android.widget.LinearLayout import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.android.billingclient.api.* - import kotlinx.android.synthetic.main.activity_donation.* -import kotlin.collections.ArrayList -import android.util.TypedValue class DonationActivity : AppCompatActivity(), PurchasesUpdatedListener { @@ -63,7 +61,6 @@ class DonationActivity : AppCompatActivity(), PurchasesUpdatedListener { skuList.add("soheilkd.burninwiper.donation3") skuList.add("soheilkd.burninwiper.donation4") skuList.add("soheilkd.burninwiper.donation5") - skuList.add("soheilkd.burninwiper.donation6") val params = SkuDetailsParams.newBuilder() params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP) var i = 0 @@ -77,7 +74,7 @@ class DonationActivity : AppCompatActivity(), PurchasesUpdatedListener { listOfSkuDetails = skuDetailsList for (sku in skuDetailsList) { val index = i++ - MainLinearLayout.addView( + donation_layout.addView( Button(this@DonationActivity).also { button -> run { val r = resources @@ -89,10 +86,11 @@ class DonationActivity : AppCompatActivity(), PurchasesUpdatedListener { button.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, px.toInt()) - button.text = "${sku.priceCurrencyCode}${sku.price}" + + button.text = "${sku.description} for ${sku.price}" px = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_SP, - 8f, + 5f, r.displayMetrics ) button.textSize = px @@ -110,13 +108,21 @@ class DonationActivity : AppCompatActivity(), PurchasesUpdatedListener { } override fun onBillingServiceDisconnected() { - // Try to restart the connection on the next request to - // Google Play by calling the startConnection() method. + Toast.makeText( + this@DonationActivity, + "Billing Service Disconnected", + Toast.LENGTH_LONG + ).show() + finish() } }) } catch (e: Exception) { - Toast.makeText(this@DonationActivity, "Connection To Playstore Billing Failed", Toast.LENGTH_LONG).show() + Toast.makeText( + this@DonationActivity, + "Connection To Play Store Billing Failed", + Toast.LENGTH_LONG + ).show() finish() } } diff --git a/app/src/main/java/soheilkd/burninwiper/Helper.kt b/app/src/main/java/soheilkd/burninwiper/Helper.kt new file mode 100644 index 0000000..41508c2 --- /dev/null +++ b/app/src/main/java/soheilkd/burninwiper/Helper.kt @@ -0,0 +1,69 @@ +package soheilkd.BurninWiper + +import android.graphics.Color +import android.graphics.drawable.ColorDrawable +import android.view.View +import android.view.Window +import java.util.* +import kotlin.concurrent.timerTask + +class Helper { + companion object { + fun setTimer(index: Int, onFinish: () -> Unit): Timer { + val timer = Timer() + val timerTask = timerTask { + onFinish() + } + + fun minToMs(m: Int): Long { + return m * 60L * 1000 + } + when (index) { + 1 -> timer.schedule(timerTask, minToMs(5)) + 2 -> timer.schedule(timerTask, minToMs(10)) + 3 -> timer.schedule(timerTask, minToMs(20)) + 4 -> timer.schedule(timerTask, minToMs(30)) + 5 -> timer.schedule(timerTask, minToMs(60)) + 6 -> timer.schedule(timerTask, minToMs(120)) + 7 -> timer.schedule(timerTask, minToMs(180)) + } + return timer + } + + fun makeImmersive(window: Window, view: View) { + window.setFlags(128, 128) + view.systemUiVisibility = + View.SYSTEM_UI_FLAG_LOW_PROFILE or + View.SYSTEM_UI_FLAG_FULLSCREEN or + View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or + View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + } + + fun getColorArrayById(id: Int): Array { + return when (id) { + R.id.main_radio1 -> getColorArray(0) + R.id.main_radio2 -> getColorArray(1) + R.id.main_radio3 -> getColorArray(2) + else -> getColorArray(-1) + } + } + + fun getColorArray(index: Int): Array { + val white by lazy { ColorDrawable(Color.WHITE) } + val red by lazy { ColorDrawable(Color.RED) } + val green by lazy { ColorDrawable(Color.GREEN) } + val blue by lazy { ColorDrawable(Color.BLUE) } + val black by lazy { ColorDrawable(Color.BLACK) } + val gray by lazy { ColorDrawable(Color.DKGRAY) } + + return when (index) { + 0 -> arrayOf(white, red, green, blue, black) + 1 -> arrayOf(white, black) + 2 -> arrayOf(white) + else -> arrayOf(gray) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/soheilkd/burninwiper/MainActivity.kt b/app/src/main/java/soheilkd/burninwiper/MainActivity.kt index 444884a..be6d894 100644 --- a/app/src/main/java/soheilkd/burninwiper/MainActivity.kt +++ b/app/src/main/java/soheilkd/burninwiper/MainActivity.kt @@ -2,13 +2,10 @@ package soheilkd.BurninWiper import android.content.Intent import android.os.Bundle -import android.util.Log import android.widget.ArrayAdapter -import androidx.preference.PreferenceManager import androidx.appcompat.app.AppCompatActivity - +import androidx.preference.PreferenceManager import kotlinx.android.synthetic.main.activity_main.* -import kotlinx.android.synthetic.main.content_main.* class MainActivity : AppCompatActivity() { @@ -19,9 +16,9 @@ class MainActivity : AppCompatActivity() { loadTimerItems() loadPreferences() - StartButton.setOnClickListener { run { start() } } - CheckButton.setOnClickListener { run { start(true) } } - DonateButton.setOnClickListener { run { openDonate() } } + main_startButton.setOnClickListener { run { start() } } + main_checkButton.setOnClickListener { run { start(true) } } + main_donateButton.setOnClickListener { run { openDonate() } } } override fun onDestroy(){ @@ -33,31 +30,37 @@ class MainActivity : AppCompatActivity() { val prefs = PreferenceManager.getDefaultSharedPreferences(this) val editor = prefs.edit() - editor.putInt("ModeId", ModeRadioGroup.checkedRadioButtonId) - editor.putInt("TimerIndex", TimerSpinner.selectedItemPosition) + editor.putInt("ModeId", main_radioGroup.checkedRadioButtonId) + editor.putInt("TimerIndex", main_timeSpinner.selectedItemPosition) editor.apply() } private fun loadPreferences() { val prefs = PreferenceManager.getDefaultSharedPreferences(this) - ModeRadioGroup.clearCheck() - ModeRadioGroup.check(prefs.getInt("ModeId", R.id.modeRadioButton1)) - TimerSpinner.setSelection(prefs.getInt("TimerIndex", 0)) + main_radioGroup.clearCheck() + main_radioGroup.check(prefs.getInt("ModeId", R.id.main_radio1)) + main_timeSpinner.setSelection(prefs.getInt("TimerIndex", 0)) } private fun loadTimerItems() { - val timerItems = arrayOf(R.string.ui_timerNone, "5m", "10m", "20m", "30m", "1h", "2h", "3h") + val timerItems = + arrayOf(getString(R.string.ui_timerNone), "5m", "10m", "20m", "30m", "1h", "2h", "3h") val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, timerItems) adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) - TimerSpinner.adapter = adapter + main_timeSpinner.adapter = adapter } private fun start(isChecking: Boolean = false) { savePreferences() - val intent = Intent(this, ColorActivity::class.java) - intent.putExtra("burninwiper.colormode", ModeRadioGroup.checkedRadioButtonId) - intent.putExtra("burninwiper.timerindex", TimerSpinner.selectedItemPosition) - intent.putExtra("burninwiper.ischecking", isChecking) + val intent = + when (main_radioGroup.checkedRadioButtonId) { + R.id.main_radio4 -> Intent(this, AnimActivity::class.java) //aka animation mode + else -> Intent(this, ColorActivity::class.java) //aka other modes + } + intent.putExtra("TimerIndex", main_timeSpinner.selectedItemPosition) + intent.putExtra("ColorMode", main_radioGroup.checkedRadioButtonId) + intent.putExtra("IsChecking", isChecking) + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) startActivity(intent) } @@ -66,5 +69,4 @@ class MainActivity : AppCompatActivity() { val intent = Intent(this, DonationActivity::class.java) startActivity(intent) } - } diff --git a/app/src/main/res/drawable-v24/gif_0.gif b/app/src/main/res/drawable-v24/gif_0.gif new file mode 100644 index 0000000..223c898 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_0.gif differ diff --git a/app/src/main/res/drawable-v24/gif_1.gif b/app/src/main/res/drawable-v24/gif_1.gif new file mode 100644 index 0000000..b208b24 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_1.gif differ diff --git a/app/src/main/res/drawable-v24/gif_2.gif b/app/src/main/res/drawable-v24/gif_2.gif new file mode 100644 index 0000000..3e51151 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_2.gif differ diff --git a/app/src/main/res/drawable-v24/gif_3.gif b/app/src/main/res/drawable-v24/gif_3.gif new file mode 100644 index 0000000..6e8b3c9 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_3.gif differ diff --git a/app/src/main/res/drawable-v24/gif_4.gif b/app/src/main/res/drawable-v24/gif_4.gif new file mode 100644 index 0000000..171fc99 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_4.gif differ diff --git a/app/src/main/res/drawable-v24/gif_5.gif b/app/src/main/res/drawable-v24/gif_5.gif new file mode 100644 index 0000000..98d3e56 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_5.gif differ diff --git a/app/src/main/res/drawable-v24/gif_6.gif b/app/src/main/res/drawable-v24/gif_6.gif new file mode 100644 index 0000000..2477b7b Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_6.gif differ diff --git a/app/src/main/res/drawable-v24/gif_7.gif b/app/src/main/res/drawable-v24/gif_7.gif new file mode 100644 index 0000000..06c25c2 Binary files /dev/null and b/app/src/main/res/drawable-v24/gif_7.gif differ diff --git a/app/src/main/res/drawable/ic_shortcut4.png b/app/src/main/res/drawable/ic_shortcut4.png new file mode 100644 index 0000000..8a2a1b0 Binary files /dev/null and b/app/src/main/res/drawable/ic_shortcut4.png differ diff --git a/app/src/main/res/layout/activity_anim.xml b/app/src/main/res/layout/activity_anim.xml new file mode 100644 index 0000000..05c5aac --- /dev/null +++ b/app/src/main/res/layout/activity_anim.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_color.xml b/app/src/main/res/layout/activity_color.xml index 49bc5df..e4f6923 100644 --- a/app/src/main/res/layout/activity_color.xml +++ b/app/src/main/res/layout/activity_color.xml @@ -3,7 +3,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0099cc" - android:id="@+id/ColorFrameLayout" + android:id="@+id/color_layout" android:theme="@style/AppTheme.NoActionBar" - tools:context="soheilkd.BurninWiper.ColorActivity"> + tools:context=".ColorActivity"> diff --git a/app/src/main/res/layout/activity_donation.xml b/app/src/main/res/layout/activity_donation.xml index 2035a42..6e41917 100644 --- a/app/src/main/res/layout/activity_donation.xml +++ b/app/src/main/res/layout/activity_donation.xml @@ -2,20 +2,32 @@ + +