5.5. MainActivity Class

Class MainActivity (Figs. 5.18Fig. 5.23) hosts the app’s QuizFragment when the app is running in portrait orientation, and hosts both the SettingsFragment and QuizFragment when the app is running on a tablet in landscape orientation.


 1   // MainActivity.java
 2   // Hosts the QuizFragment on a phone and both the
 3   // QuizFragment and SettingsFragment on a tablet
 4   package com.deitel.flagquiz;
 5
 6   import java.util.Set;
 7
 8   import android.app.Activity;
 9   import android.content.Intent;
10   import android.content.SharedPreferences;
11   import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
12   import android.content.pm.ActivityInfo;                                   
13   import android.content.res.Configuration;                                 
14   import android.graphics.Point;                                            
15   import android.os.Bundle;
16   import android.preference.PreferenceManager;
17   import android.view.Display;                
18   import android.view.Menu;                   
19   import android.view.MenuItem;               
20   import android.view.WindowManager;          
21   import android.widget.Toast;                
22
23   public class MainActivity extends Activity
24   {
25      // keys for reading data from SharedPreferences
26      public static final String CHOICES = "pref_numberOfChoices";
27      public static final String REGIONS = "pref_regionsToInclude";
28
29      private boolean phoneDevice = true; // used to force portrait mode
30      private boolean preferencesChanged = true; // did preferences change?
31


Fig. 5.18 | MainActivity package statement, import statements and fields.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset