2
2
3
3
import android .annotation .SuppressLint ;
4
4
import android .content .Intent ;
5
- import android .content .IntentSender ;
6
5
import android .net .Uri ;
7
6
import android .os .Bundle ;
8
7
import android .os .Handler ;
9
8
import android .os .Looper ;
10
9
import android .view .Menu ;
11
10
import android .view .MenuItem ;
12
- import android .view .View ;
13
11
14
12
import androidx .annotation .NonNull ;
15
13
import androidx .appcompat .app .ActionBarDrawerToggle ;
21
19
import androidx .recyclerview .widget .RecyclerView ;
22
20
23
21
import com .google .android .material .navigation .NavigationView ;
24
- import com .google .android .play .core .appupdate .AppUpdateInfo ;
25
- import com .google .android .play .core .appupdate .AppUpdateManager ;
26
- import com .google .android .play .core .appupdate .AppUpdateManagerFactory ;
27
- import com .google .android .play .core .install .model .AppUpdateType ;
28
- import com .google .android .play .core .install .model .UpdateAvailability ;
29
- import com .google .android .play .core .tasks .Task ;
30
22
31
23
import java .util .ArrayList ;
32
24
import java .util .Objects ;
@@ -38,18 +30,12 @@ public class SelectionActivity extends AppCompatActivity {
38
30
39
31
boolean doubleBackToExitPressedOnce = false ;
40
32
41
- //for checking the app version, if the version is old then it will show the pop-up update message to the user.
42
- private AppUpdateManager appUpdateManager ;
43
- private final int PATTERN_PROGRAMS_IN_JAVA_APP_UPDATE_REQ_CODE = 1008 ;
44
-
33
+ @ SuppressLint ("NonConstantResourceId" )
45
34
@ Override
46
35
protected void onCreate (Bundle savedInstanceState ) {
47
36
super .onCreate (savedInstanceState );
48
37
setContentView (R .layout .activity_selection );
49
38
50
- //for checking update.
51
- PopUpAppUpdate ();
52
-
53
39
//FindViews
54
40
RecyclerView selection_recyclerView = findViewById (R .id .selection_recycler );
55
41
drawerLayout = findViewById (R .id .drawer_layout );
@@ -68,66 +54,57 @@ protected void onCreate(Bundle savedInstanceState) {
68
54
Objects .requireNonNull (getSupportActionBar ()).setDisplayHomeAsUpEnabled (true );
69
55
70
56
//set toolbar nav btn click
71
- toolbar .setNavigationOnClickListener (new View .OnClickListener () {
72
- @ Override
73
- public void onClick (View v ) {
74
- drawerLayout .openDrawer (GravityCompat .START );
75
- }
76
- });
57
+ toolbar .setNavigationOnClickListener (v -> drawerLayout .openDrawer (GravityCompat .START ));
77
58
78
59
//default set checked
79
60
nav .setCheckedItem (R .id .home );
80
61
//set navigation
81
- nav .setNavigationItemSelectedListener (new NavigationView .OnNavigationItemSelectedListener () {
82
- @ SuppressLint ("NonConstantResourceId" )
83
- @ Override
84
- public boolean onNavigationItemSelected (@ NonNull MenuItem item ) {
85
- Intent intent ;
86
- Uri uri ;
87
- switch (item .getItemId ()) {
88
- case R .id .pattern1 :
89
- intent = new Intent (SelectionActivity .this , QuestionsActivity .class );
90
- intent .putExtra ("heading" , "Star Pattern Programs" )
91
- .putExtra ("value" , 1 );
92
- startActivity (intent );
93
- break ;
94
- case R .id .pattern2 :
95
- intent = new Intent (SelectionActivity .this , QuestionsActivity .class );
96
- intent .putExtra ("heading" , "Number Pattern Programs" )
97
- .putExtra ("value" , 2 );
98
- startActivity (intent );
99
- break ;
100
- case R .id .pattern3 :
101
- intent = new Intent (SelectionActivity .this , QuestionsActivity .class );
102
- intent .putExtra ("heading" , "Alphabet Pattern Programs" )
103
- .putExtra ("value" , 3 );
104
- startActivity (intent );
105
- break ;
106
- case R .id .share :
107
- intent = new Intent (Intent .ACTION_SEND );
108
- intent .setType ("text/plain" );
109
- String shareBody = "I'm using " + getString (R .string .app_name ) + " App for creating amazing java patterns, try this App.\n Download link - https://play.google.com/store/apps/details?id=" + getPackageName ();
110
- String shareSubject = String .valueOf (R .string .app_name );
111
- intent .putExtra (Intent .EXTRA_TEXT , shareBody );
112
- intent .putExtra (Intent .EXTRA_SUBJECT , shareSubject );
113
- startActivity (Intent .createChooser (intent , "Share using" ));
114
- break ;
115
- case R .id .rate_us :
116
- uri = Uri .parse ("http://play.google.com/store/apps/details?id=" + getPackageName ());
117
- intent = new Intent (Intent .ACTION_VIEW , uri );
118
- intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
119
- startActivity (intent );
120
- break ;
121
- case R .id .more_apps :
122
- uri = Uri .parse ("https://play.google.com/store/search?q=pub%3AAniket%20Jain&c=apps" );
123
- intent = new Intent (Intent .ACTION_VIEW , uri );
124
- intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
125
- startActivity (intent );
126
- break ;
127
- }
128
- drawerLayout .closeDrawer (GravityCompat .START );
129
- return true ;
62
+ nav .setNavigationItemSelectedListener (item -> {
63
+ Intent intent ;
64
+ Uri uri ;
65
+ switch (item .getItemId ()) {
66
+ case R .id .pattern1 :
67
+ intent = new Intent (SelectionActivity .this , QuestionsActivity .class );
68
+ intent .putExtra ("heading" , "Star Pattern Programs" )
69
+ .putExtra ("value" , 1 );
70
+ startActivity (intent );
71
+ break ;
72
+ case R .id .pattern2 :
73
+ intent = new Intent (SelectionActivity .this , QuestionsActivity .class );
74
+ intent .putExtra ("heading" , "Number Pattern Programs" )
75
+ .putExtra ("value" , 2 );
76
+ startActivity (intent );
77
+ break ;
78
+ case R .id .pattern3 :
79
+ intent = new Intent (SelectionActivity .this , QuestionsActivity .class );
80
+ intent .putExtra ("heading" , "Alphabet Pattern Programs" )
81
+ .putExtra ("value" , 3 );
82
+ startActivity (intent );
83
+ break ;
84
+ case R .id .share :
85
+ intent = new Intent (Intent .ACTION_SEND );
86
+ intent .setType ("text/plain" );
87
+ String shareBody = "I'm using " + getString (R .string .app_name ) + " App for creating amazing java patterns, try this App.\n Download link - https://play.google.com/store/apps/details?id=" + getPackageName ();
88
+ String shareSubject = String .valueOf (R .string .app_name );
89
+ intent .putExtra (Intent .EXTRA_TEXT , shareBody );
90
+ intent .putExtra (Intent .EXTRA_SUBJECT , shareSubject );
91
+ startActivity (Intent .createChooser (intent , "Share using" ));
92
+ break ;
93
+ case R .id .rate_us :
94
+ uri = Uri .parse ("http://play.google.com/store/apps/details?id=" + getPackageName ());
95
+ intent = new Intent (Intent .ACTION_VIEW , uri );
96
+ intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
97
+ startActivity (intent );
98
+ break ;
99
+ case R .id .more_apps :
100
+ uri = Uri .parse ("https://play.google.com/store/search?q=pub%3AAniket%20Jain&c=apps" );
101
+ intent = new Intent (Intent .ACTION_VIEW , uri );
102
+ intent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
103
+ startActivity (intent );
104
+ break ;
130
105
}
106
+ drawerLayout .closeDrawer (GravityCompat .START );
107
+ return true ;
131
108
});
132
109
133
110
//Adding Selection Array Elements
@@ -183,26 +160,4 @@ public void onBackPressed() {
183
160
doubleBackToExitPressedOnce = true ;
184
161
new Handler (Looper .getMainLooper ()).postDelayed (() -> doubleBackToExitPressedOnce = false , 2000 );
185
162
}
186
-
187
- private void PopUpAppUpdate () {
188
- appUpdateManager = AppUpdateManagerFactory .create (this );
189
-
190
- // Returns an intent object that you use to check for an update.
191
- Task <AppUpdateInfo > appUpdateInfoTask = appUpdateManager .getAppUpdateInfo ();
192
-
193
- // Checks that the platform will allow the specified type of update.
194
- appUpdateInfoTask .addOnSuccessListener (appUpdateInfo -> {
195
- if (appUpdateInfo .updateAvailability () == UpdateAvailability .UPDATE_AVAILABLE
196
- // This example applies an immediate update. To apply a flexible update
197
- // instead, pass in AppUpdateType.IMMEDIATE
198
- && appUpdateInfo .isUpdateTypeAllowed (AppUpdateType .IMMEDIATE )) {
199
- // Request the update.
200
- try {
201
- appUpdateManager .startUpdateFlowForResult (appUpdateInfo , AppUpdateType .IMMEDIATE , SelectionActivity .this , PATTERN_PROGRAMS_IN_JAVA_APP_UPDATE_REQ_CODE );
202
- } catch (IntentSender .SendIntentException exception ) {
203
- exception .printStackTrace ();
204
- }
205
- }
206
- });
207
- }
208
163
}
0 commit comments