Drawable Help.. - Java for Android App Development

Hey all -
I'm getting into an area I hadn't gone before - drawable XML files, and am stumped, since what I think should work is giving me an exception.
Some background -
I have multiple images, used as a background. Then there are a couple other images used for foreground symbols. (These are for markers on a map.) So, for example, I have 5 different colors, and 5 symbols. Instead of creating 30 different markers (5 symbols + blank) I figured I could include the resources, and then use a list-layer to show the symbol on top of the marker. Would save some room when the APK's created.
So, I made a simple test, like this. XML file is simply named "marker":
Code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="34dp"
android:drawable="@drawable/marker_green_blank"
android:left="0dp"
android:right="20dp"
android:top="0dp"/>
<item
android:bottom="20dp"
android:drawable="@drawable/marker_symbol_int"
android:left="3dp"
android:right="19dp"
android:top="4dp"/>
</layer-list>
Oddly, when I go to use this, I get an exception when it's tried to be used:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
Any thoughts? I obviously missed something - probably something idiotic, since I do that a lot.
Or, is there another way to combine two images/res's together?
--Mike
Edit:
I forgot to add - this is how I'm creating the 'icon' to add it to the map. The second line is map-specific code and may not really apply here. I'm starting to think that the first line - BitmapDescriptor - is causing the issue:
Code:
BitmapDescriptor marker_red_blank = BitmapDescriptorFactory
.fromResource(R.drawable.marker);
<!-- Code that sets other options using a MarkerOptions object ... -->
opt.icon(marker_red_blank);
mark.associatedMapMarker = MapViewFragment.this.mMap.addMarker(opt);

coyttl said:
Hey all -
I'm getting into an area I hadn't gone before - drawable XML files, and am stumped, since what I think should work is giving me an exception.
Some background -
I have multiple images, used as a background. Then there are a couple other images used for foreground symbols. (These are for markers on a map.) So, for example, I have 5 different colors, and 5 symbols. Instead of creating 30 different markers (5 symbols + blank) I figured I could include the resources, and then use a list-layer to show the symbol on top of the marker. Would save some room when the APK's created.
So, I made a simple test, like this. XML file is simply named "marker":
Code:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="34dp"
android:drawable="@drawable/marker_green_blank"
android:left="0dp"
android:right="20dp"
android:top="0dp"/>
<item
android:bottom="20dp"
android:drawable="@drawable/marker_symbol_int"
android:left="3dp"
android:right="19dp"
android:top="4dp"/>
</layer-list>
Oddly, when I go to use this, I get an exception when it's tried to be used:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
Any thoughts? I obviously missed something - probably something idiotic, since I do that a lot.
Or, is there another way to combine two images/res's together?
--Mike
Edit:
I forgot to add - this is how I'm creating the 'icon' to add it to the map. The second line is map-specific code and may not really apply here. I'm starting to think that the first line - BitmapDescriptor - is causing the issue:
Code:
BitmapDescriptor marker_red_blank = BitmapDescriptorFactory
.fromResource(R.drawable.marker);
<!-- Code that sets other options using a MarkerOptions object ... -->
opt.icon(marker_red_blank);
mark.associatedMapMarker = MapViewFragment.this.mMap.addMarker(opt);
Click to expand...
Click to collapse
Although I haven't used BitmapDescriptors, I do use layer-list a fair bit to overlay shapes, backgrounds etc.
Looking at the documentation for fromResource...
'Creates a BitmapDescriptor using the resource id of an image.'
It seems that you're not passing it an image, you're passing it a drawable (layer-list in this case).

PicomatStudios said:
Although I haven't used BitmapDescriptors, I do use layer-list a fair bit to overlay shapes, backgrounds etc.
Looking at the documentation for fromResource...
'Creates a BitmapDescriptor using the resource id of an image.'
It seems that you're not passing it an image, you're passing it a drawable (layer-list in this case).
Click to expand...
Click to collapse
Thanks, I'll look into that. I had thought I tried to create a bitmap out of it, but it still gave the error - but since my memory is flaky, I'll do it and see what I get.
Cheers-
Mike

