How to make a layout is totally wrap content the background in the drawable folder? - android-shape

i have an issue here. I have an .xml file in the drawable which is the android:shape="line". below is the code:
<stroke android:width="2dp" android:color="#FF00FFFF" />
<size android:height="1dp"/>
when this .xml is applied to my linear layout as background as in figure below:
the left side and the right side of the line is touch to the linear layout. but, if i increase the "android:width" to '11', the line thickness will increase, but the left and the right side of the line didn't touch anymore to the linear layout as in figure below:
I want the line touch the left and the right side of my linear layout even the stroke "android:width" is increase.
please help.

You can also try to use linear layouts' divider property.
<LinearLayout
...
android:divider="#drawable/divider_vertical">
<TextView />
<TextView />
</LinearLayout>
File: drawable/divider_vertical.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="1dp" />
<solid android:color="#FF00FFFF" />
</shape>

I already solve my problem :). It is simply put padding but not in the shape element because if I put in the shape element, the padding doesn't work. We must put the padding outside the shape region, or in other word, put padding in item region. Means that, the root element is layer-list, since item element and shape element is in same .xml file:
<item android:left="-7px" android:right="-7px">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="11dp" android:color="#FF00FFFF" />
<size android:height="1dp"/>
</shape>
</item>

Related

Qt5 custom widget - Curved slider

I'm starting my next electronics project which is to create my own version of Google's Nest Thermostat. I like the whole circular dial for temperature selection and I've been having a think about how to create this myself. GUI programming is not my area of expertise (CLI all the way!).
So far I'm think along one of two lines, both involving custom widgets:
Create a widget that inherits from the pushbutton class. This subclass will contain lots of buttons, one for each step in the temperature scale, arranged in a 3/4 circle.
Create a widget that inherits from the slider class, defining an object that is curved around 3/4 of a circle. Each step is a temperature.
Now... I have no idea if these are practical solutions to this problem or if there is a much easier way of doing this. I've had a look at the style sheets and I don't THINK that is going to do it. I've had a root around Google for anything similar and not found anything yet; that said, AnalogWidgets from 3electrons at least creates dials, but these are for output rather than input.
I tried this out yesterday and it works rather nicely if you want to simulate the nest thermostat in an app this includes the js and SVG image:
https://www.svidget.io/examples/nestthermostat
HTML snippet:
<object id="nestThermostatWidget" role="svidget" data="nestThermostatWidget.svg" type="image/svg+xml" width="400" height="400">
<param name="targetTemp" value="77" />
<param name="ambientTemp" value="80" />
<param name="unit" value="F" />
<param name="state" value="cooling" />
<param name="showLeaf" value="1" />
<param name="awayMode" value="0" />
</object>

selector for actionBarItemBackground not working

I have to following problem, I want to change the selector from the actionbar item (just the normal actionbar, neither support actionbar nor actionbarsherlock). The backgroud color should be grey instead of default blue if the item icon is pressed. I have searched a lot and know that I need to override the attribute android:actionBarItemBackground in styles, but still my selector doesnt work, the background color is transparent, but the color in on pressed state is not grey, it stays transparent. :/
here is my code:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarItemBackground">#drawable/action_bar_item_drawable</item>
</style>
and here the drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_shortAnimTime">
<item android:drawable="#android:color/transparent"/>
<item android:drawable="#color/grey" android:state_pressed="true"/>
</selector>
anyone an idea?
When you supply a selector as a drawable, the first matching item that satisfies all conditions will be displayed.
In your drawable, the transparent color gets chosen every time because it doesn't have any condition such as state_pressed="true".
You should put items with more restricting conditions first and item without any condition as the last one.
Your drawable should instead look like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="#android:integer/config_shortAnimTime">
<item android:drawable="#color/grey" android:state_pressed="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>

keeping data during orientation changes by using fragments

I am trying to understand fragments. All the examples I read is about having a main activity and then two sub fragments.
The issue is that my program has only 1 activity. Can I make it a fragment?
Current ui main class
public class MainActivity extends Activity {}
Can I make it
public class MainActivity extends Fragment {}
The program I am trying to create will constantly monitor phone variables and display logs in a textView. I don't want to lose the logs when the user changes the orientation or some other change when the os destroys the ui.
The UI is basically 1 textView that gets filled by a runnable that updates the textView every 5 seconds with the content of a linked list. I don't want to lose the content of the linked list basically.
I checked getLastNonConfigurationInstance() but it seems it's depreciated so I don't want to use that
Any help would be highly appreciated.
Amish
Found answer here:
http://blog.webagesolutions.com/archives/458
So after a lot of searching I found that if you add the following:
android:configChanges="orientation|screenSize"
in the androidManifest.xml, the os will not destroy the activity when switching from portrait mode to landscape mode.
My xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.axr0284.phonecontrol"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.axr0284.phonecontrol.MainActivity"
android:label="#string/app_name"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Hope this helps somebody,
Amish

