📜 ⬆️ ⬇️

Application development for the e-book Barnes & Noble Nook

image

Introduction


Recently, we ( mynook.ru , first post , second post ) opened our profile on reformal.ru , where we were asked how to write applications under Nook, and also asked to post the FBReader source.
All the source code you can now find on Google Code , but about the first one I will try to tell now.

Many thanks to the great designer nilov for helping me put this post in pictures, for how well he redesigned the icons and for directly translating Nook.
')

On whom it is calculated


I assume that the person who will read further knows the basics of development for android (to be more precise, under 1.5) and accordingly I ask you not to ask questions about the basics of android and even more so not to discuss how to buy Nook in Russia / Ukraine / etc ...

Features of a piece of iron


You can find the most accurate information on the corresponding page on nookdevs.org
The key point for us is the screen. He is known to be divided into two parts in Nuk - color sensory and b / w E-Ink. And in width they do not match :



From the point of view of the android itself, this is one big screen, 600x944 px in size, and the image for the LCD is not stretched, but cropped. Here is how this mess looks from the point of view of the system:



Screen layout


Everything is very simple here. You just need to use the following template, which creates two containers for E-Ink and for the LCD screen:

<? xml version ="1.0" encoding ="utf-8" ? > <br> < LinearLayout <br> xmlns:android ="http://schemas.android.com/apk/res/android" <br> android:layout_width ="fill_parent" <br> android:layout_height ="fill_parent" <br> android:orientation ="vertical" > <br><br> < FrameLayout <br> android:id ="@+id/eink" <br> android:layout_width ="600.0px" <br> android:layout_height ="760.0px" <br> android:background ="@android:color/white" /> <br><br> < FrameLayout <br> android:id ="@+id/lcd" <br> android:layout_width ="480.0px" <br> android:layout_height ="144.0px" <br> android:background ="@android:color/black" /> <br><br> </ LinearLayout > <br><br> * This source code was highlighted with Source Code Highlighter .


However, the borders of the E-Ink screen are very close to the edge and because of this, the content that is close to the borders is very inconvenient to read and looks bad in general, and therefore I would advise you to use the option immediately with the necessary indents from the edges ( there is no need to indent from above, because there is not a border of the screen, but a taskbar and everything looks fine):

<? xml version ="1.0" encoding ="utf-8" ? > <br> < LinearLayout <br> xmlns:android ="http://schemas.android.com/apk/res/android" <br> android:layout_width ="fill_parent" <br> android:layout_height ="fill_parent" <br> android:orientation ="vertical" > <br><br> < FrameLayout <br> android:id ="@+id/eink" <br> android:layout_width ="584.0px" <br> android:layout_height ="752.0px" <br> android:layout_marginLeft ="8px" <br> android:layout_marginRight ="8px" <br> android:layout_marginBottom ="8px" <br> android:background ="@android:color/white" /> <br><br> < FrameLayout <br> android:id ="@+id/lcd" <br> android:layout_width ="480.0px" <br> android:layout_height ="144.0px" <br> android:background ="@android:color/black" /> <br><br> </ LinearLayout > <br><br> * This source code was highlighted with Source Code Highlighter .


Next, we need to disable TitleBar in our application (a narrow strip that plays the role of a screen title on a regular android). This is done through the application / activity argument in AndroidManifest.xml: android: theme = "@ android: style / Theme.Light.NoTitleBar"

Of course, you can also make a completely full-screen mode, so that the taskbar would disappear, but the screen is so large and I see no point in doing this, and you do not advise doing so.

Additional API


I have added some additional API in NookActivity and another class that you can get by downloading a skeleton application.

Setting the title in the taskbar

This is done through the intent by the following code:
private final static String NOOK_UPDATE_TITLE = "com.bravo.intent.UPDATE_TITLE" ;<br><br> protected void nookUpdateTitle( String title) {<br> try {<br> Intent intent = new Intent(NOOK_UPDATE_TITLE);<br> String key = "apptitle" ;<br> intent.putExtra(key, title);<br> sendBroadcast(intent);<br> } catch (Exception ex) {<br> ex.printStackTrace();<br> }<br> } <br><br> * This source code was highlighted with Source Code Highlighter .


Hardkey buttons and gestures

The page turning buttons have the following codes:
public static final int NOOK_KEY_PREV_LEFT = 96;<br> public static final int NOOK_KEY_PREV_RIGHT = 98;<br><br> public static final int NOOK_KEY_NEXT_LEFT = 95;<br> public static final int NOOK_KEY_NEXT_RIGHT = 97; <br><br> * This source code was highlighted with Source Code Highlighter .

