Pro Java ME Apps pot

355 283 0
Pro Java ME Apps pot

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info i Pro Java ME Apps ■ ■ ■ Ovidiu Iliescu www.it-ebooks.info Pro Java ME Apps Copyright © 2011 by Ovidiu Iliescu All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302- 3327-5 ISBN-13 (electronic): 978-1-4302- 3328-2 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Steve Anglin Development Editor: Douglas Pundick Technical Reviewer: Carol Hamer Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Adam Heath Copy Editor: Mary Ann Fugate, Sharon Wilkey Compositor: MacPS, LLC Indexer: SPi Global Artist: SPi Gobal Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. www.it-ebooks.info Mom, Dad, Grandpa – Thank you for everything. I love you. www.it-ebooks.info iv Contents at a Glance Contents v About the Author xi About the Technical Reviewer xii Acknowledgments xiii Introduction xiv ■ Chapter 1: Getting Started 1 ■ Chapter 2: A Java ME Framework 25 ■ Chapter 3: Defining Our Data 51 ■ Chapter 4: The Networking Module 63 ■ Chapter 5: The Persistence Module 93 ■ Chapter 6: The UI Module 115 ■ Chapter 7: The Localization Module 155 ■ Chapter 8: Putting It All Together 169 ■ Chapter 9: Device Fragmentation 193 ■ Chapter 10: Optimizing Your Code 223 ■ Chapter 11: Adding Fine Touches and User Interaction Improvements 251 ■ Chapter 12: Java ME Application Testing 271 ■ Chapter 13: Advanced Java ME Graphics 283 ■ Chapter 14: The Proper Java ME Mindset 305 ■ Chapter 15: Java ME and the Future 325 ■ Chapter 16: Final Words 337 Index 341 www.it-ebooks.info v Contents Contents at a Glance iv About the Author xi About the Technical Reviewer xii Acknowledgments xiii Introduction xiv ■ Chapter 1: Getting Started 1 Java ME, Smartphones, and Feature Phones 1  Java ME’s Advantages 1  Java ME’s Disadvantages 2  The Bottom Line 3  Creating a Java ME Application 3  The Idea for the Application 4  Goals, Features, Revenue Sources, and Target Devices 4  Identifying the Target Devices 6  Identifying Java ME Technical Limitations 7  Regular Java ME Applications vs. Pro Java ME Applications 13  Writing Flexible Java ME Applications 15  Coding Defensively 16  Avoiding Wrong Assumptions 18  Learning How to Handle Complexity 18  Trade-Offs Are Your Friends—Use Them Wisely 20  Aim for a Loose and Decentralized Architecture 22  Never Do On-Device What You Can Do Off-Device 23  Summary 24  ■ Chapter 2: A Java ME Framework 25 The Importance of Using a Framework 25  Why a Custom Framework for Each Application? 26  Defining the Framework’s Structure 27  Basic Object Types 28  Events 29  Event Listeners 31  www.it-ebooks.info ■ CONTENTS vi Providers 31  Consumers 32  Managers 33  Models and Controllers 33  Views 34  Common Objects 35  The EventController Class 35  The EventControllerManager 37  Core Objects and Classes 39  The Application Class 39  The EventManagerThreads Class 40  The Bootstrap Class 44  A Simple Test Application 45  Summary 49  ■ Chapter 3: Defining Our Data 51 Why Implement the Model Interface? 51  Making Data Types Immutable 52  Defining the Tweet Data Type 53  Defining the TwitterUser Data Type 54  Defining the TwitterServer Entity 55  Defining the UserCredentials Data Type 56  Defining the TweetFilter Data Type 58  Defining the Timeline Entity 58  Choosing Intelligent Representations for Your Data 59  Summary 61  ■ Chapter 4: The Networking Module 63 Setting Up and Configuring the Library 63  Working with High-Level Objects 66  Using Your Own Data Types 66  Writing Our TwitterServer Implementation 67  Defining the General Structure 67  Initializing a ServerImplementation Instance 68  Providing Login Support 69  Posting Tweets 73  Retrieving Tweets 74  The getMyProfile() and getProfileFor() Methods 85  Best Practices for Java ME Networking 86  Do Not Reinvent the Wheel 86  Mobile Internet Is Special 87  Remember the Limitations of the Devices You’re Targeting 88  Support Network Throttling and Sleep Mode 88  Transmitting Your Data Efficiently 89  Keeping the Networking Code Light 90  Be Independent 91  Summary 91  www.it-ebooks.info ■ CONTENTS vii ■ Chapter 5: The Persistence Module 93 Understanding Java ME Persistence Options 93  Designing the Persistence Module 95  The Persistence Providers 96  RecordReaders and RecordWriters 97  Serializers and Deserializers 99  Persistence Helpers 100  Implementing the Core Architecture 100  Implementing Serializers and Deserializers 101  Implementing RecordReaders and RecordWriters 103  Implementing the PersistenceProvider 104  Testing the Code 106  Writing Persistence Helpers 107  Using the Module in a Real-Life Scenario 112  Taking the Module Further 113  Summary 113  ■ Chapter 6: The UI Module 115 Why Create a Custom UI Module? 116  Understanding the Basics of Creating a UI Module 116  Widgets 117  Containers 118  Clipping Rectangles 120  Views 124  Themes 124  Handling User Interaction 126  Implementing Basic Widget Support 127  The BaseWidget Class 127  BaseContainerWidget and BaseContainerManager 130  Implementing Concrete Widgets 135  The VerticalContainer and HorizontalContainer Classes 135  The SimpleTextButton Class 139  The StringItem Class 141  InputStringItem 143  GameCanvasView 146  Testing the UI Module 147  Implementing UIs on Touch-Only Devices 149  Final Words About the UI Module 151  Summary 153  ■ Chapter 7: The Localization Module 155 Understanding the Features of a Good Localization Module 155  Understanding Native Java ME Localization 156  Adding Custom Localization Support to a Java ME Application 157  Processing Localization Files 159  Loading Localization Data on the Device 161  Testing the Localization Module 164  Implementing Advanced Localization Features 165  Summary 168  www.it-ebooks.info ■ CONTENTS viii ■ Chapter 8: Putting It All Together 169 Jump-Starting the Application 169  Implementing the FlowController 170  Implementing the TweetsController 173  Implementing the WelcomeScreenController and the WelcomeForm 175  Implementing the MainForm and MainScreenController 179  Implementing the SettingsScreenController and the SettingsForm 184  Implementing the EVT Class 188  Improving the Application 189  Improving Error Handling 189  Increasing Functionality 191  Improving the UI Framework 191  Summary 192  ■ Chapter 9: Device Fragmentation 193 Hardware Fragmentation 194  CPU Power 194  RAM 197  Screen 199  Other Hardware Considerations 201  Capabilities Fragmentation 202  API Inconsistencies 206  Localized API Inconsistencies 207  Global API Inconsistencies 210  Inconsistencies Open for Interpretation 212  Porting Frameworks 214  The Preprocessor 214  The Device Database 216  The Build Engine 216  The Abstraction API 217  Multi-platform Support 218  Utility Code and Tools 218  UI Library 219  Customer Support 219  Code License 220  Cross-Development and Porting Tools 220  Summary 221  ■ Chapter 10: Optimizing Your Code 223 A Crash Course in Optimizing Code 224  Code Optimization Techniques 226  Fast Code Path Switching 226  Avoid Redundancy 227  Use Locality to Your Advantage 227  Optimize Your Math 228  Unroll Loops 231  Inline Code 231  Optimize Loop-Related Math 232  Keep Your Loops Conditional-Free 233  www.it-ebooks.info ■ CONTENTS ix Eliminate Special Iterations from Your Loops 234  Use Loop Fission 235  Avoiding High-Level Language Features 235  Stick to the Basics 236  Avoid Unnecessary Object Creation 237  Optimize Memory Access 240  Algorithm Optimization Techniques 241  Comparing Algorithms 241  Improving Your Algorithms 243  Summary 250  ■ Chapter 11: Adding Fine Touches and User Interaction Improvements 251 Adding Fine Touches to Your Application 251  Understanding Fine Touches 252  Adding Proper In-Application Help 253  Adding Contextual Information 255  Adding Proper Feedback 256  Adding Adaptive Text Capabilities 257  Adding History and Auto-Complete Support 259  Adding Intent Detection 260  Synchronizing Your Data Between Devices 261  Improving User Interaction 262  Eliminating User Confusion 263  Keeping the Interface Simple 264  Allowing Customers to Reach You Easily 266  Creating Nonmobile Versions of Your Application 267  Deploying Continuous Application Updates 267  Adding Skin Support 268  Advertising Related Products 269  Deciding Which Fine Touches and Improvements to Implement 270  Summary 270  ■ Chapter 12: Java ME Application Testing 271 Gathering Debug Information 271  Performing Unit Testing 273  Solving Common Unit Test–Related Problems 274  Gathering Quality Debug Data 275  Running the Tests in a Desktop Environment 276  Performing Visual Debugging 276  Performing Battery Testing 277  Testing the Application in a Variety of Scenarios 279  Testing Performance Improvement and Optimization Techniques 280  Summary 281  ■ Chapter 13: Advanced Java ME Graphics 283 Using Pre-rendered Graphics 284  Using Image Masking 287  Using Image Blending Techniques 289  Rotating Images 294  Resizing Images 300  www.it-ebooks.info [...]... 15: Java ME and the Future 325 Java ME Hardware Evolution 325 The Evolution of the Java ME API .327 The Evolution of the Java ME Mindset and Development Philosophy .328 Java ME s Target Market 329 Java ME and Other Platforms .330 Java ME Application Types 331 Java ME Innovation .332 Java ME s... the core Java ME features So you see, Java ME is still an excellent candidate for developing your mobile applications Java ME s Disadvantages Like all software platforms, Java ME has weaknesses as well as strengths In order to provide a fair assessment, let’s look at Java ME s most notable disadvantages—and how these can be mitigated The main problem with Java ME is that its core API is somewhat outdated... color scheme on the user’s birthday High-quality Java ME applications are also very resource-conscious, adapting themselves on the fly to make the most of the resources available, be they scarce or plentiful Pro Java ME Apps Are Built Around a Custom Framework Pro Java ME applications are invariably built around a custom framework This framework is usually developed in-house to fit the specific project... regular Java ME applications, which tend to use fewer third-party libraries, mostly for budgetary reasons Pro Java ME Apps Reuse Code Code reuse has always been a touchy subject for Java ME, because of the widely different environments and circumstances Java ME applications have to run on This means that much of the code you write for one project (or even for one device-specific build of a project)... particular project, thus keeping your code base clean and to the point Java ME also suffers from device fragmentation (which is somewhat unavoidable considering the staggering number of devices that support Java ME) This was a huge problem in the early days; however, device support has become more standardized and tools have appeared to combat fragmentation Today, fragmentation is still a problem, but... Application Every project starts with an idea Since this book is a learning tool, our project should be something simple, fun, rewarding, and easy to understand, but at the same time it should be substantive enough to have the potential of becoming a Pro Java ME application Beginner programming books typically start with a “Hello, world” example, but we need something a little more complex So for our project,... problem, possibly the biggest problem affecting Java ME (and, to a lesser extent, other platforms, such as Android) Not all devices implement the Java ME API in the same way, and some of them even implement it wrongly This can range from easy-to-spot-and-resolve issues like different keycodes on different devices, to blatant bugs that appear only in some circumstances and only on some devices, and which are... effective in prolonging battery life, provided it is implemented properly We will learn more about this later in the book Network Variations Most of the time, devices are connected via a 2G or 3G network, whose signal can drop at any time and whose speed can vary from extremely fast to very slow and back again in mere seconds Pro Java ME applications have to take this into consideration For some applications,... Pro Java ME Applications After you’ve identified the device limitations and dealt with all the other project management issues, development typically begins Before we get to that, however, let’s look at the most important differences between regular Java ME applications, the kind that you’d write as a hobby, and Pro Java ME applications, the kind we aim to create through the course of this book Pro Java. .. comprehensive picture of what modern Java ME application development is all about Once the application is written, we will cover other aspects essential to Java ME development Code optimization, application testing, advanced graphics, improving the user’s experience and the proper Java ME developer’s mindset will all be discussed Finally, we will take a look at Java ME s future in order to get a better . Philosophy 328  Java ME s Target Market 329  Java ME and Other Platforms 330  Java ME Application Types 331  Java ME Innovation 332  Java ME s Death 333  Summary. 15: Java ME and the Future 325 Java ME Hardware Evolution 325  The Evolution of the Java ME API 327  The Evolution of the Java ME Mindset and Development

Ngày đăng: 08/03/2014, 10:20

Tài liệu cùng người dùng

Tài liệu liên quan