2424import android .view .animation .*;
2525import android .webkit .*;
2626import android .widget .*;
27- import androidx .core .*;
28- import androidx .lifecycle .lifecycle .runtime .anchor .*;
2927import com .aexon .material .viewpager .AexonViewPager ;
3028import com .aexon .view .AexonFloatingButton ;
3129import com .aexon .view .AexonNavigationBar ;
4341import com .aexon .aexon .animation .AexonAnimationCompat ;
4442import android .content .pm .ShortcutManager ;
4543import android .graphics .drawable .Icon ;
46- import android .content .pm .ShortcutInfo ;
44+ import android .content .pm .ShortcutInfo ;
45+
46+
4747
4848public class MainActivity extends Activity {
4949
50- private final AexonThemeListener themeListener = (seedColor , theme ) -> {
51- _applyTheme (theme );
50+ private final AexonThemeListener themeListener = (seedColor , theme ) -> {
51+ _applyTheme (theme );
5252 };
5353 private LinearLayout root_view ;
5454
@@ -69,8 +69,8 @@ protected void onCreate(Bundle _savedInstanceState) {
6969 }
7070
7171 private void initialize (Bundle _savedInstanceState ) {
72- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
73- getWindow ().setDecorFitsSystemWindows (true );
72+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
73+ getWindow ().setDecorFitsSystemWindows (true );
7474 }
7575 root_view = findViewById (R .id .root_view );
7676 toolbar = findViewById (R .id .toolbar );
@@ -79,111 +79,111 @@ private void initialize(Bundle _savedInstanceState) {
7979 fab = findViewById (R .id .fab );
8080 aexonnavigationbbar1 = findViewById (R .id .aexonnavigationbbar1 );
8181
82- viewpager1 .setOnPageScrollListener (new AexonViewPager .OnPageScrollListener () {
83- @ Override
84- public void onPageScrolled (int _position , float _positionOffset , int _positionOffsetPixels ) {
85-
82+ viewpager1 .setOnPageScrollListener (new AexonViewPager .OnPageScrollListener () {
83+ @ Override
84+ public void onPageScrolled (int _position , float _positionOffset , int _positionOffsetPixels ) {
85+
8686 }
8787
88- @ Override
89- public void onPageSelected (int _position ) {
90- AexonTheme theme = AexonTheme .getInstance ();
91- if (_position == 0 ) {
92- aexonnavigationbbar1 .setChecked (0 );
93- toolbar .setTitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_title_home_toolbar ));
94- toolbar .setSubtitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_sub_title_home_toolbar ));
95- toolbar .setItemVisible (R .id .action_power , true );
96- toolbar .setItemVisible (R .id .action_info , false );
97- _setStatus ();
98- }
99- if (_position == 1 ) {
100- aexonnavigationbbar1 .setChecked (1 );
101- toolbar .setTitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_title_app_toolbar ));
102- toolbar .setSubtitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_sub_title_app_toolbar ));
103- toolbar .setItemVisible (R .id .action_power , false );
104- toolbar .setItemVisible (R .id .action_info , false );
105- fab .setVisibility (View .GONE );
106- }
107- if (_position == 2 ) {
108- aexonnavigationbbar1 .setChecked (2 );
109- toolbar .setTitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_title_settings_toolbar ));
110- toolbar .setSubtitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_sub_title_settings_toolbar ));
111- toolbar .setItemVisible (R .id .action_power , false );
112- toolbar .setItemVisible (R .id .action_info , true );
113- fab .setVisibility (View .GONE );
114- }
88+ @ Override
89+ public void onPageSelected (int _position ) {
90+ AexonTheme theme = AexonTheme .getInstance ();
91+ if (_position == 0 ) {
92+ aexonnavigationbbar1 .setChecked (0 );
93+ toolbar .setTitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_title_home_toolbar ));
94+ toolbar .setSubtitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_sub_title_home_toolbar ));
95+ toolbar .setItemVisible (R .id .action_power , true );
96+ toolbar .setItemVisible (R .id .action_info , false );
97+ _setStatus ();
98+ }
99+ if (_position == 1 ) {
100+ aexonnavigationbbar1 .setChecked (1 );
101+ toolbar .setTitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_title_app_toolbar ));
102+ toolbar .setSubtitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_sub_title_app_toolbar ));
103+ toolbar .setItemVisible (R .id .action_power , false );
104+ toolbar .setItemVisible (R .id .action_info , false );
105+ fab .setVisibility (View .GONE );
106+ }
107+ if (_position == 2 ) {
108+ aexonnavigationbbar1 .setChecked (2 );
109+ toolbar .setTitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_title_settings_toolbar ));
110+ toolbar .setSubtitle (SketchwareUtil .getString (MainActivity .this , R .string .tag_sub_title_settings_toolbar ));
111+ toolbar .setItemVisible (R .id .action_power , false );
112+ toolbar .setItemVisible (R .id .action_info , true );
113+ fab .setVisibility (View .GONE );
114+ }
115115 }
116116
117- @ Override
118- public void onPageScrollStateChanged (int _scrollState ) {
119-
120- }
117+ @ Override
118+ public void onPageScrollStateChanged (int _scrollState ) {
119+
120+ }
121121 });
122122
123123 fab .setOnClickListener (_v -> {
124- ax_intent .setClass (MainActivity .this , TerminalActivity .class );
125- startActivity (ax_intent );
124+ ax_intent .setClass (MainActivity .this , TerminalActivity .class );
125+ startActivity (ax_intent );
126126 overridePendingTransition (R .anim .fade_in , R .anim .fade_out );
127127 });
128128 }
129129
130- private final Aexon .OnBinderReceivedListener mainBinderReceived = () -> {
131- runOnUiThread (() -> {
132- if (viewpager1 .getCurrentItem () == 0 ) _setStatus ();
133- });
134- };
135-
136- private final Aexon .OnBinderDeadListener mainBinderDead = () -> {
137- runOnUiThread (() -> {
138- if (viewpager1 .getCurrentItem () == 0 ) _setStatus ();
139- });
140- };
130+ private final Aexon .OnBinderReceivedListener mainBinderReceived = () -> {
131+ runOnUiThread (() -> {
132+ if (viewpager1 .getCurrentItem () == 0 ) _setStatus ();
133+ });
134+ };
135+
136+ private final Aexon .OnBinderDeadListener mainBinderDead = () -> {
137+ runOnUiThread (() -> {
138+ if (viewpager1 .getCurrentItem () == 0 ) _setStatus ();
139+ });
140+ };
141141 private void initializeLogic () {
142- FragmentAdapter fragment = new FragmentAdapter (getApplicationContext (), getFragmentManager ());
143- fragment .setTabCount (3 );
144- viewpager1 .setAdapter (fragment );
145- viewpager1 .setCurrentItem (0 );
146- viewpager1 .setOffscreenPageLimit (3 );
147-
148- aexonnavigationbbar1 .setOnItemSelectedListener (new AexonNavigationBar .OnItemSelectedListener () {
149- @ Override
150- public void onItemSelected (int index , int itemId ) {
151- viewpager1 .setCurrentItem (index , true );
152- }
153- });
154-
155- toolbar .setItemVisible (R .id .action_power , true );
156- toolbar .setItemVisible (R .id .action_info , false );
157- toolbar .setOnMenuItemClickListener ((itemId , view ) -> {
158- if (itemId == R .id .action_power ) {
159- DialogCustom dialog = new DialogCustom (MainActivity .this );
160- dialog .setOwnerActivity (MainActivity .this );
161- dialog .setOnSwipeListener (new DialogCustom .OnSwipeListener () {
162- @ Override
163- public void onSwipeUp () {
164- Aexon .stopDaemonPermanently ();
165- }
166- @ Override
167- public void onSwipeDown () {
168- Aexon .stopDaemon ();
169- }
170- });
171- dialog .show ();
172- } else if (itemId == R .id .action_info ) {
173- InfoDialogFragmentActivity bottomSheet = new InfoDialogFragmentActivity ();
174- bottomSheet .show (getFragmentManager (), "InfoDialog" );
175- }
142+ FragmentAdapter fragment = new FragmentAdapter (getApplicationContext (), getFragmentManager ());
143+ fragment .setTabCount (3 );
144+ viewpager1 .setAdapter (fragment );
145+ viewpager1 .setCurrentItem (0 );
146+ viewpager1 .setOffscreenPageLimit (3 );
147+
148+ aexonnavigationbbar1 .setOnItemSelectedListener (new AexonNavigationBar .OnItemSelectedListener () {
149+ @ Override
150+ public void onItemSelected (int index , int itemId ) {
151+ viewpager1 .setCurrentItem (index , true );
152+ }
153+ });
154+
155+ toolbar .setItemVisible (R .id .action_power , true );
156+ toolbar .setItemVisible (R .id .action_info , false );
157+ toolbar .setOnMenuItemClickListener ((itemId , view ) -> {
158+ if (itemId == R .id .action_power ) {
159+ DialogCustom dialog = new DialogCustom (MainActivity .this );
160+ dialog .setOwnerActivity (MainActivity .this );
161+ dialog .setOnSwipeListener (new DialogCustom .OnSwipeListener () {
162+ @ Override
163+ public void onSwipeUp () {
164+ Aexon .stopDaemonPermanently ();
165+ }
166+ @ Override
167+ public void onSwipeDown () {
168+ Aexon .stopDaemon ();
169+ }
170+ });
171+ dialog .show ();
172+ } else if (itemId == R .id .action_info ) {
173+ InfoDialogFragmentActivity bottomSheet = new InfoDialogFragmentActivity ();
174+ bottomSheet .show (getFragmentManager (), "InfoDialog" );
175+ }
176176 });
177177 _applyTheme (AexonTheme .getInstance ());
178178 fab .setElevation ((float )SketchwareUtil .getDip (getApplicationContext (), (int )(4 )));
179- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N_MR1 ) {
180- ShortcutManager shortcutManager = getSystemService (ShortcutManager .class );
181- if (shortcutManager != null ) {
182- Intent shortcutIntent = new Intent (this , TerminalActivity .class );
183- shortcutIntent .setAction (Intent .ACTION_VIEW );
184- ShortcutInfo shortcut = new ShortcutInfo .Builder (this , "shortcut_terminal" ).setShortLabel ("Open Terminal" ).setIcon (Icon .createWithResource (this , R .drawable .ic_terminal_2 )).setIntent (shortcutIntent ).build ();
185- shortcutManager .setDynamicShortcuts (Arrays .asList (shortcut ));
186- }
179+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N_MR1 ) {
180+ ShortcutManager shortcutManager = getSystemService (ShortcutManager .class );
181+ if (shortcutManager != null ) {
182+ Intent shortcutIntent = new Intent (this , TerminalActivity .class );
183+ shortcutIntent .setAction (Intent .ACTION_VIEW );
184+ ShortcutInfo shortcut = new ShortcutInfo .Builder (this , "shortcut_terminal" ).setShortLabel ("Open Terminal" ).setIcon (Icon .createWithResource (this , R .drawable .ic_terminal_2 )).setIntent (shortcutIntent ).build ();
185+ shortcutManager .setDynamicShortcuts (Arrays .asList (shortcut ));
186+ }
187187 }
188188 }
189189
@@ -203,51 +203,51 @@ public void onResume() {
203203 @ Override
204204 public void onStart () {
205205 super .onStart ();
206- AexonTheme .getInstance ().addListener (themeListener );
207- Aexon .addBinderReceivedListener (mainBinderReceived );
206+ AexonTheme .getInstance ().addListener (themeListener );
207+ Aexon .addBinderReceivedListener (mainBinderReceived );
208208 Aexon .addBinderDeadListener (mainBinderDead );
209209 }
210210
211211 @ Override
212212 public void onStop () {
213213 super .onStop ();
214- AexonTheme .getInstance ().removeListener (themeListener );
215- Aexon .removeBinderReceivedListener (mainBinderReceived );
214+ AexonTheme .getInstance ().removeListener (themeListener );
215+ Aexon .removeBinderReceivedListener (mainBinderReceived );
216216 Aexon .removeBinderDeadListener (mainBinderDead );
217217 }
218218 public void _applyTheme (final AexonTheme _theme ) {
219- //nav
220- aexonnavigationbbar1 .setBackgroundColor (_theme .getColorSurfaceContainerHigh ());
221- ColorStateList iconTint = new ColorStateList (new int [][]{new int []{ android .R .attr .state_checked }, new int []{}}, new int []{_theme .getColorPrimary (), _theme .getColorOnSurfaceVariant ()});
222- aexonnavigationbbar1 .setItemIconTint (iconTint );
223- aexonnavigationbbar1 .setThumbColor (_theme .getColorPrimary ());
224- aexonnavigationbbar1 .setRippleColor (_theme .getColorOnPrimaryDark ());
225-
226- //fab
227- fab .setBackgroundColor (_theme .getColorPrimary ());
228- fab .setRippleColor (_theme .getColorOnPrimaryDark ());
229- fab .setIconTint (_theme .getColorOnPrimary ());
230-
231- //toolbar
232- toolbar .setTitleColor (_theme .getColorPrimary ());
233- toolbar .setSubtitleColor (_theme .getColorOnSurfaceVariant ());
234- toolbar .setActionRippleColor (_theme .getColorOnSurface ());
235- toolbar .setActionIconTint (_theme .getColorOnSurface ());
236-
237- //
219+ //nav
220+ aexonnavigationbbar1 .setBackgroundColor (_theme .getColorSurfaceContainerHigh ());
221+ ColorStateList iconTint = new ColorStateList (new int [][]{new int []{ android .R .attr .state_checked }, new int []{}}, new int []{_theme .getColorPrimary (), _theme .getColorOnSurfaceVariant ()});
222+ aexonnavigationbbar1 .setItemIconTint (iconTint );
223+ aexonnavigationbbar1 .setThumbColor (_theme .getColorPrimary ());
224+ aexonnavigationbbar1 .setRippleColor (_theme .getColorOnPrimaryDark ());
225+
226+ //fab
227+ fab .setBackgroundColor (_theme .getColorPrimary ());
228+ fab .setRippleColor (_theme .getColorOnPrimaryDark ());
229+ fab .setIconTint (_theme .getColorOnPrimary ());
230+
231+ //toolbar
232+ toolbar .setTitleColor (_theme .getColorPrimary ());
233+ toolbar .setSubtitleColor (_theme .getColorOnSurfaceVariant ());
234+ toolbar .setActionRippleColor (_theme .getColorOnSurface ());
235+ toolbar .setActionIconTint (_theme .getColorOnSurface ());
236+
237+ //
238238 root_view .setBackgroundColor (_theme .getColorSurface ());
239239 AexonWindowHelper .setWindowStyle (getWindow (), _theme .getColorSurface ());
240240 }
241241
242242
243243 public void _setStatus () {
244- if (Aexon .isBinder ()) {
245- toolbar .setItemVisible (R .id .action_power , true );
246- fab .setVisibility (View .VISIBLE );
247- } else {
248- toolbar .setItemVisible (R .id .action_power , false );
249- fab .setVisibility (View .GONE );
244+ if (Aexon .isBinder ()) {
245+ toolbar .setItemVisible (R .id .action_power , true );
246+ fab .setVisibility (View .VISIBLE );
247+ } else {
248+ toolbar .setItemVisible (R .id .action_power , false );
249+ fab .setVisibility (View .GONE );
250250 }
251251 }
252252
253- }
253+ }
0 commit comments