Template initial state

This commit is contained in:
Андрей II Лимасов 2024-11-13 08:20:09 +03:00
parent f4011dde9e
commit 8f7bf548b3
6 changed files with 123 additions and 16 deletions

View File

@ -32,6 +32,10 @@ android {
} }
dependencies { dependencies {
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.activity:activity:1.9.3")
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
defaultLibrary() defaultLibrary()
} }

View File

@ -1,16 +1,26 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<application <application
android:allowBackup="true" android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Default" android:theme="@style/Theme.Default"
tools:targetApi="31" /> tools:targetApi="33">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest> </manifest>

View File

@ -0,0 +1,55 @@
package ru.myitschool.work;
import static java.util.Map.entry;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Map;
import ru.myitschool.work.databinding.ActivityMainBinding;
@RequiresApi(api = Build.VERSION_CODES.TIRAMISU)
public class MainActivity extends AppCompatActivity {
final static Map<String, String> CodelabActionsMap = Map.ofEntries(
entry(Intent.ACTION_AIRPLANE_MODE_CHANGED, "ACTION_AIRPLANE_MODE_CHANGED"),
entry(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED, "ACTION_APPLICATION_RESTRICTIONS_CHANGED"),
entry(Intent.ACTION_APPLICATION_LOCALE_CHANGED, "ACTION_APPLICATION_LOCALE_CHANGED"),
entry(Intent.ACTION_ASSIST, "ACTION_ASSIST"),
entry(Intent.ACTION_BATTERY_CHANGED, "ACTION_BATTERY_CHANGED"),
entry(Intent.ACTION_BATTERY_LOW, "ACTION_BATTERY_LOW"),
entry(Intent.ACTION_BATTERY_OKAY, "ACTION_BATTERY_OKAY"),
entry(Intent.ACTION_CALL, "ACTION_CALL"),
entry(Intent.ACTION_DATE_CHANGED, "ACTION_DATE_CHANGED"),
entry(Intent.ACTION_DEFAULT, "ACTION_DEFAULT"),
entry(Intent.ACTION_HEADSET_PLUG, "ACTION_HEADSET_PLUG"),
entry(Intent.ACTION_LOCALE_CHANGED, "ACTION_LOCALE_CHANGED"),
entry(Intent.ACTION_TIME_TICK, "ACTION_TIME_TICK")
);
ActivityMainBinding ui;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ui = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(ui.getRoot());
}
public BroadcastReceiver makeBroadcastReceiver() {
return new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
var text = CodelabActionsMap.get(intent.getAction());
if (text != null) ui.content.statusText.setText(text);
}
};
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<include
android:id="@+id/content"
layout="@layout/content_main" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/status_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center"
android:text="@string/text"
android:textSize="25sp" />
</LinearLayout>

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">Work</string> <string name="app_name">Созерцание</string>
<string name="text">Ожидание…</string>
</resources> </resources>