2929import com .instabug .library .invocation .InstabugInvocationMode ;
3030import com .instabug .library .logging .InstabugLog ;
3131import com .instabug .library .logging .InstabugNetworkLog ;
32+ import com .instabug .library .ui .onboarding .WelcomeMessage ;
3233
3334import org .json .JSONException ;
3435import org .json .JSONObject ;
4041import java .io .OutputStreamWriter ;
4142import java .net .HttpURLConnection ;
4243import java .net .URL ;
44+ import java .util .Set ;
4345
44- public class MainActivity extends BaseActivity
45- implements NavigationView .OnNavigationItemSelectedListener {
46-
47- DrawerLayout drawer ;
48- NavigationView navigationView ;
49- Spinner spinner ;
50- ImageView headerImage ;
51-
52- private static String [] colorNames = {"Red" , "Blue" , "Green" , "Yellow" };
53- private static int [] colors = {Color .RED , Color .BLUE , Color .GREEN , Color .YELLOW };
46+ public class MainActivity extends BaseActivity {
5447
5548 @ Override
5649 protected void onCreate (Bundle savedInstanceState ) {
@@ -62,45 +55,10 @@ protected void onCreate(Bundle savedInstanceState) {
6255
6356 registerGCM ();
6457
65- drawer = findViewById (R .id .drawer_layout );
66- navigationView = findViewById (R .id .nav_view );
67- spinner = findViewById (R .id .spinner );
68- headerImage = navigationView .getHeaderView (0 ).findViewById (R .id .headerImageView );
69- headerImage .setOnClickListener (new View .OnClickListener () {
70- @ Override
71- public void onClick (View v ) {
72- onHeaderImageClicked ();
73- }
74- });
75-
7658 Toolbar toolbar = findViewById (R .id .toolbar );
7759 setSupportActionBar (toolbar );
7860
79- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle (this , drawer , toolbar , R .string .navigation_drawer_open , R .string .navigation_drawer_close );
80- drawer .setDrawerListener (toggle );
81- toggle .syncState ();
82-
83- navigationView .setNavigationItemSelectedListener (this );
84-
85- if (savedInstanceState == null ) {
86- navigationView .setCheckedItem (navigationView .getMenu ().getItem (0 ).getItemId ());
87- }
88-
89- ArrayAdapter <String > dataAdapter = new ArrayAdapter <>(this , android .R .layout .simple_spinner_item , colorNames );
90- dataAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
91- spinner .setAdapter (dataAdapter );
92-
93- spinner .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
94- @ Override
95- public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
96- Instabug .setPrimaryColor (colors [position ]);
97- }
98-
99- @ Override
100- public void onNothingSelected (AdapterView <?> parent ) {
101-
102- }
103- });
61+ doNetworkRequest ();
10462 }
10563
10664 private void registerGCM () {
@@ -109,46 +67,16 @@ private void registerGCM() {
10967 startService (intent );
11068 }
11169
112- public void onFeedbackFABClicked (View view ) {
113- Instabug .invoke ();
114- }
115-
116- public void onShowIntroMessageClicked (View view ) {
117- Instabug .showIntroMessage ();
118- }
119-
120- public void onFeedbackClicked (View view ) {
121- Instabug .invoke (InstabugInvocationMode .NEW_FEEDBACK );
122- }
123-
124- public void onBugReportClicked (View view ) {
125- Instabug .invoke (InstabugInvocationMode .NEW_FEEDBACK );
126- }
127-
128- public void onNewConversationClicked (View view ) {
129- Instabug .invoke (InstabugInvocationMode .NEW_CHAT );
130- }
131-
132- public void onConversationListClicked (View view ) {
133- Instabug .invoke (InstabugInvocationMode .CHATS_LIST );
70+ public void onShowLiveOnboardingMessageClicked (View view ) {
71+ Instabug .showWelcomeMessage (WelcomeMessage .State .LIVE );
13472 }
13573
136- public void onNewMessageCountClicked (View view ) {
137- Toast .makeText (this ,
138- "Number of unread messages: " +
139- String .valueOf (Instabug .getUnreadMessagesCount ()), Toast .LENGTH_SHORT )
140- .show ();
74+ public void onShowBetaOnboardingMessageClicked (View view ) {
75+ Instabug .showWelcomeMessage (WelcomeMessage .State .BETA );
14176 }
14277
143- public void onSendHandledExceptionClicked (View view ) {
144- new AlertDialog .Builder (MainActivity .this )
145- .setMessage ("Do you want to report a handled NullPointerException" )
146- .setPositiveButton ("Why not?" , new DialogInterface .OnClickListener () {
147- @ Override
148- public void onClick (DialogInterface dialog , int which ) {
149- Instabug .reportException (new NullPointerException (), "Handled Exception" );
150- }
151- }).show ();
78+ public void onShowInstabugClicked (View view ) {
79+ Instabug .invoke ();
15280 }
15381
15482 public void onCrashTheAppClicked (View view ) {
@@ -165,71 +93,29 @@ public void onClick(DialogInterface dialog, int which) {
16593 .show ();
16694 }
16795
168- public void onDoNetworkRequestClicked (View view ) {
169- new FetchMoviesData ().execute ();
170- }
171-
172- public void onHeaderImageClicked () {
173- Intent browserIntent = new Intent (Intent .ACTION_VIEW , Uri .parse ("http://www.instabug.com" ));
174- startActivity (browserIntent );
96+ public void showNPSSurvey (View view ) {
97+ Instabug .showSurvey ("ulUaFocMCejDr3Ldd8VBaA" );
17598 }
17699
177- @ Override
178- public void onBackPressed () {
179- if (drawer .isDrawerOpen (GravityCompat .START )) {
180- drawer .closeDrawer (GravityCompat .START );
181- } else {
182- super .onBackPressed ();
183- }
100+ public void showMultipleQuestionSurvey (View view ) {
101+ Instabug .showSurvey ("AGI5OH47k3eEAIKj-yKDWA" );
184102 }
185103
186- @ Override
187- public boolean onCreateOptionsMenu (Menu menu ) {
188- return true ;
104+ public void showFeatureRequests (View view ) {
105+ Instabug .showFeatureRequests ();
189106 }
190107
191- @ Override
192- public boolean onOptionsItemSelected (MenuItem item ) {
193- return super .onOptionsItemSelected (item );
108+ public void onShowSettingsClicked (View view ) {
109+ startActivity (new Intent (this , SettingsActivity .class ));
194110 }
195111
196- @ Override
197- public boolean onNavigationItemSelected (MenuItem item ) {
198- int id = item .getItemId ();
199- if (id == R .id .nav_home ) {
200- AlertDialog alertDialog = new AlertDialog .Builder (this )
201- .setMessage ("Do you want to get a NullPointerException, because that's how " +
202- "you get a NullPointerException :D" )
203- .setPositiveButton ("Why not?" , new DialogInterface .OnClickListener () {
204- @ Override
205- public void onClick (DialogInterface dialog , int which ) {
206- throw new NullPointerException ("Test issue in Instabug Sample app" );
207- }
208- }).show ();
209- Instabug .setDialog (alertDialog );
210- } else if (id == R .id .nav_maps ) {
211- startActivity (new Intent (this , GoogleMapsActivity .class ));
212- } else if (id == R .id .nav_openGl ) {
213- startActivity (new Intent (this , OpenGLActivity .class ));
214- } else if (id == R .id .nav_share ) {
215- startActivity (Intent .createChooser (getShareIntent (), getResources ().getString (R .string .share_to_friends )));
216- } else if (id == R .id .nav_about ) {
217- Instabug .showIntroMessage ();
218- // TODO click about to show dialog to test screenshot with dialogs
219- Toast .makeText (this , "Coming soon" , Toast .LENGTH_SHORT ).show ();
220- }
221-
222- DrawerLayout drawer = findViewById (R .id .drawer_layout );
223- drawer .closeDrawer (GravityCompat .START );
224- return true ;
112+ public void doNetworkRequest () {
113+ new FetchMoviesData ().execute ();
225114 }
226115
227- public Intent getShareIntent () {
228- String sharedText = "Check out this awesome sample app by @instabug\n \n https://github.com/Instabug/android-sample" ;
229- Intent shareIntent = new Intent (Intent .ACTION_SEND );
230- shareIntent .setType ("text/plain" );
231- shareIntent .putExtra (Intent .EXTRA_TEXT , sharedText );
232- return shareIntent ;
116+ public void onHeaderImageClicked () {
117+ Intent browserIntent = new Intent (Intent .ACTION_VIEW , Uri .parse ("http://www.instabug.com" ));
118+ startActivity (browserIntent );
233119 }
234120
235121 private class FetchMoviesData extends AsyncTask <Void , Void , String > {
@@ -326,4 +212,5 @@ protected void onPostExecute(String s) {
326212 Log .d ("Response" , s + "" );
327213 }
328214 }
215+
329216}
0 commit comments