Open entire module file tree in Android Studio - android

Not sure if this is possible, but I have many multi module projects. Each module essentially follows module/src/main/java/packages... This is shown in photo below
Currently I have to click src -> main -> java -> etc....
Ideally I would like to just click src and have the whole directory open up. This would save me a good amount of time in the long run. I have searched for an Android Studio setting that does this but no luck. Would I have to write some kind of script for this? I'm lost on how to achieve this
Thanks

You can use the key * on the numeric keypad, it will automatically expand the tree. This setting can be configured with a different key by searching:
Fully Expand Tree Node

I don't think exactly what you're looking for exists (to my knowledge, and I've been using Android Studio since its beta).
I think the closest thing you're looking for are these two things: 'Compact Middle Packages' and/or setting your project view to 'Android' (see screenshots below).
I hope this helps, if not, you could create a feature request to the Android Studio team.

Set your project view to 'Android' and select 'Flatten Packages' as shown in image.
When you expand java it will show list of all packages (check below image).

Related

Android Studio changing ID's in one xml file changes the ID's in another file

I used to give simple ids to Android Views, but lately, I stopped that altogether because of this issue.
Let's say I have 2 layouts, one named first_layout.xml and second named second_layout.xml. In each of these layouts, there is a view with id username_input. This id is used in different activity classes to access target view, be it ButterKnife binding, Kotlin Android Extensions, or even findViewById.
Now, for whatever reason, I need to rename id in just one layout. Thus I do Refactor -> Rename. What happens? Android Studio simply replaces id username_input in the whole project, messing other layouts that had view the same id. Most people don't use a unique id for each and every view in the project since it's not mandatory, but I do because I do lots of refactoring, and many times I lost hours because of this non-contextual replacement in the project.
What are my options in this case? Is there a way to make Android Studio do the contextual replacement in such a situation, or should I keep making unique ids in my project?
Moments ago I was facing this same issue and I found it to be the Android Studio's expected behavior, as other elements might be constrained to the element whose ID is getting changed. So you need to update all the IDs particularly in your new layout file through its text editor AND NOT from the Attribute section of its design editor
Its working fine for me, and so must work well for you too :)
I too faced same issue, when i copied widget from an one activity to another activity and tried to change ID in copied widget. It prompt a dialog box and i clicked "No (Local Only)". But, i feel no use of that option. it still updated ID in old activity too.
Workaround:
Try to change ID or Attributes through Code(Text Editor) not from Design.
I feel google should address this issue and remove this bug.
Right click on the id you want to rename the go to:
Refactor -> Rename
Now you will see an option "Scope" and under Scope you need to select "Current File" in order to rename the id in that file only.
(Not sure if it was there when this question was asked!)
I just came across this post because I was having a similar problem. I have an app with different flavors. In one of my layouts I have 12 buttons. In a different flavor, I want all of those buttons plus I add 4 more. So, I created a new version of the layout in a flavor-specific directory. The problem is every time I tried to change anything that has an ID it would change the identically-named layout in the main directory.
With flavors, you're supposed to be able to override the main directory's layout with a flavor specific one. This was extremely frustrating!
This MUST be a bug in Android Studio. The frustrating part is that it's still not fixed. I installed Android Studio via the JetBrains toolbox since I use other JetBrains IDEs. Currently I'm on version 3.5.3
My workaround
To get around this bug I created a "test" project. I copied the layout code that I wanted to modify, pasted it in the test project and edited it there. When I was done altering it the way I wanted, I created the alternative layout in the flavor specific directory (using the same name as the main directory's layout that I want to override) of the actual project I was working on. Then I copied the layout from my test project and pasted it into the flavor specific file. By doing this, it didn't alter the layout in the project's main directory.
My thoughts
You shouldn't have to do this. It's certainly not the intuitive way. This is why I can't believe that this is anything but a bug. With that said, I hope I have provided a clear workaround for anyone else who's stuck. If I haven't comment below and I will clarify what I can.

Android Studio: how to show author of just selected line

I noticed a pretty feature in Visual Studio Code (don't know if it's due to the GitLens extension): when I'm editing a line I can see the GIT annotation of that line including author, time of last edit and commit message.
This is quite cool, since it does not take a big amount of space as the "annotations" pane that you can enable in Android Studio. It's fast, easy, straightforward.
My question is: is there any Android Studio extension, as far as you know, allowing a similar visualization?
Thank you
Marco
I managed to get the same in Android studio by using a plugin called GitToolBox
You can right click besides line number (Left side strip where we put breakpoints) in Android studio code and check annotate option.
OR
You can right click in code file, then select Git option and then select annotate option.
SOLUTION
You can try this by right clicking on a place where to add debug break point
Chill Pill:)