Drawable Button XML resource selector
This technique could be used for animation of XML drawables.
Keep separate drawables in your res/layout folders as usual.
switchable_drawables.xml ( put this in res/layout too)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Button Focused-->
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/active_button"
/>
<!-- Button Focused Pressed-->
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/active_button"
/>
<!-- Button Pressed-->
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/active_button"
/>
<!-- Button Default Image-->
<item android:drawable="@drawable/inactive_button"/>
</selector>
coyttl said:
Thanks, I'll look into that. I had thought I tried to create a bitmap out of it, but it still gave the error - but since my memory is flaky, I'll do it and see what I get.
Cheers-
Mike
Click to expand...
Click to collapse

Hey guys -
Thanks for the info. Unfortunately, same error. The code now looks like:
Code:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferQualityOverSpeed = true;
opts.outHeight = 34;
opts.outWidth = 20;
Bitmap icon = BitmapFactory.decodeResource(MapViewFragment.this.getResources(),
R.drawable.marker, opts);
BitmapDescriptor marker_green_blank = BitmapDescriptorFactory.fromBitmap(icon);
Creating options to generate the bitmap, setting desired height and width, and then using the decodeRecource function, creating a Bitmap, then using the .fromBitmap to turn it into a Descriptor. When the GMaps tries to access it, same null error. I may post this over on StackOverflow, since looking at the docuemtation and other examples, this should work.

Related

ThrottleLauncher Skining tutorial