How to set splitter exactly to half window width in p4merge?

I'm wondering if there is a way to set the splitter in p4merge window exactly to 50% screen width. For instance in Total Commander you can right click on splitter and choose from list but there is nothing like that in p4merge.
I used Process Monitor from Sysinternals to track where p4merge writes settings.
Appears that settings file resides here
%USERPROFILE%\.p4merge\ApplicationSettings.xml
and it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!--perforce-xml-version=1.0-->
<PropertyList varName="ApplicationSettings" IsManaged="TRUE">
<String varName="CharSet">utf8-bom</String>
<PropertyList varName="Connection" IsManaged="TRUE">
<String varName="ApplicationLanguage">en</String>
</PropertyList>
<String varName="DiffOption">dl</String>
<ByteArray varName="DiffSplitter">AAAA/wAAAAAAAAACAAAA8wAAAUMBAAAAMgEAAAAB</ByteArray>
<Font varName="Font">
<family>Courier</family>
<pointSize>10</pointSize>
<weight>Normal</weight>
<italic>false</italic>
</Font>
<!--i cut it here for concise-->
</PropertyList>
My guess was:
<ByteArray varName="DiffSplitter">AAAA/wAAAAAAAAACAAAA8wAAAUMBAAAAMgEAAAAB</ByteArray>
is a place where p4merge stores the splitter position.
I didn't feel like decrypting the value so i just deleted the whole tag and splitter moved to exactly 50% width of window.

How to do proper nesting in a Magento theme?