Can I use Android Studio's 'Find Useage' for Android SDK Source Code?

One of the most useful functions in AS is right-click and 'Find Useage' or 'See Declaration'. For my code, the 'Find Useage' will show all instances of where a function/object is used.
I have the SDK source code in AS too, but I can't 'Find Useage' on that code. Is there a way to set up my projects so that I can use 'Find Useage' on Android SDK code? For example, I would like to go to android/platform /frameworks/.../Configuration.java, right click on Configuration, and see where that class is being used elsewhere.
Failing that, is there a way to find useages short of grepping around the massive SDK project?
Yes, that is possible. You can configure the scope of the search function.
Move the cursor on the symbol you want to analyse, press Ctrl+Shift+a (search for action) and search for Find Usage Setting or from the menu select Edit -> Find -> Find Usage Setting and select Project and Libraries in the scope section.
If the menu item is grayed out, it's because no symbol has been selected.
Furthermore, if you are looking for a particular feature in AS the search for action function is a huge time saver.
BTW: If Project and Libraries is not available it's because there is no usage of the selected symbol in any library.
May be you are looking for this:
Edit->Find->Find in path...
If you are using Android Platforms Codebase directly from the repo, then you can do it. In this case, you will have to update your dependencies by creating another gradle project in your studio where the platform codebase is and then import that in your project.

Can't see errors/warnings in Problems view unless project is selected in Package Explorer

I can not see any errors or warnings in my Eclipse(4.4.2) unless I specifically select the project or file in Package Explorer and then go to the Problem view.
So far I tried different options in "configure contents" and "show" dialogs in the Problems view menu without success. The only time I see errors in the Problems view is if I set the options "show all" or "all errors" and then it shows every issue with every project I have, don't want/need that.
I also tried (following suggestions from other posts) closing/reopening project, Build Automatically and fix project properties... no luck.
I remember it used to be that if you had issues in a file you were currently editing you could jump straight to the Problems view and it would show you the issues for the project where that file lives, in other words the current project being edited. This is the result I want.
Android SDK manager is up to date so I am out of ideas. Appreciate any help.
Open the 'Configure Contents' menu and select the 'All Errors' (click the line don't use click the check box). You should then be able to configure the Scope of the errors on the right hand side of the dialog (such as any element in same project)

Need explanation on Project Tree Android Studio

I may be missing something here but, how come my android project tree used to look like that when I created my first project 5 months ago (with folders like .idea, build, or R.java)
And now, I've just created a new projet and it looks like that :
Did I make a mistake at some point ? How can I display all the folders and files like R.java ?
Thank you.
If you look at the files outside of Android Studio, you should find that the structure is nearly identical.
What you are seeing is the new Android project view. Note that at the very top of your screenshots the first one says "project" and the second one says "Android."
The Android project view simplifies the way the information is present a bit- for example, it will put all your Gradle scripts together and it will combine drawables with the same name to make finding different versions of the same drawable a bit easier.
If you don't like the new view, you can click on "Android" to see a dropdown containing other options, including the old Project view.
Sorry, silly mistake : the view was different.

Categories

Resources