Hi!!!
Here you have a little tutorial on how to create Themes for throttlelauncher. I still have to work on it but almost all is here. With this, theorically you can create almost any interface (still there's some work to do to achieve this ).
Any help, sugestions or requests are appreciated.
To read this tutorial is recomended to know XML file format.
First of all the file structure of a setup for throttlelauncher must be this.
- throttlelauncher instalation
|- Setups
|- MyTheme
|- Skins
|- Skin1
|- skin.xml
|- ...pictures of the skin​ |- Skin2
|- skin.xml
|- ...pictures of the skin​ |- Skin3​ |- config.xml
|- ....imported xml files
|- icons
|- ....my icons... any dir estructure​can be placed inside
To configure the app there are several tags. All the xml must be inside the root tag.
configuration: this tag contains the configuration parameters for the app (especified by the tag param). The allowed params names are:
- appear: Boolean value. Defines if the animation from down to top when the app got focus is activated (only valid for the standalon app).
- skin: defines the path of the folder of the skin to use. Relative to the app folder. See some post's below how to create the skin files.
- speeddecreaserate: factor that multiplies the value of your finger speed when starting kinetic scrolling.
- speedinitmultiply: factor that sets how fast the speed will be decreased in kinetic scrolling. IMPORTANT: set a value greatter than 1.
- status: two possible values. 0: normal (will show title bar and button bar of the app). 1: Maximized (will show the app fullscreen).
- osdenabled: It true, the OSD top bar will be shown when element is selected.
- imagecontactnophoto: Relative path to the image to be used it there's no contact photo.
- minclicktime: Min lapse time in miliseconds between the mouse down and up events to perform a click over the pressed element.
- .... there are some more... I will add them latter.
Example:
Code:
<configuration>
<param name="screenshot" value="True" />
<param name="appear" value="True" />
<param name="skin" value="Setups\Touchflo3D\skins\general" />
<param name="speeddecreaserate" value="1.2" />
<param name="speedinitmultiply" value="1.4" />
<param name="status" value="1" />
</configuration>
page: wich represent a page inside the app. Must be placed inside the root tag and the first one in the file is going to be the first one been showed by default. Page can have 2 attributes:
- name: contains the name of the page. This is going to be used when whe create a link to this page.
- loadonstartup: Boolean value, the default is "true". I recomend to set it to "false" in any page that be do not use frecuently to reduce memory usage.
- autounload: Indicates if the page will be unloaded automatically (and all it's resources will be freed).
- autounloadtime: time a unused page will remain loaded until autounload event starts. This param will be only used it autounload is true.
- import: will import the target xml as content of the page.
Example:
Code:
<page name="Home" loadonstartup="True" autounload="false">
row: Must be placed inside a page tag. They are specified in order from top to bottom. The following attributes are allowed:
- name
- marginX / marginY : margin bettwen the elements contained in the row.
- rows: number of rows of elements. If you set it up to -1 the number of rows is infinite.
- minheight: minimum height of the row (use recomended with dinamically sized rows due to contents like all contactswith photo or runningapps or recent)
- mincolwidth:
- scrollingmode: one of [Paged, WheelOfFortune, Direct, Kinetic, Auto, None]
- alignment: one of [left,right,center]
Example:
Code:
<row name="Programs" marginX="5" marginY="1" rows="3" scrolling="Paged">
footer: Must be placed inside the root tag. It parametters are exactly the same as the row. The footer is common for all the pages. Only one footer can be especified.
icon: Must be used inside the row tag or the footer tag. Used to display an icon. The allowed attributes are:
- name: Will be shown in the OSD when the icon is selected.
- path: path of the icon file. Recomended to use png. Can be absolute or relative to the app path. If the path is not specified, then the file on exec (if it's exe or lnk) will be used to obtain the icon image. No zooming efect will be applied in this case.
- exec: file to execute when the icon is clicked (deprecated, use event click instead).
- params: params for the file execution (deprecated, use event click instead).
- width: override the icons width.
- height: override the icons height.
- rowspan: indicates that the icon fills that number of rows intead of 1.
- showtext: will display the name of the icon as footer text.
Example:
Code:
<icon name="New Contact" exec="\windows\poutlook.exe" params="contacts -new" path="icons\contact.png" />
separator: must be especified inside a row or a footer. Allowed attributes are:
- name: if especified will show a vertical oriented text. If not especified the separator will show a vertical line.
Example:
Code:
<separator name="Personal" />
continues
text: Must be especified inside a row or a footer. Used to show text. Inherits all the atributes of the icon (so background icon can be displayed) plus:
- text: contains the text to be shown. The ~ symbol can be used for "new line", and two especial sentences:
* date: #$date,format#. Will be replaced by the date in the format especified. Will be updated automatically every second.
* reg: #$reg,key#. Will de replaced by the value of the desired key. Will be updated every second. When regkey is especified you can also use this format to parse date registry values: #$reg,key,date,dateformat
Example, start date for next apointment: #$reg,HKEY_CURRENT_USER\System\State\Appointments\Next\Start Time,date,MMM/dd/yyyy hh:mm#
- fonttype: font type specified by "fontname,size,bold" or "size,bold".
- fontcolor: RGB value.
- leftmargin: margin left of the text.
- topmargin: margin top of the text.
- spacing: interline spacing.
- textwidth: defines the width of the area filled by the text
- textheight: defines the height of area filled by the text
- textimages: defines a path where you can place images for each caracter on the text. Example: textimages="setups\Touchflo3d\icons\tf3d\numbers\#$char#.png" where #$char# will be replaced on the path for the character.
Example:
Code:
<text text="#$date,HH:mm:ss#~#$date,dd/MM/yy#~#$date,ddd#" fonttype="12,true" fontcolor="255,255,255" leftmargin="10" topmargin="10" spacing="-10" rowspan="3" width="100"/>
clock: must be inside a row or a footer. Inherits all the attributes of the icon. Can contain the following tags:
- hours
- minutes
- seconds
Each of those tags can contain a color attribute with the color in RGB for the line. If some of those tags is not especified, the respective line will not be shown.
Example:
Code:
<clock name="clock" path="clock.png" rowspan="3">
<hours color="0,0,100"/>
<minutes color="100,100,200"/>
<seconds color="160,160,255"/>
</clock>
allcontactswithphoto: must be inside a row or a footer. Will display all contact with photo matching the criteria in the attributes and assigned to the category "ThrottlePhotoDial".
- name: name of the tag element.
- categoryfilter: comma separated list of contact categories to be included on the filter.
- showcategories: If true will automatically show a separator for each category containing contacts.
- max: max number of contacts to display.
- width/height: define the diaplay size of the contact photos.
- All contacts with photo tag may contain two special icons with this two exec values: ":addcontact",":removecontact". This icons will open a contact selecting dialog allowing to choose a contact to asign or remove the "ThrottlePhotoDialer" category.
Example:
Code:
<allcontactswithphoto height="80" width="60" max="100" showcategories="True" name="Group unnamed">
<icon name="New Contact" exec=":addcontact" rowspan="1" height="80" width="80" path="setups\Default\icons\contact_add.png" />
<icon name="Remove Contact" exec=":removecontact" rowspan="1" height="80" width="80" path="setups\Default\icons\contact_del.png" />
</allcontactswithphoto>
lastapps: must be included inside a row or a footer. Will display the last 12 apps executed (same shown in the start menu). Can include the following attributes:
- name.
- zoom: will zoom the icons if different than 1.
Example:
Code:
<lastapps zoom="1" name="Group unnamed" />
runningapps: will display the running apps icons. The following attributes can be included:
- name.
- zoom: will zoom the icons if different than 1.
Inside you can especify the app's to exclude from the list by using the exclude tag as shown in the example.
Example:
Code:
<runningapps zoom="1" name="Group unnamed">
<exclude name="\Windows\shell32.exe" />
<exclude name="\Windows\cprog.exe" />
<exclude name="\Windows\repllog.exe" />
<exclude name="\Windows\gwes.exe" />
<exclude name="\Windows\filesys.exe" />
<exclude name="\Program Files\ThrottleLauncher\ThrottleLauncher.exe" />
</runningapps>
continued....
folder: this will add an icon for each file cotained in the specified folder matching the pattern if any.
- zoom: zoom to be aplied to the icons.
- path: path of the folder to load. If the folder path is on the registry, you may specify the registry path (sample: HKEY_LOCAL_MACHINE\Explorer\CrossPlatformNavigationURL).
- pattern: pattern to be used to filter the files.
- recursive: indicates wether to look into subfolders (any subfolder loaded will generate automatically a spearator named as the folder).
- name
plugin: this is used to include a today plugin inside the main app (not the today plugin).
- name: name of the plugin to be used. Importan the name MUST be the name of entry in HKEY_LOCAL_MACHINE\Software\Microsoft\Today\Items\. ONLY PLUGINS BASE ON DLL's WILL WORK.
examples:
Code:
<plugin name="ADBWeatherPlus"/>
<plugin name="rlToday"/>
<plugin name="HTC Home"/>
<plugin name="BatteryStatus"/>
-throttleplugin: with this tag you can include 3rd party plugins for throttle launcher. For example you can include flash using the following:
<throttleplugin name="Reloj" path="#$THROTTLE#\Plugins\Flash\FlashPlugin.dll" height="90" class="FlashPlugin.FlashThrottlePlugin">
<param name="movie" value="#$THROTTLE#/Setups/Touchflo3dFlash/TWolf/Clock/horas_28_LITE.swf"/>
<param name="width" value="240"/>
<param name="backgroundpath" value="#$THROTTLE#\Setups\Touchflo3dFlash\TWolf\Clock/fondoReloj.jpg"/>
</throttleplugin>
Skins
Skins are based on xml file as config.xml does. Skin xml file may only contain param tag placed inside the root tag. All the params are optional, so if you don't need one, don't especify it!!
All files refenced by the skin.xml need to be placed on the same skin folder.
Params tag format is the following:
Code:
<param name="name" value="value"/>
The allowed names and it's values meanings are:
- trasparency: will allow trasparency for the skin. This means that if the skin is applied to a row the row background will be filled with the main setup skin texture.
- pagebackcolor: backcolor to be used as page background (only used for main setup skin).
- rowbackcolor: backcolor to be used on the rows (this will be used as the trasparent color if trasparency is specified).
- texture: relative path to the texture image to be used as page background.
- rowtexture: relative path to the texture image to be used as rowbackground.
- buttonback: relative path to the back image to be used on all clickable elements.
- selectionimage: relative path to the hover image to be used when an element is selected.
- buttonbackmargin: margin to be used between the buttonback image and the main element image.
- fontstyle: font style for the text displayed for example in the separators or the contact names. Two formats can be used: "size, bold" or "size, bold, fonttype".
- linecolor: color to be used for lines. Must be specified in an RGB value.
- textcolor: color for text. RGB
- osdtextcolor: color for OSD text. RGB
- osdbackcolor: color to be used as the OSD back color. RGB.
- osdfontstyle: font style for the text displayed in the OSD. Two formats can be used: "size, bold" or "size, bold, fonttype".
reserved.......
reserved.....
Thanks, APBilbo, for sharing this. Really appreciate your help towards the community.
Thanks a lot!!! I really love this app. Its the best one I have found so far. I would be surprised if Verizon and T-mobile dont start using this in the phones they sell...
I wish I had the time to create using ThrottleLauncher, I guess I'll leave it up to the pro's. Thanks for sharing your knowledge.

[Q] ScrollView, SetText and scrollTo

Hi,
Im just getting into Android development and picking up pace slowly. Getting confused how people are getting settings style menus with the appropriate colour Summary Line while adding icons for Stars and Checkboxes etc to highlight and tick.
Anyhoo, I have a TextViews inside a LinearLayout inside a ScrollView, seems to work OK. I use SetText to set the Text on the TextViews and I create everything at run time instead of through the XML files.
But the application I have is a polling type application and I need to repopulate the TextViews and redraw the ScrollView in the same position that the user scrolled to previously.
Im accutely aware of problems using ScrollTo after you've used SetText, so I found the following code:
Code:
sView.post(new Runnable() {
public void run() {
sView.scrollTo(0, iTop);
}
});
It works, but there's a screen flicker where it first draws the screen in its normal position then sets the scrollTo.
What is the best way of achieving this, or am I doing everything completely backwards and most normal people wouldn't have this kind of problem?
Thanks
Simon
It sounds more like you might want to consider using a listview instead. It was designed to contain several child views and scrolls and updates seamlessly.
Hi,
Thanks for the reply. Perhaps I am a bit too much of a beginner.
I seem to be favouring TableLayout so that I can display tabular data and have columns resize correctly and have the data presented OK.
I think that's why I went with updating everything at design time because I have a variable number of rows that can be added. IIUC, variable rows (in an XML file) I think can only be created using ListView, but of course a TableRow needs a TableLayout as a parent.
Here is the idea...
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"><TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:text="@+id/TextView01" android:paddingRight="5px" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="@+id/TextView02" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</TableRow>
</TableLayout>
The code I have for TableRows is not dissimilar to, http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout
But of course using setText means I cannot then scrollTo
Duh.
First learning curve mastered.
You only need to add views to containers etc the first time you display the screen.
You can update the text in the views later on without affecting the screen position.
I like this.

[Q] addind a button to a secondary view is crashing my program

I am making a game that has a main.xml view (the default one that the game screen is made from. But I have a button for "help" that starts a new view which is just text explaining how to play the game. But I want to add a button to the help menu that will take the user back to the main game. Only problem is when I add a button to the xml file for it, it always crashes as soon as it is called. All the other buttons work fine in main.xml but I cant get the ones in the help.xml to work. Any suggestions?
The way that android's view hierarchy works is actually kind of complicated, and is one thing that I still at times struggle to grasp.
So when you press the help button, and help.xml is supposed to show up, it crashes?
yeah, heres my xml code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidadding="10dip" >
<TextView
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text goes here" />
</ScrollView>
But it crashes if theres a button inside of it
are you using the new layout in the same Activity or a new one? If the same, try out making a new Activity class (remember to add it to manifest!), it might be a lot easier to then determine your problem if it's separate.
We could do with a logcat output of the crash to help determine what's wrong

[Q] Simple math, what am I missing?

Hi people!
I'm trying to learn how to develop android apps. I'm not trying to become a developer but for fun and learn this. So I go step by step.In the past I just have very basic visual basic and fortran experience...I don't know java lang. But while searching I found out that android is based on java. so I grabbed netbeans and jdk. and it was easy and understandable to do some basic math(with tutorials) with it, like + - * /
So I thought I'd give a try to appinventor. Ok easy enough.Done basic math. But I want to learn the code itself.
So I'm dealing with eclipse right know. I learned some basic stuff which you can not learn with appinventor.
But when it comes to basic math, I'm stuck!
Let me explain:
with appinventor it's easy to make this (pics are at the end of the post)
when I try to make this with eclicpe...I'm going nuts. I couldn't find any tutor.
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Lorem Ipsum</string>
<string name="input"></string>
<string name="butcel">Button</string>
<string name="result">result</string>
<string name="ClickHandler">ClickHandler</string>
</resources>
Click to expand...
Click to collapse
Forum does not let me enter my main.xml and main.java codes. so I atteched the pics and txt files below.
this gives me a "app has stopped unexpectedly" error
what I'm trying to do is
1)user inputs a number
2)clicks on a button (there will be several buttons in my app,this is just a test app)
3)application does some math with that number
ie. ((number*5)/2)
4)textView1 shows the result
Should it be simple like in appinventor or am I missing sth in my codes?
And I'm not sure but do I need to add a java math function or sth like that in my app to do simple math like this?
Any advice is appreciated.
Thanks in advance.
The first thing to check is your AndroidManifest.xml file. The Eclipse ADT plugin should create this file and include the main activity for your app automatically if it has been installed. However, an app will throw the error you are receiving if an activity is run that isn't listed in the manifest and it's very common(at least for me) to forget at first to add a newly created activity to the manifest. Below is an example of an AndroidManifest.xml file from the Hello, Android tutorial.
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloAndroid"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hi there desisamay,
to be honest i did not really look and your code to try and find the error, but i did write you an example app you can expand or use to learn .
Attached to my post is the example app and my whole eclipse project directory of it.
The app has an edittext to input a number, a button to start the calculation x*2/5 and a textview to show the result.
I hope you enjoy it and if anything is still unclear, just ask!
when the activity starts you try to get the text of the edittext and convert it to string which is null since the edittext is empty at the beginning. You should get the input when you click the button (and maybe even check if the edittext is empty)
Dark3n said:
Hi there desisamay,
to be honest i did not really look and your code to try and find the error, but i did write you an example app you can expand or use to learn .
Attached to my post is the example app and my whole eclipse project directory of it.
The app has an edittext to input a number, a button to start the calculation x*2/5 and a textview to show the result.
I hope you enjoy it and if anything is still unclear, just ask!
Click to expand...
Click to collapse
Thank you very much! This was exactly what I was trying to do! I was trying to do this with onClickListener and defining values... But your lines are clear and understandable and now I know how to make definitions and basic math functions. I think there'd be more lines to write with onClickListener. But this way is simple and works like a charm. Thank you again.
Also I've added
android:inputType="numberDecimal|numberSigned"
Click to expand...
Click to collapse
to EditText in main.xml just to be sure the user inputs numbers only. maybe just "number" will do the same.
But one more question:
we write the result to output like this
output.setText("The result of " + mInput + " times two, divided by 5 is " + mOutput);
do we have to use some text in it? if I try just
output.setText(mOutput);
eclipse warns me
The method setText(CharSequence) in the type TextView is not applicable for the arguments (double)
Click to expand...
Click to collapse
and underlines setText with red. but we 've already defined mOutput before like double mOutput = (mInput*2/5);
@MongooseHelix
My AndroidManifest.xml was the same as you posted. Since I only have one action. Thanks.
@nemoc 23
I was trying to that. get the input when button clicked. Convert to string of course and do some math. But I couldn't.(now I can ) But you're right for checking the edittext field after clicking the button. I'm pretty sure if you click the button with an empty edittext area, app will give an error.(i tried and it did)
When writing my little app I'm planning to add this and warn the user with a toast text.
output.setText( mOutput.toString() );