I've copied the default Magento theme in the two dirs and renamed it.
After a lot of tweaking I've come to a point where I'm stuck.
I've got a 3columns.phtml file where the basic layout resides:
top (top.phtml)
header (header.phtml)
main (main.phtml)
footer (footer.phtml)
with main.phtml:
left.phtml
middle.phtml
right.phtml
Now when I referenced these blocks separately in the 3columns.phtml with the getChildHtml() function everything was peachy. Now, after putting them in the main.phtml file it doesn't seem to work anymore. Any content in the main.phtml is not shown (not even simpel html tags). Thinking it could have to do with the xml layout files I looked into page.xml but found out some things are handled by catalog.xml
I now have these block declarations in page.xml:
top (no template= set)
header (no template= set)
main (template="page/html/main.phtml")
left (template="page/html/left.phtml")
middle (template="page/html/middle.phtml")
topmenu (template="page/html/topmenu.phtml")
breadcrumbs (no template= set)
right (template="page/html/right.phtml")
footer (template="page/html/footer.phtml")
And eventhough top and header have no template set their html shows up fine in the frontend. the footer shows up fine too.
Left's output is shown, but not wrapped by main's output.
Right's output the same.
Middle's output shows, but any getChildHtml calls in it don't.
Any ideas as to what's going on?
Also, how do the page.xml and catalog.xml relate to the template? Does every single call to getChildHtml have to be in the page.xml file? what's the difference between page and catalog.
The part of page.xml: http://www.snipplr.com/view/66919/part-of-pagexml-not-working/
The part of catalog.xml: http://www.snipplr.com/view/66920/default-part-of-catalogxml-not-working/
The 3columns.phtml: http://www.snipplr.com/view/66921/main-theme-file-3columnsphtml/
For the detail explanation you can read Alanstorm's book, "No Frills Magento Layout".
I'll give you "brief" explanation so that you have a little enlightment.
In our controller, when we call $this->loadLayout();, it will automatically "call" <default> handle.
Later, all of the handle in all layout xml will be merged.
Let's say you have <default> in page.xml, then you also have <default> in your catalog.xml.
After the call of $this->loadLayout() those <default> from page.xml and catalog.xml will be merged.
That's the relation between them.
We can say <default> is the main of everything. It is the main structure. Any other layout usually "referencing" from it.
Let's say you want to add something in the main body (content), we will call:
<reference name="content">
<block type="core/template" name="testing" template="some/test/template.phtml"></block>
</reference>
Those tag means: Put <block type="core/template" name="testing" template="some/test/template.phtml"></block> under block with name content.
If you see the definition of block with name content:
<block type="core/text_list" name="content" as="content" translate="label">
<label>Main Content Area</label>
</block>
You can see the type is core/text_list. Block with this type will render every child under it and it DOES NOT need a template.
As you can see, there is no definition for template="blabla/blibli.phtml".
The type of block that have template is core/block_template. In this type of block, if you want to render its child, you have to "consciously" call echo $this->getChildHtml('mykid').
Do you get it?
That's why your definition is incorrect: <block type="core/text_list" name="main" as="main" translate="label" template="page/html/main.phtml">.
core/text_list doesn't need and doesn't have a template. You can imagine if "content" is a core/block_template: every time you're going to create a child under "content" you have to "consciously" call echo $this->getChildHtml('mykid'). Let's say you have 100 child, you will need to call echo $this->getChildHtml('mykid1'), echo $this->getChildHtml('mykid2'), ..., echo $this->getChildHtml('mykid100').
Then let's see your catalog.xml:
<default>
<!-- Mage_Catalog -->
<block type="core/template" name="top" template="page/html/top.phtml"></block>
<block type="core/template" name="header" template="page/html/header.phtml"></block>
<block type="core/template" name="main" template="page/html/main.phtml">
<block type="core/template" name="left" template="page/html/left.phtml"></block>
<block type="core/template" name="middle" template="page/html/middle.phtml"></block>
<block type="core/template" name="right" template="page/html/right.phtml"></block>
</block>
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map">
<label>Site Map</label>
<url helper="catalog/map/getCategoryUrl" />
<title>Site Map</title>
</action>
</reference>
<block type="catalog/product_price_template" name="catalog_product_price_template" />
</default>
I don't get it what you're going to achieve from this catalog.xml. There are no reference for: <block type="core/template" name="top" template="page/html/top.phtml"></block>, <block type="core/template" name="header" template="page/html/header.phtml"></block>, etc.
If you're going to add some layout (children), you need to "referencing" from an existing one. Let's say you're going to add children under block with name "main" and you're going to put the code in your catalog.xml:
Then your catalog.xml will be like this:
<default>
<reference name="main">
<block type="core/template" name="i" template="my/new/template1.phtml"></block>
<block type="core/template" name="dont" template="my/new/template2.phtml"></block>
<block type="core/template" name="know" template="my/new/template3.phtml"></block>
</reference>
</default>
Now it depends on the definition of block with name "main".
If your block with name "main" is:
<block type="core/text_list" name="main" as="main" translate="label">
...
</block>
then those blocks (blocks with name "i", "dont", "know") will be automatically called (rendered).
If your block with name "main" is:
<block type="core/template" name="main" as="main" translate="label" template="page/html/main.phtml">
...
</block>
Then you need to call this in your page/html/main.phtml:
echo $this->getChildHtml('i');
echo $this->getChildHtml('dont');
echo $this->getChildHtml('know');
That's as far as I can explain as it's pretty much incorrect things in your layout, if you get the point, you can fix it by reading my explanation.
Few tips:
To see which handles loaded, put this code in your controller under $this->loadLayout(); :
$layout = Mage::getSingleton('core/layout');
$updates = $layout->getUpdate();
$handles = $updates->getHandles();
var_dump($handles);
To see the generated xml from load layout, put this code in your controller under $this->loadLayout(); :
$layout = Mage::getSingleton('core/layout');
$updates = $layout->getUpdate();
$xml = $updates->asString();
var_dump($xml);
Maybe you will need echo "<pre>" / wrap using htmlentities / Mage::log for neat looking purpose.
Here are some possible explanations.
Since left, middle, and right are children of 'main' you need to call getChildChildHtml (note the double child).
Since 'main' is a child (nested) inside 3columns it is not considered it's own page type (i.e. 1 column), the better solution seems to edit the 3columns.phtml file to have the blocks that you want.
When calling getChildHtml the parameter passed to it is the name='' attribute in the xml (so for example if the 'right' block needs to be called, then we need to find the name attribute in the xml - in this case it's 'right' and use that for the parameter).
The left, footer etc. blocks are showing because they are already being called in the 3columns.phtml file.
Also double check that the template file to 'main' is in the right location.
I hope these were some helpful pointers