@@ -369,7 +369,9 @@ protected void onResume() {
369369 boolean wifiJustOn = ensureWifiOnWhenForeground ();
370370
371371 applyIntentState (getIntent ());
372- if (USE_GENERIC_IMAGE ) {
372+ if (ApiPrefs .isGiftModeEnabled (this )) {
373+ showGiftModeScreen ();
374+ } else if (USE_GENERIC_IMAGE ) {
373375 showGenericImageAndSleep ();
374376 } else if (ensureCredentials ()) {
375377 if (!fetchInProgress ) {
@@ -858,6 +860,155 @@ private void setBootStatus(String status) {
858860 }
859861 }
860862
863+ private void showGiftModeScreen () {
864+ hideBootScreen ();
865+ if (bootLayout != null ) bootLayout .setVisibility (View .GONE );
866+ if (logView != null ) logView .setVisibility (View .GONE );
867+ if (imageRotateLayout != null ) imageRotateLayout .setVisibility (View .GONE );
868+ if (contentScroll != null ) contentScroll .setVisibility (View .VISIBLE );
869+
870+ String code = ApiPrefs .getFriendlyDeviceCode (this );
871+ String fromName = ApiPrefs .getGiftFromName (this );
872+ String toName = ApiPrefs .getGiftToName (this );
873+
874+ // Build a left-aligned layout
875+ ScrollView .LayoutParams scrollParams = new ScrollView .LayoutParams (
876+ ViewGroup .LayoutParams .FILL_PARENT , ViewGroup .LayoutParams .FILL_PARENT );
877+
878+ LinearLayout giftLayout = new LinearLayout (this );
879+ giftLayout .setOrientation (LinearLayout .VERTICAL );
880+ giftLayout .setGravity (Gravity .CENTER_VERTICAL );
881+ giftLayout .setPadding (50 , 40 , 50 , 40 );
882+ giftLayout .setLayoutParams (scrollParams );
883+
884+ // Logo + Title row
885+ LinearLayout headerRow = new LinearLayout (this );
886+ headerRow .setOrientation (LinearLayout .HORIZONTAL );
887+ headerRow .setGravity (Gravity .CENTER_VERTICAL );
888+
889+ ImageView logo = new ImageView (this );
890+ logo .setImageResource (R .drawable .ic_launcher );
891+ headerRow .addView (logo );
892+
893+ TextView title = new TextView (this );
894+ title .setText ("TRMNL" );
895+ title .setTextSize (22 );
896+ title .setTextColor (0xFF000000 );
897+ title .setPadding (12 , 0 , 0 , 0 );
898+ headerRow .addView (title );
899+
900+ giftLayout .addView (headerRow );
901+
902+ // Greeting
903+ StringBuilder greeting = new StringBuilder ();
904+ if (toName != null && toName .length () > 0 ) {
905+ greeting .append ("Hey " ).append (toName ).append ("! " );
906+ }
907+ if (fromName != null && fromName .length () > 0 ) {
908+ greeting .append (fromName ).append (" gifted you this display!" );
909+ } else {
910+ greeting .append ("This display was gifted to you!" );
911+ }
912+
913+ TextView greetingView = new TextView (this );
914+ greetingView .setText (greeting .toString ());
915+ greetingView .setTextSize (14 );
916+ greetingView .setTextColor (0xFF000000 );
917+ LinearLayout .LayoutParams greetParams = new LinearLayout .LayoutParams (
918+ ViewGroup .LayoutParams .FILL_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT );
919+ greetParams .topMargin = 16 ;
920+ giftLayout .addView (greetingView , greetParams );
921+
922+ // Description
923+ TextView desc = new TextView (this );
924+ desc .setText ("Use it for weather, calendars, news, or hundreds of other plugins from trmnl.com" );
925+ desc .setTextSize (12 );
926+ desc .setTextColor (0xFF666666 );
927+ LinearLayout .LayoutParams descParams = new LinearLayout .LayoutParams (
928+ ViewGroup .LayoutParams .FILL_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT );
929+ descParams .topMargin = 6 ;
930+ giftLayout .addView (desc , descParams );
931+
932+ // Divider line
933+ View divider = new View (this );
934+ divider .setBackgroundColor (0xFFCCCCCC );
935+ LinearLayout .LayoutParams divParams = new LinearLayout .LayoutParams (
936+ ViewGroup .LayoutParams .FILL_PARENT , 1 );
937+ divParams .topMargin = 20 ;
938+ giftLayout .addView (divider , divParams );
939+
940+ // Setup steps title
941+ TextView stepsTitle = new TextView (this );
942+ stepsTitle .setText ("SETUP" );
943+ stepsTitle .setTextSize (11 );
944+ stepsTitle .setTextColor (0xFF888888 );
945+ LinearLayout .LayoutParams stepsTitleParams = new LinearLayout .LayoutParams (
946+ ViewGroup .LayoutParams .FILL_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT );
947+ stepsTitleParams .topMargin = 16 ;
948+ giftLayout .addView (stepsTitle , stepsTitleParams );
949+
950+ // Step 1
951+ giftLayout .addView (createStepRow ("1" , "Sign up at trmnl.com/signup" ), createStepParams (12 ));
952+
953+ // Step 2
954+ String step2Text = (code != null && code .length () > 0 )
955+ ? "Add device with code: " + code
956+ : "Add device (get code from gifter)" ;
957+ giftLayout .addView (createStepRow ("2" , step2Text ), createStepParams (8 ));
958+
959+ // Step 3
960+ giftLayout .addView (createStepRow ("3" , "Tap screen → Settings → Edit" ), createStepParams (8 ));
961+
962+ // Replace contentView's parent contents
963+ if (contentScroll != null ) {
964+ contentScroll .removeAllViews ();
965+ contentScroll .setFillViewport (true );
966+ contentScroll .addView (giftLayout );
967+ }
968+
969+ // Write gift mode screen to screensaver so NOOK shows it when asleep
970+ writeGiftModeScreensaver (code , fromName , toName );
971+ }
972+
973+ private LinearLayout createStepRow (String number , String text ) {
974+ LinearLayout row = new LinearLayout (this );
975+ row .setOrientation (LinearLayout .HORIZONTAL );
976+
977+ TextView numView = new TextView (this );
978+ numView .setText (number );
979+ numView .setTextSize (16 );
980+ numView .setTextColor (0xFF000000 );
981+ numView .setGravity (Gravity .CENTER );
982+ numView .setBackgroundColor (0xFFEEEEEE );
983+ numView .setPadding (12 , 4 , 12 , 4 );
984+ row .addView (numView );
985+
986+ TextView textView = new TextView (this );
987+ textView .setText (text );
988+ textView .setTextSize (12 );
989+ textView .setTextColor (0xFF000000 );
990+ textView .setPadding (12 , 0 , 0 , 0 );
991+ textView .setGravity (Gravity .CENTER_VERTICAL );
992+ row .addView (textView );
993+
994+ return row ;
995+ }
996+
997+ private LinearLayout .LayoutParams createStepParams (int topMargin ) {
998+ LinearLayout .LayoutParams params = new LinearLayout .LayoutParams (
999+ ViewGroup .LayoutParams .FILL_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT );
1000+ params .topMargin = topMargin ;
1001+ return params ;
1002+ }
1003+
1004+ private void writeGiftModeScreensaver (String code , String fromName , String toName ) {
1005+ // Use gift screensaver image (already in native portrait orientation 600x800)
1006+ Bitmap bitmap = BitmapFactory .decodeResource (getResources (), R .drawable .gift_screensaver );
1007+ if (bitmap != null ) {
1008+ writeScreenshotToScreensaver (bitmap );
1009+ }
1010+ }
1011+
8611012 private void toggleMenu () {
8621013 if (menuVisible ) {
8631014 hideMenu ();
@@ -1011,6 +1162,10 @@ public void run() {
10111162 }
10121163
10131164 private boolean ensureCredentials () {
1165+ // Don't redirect to settings if gift mode is enabled
1166+ if (ApiPrefs .isGiftModeEnabled (this )) {
1167+ return false ;
1168+ }
10141169 if (!ApiPrefs .hasCredentials (this )) {
10151170 startActivity (new Intent (this , SettingsActivity .class ));
10161171 return false ;
0 commit comments