[Q] how to show focus on clickable image?

I have created a custon UI menu, and for backwards compatabilty to non-touchscreen devices (such as google TV) I want the user to be able to visually see that the image is selected (I have tried with my desires trackball and it works but just looks the same)
How would i get my app to show the different image on focus and switch back when off focus?
So far i have tried:
Code:
@Override
public void onFocusChange(View arg0, boolean arg1) {
ImageView imageView = (ImageView) findViewById(R.id.tl);
Drawable newFocusImage;
newFocusImage = getResources().getDrawable(R.drawable.menu_top_left_trans_ic_fcs);
imageView.setImageDrawable(newFocusImage);
}
However this somehow changes it to a completely different image than the new drawable specified, and does not revert on un-focus.
All help would be greatly appreciated
Thanks
Rather than draw a new image, why not say change the alpha channel values to make it appear lighter or darker? Or overlay it with a solid color image with a low alpha value?
The alpha change is a good idea. As a photographer i would say adding a transparent vignette would look great. If you don't know what a vignette is, its basically darkening the edges of an image / a circular gradient (dark edges, light middle)
From something awesome
ye that sounds cool
however my main problem still lies in the coding of the problem, do you know how to code a vignette? is it possible to change a image like that in java?
Instead of using getDrawable and setImageDrawable use setImageResource
Create two images:
menu_top_left_trans_ic_fcs_normal - to be shown when not focused
menu_top_left_trans_ic_fcs_focused - to be shown when focused
Then add to res/drawable a new file named menu_top_left_trans_ic_fcs.xml with the following content:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/menu_top_left_trans_ic_fcs_focused" android:state_focused="true" />
<item android:drawable="@drawable/menu_top_left_trans_ic_fcs_normal" />
</selector>
Note: You can also set android:state_pressed
Use in your code
Code:
imageView.setImageResource(R.drawable.menu_top_left_trans_ic_fcs);
I never tested this exact code but it should work.
thanks it worked !!

Categories

Resources