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
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.
Right now I am in the process of creating a custom date picker on screen in a test app, but I wish to use it in multiple activities in my app, and it is complex enough that I just don't want to copy and past the code. I was wondering whether there is a way to nicely package it so I can reuse it easily.
Thanks for any help and info!
Create whatever widget u intend to in a separate layout resource say "my_widget. xml"
And then use it another activity's xml (say activity_1.xml) by calling your widget in it, using
<include layout=#layout/my_widget />
Create a custom view (aka widget) following this "Guide" implementing all your customizations you currently have to the view in your activity (as I understood) and then you can reuse your widget anywhere in this application or even on other applications (this is if you export this view into separate lib, and is subject for another discussion)
Just start developing with android and think instead of reading a book a webinar could be better because a webinar could also teach me short ways and how an android developer thinks when writing the code but now got a problem
<CheckedTextView
android:id="#android:id/text1"
android:checkMark="?android:attr/listChoiseIndicatorMultiple"
</>
I dont understand the above code up to now see lots of different id definitions some of them was for resources and start with #resource/name, and some of those id definitions was like #+id/name just for creating a new id for the component but this time it is using android:id/text1 and I dont understand why it is using it in that manner
Besides, the checkMark thing make me confuse more what are all those ?android:attr/listChoiseIndicatorMultiple means?
Could you please explain me and show me some resource where can I find all those magic attributes so I can cope next time by myself and hope someday can answer other newbie questions
Thanks a lot in advance, and all comment will be appreciated.
Well, reading the docs has always been helpful to me:
Android Developer Site
XML Layout specific docs
#android:id/text1 is just a format used when the id has been previously defined. When you put a + in there that means the framework should create the resource id if it doesn't already exist.
It's normal to use #+id/thisid when defining a new view in a layout, and then use #id/thisid to reference the aforementioned view from another part of the layout (say, in a RelativeLayout where you need to tell one widget to be below another).
A question mark before the ID indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute.
#android:id/text1 basically this is used when you create any android component like button, layout, textviews etc.
but when you need any external component which is general for different platform like any color, image etc then you can declare it as #resource/name.
actually there is nothing different just keep one thing in mind that in #android:id/text1, id will simply work as an class name will contains other objects like textview, imageview or any other.
now if you declare #resource/name then in that also instead of id class name will be resource. actually when you will use it in java then these(#android:id/text1) will be converted into object hierarchy.
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.
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.