Placeholder Image

字幕列表 影片播放

  • >>Xavier Ducrohet: Hello, everyone. Welcome to I/O and welcome our session on What's New

  • in Android Developer Tools. My name is Xavier Ducrohet.

  • >>> I think we have a few things to show. >>Xavier Ducrohet: Maybe. So Android Studio.

  • So when we released the first SDK in 2007, we released some tools with it and since then

  • we've done a lot of progress in and outside of the IDE based on Eclipse and we are going

  • to keep on doing that, but one thing that we could never really do is really improve

  • the whole workflow of being an Android developer inside the IDE, and we really wanted to improve

  • that. So when we wanted to concentrate on Android-focused

  • IDE, we decided to go with IntelliJ. IntelliJ is a great Java IDE, but it's also based on

  • a very extensible platform. It's the same platform that borrowed some of the other IDE

  • from JetBrains, like (indiscernible), Python IDE or Javascript IDE. And the extensibility

  • is really available throughout. Some of the core components like product support, build

  • support, the support that powers all of the refactoring, all the way up to the UI where

  • everything is customizable. >>Tor Norbye: And the build support, that

  • extensibility is the most important part given what we're going to show you.

  • >>Xavier Ducrohet: So this is going to allow us to create a lot of very advanced features

  • that we couldn't really do before, but also creates an experience that is really focused

  • for Android. And when we did something in the IntelliJ

  • platform that is not extensible we worked directly with JetBrains to make sure that

  • Web extension point so we don't fog that platform. We're just basing all IDE on their platform.

  • We're using everything that they're doing. In fact, we're actually building on top of

  • their existing Android support. So it had support for building, editing, debugging and

  • not just extending that. So in the past few months we've mostly worked

  • in our internal repository because we wanted that to be a surprise, and today we're moving

  • back to the open source project, so it's live now in AOSP and since we're doing that we

  • figured out we would also give you a preview. So today it went live, not too long ago. You

  • can go download Android Studio, it's version 0.1. It's a bit rough around the edges. The

  • IntelliJ part is mostly stable. >>Tor Norbye: There are some parts that are

  • rock solid and other parts that are not. >>Xavier Ducrohet: Yes, but we want to have

  • a lot of feedback. We want to make the best IDE possible. We're going to integrate very

  • quickly, fix bugs, add new features and gather feedback from you. So please try it and send

  • us feedback. Now, I realize that probably some of you,

  • you know, have never tried IntelliJ before and so we wanted to give you a quick overview

  • of IntelliJ before we show you some of the Android Studio specific features.

  • So I'm very happy to introduce on stage Dmitry Jemerov, the CTO of JetBrains to give you

  • an overview of IntelliJ. >>> Hello, everyone. So my name is Dmitry,

  • the CTO of JetBrains. I'm very excited to be here and thanks for the warm reception

  • during the keynote. And I'd like to tell a bit about our side of this story.

  • So we have been long watching the work that the tools team has been doing on the Android

  • tooling and we have been very impressed with the quality of that work so we are sure that

  • our Android plug-in is in good hands now. From our side we fully support that effort.

  • We provide the necessary extensions in the platform that the guys here need from us and

  • so it's all versed together very nicely. From our side we're also going to ship all

  • of that stuff as part of our release as part of IntelliJ Idea itself. And for those of

  • you not familiar with our products, we have actually two editions of the product. The

  • IntelliJ IDEA Community edition is the free and open source version which is what Android

  • Studio is based on. And we have IntelliJ IDEA Ultimate, the commercial edition of the IDE,

  • which also includes support for server side development, starting with CSS and JavaScript

  • and proceeding to the Java enterprise frameworks like Spring Hibernate, Java EE and stuff like

  • that, database support and so on. So if you're working on a pure Android project,

  • the Android Studio is the best tool of choice for you and if you have a project that has

  • a service side component or simply if you're working in a more distributed environment,

  • then you might want to look at IntelliJ IDEA Ultimate.

  • So now I'm going to give a quick demo of the features in IntelliJ. It's not going to be

  • Android specific so that will be Tor's part of the demo. I'll just start with a general

  • overview. So the motto of our company is "Develop with

  • Pleasure." And one of the key things from which pleasure comes during development is

  • not having to worry about routine tasks, so stuff happening -- as much stuff as possible

  • should happen automatically, should be done automatically for you.

  • So for example, like routine stuff like saving files or managing imports, this is all done

  • for you by the IDE automatically on the fly. Another part is that IntelliJ IDEA has a wide

  • array of refactorings and quick fixes for the problems that you can encounter in your

  • code. And we do not see them just as tools for fixing errors or fixing code that is broken.

  • We see them as an integral part of the code-writing experience inside IntelliJ. And I'm going

  • to show a little bit of how this works in practice.

  • So I'm going to start writing -- this is a simple Android app, a little more than Hello

  • world. And I've written a method and told that does not exist and so now I'll use a

  • quick fix to create it for me. Now I'm going to call the regular find ULD

  • method which all of you know, and now I'll use refactoring to save this as enter variable.

  • So I introduce the variable refactoring and I enter the name of the variable.

  • And by the way, notice this all happens in place. There are no dialogue box popping up,

  • nothing like that. Now it has the wrong type and it's actually

  • a text use so I'm entering text use here. Of course it can also insert the necessary

  • type cast for me. Now I'm going to write some control structures,

  • 2013, and now this statement is incomplete. It lacks parenthesis and stuff, and I'm going

  • to use an action called complete statement that is going to turn this into a complete

  • statement for me essentially. So I'm invoking from the menu, but -- you

  • always use the keyboard for this, but in order for you to see what I'm doing, the menu is

  • more clear. So now this is an unresolved parameter and

  • I'm going to create this now, create parameter, and this actually triggers another refactoring,

  • the change signature refactoring. And this is going to go through all of the

  • calls of the method from -- of which there is only one and it will actually introduce

  • the necessary value into the call. Now, set text, Hello I/O. Of course, this

  • is an Android app so this is supposed to be a resource and we have a fix for that, but

  • that's part of Tor's demo, not mine. Another thing showing is in IntelliJ IDEA

  • we have two code completion actions. There's the regular code completion which you have

  • seen a number of times already and we also have the smart app completion. And the smart

  • app completion actually restricts the options on the completion list to the values of the

  • correct type. And it's actually not something that you always

  • want, but when you do want it, it's very easy and accessible using keyboard shortcut. And

  • if you press the same keyboard shortcut again it will have return values of the same type.

  • Now, actually, it looks like I'm -- I'm not really going to need this so I'm going to

  • use another nice coding assistance action called unwrap remove to get rid of this statement

  • for me. I select the option to unwrap gift and, poof,

  • it disappears. Now this parent is no longer used and, of

  • course, there's another quick fix to get rid of it. And remove parameter. It's gone. By

  • the way, I mentioned background code analysis and I would like specifically to highlight

  • some of the (Indiscernible) features. Some of them are pretty smart.

  • For example, this is my favorite, inspection. So when you are writing UI code you can often

  • make the error of mixing up the coordinates, mixing up X and Y or height and width or something

  • like that, and we have built in something especially for that. In this case I'm having

  • the max width value and set the height. IntelliJ IDEA highlights that problem and

  • I'm probably doing something wrong and probably I have messed things up and I should correct

  • them. The next thing I would -- I want to look at

  • is our version control integration. An important thing to note that in IntelliJ IDEA all the

  • version control plug-ins such as gifts (indiscernible) and a few more, they're all bundled in the

  • distribution of the product so you don't have to hunt for plug-ins. All the plug-ins have

  • a consistent user experience and work in a similar way.

  • And the key part of the version control integration is our changes view.

  • This is the view that shows the list of all the things that you have modified or added

  • to the project or removed from the version control, and it's automatically updated on

  • the fly. And you can always access the diffs and see

  • what changes exactly have you made. You can also use this view to trigger the

  • commit action so you select the files that you want to go in and you click on commit

  • changes and you get this commit dialogue. And because this product is using get, I also

  • get the option to put the changes in -- no, no, I don't want to do that.

  • I get the option of push the changes to the server immediately.

  • Now, if you want to look at what other people in the project have been doing, you can use

  • the get log view for that. So if you switch to that tab it shows a nice

  • graph for commit so this part does not have any complications in branch structure, but

  • if it had it would be displayed right here. Of course I can also show diffs to see exactly

  • was changed and you can pull the latest changes to my machine.

  • And another nice thing we have for get is this branch chooser pop-up. So right now I

  • am under my diff branch and I can use a new one that I'm doing or merge this into the

  • master branch or something like that. Now, of course, I could be talking for hours

  • about different features of the IDE, but we don't have that much time, so I'll switch

  • to giving you some useful pointers on how to explore the IDE further.

  • So first of all we have this tip of the day thing. And unlike some other products it actually

  • contains useful and relevant information so you can go look through those and learn something

  • useful. Another useful thing is the find action keyboard

  • shortcut. So for example, some of the things that I

  • have used you can type in complete and it will show the complete commit statement and

  • shortcut for it so that you can invoke it that way and learn the keyboard shortcut in

  • the future. We also have a blog with a lot of useful information

  • on our product. You can follow us on Twitter. And finally, we have a booth in the developer

  • sandbox and we will be there for the whole three days of the conference and if you have

  • any questions on what's going on with IntelliJ or how is it better than Eclipse or stuff

  • like that, please go there and ask us and we will be happy to answer it -- answer those

  • questions. Now I'm handing over to Xav for the communication

  • demo. [ Applause ]

  • >>Xavier Ducrochet: Thank you. We're really excited to build Studio on IntelliJ.

  • It's really a fantastic tool. Now I want to talk a little about project support because

  • this is something we really want to do well. If you look at the current situation you will

  • -- in Eclipse we have some custom builders. We have an end script somewhere. IntelliJ

  • has its own builder and they may not all do the same thing and it's really a problem and

  • we wanted to fix that. We want to have a single system, a system

  • that's flexible and customizable so that it can adopt to all your needs, and some of you

  • have some very specific needs. And we want to make sure also that whether

  • you're working in the IDE or whether you're building in your continuous integration server

  • then you should have exactly the same results. If you have some customization and you're

  • working in the IDE and you don't get the same result because the IDE doesn't understand

  • the customization, that's a problem. So for a little under a year now we've we

  • started working on that, we started an implementing a new design build system. It's based on Gradle

  • and it's very extensive, customizable and very extensible and it is deeply integrated

  • into the IDE. That means that in Studio the different behavior is when you create a new

  • project it will create a Gradle project using our Gradle plug-in and then it will get imported

  • into Studio using the great Gradle support that JetBrains is adding into IntelliJ.

  • And when you're building from studio it's going to actually delegate the build to Gradle

  • and have Gradle do the build so that whether you're inside your IDE or on a build server,

  • the same result every time, and that's really important.

  • We have a concept of a build variant in this build system. There was a talk during the

  • keynote talking about beta test and alpha test and being able to deploy that to users

  • so we have the ability to have different build environs whether you want to do release build

  • or maybe a bit hub build. We also have support for debug, for instance. So here we have a

  • build file that has two product flavors, paid versus free, then it has a new build type

  • bit hub. And you could configure it different ways.

  • I have a new panel here that shows build IM that shows I am working right now on the paid

  • debug version. That means when I click launch it's actually launching your paid debug version.

  • If you look at the source folders on the left here, the blue source folder, Java here and

  • then it's source main Java and source paid Java are your main source folders, so in that

  • paid Java folder it would put code specific to that version.

  • The green version says here that your test code, so the instrumentation test and instrumentation

  • test paid, that's your test specifically to test the paid version. And notice there's

  • a free Java and -- it says free Java here. That's not selected because you're not working

  • on the free version. So here, based on everything that we say in

  • the build script the IDE is aware that you have six different buy-ins and when you switch

  • to free debug it's going to automatically switch those here.

  • So the IDE is really aware of all your configuration. A lot of this is working now. There are some

  • things if you deal with buy-ins -- if you deal with resources and flavor (indiscernible),

  • we are going to fix that, but the point here is that everything that you do in the build

  • script to customize your application will be understood by the IDE and that's very important.

  • I'm not going to talk more about the build session. I have a session at 9:00 a.m. on

  • Friday only about the build session and I encourage you to attend it.

  • And now Tor is going to talk for us. >>Tor Norbye: All right. So I'm going to focus

  • today on -- is my monitor okay? I'm going to focus today on the areas where

  • Android Studio is different than Eclipse because there are many things that are the same, so

  • showing that wouldn't -- we're not trying to prove that we're done because we're not.

  • There's many areas that are missing. So if I can bring up the screen, here you

  • can see the environment. And one of the, I think, most noticeable features is when you're

  • editing layouts you get this preview on the right and we have a little bit of eye candy.

  • We've got Romain Guy's device frame art integrated so you can sort of see the device here. So

  • if I switch, for example, to Galaxy Nexus I can see that art and with drop shadows and

  • everything. And if you don't like that, if you really

  • want your pixels back, which I understand, you can go to the options and turn off the

  • device frame so you can take all the space for the layout, but personally I just sit

  • there and look at the reflection, overlay and love it.

  • [ Laughter ] >>Tor Norbye: So obviously as you're editing

  • you can kind of keep an eye on this. And note that as I'm moving the carat around in the

  • layout you can see the corresponding views getting selected in the layout preview. You

  • can see what you're doing. And likewise I can actually click over here

  • to navigate around the XML, so it makes it easy to navigate around and know what the

  • different parts are. And just like in Eclipse we have the configuration

  • chooser up on top here. You saw me switch devices and you can switch locales. This is

  • what we showed in the keynote demo this morning. And there's a theme to it, which is now a

  • dialogue so you can more quickly search for things. If I'm looking for dark action bar,

  • for example, it will find it right there and then I can click on it to choose it, for example.

  • One of the really nice things about this XML preview is that it's tied in with IntelliJ's

  • XML model, which is really good at fault tolerance. So one of the nice things is if I, for example,

  • go and put a typo into this thing right here, into this switch, what you will see happen

  • is this widget disappeared because it's no longer valid, but the rest of the layout actually

  • completed because it's not starting a fresh render each time. It's sort of hey, I have

  • an error node in the dump. And this also shows the error panel, which

  • is showing up in the bottom right here. So I'm going to create a new layout. So to

  • do that I can invoke the new menu, new layout resource file. So -- oh, and it's locale.

  • I'm going to switch locale back to English. So when I'm entering text here, let's say

  • I enter a button, you can see it's immediately telling me there are some problems here. So

  • it's saying you need to insert a width and a height. There are also links here, so I

  • can click on automatically add all missing attributes and they kind of just appear. So

  • there are a bunch of error recovery links right there.

  • If there's a typo, for example, it will figure out what you probably meant button, and it

  • will fix it. If you use fragments -- let's do it. I'll

  • add a fragment and we're going to need sizes again.

  • So for fragments it's saying, hey, you probably want to have a class associated with this

  • fragment, right? So I can invoke the chooser for that and pick one. Countdown fragment,

  • maybe. And now it's saying that maybe at design time you want to have a layout because the

  • whole point of fragments is it's a Java class and that class can decide based on the time

  • of day and locale and whatever, logic, whatever to actually use, a design time you can pick

  • different ones at different times. So I will pick a random one and now the layout is using

  • that fragment. You can see here in the layout this special

  • tools attribute, this is where we store metadata. You can safely ignore those. In fact, AAPT

  • will also ignore them, so there's not runtime benefit. This is how we put stuff in the model,

  • and we do the same thing in Eclipse for fragments. One more thing on the device art, we've also

  • integrated this with the screen shot action, so in the Android window I don't have a device

  • connected, but if I did, you could basically click on the screen shot from your live device,

  • get a screen shot and then add whatever art you want.

  • All right. So let's switch to the layout editor. So I'm going to -- in fact, I'll switch over

  • to this layout right here. This is a simple form.

  • So now we're in the layout editor. And I'll say right away we are not feature complete

  • here. Not everything that you had in Eclipse is ready here. I will show you the few things

  • where we are ahead, and that would be grid layout support.

  • So the grid layout support in our Eclipse plug-in is very complete and it's much better

  • here. As you can see, I can see the rows and columns

  • here and I can, for example, drag on these things to re-order them.

  • If I want to pull in new widgets, here's the palette and I get the predictable grid and

  • I can put it between. If you're doing grid layout editing I would

  • already use this, but there are some other areas where we're still working on it.

  • The good news about this preview, by the way, is that they have a really good update mechanism.

  • At least on some platforms it downloads a small patch file and restarts the IDE so it

  • takes 30 seconds, and we plan to use this to have this be a rolling preview. We talked

  • about every week. We're publicly committing right now to consider our update interval.

  • So that's the layout editor. Let's see. The next thing I want to show you

  • is code editing. So here's the feature we demoed this morning

  • in the keynote, and that is the resource folding. So one of the really cool features in IntelliJ

  • is they have this folding feature where it collapses code. So when you have a static

  • interclass, you have a run, one line for the override annotation, another line for the

  • public void run, a couple more lines for the opening and close breaks, they will fold that

  • all into a single line. So we've just used that feature and combined it with Android's

  • resources to do what you see here. This is not the default color that we have

  • for folding regions, but for the dark theme the default one was a bit hard to spot for

  • the keynote with the large screen so we made it more blue. But in general you can see here

  • -- let me click here to open all folds. So this is what the code really looks like.

  • So you don't have to know the key binding I just hit because by default you open a file

  • and it does one of these get string calls. We just show the string. When you hover over

  • it you basically get to see the real code. Like this.

  • And take a look at this last one here. I'm going to jump into this resource. And you

  • can see that what this is doing is it actually has formatting arguments. All right?

  • And when I go back and I look at the folded string, you can see that it's showing the

  • actual parameters that we have in the code, sort of in line with the strings. So it makes

  • it really easy to see what logically your code is doing.

  • So now you may wonder, okay, so have you hard coded this for get string? We have not.

  • So if I look for -- let's see -- set text, for example, what we do is we use an annotation

  • for this. So now I'm going to jump into the Android framework source code. Hopefully there's

  • nothing proprietary here. If you look, this is the TextView class. And

  • there's a new annotation on here and this is a bit TBD. We haven't actually integrated

  • this, but I think there is consensus that this is what we're going to do. This is a

  • resource data annotation. And it's saying, hey, this integer parameter right here, we

  • expect that to be a resource in. So that's the actual thing that the code folding is

  • using is this method. So when you call set text, even if you don't call get string, if

  • you just pass r.string.fu it will actually do this resolution.

  • So since we're talking about annotations, let me show you a few others that we're adding.

  • If I go to context, you can see not null. We're also adding nullability annotations,

  • and IntelliJ can actually show those. So if I open up the project configuration for my

  • SDK, there's this annotations setting where we have basically bundled Android annotations.

  • So it can basically read annotations from an external file, not part of the SDK, and

  • that's how we can actually take these annotations and associate them with older SDKs and it's

  • using this on the fly. So if I now jump down to the bottom of the

  • file here -- let's see here, for example, this line is highlighted because it shows

  • that get current focus, which is an inherited method from the framework, can return null

  • and therefore this line could potentially return -- cause a null pointer exception.

  • If I jump into the other annotation here, service name, I'm going to jump to source

  • for that. And this is making a local annotation saying that service name has to be one of

  • these identifiers. So in fact, if I go back to my Android Studio,

  • you can see we have another annotation here saying that you're passing in the right to

  • set layout direction, but it's the wrong right. Even though these are both ints and the compiler

  • is happy to do it for you, we know it's wrong. And that's because again we have this information

  • now in this external file that basically records what constants are allowed for integer parameters.

  • At that's in this external file that basically records what constants are allowed for integer

  • parameters, and in the case of the system service here, strings. And we use this not

  • just for semantic analysis. If I, for example, go in to get system service

  • and press control space for completion, you can see it notes the strings there, too. So

  • especially for integer APIs, it's kind of nice. You don't have to know exactly what

  • the strings are. At this point, I'm going to jump in and show

  • you a few other IntelliJ editor features. So when I was showing you the resources earlier

  • here, we have references to notification icons and those are being previewed on the left.

  • This is the actual size we show them in. I think we max them out at 14 pixels. In the

  • keynote we had them bigger to be visible, but this is what they'll get scaled down to.

  • So these graphics -- these aren't just for icons. If you have a 128 by 128 icon, it will

  • just be shoved into this editor margin. And colors are previewed as well.

  • And if you open up the show documentation view, I think it's F1. If not, we have an

  • expert on stage -- F1, yes. This is the documentation for this resource. We show you all the translations

  • right there in the popup. And if I do it on an icon, I can see all the icon versions.

  • And I think -- yes, it's computing what the actual pixel sizes are at the different densities.

  • All right. So we've also integrated lint. There was already

  • a lint integration in IntelliJ but it now does more the inspections. And lint actually

  • does analysis on both XML, Java and class files. And the last part is tricky because

  • one of the things you'll discover in Android Studio is it doesn't do background compilation

  • in the way you're used to. There's an explicit compile action. So because of that, lint doesn't

  • have the class files to look at. So we've implemented the most important one,

  • API check, using IntelliJ's own AST APIs. And so if I look for API check, here's an

  • example of this. So if I hover over this, it's telling me that

  • this API requires 14, and you're current min SDK is 7, and that's a potential runtime problem.

  • So what you can do is use an annotation to basically say you know this method will only

  • be called when we've already validated that the platform is at least 14.

  • The way people typically do that is what you see on the next slide. You actually have an

  • SDK check. And it was very tricky to do this with sort of flow analysis in the class file

  • but it was easy with AST. So this is something we haven't run in Eclipse or the command line

  • lint yet, but in IntelliJ it knows not to flag these two lines because they are inside

  • this version check right there. We also have a couple of newlin checks.

  • Is there a talk on the right-to-left text stuff here at I/O? If not, at least we have

  • a couple of new lint checks related to right-to-left and they are disabled by default but they're

  • a bit experimental, but if you're trying to target API 17 and you're doing right-to-left

  • text, you can check out the lint options. So in the search box you can just search for

  • lint. You'll find all the inspections. And you can see the ones that don't have a check

  • box next to them are off by default and you may want to turn them on. For the basic Java

  • code analysis in IntelliJ, there are some off by default that we've gone and bumped

  • up. On our team, for the tools, for example, we make override annotations mandatory. You

  • can't actually override without setting the override annotation.

  • All right. This part I want to show you a couple of IntelliJ

  • features that Dmitri didn't get into. So the first one is scopes.

  • So here I have a library project, and I can go ahead and create -- and I'm using action

  • brochure lock because I'm trying to have an action bar in an older version of Android.

  • So I can go ahead and open up the scopes feature. And I can go ahead and make a new scope, a

  • new local scope and I'm going to call it action bar.

  • And then I can say that I want this to basically match all of action bar -- I just closed the

  • dialogue. Sorry about that.

  • And now I can basically say that I want to add everything from -- I don't know, I'm making

  • a mistake here. Project. Okay. I'm going to choose everything in the

  • action bar Sherlock and include recursively. So now we have a new scope. Now I can go to

  • file colors, and I can basically add a new color scope for my new scope. So I'm going

  • to make everything related to action bar orange. And now if you look in the project explorer,

  • everything here is orange. And if I open these files you can see the tabs are orange. And

  • in, in fact, in the recent file dialogue, things are orange. So this is really good

  • if you have projects that you're trying to use and they're in your work space but you

  • don't want it accidentally edit them. You're jumping into resource and you find, ah, this

  • is actually in the library. I can't change this. This feature is really useful for that.

  • My favorite feature in IntelliJ is open symbol. So if you are exploring a new API, if you're

  • not particularly familiar with something in an API, open symbol lets you jump to a method

  • name or field name. So if you're not sure which class to look in, instead of searching

  • with Google, which you should do, you can use open symbol here.

  • So I'm going to use the go to action feature that Dmitry showed you. So if you don't know

  • any key binding, basically you can open this dialogue and just search for it and it will

  • basically match. Open symbol. Okay. So this is the open symbol action.

  • And now let's say I want to find out the parent activity name or something like that. So I

  • can type parent activity name. And actually I want to go to this one. So

  • nav util contains a method called get parent activity name (indiscernible) in the context.

  • Another cool feature is injecting languages. So here I'm showing a method called inject.

  • And so if you look carefully you can see there's a green shine to this area. That's telling

  • me that it knows there's a sort of different language inside this string. And if I open

  • up the quick dialogue, it says this is a regular expression and I can, for example, open a

  • regular expression tester and I can type in text to see if it matches.

  • And so -- [ Applause ]

  • >>Tor Norbye: -- so on the next line, you can see I'm actually -- I'm going to go on

  • the third line here. This looks like XML; right? I can say inject language and I can

  • pick the language I know this is. I'm going to say this is XML. And now this is going

  • to be treated as XML. So, in fact, let me make a mistake in the

  • XML. So now it's saying, hey, this looks invalid to me. It's saying there's no attribute value

  • here; right? So it's basically validating my string escaped

  • as XML. And I believe this is really useful when you,

  • for example, are doing database queries. I think IntelliJ has a database plug-in so if

  • I were to treat this as SQL, for example, you can get additional language help that

  • way. And I am almost out of time.

  • The last tip I'll give you is that in a lot of dialogues, in the IDE, you can just start

  • typing. It's not going to tell you you can do this. It's just something you know.

  • So my favorite key binding is, other than alt enter, is control T. Control T is basically

  • the action to refactor this. So if you can't remember the key binding for,

  • you know, renaming or moving or whatever, just control T, refactor this.

  • And so here's this dialogue. Notice that there's numbers at beginning of these items. I can

  • just hit the number on the keyboard to invoke that action but more importantly I can just

  • start typing. So if I type change -- actually, that was a bad word.

  • Okay. Constant. If I try typing C-O-N, you can see it matches. So it's a very quick way

  • to navigate and this works in lots of places. For example, if I want to go create a new

  • resource folder here, add new resource directory, if I, for example, want to go and add a language

  • to my animation folder, let's change that to layout instead because I like layouts.

  • Oh, that's the name. Layouts. If I add in a new language, you can see we have region

  • art here. So if I just start typing Norway, you can

  • see it's now matching from the whole list of hundreds of regions down to the region

  • that I'm trying to add here. And then I can add my resource photo like that.

  • All right. I'm out of time but there's more stuff, so, you know, keep looking at our blogs

  • and posts for additional tips. [ Applause ]

  • >>Tor Norbye: Thanks. >>Xavier Ducrohet: Thank you, Tor.

  • So one other thing we wanted to do is to cover more than just, like, regular Android applications.

  • I mean in the context of Android application. A lot of your users are going to have more

  • than one device that have a phone and a tablet. And if they install your application on their

  • device they are going to expect those two installations to be synced together. So we

  • wanted to add support to really help you build applications that are connected like that.

  • And so I'd like to invite on stage Brad Abrams, the PM for app engine, to tell you about this

  • feature. >>Brad Abrams: Awesome. So the best Android

  • apps are powered by the cloud, and customers tell us that google's cloud platform is really

  • ideal for mobile back-ends. And that's why we were very happy to invest in the Android

  • Studio project. So what I thought we'd do is actually cloud

  • connect the stopwatch application that you saw earlier.

  • So what we're going to do in just a couple of minutes is build out a completely synchronized

  • stopwatch application. So somebody at the front of the race can have the stopwatch.

  • Someone at the end of the race can see exactly start/stop time of that.

  • So in order to do that, one stopwatch will click start. That will send a rest request

  • up to our server running in app engine. That will send a message to GCM. Beeping is going

  • on. GCM will send a tickle down to another Android application, and then that will do

  • a rest request back up to app engine and get the actual state. So let's flip over to the

  • demo and see that, which is here. So what I have is the Android Studio, and

  • I have the exact project that we've been using, the stopwatch app. And I thought I'd start

  • exactly where Tor left off in the keynote today.

  • Tor did a great job in the keynote, didn't he? It was pretty good?

  • [ Applause ] >>Brad Abrams: So let's start where he left

  • off. We'll come in and say generate back end. So what this is going to do is -- those values

  • you can fill in later. What this is going to do is generate for us a project, a server

  • project that you can easily go deploy to app engine that already knows about this client

  • side code. So if we look in this server project, there's

  • a few pieces of code here, and you see we have a couple of end points. We have a device

  • end point and a messaging end point. The device end point encapsulates all the plumbing needed

  • to do GCM. Google Cloud Messaging. How about of you have actually done GCM before?

  • And there was probability some drudgery in getting that to work especially on the server.

  • So we've taken care of all of that for you and that's encapsulated in there.

  • What we want to do now is add our own custom end point that's going to be exposed as a

  • custom interface. So in order to do that, I'm just going to

  • copy in a stopwatch state class, and this is a POJO. This is a plain old Java object.

  • I've marked it up a little bit, but all it's storing really is three bits of information:

  • the device ID, the time stamp, and then whether or not we're running or not.

  • So we've got this -- and you can see it's just got basic accessories on it.

  • Now what we want to do is take this and we want to generate a rest interface based on

  • that POJO. So what we're going to do is just generate

  • a cloud end point for that. And if we flip over into this end point, you can see we've

  • already got the code for listing all the entities for doing -- that includes paging, by the

  • way, in case you have a lot of these. You can get the stopwatch state, you can insert

  • the stopwatch state and whatnot. So all of that is already done for you. It

  • stores the data in app engines. No SQL data store.

  • But now what we want to do is go and add a little bit more logic into here, so I'm just

  • going grab import, and I'm going to do some of the GCM code.

  • So what we want to do is when there's an insert -- so we'll come down here to insert. Right

  • now when we're inserting, we're just storing the data in data store. But what we need to

  • do in addition to that is send a tickle out over GCM.

  • So we have some utility code for doing that, that I'll put in here, and we'll post this

  • code later so you can take a look at it. And then we just need to add a little bit

  • of code to actually do the send. So right after the -- we persist it. What

  • we're going to do is get -- enumerate through all the devices that have registered.

  • Now, we may have a hundred people with a stopwatch application wanting to be updated in real

  • time. So we enumerate through all of those. We just check to see if the -- if the one

  • we've gotten to is the same one that sent the request, so we don't want to reset ourselves.

  • So we exclude that one, and then we just send that tickle.

  • And then to make this compile, I need to -- throws I/O exception. And it's nice to decorate that

  • because actually we're going to propagate even exceptions and errors all the way down

  • to the Android app, as you'll see in a little bit.

  • So we basically got the server side of our application done, and you can see it's done

  • in the same IDE, in the same language, very easy, seamless to move between that.

  • Now what we can do is come in and upload this application to app engine. Go ahead and deploy

  • it directly from the IDE. In the interest of time, I've already deployed that for us

  • a little bit this morning. So let me bring that up.

  • What you'll get by default with this project is a simple test page. It shows you all the

  • devices that have registered. In this case, nobody has registered yet. And then it will

  • let me send a message. But to explore those end points, if you go

  • to underscore ah/api/explore, you can actually explore all the interfaces we just defined.

  • So you can see there's the rest interface for C2DM and here's the stopwatch one we just

  • added. I can come and interact with this. I can test authentication. You see the rest

  • responses and whatnot I get out of here. So this is a good way to make sure your server

  • side logic is working exactly the way you expect before you start moving to the client.

  • Okay. So back in the client, what we need to do now, we have our rest interface. We

  • need to be able to call from the client. So in order to do that I'm going to come back

  • in here and I'm going to generate a client library. And what this is going to do is take

  • the same discovery document that we -- that powers that API explorer and use that to generate

  • strongly tied to Java code that's Android optimized, mobile aware code, and stick that

  • in our client project for us. So to make it very seamless for us to access

  • this server code. So now you see it created this new folder.

  • We're back in the client side of the app. It created in new folder with these three

  • end points. On it. Now let's take a look at how we go and call

  • that. So I've just made a few modifications to the code to be able to call the end point

  • we defined, and we'll go ahead and overwrite those.

  • And the main thing that we just did, we added some helper class, but the main thing we did

  • is make sure all the network operations happen on a background thread. So either by spinning

  • up a thread or, in our case, we're using an async worker so that ensures as I'm doing

  • that network traffic, the UI is not hanging and freezing and whatnot.

  • So that's that basic code. Now, the last bit is I just need to come in

  • and wire it up. So when I hit start and stop, the actual methods get called.

  • So I've already got a handy dandy added to my method this send state with end point,

  • and you can see it's grabbing the current time. So I'm actually going to take the current

  • time. I'm going to send whether or not this is running and then my ID. And this is going

  • to send it up. And notice I call that in this method startstop.

  • So whenever I hit start or stop I do a rest request up to the server.

  • So I think we've got it basically working. You guys want to see this thing running live?

  • Okay. So let's go. I think I hit this. Okay. So I've got two phones here. Whoop.

  • That one can't go yet. So the first thing I want to show you -- are

  • we seeing it? Yeah. The first thing I want to show you is when

  • I launch this app, by default the project that comes with Android Studio, it will give

  • you this registration screen. This is your indication that the GCM registration was successful.

  • You're able to contact your app engine back-end and it was able to register this device ID

  • with GCM. Obviously when you go to deploy this app,

  • you can remove this screen. So we've registered. Hopefully they're both

  • up. Let's reset and start this one. Okay. Notice when I started this one, the

  • other one stopped -- started, and when I because this one, this one pauses at exactly the same

  • time. Pretty cool, huh?

  • [ Applause ] >>> So let me just switch back here.

  • And one more slide to leave you with. We're very excited on the cloud team to support

  • Android Studio. As Xav mentioned, we've done the work to make sure you can do builds of

  • even the server side stuff outside of Android Studio, so you can do it in your build tool

  • of choice. And you can find more information about the cloud at that URL. And I'm giving

  • a little bit longer version of the talk later at this place. So love to see you there.

  • Thanks. [ Applause ]

  • >>Xavier Ducrohet: Thank you, Brad. So, you know, it's an Android idea. We're

  • going to add a lot more features, including features like the cloud stuff. That's not

  • where I wanted to go. So we're still (inaudible) Eclipse and I want

  • to show you a feature that's new in Eclipse that about bring to ID.

  • You saw during the keynote we translation on the play console, and I want to show you

  • that now. So here -- so this is my account, you know,

  • and I have an app. It's called sample app. And I can create a new translation.

  • So I already have some French translation that are ready to go but I'm going to create

  • a new version. I'll call that test. My original translation is in English. Continue.

  • All right. And here I can use the plug-in. If you have a complex project, you're going

  • to have a lot of strings and you probably don't want to go them and upload them manually

  • so generally in the plug-in you can say use plug-in and then you're told what to do, which

  • is useful. And then you can to Eclipse where we have

  • this new plug-in. It's not part of the bundle, the bundle that we have with ADT and Eclipse.

  • It's available. If you go to developer.android.com you have the instruction right next to the

  • ADT instruction to install it. And from here you can very easily -- I think

  • from here translation manager, you can just do request translation.

  • So I already -- there you go. So I already logged in with my same account,

  • and it discovered that I had my, you know, test project that is waiting in my browser.

  • And so I can just click next, and then it knows all the strings that I have so you can

  • go and look and make sure those are the strings that you want and then you just upload them.

  • In that case here, just a single string, but if you had a lot of string file, it would

  • just upload all of them, which is really convenient. And when you finish, you go back into the

  • console here, you click continue, and then you say, well, I want to translate them in

  • German, for instance. You click okay. And then you choose your translation. And

  • then you choose some translator. And then you click confirm, and then you get, you know,

  • a week later, your translation. And then of course we want same thing; right?

  • Because the format you get back from the translator may not be exactly the format that we want.

  • So here we go and easily click download, and here I have some translations here that are

  • ready, and so I click next. There they are. I click download, and on the left here on

  • the values, I have my -- you show here which string you just got. And you got your string

  • translated directly. So the whole work flow is directly integrated

  • into the IDE. We'll have (indiscernible) Studio, of course. It's available now. I think you

  • have to go and sign up for the pilot to be able to do that.

  • All right. And this is, you know, the end. We have a couple of -- well -- no.

  • So we are taking questions. You know, so feedback again. (Indiscernible). We have a mailing

  • list, (indiscernible) @Google groups, and then we'd love feedback on Android Studio.

  • All right. [ Applause ]

  • >>> The translation is a nice feature. A question is what if you translated it once and then

  • you added a couple strings or changed a couple? Does is it know to just ask for translating

  • what changed? >>Xavier Ducrohet: I think it deals with that.

  • There is a talk on Friday at 12:00 p.m. that will talk a lot more about that, and you should

  • go and check it out. They will probably have the answer. But I think the (indiscernible)

  • already been translated and they only translate the new things.

  • >>> I'm looking forward to your weekly updates. I want to get a clarification on the direction

  • between Eclipse and the Studio and kind of validate where we're going with the two IDs.

  • >>Tor Norbye: We suspected that question would come up.

  • >>Xavier Ducrohet: Yes, we are going to keep supporting Eclipse. You know, that's something

  • that we won't be able to do in Eclipse because it has, you know, the language framework is

  • not as good, or as extensible. So it's harder for us to plug into it.

  • But we are going to keep supporting Eclipse. Right now we're focusing a lot on studio because

  • we have to bring a lot of the features from ADT into studio but we're going to keep supporting

  • both. At some point we're going to integrate Gradle directly inside ADT also so you have

  • a single build and (indiscernible) to be able to build with that.

  • >>> One of the things -- First of all, thank you for using IntelliJ. It's a great IDE.

  • >>Xavier Ducrohet: Yes. >>> One of the things that I missed from Eclipse

  • is merge manifest. Do you know when that's going to be available for --

  • >>Tor Norbye: It's a feature of the new build system.

  • >>Xavier Ducrohet: Yes, the new build system merged the manifest so you don't have to do

  • anything. We still support the old builder in IntelliJ in case you have an older IntelliJ

  • project that you are using so you can open it and use it, but the default behavior is

  • to use the new build system, and the new build system deals with merging the manifest.

  • >>> Is that available now? I already use IntelliJ. >>Xavier Ducrohet: Yes, it is available now.

  • >>> So just on -- >>Xavier Ducrohet: Yeah, if you get Studio,

  • you'll have automatically create a new project and you'll see the new build system and it

  • does manifest merging. >>Tor Norbye: In the new -- in Android Studio,

  • you can't create -- in the Android Studio version, not with plug-in in IntelliJ, you

  • can't create old style. You can only create Gradle-based projects because we're really

  • trying to get that part working beautifully. >>> Translation question. My apps are all

  • translated by volunteer users. I'd love to see crowd sourcing in your framework. Anything

  • on that? >>Xavier Ducrohet: Again, session at 12:00

  • on Friday, the people who deal with that will give you a big LMO and they can answer that

  • question. >>> Thanks for the switch to IntelliJ.

  • >>Tor Norbye: Last question. >>> That's really appreciated. I'll have to

  • get used to Gradle, I guess, because I'm using Maven to do all the builds.

  • I have a question about compiling with multiple APK loops. You mentioned action by Sherlock

  • before. That's commonly used and it is not uncommon to use it with Holo Everywhere and

  • Holo Everywhere Preference. Maybe with your own APK lib as well.

  • So in some of my projects, I'm building with four APK loops all at once. At the moment

  • that takes a long time because you have to run ADTs through all of them.

  • Where are you progressing on that? >>Xavier Ducrohet: So we have better support

  • for that. I think it's a lot dependent on text merging to be able to help with that,

  • but we have a new feature to merge resources that's more incremental, so that will be faster.

  • (Indiscernible), we're improving that a lot. It may not be just there yet, but we're improving

  • it a lot. Also, one thing is because of Gradle, you won't necessarily need to have all those

  • projects open in Eclipse before you have to. You have (indiscernible) open, so here you

  • can just focus on one module, and that makes things faster anyway.

  • >>Tor Norbye: So we're unfortunately out of time, but we're going to be out there.

  • >>Xavier Ducrohet: So we're going to be at the office hours and we'll be there as long

  • as people have questions. So, you know, just come and talk to us.

  • >>Tor Norbye: And that's right now. We're going there right now. All right. Thank you.

  • >>Xavier Ducrohet: Thank you very much. [ Applause ]

>>Xavier Ducrohet: Hello, everyone. Welcome to I/O and welcome our session on What's New

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

谷歌I/O 2013--Android開發者工具有哪些新功能? (Google I/O 2013 - What's New in Android Developer Tools)

  • 93 12
    winiex 發佈於 2021 年 01 月 14 日
影片單字