What I'm trying to do is have a clock widget of different sizes (i.e. 2x2, 3x3, 4x4 etc) in one apk and a configuration activity to be able to select which size to add.
From what i've learned from documentation:
Widget size is specified in <appwidget-provider> tag in respective xml file
Also in that file I set up the configuration activity for that provider
So it seems that size is a property of AppWidgetProvider and I'll need to somehow create another provider from the code in configuration Activity of the first one...
Or am I getting this wrong and there's another way?
Is this possible at all? :)
I've been told that some widgets can do this :)
Thanks in advance!
P.S. I have read this and this. First one explains how to put multiple wigets in one apk, but it's not clear how to select between them in runtime. Second one is about changing layouts, but not size...
Do you really have to do this at runtime? It is possible to define several widgets in one .apk.
Maybe you can have a look on transdroid source? They are including two sizes of a widget in the same package.
AndroidManifest.xml used by Transdroid
I hope I have read your question right and think I have your answer. I could rewrite this information or just point you to it (as I would more than likely not be able to do it justice).
http://developer.android.com/guide/topics/appwidgets/index.html#Manifest
Look under "Creating an App Widget Configuration Activity". The example is good as well.
By doing it this way you may not be able to set a certain layout sizes without a lot of editing but will allow for customization by the user (which is what you want correct?)
I have the same problem and was hoping to find a way to add only a single entry to the Widget list, and have the configuration activity decide the size, but I realize this is not possible.
When thinking about it, it's only fair: if the program would have the right to set the widget's size at runtime, one would maliciously increase the widget once added to the launcher, and occupy more real estate than it was authorized to.
So as mentioned above, the solution is to add multiple widget providers and let the user choose the size she wants. You can even use the same configuration Activity if the options are not related to style but only colors, or refresh periodicity.
Related
I have to make a new design for an Android App, but I only have to create the visual part (native Android). The app logic would be created by another guy based on what I present to him.
My question is? How would this be managed correctly? Do I have to make the XML's of each layout? How could I show the other person my progress?
What things should I consider when doing this?
Thanks
You need to mock the app first (create a prototype) as suggested by NoChinDeluxe. Then if you guys go ahead and decide to code it, the answer to your problem is separation of responsibilities. As Jeffrey said UI work is not only about layouts, but code as well. What I would suggest is that you and the other guy get together first and define some contracts (interfaces) that will allow you guys to split the work and work in parallel. Therefore, he can create the business logic of the app without worrying about the UI implementation. You, on the other hand, will have to mock that business logic he's implementing at the beginning so it doesn't block your UI work.
you could create layout XML files for all the Activities/screens, using resources (icons, etc as suggested by #NoChinDeluxe). However since you'd want to run the mock app, you might want to also create a "throw-away" Activity that allows you navigate to different screens of the app. Here you can add a number of buttons and when you click on each button, your app shows a specific activity. This way, you will be able to show your colleague all the screens you have created. I hope this helps.
This may not be what you want to hear, but creating Android layouts isn't a design task. They are closely tied to the code, and the design of them is going to depend on how the engineer chooses to implement the app.
Here's an example. You might have a grid with 4 cells. You could use a RelativeLayout, a LinearLayout, or GridLayout, or a GridViewLayout. Which will use choose?
I'd suggest providing your engineer with mockups and graphical assets where required. Let him / her take those and create the layouts. If you want to create layouts as a (visual-only) reference for engineering, great, but it's certainly a non-optimal tool for that task.
Things You will consider when doing visual part:-
You have to work on the resource folder of your application
Layout : All Layout you have to prepare.
Drawable : Images and drawable .xml.
Inside Values folder you will find
dimen.xml : For different devices dimen you can set.
string.xml : You can store string for hint or other purpose.
style.xml : For designing or theme or custom design.
color.xml : Color which are going to used in the application.
I want the same application to be delivered 2 different set of layouts. Ie the functionality is same but the graphics will be different for two different versions of the app. So i want to keep the same code and based of some variables want to decide which layout to be set for each activity. SO for each activity i will define two different layout.
This is my requirement. What is the best way to implement this. I can have an if else in each activity and define which layout to be set. Is that the right and best way. Please give your options on this
Take a look at this answer. It's about accessing a resource file from identifier, ie file name. You can do this with any type of resource (I think).
How to use getResource.getIdentifier() to get Layout?
Basically, you can do an if-else statement and assign the id of the layout you wish to use to a variable then load the layout using the identifier.
Actually there are many ways for ex you can change your layout based upon the orientation i.e landscape or portrait or you can change your layouts using languages for ex- you can create various folders for different languages.
Please explain your requirement briefly and if possible post some code also.
You can follow below links also.
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screendensities.html
Language Specific layout for android
http://www.c-sharpcorner.com/UploadFile/0e8478/supporting-different-languages-layouts-in-an-android-appli/
I don't know whether i am asking the right question or a wrong one.
it may sound foolish but still i feel to clear my basic doubts.
the question is:
i have three different layout files for a single activity.
depending upon the purpose for which the activity is started, it will take one of these layout files as its content.
these layouts have various fields in common.
i have a question that in these different layout files can i have the same "id's" for the common fields.
for ex: i have a save button for all the three layouts.
in all those three layout files..... can i have (For the button)
android:id="#+id/save_button"
the same ID attribute in all the three files.
i require this because i have too many elements(components) in my layout files.
if they can be identified with common names (as they serve the same purpose in their respective layouts) there would be very less names/ids to remember, which will make my program easy to be readable and less things for me to remember.
else i will have to write the same code for components with same functionality.
thankyou in advance.
your answers will help me clear my doubts. please correct me if i am moving with wrong concepts.
Not only is this allowed, but I would encourage it. Using the same id across files allows you to create new layout files without having to change any of the code referencing the button. As long as the id is descriptive of what it relates to, then it shouldn't cause any problems.
I was searching in internet but nothing helps. I want to make second widget, just bigger. Im using service to update my widget so I need to create 2 services (update data in widget by remoteviews etc.) or can I make it easier?
When I add medium widget, it shows up te small one but it takes more space (144dp x 72dp) and there is no update. Maybe I should copy whole app classes and modify it, but I think this is stupid solution.
I was trying this solutions
how to add multiple widgets in one app?
How to put multiple widget sizes in one apk?
Any hints? :)
I had the same need with my widget. Precisely those two links you have posted helped me find the solution, which came at last with a bit more of research.
In order to have a second size for your widget:
Define another receiver in your manifest, with a diferent name. This is important: if you don't use a different name, only one will show in the list of available widgets. For example: android:name=".MyWidget_Small" and android:name=".MyWidget_Medium". Also modify the labels accordingly
The additional receiver needs a new appwidget provider in res/xml. In android:resource of the meta-data tag type the name of another XML file. You'll have then android:resource="#xml/MyWidgetProvider_Small" and android:resource="#xml/MyWidgetProvider_Medium"
Each XML file in res/xml must point to a separate layout. You will have android:initialLayout="#layout/MyWidget_Small" and android:initialLayout="#layout/MyWidget_Medium"
Now the Java part. Each appwidget provider need its correspondent Java class that extends AppWidgetProvider, so you will need two additional classes. If your original class was MyWidget.java, you'll add MyWidgetSmall.java and MyWidgetMedium.java. You'll probably end up subclassing your original Java class, and perhaps modifing each new class if the widget has a distinct behavior in each size. Remember to name the two classes as you did in step 1 in the receivers's android:name
Your service doesn't need duplication. However you should examine your source code to find occurrences of explicit references to MyWidget.class. If you did this, you must reference the actual subclass
Hope this helps
I'm making a new application and its basically filled with information about Warcraft.
I have similar apps on my phone that have similar information and when I looked inside their .apk they only had like 10 layouts.
The app that I am making already has 5 layouts and it seems like I will need about 50-60 layouts.
So now my question is it normal to have that many layouts? Or do I have to learn to make one general layout and keep reusing it? For example, like if I need to display information about a topic for instance the classes in warcraft which are 10 different classes with 2-3 different guide pages on average for each class, would I need to make a different layout for each page or is their a better way of doing it?
I would really appreciate any input/suggestions.
What I recommend is having one layout for every type of screen (basically one per Activity) and use Java to fill in all of the info. Use getResources().getString(int id) and pass something from R.string. That means you need to keep all of your information in a strings.xml file in your values folder (located in /res/values). List all of your views in the layout XML file and then find them by ID and set their values.
It's best to keep all of your string resources in a separate XML file and not hard code them into the layout (otherwise it's a pain to replace every instance of a word you realized you misspelled or something). If you don't know how to write XML, that's okay since there are tools in Eclipse, but I HIGHLY recommend learning it.
You can re-use layouts without any problems. In fact for maintaining the code it is a very good idea to do so. No one wants to maintain 50+ layouts and associated code.