archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Testing Android Studio Apps on a Physical Android 6 Device - Techotopia
    on OK Repeating the adb devices command should now list the device as being available List of devices attached 015d41d4454bf80c device In the event that the device is not listed try logging out and then back in to the Mac OS X desktop and if the problem persists rebooting the system Windows ADB Configuration The first step in configuring a Windows based development system to connect to an Android device using ADB is to install the appropriate USB drivers on the system The USB drivers to install will depend on the model of Android Device If you have a Google Nexus device then it will be necessary to install and configure the Google USB Driver package on your Windows system Detailed steps to achieve this are outlined on the following web page http developer android com sdk win usb html For Android devices not supported by the Google USB driver it will be necessary to download the drivers provided by the device manufacturer A listing of drivers together with download and installation information can be obtained online at http developer android com tools extras oem usb html eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters With the drivers installed and the device now being recognized as the correct device type open a Command Prompt window and execute the following command adb devices This command should output information about the connected device similar to the following List of devices attached HT4CTJT01906 offline If the device is listed as offline or unauthorized go to the device display and check for the dialog shown in Figure 6 4 seeking permission to Allow USB debugging Figure 6 4 Enable the checkbox next to the option that reads Always allow from this computer before clicking on OK Repeating the adb devices command should now list the device as being ready List of devices attached HT4CTJT01906 device In the event that the device is not listed execute the following commands to restart the ADB server adb kill server adb start server If the device is still not listed try executing the following command android update adb Note that it may also be necessary to reboot the system Linux adb Configuration For the purposes of this chapter we will once again use Ubuntu Linux as a reference example in terms of configuring adb on Linux to connect to a physical Android device for application testing Begin by attaching the Android device to a USB port on the Ubuntu Linux system Once connected open a Terminal window and execute the Linux lsusb command to list currently available USB devices lsusb Bus 001 Device 003 ID 18d1 4e44 asus Nexus 7 9999 Bus 001 Device 001 ID 1d6b 0001 Linux Foundation 1 1 root hub Each USB device detected on the system will be listed

    Original URL path: http://www.techotopia.com/index.php/Testing_Android_Studio_Apps_on_a_Physical_Android_6_Device (2016-02-13)
    Open archived version from archive


  • The Basics of the Android Studio Code Editor - Android 6 - Techotopia
    the splitter in action with the editor split into three panels Figure 7 5 The orientation of a split panel may be changed at any time by right clicking on the corresponding tab and selecting the Change Splitter Orientation menu option Repeat these steps to unsplit a single panel this time selecting the Unsplit option from the menu All of the split panels may be removed by right clicking on any tab and selecting the Unsplit All menu option Window splitting may be used to display different files or to provide multiple windows onto the same file allowing different areas of the same file to be viewed and edited concurrently Code Completion The Android Studio editor has a considerable amount of built in knowledge of Java programming syntax and the classes and methods that make up the Android SDK as well as knowledge of your own code base As code is typed the editor scans what is being typed and where appropriate makes suggestions with regard to what might be needed to complete a statement or reference When a completion suggestion is detected by the editor a panel will appear containing a list of suggestions In Figure 7 6 for example the editor is suggesting possibilities for the beginning of a String declaration Figure 7 6 If none of the auto completion suggestions are correct simply keep typing and the editor will continue to refine the suggestions where appropriate To accept the top most suggestion simply press the Enter or Tab key on the keyboard To select a different suggestion use the arrow keys to move up and down the list once again using the Enter or Tab key to select the highlighted item Completion suggestions can be manually invoked using the Ctrl Space keyboard sequence This can be useful when changing a word or declaration in the editor When the cursor is positioned over a word in the editor that word will automatically highlight Pressing Ctrl Space will display a list of alternate suggestions To replace the current word with the currently highlighted item in the suggestion list simply press the Tab key In addition to the real time auto completion feature the Android Studio editor also offers a system referred to as Smart Completion Smart completion is invoked using the Shift Ctrl Space keyboard sequence and when selected will provide more detailed suggestions based on the current context of the code Pressing the Shift Ctrl Space shortcut sequence a second time will provide more suggestions from a wider range of possibilities Code completion can be a matter of personal preference for many programmers In recognition of this fact Android Studio provides a high level of control over the auto completion settings These can be viewed and modified by selecting the File Settings menu option and choosing Editor General Code Completion from the settings panel as shown in Figure 7 7 Figure 7 7 Statement Completion Another form of auto completion provided by the Android Studio editor is statement

    Original URL path: http://www.techotopia.com/index.php/The_Basics_of_the_Android_Studio_Code_Editor_-_Android_6 (2016-02-13)
    Open archived version from archive

  • A Guide to the Android Studio Designer Tool - Android 6 - Techotopia
    the key areas of the Android Studio Designer tool in design mode Figure 15 3 eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters A Palette The palette provides access to the range of view components provided by the Android SDK These are grouped into categories for easy navigation Items may be added to the layout either by dragging a view component from the palette and dropping it at the desired position on the layout or by clicking on a widget in the palette and then clicking at the location on the layout where it is to be positioned B Device Screen The device screen provides a visual what you see is what you get representation of the user interface layout as it is being designed This layout allows for direct manipulation of the design in terms of allowing views to be selected deleted moved and resized The device model represented by the layout can be changed at any time using a menu located in the toolbar Note that if you find the image of the device frame surrounding the display layout distracting it can be turned off by selecting the settings menu in the toolbar represented by the gear icon and toggling off the Include Device Frames if available option C Component Tree As outlined in the previous chapter Understanding Android Views View Groups and Layouts user interfaces are constructed using a hierarchical structure The component tree provides a visual overview of the hierarchy of the user interface design Selecting an element from the component tree will cause the corresponding view in the layout to be selected Similarly selecting a view from the device screen layout will select that view in the component tree hierarchy D Properties All of the component views listed in the palette have associated with them a set of properties that can be used to adjust the behavior and appearance of that view The Designer s properties panel provides access to the properties of the currently selected view in the layout allowing changes to be made E Toolbar The Designer toolbar provides quick access to a wide range of options including amongst other options the ability to zoom in and out of the device screen layout change the device model currently displayed rotate the layout between portrait and landscape and switch to a different Android SDK API level The toolbar also has a set of context sensitive buttons which will appear when relevant view types are selected in the device screen layout F Mode Switching Tabs The tabs located along the lower edge of the Designer provide a way to switch back and forth between the Designer tool s text and design modes Text Mode It is important to keep in mind when using the Android Studio Designer tool that all it

    Original URL path: http://www.techotopia.com/index.php/A_Guide_to_the_Android_Studio_Designer_Tool_-_Android_6 (2016-02-13)
    Open archived version from archive

  • Designing a User Interface using the Android Studio Designer Tool - Android 6 - Techotopia
    Set Attribute Value dialog Click on OK to dismiss the dialog and set the attribute Editing View Properties Once a view object has been placed into the user interface the properties of that view may also be modified from within the Designer tool In the first instance the width of the EditText object may be inadequate for allowing the user to enter text In order to change this select the EditText object and locate and select the Width property in the Properties panel In the value field enter a value for the desired width of the field The value must include a unit of measurement from the following list in Inches mm Millimeters pt Points 1 72 of an inch dp Density independent pixels An abstract unit of measurement based on the physical density of the device display relative to a 160dpi display baseline sp Scale independent pixels Similar to dp but scaled based on the user s font preference px Actual screen pixels Use is not recommended since different displays will have different pixels per inch Use dp in preference to this unit For the purposes of this example we will use density independent pixels as our unit of measurement so enter 350dp into the dialog and click on the OK button The width of the EditText view should change accordingly Next double click on the Button view and in the resulting panel change the text property from New Button to Press Me Click on the light bulb icon followed by the I18N message to display the Extract Resource dialog Name the resource button string and click on OK to create a string resource for the button The very simple user interface design is now complete Designing a more complex user interface layout is a continuation of the steps outlined above Simply drag and drop views onto the display position and set properties as needed and nest layouts as required Running the Application All that remains is to test that the application runs Click on the run button in the main window toolbar Select either the simulator or a physical Android device and wait for the application to start Assuming the absence of errors the application and activity should launch and appear exactly as designed using the Designer tool Manually Creating an XML Layout While the design of layouts using the layout tool greatly improves productivity it is still possible to create XML layouts by manually editing the XML The structure of an XML layout file is actually quite straightforward and follows the hierarchical approach of the view tree The first line of an XML resource file should ideally include the following standard declaration xml version 1 0 encoding utf 8 eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters This declaration should be followed by the root element of the layout typically a container view such as a layout manager This is represented by both opening and closing tags and any properties that need to be set on the view The following XML for example declares a RelativeLayout view as the root element and sets match parent properties such that it fills all the available space of the device display with padding on each side of 64 density independent pixels RelativeLayout xmlns android http schemas android com apk res android xmlns tools http schemas android com tools android layout width match parent android layout height match parent android paddingLeft 16dp android paddingRight 16dp android paddingTop 16dp android paddingBottom 16dp tools context com ebookfrenzy layoutsample LayoutSampleActivity RelativeLayout Any children that need to be added to the RelativeLayout parent must be nested within the opening and closing tags In the following example a Button and an EditText field have been added as children of the RelativeLayout view RelativeLayout xmlns android http schemas android com apk res android xmlns tools http schemas android com tools android layout width match parent android layout height match parent android paddingLeft 16dp android paddingRight 16dp android paddingTop 16dp android paddingBottom 16dp tools context com ebookfrenzy layoutsample LayoutSampleActivity Button android layout width wrap content android layout height wrap content android text string button string android id id button android layout centerVertical true android layout centerHorizontal true EditText android layout width wrap content android layout height wrap content android id id editText android layout above id button android layout centerHorizontal true android layout marginBottom 56dp android inputType text android width 350dp RelativeLayout Also note that the two child views have a number of properties declared In the case of the Button view it has been assigned ID button and configured to display the text that is represented by a string resource named button string Additionally it has been centered vertically and horizontally within the parent view and wrap content height and width properties have been declared so that the button is sized to accommodate the content in this case the text shown on the button The EditText view on the other hand has a width declared as 350dp is centered horizontally within the parent and positioned 56dp above the button view This XML file is of course the layout that was created using the Designer tool in this chapter When to write XML manually as opposed to using the Designer tool in design mode is a matter of personal preference There are however advantages to using design mode First design mode will generally be quicker given that it avoids the necessity to type lines of XML Additionally design mode avoids the necessity to learn the intricacies of the various property values of the Android SDK view classes Rather than continually refer to the Android documentation to find the correct keywords and values most properties can be located by referring to the Properties panel All the advantages of design mode aside it is important to

    Original URL path: http://www.techotopia.com/index.php/Designing_a_User_Interface_using_the_Android_Studio_Designer_Tool_-_Android_6 (2016-02-13)
    Open archived version from archive

  • Creating an Android 6 User Interface in Java Code - Techotopia
    layout named activity java layout Once the project has been created the JavaLayoutActivity java file should automatically load into the editing panel As we have come to expect Android Studio has created a template activity and overridden the onCreate method providing an ideal location for Java code to be added to create a user interface Adding Views to an Activity The onCreate method is currently designed to use a resource layout file for the user interface Begin therefore by deleting this line from the method Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState The next modification to the onCreate method is to write some Java code to add a RelativeLayout object with a single Button view child to the activity This involves the creation of new instances of the RelativeLayout and Button classes The Button view then needs to be added as a child to the RelativeLayout view which in turn is displayed via a call to the setContentView method of the activity instance package com ebookfrenzy javalayout import android support v7 app AppCompatActivity import android os Bundle import android widget Button import android widget RelativeLayout public class JavaLayoutActivity extends AppCompatActivity Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState Button myButton new Button this RelativeLayout myLayout new RelativeLayout this myLayout addView myButton setContentView myLayout eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters When new instances of user interface objects are created in this way the constructor methods must be passed the context within which the object is being created which in this case is the current activity Since the above code resides within the activity class the context is simply referenced by the standard Java this keyword Button myButton new Button this Once the above additions have been made compile and run the application either on a physical device or an emulator Once launched the visible result will be a button containing no text appearing in the top left hand corner of the RelativeLayout view as shown in Figure 17 1 Figure 17 1 Setting View Properties For the purposes of this exercise we need the background of the RelativeLayout view to be blue and the Button view to display text that reads Press Me on a yellow background Both of these tasks can be achieved by setting properties on the views in the Java code as outlined in the following code fragment package com ebookfrenzy javalayout import android support v7 app AppCompatActivity import android os Bundle import android widget Button import android widget RelativeLayout import android graphics Color public class JavaLayoutActivity extends AppCompatActivity Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState Button myButton new Button this myButton setText Press Me myButton setBackgroundColor Color YELLOW RelativeLayout myLayout new RelativeLayout this myLayout setBackgroundColor Color BLUE myLayout addView myButton setContentView myLayout When the application is now compiled and run the layout will reflect the property settings such that the layout will appear with a blue background and the button will display the assigned text on a yellow background Adding Layout Parameters and Rules By default the RelativeLayout view has placed the button view in the top left corner of the display In order to instruct the layout view to place the button in a different location in this case centered both horizontally and vertically it will be necessary to create a LayoutParams object and initialize it with the appropriate values Typically a new LayoutParams instance is created by passing through the height and width values for the view These values should be set to either MATCH PARENT WRAP CONTENT or specific size values The MATCH PARENT setting instructs the parent layout to expand the child view so that it matches the size of the parent WRAP CONTENT on the other hand instructs the parent to size the child view so that it is only large enough to display any content it may be configured to show to the user The code to create a LayoutParams object for our button would read as follows RelativeLayout LayoutParams buttonParams new RelativeLayout LayoutParams RelativeLayout LayoutParams WRAP CONTENT RelativeLayout LayoutParams WRAP CONTENT The above code creates a new RelativeLayout LayoutParams object named buttonParams and sets the height and width such that the button will only be large enough to display the Press Me text previously configured via the property setting Now that the LayoutParams object has been created the next step is to add some additional rules to the parameters to instruct the layout parent to center the button vertically and horizontally This is achieved by calling the addRule method of the buttonParams object passing through the appropriate values as arguments buttonParams addRule RelativeLayout CENTER HORIZONTAL buttonParams addRule RelativeLayout CENTER VERTICAL Simply creating a new LayoutParams object and configuring it is only useful if that object is then assigned to the child view One way to achieve this is to pass the LayoutParams object through as an argument when the child view is added to the parent myLayout addView myButton buttonParams Alternatively the parameters can be assigned to the child via a call to the setLayoutParams method of the view myButton setLayoutParams buttonParams Bringing these together results in a modified onCreate method that reads as follows Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState Button myButton new Button this myButton setText Press me myButton setBackgroundColor Color YELLOW RelativeLayout myLayout new RelativeLayout this myLayout setBackgroundColor Color BLUE myButton setBackgroundColor Color YELLOW RelativeLayout LayoutParams buttonParams new RelativeLayout LayoutParams RelativeLayout LayoutParams WRAP CONTENT RelativeLayout LayoutParams WRAP CONTENT buttonParams addRule RelativeLayout CENTER HORIZONTAL buttonParams addRule RelativeLayout CENTER VERTICAL myLayout addView myButton buttonParams setContentView myLayout Having made the above changes compile and run the application once again this time noting that the button is now centered within the RelativeLayout view as illustrated in Figure 17 2 Figure 17 2 In order to gain a

    Original URL path: http://www.techotopia.com/index.php/Creating_an_Android_6_User_Interface_in_Java_Code (2016-02-13)
    Open archived version from archive

  • Using the Android 6 GridLayout Manager in Android Studio Designer - Techotopia
    enough to accommodate the child views contained therein As such the height and width parameters of the GridLayout view need to be changed from match parent to wrap content One way to make this change is to locate the properties in the Designer tool s Properties panel A quicker option is to select the GridLayout instance and use the two buttons in the Designer toolbar Set the width property by clicking on the layout width button as highlighted in Figure 18 2 Figure 18 2 Having set the width property to wrap content click on the adjacent toolbar button to similarly set the layout height property These settings will have the effect of shrinking the layout down to a small square ready to accommodate some child views If the GridLayout instance is still positioned in the center of the screen click and drag it to the upper left hand corner Adding Views to GridLayout Cells To place view objects into the cells of a GridLayout simply click on the required view in the palette and drag it to the GridLayout instance in the device screen layout canvas As the view passes over the GridLayout information will appear indicating the placement of the view if it is dropped at that point Begin by clicking and dragging a Button view from the palette over to the top left hand corner of the GridLayout as illustrated in Figure 18 3 Figure 18 3 As is evident from the message displayed by the tool releasing the view at this point will position it in the cell referenced by the co ordinates of 0 0 Release the view at this point and note that the Button is placed in the cell as shown in Figure 18 4 Figure 18 4 Note also that green bars have appeared in the margins on the upper and right hand sides of the main Designer area These bars represent the rows and columns present in the GridLayout currently the layout has one row and one column Repeat the above steps to place a second button into the GridLayout so that it is positioned in row zero and after column 0 such that it appears immediately to the right of the first button Drag a third Button view to a position to the left of the first Button view until the message shown in Figure 18 5 appears providing the option to shift column 0 right and insert the new view into the cell at 0 0 Figure 18 5 When the view is dropped at this position the existing columns will be shifted one place to the right a new column will be inserted at the left hand edge of the GridLayout and the new button placed into the cell eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions

    Original URL path: http://www.techotopia.com/index.php/Using_the_Android_6_GridLayout_Manager_in_Android_Studio_Designer (2016-02-13)
    Open archived version from archive

  • Working with the Android 6 GridLayout using XML Layout Resources - Techotopia
    com tools android id id GridLayout1 android layout width wrap content android layout height wrap content android columnCount 2 android rowCount 2 android orientation horizontal tools context GridLayoutActivity GridLayout eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Adding Child Views to the GridLayout Child views can be added to a GridLayout by declaring the elements within the GridLayout structure in the XML file If no row and column values are declared for a child it is positioned automatically by the GridLayout class based on the configuration of the layout and the position of the view in the XML file The following XML places four buttons within the above GridLayout with each view placed in the top left hand corner of the encapsulating cell GridLayout xmlns android http schemas android com apk res android xmlns tools http schemas android com tools android id id GridLayout1 android layout width wrap content android layout height wrap content android columnCount 2 android rowCount 2 android orientation horizontal tools context GridLayoutActivity Button android id id button1 android layout gravity start top android text Button Button android id id button2 android layout gravity start top android text Button Button android id id button3 android layout gravity start top android text Button Button android id id button4 android layout gravity start top android text Button GridLayout google ADSDAQBOX FLOW google The above layout would be visually represented as illustrated in Figure 19 1 Figure 19 1 Note that after entering the above XML code it may be necessary to click on the refresh button located in the Designer toolbar in order for the user interface to appear correctly A view can be placed within a specific cell by specifying the intersecting row and column number of the destination cell The following Button view for example will be placed in the cell located at row 1 column 2 of the parent GridLayout Button android id id button5 android layout column 2 android layout row 1 android layout gravity start top android text Button Declaring Cell Spanning Gravity and Margins The child of a GridLayout can be configured to span multiple cells using the android layout rowSpan and android layout columnSpan properties The gravity of the child is controlled via the android layout gravity property In the XML fragment below a Button view is configured to span 3 columns and 2 rows and to fill the space available both horizontally and vertically Button android id id button4 android layout columnSpan 3 android layout rowSpan 2 android layout gravity fill android text Button The margins around a view within a cell can be declared for all sides of the view using the android layout margin margin property Alternatively margins for individual sides may be defined using the topMargin bottomMargin leftMargin and rightMargin properties The following Button

    Original URL path: http://www.techotopia.com/index.php/Working_with_the_Android_6_GridLayout_using_XML_Layout_Resources (2016-02-13)
    Open archived version from archive

  • An Overview and Example of Android 6 Event Handling - Techotopia
    methods that require an index value this should be obtained by converting the ID for a touch to the corresponding index value via a call to the findPointerIndex method of the MotionEvent object An Example Multi Touch Application The example application created in the remainder of this chapter will track up to two touch gestures as they move across a layout view As the events for each touch are triggered the coordinates index and ID for each touch will be displayed on the screen Create a new project in Android Studio entering MotionEvent into the Application name field and ebookfrenzy com as the Company Domain setting before clicking on the Next button On the form factors screen enable the Phone and Tablet option and set the minimum SDK setting to API 8 Android 2 2 Froyo Continue to proceed through the screens requesting the creation of an empty activity named MotionEventActivity with a corresponding layout file named activity motion event Click on the Finish button to initiate the project creation process Designing the Activity User Interface The user interface for the application s sole activity is to consist of a RelativeLayout view containing two TextView objects Within the Project tool window navigate to app res layout and double click on the activity motion event xml layout resource file to load it into the Android Studio Designer tool One option is to design the layout illustrated in Figure 21 1 using a RelativeLayout as the root view and keeping in mind that the lower TextView component is centered horizontally within the parent view and the upper TextView is positioned a relative distance above the lower TextView When the layout design is complete double click on the RelativeLayout essentially the background of the layout and set the ID to RelativeLayout1 Repeat these steps to assign IDs textView1 and textView2 to the TextView components Alternatively switch to the XML editor by selecting the Text tab at the bottom of the Designer panel and replace the current XML with the following xml version 1 0 encoding utf 8 RelativeLayout xmlns android http schemas android com apk res android android id id RelativeLayout1 android layout width match parent android layout height match parent TextView android id id textView2 android layout width wrap content android layout height wrap content android layout centerHorizontal true android layout centerVertical true android text Touch Two Status TextView android id id textView1 android layout width wrap content android layout height wrap content android layout above id textView2 android layout alignStart id textView2 android layout marginBottom 47dp android text Touch One Status RelativeLayout Switch to Design mode and select the upper TextView in the device screen layout When the light bulb icon appears click on it and select the I18N hardcoded string warning message to display the Extract Resource dialog Within the dialog name the resource string status1 string and click on the OK button Repeat these steps for the second TextView component this time naming the string resource status2 string Figure

    Original URL path: http://www.techotopia.com/index.php/An_Overview_and_Example_of_Android_6_Event_Handling (2016-02-13)
    Open archived version from archive



  •