Touchscreen gestures have the following codes:
public static final int NOOK_KEY_SHIFT_UP = 101;<br> public static final int NOOK_KEY_SHIFT_DOWN = 100; <br><br> * This source code was highlighted with Source Code Highlighter .


Control the appearance of the screensaver


As it turned out, you need to manually do so that the screen saver itself does not turn on.
To do this, I wrote my own classic, which controls the appearance of splash screens, and this code requires the permission "android.permission.WAKE_LOCK":

public class NookScreensaverLock {<br> Context context;<br> long timeOut = 10 * 60000;<br> PowerManager.WakeLock lock ;<br><br> public NookScreensaverLock(Context context) {<br> this .context = context;<br><br><br> PowerManager power = (PowerManager) context.getSystemService(Activity.POWER_SERVICE);<br> lock = power.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "nookactivity" + hashCode());<br> lock .setReferenceCounted( false );<br><br> readSystemValues();<br> }<br><br> private void readSystemValues() {<br><br> try {<br> String [] values = {<br> "value" <br> };<br> String name = null ;<br> String [] fields = {<br> "bnScreensaverDelay" <br> };<br> for ( int i = 0; i < fields.length; i++) {<br> if (name == null ) {<br> name = "name=?" ;<br> } else {<br> name += " or name=?" ;<br> }<br> }<br> Cursor c = context.getContentResolver().query( Uri .parse( "content://settings/system" ), values, name, fields, "name" );<br> if (c != null ) {<br> c.moveToFirst();<br> long lvalue = c.getLong(0);<br> if (lvalue > 0) {<br> timeOut = lvalue;<br> }<br><br> }<br> c.close();<br> c.deactivate();<br><br> } catch (Exception ex) {<br> ex.printStackTrace();<br> }<br> }<br><br> public void release() {<br> if ( lock .isHeld())<br> lock .release();<br> }<br><br> public void acquire( long time) {<br> lock .acquire(time);<br> }<br><br> public void acquire() {<br> lock .acquire(timeOut);<br> }<br>} <br><br> * This source code was highlighted with Source Code Highlighter .


readSystemValues ​​() reads the system settings and gets the timeout value of the screensaver that the user entered in the settings.

Basic Activity for Nuka


This is what you need to inherit all your activations for more convenient work in Nuk, as well as here you can understand how NookScreensaverLock is used.
public abstract class NookActivity extends Activity {<br><br> public static final int NOOK_KEY_PREV_LEFT = 96;<br> public static final int NOOK_KEY_PREV_RIGHT = 98;<br><br> public static final int NOOK_KEY_NEXT_LEFT = 95;<br> public static final int NOOK_KEY_NEXT_RIGHT = 97;<br><br> public static final int NOOK_KEY_SHIFT_UP = 101;<br> public static final int NOOK_KEY_SHIFT_DOWN = 100;<br><br> private NookScreensaverLock lock ;<br><br> private final static String NOOK_UPDATE_TITLE = "com.bravo.intent.UPDATE_TITLE" ;<br><br> protected void nookUpdateTitle( String title) {<br> try {<br> Intent intent = new Intent(NOOK_UPDATE_TITLE);<br> String key = "apptitle" ;<br> intent.putExtra(key, title);<br> sendBroadcast(intent);<br> } catch (Exception ex) {<br> ex.printStackTrace();<br> }<br> }<br><br> @Override<br> protected void onCreate(Bundle savedInstanceState) {<br> super.onCreate(savedInstanceState);<br> lock = new NookScreensaverLock( this );<br> lock .acquire();<br> }<br><br> @Override<br> public void onUserInteraction() {<br> super.onUserInteraction();<br> lock .acquire();<br> }<br><br> @Override<br> protected void onResume() {<br> super.onResume();<br> lock .acquire();<br> }<br><br> @Override<br> protected void onPause() {<br> super.onPause();<br> lock .release();<br> }<br>} <br><br> * This source code was highlighted with Source Code Highlighter .


Design features



Ruth


First of all, you need a root. I can advise my and nilov 'and the firmware, which can always be found on our blog mynook.ru, it has, for example, an application manager, which is sometimes convenient when developing.

Instructions: mynook.ru , nookdevs.com

Adb and debag


Total


Actually, I tried to state all the key features of the development under Nuk, as well as write simple classes that would simplify the development.
Just in case I will duplicate the link to the skeleton application .

Source: https://habr.com/ru/post/98021/


All Articles