tag:blogger.com,1999:blog-85109999142116176432024-03-14T01:47:00.896+07:00Welcome to vuihi's blogAnonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.comBlogger117125tag:blogger.com,1999:blog-8510999914211617643.post-40883419262305867022018-03-09T20:57:00.002+07:002018-03-09T20:57:44.186+07:00Simple PHP echo code not workingThe issues:<br />
"<span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;">Here is my html with a php script:</span><br />
<blockquote style="background-color: cornsilk; border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgb(255, 235, 142); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 10px; padding: 10px; quotes: none; vertical-align: baseline;">
<pre class="lang-php prettyprint prettyprinted" style="background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><html></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><head></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><title></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Bob's Auto Parts</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></title></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></head></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><body></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><h1></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Bob's Auto Parts</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></h1></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><table</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; box-sizing: inherit; color: #e64320; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">width</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atv" style="border: 0px; box-sizing: inherit; color: #0f74bd; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">100%</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><tr></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><?</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">php
echo </span><span class="str" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"<td>This is working.</td>"</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">?></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></tr></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></table></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></body></span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="tag" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"></html></span></code></pre>
</blockquote>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Here is the ouput</div>
<blockquote style="background-color: cornsilk; border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: rgb(255, 235, 142); border-left-style: solid; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 0px 2px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px 0px 10px; padding: 10px; quotes: none; vertical-align: baseline;">
<div style="border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
Bob's Auto Parts</div>
<h1 style="border: 0px; box-sizing: inherit; font-family: inherit; font-size: 21px; font-stretch: inherit; font-style: inherit; font-variant: inherit; line-height: 1.3; margin: 0px 0px 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
Bob's Auto Parts</h1>
This is working."; ?><div style="border: 0px; box-sizing: inherit; clear: both; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; padding: 0px; vertical-align: baseline;">
</div>
</blockquote>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
"</div>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
How to fix:</div>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
In my case (which is a very specific case) installing this missing package (Ubuntu 14.04) did the trick:</div>
<pre class="lang-php prettyprint prettyprinted" style="background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">sudo apt</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="kwd" style="border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">get</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> install libapache2</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">mod</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">php5</span></code></pre>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
for users working with php7 install the package:</div>
<pre class="lang-php prettyprint prettyprinted" style="background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">sudo apt</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="kwd" style="border: 0px; box-sizing: inherit; color: #101094; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">get</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> install libapache2</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">mod</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">php7</span><span class="pun" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="lit" style="border: 0px; box-sizing: inherit; color: #7d2727; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">0</span></code></pre>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
After that, just restart apache:</div>
<pre class="lang-php prettyprint prettyprinted" style="background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #393318; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto; word-wrap: normal;"><code style="border: 0px; box-sizing: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="pln" style="border: 0px; box-sizing: inherit; color: #303336; font-family: inherit; font-size: inherit; font-stretch: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">sudo service apache2 restart</span></code></pre>
<div style="background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin-bottom: 1em; padding: 0px; vertical-align: baseline;">
And there you go.</div>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com1tag:blogger.com,1999:blog-8510999914211617643.post-23237730404895819612015-09-13T10:10:00.000+07:002015-09-25T17:37:53.685+07:00How to change iphone ringtone to any song without iTunes<h2>
How to Get Started?</h2>
Simply, make sure that you already have <b>Apple iTunes</b> installed on your Mac or Windows (you are not going to use it).<br />
<br />
<b>What we need:</b><br />
<ul>
<li>Connected iPhone to PC, laptop</li>
<li>Installed iTunes and iTools in your PC, laptop</li>
</ul>
*Download <b><a href="http://taimienphi.vn/download-itunes-19" target="_blank">iTunes</a></b><br />
*Download <b><a href="http://taimienphi.vn/download-itools-7947" target="_blank">iTools</a></b> <br />
<h2>
</h2>
<h2>
Add Ringtones to iPhone Now!</h2>
<i>Step1</i>: Open iTools, select button <b>Ringtone</b>.<br />
<br />
<div style="text-align: center;">
<img alt="tao nhac chuong cho iphone bang itools" src="http://thuthuat.taimienphi.vn/cf/Images/2015/8/laihv/huong-dan-tao-nhac-chuong-cho-iphone-bang-itools-1.jpg" style="font-size: 12px;" /> </div>
<div style="text-align: center;">
<br /></div>
<i>Step2:</i> Click <b>Choose</b> to select the song in local or in device.<br />
<br />
<div style="text-align: center;">
<img alt="tao nhac chuong bang itools" src="http://taimienphi.vn/tmp/cf/aut/huong-dan-tao-nhac-chuong-cho-iphone-bang-itools-2.jpg" style="font-size: 12px;" /></div>
<br />
Note: iPhone's ringtone has duration time only 30 seconds.<br />
<br />
<b>Set start</b>: Start point of ringtone<br />
<b>Set end</b>: End point of ring tone:<br />
<b>Play</b>: Check your ringtones<br />
<br />
And click <b>Save</b> .<br />
<div style="text-align: center;">
<img alt="su dung itools lam nhac chuong iphone" src="http://imgt.taimienphi.vn/cf/Images/2015/8/laihv/huong-dan-tao-nhac-chuong-cho-iphone-bang-itools-3.jpg" style="font-size: 12px;" /> </div>
<div style="text-align: center;">
<br /></div>
<br />
<div style="text-align: center;">
<img alt="tao nhac chuong cho iphone bang itools, tao nhac chuong bang itools, su dung itools lam nhac chuong iphone" src="http://imgt.taimienphi.vn/cf/Images/2015/8/laihv/huong-dan-tao-nhac-chuong-cho-iphone-bang-itools-4.jpg" style="font-size: 12px;" /><br />
<br />
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Video:</div>
<div style="text-align: left;">
<br /></div>
</div>
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/qlsW7Y-wGeg" width="560"></iframe></div>
Anonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.com2tag:blogger.com,1999:blog-8510999914211617643.post-73672509085921633162015-07-22T08:41:00.000+07:002015-07-22T08:44:20.990+07:00IDTech Unimag Card Swiper on Android<table><tbody>
<tr><td class="votecell"><div class="vote">
<span class="vote-count-post " itemprop="upvoteCount"></span><span class="vote-accepted-on load-accepted-answer-date" title="loading when this answer was accepted..."><br /></span>
<br />
<span class="vote-count-post " itemprop="upvoteCount"></span><span class="vote-accepted-on load-accepted-answer-date" title="loading when this answer was accepted..."><br /></span>
</div>
</td>
<td class="answercell"><div class="post-text" itemprop="text">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://cdn.posmicro.com/prodimages/shuttle.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://cdn.posmicro.com/prodimages/shuttle.jpg" width="320" /></a></div>
<br />
Here's what I used with the UniMag. Using a handler to output the
swiped data, and a 'Swipe' button to start the swiping. To improve, one
should wait until the card reader reports it is connected / ready to
swipe, then enable the button, disable while waiting for swipe, and
re-enable after receiving data.<br />
<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="pln">regex</span><span class="pun">.</span><span class="typ">Matcher</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="pln">regex</span><span class="pun">.</span><span class="typ">Pattern</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="typ">IDTech</span><span class="pun">.</span><span class="pln">MSR</span><span class="pun">.</span><span class="typ">XMLManager</span><span class="pun">.</span><span class="typ">StructConfigParameters</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="typ">IDTech</span><span class="pun">.</span><span class="pln">MSR</span><span class="pun">.</span><span class="pln">uniMag</span><span class="pun">.</span><span class="pln">uniMagReader</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> </span><span class="typ">IDTech</span><span class="pun">.</span><span class="pln">MSR</span><span class="pun">.</span><span class="pln">uniMag</span><span class="pun">.</span><span class="pln">uniMagReaderMsg</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">app</span><span class="pun">.</span><span class="typ">Activity</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">os</span><span class="pun">.</span><span class="typ">Bundle</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">os</span><span class="pun">.</span><span class="typ">Handler</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">os</span><span class="pun">.</span><span class="typ">Message</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">util</span><span class="pun">.</span><span class="typ">Log</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">view</span><span class="pun">.</span><span class="typ">View</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">view</span><span class="pun">.</span><span class="typ">View</span><span class="pun">.</span><span class="typ">OnClickListener</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">widget</span><span class="pun">.</span><span class="typ">Button</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">import</span><span class="pln"> android</span><span class="pun">.</span><span class="pln">widget</span><span class="pun">.</span><span class="typ">TextView</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MainActivity</span><span class="pln"> </span><span class="kwd">extends</span><span class="pln"> </span><span class="typ">Activity</span><span class="pln"> </span><span class="kwd">implements</span><span class="pln"> uniMagReaderMsg </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">private</span><span class="pln"> uniMagReader myUniMagReader </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">private</span><span class="pln"> </span><span class="typ">Button</span><span class="pln"> btnSwipe</span><span class="pun">;</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onCreate</span><span class="pun">(</span><span class="typ">Bundle</span><span class="pln"> savedInstanceState</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">super</span><span class="pun">.</span><span class="pln">onCreate</span><span class="pun">(</span><span class="pln">savedInstanceState</span><span class="pun">);</span><span class="pln">
setContentView</span><span class="pun">(</span><span class="pln">R</span><span class="pun">.</span><span class="pln">layout</span><span class="pun">.</span><span class="pln">activity_main</span><span class="pun">);</span><span class="pln">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">myUniMagReader </span><span class="pun">==</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
myUniMagReader </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> uniMagReader</span><span class="pun">(</span><span class="kwd">this</span><span class="pun">,</span><span class="kwd">this</span><span class="pun">);</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">setSaveLogEnable</span><span class="pun">(</span><span class="kwd">false</span><span class="pun">);</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">setXMLFileNameWithPath</span><span class="pun">(</span><span class="kwd">null</span><span class="pun">);</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">loadingConfigurationXMLFile</span><span class="pun">(</span><span class="kwd">true</span><span class="pun">);</span><span class="pln">
</span><span class="com">//myUniMagReader.setVerboseLoggingEnable(true);</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">registerListen</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
btnSwipe </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Button</span><span class="pun">)</span><span class="pln"> findViewById</span><span class="pun">(</span><span class="pln">R</span><span class="pun">.</span><span class="pln">id</span><span class="pun">.</span><span class="pln">button1</span><span class="pun">);</span><span class="pln">
btnSwipe</span><span class="pun">.</span><span class="pln">setOnClickListener</span><span class="pun">(</span><span class="kwd">new</span><span class="pln"> </span><span class="typ">OnClickListener</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onClick</span><span class="pun">(</span><span class="typ">View</span><span class="pln"> v</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">startSwipeCard</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onDestroy</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">stopSwipeCard</span><span class="pun">();</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">unregisterListen</span><span class="pun">();</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">release</span><span class="pun">();</span><span class="pln">
</span><span class="kwd">super</span><span class="pun">.</span><span class="pln">onDestroy</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">boolean</span><span class="pln"> getUserGrant</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> arg0</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> arg1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"getUserGrant -- "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> arg1</span><span class="pun">);</span><span class="pln">
</span><span class="kwd">return</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgAutoConfigProgress</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> arg0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="com">// TODO Auto-generated method stub</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgAutoConfigProgress"</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgCardData</span><span class="pun">(</span><span class="kwd">byte</span><span class="pln"> arg0</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">byte</span><span class="pun">[]</span><span class="pln"> arg1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgCardData"</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Successful swipe!"</span><span class="pun">);</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> strData </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">String</span><span class="pun">(</span><span class="pln">arg1</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"SWIPE - "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> strData</span><span class="pun">);</span><span class="pln">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">myUniMagReader</span><span class="pun">.</span><span class="pln">isSwipeCardRunning</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">stopSwipeCard</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="com">// Match the data we want.</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> pattern </span><span class="pun">=</span><span class="pln"> </span><span class="str">"%B(\\d+)\\^([^\\^]+)\\^(\\d{4})"</span><span class="pun">;</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> pattern</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Pattern</span><span class="pln"> r </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Pattern</span><span class="pun">.</span><span class="pln">compile</span><span class="pun">(</span><span class="pln">pattern</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Matcher</span><span class="pln"> m </span><span class="pun">=</span><span class="pln"> r</span><span class="pun">.</span><span class="pln">matcher</span><span class="pun">(</span><span class="pln">strData</span><span class="pun">);</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> card </span><span class="pun">=</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> name </span><span class="pun">=</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> exp </span><span class="pun">=</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> data </span><span class="pun">=</span><span class="pln"> </span><span class="str">""</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">m</span><span class="pun">.</span><span class="pln">find</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="kwd">for</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> a </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"> a </span><span class="pun"><</span><span class="pln"> m</span><span class="pun">.</span><span class="pln">groupCount</span><span class="pun">();</span><span class="pln"> </span><span class="pun">++</span><span class="pln">a</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> a </span><span class="pun">+</span><span class="pln"> </span><span class="str">" - "</span><span class="pun">+</span><span class="pln">m</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">(</span><span class="pln">a</span><span class="pun">));</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
card </span><span class="pun">=</span><span class="pln"> m</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">(</span><span class="lit">1</span><span class="pun">);</span><span class="pln">
name </span><span class="pun">=</span><span class="pln"> m</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">(</span><span class="lit">2</span><span class="pun">);</span><span class="pln">
exp </span><span class="pun">=</span><span class="pln"> m</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">(</span><span class="lit">3</span><span class="pun">);</span><span class="pln">
data </span><span class="pun">=</span><span class="pln"> </span><span class="str">"Data: "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> name </span><span class="pun">+</span><span class="pln"> </span><span class="str">" -- "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> card </span><span class="pun">+</span><span class="pln"> </span><span class="str">" -- "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> exp</span><span class="pun">;</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> data</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Message</span><span class="pln"> msg </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Message</span><span class="pun">();</span><span class="pln">
msg</span><span class="pun">.</span><span class="pln">obj </span><span class="pun">=</span><span class="pln"> data</span><span class="pun">;</span><span class="pln">
swipeHandler</span><span class="pun">.</span><span class="pln">sendMessage</span><span class="pun">(</span><span class="pln">msg</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">final</span><span class="pln"> </span><span class="typ">Handler</span><span class="pln"> swipeHandler </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">Handler</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> handleMessage</span><span class="pun">(</span><span class="typ">Message</span><span class="pln"> msg</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> text </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="typ">String</span><span class="pun">)</span><span class="pln">msg</span><span class="pun">.</span><span class="pln">obj</span><span class="pun">;</span><span class="pln">
</span><span class="typ">TextView</span><span class="pln"> dataView </span><span class="pun">=</span><span class="pln"> </span><span class="pun">(</span><span class="typ">TextView</span><span class="pun">)</span><span class="pln"> findViewById</span><span class="pun">(</span><span class="pln">R</span><span class="pun">.</span><span class="pln">id</span><span class="pun">.</span><span class="pln">text_view</span><span class="pun">);</span><span class="pln">
dataView</span><span class="pun">.</span><span class="pln">setText</span><span class="pun">(</span><span class="pln">text</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">};</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgCommandResult</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> arg0</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">byte</span><span class="pun">[]</span><span class="pln"> arg1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgCommandResult"</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgConnected</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgConnected"</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"Card reader is connected."</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgDisconnected</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgDisconnected"</span><span class="pun">);</span><span class="pln">
</span><span class="kwd">if</span><span class="pun">(</span><span class="pln">myUniMagReader</span><span class="pun">.</span><span class="pln">isSwipeCardRunning</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">stopSwipeCard</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
myUniMagReader</span><span class="pun">.</span><span class="pln">release</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgFailureInfo</span><span class="pun">(</span><span class="kwd">int</span><span class="pln"> arg0</span><span class="pun">,</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> arg1</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="str">"onReceiveMsgFailureInfo -- "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> arg1</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgSDCardDFailed</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> arg0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgSDCardDFailed -- "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> arg0</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgTimeout</span><span class="pun">(</span><span class="typ">String</span><span class="pln"> arg0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgTimeout -- "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> arg0</span><span class="pun">);</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="str">"Timed out!"</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgToConnect</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="str">"Swiper Powered Up"</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgToSwipeCard</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="str">"onReceiveMsgToSwipeCard"</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="lit">@Override</span><span class="pln">
</span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> onReceiveMsgAutoConfigCompleted</span><span class="pun">(</span><span class="typ">StructConfigParameters</span><span class="pln"> arg0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="typ">Log</span><span class="pun">.</span><span class="pln">d</span><span class="pun">(</span><span class="str">"UniMag"</span><span class="pun">,</span><span class="pln"> </span><span class="str">"onReceiveMsgAutoConfigCompleted"</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span></code></pre>
</blockquote>
</div>
</td></tr>
</tbody></table>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-62496381273454040122015-06-24T14:05:00.003+07:002015-06-24T14:05:33.533+07:00Java HttpURLConnection follow redirect example<div class="pic" style="text-align: center;">
<img alt="301-redirect" class="alignnone size-full wp-image-12918" height="172" src="http://www.mkyong.com/wp-content/uploads/2013/03/301-redirect.jpg" width="168" /></div>
The <code>HttpURLConnection</code>‘s
follow redirect is just an indicator, in fact it won’t help you to do
the “real” http redirection, you still need to handle it manually.<br />
<div class="wp_syntax">
<div class="code">
<pre class="java" style="font-family: monospace;"><span style="color: #003399;">URL</span> obj <span style="color: #339933;">=</span> <span style="color: black; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">(</span>url<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">HttpURLConnection</span> conn <span style="color: #339933;">=</span> <span style="color: #009900;">(</span><span style="color: #003399;">HttpURLConnection</span><span style="color: #009900;">)</span> obj.<span style="color: #006633;">openConnection</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">setInstanceFollowRedirects</span><span style="color: #009900;">(</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//you still need to handle redirect manully.</span>
<span style="color: #003399;">HttpURLConnection</span>.<span style="color: #006633;">setFollowRedirects</span><span style="color: #009900;">(</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<h2>
1. Java Http Redirect Example</h2>
If a server is redirected from the original URL to another URL, the response code should be <strong>301: Moved Permanently</strong> or <strong>302: Temporary Redirect</strong>. And you can get the new redirected url by reading the “<strong>Location</strong>” header of the HTTP response header.<br />
For example, access to the normal HTTP twitter website – <a href="http://www.twitter.com/" target="_blank">http://www.twitter.com</a> , it will auto redirect to the HTTPS twitter website – <a href="http://www.twitter.com/" target="_blank">https://www.twitter.com</a>.<br />
<div class="filename">
HttpRedirectExample – Full Java follow redirect example, see comments for self-explanatory.</div>
<div class="wp_syntax">
<div class="code">
<pre class="java" style="font-family: monospace;"><span style="color: black; font-weight: bold;">package</span> <span style="color: #006699;">com.mkyong.http</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">import</span> <span style="color: #006699;">java.net.HttpURLConnection</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">public</span> <span style="color: black; font-weight: bold;">class</span> HttpRedirectExample <span style="color: #009900;">{</span>
<span style="color: black; font-weight: bold;">public</span> <span style="color: black; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">(</span><span style="color: #003399;">String</span><span style="color: #009900;">[</span><span style="color: #009900;">]</span> args<span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
<span style="color: black; font-weight: bold;">try</span> <span style="color: #009900;">{</span>
<span style="color: #003399;">String</span> url <span style="color: #339933;">=</span> <span style="color: blue;">"http://www.twitter.com"</span><span style="color: #339933;">;</span>
<span style="color: #003399;">URL</span> obj <span style="color: #339933;">=</span> <span style="color: black; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">(</span>url<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">HttpURLConnection</span> conn <span style="color: #339933;">=</span> <span style="color: #009900;">(</span><span style="color: #003399;">HttpURLConnection</span><span style="color: #009900;">)</span> obj.<span style="color: #006633;">openConnection</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">setReadTimeout</span><span style="color: #009900;">(</span><span style="color: #cc66cc;">5000</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">addRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"Accept-Language"</span>, <span style="color: blue;">"en-US,en;q=0.8"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">addRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"User-Agent"</span>, <span style="color: blue;">"Mozilla"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">addRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"Referer"</span>, <span style="color: blue;">"google.com"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">(</span><span style="color: blue;">"Request URL ... "</span> <span style="color: #339933;">+</span> url<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">boolean</span> redirect <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// normally, 3xx is redirect</span>
<span style="color: #000066; font-weight: bold;">int</span> status <span style="color: #339933;">=</span> conn.<span style="color: #006633;">getResponseCode</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">if</span> <span style="color: #009900;">(</span>status <span style="color: #339933;">!=</span> <span style="color: #003399;">HttpURLConnection</span>.<span style="color: #006633;">HTTP_OK</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
<span style="color: black; font-weight: bold;">if</span> <span style="color: #009900;">(</span>status <span style="color: #339933;">==</span> <span style="color: #003399;">HttpURLConnection</span>.<span style="color: #006633;">HTTP_MOVED_TEMP</span>
<span style="color: #339933;">||</span> status <span style="color: #339933;">==</span> <span style="color: #003399;">HttpURLConnection</span>.<span style="color: #006633;">HTTP_MOVED_PERM</span>
<span style="color: #339933;">||</span> status <span style="color: #339933;">==</span> <span style="color: #003399;">HttpURLConnection</span>.<span style="color: #006633;">HTTP_SEE_OTHER</span><span style="color: #009900;">)</span>
redirect <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">(</span><span style="color: blue;">"Response Code ... "</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">if</span> <span style="color: #009900;">(</span>redirect<span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
<span style="color: #666666; font-style: italic;">// get redirect url from "location" header field</span>
<span style="color: #003399;">String</span> newUrl <span style="color: #339933;">=</span> conn.<span style="color: #006633;">getHeaderField</span><span style="color: #009900;">(</span><span style="color: blue;">"Location"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// get the cookie if need, for login</span>
<span style="color: #003399;">String</span> cookies <span style="color: #339933;">=</span> conn.<span style="color: #006633;">getHeaderField</span><span style="color: #009900;">(</span><span style="color: blue;">"Set-Cookie"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// open the new connnection again</span>
conn <span style="color: #339933;">=</span> <span style="color: #009900;">(</span><span style="color: #003399;">HttpURLConnection</span><span style="color: #009900;">)</span> <span style="color: black; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">(</span>newUrl<span style="color: #009900;">)</span>.<span style="color: #006633;">openConnection</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"Cookie"</span>, cookies<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">addRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"Accept-Language"</span>, <span style="color: blue;">"en-US,en;q=0.8"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">addRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"User-Agent"</span>, <span style="color: blue;">"Mozilla"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
conn.<span style="color: #006633;">addRequestProperty</span><span style="color: #009900;">(</span><span style="color: blue;">"Referer"</span>, <span style="color: blue;">"google.com"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">(</span><span style="color: blue;">"Redirect to URL : "</span> <span style="color: #339933;">+</span> newUrl<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #003399;">BufferedReader</span> in <span style="color: #339933;">=</span> <span style="color: black; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">(</span>
<span style="color: black; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">(</span>conn.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> inputLine<span style="color: #339933;">;</span>
<span style="color: #003399;">StringBuffer</span> html <span style="color: #339933;">=</span> <span style="color: black; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: black; font-weight: bold;">while</span> <span style="color: #009900;">(</span><span style="color: #009900;">(</span>inputLine <span style="color: #339933;">=</span> in.<span style="color: #006633;">readLine</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
html.<span style="color: #006633;">append</span><span style="color: #009900;">(</span>inputLine<span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
in.<span style="color: #006633;">close</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">(</span><span style="color: blue;">"URL Content... <span style="color: #000099; font-weight: bold;">\n</span>"</span> <span style="color: #339933;">+</span> html.<span style="color: #006633;">toString</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">(</span><span style="color: blue;">"Done"</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span> <span style="color: black; font-weight: bold;">catch</span> <span style="color: #009900;">(</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">)</span> <span style="color: #009900;">{</span>
e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span>
<span style="color: #009900;">}</span></pre>
</div>
</div>
<em>Output</em><br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">Request URL ... http:<span style="color: black; font-weight: bold;">//</span>www.twitter.com
Response Code ... <span style="color: black;">301</span>
Redirect to URL : https:<span style="color: black; font-weight: bold;">//</span>twitter.com<span style="color: black; font-weight: bold;">/</span>
URL Content...
<span style="color: black; font-weight: bold;"><!</span>DOCTYPE html<span style="color: black; font-weight: bold;">><!</span>--<span style="color: #7a0874; font-weight: bold;">[</span><span style="color: black; font-weight: bold;">if</span> IE <span style="color: black;">8</span><span style="color: #7a0874; font-weight: bold;">]</span><span style="color: black; font-weight: bold;">><</span>html <span style="color: #007800;">class</span>= <span style="color: black; font-weight: bold;">//</span> twitter.com url content...</pre>
</div>
</div>
Do share if you have better way to handle the HTTP redirection :)<br />
<div style="text-align: right;">
ref: http://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/ </div>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-24842615809002913132015-06-19T09:17:00.000+07:002015-06-19T09:17:40.765+07:00Android Convert Dimensions Class<br /><blockquote class="tr_bq">
public class Dimensions {<br /> /**<br /> * The FIRST_DIMENTION_NUMBER.<br /> */<br /> public static final int FIRST_DIMENTION_NUMBER = 160;<br /> /**<br /> * The SECOND_DIMENTION_NUMBER.<br /> */<br /> public static final int SECOND_DIMENTION_NUMBER = 213;<br /><br /> /**<br /> * displayMetrics.<br /> */<br /> private static DisplayMetrics displayMetrics;<br /><br /> /**<br /> * Convert PX to DP.<br /> * @param d<br /> * number of PX.<br /> * @param context<br /> * application context.<br /> * @return number of DP<br /> */<br /> public static int convertDptoPx(final double d, final Context context) {<br /> if (displayMetrics == null) {<br /> displayMetrics = context.getResources().getDisplayMetrics();<br /> }<br /> return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,<br /> (float) ((d * FIRST_DIMENTION_NUMBER) / SECOND_DIMENTION_NUMBER), displayMetrics);<br /> }<br /></blockquote>
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b> <img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></b></h3>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-31807163620718098842015-06-19T09:14:00.001+07:002015-06-19T09:14:08.709+07:00[Resolved] Java : Unsupported major.minor version 51.0<div class="entry-content">
<h2>
1. Problem</h2>
Run a “jar” on Debian 7.5, and hits the following error messages :<br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">$ java <span style="color: #660033;">-jar</span> ripecrawler.jar
Exception <span style="color: black; font-weight: bold;">in</span> thread <span style="color: red;">"main"</span> java.lang.UnsupportedClassVersionError:
com<span style="color: black; font-weight: bold;">/</span>mkyong<span style="color: black; font-weight: bold;">/</span>whois<span style="color: black; font-weight: bold;">/</span>job<span style="color: black; font-weight: bold;">/</span>RipeCrawlJob : Unsupported major.minor version <span style="color: black;">51.0</span>
at java.lang.ClassLoader.defineClass1<span style="color: #7a0874; font-weight: bold;">(</span>Native Method<span style="color: #7a0874; font-weight: bold;">)</span>
at java.lang.ClassLoader.defineClass<span style="color: #7a0874; font-weight: bold;">(</span>ClassLoader.java:<span style="color: black;">643</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.security.SecureClassLoader.defineClass<span style="color: #7a0874; font-weight: bold;">(</span>SecureClassLoader.java:<span style="color: black;">142</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.net.URLClassLoader.defineClass<span style="color: #7a0874; font-weight: bold;">(</span>URLClassLoader.java:<span style="color: black;">277</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.net.URLClassLoader.access<span style="color: #007800;">$0</span>00<span style="color: #7a0874; font-weight: bold;">(</span>URLClassLoader.java:<span style="color: black;">73</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.net.URLClassLoader<span style="color: #007800;">$1</span>.run<span style="color: #7a0874; font-weight: bold;">(</span>URLClassLoader.java:<span style="color: black;">212</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.security.AccessController.doPrivileged<span style="color: #7a0874; font-weight: bold;">(</span>Native Method<span style="color: #7a0874; font-weight: bold;">)</span>
at java.net.URLClassLoader.findClass<span style="color: #7a0874; font-weight: bold;">(</span>URLClassLoader.java:<span style="color: black;">205</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.lang.ClassLoader.loadClass<span style="color: #7a0874; font-weight: bold;">(</span>ClassLoader.java:<span style="color: black;">323</span><span style="color: #7a0874; font-weight: bold;">)</span>
at sun.misc.Launcher<span style="color: #007800;">$AppClassLoader</span>.loadClass<span style="color: #7a0874; font-weight: bold;">(</span>Launcher.java:<span style="color: black;">294</span><span style="color: #7a0874; font-weight: bold;">)</span>
at java.lang.ClassLoader.loadClass<span style="color: #7a0874; font-weight: bold;">(</span>ClassLoader.java:<span style="color: black;">268</span><span style="color: #7a0874; font-weight: bold;">)</span></pre>
</div>
</div>
A quick check on the Java version, shows the Debian is using 1.6<br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">$ java <span style="color: #660033;">-version</span>
java version <span style="color: red;">"1.6.0_31"</span>
OpenJDK Runtime Environment <span style="color: #7a0874; font-weight: bold;">(</span>IcedTea6 1.13.3<span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #7a0874; font-weight: bold;">(</span>6b31-1.13.3-<span style="color: black;">1</span>~deb7u1<span style="color: #7a0874; font-weight: bold;">)</span>
OpenJDK <span style="color: black;">64</span>-Bit Server VM <span style="color: #7a0874; font-weight: bold;">(</span>build <span style="color: black;">23.25</span>-b01, mixed mode<span style="color: #7a0874; font-weight: bold;">)</span></pre>
</div>
</div>
<div>
<div class="hide_if_width_less_800" style="margin: 20px 0;">
<ins class="adsbygoogle hide_if_width_less_800" data-ad-client="ca-pub-2836379775501347" data-ad-region="mkyongregion" data-ad-slot="7391621200" data-adsbygoogle-status="done" style="display: inline-block; height: 90px; width: 728px;"><ins id="aswift_1_expand" style="background-color: transparent; border: none; display: inline-table; height: 90px; margin: 0; padding: 0; position: relative; visibility: visible; width: 728px;"><ins id="aswift_1_anchor" style="background-color: transparent; border: none; display: block; height: 90px; margin: 0; padding: 0; position: relative; visibility: visible; width: 728px;"></ins></ins></ins></div>
</div>
<h2>
2. Reason</h2>
This is because the “jar” is compiled with JDK 1.7, but you try to run in a JDK 1.6 environment. Refer to the following <a href="http://en.wikipedia.org/wiki/Java_class_file" target="_blank">Wikipedia Java class reference</a>.<br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">J2SE <span style="color: black;">8</span> = <span style="color: black;">52</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x34 hex<span style="color: #7a0874; font-weight: bold;">)</span>
J2SE <span style="color: black;">7</span> = <span style="color: black;">51</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x33 hex<span style="color: #7a0874; font-weight: bold;">)</span>
J2SE <span style="color: black;">6.0</span> = <span style="color: black;">50</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x32 hex<span style="color: #7a0874; font-weight: bold;">)</span>
J2SE <span style="color: black;">5.0</span> = <span style="color: black;">49</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x31 hex<span style="color: #7a0874; font-weight: bold;">)</span>
JDK <span style="color: black;">1.4</span> = <span style="color: black;">48</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x30 hex<span style="color: #7a0874; font-weight: bold;">)</span>
JDK <span style="color: black;">1.3</span> = <span style="color: black;">47</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x2F hex<span style="color: #7a0874; font-weight: bold;">)</span>
JDK <span style="color: black;">1.2</span> = <span style="color: black;">46</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x2E hex<span style="color: #7a0874; font-weight: bold;">)</span>
JDK <span style="color: black;">1.1</span> = <span style="color: black;">45</span> <span style="color: #7a0874; font-weight: bold;">(</span>0x2D hex<span style="color: #7a0874; font-weight: bold;">)</span></pre>
</div>
</div>
<em>P.S major.minor version 51.0 = JDK 1.7 / 7</em><br />
For
example, if you compiled your “jar” with JDK 1.6, and try to run in a
JDK 1.5 environment, the error message will change to this :<br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">Unsupported major.minor version <span style="color: black;">50.0</span></pre>
</div>
</div>
<h2>
3. Solution</h2>
To fix it, download JDK 7, and change the default JDK from 1.6 to 1.7<br />
<em>3.1</em> Download and install <code>openjdk-7-jdk</code><br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> openjdk-<span style="color: black;">7</span>-jdk openjdk-<span style="color: black;">7</span>-jre</pre>
</div>
</div>
<em>3.2</em> Change the default Java to 1.7 (Working on Debian like system only).<br />
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> update-alternatives <span style="color: #660033;">--config</span> java
There are <span style="color: black;">2</span> choices <span style="color: black; font-weight: bold;">for</span> the alternative java <span style="color: #7a0874; font-weight: bold;">(</span>providing <span style="color: black; font-weight: bold;">/</span>usr<span style="color: black; font-weight: bold;">/</span>bin<span style="color: black; font-weight: bold;">/</span>java<span style="color: #7a0874; font-weight: bold;">)</span>.
Selection Path Priority Status
<span style="color: #660033;">------------------------------------------------------------</span>
<span style="color: black; font-weight: bold;">*</span> <span style="color: black;">0</span> <span style="color: black; font-weight: bold;">/</span>usr<span style="color: black; font-weight: bold;">/</span>lib<span style="color: black; font-weight: bold;">/</span>jvm<span style="color: black; font-weight: bold;">/</span>java-<span style="color: black;">6</span>-openjdk-amd64<span style="color: black; font-weight: bold;">/</span>jre<span style="color: black; font-weight: bold;">/</span>bin<span style="color: black; font-weight: bold;">/</span>java <span style="color: black;">1061</span> auto mode
<span style="color: black;">1</span> <span style="color: black; font-weight: bold;">/</span>usr<span style="color: black; font-weight: bold;">/</span>lib<span style="color: black; font-weight: bold;">/</span>jvm<span style="color: black; font-weight: bold;">/</span>java-<span style="color: black;">6</span>-openjdk-amd64<span style="color: black; font-weight: bold;">/</span>jre<span style="color: black; font-weight: bold;">/</span>bin<span style="color: black; font-weight: bold;">/</span>java <span style="color: black;">1061</span> manual mode
<span style="color: black;">2</span> <span style="color: black; font-weight: bold;">/</span>usr<span style="color: black; font-weight: bold;">/</span>lib<span style="color: black; font-weight: bold;">/</span>jvm<span style="color: black; font-weight: bold;">/</span>java-<span style="color: black;">7</span>-openjdk-amd64<span style="color: black; font-weight: bold;">/</span>jre<span style="color: black; font-weight: bold;">/</span>bin<span style="color: black; font-weight: bold;">/</span>java <span style="color: black;">1051</span> manual mode
Press enter to keep the current choice<span style="color: #7a0874; font-weight: bold;">[</span><span style="color: black; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">]</span>, or <span style="color: #7a0874; font-weight: bold;">type</span> selection number: <span style="color: black;">2</span>
update-alternatives: using <span style="color: black; font-weight: bold;">/</span>usr<span style="color: black; font-weight: bold;">/</span>lib<span style="color: black; font-weight: bold;">/</span>jvm<span style="color: black; font-weight: bold;">/</span>java-<span style="color: black;">7</span>-openjdk-amd64<span style="color: black; font-weight: bold;">/</span>jre<span style="color: black; font-weight: bold;">/</span>bin<span style="color: black; font-weight: bold;">/</span>java
to provide <span style="color: black; font-weight: bold;">/</span>usr<span style="color: black; font-weight: bold;">/</span>bin<span style="color: black; font-weight: bold;">/</span>java <span style="color: #7a0874; font-weight: bold;">(</span>java<span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: black; font-weight: bold;">in</span> manual mode</pre>
</div>
</div>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family: monospace;">$ java <span style="color: #660033;">-version</span>
java version <span style="color: red;">"1.7.0_55"</span>
OpenJDK Runtime Environment <span style="color: #7a0874; font-weight: bold;">(</span>IcedTea 2.4.7<span style="color: #7a0874; font-weight: bold;">)</span> <span style="color: #7a0874; font-weight: bold;">(</span>7u55-2.4.7-<span style="color: black;">1</span>~deb7u1<span style="color: #7a0874; font-weight: bold;">)</span>
OpenJDK <span style="color: black;">64</span>-Bit Server VM <span style="color: #7a0874; font-weight: bold;">(</span>build <span style="color: black;">24.51</span>-b03, mixed mode<span style="color: #7a0874; font-weight: bold;">)</span></pre>
</div>
</div>
Done.</div>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-71743499696338777602015-06-16T12:41:00.000+07:002015-06-16T12:41:36.211+07:00Android color xml resource file<blockquote class="tr_bq">
<pre class="lang-xml prettyprint prettyprinted"><code><span class="pun"><?</span><span class="pln">xml version</span><span class="pun">=</span><span class="str">"1.0"</span><span class="pln"> encoding</span><span class="pun">=</span><span class="str">"utf-8"</span><span class="pun">?></span><span class="pln">
</span><span class="tag"><resources></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"white"</span><span class="tag">></span><span class="pln">#FFFFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"yellow"</span><span class="tag">></span><span class="pln">#FFFF00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"fuchsia"</span><span class="tag">></span><span class="pln">#FF00FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"red"</span><span class="tag">></span><span class="pln">#FF0000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"silver"</span><span class="tag">></span><span class="pln">#C0C0C0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"gray"</span><span class="tag">></span><span class="pln">#808080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"olive"</span><span class="tag">></span><span class="pln">#808000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"purple"</span><span class="tag">></span><span class="pln">#800080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"maroon"</span><span class="tag">></span><span class="pln">#800000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"aqua"</span><span class="tag">></span><span class="pln">#00FFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"lime"</span><span class="tag">></span><span class="pln">#00FF00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"teal"</span><span class="tag">></span><span class="pln">#008080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"green"</span><span class="tag">></span><span class="pln">#008000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"blue"</span><span class="tag">></span><span class="pln">#0000FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"navy"</span><span class="tag">></span><span class="pln">#000080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"black"</span><span class="tag">></span><span class="pln">#000000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"></resources></span><span class="pln">
</span><span class="pun"><?</span><span class="pln">xml version</span><span class="pun">=</span><span class="str">"1.0"</span><span class="pln"> encoding</span><span class="pun">=</span><span class="str">"utf-8"</span><span class="pun">?></span><span class="pln">
</span><span class="tag"><resources></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"White"</span><span class="tag">></span><span class="pln">#FFFFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Ivory"</span><span class="tag">></span><span class="pln">#FFFFF0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightYellow"</span><span class="tag">></span><span class="pln">#FFFFE0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Yellow"</span><span class="tag">></span><span class="pln">#FFFF00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Snow"</span><span class="tag">></span><span class="pln">#FFFAFA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"FloralWhite"</span><span class="tag">></span><span class="pln">#FFFAF0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LemonChiffon"</span><span class="tag">></span><span class="pln">#FFFACD</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Cornsilk"</span><span class="tag">></span><span class="pln">#FFF8DC</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Seashell"</span><span class="tag">></span><span class="pln">#FFF5EE</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LavenderBlush"</span><span class="tag">></span><span class="pln">#FFF0F5</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PapayaWhip"</span><span class="tag">></span><span class="pln">#FFEFD5</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"BlanchedAlmond"</span><span class="tag">></span><span class="pln">#FFEBCD</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MistyRose"</span><span class="tag">></span><span class="pln">#FFE4E1</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Bisque"</span><span class="tag">></span><span class="pln">#FFE4C4</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Moccasin"</span><span class="tag">></span><span class="pln">#FFE4B5</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"NavajoWhite"</span><span class="tag">></span><span class="pln">#FFDEAD</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PeachPuff"</span><span class="tag">></span><span class="pln">#FFDAB9</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Gold"</span><span class="tag">></span><span class="pln">#FFD700</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Pink"</span><span class="tag">></span><span class="pln">#FFC0CB</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightPink"</span><span class="tag">></span><span class="pln">#FFB6C1</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Orange"</span><span class="tag">></span><span class="pln">#FFA500</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightSalmon"</span><span class="tag">></span><span class="pln">#FFA07A</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkOrange"</span><span class="tag">></span><span class="pln">#FF8C00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Coral"</span><span class="tag">></span><span class="pln">#FF7F50</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"HotPink"</span><span class="tag">></span><span class="pln">#FF69B4</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Tomato"</span><span class="tag">></span><span class="pln">#FF6347</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"OrangeRed"</span><span class="tag">></span><span class="pln">#FF4500</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DeepPink"</span><span class="tag">></span><span class="pln">#FF1493</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Fuchsia"</span><span class="tag">></span><span class="pln">#FF00FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Magenta"</span><span class="tag">></span><span class="pln">#FF00FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Red"</span><span class="tag">></span><span class="pln">#FF0000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"OldLace"</span><span class="tag">></span><span class="pln">#FDF5E6</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightGoldenrodYellow"</span><span class="tag">></span><span class="pln">#FAFAD2</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Linen"</span><span class="tag">></span><span class="pln">#FAF0E6</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"AntiqueWhite"</span><span class="tag">></span><span class="pln">#FAEBD7</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Salmon"</span><span class="tag">></span><span class="pln">#FA8072</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"GhostWhite"</span><span class="tag">></span><span class="pln">#F8F8FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MintCream"</span><span class="tag">></span><span class="pln">#F5FFFA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"WhiteSmoke"</span><span class="tag">></span><span class="pln">#F5F5F5</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Beige"</span><span class="tag">></span><span class="pln">#F5F5DC</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Wheat"</span><span class="tag">></span><span class="pln">#F5DEB3</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SandyBrown"</span><span class="tag">></span><span class="pln">#F4A460</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Azure"</span><span class="tag">></span><span class="pln">#F0FFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Honeydew"</span><span class="tag">></span><span class="pln">#F0FFF0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"AliceBlue"</span><span class="tag">></span><span class="pln">#F0F8FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Khaki"</span><span class="tag">></span><span class="pln">#F0E68C</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightCoral"</span><span class="tag">></span><span class="pln">#F08080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PaleGoldenrod"</span><span class="tag">></span><span class="pln">#EEE8AA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Violet"</span><span class="tag">></span><span class="pln">#EE82EE</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkSalmon"</span><span class="tag">></span><span class="pln">#E9967A</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Lavender"</span><span class="tag">></span><span class="pln">#E6E6FA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightCyan"</span><span class="tag">></span><span class="pln">#E0FFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"BurlyWood"</span><span class="tag">></span><span class="pln">#DEB887</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Plum"</span><span class="tag">></span><span class="pln">#DDA0DD</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Gainsboro"</span><span class="tag">></span><span class="pln">#DCDCDC</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Crimson"</span><span class="tag">></span><span class="pln">#DC143C</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PaleVioletRed"</span><span class="tag">></span><span class="pln">#DB7093</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Goldenrod"</span><span class="tag">></span><span class="pln">#DAA520</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Orchid"</span><span class="tag">></span><span class="pln">#DA70D6</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Thistle"</span><span class="tag">></span><span class="pln">#D8BFD8</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightGrey"</span><span class="tag">></span><span class="pln">#D3D3D3</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Tan"</span><span class="tag">></span><span class="pln">#D2B48C</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Chocolate"</span><span class="tag">></span><span class="pln">#D2691E</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Peru"</span><span class="tag">></span><span class="pln">#CD853F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"IndianRed"</span><span class="tag">></span><span class="pln">#CD5C5C</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumVioletRed"</span><span class="tag">></span><span class="pln">#C71585</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Silver"</span><span class="tag">></span><span class="pln">#C0C0C0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkKhaki"</span><span class="tag">></span><span class="pln">#BDB76B</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"RosyBrown"</span><span class="tag">></span><span class="pln">#BC8F8F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumOrchid"</span><span class="tag">></span><span class="pln">#BA55D3</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkGoldenrod"</span><span class="tag">></span><span class="pln">#B8860B</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"FireBrick"</span><span class="tag">></span><span class="pln">#B22222</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PowderBlue"</span><span class="tag">></span><span class="pln">#B0E0E6</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightSteelBlue"</span><span class="tag">></span><span class="pln">#B0C4DE</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PaleTurquoise"</span><span class="tag">></span><span class="pln">#AFEEEE</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"GreenYellow"</span><span class="tag">></span><span class="pln">#ADFF2F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightBlue"</span><span class="tag">></span><span class="pln">#ADD8E6</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkGray"</span><span class="tag">></span><span class="pln">#A9A9A9</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Brown"</span><span class="tag">></span><span class="pln">#A52A2A</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Sienna"</span><span class="tag">></span><span class="pln">#A0522D</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"YellowGreen"</span><span class="tag">></span><span class="pln">#9ACD32</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkOrchid"</span><span class="tag">></span><span class="pln">#9932CC</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"PaleGreen"</span><span class="tag">></span><span class="pln">#98FB98</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkViolet"</span><span class="tag">></span><span class="pln">#9400D3</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumPurple"</span><span class="tag">></span><span class="pln">#9370DB</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightGreen"</span><span class="tag">></span><span class="pln">#90EE90</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkSeaGreen"</span><span class="tag">></span><span class="pln">#8FBC8F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SaddleBrown"</span><span class="tag">></span><span class="pln">#8B4513</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkMagenta"</span><span class="tag">></span><span class="pln">#8B008B</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkRed"</span><span class="tag">></span><span class="pln">#8B0000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"BlueViolet"</span><span class="tag">></span><span class="pln">#8A2BE2</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightSkyBlue"</span><span class="tag">></span><span class="pln">#87CEFA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SkyBlue"</span><span class="tag">></span><span class="pln">#87CEEB</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Gray"</span><span class="tag">></span><span class="pln">#808080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Olive"</span><span class="tag">></span><span class="pln">#808000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Purple"</span><span class="tag">></span><span class="pln">#800080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Maroon"</span><span class="tag">></span><span class="pln">#800000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Aquamarine"</span><span class="tag">></span><span class="pln">#7FFFD4</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Chartreuse"</span><span class="tag">></span><span class="pln">#7FFF00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LawnGreen"</span><span class="tag">></span><span class="pln">#7CFC00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumSlateBlue"</span><span class="tag">></span><span class="pln">#7B68EE</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightSlateGray"</span><span class="tag">></span><span class="pln">#778899</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SlateGray"</span><span class="tag">></span><span class="pln">#708090</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"OliveDrab"</span><span class="tag">></span><span class="pln">#6B8E23</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SlateBlue"</span><span class="tag">></span><span class="pln">#6A5ACD</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DimGray"</span><span class="tag">></span><span class="pln">#696969</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumAquamarine"</span><span class="tag">></span><span class="pln">#66CDAA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"CornflowerBlue"</span><span class="tag">></span><span class="pln">#6495ED</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"CadetBlue"</span><span class="tag">></span><span class="pln">#5F9EA0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkOliveGreen"</span><span class="tag">></span><span class="pln">#556B2F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Indigo"</span><span class="tag">></span><span class="pln">#4B0082</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumTurquoise"</span><span class="tag">></span><span class="pln">#48D1CC</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkSlateBlue"</span><span class="tag">></span><span class="pln">#483D8B</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SteelBlue"</span><span class="tag">></span><span class="pln">#4682B4</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"RoyalBlue"</span><span class="tag">></span><span class="pln">#4169E1</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Turquoise"</span><span class="tag">></span><span class="pln">#40E0D0</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumSeaGreen"</span><span class="tag">></span><span class="pln">#3CB371</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LimeGreen"</span><span class="tag">></span><span class="pln">#32CD32</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkSlateGray"</span><span class="tag">></span><span class="pln">#2F4F4F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SeaGreen"</span><span class="tag">></span><span class="pln">#2E8B57</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"ForestGreen"</span><span class="tag">></span><span class="pln">#228B22</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"LightSeaGreen"</span><span class="tag">></span><span class="pln">#20B2AA</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DodgerBlue"</span><span class="tag">></span><span class="pln">#1E90FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MidnightBlue"</span><span class="tag">></span><span class="pln">#191970</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Aqua"</span><span class="tag">></span><span class="pln">#00FFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Cyan"</span><span class="tag">></span><span class="pln">#00FFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"SpringGreen"</span><span class="tag">></span><span class="pln">#00FF7F</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Lime"</span><span class="tag">></span><span class="pln">#00FF00</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumSpringGreen"</span><span class="tag">></span><span class="pln">#00FA9A</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkTurquoise"</span><span class="tag">></span><span class="pln">#00CED1</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DeepSkyBlue"</span><span class="tag">></span><span class="pln">#00BFFF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkCyan"</span><span class="tag">></span><span class="pln">#008B8B</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Teal"</span><span class="tag">></span><span class="pln">#008080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Green"</span><span class="tag">></span><span class="pln">#008000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkGreen"</span><span class="tag">></span><span class="pln">#006400</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Blue"</span><span class="tag">></span><span class="pln">#0000FF</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"MediumBlue"</span><span class="tag">></span><span class="pln">#0000CD</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"DarkBlue"</span><span class="tag">></span><span class="pln">#00008B</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Navy"</span><span class="tag">></span><span class="pln">#000080</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"><color</span><span class="pln"> </span><span class="atn">name</span><span class="pun">=</span><span class="atv">"Black"</span><span class="tag">></span><span class="pln">#000000</span><span class="tag"></color></span><span class="pln">
</span><span class="tag"></resources></span></code></pre>
</blockquote>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-9123304353398647862015-06-15T17:13:00.003+07:002015-06-15T17:13:40.104+07:00How to install Google Play Services on Genymotion Step by StepDue to Genymotion's fluidness and ease of use, it now becomes the
most popular android emulator allows android developers to test their
app directly on their computer.<br />
However, it still lacks of Google Services just like Google Play
Store, Google Maps, etc. on Genymotion emulator which makes us developer
not be able to test those functionalities that use Google Services for
example GCM Push Notifications or Google Maps.<br />
Anyway it is not a problem anymore since there is some simple steps
to do to make Google Services be avaiable on Genymotion with some help
from <strong>CyanogenMod's gapps</strong>.<br />
<strong>Step 1: Install ARM Translation</strong> - The secret behind
Genymotion's fluidness is its ROM is compiled to x86 to match the most
popular computer's CPU Architecture. But CyanogenMod's gapps is compiled
in ARM. That's the reason why we can't just simply install gapps on
Genymotion. To make it works, we need to install an <strong>ARM Translation</strong> which will let those ARM apps be able to run on this x86 virtual device.<br />
To install, download <a href="http://filetrip.net/dl?4SUOrdcMRv" target="_blank">Genymotion-ARM-Translation_v1.1zip</a> and
then drop&drop the downloaded file to an opened Genymotion virtual
device. After file transfering is done, there will be a confirmation
dialog like below. Just simple click <strong>OK</strong> to flash it on virtual device.<br />
<img alt="armtranslationflash" class="width-100percent" src="http://inthecheesefactory.com/uploads/source/genymotion/armtranslationflash.jpg" /><br />
There will be an another dialog to let you know that the flashing process is done.<br />
<img alt="armtranslationflashed" class="width-100percent" src="http://inthecheesefactory.com/uploads/source/genymotion/armtranslationflashed.jpg" /><br />
You need to reboot the virtual device now but we don't suggest to
just close the virtual device and relaunch it once again since it may
leads to some weird behaviour. To make it done completely find, you need
to reboot the device through command line like this:<br />
<div>
<div class="syntaxhighlighter bash" id="highlighter_458574">
<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td class="gutter"><div class="line number1 index0 alt2">
1</div>
</td><td class="code"><div class="container">
<div class="line number1 index0 alt2">
<code class="bash plain">adb reboot</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
In case you accidentally close the virtual device, don't be panic.
You might need to relaunch for a few times before it can boot up.<br />
<strong>Step 2: Install gapps</strong> - Before we go on to the next step, you need to download the flashable zip of gapps by your virtual device's Android version:<br />
<a href="https://www.androidfilehost.com/?fid=95784891001614559" target="_blank">Android 5.0.x</a>, <a href="https://www.androidfilehost.com/?fid=95832962473395379" target="_blank">Android 4.4.x</a>, <a href="http://goo.im/gapps/gapps-jb-20130813-signed.zip" target="_blank">Android 4.3.x</a>, <a href="http://goo.im/gapps/gapps-jb-20130812-signed.zip" target="_blank">Android 4.2.x</a>, <a href="http://goo.im/gapps/gapps-jb-20121011-signed.zip" target="_blank">Android 4.1.x</a>, <a href="https://www.androidfilehost.com/?fid=22979706399755108" target="_blank">Android 4.0.x</a>, <a href="https://www.androidfilehost.com/?fid=22979706399755027" target="_blank">Android 2.3.3</a><br />
And then drop&drop the downloaded file to a virtual device like previous and go through the flashing process.<br />
<img alt="flashgapps" class="width-100percent" src="http://inthecheesefactory.com/uploads/source/genymotion/flashgapps.jpg" /><br />
Reboot the virtual device once again.<br />
<div>
<div class="syntaxhighlighter bash" id="highlighter_582961">
<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td class="gutter"><div class="line number1 index0 alt2">
1</div>
</td><td class="code"><div class="container">
<div class="line number1 index0 alt2">
<code class="bash plain">adb reboot</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
After the virtual device is booted up, you will notice that <strong>Google Play services has stopped</strong> problem will keep popping up like this:<br />
<img alt="unfortunate" class="width-100percent" src="http://inthecheesefactory.com/uploads/source/genymotion/unfortunate.jpg" /><br />
Don't be surprised and don't panic. You did it all right. This error
happens because the installed gapps is just too old and didn't match the
latest ROM Genymotion provided. All you need to do is be patient and
login to Google Play Store and update all of installed app.<br />
<img alt="updateall" class="width-100percent" src="http://inthecheesefactory.com/uploads/source/genymotion/updateall.jpg" /><br />
And also don't forget to update <strong>Google Play Services</strong> as well. It should be notified through the device's notification area after your pressed the <em>Update All</em> button in Google Play Store.<br />
Congratulations, Google Play Services are now available on your
Genymotion virtual device. A by-product of this installation is you are
also able to run the app compiled in ARM on Genymotion as well.<br />
<img alt="done" class="width-100percent" src="http://inthecheesefactory.com/uploads/source/genymotion/done.jpg" /><br />
Hope you find this article helpful. =)<br />
<strong>Source:</strong> <a href="http://forum.xda-developers.com/showthread.php?t=2528952" target="_blank">XDA-Developers</a>, <a href="http://wiki.cyanogenmod.org/w/Google_Apps" target="_blank">CyanogenMod</a>2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-1829519606775279972015-06-05T10:04:00.000+07:002015-06-12T10:34:22.858+07:00Each Navigation Drawer Hides a ViewDragHelperRecently, at the Google I/O 2013, two new layouts have been introduced: <code>SlidingPaneLayout</code>, a view that can be dragged from bottom to top and vice versa and the <code>DrawerLayout</code>, now used in almost all Google applications. Both of these use a new concept to more easily manage dragging: the <b>ViewDragHelper</b>.<br />
In this article, I’m going to talk about the ViewDragHelper (aka VDH)
because making a custom layout with dragging child view may be pain
sometimes. First, I will show you how to use it and how it works (the
main lines). Secondly, I will expose you a use case where the VDH is
really useful.<br />
<a href="http://flavienlaurent.com/media/2013-08-28-each-navigation-drawer-hides-a-viewdraghelper/sample.apk">Download Sample Application</a><br />
<h1>
API design</h1>
<h2>
In a few words</h2>
There are some important points to remember about VDH:<br />
<ul>
<li>a <code>ViewDragHelper.Callback</code> is used as a communication channel between parent view and VDH</li>
<li>there is a static factory method to create a VDH instance</li>
<li>you can configure the drag direction as you want</li>
<li>a drag can be detected from edge even if there is no view to capture (left, right, top, bottom)</li>
</ul>
Remember to read the official documentation: <a href="http://developer.android.com/reference/android/support/v4/widget/ViewDragHelper.html">ViewDragHelper</a> and <a href="http://developer.android.com/reference/android/support/v4/widget/ViewDragHelper.Callback.html">ViewDragHelper.Callback</a><br />
<h2>
Reading the source code</h2>
The VDH and its callback are available in the support-v4 library. You can read the source code : <a href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/widget/ViewDragHelper.java">ViewDragHelper</a> and <a href="http://developer.android.com/reference/android/support/v4/widget/ViewDragHelper.Callback.html">ViewDragHelper.Callback</a>.<br />
It uses some common classes of the framework : a <a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/view/VelocityTracker.java">VelocityTracker</a> for tracking fingling and other touch events and a <a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/Scroller.java">Scroller</a> to scroll views when it’s needed.<br />
You must read the source code as much as possible because first, it’s
very interesting and then if you know how it works, you will be able to
use it in a better way.<br />
<h1>
Using the VDH</h1>
In this section, I’m going to show you a few examples of what is
possible to configure on a VDH. Let’s begin with some initializations
and then, I will explain a few possible configurations.<br />
<h2>
VDH’s initialization</h2>
A custom <code>ViewGroup</code> extending a <code>LinearLayout</code> (<code>DragLayout</code>) with a simple child <code>View</code> (named <code>mDragView</code>).<br />
<blockquote class="tr_bq">
<pre><code class="java"><span class="line"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">DragLayout</span> <span class="kd">extends</span> <span class="n">LinearLayout</span> <span class="o">{</span>
</span><span class="line">
</span><span class="line"><span class="kd">private</span> <span class="kd">final</span> <span class="n">ViewDragHelper</span> <span class="n">mDragHelper</span><span class="o">;</span>
</span><span class="line"><span class="kd">private</span> <span class="n">View</span> <span class="n">mDragView</span><span class="o">;</span>
</span><span class="line">
</span><span class="line"><span class="kd">public</span> <span class="nf">DragLayout</span><span class="o">(</span><span class="n">Context</span> <span class="n">context</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="k">this</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="kc">null</span><span class="o">);</span>
</span><span class="line"><span class="o">}</span>
</span><span class="line">
</span><span class="line"><span class="kd">public</span> <span class="nf">DragLayout</span><span class="o">(</span><span class="n">Context</span> <span class="n">context</span><span class="o">,</span> <span class="n">AttributeSet</span> <span class="n">attrs</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="k">this</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">attrs</span><span class="o">,</span> <span class="mi">0</span><span class="o">);</span>
</span><span class="line"><span class="o">}</span>
</span><span class="line">
</span><span class="line"><span class="kd">public</span> <span class="nf">DragLayout</span><span class="o">(</span><span class="n">Context</span> <span class="n">context</span><span class="o">,</span> <span class="n">AttributeSet</span> <span class="n">attrs</span><span class="o">,</span> <span class="kt">int</span> <span class="n">defStyle</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="kd">super</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">attrs</span><span class="o">,</span> <span class="n">defStyle</span><span class="o">);</span>
</span><span class="line"><span class="o">}</span>
</span></code></pre>
</blockquote>
Create a VDH with its callback. Note that you can specify the sensivity (official documentation says <i>Multiplier
for how sensitive the helper should be about detecting the start of a
drag. Larger values are more sensitive. 1.0f is normal.</i>)<br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
</pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="kd">public</span> <span class="nf">DragLayout</span><span class="o">(</span><span class="n">Context</span> <span class="n">context</span><span class="o">,</span> <span class="n">AttributeSet</span> <span class="n">attrs</span><span class="o">,</span> <span class="kt">int</span> <span class="n">defStyle</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="kd">super</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">attrs</span><span class="o">,</span> <span class="n">defStyle</span><span class="o">);</span>
</span><span class="line"> <span class="n">mDragHelper</span> <span class="o">=</span> <span class="n">ViewDragHelper</span><span class="o">.</span><span class="na">create</span><span class="o">(</span><span class="k">this</span><span class="o">,</span> <span class="mf">1.0f</span><span class="o">,</span> <span class="k">new</span> <span class="nf">DragHelperCallback</span><span class="o">());</span>
</span><span class="line"><span class="o">}</span>
</span><span class="line">
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
The most important, don’t forget to call VDH methods in <code>onInterceptTouch</code> and <code>onTouch</code>.<br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
</pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">onInterceptTouchEvent</span><span class="o">(</span><span class="n">MotionEvent</span> <span class="n">ev</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">action</span> <span class="o">=</span> <span class="n">MotionEventCompat</span><span class="o">.</span><span class="na">getActionMasked</span><span class="o">(</span><span class="n">ev</span><span class="o">);</span>
</span><span class="line"> <span class="k">if</span> <span class="o">(</span><span class="n">action</span> <span class="o">==</span> <span class="n">MotionEvent</span><span class="o">.</span><span class="na">ACTION_CANCEL</span> <span class="o">||</span> <span class="n">action</span> <span class="o">==</span> <span class="n">MotionEvent</span><span class="o">.</span><span class="na">ACTION_UP</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="n">mDragHelper</span><span class="o">.</span><span class="na">cancel</span><span class="o">();</span>
</span><span class="line"> <span class="k">return</span> <span class="kc">false</span><span class="o">;</span>
</span><span class="line"> <span class="o">}</span>
</span><span class="line"> <span class="k">return</span> <span class="n">mDragHelper</span><span class="o">.</span><span class="na">shouldInterceptTouchEvent</span><span class="o">(</span><span class="n">ev</span><span class="o">);</span>
</span><span class="line"><span class="o">}</span>
</span><span class="line">
</span><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">onTouchEvent</span><span class="o">(</span><span class="n">MotionEvent</span> <span class="n">ev</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="n">mDragHelper</span><span class="o">.</span><span class="na">processTouchEvent</span><span class="o">(</span><span class="n">ev</span><span class="o">);</span>
</span><span class="line"> <span class="k">return</span> <span class="kc">true</span><span class="o">;</span>
</span><span class="line"><span class="o">}</span>
</span><span class="line">
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
Now, you can change the VDH behavior just by configuring the callback.<br />
<h2>
Horizontal only</h2>
Implements <code>clampViewPositionHorizontal</code> to allow horizontal drag and to bound the drag motion. Note that documentation says <i>The default implementation does not allow horizontal motion</i>.<br />
<i>You have to take margins and parent padding into consideration.</i><br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
</pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">int</span> <span class="nf">clampViewPositionHorizontal</span><span class="o">(</span><span class="n">View</span> <span class="n">child</span><span class="o">,</span> <span class="kt">int</span> <span class="n">left</span><span class="o">,</span> <span class="kt">int</span> <span class="n">dx</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="n">Log</span><span class="o">.</span><span class="na">d</span><span class="o">(</span><span class="s">"DragLayout"</span><span class="o">,</span> <span class="s">"clampViewPositionHorizontal "</span> <span class="o">+</span> <span class="n">left</span> <span class="o">+</span> <span class="s">","</span> <span class="o">+</span> <span class="n">dx</span><span class="o">);</span>
</span><span class="line">
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">leftBound</span> <span class="o">=</span> <span class="n">getPaddingLeft</span><span class="o">();</span>
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">rightBound</span> <span class="o">=</span> <span class="n">getWidth</span><span class="o">()</span> <span class="o">-</span> <span class="n">mDragView</span><span class="o">.</span><span class="na">getWidth</span><span class="o">();</span>
</span><span class="line">
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">newLeft</span> <span class="o">=</span> <span class="n">Math</span><span class="o">.</span><span class="na">min</span><span class="o">(</span><span class="n">Math</span><span class="o">.</span><span class="na">max</span><span class="o">(</span><span class="n">left</span><span class="o">,</span> <span class="n">leftBound</span><span class="o">),</span> <span class="n">rightBound</span><span class="o">);</span>
</span><span class="line">
</span><span class="line"> <span class="k">return</span> <span class="n">newLeft</span><span class="o">;</span>
</span><span class="line"><span class="o">}</span>
</span><span class="line">
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
<img src="http://flavienlaurent.com/media/2013-08-28-each-navigation-drawer-hides-a-viewdraghelper/hdrag.gif" /><br />
<h2>
Vertical only</h2>
Implements <code>clampViewPositionVertical</code> to allow horizontal drag and to bound the drag motion. Note that documentation says <i>The default implementation does not allow vertical motion</i>.<br />
<i>You have to take margins and parent padding into consideration. Not like in the code below</i><br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
</pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">int</span> <span class="nf">clampViewPositionVertical</span><span class="o">(</span><span class="n">View</span> <span class="n">child</span><span class="o">,</span> <span class="kt">int</span> <span class="n">top</span><span class="o">,</span> <span class="kt">int</span> <span class="n">dy</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">topBound</span> <span class="o">=</span> <span class="n">getPaddingTop</span><span class="o">();</span>
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">bottomBound</span> <span class="o">=</span> <span class="n">getHeight</span><span class="o">()</span> <span class="o">-</span> <span class="n">mDragView</span><span class="o">.</span><span class="na">getHeight</span><span class="o">();</span>
</span><span class="line">
</span><span class="line"> <span class="kd">final</span> <span class="kt">int</span> <span class="n">newTop</span> <span class="o">=</span> <span class="n">Math</span><span class="o">.</span><span class="na">min</span><span class="o">(</span><span class="n">Math</span><span class="o">.</span><span class="na">max</span><span class="o">(</span><span class="n">top</span><span class="o">,</span> <span class="n">topBound</span><span class="o">),</span> <span class="n">bottomBound</span><span class="o">);</span>
</span><span class="line">
</span><span class="line"> <span class="k">return</span> <span class="n">newTop</span><span class="o">;</span>
</span><span class="line"><span class="o">}</span>
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
<img src="http://flavienlaurent.com/media/2013-08-28-each-navigation-drawer-hides-a-viewdraghelper/vdrag.gif" /><br />
<h2>
Capture or not capture a view</h2>
Implements <code>tryCaptureView</code> to allow a child view to be captured. Here, there are two child views (<code>mDragView1</code> and <code>mDragView2</code>) but only one (<code>mDragView1</code>) is draggable.<br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
</pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">boolean</span> <span class="nf">tryCaptureView</span><span class="o">(</span><span class="n">View</span> <span class="n">child</span><span class="o">,</span> <span class="kt">int</span> <span class="n">pointerId</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="k">return</span> <span class="n">child</span> <span class="o">==</span> <span class="n">mDragView1</span><span class="o">;</span>
</span><span class="line"><span class="o">}</span>
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
<img src="http://flavienlaurent.com/media/2013-08-28-each-navigation-drawer-hides-a-viewdraghelper/capture.gif" /><br />
<h2>
DragRange</h2>
Implements <code>getViewHorizontalDragRange</code> or <code>getViewVerticalDragRange</code> to returns the range of horizontal|vertical drag in pixels. This range is used by the VDH when you call <code>smoothSlideViewTo</code> or <code>settleCapturedViewAt</code> to calculate the scroll duration. Also, it’s used to check the horizontal|vertical touch slop.<br />
<h2>
Edge dragging</h2>
This feature is used in the <code>DrawerLayout</code> with <code>EDGE_LEFT</code> and <code>EDGE_RIGHT</code>.<br />
Configure the VDH to enable edge tracking.<br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number"></span></pre>
<br /></td><td class="code"><pre><code class="java"><span class="line"><span class="n">mDragHelper</span><span class="o">.</span><span class="na">setEdgeTrackingEnabled</span><span class="o">(</span><span class="n">ViewDragHelper</span><span class="o">.</span><span class="na">EDGE_LEFT</span><span class="o">);</span>
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
Implements <code>onEdgeTouched</code> called when the configured edge is touched. <i>Note that at this time, no child view is currently captured.</i><br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers">
<span class="line-number"></span></pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">void</span> <span class="nf">onEdgeTouched</span><span class="o">(</span><span class="kt">int</span> <span class="n">edgeFlags</span><span class="o">,</span> <span class="kt">int</span> <span class="n">pointerId</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="kd">super</span><span class="o">.</span><span class="na">onEdgeTouched</span><span class="o">(</span><span class="n">edgeFlags</span><span class="o">,</span> <span class="n">pointerId</span><span class="o">);</span>
</span><span class="line"> <span class="n">Toast</span><span class="o">.</span><span class="na">makeText</span><span class="o">(</span><span class="n">getContext</span><span class="o">(),</span> <span class="s">"edgeTouched"</span><span class="o">,</span> <span class="n">Toast</span><span class="o">.</span><span class="na">LENGTH_SHORT</span><span class="o">).</span><span class="na">show</span><span class="o">();</span>
</span><span class="line"><span class="o">}</span>
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
Implements <code>onEdgeDragStarted</code> called when a real drag from the configured edge has started. <i>Note that at this time, no child view is currently captured.</i> In this method, you have to capture a child view manually.<br />
<br />
<figure class="code"><figcaption></figcaption><div class="highlight">
<table><tbody>
<tr><td class="gutter"><pre class="line-numbers"><span class="line-number"></span>
<span class="line-number"></span>
<span class="line-number"></span>
</pre>
</td><td class="code"><pre><code class="java"><span class="line"><span class="nd">@Override</span>
</span><span class="line"><span class="kd">public</span> <span class="kt">void</span> <span class="nf">onEdgeDragStarted</span><span class="o">(</span><span class="kt">int</span> <span class="n">edgeFlags</span><span class="o">,</span> <span class="kt">int</span> <span class="n">pointerId</span><span class="o">)</span> <span class="o">{</span>
</span><span class="line"> <span class="n">mDragHelper</span><span class="o">.</span><span class="na">captureChildView</span><span class="o">(</span><span class="n">mDragView2</span><span class="o">,</span> <span class="n">pointerId</span><span class="o">);</span>
</span><span class="line"><span class="o">}</span>
</span></code></pre>
</td></tr>
</tbody></table>
</div>
</figure>
<img src="http://flavienlaurent.com/media/2013-08-28-each-navigation-drawer-hides-a-viewdraghelper/edge.gif" /><br />
<h2>
A real example, the Youtube while playing layout</h2>
Recently, I’ve received an update of the Youtube app on my phone.
Before this update, the most annoying thing was to not be able to watch a
video and search the next video at the same time. They fixed this by
implementing a nice layout in which you can minimize the video view from
top to bottom.<br />
I’m going to show how to do it and how it’s simple thanks to VDH.<br />
Here is the expected result<br />
<img src="http://flavienlaurent.com/media/2013-08-28-each-navigation-drawer-hides-a-viewdraghelper/youtube.gif" /><br />
Key points:<br />
<ul>
<li><code>tryCaptureView</code> returns true only for the header view</li>
<li>drag range is calculated <code>onLayout</code></li>
<li>use VDH’s methods in <code>onInterceptTouchEvent</code> and <code>onTouchEvent</code></li>
<li>call <code>continueSettling</code> in <code>computeScroll</code> (because VDH uses a scroller)</li>
<li>use <code>smoothSlideViewTo</code> to finish the drag motion</li>
</ul>
Be careful, this layout is not well made: it’s a draft. There is
still work to do; on the scale part, touch event when the header is
scaled, <code>onLayout</code> and <code>onMeasure</code> are badly written too. Also, I don’t know if calling <code>requestLayout</code> in <code>onViewPositionChanged</code> is good solution… Anyway, if you have remarks or ideas to improve this layout, please tell me!).<br />
<br />
<figure class="code"><figcaption>activity_main.xml</figcaption><div class="highlight">
<table><tbody>
<tr></tr>
</tbody></table>
<blockquote class="tr_bq">
<pre><code class="xml"><span class="line"><span class="nt"><FrameLayout</span>
</span><span class="line">
</span><span class="line"> <span class="na">xmlns:android=</span><span class="s">"http://schemas.android.com/apk/res/android"</span>
</span><span class="line"> <span class="na">android:layout_width=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:layout_height=</span><span class="s">"match_parent"</span><span class="nt">></span>
</span><span class="line">
</span><span class="line"> <span class="nt"><ListView</span>
</span><span class="line"> <span class="na">android:id=</span><span class="s">"@+id/listView"</span>
</span><span class="line"> <span class="na">android:layout_width=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:layout_height=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:tag=</span><span class="s">"list"</span>
</span><span class="line"> <span class="nt">/></span>
</span><span class="line">
</span><span class="line"> <span class="nt"><com.example.vdh.YoutubeLayout</span>
</span><span class="line"> <span class="na">android:layout_width=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:layout_height=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:id=</span><span class="s">"@+id/youtubeLayout"</span>
</span><span class="line"> <span class="na">android:orientation=</span><span class="s">"vertical"</span>
</span><span class="line"> <span class="na">android:visibility=</span><span class="s">"visible"</span><span class="nt">></span>
</span><span class="line">
</span><span class="line"> <span class="nt"><TextView</span>
</span><span class="line"> <span class="na">android:id=</span><span class="s">"@+id/viewHeader"</span>
</span><span class="line"> <span class="na">android:layout_width=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:layout_height=</span><span class="s">"128dp"</span>
</span><span class="line"> <span class="na">android:fontFamily=</span><span class="s">"sans-serif-thin"</span>
</span><span class="line"> <span class="na">android:textSize=</span><span class="s">"25sp"</span>
</span><span class="line"> <span class="na">android:tag=</span><span class="s">"text"</span>
</span><span class="line"> <span class="na">android:gravity=</span><span class="s">"center"</span>
</span><span class="line"> <span class="na">android:textColor=</span><span class="s">"@android:color/white"</span>
</span><span class="line"> <span class="na">android:background=</span><span class="s">"#AD78CC"</span><span class="nt">/></span>
</span><span class="line">
</span><span class="line"> <span class="nt"><TextView</span>
</span><span class="line"> <span class="na">android:id=</span><span class="s">"@+id/viewDesc"</span>
</span><span class="line"> <span class="na">android:tag=</span><span class="s">"desc"</span>
</span><span class="line"> <span class="na">android:textSize=</span><span class="s">"35sp"</span>
</span><span class="line"> <span class="na">android:gravity=</span><span class="s">"center"</span>
</span><span class="line"> <span class="na">android:text=</span><span class="s">"Loreum Loreum"</span>
</span><span class="line"> <span class="na">android:textColor=</span><span class="s">"@android:color/white"</span>
</span><span class="line"> <span class="na">android:layout_width=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:layout_height=</span><span class="s">"match_parent"</span>
</span><span class="line"> <span class="na">android:background=</span><span class="s">"#FF00FF"</span><span class="nt">/></span>
</span><span class="line">
</span><span class="line"> <span class="nt"></com.example.vdh.YoutubeLayout></span>
</span><span class="line"><span class="nt"></FrameLayout></span>
</span></code></pre>
<blockquote>
<br /></blockquote>
</blockquote>
<table><tbody>
<tr><td class="code"><br /></td></tr>
</tbody></table>
</div>
</figure>
<figure class="code"><figcaption>YoutubeLayout.java</figcaption><div class="highlight">
<table><tbody>
<tr></tr>
</tbody></table>
<blockquote class="tr_bq">
<pre><code class="java"><span class="line"><span class="kd">public class YoutubeLayout extends ViewGroup{
private static final String TAG = "YoutubeLayout";
private static final int MIN_FLING_VELOCITY = 400; // dips per second
private View mHeaderView;
private View mDescView;
private float mInitialMotionX;
private float mInitialMotionY;
private int mDragRange;
private int mTop;
private float mDragOffset;
private ViewDragHelper mDragHelper;
public YoutubeLayout(Context context) {
super(context);
init(context);
}
public YoutubeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public YoutubeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context);
}
private void init(Context context) {
final float density = context.getResources().getDisplayMetrics().density;
mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}
public void maximize()
{
smoothSlideTo(0.0f);
}
public void minimize()
{
smoothSlideTo(1.0f);
}
private boolean smoothSlideTo(float slideOffset) {
final int topBound = getPaddingTop();
int y = (int) (topBound + slideOffset * mDragRange);
if(mDragHelper.smoothSlideViewTo(mHeaderView, mHeaderView.getLeft(), y))
{
ViewCompat.postInvalidateOnAnimation(this);
return true;
}
return false;
}
@Override
protected void onFinishInflate() {
Log.d(TAG, "onFInishInflate");
mHeaderView = findViewById(R.id.viewHeader);
mDescView = findViewById(R.id.viewDesc);
}
@SuppressLint("NewApi")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Log.d(TAG, "onMeasure");
measureChildren(widthMeasureSpec, heightMeasureSpec);
int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, 0), resolveSizeAndState(maxHeight, heightMeasureSpec, 0));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int parentViewHeight = getHeight();
int dragViewHeight = mHeaderView.getMeasuredHeight();
mDragRange = parentViewHeight - dragViewHeight;
mHeaderView.layout(
0,
mTop,
r,
mTop + mHeaderView.getMeasuredHeight());
mDescView.layout(
0,
mTop + mHeaderView.getMeasuredHeight(),
r,
mTop + b);
}
private class DragHelperCallback extends ViewDragHelper.Callback
{
@Override
public boolean tryCaptureView(View child, int pointerId) {
return child == mHeaderView;
}
@SuppressLint("NewApi")
@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
mTop = top;
mDragOffset = (float) top / mDragRange;
mHeaderView.setPivotX(mHeaderView.getWidth());
mHeaderView.setPivotY(mHeaderView.getHeight());
mHeaderView.setScaleX(1 - mDragOffset / 2);
mHeaderView.setScaleY(1 - mDragOffset / 2);
mDescView.setAlpha(1 - mDragOffset);
requestLayout();
}
@Override
public int clampViewPositionVertical(View child, int top, int dy) {
final int topBound = getPaddingTop();
final int bottomBound = getHeight() - mHeaderView.getHeight() - mHeaderView.getPaddingBottom();
final int newTop = Math.min(Math.max(top, topBound), bottomBound);
return newTop;
}
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
int top = getPaddingTop();
if (yvel > 0 || (yvel == 0 && mDragOffset > 0.4f)) {
top += mDragRange;
}
mDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top);
invalidate();
}
@Override
public int getViewVerticalDragRange(View child) {
return mDragRange;
}
}
@Override
public void computeScroll() {
if(mDragHelper.continueSettling(true))
{
ViewCompat.postInvalidateOnAnimation(this);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if(action != MotionEvent.ACTION_DOWN)
{
mDragHelper.cancel();
return super.onInterceptTouchEvent(ev);
}
if(action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP)
{
mDragHelper.cancel();
return false;
}
final float x = ev.getX();
final float y = ev.getY();
boolean interceptTap = false;
switch(action)
{
case MotionEvent.ACTION_DOWN:
mInitialMotionX = x;
mInitialMotionY = y;
interceptTap = mDragHelper.isViewUnder(mHeaderView, (int) x, (int) y);
break;
case MotionEvent.ACTION_MOVE:
final float adx = Math.abs(x - mInitialMotionX);
final float ady = Math.abs(y - mInitialMotionY);
final int slop = mDragHelper.getTouchSlop();
if(ady > slop && adx > ady)
{
mDragHelper.cancel();
return false;
}
break;
}
return mDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
mDragHelper.processTouchEvent(event);
final int action = event.getAction();
final float x = event.getX();
final float y = event.getY();
boolean isHeaderViewUnder = mDragHelper.isViewUnder(mHeaderView, (int)x, (int)y);
switch(action & MotionEventCompat.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
{
mInitialMotionX = x;
mInitialMotionY = y;
break;
}
case MotionEvent.ACTION_UP:
{
final float dx = x - mInitialMotionX;
final float dy = y - mInitialMotionY;
final float slop = mDragHelper.getTouchSlop();
if(dx * dx + dy * dy < slop * slop && isHeaderViewUnder)
{
if (mDragOffset == 0) {
minimize();
} else {
maximize();
}
}
break;
}
}
return isHeaderViewUnder && isViewHit(mHeaderView, (int) x, (int) y) || isViewHit(mDescView, (int) x, (int) y);
}
private boolean isViewHit(View view, int x, int y) {
int[] viewLocation = new int[2];
view.getLocationOnScreen(viewLocation);
int[] parentLocation = new int[2];
this.getLocationOnScreen(parentLocation);
int screenX = parentLocation[0] + x;
int screenY = parentLocation[1] + y;
return screenX >= viewLocation[0] && screenX < viewLocation[0] + view.getWidth() &&
screenY >= viewLocation[1] && screenY < viewLocation[1] + view.getHeight();
}
}</span></span><span class="line"><span class="o"></span>
</span></code></pre>
<blockquote>
<br /></blockquote>
</blockquote>
<table><tbody>
<tr><td class="code"><br /></td></tr>
</tbody></table>
</div>
</figure>
<br />
<h1>
Conclusion</h1>
The VDH is one of the useful but <b>unknown</b> class in the framework. Don’t hesitate to try it, use it and to appreciate it because it saves a lot of time and a lot of code!<br />
<br />
<blockquote class="tr_bq">
Source: http://flavienlaurent.com/blog/2013/08/28/each-navigation-drawer-hides-a-viewdraghelper/</blockquote>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-10450507080021336462015-05-08T12:02:00.000+07:002015-05-08T12:02:00.722+07:00Android - Countdown timer using handler1/. Create <b>CountDownHandler</b> class<br />
<blockquote class="tr_bq">
private final Runnable mCountDown = new Runnable() {<br /> public void run() {<br /> if (mCurrentCount > 0) {<br /> mCurrentCount--;<br /> } else {<br /> // Your code here<br /> }<br /> };</blockquote>
<b>Create method to start and stop countDown</b><br />
<blockquote class="tr_bq">
/**<br /> * Starts the count down animation.<br /> */<br /> public void start() {<br /> mHandler.removeCallbacks(mCountDown);<br /><br /> mTextView.setText(mStartCount + "");<br /> mTextView.setVisibility(View.VISIBLE);<br /><br /> mCurrentCount = mStartCount;<br /><br /> mHandler.post(mCountDown);<br /> for (int i = 1; i <= mStartCount; i++) {<br /> mHandler.postDelayed(mCountDown, i * 1000);<br /> }<br /> }<br /><br /> /**<br /> * Cancels the count down animation.<br /> */<br /> public final void cancel() {<br /> mHandler.removeCallbacks(mCountDown);<br /> }</blockquote>
<blockquote class="tr_bq">
/**<br /> * Sets a new starting count number for the count down animation.<br /> * <br /> * @param startCount<br /> * The starting count number<br /> */<br /> public void setStartCount(int startCount) {<br /> this.mStartCount = startCount;<br /> }<br /><br /> /**<br /> * Returns the starting count number for the count down animation.<br /> */<br /> public int getStartCount() {<br /> return mStartCount;<br /> }<br /> </blockquote>
<br />
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b><a href="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="-webkit-transition: all 0.4s ease-in-out; box-sizing: border-box; color: #999999; font-family: Verdana, Geneva, sans-serif; font-size: 11px; line-height: 17.59375px; margin-left: 1em; margin-right: 1em; max-width: 100%; text-align: center; text-decoration: none; transition: all 0.4s ease-in-out;"><img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></a></b></h3>
Anonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-74047365175265679122015-05-06T11:06:00.001+07:002015-05-06T11:06:14.387+07:00Android: Understanding Activity launch mode<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2 blog-post-body">
Before I dive into the launch mode of an activity, we need
to first understand the term, 'Task'. A task is the stack ("Last in,
First out") which contains a collection of activity instances. Normally,
when a user starts an app a new task will be created, and the first
activity instance is called as a root of the task. The Android system
can hold multiple tasks at the same time and only one task is in the
foreground. Similar to a double click of the home key on iOS, if you
long press the HOME key on Android you'll be presented with a list of
your currently running applications. You can select any one of these
applications (which are currently running in the background) in order to
bring it to the foreground and interact with the app! Of course,
because background tasks do tend to use up your processor cycles you
should try to keep your backgrounded apps to a minimum to ensure your
phone performs optimally.<br />
Now let's look at the launch mode of an activity. Launch mode allows
you to define how a new instance or the existing instance of an activity
is associated with the current task. The activity launch mode has four
valid values: <br />
<div class="gist" id="gist1022415">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="file-data">
<table cellpadding="0" cellspacing="0" class="lines highlight">
<tbody>
<tr>
<td class="line-numbers">
<span class="line-number" id="file-activity-launchmode-xml-L1" rel="file-activity-launchmode-xml-L1">1</span>
</td>
<td class="line-data">
<pre class="line-pre"><div class="line" id="file-activity-launchmode-xml-LC1">
<<span class="pl-ent">activity</span> android:launchMode = [<span class="pl-s1"><span class="pl-pds">"</span>standard<span class="pl-pds">"</span></span> | <span class="pl-s1"><span class="pl-pds">"</span>singleTop<span class="pl-pds">"</span></span> | <span class="pl-s1"><span class="pl-pds">"</span>singleTask<span class="pl-pds">"</span></span> | <span class="pl-s1"><span class="pl-pds">"</span>singleInstance<span class="pl-pds">"</span></span>] ../>
</div>
</pre>
</td>
</tr>
</tbody></table>
</div>
</div>
<div class="gist-meta">
<a href="https://gist.github.com/Yincan/1022415/raw/activity-launchmode.xml" style="float: right;">view raw</a>
<a href="https://gist.github.com/Yincan/1022415#file-activity-launchmode-xml">activity-launchmode.xml</a>
hosted with ❤ by <a href="https://github.com/">GitHub</a>
</div>
</div>
</div>
The 'standard' is the default value. The four values fall into two groups:
<br />
<ul>
<li> 'standard' and 'singleTop' can instantiate multiple activity instances and the instance will stay in the same task.</li>
<li>For 'singleTask' or 'singleInstance', the activity class uses the
singleton pattern, and that instance will be the root activity of a new
task. Let's examine each value: </li>
</ul>
<h2>
"standard":</h2>
Multiple instances of the activity class can be instantiated and
multiple instances can be added to the same task or different tasks.
This is the common mode for most of the activities.
<br />
<h2>
"singleTop":</h2>
The difference from 'standard' is, if an instance of activity already
exists at the top of the current task and system routes intent to this
activity, no new instance will be created because it will fire off an
onNewIntent() method instead of creating a new object. Let's take the
Twitter-oauth integration as example. Suppose we have the following
NewsDetailActivity declared:<br />
<div class="gist" id="gist1022415">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="file-data">
<table cellpadding="0" cellspacing="0" class="lines highlight">
<tbody>
<tr>
<td class="line-numbers">
<span class="line-number" id="file-singletop-xml-L6" rel="file-singletop-xml-L6"></span> <span class="line-number" id="file-singletop-xml-L7" rel="file-singletop-xml-L7"></span><span class="line-number" id="file-singletop-xml-L8" rel="file-singletop-xml-L8"></span>
</td>
<td class="line-data">
<blockquote class="tr_bq">
<pre class="line-pre"><div class="line" id="file-singletop-xml-LC8">
<activity android:name=".NewsDetailActivity" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="oauth" android:host="twitt"></data>
</intent-filter>
</activity>
</div>
</pre>
</blockquote>
</td>
</tr>
</tbody></table>
</div>
</div>
<div class="gist-meta">
<a href="https://gist.github.com/Yincan/1022415/raw/singletop.xml" style="float: right;">view raw</a>
<a href="https://gist.github.com/Yincan/1022415#file-singletop-xml">singletop.xml</a>
hosted with ❤ by <a href="https://github.com/">GitHub</a>
</div>
</div>
</div>
And in the activity we will have the following code to start the
oAuth process which will bring up the browser to visit Twitter's
authorization page: <br />
<div class="gist" id="gist1022415">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="file-data">
<table cellpadding="0" cellspacing="0" class="lines highlight">
<tbody>
<tr>
<td class="line-numbers">
<span class="line-number" id="file-start-twitter-oauth-java-L1" rel="file-start-twitter-oauth-java-L1"></span><span class="line-number" id="file-start-twitter-oauth-java-L27" rel="file-start-twitter-oauth-java-L27"></span>
</td>
<td class="line-data">
<blockquote class="tr_bq">
<pre class="line-pre"><div class="line" id="file-start-twitter-oauth-java-LC27">
private void twitterOAuth() {
try {
System.setProperty("twitter4j.http.useSSL", "false");
System.setProperty("twitter4j.oauth.consumerKey", getString(R.string.twitter_oauth_consumer_key));
System.setProperty("twitter4j.oauth.consumerSecret", getString(R.string.twitter_oauth_consumer_secret));
System.setProperty("twitter4j.oauth.requestTokenURL", "http://api.twitter.com/oauth/request_token");
System.setProperty("twitter4j.oauth.accessTokenURL", "http://api.twitter.com/oauth/access_token");
System.setProperty("twitter4j.oauth.authorizationURL", "http://api.twitter.com/oauth/authorize");
// get the instance
Twitter twitter = new TwitterFactory().getInstance();
twitter4j.auth.RequestToken requestToken = twitter.getOAuthRequestToken(CALLBACK_URL);
//save the request token and secret
prefsManager.saveTwitterRequestToken(requestToken.getToken(), requestToken.getTokenSecret());
//save other data
persistNewsDatas();
//start the browser activity
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL()));
startActivity(intent);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
Toast.makeText(NewsDetailActivity.this, "Fail to connect to twitter now, please try later.",
Toast.LENGTH_SHORT).show();
}
}
</div>
</pre>
</blockquote>
</td>
</tr>
</tbody></table>
</div>
</div>
<div class="gist-meta">
<a href="https://gist.github.com/Yincan/1022415/raw/start-twitter-oauth.java" style="float: right;">view raw</a>
<a href="https://gist.github.com/Yincan/1022415#file-start-twitter-oauth-java">start-twitter-oauth.java</a>
hosted with ❤ by <a href="https://github.com/">GitHub</a>
</div>
</div>
</div>
So if a user goes to this activity in the current task (let's say
Task #1), a new instance of NewsDetailActivity will be pushed to the
top. Now start the oAuth process and the Android system routes the
intent to the default Android Browser application, whose launch mode is
'singleTask'; that means a new Task begins for the browser activity,
let's say Task #2. Hence the 'NewDetailActivity' is still on top of the
Task #1. <br />
After the user finishes the authorization on Twitter's page, the
customized callback url 'oauth://twitter' will be invoked. Because
NewsDetailActivity declares support for that data type, the system
routes the intent to the 'NewsDetailActivity'. Since
NewsDetailActivity's launch mode is 'singleTop', and the top instance on
Task #1 will be reused, its onNewIntent() method will be invoked to
continue oAuth's last step. Here is the code for that:<br />
<div class="gist" id="gist1022415">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="file-data">
<table cellpadding="0" cellspacing="0" class="lines highlight">
<tbody>
<tr>
<td class="line-numbers">
<span class="line-number" id="file-onnewintent-java-L1" rel="file-onnewintent-java-L1"></span><span class="line-number" id="file-onnewintent-java-L23" rel="file-onnewintent-java-L23"></span>
</td>
<td class="line-data">
<blockquote class="tr_bq">
<pre class="line-pre"><div class="line" id="file-onnewintent-java-LC23">
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Uri uri = intent.getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
String verifier = uri.getQueryParameter("oauth_verifier");
try {
//load other persisted data goes here
....
//get the request-token from prefs and request the access token
TwitterFactory twitter = new TwitterFactory().getInstance();
requestToken = prefsManager.getRequestToken();
prefsManager.clearTwitterRequestToken();
twitter4j.auth.AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
// save the access token
prefsManager.saveTwitterOauth(accessToken.getToken(), accessToken.getTokenSecret(), accessToken
.getScreenName());
//other logics to do the post to twitter
....
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}
</div>
</pre>
</blockquote>
</td>
</tr>
</tbody></table>
</div>
</div>
<div class="gist-meta">
<a href="https://gist.github.com/Yincan/1022415/raw/onNewIntent.java" style="float: right;">view raw</a>
<a href="https://gist.github.com/Yincan/1022415#file-onnewintent-java">onNewIntent.java</a>
hosted with ❤ by <a href="https://github.com/">GitHub</a>
</div>
</div>
</div>
<h2>
"singleTask":</h2>
A new task will always be created and a new instance will be pushed to
the task as the root one. However, if any activity instance exists in
any tasks, the system routes the intent to that activity instance
through the onNewIntent() method call. In this mode, activity instances
can be pushed to the same task. And if the user clicks the BACK key
from the singleTask activity, the system will return the user to the
previous activity. <br />
This mode is useful for activities that act as the entry points. For
example, in a tab-based Twitter client, we can declare the main
TabActivity as singleTask. This is also useful if you only want a single
instance of the activity to be created. One example of singleTask is
the Browser application. Let's take a Twitter-client-application as
example, where the main activity is a TabActivity and has three tabs:
tweets, replies and messages. And we want to suppose auto-refresh and
notification function when app is running. <br />
In AndroidManifest.xml, we have: <br />
<div class="gist" id="gist1022415">
<div class="gist-file">
<div class="gist-data gist-syntax">
<div class="file-data">
<table cellpadding="0" cellspacing="0" class="lines highlight">
<tbody>
<tr>
<td class="line-numbers">
<span class="line-number" id="file-singletask-xml-L1" rel="file-singletask-xml-L1">1</span>
<span class="line-number" id="file-singletask-xml-L2" rel="file-singletask-xml-L2">2</span>
</td>
<td class="line-data">
<pre class="line-pre"><div class="line" id="file-singletask-xml-LC1">
<<span class="pl-ent">activity</span> <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">name</span>=<span class="pl-s1"><span class="pl-pds">"</span>.MainTabActivity<span class="pl-pds">"</span></span> <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">launchMode</span>=<span class="pl-s1"><span class="pl-pds">"</span>singleTask<span class="pl-pds">"</span></span> <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">alwaysRetainTaskState</span>=<span class="pl-s1"><span class="pl-pds">"</span>true<span class="pl-pds">"</span></span> <span class="pl-e">android</span><span class="pl-e">:</span><span class="pl-e">windowSoftInputMode</span>=<span class="pl-s1"><span class="pl-pds">"</span>adjustPan<span class="pl-pds">"</span></span>>
</div>
<div class="line" id="file-singletask-xml-LC2">
</<span class="pl-ent">activity</span>>
</div>
</pre>
</td>
</tr>
</tbody></table>
</div>
</div>
<div class="gist-meta">
<a href="https://gist.github.com/Yincan/1022415/raw/singleTask.xml" style="float: right;">view raw</a>
<a href="https://gist.github.com/Yincan/1022415#file-singletask-xml">singleTask.xml</a>
hosted with ❤ by <a href="https://github.com/">GitHub</a>
</div>
</div>
</div>
Suppose we have the notification for new tweet/replies/messages, and we
hope that clickong on the notification will take the user to the current
TabActivity, and switch to corresponding tabs. (Here we suppose the app
is not closed before user clicks the notification). Because the
MainTabActivity's launch mode is singleTask, system routes the intent
to the MainTabActivity by calling its onNewIntent() method. And in this
method, we can determine which tab to switch to according to the bundle
data in the intent.
<br />
<h2>
"singleInstance":</h2>
Same as 'singleTask', except that the no activities instance can be
pushed into the same task of the singleInstance's. That means, the
activity with launch mode is always in a single activity instance task.
This is a very specialized mode and should only be used in the
applications that are implemented entirely as one activity.
<br />
<h2>
Summary:</h2>
Understanding the launch mode will help you design better navigation and
implement some special cases. Here we only discuss the launch mode from
the AndroidManifest file. Android launch mode can also be declared
using the Intent flags, such as FLAG_ACTIVITY_NEW_TASK,
FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP. And we will create
more posts to talking about intent flags in the near future, so stay
tuned!<br />
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b></b></h3>
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter,arial,sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: left;">
<b><a href="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="-webkit-transition: all 0.4s ease-in-out; box-sizing: border-box; color: #999999; font-family: Verdana, Geneva, sans-serif; font-size: 11px; line-height: 17.59375px; margin-left: 1em; margin-right: 1em; max-width: 100%; text-align: center; text-decoration: none; transition: all 0.4s ease-in-out;">for more informations: http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode</a></b></h3>
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b> <img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></b></h3>
<br />
</div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-29833176405569327652015-05-06T10:56:00.001+07:002015-05-06T10:56:42.268+07:00[Resolve] After Installation of apk “Open” and “Done” button shows, onclick of Open button it's not adding categor as launcher<br />
Android issue:
This issue is coming only 1st time after installation and clicking on
open button, after launching application with launcher icon then issue
will never come.
<br />
<br />
<ul>
<li>Steps to reproduce the problem.<br />
<ol>
<li>Install Any .apk file </li>
<li>After installation you will get two buttons "Open" and "Done".</li>
<li>Onclick of Open button it's opening/starting application.</li>
<li>now Navigate in you application and go to any other screen, like on 2nd screen, 3rd screen.</li>
<li>Now, Press Home and put application in background (means put in pause sate).</li>
<li>Now go to list of application Click on Launcher Icon of same application.</li>
</ol>
</li>
<li>What happened.<br />
<ol>
<li>It is Launching Same application from start point at first screen.</li>
<li>It must resume the running application on 3rd screen.</li>
<li>Now press back and come out from 1st screen of 2nd time started application.</li>
<li>It is showing 1st time run application's 3rd screen.</li>
</ol>
</li>
</ul>
I have explain you general behavior after installation and start app with open button.
In my application it create inconsistent state of 2 times started application.<br />
<ul>
<li>What you think the correct behavior should be.<br />
<ol>
<li>Application must resume.</li>
<li>application must not come in inconsistent state.</li>
</ol>
</li>
</ul>
I have some logs..<br />
<ul>
<li>Clicking on "Open" button logs :</li>
</ul>
10-04 21:45:28.703: INFO/ActivityManager(243): Starting activity:
Intent { act=android.intent.action.MAIN flg=0x10000000
cmp=com.test/.TestnewversionActivity } from pid 15146.<br />
"See no category added in intent above"<br />
<ul>
<li>Clicking on "Launcher" Icon’s logs :</li>
</ul>
10-04 21:46:46.109: INFO/ActivityManager(243): Starting activity:
Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] flg=0x10200000
cmp=com.test/.TestnewversionActivity } from pid 428<br />
"See category added in intent above".<br />
If some one tell me how to Resolve this or tell how to add category
as android.intent.category.LAUNCHER on "Open" button click then problem
will resolve.<br />
I have tried to add category in intent on app start, oncreate and many places.
intent.addCategory("android.intent.category.LAUNCHER");
Also tried to work with IntentFilter, PackageManager.<br />
This issue is in every Android phone.<br />
<br />
<b>RESOLVE</b> <br />
Add this code into oncreate() method<br />
<blockquote class="tr_bq">
if (!isTaskRoot()) {<br /> final Intent intent = getIntent();<br /> final String intentAction = intent.getAction();<br /> if (intent.hasCategory(Intent.CATEGORY_LAUNCHER)<br /> && intentAction != null<br /> && intentAction.equals(Intent.ACTION_MAIN)) {<br /> finish();<br /> }<br /> }</blockquote>
More informations: <a href="http://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508#16447508">http://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508#16447508</a> <br />
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b><a href="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="-webkit-transition: all 0.4s ease-in-out; box-sizing: border-box; color: #999999; font-family: Verdana, Geneva, sans-serif; font-size: 11px; line-height: 17.59375px; margin-left: 1em; margin-right: 1em; max-width: 100%; text-align: center; text-decoration: none; transition: all 0.4s ease-in-out;"><img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></a></b></h3>
Anonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-33901048425390504892015-04-28T14:37:00.001+07:002015-04-28T14:37:09.540+07:00FIX “THIS COMPUTER DOES NOT SUPPORT INTEL VIRTUALIZATION TECHNOLOGY (VT-X). HAXM CANNOT BE INSTALLED” ERROR WHEN INSTALLING HAXM FOR ANDROID EMULATOR<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
Well if you are a mobile developer you would try developing apps for several platforms. I know I do <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span> And when you do you need to test the apps you build on either real devices or on Emulators. Most of us test the apps on the emulators first and then go for the real device.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
As you know, Android Emulator is just F***ing ridiculously slow when it comes to testing on it. One way of giving the Android Emulator an <span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">ADRENALIN SHOT</span> is to use the Intel Hardware Accelerated Execution Manager (HAXM) to boot the performance of the Android Emulator. I have written a post about this. You can find it <a href="https://wpdevkvk.wordpress.com/2014/05/21/boost-you-android-emulator/" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;" target="_blank" title="Boost you Android Emulator">here</a>.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
But sometimes when you try to install HAXM you run in to this error even when you have all the requirements fulfilled.</div>
<figure class="wp-caption alignnone" data-shortcode="caption" id="attachment_183" style="color: #767676; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px; max-width: 100%; width: 509px;"><a href="https://wpdevkvk.files.wordpress.com/2014/12/error.png" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="Error message" class="size-full wp-image-183" src="https://wpdevkvk.files.wordpress.com/2014/12/error.png?w=474" style="border: 0px; display: block; height: auto; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><figcaption class="wp-caption-text" style="box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0px;">Error message</figcaption></figure><div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
On windows platform this happens when you have Hyper-V enabled in your system. I ran in to this problem when I try to install HAXM with Hyper-V enabled. I do Windows Phone development. I LOVE WP <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span> so I need to have Hyper-V enabled to use the <span style="border: 0px; font-family: inherit; font-style: inherit; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">AWESOME</span>Windows Phone Emulator. I recently started developing for Android as well so I needed to have both Development tools installed on my Windows 8.1 installation. But when I try to install HAXM to boost my Android Emulator the problem starts.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
You need to have Hyper-V disabled in Windows to use HAXM with your Android Emulator. So there is a fix for this by editing your Boot Configuration. The end result is that you will have 2 boot configurations for Android and Windows Phone development. Enough chit chat. Let’s get down to business <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span></div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
Open up a Command Prompt with Administrator privileges and enter the following command.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
<div class="syntaxhighlighter cpp" id="highlighter_23428" style="background-color: white !important; border: 0px; font-family: inherit; font-size: 1em !important; font-style: inherit; font-weight: inherit; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 474px;">
<table border="0" cellpadding="0" cellspacing="0" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 614px;"><tbody style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="gutter" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-width: 0px 3px 0px 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
1</div>
</td><td class="code" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 578px;"><div class="container" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="cpp plain" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">bcdedit /copy {current} /d “Windows 8.1 – Pro – No Hypervisor”</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
This copies your current boot configuration with the name you specified with in quotes (in this case the name is Windows 8.1 – Pro – No Hypervisor). You will see a message after stating “The entry was successfully copied to { identifier }” with the id of the new Boot configuration. See the image bellow.</div>
<figure class="wp-caption alignnone" data-shortcode="caption" id="attachment_178" style="color: #767676; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px; max-width: 100%; width: 660px;"><a href="https://wpdevkvk.files.wordpress.com/2014/12/17.png" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="Copy the current boot configuration" class="size-large wp-image-178" src="https://wpdevkvk.files.wordpress.com/2014/12/17.png?w=474&h=297" style="border: 0px; display: block; height: auto; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><figcaption class="wp-caption-text" style="box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0px;">Copy the current boot configuration</figcaption></figure><div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
Then type the following command in the command prompt.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
<div class="syntaxhighlighter cpp" id="highlighter_332081" style="background-color: white !important; border: 0px; font-family: inherit; font-size: 1em !important; font-style: inherit; font-weight: inherit; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 474px;">
<table border="0" cellpadding="0" cellspacing="0" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 474px;"><tbody style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="gutter" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-width: 0px 3px 0px 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
1</div>
</td><td class="code" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 438px;"><div class="container" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="cpp plain" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">bcdedit</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
This will now show you all the boot configurations available in your system. You can see the previous Boot configuration and the new boot configuration at the bottom with the name you gave (actually the name is the description <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span> ) Look closely at the bottom of the information. You can see that the value “hypervisorlaunchtype” is set to “Auto”. To disable Hyper-V we need to change this value. Look at the image bellow.</div>
<figure class="wp-caption alignnone" data-shortcode="caption" id="attachment_179" style="color: #767676; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px; max-width: 100%; width: 660px;"><a href="https://wpdevkvk.files.wordpress.com/2014/12/21.png" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="See all available boot configurations." class="size-large wp-image-179" src="https://wpdevkvk.files.wordpress.com/2014/12/21.png?w=474&h=540" style="border: 0px; display: block; height: auto; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><figcaption class="wp-caption-text" style="box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0px;">See all available boot configurations.</figcaption></figure><div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
Copy the unique identifier of the copied boot configuration. Next type the following command in to the command prompt</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
<div class="syntaxhighlighter cpp" id="highlighter_355236" style="background-color: white !important; border: 0px; font-family: inherit; font-size: 1em !important; font-style: inherit; font-weight: inherit; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 0px; position: relative !important; vertical-align: baseline; width: 474px;">
<table border="0" cellpadding="0" cellspacing="0" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border-spacing: 0px; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; table-layout: auto !important; top: auto !important; vertical-align: baseline !important; width: 508px;"><tbody style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<tr style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><td class="gutter" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;"><div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-width: 0px 3px 0px 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
1</div>
</td><td class="code" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 472px;"><div class="container" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">
<div class="line number1 index0 alt2" style="-webkit-box-shadow: none !important; background-attachment: initial !important; background-clip: initial !important; background-image: none !important; background-origin: initial !important; background-position: initial !important; background-repeat: initial !important; background-size: initial !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;">
<code class="cpp plain" style="-webkit-box-shadow: none !important; background: none !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; box-shadow: none !important; box-sizing: content-box !important; direction: ltr !important; display: inline !important; float: none !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;">bcdedit /set {identifier} hypervisorlaunchtype off</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
here in the { identifier }, replace it with the unique identifier you copied (that is of the new boot configuration you copied). Then you should get a message that the operation completed successfully. See the image below.</div>
<figure class="wp-caption alignnone" data-shortcode="caption" id="attachment_180" style="color: #767676; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px; max-width: 100%; width: 660px;"><a href="https://wpdevkvk.files.wordpress.com/2014/12/31.png" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="Disable hyper-visor on the new boot configuration " class="size-large wp-image-180" src="https://wpdevkvk.files.wordpress.com/2014/12/31.png?w=474&h=290" style="border: 0px; display: block; height: auto; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><figcaption class="wp-caption-text" style="box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0px;">Disable hyper-visor on the new boot configuration</figcaption></figure><div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
Then run the bcdedit command again in the prompt. Now you can see in the new boot configuration ‘hypervisorlaunchtype’ is set to off. See below.</div>
<figure class="wp-caption alignnone" data-shortcode="caption" id="attachment_181" style="color: #767676; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px; max-width: 100%; width: 660px;"><a href="https://wpdevkvk.files.wordpress.com/2014/12/41.png" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="Confirm that hyper-visor is off in the new configuration " class="size-large wp-image-181" src="https://wpdevkvk.files.wordpress.com/2014/12/41.png?w=474&h=539" style="border: 0px; display: block; height: auto; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><figcaption class="wp-caption-text" style="box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0px;">Confirm that hyper-visor is off in the new configuration</figcaption></figure><div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now its done folks <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span> you are good to go. Restart your PC. Just before the login screen you will be presented a screen saying “Choose an Operating System”. There you can see the Old boot configuration and the newly created boot configuration. To install HAXM you need to click and boot in to the new boot configuration. In this case it’s the Second option. ‘Windows 8.1 Pro – No Hypervisor’.See the image bellow.</div>
<figure class="wp-caption alignnone" data-shortcode="caption" id="attachment_182" style="color: #767676; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px; max-width: 100%; width: 660px;"><a href="https://wpdevkvk.files.wordpress.com/2014/12/51.png" style="border: 0px; color: #24890d; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><img alt="Select an operating system screen" class="size-large wp-image-182" src="https://wpdevkvk.files.wordpress.com/2014/12/51.png?w=474&h=267" style="border: 0px; display: block; height: auto; margin: 0px; max-width: 100%; vertical-align: middle;" /></a><figcaption class="wp-caption-text" style="box-sizing: border-box; font-size: 12px; font-style: italic; line-height: 1.5; margin: 9px 0px;">Select an operating system screen</figcaption></figure><div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
The system will restart at this point. Don’t worry. It’s normal <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span>When you load a new configuration from the above screen the system will restart. That mean if you change from the current boot configuration to the new one or vice versa the system need to restart. If you boot in to the same configuration you used last time, it will boot up without restarting.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
There it is guys <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span> no go on and install the HAXM software and enjoy an Android Emulator on steroids <span class="wp-smiley wp-emoji wp-emoji-bigsmile" style="border: 0px; display: inline-block !important; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; min-height: 1.2em; outline: 0px; overflow: hidden; padding: 0px; position: relative !important; text-indent: 9999px; vertical-align: bottom; white-space: nowrap; width: 1.35em;" title=":D">:D</span> If you don’t remember how to do this, here is the link to the post where I explain it.</div>
<div style="border: 0px; color: #2b2b2b; font-family: Lato, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 24px; outline: 0px; padding: 0px; vertical-align: baseline;">
<br /></div>
Anonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-48742443978159997702015-04-27T14:07:00.003+07:002015-04-27T14:07:39.161+07:00Android custom dropdown/popup menu<div style="text-align: center;">
<img alt="enter image description here" src="http://i.stack.imgur.com/eGciL.png" style="background-color: white; border: 0px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin: 0px; max-width: 630px; padding: 0px;" /></div>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
To create popup menu in android.</div>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
activity_main.xml</div>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
It contains only one button.</div>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
File: activity_main.xml</div>
<blockquote class="tr_bq" style="background-color: white; border: 0px; clear: both; margin-bottom: 1em; padding: 0px;">
<pre class="default prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"><RelativeLayout</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">xmlns:android</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"http://schemas.android.com/apk/res/android"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">xmlns:tools</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"http://schemas.android.com/tools"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_width</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"match_parent"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_height</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"match_parent"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:paddingBottom</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@dimen/activity_vertical_margin"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:paddingLeft</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@dimen/activity_horizontal_margin"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:paddingRight</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@dimen/activity_horizontal_margin"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:paddingTop</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@dimen/activity_vertical_margin"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">tools:context</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">".MainActivity"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"><Button</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:id</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@+id/button1"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_width</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"wrap_content"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_height</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"wrap_content"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_alignParentLeft</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"true"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_alignParentTop</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"true"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_marginLeft</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"62dp"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:layout_marginTop</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"50dp"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:text</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"Show Popup"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">/></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"></RelativeLayout></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span></code></pre>
</blockquote>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
popup_menu.xml</div>
<span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px;">It contains three items as show below. It is created inside the res/menu directory. File: poupup_menu.xml</span><br />
<pre class="default prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"><menu</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">xmlns:android</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"http://schemas.android.com/apk/res/android"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"><item</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:id</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@+id/one"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:title</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"One"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">/></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"><item</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:id</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@+id/two"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:title</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"Two"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">/></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;"><item</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:id</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"@+id/three"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="atn" style="border: 0px; color: red; margin: 0px; padding: 0px;">android:title</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="atv" style="border: 0px; color: blue; margin: 0px; padding: 0px;">"Three"</span><span class="tag" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">/></span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span></code></pre>
<blockquote class="tr_bq">
<span class="tag" style="background-color: #eeeeee; border: 0px; color: maroon; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"></menu></span><span class="pln" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span></blockquote>
<br />
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
Activity class</div>
<span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px;">It displays the popup menu on button click. File: MainActivity.java</span><br />
<pre class="default prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">public</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">class</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">MainActivity</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">extends</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Activity</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">private</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Button</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> button1</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">;</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">@Override</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">protected</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">void</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> onCreate</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Bundle</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> savedInstanceState</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">)</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">super</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">onCreate</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">savedInstanceState</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">);</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
setContentView</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">R</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">layout</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">activity_main</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">);</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
button1 </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Button</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">)</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> findViewById</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">R</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">id</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">button1</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">);</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
button1</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">setOnClickListener</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">new</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">OnClickListener</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">()</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="lit" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">@Override</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">public</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">void</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> onClick</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">View</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> v</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">)</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="com" style="border: 0px; color: grey; margin: 0px; padding: 0px;">//Creating the instance of PopupMenu</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">PopupMenu</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> popup </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">=</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">new</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">PopupMenu</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">MainActivity</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">this</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">,</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> button1</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">);</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="com" style="border: 0px; color: grey; margin: 0px; padding: 0px;">//Inflating the Popup using xml file</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
popup</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">getMenuInflater</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">()</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">inflate</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">R</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">menu</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">popup_menu</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">,</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> popup</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">getMenu</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">());</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="com" style="border: 0px; color: grey; margin: 0px; padding: 0px;">//registering popup with OnMenuItemClickListener</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
popup</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">setOnMenuItemClickListener</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">new</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">PopupMenu</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">OnMenuItemClickListener</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">()</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">public</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">boolean</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> onMenuItemClick</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">MenuItem</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> item</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">)</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">{</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Toast</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">makeText</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">MainActivity</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">this</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">,</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="str" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">"You Clicked : "</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">+</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> item</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">getTitle</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">(),</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="typ" style="border: 0px; color: #2b91af; margin: 0px; padding: 0px;">Toast</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">LENGTH_SHORT
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">).</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">show</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">();</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">return</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">true</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">;</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">}</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">});</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
popup</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">.</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">show</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">();</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="com" style="border: 0px; color: grey; margin: 0px; padding: 0px;">//showing popup menu</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">}</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">});</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span><span class="com" style="border: 0px; color: grey; margin: 0px; padding: 0px;">//closing the setOnClickListener method</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="pun" style="border: 0px; color: black; margin: 0px; padding: 0px;">}</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> </span></code></pre>
<blockquote class="tr_bq">
<span style="background-color: #eeeeee; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; white-space: inherit;">}</span> </blockquote>
<blockquote class="tr_bq">
<span class="pln" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin: 0px; padding: 0px; white-space: inherit;"> </span> </blockquote>
Anonymoushttp://www.blogger.com/profile/15104747258731844541noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-40470033036094204852015-04-06T10:19:00.002+07:002015-04-06T10:19:45.250+07:00Android - Unzip file data in sdcardThis is way I implement to unzip file:<br />
<blockquote class="tr_bq">
String zipFilename = Environment.getExternalStorageDirectory() + "/FileName.zip";<br />
String unzipLocation = Environment.getExternalStorageDirectory() + "/FileName/"; </blockquote>
<blockquote class="tr_bq">
private void dirChecker(final String dir) {<br />
File f = new File(mLocation + dir);<br />
<br />
if (!f.isDirectory()) {<br />
f.mkdirs();<br />
}<br />
}</blockquote>
Create ansyntask to unzip file:<br />
<blockquote class="tr_bq">
class UnZipTask extends AsyncTask<Void, Integer, Integer> {<br />
/**<br />
* Number progress.<br />
*/<br />
private int per = 0;<br />
<br />
@Override<br />
protected void onPreExecute() {<br />
super.onPreExecute();<br />
showDialog(Constants.DIALOG_UNZIP_PROGRESS);<br />
}<br />
<br />
@Override<br />
protected Integer doInBackground(final Void... params) {<br />
try {<br />
@SuppressWarnings("resource")<br />
ZipFile zipFile = new ZipFile(mZipFile);<br />
mProgressDialog.setMax(zipFile.size());<br />
FileInputStream fin = new FileInputStream(mZipFile);<br />
ZipInputStream zin = new ZipInputStream(fin);<br />
ZipEntry ze = null;<br />
while ((ze = zin.getNextEntry()) != null) {<br />
<br />
LogUtil.logD(Constants.IS_DEBUG_MODE, TAG, "Unzipping " + ze.getName());<br />
if (ze.isDirectory()) {<br />
dirChecker(ze.getName());<br />
} else {<br />
// Update of my progress bar<br />
LogUtil.logD(Constants.IS_DEBUG_MODE, TAG, "more " + ze.getName());<br />
<br />
per++;<br />
publishProgress(per);<br />
<br />
FileOutputStream fout = new FileOutputStream(mLocation + ze.getName());<br />
streamCopy(zin, fout);<br />
zin.closeEntry();<br />
fout.close();<br />
}<br />
}<br />
zin.close();<br />
} catch (Exception e) {<br />
// Log.e("Decompress", "unzip", e);<br />
LogUtil.logE(Constants.IS_DEBUG_MODE, TAG, "unzip " + e);<br />
}<br />
return null;<br />
}<br />
<br />
@Override<br />
protected void onProgressUpdate(final Integer... values) {<br />
super.onProgressUpdate(values);<br />
mProgressDialog.setProgress(per);<br />
}<br />
<br />
@Override<br />
protected void onPostExecute(final Integer result) {<br />
super.onPostExecute(result);<br />
// Log.i("UnZip" ,"Completed. Total size: "+result);<br />
if (mProgressDialog.isShowing()) {<br />
mProgressDialog.dismiss();<br />
}<br />
}<br />
}<br />
<br />
/**<br />
* This is a method universally useful standard code to copy inputstreams to outputstreams.<br />
* @param in<br />
* inputstream<br />
* @param out<br />
* outputstream<br />
* @throws IOException<br />
* exception<br />
*/<br />
public static void streamCopy(final InputStream in, final OutputStream out) throws IOException {<br />
// play with sizes..<br />
byte[] buffer = new byte[Constants.NUMBER_THIRTY_TWO * Constants.NUMBER_1024];<br />
int readCount;<br />
while ((readCount = in.read(buffer)) != -1) {<br />
out.write(buffer, 0, readCount);<br />
}<br />
} </blockquote>
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b><a href="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="-webkit-transition: all 0.4s ease-in-out; box-sizing: border-box; color: #999999; font-family: Verdana, Geneva, sans-serif; font-size: 11px; line-height: 17.59375px; margin-left: 1em; margin-right: 1em; max-width: 100%; text-align: center; text-decoration: none; transition: all 0.4s ease-in-out;"><img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></a></b></h3>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-4532166166137503322015-04-01T09:59:00.000+07:002015-04-01T09:59:14.638+07:00Driving distance and travel time duration between two locations in Google Map Android API V2<h4>
Step 1 :- Create New Android Project.</h4>
<h4>
<br />Step 2 :- Add Google-play-services_lib to your project.</h4>
<h4>
<br />Step 3 :- Open AndroidManifest.xml file.</h4>
<br />
<blockquote class="tr_bq">
<?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://schemas.android.com/apk/res/android"<br /> package="com.mapv2.demo"<br /> android:versionCode="1"<br /> android:versionName="1.0" ><br /><br /> <uses-sdk<br /> android:minSdkVersion="8"<br /> android:targetSdkVersion="17" /><br /> <br /> <br /> <uses-permission android:name="android.permission.INTERNET"/><br /><br /> <permission<br /> android:name="com.mapv2.demo.permission.MAPS_RECEIVE"<br /> android:protectionLevel="signature" /><br /><br /> <uses-permission android:name="com.mapv2.demo.permission.MAPS_RECEIVE" /><br /><br /> <uses-permission android:name="android.permission.INTERNET"/><br /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><br /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/><br /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><br /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/><br /><br /> <uses-feature<br /> android:glEsVersion="0x00020000"<br /> android:required="true"/><br /><br /> <application<br /> android:allowBackup="true"<br /> android:icon="@drawable/ic_launcher"<br /> android:label="@string/app_name"<br /> android:theme="@style/AppTheme" ><br /> <activity<br /> android:name="com.mapv2.demo.MainActivity"<br /> android:label="@string/app_name" ><br /> <intent-filter><br /> <action android:name="android.intent.action.MAIN" /><br /><br /> <category android:name="android.intent.category.LAUNCHER" /><br /> </intent-filter><br /> </activity><br /> <br /> <meta-data<br /> android:name="com.google.android.maps.v2.API_KEY"<br /> android:value="AIzaSyCmX7SLVHXxU9pSqb2QbAOvdnjAGUulOrk" /><br /> <br /> </application><br /><br /></manifest></blockquote>
<h4>
Step 4 :- Open activity_main.xml.</h4>
<br />
<blockquote class="tr_bq">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> xmlns:tools="http://schemas.android.com/tools"<br /> android:layout_width="match_parent"<br /> android:layout_height="match_parent"<br /> tools:context=".MainActivity" ><br /><br /> <TextView<br /> android:id="@+id/tv_distance_time"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:text="@string/hello_world" <br /> android:layout_alignParentTop="true" /><br /> <br /> <fragment <br /> android:id="@+id/map"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content" <br /> class="com.google.android.gms.maps.SupportMapFragment" <br /> android:layout_below="@id/tv_distance_time" /> <br /><br /></RelativeLayout></blockquote>
<h4>
Step 5 :- Open MainActivity.java</h4>
<br />
<blockquote class="tr_bq">
package com.mapv2.demo;<br /><br />import java.io.BufferedReader;<br />import java.io.IOException;<br />import java.io.InputStream;<br />import java.io.InputStreamReader;<br />import java.net.HttpURLConnection;<br />import java.net.URL;<br />import java.util.ArrayList;<br />import java.util.HashMap;<br />import java.util.List;<br /><br />import org.json.JSONObject;<br /><br />import android.graphics.Color;<br />import android.os.AsyncTask;<br />import android.os.Bundle;<br />import android.support.v4.app.FragmentActivity;<br />import android.util.Log;<br />import android.view.Menu;<br />import android.widget.TextView;<br />import android.widget.Toast;<br /><br />import com.google.android.gms.maps.GoogleMap;<br />import com.google.android.gms.maps.GoogleMap.OnMapClickListener;<br />import com.google.android.gms.maps.SupportMapFragment;<br />import com.google.android.gms.maps.model.BitmapDescriptorFactory;<br />import com.google.android.gms.maps.model.LatLng;<br />import com.google.android.gms.maps.model.MarkerOptions;<br />import com.google.android.gms.maps.model.PolylineOptions;<br /><br /><br />public class MainActivity extends FragmentActivity {<br /><br /> GoogleMap map;<br /> ArrayList<LatLng> markerPoints;<br /> TextView tvDistanceDuration;<br /> <br /> @Override<br /> protected void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.activity_main);<br /> <br /> tvDistanceDuration = (TextView) findViewById(R.id.tv_distance_time);<br /> <br /> // Initializing <br /> markerPoints = new ArrayList<LatLng>();<br /> <br /> // Getting reference to SupportMapFragment of the activity_main<br /> SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);<br /> <br /> // Getting Map for the SupportMapFragment<br /> map = fm.getMap();<br /> <br /> // Enable MyLocation Button in the Map<br /> map.setMyLocationEnabled(true); <br /> <br /> // Setting onclick event listener for the map<br /> map.setOnMapClickListener(new OnMapClickListener() {<br /> <br /> @Override<br /> public void onMapClick(LatLng point) {<br /> <br /> // Already two locations <br /> if(markerPoints.size()>1){<br /> markerPoints.clear();<br /> map.clear(); <br /> }<br /> <br /> // Adding new item to the ArrayList<br /> markerPoints.add(point); <br /> <br /> // Creating MarkerOptions<br /> MarkerOptions options = new MarkerOptions();<br /> <br /> // Setting the position of the marker<br /> options.position(point);<br /> <br /> /** <br /> * For the start location, the color of marker is GREEN and<br /> * for the end location, the color of marker is RED.<br /> */<br /> if(markerPoints.size()==1){<br /> options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));<br /> }else if(markerPoints.size()==2){<br /> options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));<br /> }<br /> <br /> <br /> // Add new marker to the Google Map Android API V2<br /> map.addMarker(options);<br /> <br /> // Checks, whether start and end locations are captured<br /> if(markerPoints.size() >= 2){ <br /> LatLng origin = markerPoints.get(0);<br /> LatLng dest = markerPoints.get(1);<br /> <br /> // Getting URL to the Google Directions API<br /> String url = getDirectionsUrl(origin, dest); <br /> <br /> DownloadTask downloadTask = new DownloadTask();<br /> <br /> // Start downloading json data from Google Directions API<br /> downloadTask.execute(url);<br /> }<br /> <br /> }<br /> });<br /> <br /> }<br /> <br /> private String getDirectionsUrl(LatLng origin,LatLng dest){<br /> <br /> // Origin of route<br /> String str_origin = "origin="+origin.latitude+","+origin.longitude;<br /> <br /> // Destination of route<br /> String str_dest = "destination="+dest.latitude+","+dest.longitude; <br /> <br /> <br /> // Sensor enabled<br /> String sensor = "sensor=false"; <br /> <br /> // Building the parameters to the web service<br /> String parameters = str_origin+"&"+str_dest+"&"+sensor;<br /> <br /> // Output format<br /> String output = "json";<br /> <br /> // Building the url to the web service<br /> String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters;<br /> <br /> <br /> return url;<br /> }<br /> <br /> /** A method to download json data from url */<br /> private String downloadUrl(String strUrl) throws IOException{<br /> String data = "";<br /> InputStream iStream = null;<br /> HttpURLConnection urlConnection = null;<br /> try{<br /> URL url = new URL(strUrl);<br /><br /> // Creating an http connection to communicate with url <br /> urlConnection = (HttpURLConnection) url.openConnection();<br /><br /> // Connecting to url <br /> urlConnection.connect();<br /><br /> // Reading data from url <br /> iStream = urlConnection.getInputStream();<br /><br /> BufferedReader br = new BufferedReader(new InputStreamReader(iStream));<br /><br /> StringBuffer sb = new StringBuffer();<br /><br /> String line = "";<br /> while( ( line = br.readLine()) != null){<br /> sb.append(line);<br /> }<br /> <br /> data = sb.toString();<br /><br /> br.close();<br /><br /> }catch(Exception e){<br /> Log.d("Exception while downloading url", e.toString());<br /> }finally{<br /> iStream.close();<br /> urlConnection.disconnect();<br /> }<br /> return data;<br /> }<br /><br /> <br /> <br /> // Fetches data from url passed<br /> private class DownloadTask extends AsyncTask<String, Void, String>{ <br /> <br /> // Downloading data in non-ui thread<br /> @Override<br /> protected String doInBackground(String... url) {<br /> <br /> // For storing data from web service<br /> String data = "";<br /> <br /> try{<br /> // Fetching the data from web service<br /> data = downloadUrl(url[0]);<br /> }catch(Exception e){<br /> Log.d("Background Task",e.toString());<br /> }<br /> return data; <br /> }<br /> <br /> // Executes in UI thread, after the execution of<br /> // doInBackground()<br /> @Override<br /> protected void onPostExecute(String result) { <br /> super.onPostExecute(result); <br /> <br /> ParserTask parserTask = new ParserTask();<br /> <br /> // Invokes the thread for parsing the JSON data<br /> parserTask.execute(result);<br /> <br /> } <br /> }<br /> <br /> /** A class to parse the Google Places in JSON format */<br /> private class ParserTask extends AsyncTask<String, Integer, List<List<HashMap<String,String>>> >{<br /> <br /> // Parsing the data in non-ui thread <br /> @Override<br /> protected List<List<HashMap<String, String>>> doInBackground(String... jsonData) {<br /> <br /> JSONObject jObject; <br /> List<List<HashMap<String, String>>> routes = null; <br /> <br /> try{<br /> jObject = new JSONObject(jsonData[0]);<br /> DirectionsJSONParser parser = new DirectionsJSONParser();<br /> <br /> // Starts parsing data<br /> routes = parser.parse(jObject); <br /> }catch(Exception e){<br /> e.printStackTrace();<br /> }<br /> return routes;<br /> }<br /> <br /> // Executes in UI thread, after the parsing process<br /> @Override<br /> protected void onPostExecute(List<List<HashMap<String, String>>> result) {<br /> ArrayList<LatLng> points = null;<br /> PolylineOptions lineOptions = null;<br /> MarkerOptions markerOptions = new MarkerOptions();<br /> String distance = "";<br /> String duration = "";<br /> <br /> <br /> <br /> if(result.size()<1){<br /> Toast.makeText(getBaseContext(), "No Points", Toast.LENGTH_SHORT).show();<br /> return;<br /> }<br /> <br /> <br /> // Traversing through all the routes<br /> for(int i=0;i<result.size();i++){<br /> points = new ArrayList<LatLng>();<br /> lineOptions = new PolylineOptions();<br /> <br /> // Fetching i-th route<br /> List<HashMap<String, String>> path = result.get(i);<br /> <br /> // Fetching all the points in i-th route<br /> for(int j=0;j<path.size();j++){<br /> HashMap<String,String> point = path.get(j); <br /> <br /> if(j==0){ // Get distance from the list<br /> distance = (String)point.get("distance"); <br /> continue;<br /> }else if(j==1){ // Get duration from the list<br /> duration = (String)point.get("duration");<br /> continue;<br /> }<br /> <br /> double lat = Double.parseDouble(point.get("lat"));<br /> double lng = Double.parseDouble(point.get("lng"));<br /> LatLng position = new LatLng(lat, lng); <br /> <br /> points.add(position); <br /> }<br /> <br /> // Adding all the points in the route to LineOptions<br /> lineOptions.addAll(points);<br /> lineOptions.width(2);<br /> lineOptions.color(Color.RED); <br /> <br /> }<br /> <br /> tvDistanceDuration.setText("Distance:"+distance + ", Duration:"+duration);<br /> <br /> // Drawing polyline in the Google Map for the i-th route<br /> map.addPolyline(lineOptions); <br /> } <br /> } <br /> <br /> <br /> @Override<br /> public boolean onCreateOptionsMenu(Menu menu) {<br /> // Inflate the menu; this adds items to the action bar if it is present.<br /> getMenuInflater().inflate(R.menu.main, menu);<br /> return true;<br /> } <br />}</blockquote>
<br />
<br />
<h4>
1.) DirectionsJSONParser.java</h4>
<br />
<br />
<blockquote class="tr_bq">
package com.mapv2.demo;<br /><br />import java.util.ArrayList;<br />import java.util.HashMap;<br />import java.util.List;<br /><br />import org.json.JSONArray;<br />import org.json.JSONException;<br />import org.json.JSONObject;<br /><br />import com.google.android.gms.maps.model.LatLng;<br /><br />public class DirectionsJSONParser {<br /> <br /> /** Receives a JSONObject and returns a list of lists containing latitude and longitude */<br /> public List<List<HashMap<String,String>>> parse(JSONObject jObject){<br /> <br />
List<List<HashMap<String, String>>> routes = new
ArrayList<List<HashMap<String,String>>>() ;<br /> JSONArray jRoutes = null;<br /> JSONArray jLegs = null;<br /> JSONArray jSteps = null; <br /> JSONObject jDistance = null;<br /> JSONObject jDuration = null;<br /> <br /> try { <br /> <br /> jRoutes = jObject.getJSONArray("routes");<br /> <br /> /** Traversing all routes */<br /> for(int i=0;i<jRoutes.length();i++){ <br /> jLegs = ( (JSONObject)jRoutes.get(i)).getJSONArray("legs"); <br /> <br />
List<HashMap<String, String>> path = new
ArrayList<HashMap<String, String>>(); <br /> <br /> /** Traversing all legs */<br /> for(int j=0;j<jLegs.length();j++){<br /> <br /> /** Getting distance from the json data */<br /> jDistance = ((JSONObject) jLegs.get(j)).getJSONObject("distance");<br /> HashMap<String, String> hmDistance = new HashMap<String, String>();<br /> hmDistance.put("distance", jDistance.getString("text"));<br /> <br /> /** Getting duration from the json data */<br /> jDuration = ((JSONObject) jLegs.get(j)).getJSONObject("duration");<br /> HashMap<String, String> hmDuration = new HashMap<String, String>();<br /> hmDuration.put("duration", jDuration.getString("text"));<br /> <br /> /** Adding distance object to the path */<br /> path.add(hmDistance);<br /> <br /> /** Adding duration object to the path */<br /> path.add(hmDuration); <br /> <br /> <br /> jSteps = ( (JSONObject)jLegs.get(j)).getJSONArray("steps");<br /> <br /> /** Traversing all steps */<br /> for(int k=0;k<jSteps.length();k++){<br /> String polyline = "";<br /> polyline = (String)((JSONObject)((JSONObject)jSteps.get(k)).get("polyline")).get("points");<br /> List<LatLng> list = decodePoly(polyline);<br /> <br /> /** Traversing all points */<br /> for(int l=0;l<list.size();l++){<br /> HashMap<String, String> hm = new HashMap<String, String>();<br /> hm.put("lat", Double.toString(((LatLng)list.get(l)).latitude) );<br /> hm.put("lng", Double.toString(((LatLng)list.get(l)).longitude) );<br /> path.add(hm); <br /> } <br /> } <br /> }<br /> routes.add(path);<br /> }<br /> <br /> } catch (JSONException e) { <br /> e.printStackTrace();<br /> }catch (Exception e){ <br /> }<br /> <br /> return routes;<br /> } <br /> <br /> <br /> /**<br /> * Method to decode polyline points <br /> * Courtesy : jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java <br /> * */<br /> private List<LatLng> decodePoly(String encoded) {<br /><br /> List<LatLng> poly = new ArrayList<LatLng>();<br /> int index = 0, len = encoded.length();<br /> int lat = 0, lng = 0;<br /><br /> while (index < len) {<br /> int b, shift = 0, result = 0;<br /> do {<br /> b = encoded.charAt(index++) - 63;<br /> result |= (b & 0x1f) << shift;<br /> shift += 5;<br /> } while (b >= 0x20);<br /> int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));<br /> lat += dlat;<br /><br /> shift = 0;<br /> result = 0;<br /> do {<br /> b = encoded.charAt(index++) - 63;<br /> result |= (b & 0x1f) << shift;<br /> shift += 5;<br /> } while (b >= 0x20);<br /> int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));<br /> lng += dlng;<br /><br /> LatLng p = new LatLng((((double) lat / 1E5)),<br /> (((double) lng / 1E5)));<br /> poly.add(p);<br /> }<br /><br /> return poly;<br /> }<br />}</blockquote>
<br />
<h4>
Step 6 :- Run Code.</h4>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-KMsl3Bk5bws/VRtelgjpHOI/AAAAAAAAA-M/4S2twTDrRf8/s1600/google%2Bamp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-KMsl3Bk5bws/VRtelgjpHOI/AAAAAAAAA-M/4S2twTDrRf8/s1600/google%2Bamp.png" /></a></div>
<br />
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-76227717644483410952015-03-30T10:47:00.000+07:002015-03-30T10:47:01.371+07:00Update location by using GoogleApiClient in androidTo use GoogleApiClient, you have to use google play services library
in your project. Questions may arise in your mind that what is google
play services? Well, Google Play services provides you with easy access
to Google services and is tightly integrated with the Android OS.
Easy-to-use client libraries are provided for each service that let you
implement the functionality you want easier and faster. google play
services gives your apps more features to attract users on a wider range
of devices. With Google Play services, your app can take advantage of
the latest, Google-powered features such as Maps, Google+, and more,
with automatic platform updates distributed as an APK through the Google
Play store. This makes it faster for your users to receive updates and
easier for you to integrate the newest that Google has to offer. All
products in Google Play services share a common authorization API that
leverages the existing Google accounts on the device. You and your users
have a consistent and safe way to grant and receive OAuth2 access
tokens to Google services. Devices running Android 2.3 or higher that
have the Google Play Store app will automatically receive updates to
Google Play services. Enhance your app with the most recent version of
Google Play services without worrying about your users’ Android version.<br />
Now comes to the use of GoogleApiClient, what is that and how it will
help us? Lets dig into it, GoogleApiClient is the main entry point of
using googleplayservices.<br />
GoogleApiClient is used with a variety of static methods. Some of
these methods require that GoogleApiClient be connected, some will queue
up calls before GoogleApiClient is connected; check the specific API
documentation to determine whether you need to be connected.<br />
Before any operation is executed, the GoogleApiClient must be connected using the <code><a href="http://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html#connect%28%29">connect()</a></code> method. The client is not considered connected until the <code><a href="http://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.ConnectionCallbacks.html#onConnected%28android.os.Bundle%29">onConnected(Bundle)</a></code> callback has been called.<br />
When your app is done using this client, call <code><a href="http://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html#disconnect%28%29">disconnect()</a></code>, even if the async result from <code><a href="http://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html#connect%28%29">connect()</a></code> has not yet been delivered.<br />
You should instantiate a client object in your Activity’s <code><a href="http://developer.android.com/reference/android/app/Activity.html#onCreate%28android.os.Bundle%29">onCreate(Bundle)</a></code> method and then call <code><a href="http://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html#connect%28%29">connect()</a></code> in <code><a href="http://developer.android.com/reference/android/app/Activity.html#onStart%28%29">onStart()</a></code> and <code><a href="http://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html#disconnect%28%29">disconnect()</a></code> in <code><a href="http://developer.android.com/reference/android/app/Activity.html#onStop%28%29">onStop()</a></code>, regardless of the state.<br />
<h4>
Step-01: Our first step will be instantiate the client object in
onCreate() method of the activity. We can do that in the way like below
code:</h4>
<blockquote class="tr_bq">
<br />
mGoogleApiClient = new GoogleApiClient.Builder(this)<br />
.addConnectionCallbacks(this)<br />
.addOnConnectionFailedListener(this)<br />
.addApi(<span class="skimlinks-unlinked">LocationServices.API</span>)<br />
.build();<br />
</blockquote>
Do not forget to declare GoogleApiClient what is mGoogleApiClient here<br />
To get the location update, we need LocationRequest object which will
be used to give some properties like what is the interval to get the
update location and what is the priority for the request. So what we
have to do, We will declare a LocationRequest variable called
mLocationRequest. we will instantiate it with our class variable and set
properties inside of the onCreate() method.<br />
<blockquote class="tr_bq">
LocationRequest mLocationRequest=new LocationRequest();<br />
mLocationRequest.setInterval(10000);<br />
mLocationRequest.setFastestInterval(5000);<br />
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);</blockquote>
Now we have to connect with GoogleApiClient. We will place this request inside of our onStart() method of the activity.<br />
<blockquote class="tr_bq">
@Override<br />
protected void onStart() {<br />
super.onStart();<br />
mGoogleApiClient.connect();//be connected with GoogleApiClient<br />
}</blockquote>
If the connection is successful it will call the onConnected() method or
if the connection is failed, it will call onConnectionFailed() or else
it will call onConnectionSuspended() method.<br />
<blockquote class="tr_bq">
@Override<br />
public void onConnected(Bundle bundle) {<br />
updateUI(); //this method will place a request for the last known location and update the UI<br />
if(requestingLocationUpdate){<br />
startLocationUpdate();// this will be calling to get the update location frequently based on user requirements<br />
}<br />
}</blockquote>
So How to get the last location? well here is the method to get it:<br />
<blockquote class="tr_bq">
Location lastLocation= LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);</blockquote>
We got the last know location above but what about our update location? This is the way to get that also<br />
<blockquote class="tr_bq">
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,this);</blockquote>
it will return update location continuously but where this location
will go to update the UI? Well it will go the method onLocationChanged()
method where you can update your update location. Why and How? Look at
the requestLocationUpdates(.., … ,…) method, it takes three parameters.
These are GoogleApiClient, LocationRequest and LocationListener. For
LocationListener, i passed “this”. What I mean by that is go to the
LocationListener interface of the Activity class which OnLocationChanged
in our case here.<br />
Now come back to OnLocationChanged method. It has one parameter which
the update location. This parameter comes from the method
“requestLocationUpdates”. Now you update your UI for this update
location or whatever you want to do. So code snippet will be something
like this:<br />
<br /><blockquote class="tr_bq">
@Override<br />
public void onLocationChanged(Location location) {<br />
locationUp=location;<br />
updateView();<br />
}<br />
</blockquote>
<h4>
<span style="text-decoration: underline;"><strong>Full Code:</strong></span></h4>
<h4>
</h4>
<h4>
<span style="text-decoration: underline;"><strong>Activity:</strong></span></h4>
<blockquote class="tr_bq">
public class MainActivity extends FragmentActivity implements<br />
GoogleApiClient.ConnectionCallbacks,<br />
GoogleApiClient.OnConnectionFailedListener,<br />
LocationListener{<br />
TextView tvLocation;<br />
TextView tvLocationUpdate;<br />
GoogleApiClient mGoogleApiClient;<br />
GoogleMap map ;<br />
Location locationUp;<br />
LocationRequest mLocationRequest=new LocationRequest();<br />
boolean requestingLocationUpdate=true;<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.activity_main);<br />
tvLocation = (TextView) findViewById(<span class="skimlinks-unlinked">R.id.tvLoc);//last</span> location<br />
tvLocationUpdate=(TextView)findViewById(R.id.tvLocUpdate);//update location<br />
mGoogleApiClient = new GoogleApiClient.Builder(this)<br />
.addConnectionCallbacks(this)<br />
.addOnConnectionFailedListener(this)<br />
.addApi(<span class="skimlinks-unlinked">LocationServices.API</span>)<br />
.build();<br />
mLocationRequest.setInterval(10000);<br />
mLocationRequest.setFastestInterval(5000);<br />
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);<br />
}<br />
@Override<br />
protected void onStart() {<br />
super.onStart();<br />
mGoogleApiClient.connect();//be connected with GoogleApiClient<br />
}<br />
@Override<br />
public void onConnected(Bundle bundle) {<br />
updateUI();<br />
if(requestingLocationUpdate){<br />
startLocationUpdate();//trying to get the update location<br />
}<br />
}<br />
private void startLocationUpdate() {<br />
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,this);<br />
}<br />
private void updateUI() {<br />
tvLocation.setText(“Last Known
Location:”+String.valueOf(getLocation().getLatitude())+String.valueOf(getLocation().getLongitude()));<br />
}<br />
private Location getLocation() {<br />
Location lastKnownLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);<br />
return lastKnownLocation;<br />
}<br />
@Override<br />
public void onConnectionSuspended(int i) {<br />
Log.d(“result:”, “connection has been suspended”);<br />
}<br />
@Override<br />
public void onConnectionFailed(ConnectionResult connectionResult) {<br />
Log.d(“result:”,”not connected with GoogleApiClient”);<br />
}<br />
@Override<br />
protected void onPause() {<br />
super.onPause();<br />
stopLocationUpdate();//when activity is on pause, need to stop the location update since we<br />
//do not need that any more<br />
}<br />
private void stopLocationUpdate() {<br />
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,this);//stopping the update location<br />
}<br />
//no need to use googleplayservices<br />
@Override<br />
protected void onStop() {<br />
super.onStop();<br />
mGoogleApiClient.disconnect();//disconnect the GoogleApiClient from the google play services<br />
}<br />
@Override<br />
protected void onResume() {<br />
super.onResume();<br />
if(mGoogleApiClient.isConnected()){<br />
startLocationUpdate();// since we need to get the update location continuously like gps<br />
//when activity is in foreground(resume), then we have to request to get update location<br />
//here alos<br />
}<br />
}<br />
//to get the location change<br />
@Override<br />
public void onLocationChanged(Location location) {<br />
locationUp=location;//this location is the update location,<br />
// came from the requestLocationUpdate() method’s interface<br />
updateView();//put your value in the text or whatever you want to do<br />
}<br />
private void updateView() {<br />
tvLocationUpdate.setText(“Update Location:”+String.valueOf(locationUp.getLatitude())+String.valueOf(locationUp.getLongitude()));<br />
}<br />
}</blockquote>
<h4>
<span style="text-decoration: underline;"><strong>My Layout:</strong></span></h4>
<blockquote class="tr_bq">
<?xml version=”1.0″ encoding=”utf-8″?><br />
<RelativeLayout xmlns:android=”<a href="http://schemas.android.com/apk/res/android&#8221" rel="nofollow">http://schemas.android.com/apk/res/android&#8221</a>;<br />
android:layout_width=”match_parent”<br />
android:layout_height=”match_parent”><br />
<TextView<br />
android:id=”@+id/tvLoc”<br />
android:layout_width=”match_parent”<br />
android:layout_height=”wrap_content”<br />
android:layout_centerInParent=”true”/><br />
<TextView<br />
android:id=”@+id/tvLocUpdate”<br />
android:layout_below=”@id/tvLoc”<br />
android:layout_marginTop=”10dp”<br />
android:layout_width=”match_parent”<br />
android:layout_height=”wrap_content”<br />
android:layout_centerHorizontal=”true”/><br />
</RelativeLayout><br />
</blockquote>
<h4>
<span style="text-decoration: underline;"><strong>Output:</strong></span></h4>
<div style="text-align: center;">
<a href="https://androidtutorialmagic.files.wordpress.com/2015/01/location.png"><img alt="location" class="alignnone size-medium wp-image-49" height="300" src="https://androidtutorialmagic.files.wordpress.com/2015/01/location.png?w=169&h=300" width="169" /></a></div>
You can find the whole code from here:<br />
<a href="https://github.com/nanofaroque/GoogleApiClientTesting" rel="nofollow">https://github.com/nanofaroque/GoogleApiClientTesting</a><br />
<br />
<br />
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b><a href="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="-webkit-transition: all 0.4s ease-in-out; box-sizing: border-box; color: #999999; font-family: Verdana, Geneva, sans-serif; font-size: 11px; line-height: 17.59375px; margin-left: 1em; margin-right: 1em; max-width: 100%; text-align: center; text-decoration: none; transition: all 0.4s ease-in-out;"><img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></a></b></h3>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-3180124597328815052015-03-27T13:17:00.000+07:002015-03-27T13:17:05.556+07:00Android - Downloading & making volley.jar<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-NR_Ie_VqB5Q/VRT12F_i45I/AAAAAAAAA94/dqpG9Uo-xTU/s1600/android-volley-library.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-NR_Ie_VqB5Q/VRT12F_i45I/AAAAAAAAA94/dqpG9Uo-xTU/s1600/android-volley-library.jpg" height="140" width="320" /></a></div>
<br />
<br />
We will start with installing tools required to clone and build
volley project. For this we need git (to clone the project) and ant (to
build) tools.<br />
<strong>1.1 Installing Git</strong><br /> Git software is used to clone git projects into your local workspace. <a class="link" href="http://git-scm.com/downloads" target="_blank">Download & install</a> git, once installed run <em>git</em>
command in terminal just to make sure that it is accessible via command
line. If you are getting git command not found error, add the git
installation directory to environmental variables.<br />
<strong>1.2 Installing apache ant</strong><br /> Apache ant is a command-line tool used to build the source code. Download <strong>ant</strong> from <a class="link" href="https://ant.apache.org/bindownload.cgi" target="_blank">https://ant.apache.org/bindownload.cgi</a> and add the <strong>bin</strong> path to environmental variables. You should able to execute <em>ant</em> command too in terminal.<br />
<strong>1.3 Cloning volley library</strong><br />
Open command prompt, navigate to a location where you want to clone
volley and execute following command. This will download a copy of
volley library into your local drive.<br />
<blockquote class="tr_bq">
<div style="text-align: center;">
<div style="text-align: center;">
<pre class="prettyprint"><span class="pln">git clone https</span><span class="pun">:</span><span class="com">//android.googlesource.com/platform/frameworks/volley</span></pre>
</div>
<pre class="prettyprint"><span class="com"></span></pre>
</div>
</blockquote>
<br />
<strong>1.4 Making volley.jar</strong><br /> You can use the volley as a library project to your main project or you can simply generate volley.jar and paste it in project <strong>libs</strong> folder. To generate volley.jar, move into volley dir (<strong>cd volley</strong>) and execute below commands.<br />
<blockquote class="tr_bq">
<div>
<div class="syntaxhighlighter nogutter php" id="highlighter_682462">
<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td class="code"><div class="container">
<div class="line number1 index0 alt2">
<code class="php plain">android update project -p .</code></div>
<div class="line number2 index1 alt1">
</div>
<div class="line number3 index2 alt2">
<code class="php plain">ant jar</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
</blockquote>
You can find generated <strong>volley.jar</strong> in volley <strong>bin</strong> folder.<br />
<br />
<br />
For more information: <a href="http://developer.android.com/training/volley/index.html" target="_blank">http://developer.android.com/training/volley/index.html</a> <br />
<br />
Resolve error:<br />
1. Getting a <code>android:command not found error.</code> <br />
android update project --path .<br />
<br />
On MacOS/Linux, define the path to wherever you installed your SDK as <code>ANDROID_HOME</code>:<br />
<strong>MacOS</strong><br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="pln">$ </span><span class="kwd">export</span><span class="pln"> ANDROID_HOME</span><span class="pun">=</span><span class="str">/Applications/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">sdk</span><span class="pun">-</span><span class="pln">macosx</span></code></pre>
</blockquote>
If you installed <a href="http://developer.android.com/sdk/index.html">Android Studio</a>, the value will need to be<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="kwd">export</span><span class="pln"> ANDROID_HOME</span><span class="pun">=</span><span class="pln">$HOME</span><span class="pun">/</span><span class="typ">Library</span><span class="pun">/</span><span class="typ">Android</span><span class="pun">/</span><span class="pln">sdk</span></code></pre>
</blockquote>
<strong>Linux</strong><br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="pln">$ </span><span class="kwd">export</span><span class="pln"> ANDROID_HOME</span><span class="pun">=~/</span><span class="pln">android</span><span class="pun">-</span><span class="pln">sdk</span><span class="pun">-</span><span class="pln">linux</span></code></pre>
</blockquote>
Then add the paths to the <code>platform-tools</code> and <code>tools</code> sub-directories (Same on MacOS/Linux).<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="pln">$ANDROID_HOME</span><span class="pun">/</span><span class="pln">tools</span><span class="pun">:</span><span class="pln">$PATH
</span><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="pln">$ANDROID_HOME</span><span class="pun">/</span><span class="pln">platform</span><span class="pun">-</span><span class="pln">tools</span><span class="pun">:</span><span class="pln">$PATH</span></code></pre>
</blockquote>
You should now be able to run <code>android</code> from the shell.<br />
<br />
2. However running <code>android update project -p .</code> in the cloned <code>volley</code> folder throws this error:
<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="typ">Error</span><span class="pun">:</span><span class="pln"> </span><span class="pun">.</span><span class="pln"> </span><span class="kwd">is</span><span class="pln"> </span><span class="kwd">not</span><span class="pln"> a valid project </span><span class="pun">(</span><span class="typ">AndroidManifest</span><span class="pun">.</span><span class="pln">xml </span><span class="kwd">not</span><span class="pln"> found</span><span class="pun">).</span></code></pre>
</blockquote>
Please follow this commands:<br />
<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="pln">$ git clone https</span><span class="pun">:</span><span class="com">//android.googlesource.com/platform/frameworks/volley</span><span class="pln">
$ cd volley
$ git checkout </span><span class="lit">008e0cc8</span><span class="pln">
$ android update project </span><span class="pun">-</span><span class="pln">p </span><span class="pun">.</span><span class="pln">
$ ant jar</span></code></pre>
</blockquote>
Then, copy <code>bin/volley.jar</code> into your <code>libs/</code> folder and off you go!<br />
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-2005494289541705722015-03-16T14:09:00.000+07:002015-03-16T14:09:29.538+07:00Resolve cordova platform add android not working while listing Android targets<div class="post-text" itemprop="text">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-4u6iMnEEPuc/VQaBndLGC1I/AAAAAAAAA9k/b7MnVjhEgVA/s1600/graphic_build_bot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-4u6iMnEEPuc/VQaBndLGC1I/AAAAAAAAA9k/b7MnVjhEgVA/s1600/graphic_build_bot.png" height="272" width="320" /></a></div>
<br />
To work, this cordova command needs to use some programs located into your <code>sdk/tools</code> directory. You need also have installed <strong>apache ant</strong>.<br />
Then you must add these directories into your <code>PATH</code> system variable:<br />
<strong>Background:</strong><br />
<ul>
<li>let's assume you have installed your <a href="http://cordova.apache.org/docs/en/3.2.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide_requirements_and_support">Android SDK</a> to the <code>c:\sdk\android</code> directory</li>
<li>you have installed you <strong>Apache ant</strong> to the <code>c:\tools\apache-ant</code> directory</li>
</ul>
Then you must create two system variables:<br />
<ol>
<li><code>ANDROID_HOME</code> with the <code>c:\sdk\android</code> value</li>
<li><code>ANT_HOME</code> with the <code>c:\tools\apache-ant</code> value</li>
</ol>
Finally, you must modify the <code>PATH</code> variable and add those two to the end of the <code>PATH</code>' value: <br />
<pre class="default prettyprint prettyprinted"><code><span class="pun">;%</span><span class="pln">PATH</span><span class="pun">%</span><span class="pln">\tools</span><span class="pun">;%</span><span class="pln">ANT_HOME</span><span class="pun">%</span><span class="pln">\b</span><span class="kwd">in</span><span class="pun">;%</span><span class="pln">ANDROID_HOME</span><span class="pun">%</span><span class="pln">\tools</span><span class="pun">;%</span><span class="pln">ANDROID_HOME</span><span class="pun">%</span><span class="pln">\platform</span><span class="pun">-</span><span class="pln">tools</span></code></pre>
<strong>NOTE:</strong> for those who uses Linux, the instruction differs a bit.<br />
More documentation available <a href="http://docs.phonegap.com/en/3.2.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide">here</a>.<br />
<br />
<div class="post-text" itemprop="text">
<h2>
For those chosen ones, who preferred Linux development environment</h2>
<h3>
Requirements</h3>
First of all, you will need a few things to get started. They are: <a href="http://developer.android.com/sdk/index.html"><code>Android SDK</code></a> and <a href="http://ant.apache.org/"><code>Apache Ant</code></a>. Of course, you will need <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html"><code>Java SDK</code></a> (JDK) installed.<br />
To get Android SDK working for all users, you shall need to modify the <code>/etc/environment</code>
file and then restart your PC. But if you do not want that hard way -
follow me, think of yourself as the only PC user. And use <code>/home/YOUR_USERNAME/.bashrc</code> file to edit.<br />
Let's remember your home path one time to prevent further long lines. Add this one to your <code>/home/YOUR_USERNAME/.bashrc</code>:<br />
<pre class="default prettyprint prettyprinted"><code><span class="kwd">export</span><span class="pln"> HOME</span><span class="pun">=</span><span class="str">"/home/YOUR_USERNAME"</span></code></pre>
We'll then use the <code>$HOME</code> notation when we want to say "<code>/home/YOUR_USERNAME directory</code>".<br />
<h3>
Setting up Android SDK</h3>
Download the Android SDK archive and unzip it somewhere. Let's say, yo your home directory, <code>$HOME/adt-bundle/</code>.<br />
Add these lines to your <code>$HOME/.bashrc</code>:<br />
<pre class="default prettyprint prettyprinted"><code><span class="kwd">export</span><span class="pln"> ANDROID_HOME</span><span class="pun">=</span><span class="str">"$HOME/android-bundle/sdk/tools"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> ANDROID_PLATFORM_TOOLS</span><span class="pun">=</span><span class="str">"$HOME/android-bundle/sdk/platform-tools"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="str">"$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"</span></code></pre>
<h3>
Setting up Ant</h3>
Just as with the Android SDK, download an archive and unzip it to your home directory. Then add these to your <code>.bashrc</code>:<br />
<pre class="default prettyprint prettyprinted"><code><span class="kwd">export</span><span class="pln"> ANT_HOME</span><span class="pun">=</span><span class="str">"$HOME/ant"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="str">"$PATH:$ANT_HOME/bin"</span></code></pre>
I've installed one via the <code>apt-get</code> so this did not affect my <code>.bashrc</code>.<br />
<h2>
Applying changes</h2>
To make these changes work, you should either work in a new terminal window (opened <strong>after</strong> the changes), or run <code>source ~/.bashrc</code> to make changes available in the current terminal window.<br />
<h2>
Wrapping up</h2>
At the end, you will got:<br />
<ol>
<li>Two directories at your home directory - <code>ant</code> and <code>android-bundle</code></li>
<li>A few lines, added to your <code>.bashrc</code>:<br />
<pre class="default prettyprint prettyprinted"><code><span class="kwd">export</span><span class="pln"> ANDROID_HOME</span><span class="pun">=</span><span class="str">"$HOME/android-bundle/sdk/tools"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> ANDROID_PLATFORM_TOOLS</span><span class="pun">=</span><span class="str">"$HOME/android-bundle/sdk/platform-tools"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="str">"$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> ANT_HOME</span><span class="pun">=</span><span class="str">"$HOME/ant"</span><span class="pln">
</span><span class="kwd">export</span><span class="pln"> PATH</span><span class="pun">=</span><span class="str">"$PATH:$ANT_HOME/bin"</span></code></pre>
</li>
</ol>
</div>
</div>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-56563163500979250782015-01-28T08:32:00.001+07:002015-01-28T08:32:28.654+07:00 Failed to find style 'textViewStyle' in current themeIssue:<br />
<blockquote class="tr_bq">
I am getting below error on android. pls anyone help me. The error is<br /><br /><span style="font-style: italic;">Failed to find style 'textViewStyle' in current theme</span></blockquote>
<br />
Resolve:<br />
<br />
Just choose another theme thats all. follow below steps.<br /><br />
<blockquote class="tr_bq">
1. Open activity in "Graphic Layout"<br />2. Click drop down list AppTheme (On top bar of activity "Graphic Layout")<br />3. Select Project Themes->AppBaseTheme</blockquote>
<br />Now error log will be clear automatically. 2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-64079258920585338822014-12-11T09:08:00.003+07:002014-12-11T09:08:34.435+07:00Android switch button example A switch is type of button that can only have two states ON and OFF. You
can set the initial state and then the user can change it. To get the
current state you can check if the switch is checked or not, in addition
to that you can attach a OnCheckedChangeListener to the switch to get
notification when the state changes.<br />
<br />
<br />
<table>
<tbody>
<tr>
<td><a href="http://2.bp.blogspot.com/-fnTuVMaC2Xk/UWdvW8dCpKI/AAAAAAAADO4/Om8jTHDntmA/s1600/Android+switch+button+OFF+state.png"><img alt="Android switch button OFF state" border="0" src="http://2.bp.blogspot.com/-fnTuVMaC2Xk/UWdvW8dCpKI/AAAAAAAADO4/Om8jTHDntmA/s320/Android+switch+button+OFF+state.png" /></a>
</td>
<td><a href="http://1.bp.blogspot.com/-Nz491uUD0zc/UWdvZgLcRJI/AAAAAAAADPA/WzfZlz5zXNM/s1600/Android+switch+button+ON+state.png"><img alt="Android switch button ON state" border="0" src="http://1.bp.blogspot.com/-Nz491uUD0zc/UWdvZgLcRJI/AAAAAAAADPA/WzfZlz5zXNM/s320/Android+switch+button+ON+state.png" /></a>
</td>
</tr>
</tbody>
</table>
<h4>
Android Screen Layout</h4>
<div>
<div class="syntaxhighlighter xml" id="highlighter_811577">
<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr></tr>
</tbody></table>
<blockquote class="tr_bq">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> xmlns:tools="http://schemas.android.com/tools"<br /> android:layout_width="match_parent"<br /> android:layout_height="match_parent"<br /> tools:context=".MainActivity"<br /> android:padding="5dp"><br /><br /> <Switch<br /> android:id="@+id/mySwitch"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:layout_alignParentLeft="true"<br /> android:layout_alignParentTop="true"<br /> android:layout_marginTop="20dp"<br /> android:text="Play with the Switch" /><br /><br /> <TextView<br /> android:id="@+id/switchStatus"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:layout_alignParentLeft="true"<br /> android:layout_below="@+id/mySwitch"<br /> android:layout_marginTop="22dp"<br /> android:text="Medium Text"<br /> android:textAppearance="?android:attr/textAppearanceMedium" /><br /> <br /></RelativeLayout><br /><blockquote>
<br /></blockquote>
</blockquote>
<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td class="code"><br /></td></tr>
</tbody></table>
</div>
</div>
<br />
<h4>
Android Main Activity</h4>
<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td class="gutter"><br /></td><td class="code"><div class="container">
<blockquote class="tr_bq">
<code>package com.as400samplecode;<br /><br />import android.os.Bundle;<br />import android.app.Activity;<br />import android.view.Menu;<br />import android.widget.CompoundButton;<br />import android.widget.CompoundButton.OnCheckedChangeListener;<br />import android.widget.Switch;<br />import android.widget.TextView;<br /><br />public class MainActivity extends Activity {<br /><br /> private TextView switchStatus;<br /> private Switch mySwitch;<br /><br /> @Override<br /> protected void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);<br /> setContentView(R.layout.activity_main);<br /><br /> switchStatus = (TextView) findViewById(R.id.switchStatus);<br /> mySwitch = (Switch) findViewById(R.id.mySwitch);<br /><br /> //set the switch to ON <br /> mySwitch.setChecked(true);<br /> //attach a listener to check for changes in state<br /> mySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {<br /><br /> @Override<br /> public void onCheckedChanged(CompoundButton buttonView,<br /> boolean isChecked) {<br /><br /> if(isChecked){<br /> switchStatus.setText("Switch is currently ON");<br /> }else{<br /> switchStatus.setText("Switch is currently OFF");<br /> }<br /><br /> }<br /> });<br /> <br /> //check the current state before we display the screen<br /> if(mySwitch.isChecked()){<br /> switchStatus.setText("Switch is currently ON");<br /> }<br /> else {<br /> switchStatus.setText("Switch is currently OFF");<br /> }<br /> }<br /><br /> @Override<br /> public boolean onCreateOptionsMenu(Menu menu) {<br /> // Inflate the menu; this adds items to the action bar if it is present.<br /> getMenuInflater().inflate(R.menu.activity_main, menu);<br /> return true;<br /> }<br /><br />}</code></blockquote>
<div class="line number57 index56 alt2">
</div>
</div>
</td></tr>
</tbody></table>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-15125831809447996562014-12-03T09:52:00.005+07:002014-12-03T09:54:39.066+07:00How to download the playlist from youtube and play the videos in android1) Click on the link to register your application to get the developer api key<br />
<a href="https://developers.google.com/youtube/v3/">https://developers.google.com/youtube/v3/</a><br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-QT61ifR7srs/UsLCZHt8uzI/AAAAAAAAAWk/q31AdHeQ57w/s1600/first.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-QT61ifR7srs/UsLCZHt8uzI/AAAAAAAAAWk/q31AdHeQ57w/s400/first.jpg" height="320" width="400" /></a></div>
<br />
<br />
2) After clicking on the above link click on Register your application <br />
this will redirect you to a Google console page<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-u-p5Jk4mg4I/UsLCi3qhpMI/AAAAAAAAAWs/2edJiMclUMA/s1600/second.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-u-p5Jk4mg4I/UsLCi3qhpMI/AAAAAAAAAWs/2edJiMclUMA/s400/second.jpg" height="320" width="400" /></a></div>
<br />
<br />
<b> Create a new project</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-VNFEKkpCZ9g/UsLDBmTz6EI/AAAAAAAAAW0/fINKpBBB3ac/s1600/third.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-VNFEKkpCZ9g/UsLDBmTz6EI/AAAAAAAAAW0/fINKpBBB3ac/s400/third.jpg" height="320" width="400" /></a></div>
<br />
a) Enter the name of your project and check the term and service box.<br />
b) Click create after this it will ask to verify your account enter the <b>SMS</b> code <br />
that you get via <b>SMS</b><br />
<br />
<br />
3) After verifying click on APIs under APIs and auth.<br />
Turn <span style="color: lime;"><span style="color: blue;"><b>ON</b></span> </span>the <span style="color: red;"><b>YouTube Analytics API</b></span> and <span style="color: red;"><b>YouTube Data API v3</b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-uuUxrOrIHUQ/UsLDdBXB--I/AAAAAAAAAW8/Au9gYyn6b-A/s1600/four.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-uuUxrOrIHUQ/UsLDdBXB--I/AAAAAAAAAW8/Au9gYyn6b-A/s400/four.jpg" height="320" width="400" /></a></div>
<br />
<br />
4) Now click on credentials<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-ZgLyumfsBV4/UsLDzONsGpI/AAAAAAAAAXE/S1YyhlYqIcg/s1600/five.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-ZgLyumfsBV4/UsLDzONsGpI/AAAAAAAAAXE/S1YyhlYqIcg/s400/five.jpg" height="320" width="400" /></a></div>
<br />
<span style="color: red;"><b> In public API access</b></span> <br />
Click create new key to generate the <i><b><span style="color: red;">Android API key </span></b></i><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-PKXiwWuuoOU/UsLEC-SaAxI/AAAAAAAAAXM/bmMYerFjYOU/s1600/six.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-PKXiwWuuoOU/UsLEC-SaAxI/AAAAAAAAAXM/bmMYerFjYOU/s400/six.jpg" height="320" width="400" /></a></div>
<br />
<br />
<b> For this open your cmd prompt change the location for your current directory to <br /> C:\Program Files\Java\jdk1.6.0_16\bin></b> and type<br />
<div style="text-align: left;">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-Om1BeiTOqjI/UsLFLrkUKmI/AAAAAAAAAXY/Kndm_jODUAw/s1600/hello.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-Om1BeiTOqjI/UsLFLrkUKmI/AAAAAAAAAXY/Kndm_jODUAw/s400/hello.jpg" height="320" width="400" /></a></div>
<span style="color: blue;"> </span></div>
<div style="text-align: left;">
<span style="color: blue;"> keytool -v -list -alias androiddebugkey -keystore "Your debug key location" -storepass android </span></div>
<div style="text-align: left;">
<span style="color: blue;"> -keypass android</span> </div>
<div style="text-align: left;">
<br />
this will give you the SHA1 fingerprints copy the fingerprints and paste the fingerprints to the API </div>
<div style="text-align: left;">
Console box with the<b> package name of your project</b> and click create.<br />
<br />
5) Now copy the Android API key and save it to some Notepad.</div>
<br />
6) Again go to the create new key and generate the <i><span style="color: red;"><b>Browser API key</b></span></i> add some <b>valid url </b>and click <br />
on create<br />
copy the API key and save that key to some Notepad.<br />
<br />
7) You Need to download the<span style="color: blue;"><b> YouTubeAndroidPlayerApi.jar</b></span> from this link <a href="https://github.com/youtube/yt-direct-lite-android">https://github.com/youtube/yt-direct-lite-android</a> download the Zip extract it and copy the <b>jar from the lib folder</b> to your<b> project lib folder.</b><br />
<br />
8)<b> </b>Now open<b> </b>eclipse create a new project Android Application Project enter the <i><b><span style="color: red;">name of project </span></b></i><br />
for example<br />
<b>Youtube</b> and the <b><i><span style="color: red;">package name</span> </i>com.example.youtube</b><br />
click Next to enter the activity name for example MainActivity<br />
and then click finish.<br />
<br />
9) In activity_main.xml type the following code<br />
<br />
<blockquote class="tr_bq">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
xmlns:tools="http://schemas.android.com/tools"<br />
android:layout_width="match_parent"<br />
android:layout_height="match_parent" ><br />
<br />
<ListView<br />
android:layout_width="fill_parent"<br />
android:layout_height="fill_parent"<br />
android:id="@+id/videolist"/><br />
<br />
</LinearLayout></blockquote>
<br />
10) Right click on layout folder create new <span style="color: red;"><b>android xml file</b></span> name it<br />
a) <b><span style="color: blue;">textvideo.xml </span></b>type the following code<br />
<br />
<blockquote class="tr_bq">
<?xml version="1.0" encoding="utf-8"?><br />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:layout_width="fill_parent"<br />
android:layout_height="wrap_content" ><br />
<br />
<ImageView<br />
android:id="@+id/tumbhid"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:paddingBottom="2dp"<br />
android:paddingLeft="4dp" /><br />
<br />
<TextView<br />
android:id="@+id/label"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:paddingLeft="118dp"<br />
android:textColor="#5D2EE8"<br />
android:textSize="20sp" ><br />
</TextView><br />
<br />
</RelativeLayout></blockquote>
<br />
b) full_screendemo.xml type the following code<br />
<br />
<blockquote class="tr_bq">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
android:id="@+id/layout"<br />
android:layout_width="match_parent"<br />
android:layout_height="match_parent"<br />
android:orientation="vertical" ><br />
<br />
<com.google.android.youtube.player.YouTubePlayerView<br />
android:id="@+id/player"<br />
android:layout_width="match_parent"<br />
android:layout_height="wrap_content" /><br />
<br />
<LinearLayout<br />
android:id="@+id/other_views"<br />
android:layout_width="match_parent"<br />
android:layout_height="0dp"<br />
android:layout_weight="1"<br />
android:orientation="vertical"<br />
android:background="@android:color/black"<br />
android:padding="5dp" ><br />
<CheckBox<br />
android:id="@+id/landscape_fullscreen_checkbox"<br />
android:layout_width="wrap_content"<br />
android:layout_height="wrap_content"<br />
android:layout_marginTop="10dp"<br />
android:textColor="@android:color/white"<br />
android:text="@string/landscape_fullscreen" /><br />
</LinearLayout><br />
</LinearLayout></blockquote>
<br />
11) Navigate to Values folder open the <b>Strings.xml file</b> and add following values<br />
<br />
<blockquote class="tr_bq">
<string name="error_player">There was an error initializing the YouTubePlayer</string><br />
<string name="landscape_fullscreen">Click on check for full screen video in landscape mode</string><br />
<string name="enter_fullscreen">Enter Fullscreen</string></blockquote>
<br />
<br />
12) Navigate to source folder open the MainActivity.java and type this code<br />
<br />
<blockquote class="tr_bq">
package com.example.youtube;<br />
<br />
import java.util.ArrayList;<br />
<br />
import org.json.JSONArray;<br />
import org.json.JSONObject;<br />
import com.example.youtube.R;<br />
import android.os.AsyncTask;<br />
import android.os.Bundle;<br />
import android.accounts.AccountManager;<br />
import android.accounts.AccountManagerCallback;<br />
import android.accounts.AccountManagerFuture;<br />
import android.app.Activity;<br />
import android.app.ProgressDialog;<br />
import android.content.Intent;<br />
import android.util.Log;<br />
import android.view.Menu;<br />
import android.view.View;<br />
import android.widget.AdapterView;<br />
import android.widget.AdapterView.OnItemClickListener;<br />
import android.widget.ListView;<br />
<br />
public class MainActivity extends Activity implements OnItemClickListener{<br />
<br />
private ArrayList<Video> videoArrayList;<br />
private ListView listVideo;<br />
private VideoAdapter videoAdapter;<br />
private String auth_token;<br />
private Video vObject;<br />
private JsonParser parserVideo;<br />
private ProgressDialog progress;<br />
<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.activity_main);<br />
listVideo=(ListView)findViewById(R.id.videolist);<br />
parserVideo=new JsonParser();<br />
getAuthToken(); <br />
videoArrayList=new ArrayList<Video>();<br />
listVideo.setOnItemClickListener(this);<br />
listVideo.setAdapter(videoAdapter);<br />
}<br />
<br />
@Override<br />
public boolean onCreateOptionsMenu(Menu menu) {<br />
// Inflate the menu; this adds items to the action bar if it is present.<br />
getMenuInflater().inflate(R.menu.main, menu);<br />
return true;<br />
}<br />
<br />
@Override<br />
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {<br />
// TODO Auto-generated method stub<br />
// here we are getting the index of listview and through this we are getting the youtube video id<br />
vObject=videoArrayList.get(position); <br />
String video=vObject.getVideoId();<br />
Intent inFullScreenDemo=new Intent(MainActivity.this,FullscreenDemoActivity.class);<br />
inFullScreenDemo.putExtra("video",video);<br />
inFullScreenDemo.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK);<br />
startActivity(inFullScreenDemo); <br />
}<br />
////This method is used to get the auth_token from your gmail sync account////<br />
public void getAuthToken(){<br />
AccountManager.get(getApplicationContext()).getAuthTokenByFeatures("com.google",
"oauth2:https://gdata.youtube.com", null, this,<br />
null, null, new AccountManagerCallback<Bundle>() {<br />
@Override<br />
public void run(AccountManagerFuture<Bundle> future) {<br />
try {<br />
Bundle bundle = future.getResult();<br />
@SuppressWarnings("unused")<br />
String acc_name = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);<br />
auth_token = bundle.getString(AccountManager.KEY_AUTHTOKEN);<br />
Log.e("auth_token",auth_token);<br />
} catch (Exception e) { <br />
e.printStackTrace(); <br />
}<br />
}<br />
}, null); <br />
new Async().execute(""); <br />
}<br />
<br />
public ArrayList<Video>parsingJson(String videoUrl){<br />
try { <br />
JSONObject json=parserVideo.getJsonFromYoutube(videoUrl+auth_token);<br />
JSONArray jArray=new JSONArray(json.getString("items"));<br />
for(int i=0;i<jArray.length();i++){<br />
JSONObject thumbnail=jArray.getJSONObject(i);<br />
JSONObject snippets=thumbnail.getJSONObject("snippet");<br />
JSONObject defaulturl=snippets.getJSONObject("thumbnails");<br />
JSONObject url=defaulturl.getJSONObject("high");<br />
JSONObject resourceId=snippets.getJSONObject("resourceId");<br />
String videoId=resourceId.getString("videoId");<br />
String imageurl=url.getString("url");<br />
String title=snippets.getString("title");<br />
vObject=new Video(title, imageurl, videoId);<br />
videoArrayList.add(i,vObject); <br />
//Log.e("videoArrayList",""+videoArrayList.size());<br />
}<br />
} catch (Exception e) {<br />
e.printStackTrace(); <br />
} <br />
return videoArrayList;<br />
}<br />
<br />
public void invalidateAccount(){<br />
AccountManager accountManager = AccountManager.get(MainActivity.this);<br />
accountManager.invalidateAuthToken("com.google",auth_token);<br />
}<br />
///This class is used to do some background task.<br />
//Here in this blog, we are using it for parsing the JSON data <br />
//that we are getting from youtube. <br />
public class Async extends AsyncTask<String,String,String>{<br />
ArrayList<Video> videolist;<br />
@Override<br />
protected void onPreExecute() {<br />
// TODO Auto-generated method stub<br />
super.onPreExecute();<br />
progress=new ProgressDialog(MainActivity.this);<br />
progress.setMessage("Loading data...");<br />
progress.show();<br />
}<br />
@Override<br />
protected String doInBackground(String... params) {<br />
// TODO Auto-generated method stub<br />
try{<br />
videolist=parsingJson(parserVideo.url); //through this method we are parsing the data <br />
}catch (Exception e) {<br />
// TODO: handle exception<br />
finish(); //If some exception occur we are killing the application<br />
<br />
}<br />
return null;<br />
}<br />
@Override<br />
protected void onPostExecute(String result) {<br />
// TODO Auto-generated method stub<br />
super.onPostExecute(result);<br />
try{<br />
//videoAdapter class is used to customized the ListView<br />
videoAdapter=new
VideoAdapter(MainActivity.this,videolist,MainActivity.this.getContentResolver(),MainActivity.this.getResources());
<br />
listVideo.setAdapter(videoAdapter);<br />
listVideo.setFastScrollEnabled(true);<br />
progress.dismiss(); // Here we are closing the progress dialog after completing the background task.<br />
}catch (Exception e) {<br />
// TODO: handle exception<br />
}<br />
}<br />
}<br />
<br />
}</blockquote>
<br />
13) Right Click to <b>com.example.youtube </b>create new java class name it <span style="background-color: blue;"><b><span style="color: blue;"><span style="background-color: white;">Video.java </span></span></b></span>and type this code<br />
<br />
<blockquote class="tr_bq">
package com.example.youtube;<br />
<br />
public class Video {<br />
private String videoTitle;<br />
private String videoThumbnail;<br />
private String videoId;<br />
public String getVideoTitle() {<br />
return videoTitle;<br />
}<br />
public void setVideoTitle(String videoTitle) {<br />
this.videoTitle = videoTitle;<br />
}<br />
public String getVideoThumbnail() {<br />
return videoThumbnail;<br />
}<br />
public void setVideoThumbnail(String videoThumbnail) {<br />
this.videoThumbnail = videoThumbnail;<br />
}<br />
public String getVideoId() {<br />
return videoId;<br />
}<br />
public void setVideoId(String videoId) {<br />
this.videoId = videoId;<br />
}<br />
public Video(String videoTitle, String videoThumbnail, String videoId) {<br />
super();<br />
this.videoTitle = videoTitle;<br />
this.videoThumbnail = videoThumbnail;<br />
this.videoId = videoId;<br />
}<br />
<br />
public Video() {<br />
super();<br />
}<br />
@Override<br />
public String toString() {<br />
return "Video [videoTitle=" + videoTitle + ", videoThumbnail="<br />
+ videoThumbnail + ", videoId=" + videoId + "]";<br />
}<br />
}</blockquote>
<br />
14) Right Click to <b>com.example.youtube </b>create new java class name it <b><span style="color: blue;">VideoAdapter.java</span></b><br />
and in <b>Superclass tab</b> type <span style="color: blue;"><b>android.widget.ArrayAdapter </b></span><br />
<br />
<blockquote class="tr_bq">
package com.example.youtube;<br />
<br />
import java.util.ArrayList;<br />
import java.util.Collections;<br />
import java.util.HashMap;<br />
import java.util.Set;<br />
import com.example.youtube.R;<br />
import com.example.loadimage.ImageLoader;<br />
<br />
import android.content.ContentResolver;<br />
import android.content.Context;<br />
import android.content.res.Resources;<br />
import android.view.LayoutInflater;<br />
import android.view.View;<br />
import android.view.ViewGroup;<br />
import android.widget.ArrayAdapter;<br />
import android.widget.ImageView;<br />
import android.widget.RelativeLayout;<br />
import android.widget.SectionIndexer;<br />
import android.widget.TextView;<br />
public class VideoAdapter extends ArrayAdapter<Video> implements SectionIndexer {<br />
<br />
@SuppressWarnings("unused")<br />
private final Context context;<br />
private final ArrayList<Video> itemsArrayList;<br />
ContentResolver resolver;<br />
Resources resource;<br />
HashMap<String, Integer> alphaIndexer;<br />
String[] sections;<br />
private ImageLoader imgLoader;<br />
<br />
public VideoAdapter(Context context, ArrayList<Video> itemsArrayList,ContentResolver resolver,Resources resource) {<br />
<br />
super(context, R.layout.textvideo, itemsArrayList);<br />
this.context = context;<br />
this.itemsArrayList = itemsArrayList;<br />
this.resolver=resolver;<br />
this.resource=resource;<br />
<br />
alphaIndexer = new HashMap<String, Integer>();<br />
int size = itemsArrayList.size();<br />
<br />
for (int x = 0; x < size; x++) {<br />
Video s = itemsArrayList.get(x);<br />
// get the first letter of the store<br />
String ch = s.getVideoTitle().substring(0, 1);<br />
// convert to uppercase otherwise lowercase a -z will be sorted<br />
// after upper A-Z <br />
ch = ch.toUpperCase();<br />
// put only if the key does not exist<br />
if (!alphaIndexer.containsKey(ch))<br />
alphaIndexer.put(ch, x);<br />
}<br />
imgLoader = new ImageLoader(context);<br />
Set<String> sectionLetters = alphaIndexer.keySet();<br />
// create a list from the set to sort<br />
ArrayList<String> sectionList = new ArrayList<String>(<br />
sectionLetters);<br />
Collections.sort(sectionList);<br />
sections = new String[sectionList.size()];<br />
sections = sectionList.toArray(sections);<br />
notifyDataSetChanged(); <br />
}<br />
<br />
@Override<br />
public View getView(int position, View convertView, ViewGroup parent) {<br />
RelativeLayout alertView;<br />
//Get the current alert object<br />
// alerts al = getItem(position);<br />
<br />
//Inflate the view<br />
if(convertView==null)<br />
{<br />
alertView = new RelativeLayout(getContext());<br />
String inflater = Context.LAYOUT_INFLATER_SERVICE;<br />
LayoutInflater vi;<br />
vi = (LayoutInflater)getContext().getSystemService(inflater);<br />
vi.inflate(R.layout.textvideo, alertView, true);<br />
}<br />
else<br />
{<br />
alertView = (RelativeLayout) convertView;<br />
}<br />
ImageView image=(ImageView)alertView.findViewById(R.id.tumbhid);<br />
TextView labelView = (TextView) alertView.findViewById(R.id.label);<br />
imgLoader.DisplayImage(itemsArrayList.get(position).getVideoThumbnail(), R.drawable.ic_launcher, image);<br />
labelView.setText(itemsArrayList.get(position).getVideoTitle());<br />
return alertView;<br />
}<br />
<br />
@Override<br />
public int getPositionForSection(int section) {<br />
// TODO Auto-generated method stub<br />
return alphaIndexer.get(sections[section]);<br />
}<br />
<br />
@Override<br />
public int getSectionForPosition(int position) {<br />
// TODO Auto-generated method stub<br />
return 0;<br />
}<br />
<br />
@Override<br />
public Object[] getSections() {<br />
// TODO Auto-generated method stub<br />
return sections;<br />
}<br />
}</blockquote>
<br />
<br />
<br />
15) Right Click to <b>com.example.youtube </b>create new java class name it <b><span style="color: blue;">JsonParser.java </span></b><br />
and type this code<br />
<br />
<blockquote class="tr_bq">
package com.example.youtube;<br />
<br />
import java.io.BufferedReader;<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.io.InputStreamReader;<br />
import java.io.UnsupportedEncodingException;<br />
import java.util.zip.GZIPInputStream;<br />
<br />
import org.apache.http.Header;<br />
import org.apache.http.HttpEntity;<br />
import org.apache.http.HttpResponse;<br />
import org.apache.http.client.methods.HttpGet;<br />
import org.apache.http.impl.client.DefaultHttpClient;<br />
import org.json.JSONObject;<br />
<br />
import android.util.Log;<br />
<br />
public class JsonParser {<br />
<br />
public String
url="https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=30&playlistId=PLuwvwpFd3r9VCVeEymYcRqmoPVFzJjhZJ&fields=items(contentDetails%2Cetag%2Cid%2Csnippet)%2CnextPageToken&key=<b><span style="color: magenta;">"ENTER Your Browser API KEY"</span></b>&access_token=";<br />
<br />
//You can change the playlistId<br />
//You can change the maxResults from 30 to 50 only videos can be fetched at a time<br />
//For more detail go to this link <span style="color: blue;"><a href="https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it">https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it </a></span><br />
<br />
private static StringBuilder sb;<br />
private JSONObject jObj; <br />
<br />
public JsonParser() {<br />
// TODO Auto-generated constructor stub<br />
}<br />
<br />
public JSONObject getJsonFromYoutube(String url){ <br />
DefaultHttpClient httpclient = new DefaultHttpClient();<br />
Log.e("url",url); <br />
HttpGet getRequest = new HttpGet(url);<br />
getRequest.setHeader("Accept", "application/json");<br />
// Use GZIP encoding<br />
getRequest.setHeader("Accept-Encoding", "gzip"); //<br />
try {<br />
HttpResponse response = (HttpResponse) httpclient<br />
.execute(getRequest);<br />
HttpEntity entity = response.getEntity();<br />
if (entity != null) {<br />
InputStream instream = entity.getContent();<br />
Header contentEncoding = response.getFirstHeader("Content-Encoding");<br />
if (contentEncoding != null<br />
&& contentEncoding.getValue().equalsIgnoreCase("gzip")) {<br />
instream = new GZIPInputStream(instream);<br />
}<br />
// convert content stream to a String<br />
String result = readStream(instream);<br />
Log.i("JSON", result);<br />
instream.close();<br />
jObj = new JSONObject(result);<br />
}<br />
} catch (Exception e) {<br />
e.printStackTrace();<br />
}<br />
return jObj;<br />
}<br />
private static String readStream(InputStream is) {<br />
BufferedReader reader;<br />
try {<br />
reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);<br />
<br />
sb = new StringBuilder();<br />
<br />
String line = null;<br />
try {<br />
while ((line = reader.readLine()) != null) {<br />
sb.append(line + "\n");<br />
}<br />
} catch (IOException e) {<br />
e.printStackTrace();<br />
} finally {<br />
try {<br />
is.close();<br />
} catch (IOException e) {<br />
e.printStackTrace();<br />
}<br />
}<br />
} catch (UnsupportedEncodingException e1) {<br />
// TODO Auto-generated catch block<br />
e1.printStackTrace();<br />
}<br />
return sb.toString();<br />
}<br />
}</blockquote>
<br />
16) Right Click to <b>com.example.youtube </b>create new java class name it <b><span style="color: blue;">DeveloperKey.java</span></b> and type this code<br />
<br />
// Copyright 2012 Google Inc. All Rights Reserved.<br />
<br />
<blockquote class="tr_bq">
package com.example.youtube;<br />
<br />
/**<br />
* Static container class for holding a reference to your YouTube Developer Key.<br />
*/<br />
public class DeveloperKey {<br />
<br />
/**<br />
* Please replace this with a valid API key which is enabled for the <br />
* YouTube Data API v3 service. Go to the <br />
* <a href="https://code.google.com/apis/console/">Google APIs Console</a> to<br />
* register a new developer key.<br />
*/<br />
public static final String DEVELOPER_KEY = <span style="color: magenta;"><b>"Enter your Android API KEY"</b></span>;<br />
<br />
}</blockquote>
<br />
17) Right Click to <b>com.example.youtube </b>create new java class name it <b><span style="color: blue;">FullscreenDemoActivity.java</span></b> and type this code<br />
<blockquote class="tr_bq">
<br />
/*<br />
* Copyright 2012 Google Inc. All Rights Reserved.<br />
*<br />
* Licensed under the Apache License, Version 2.0 (the "License");<br />
* you may not use this file except in compliance with the License.<br />
* You may obtain a copy of the License at<br />
*<br />
* http://www.apache.org/licenses/LICENSE-2.0<br />
*<br />
* Unless required by applicable law or agreed to in writing, software<br />
* distributed under the License is distributed on an "AS IS" BASIS,<br />
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br />
* See the License for the specific language governing permissions and<br />
* limitations under the License.<br />
*/<br />
<br />
package com.example.youtube;<br />
<br />
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;<br />
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;<br />
import com.example.youtube.R;<br />
import com.google.android.youtube.player.YouTubePlayer;<br />
import com.google.android.youtube.player.YouTubePlayerView;<br />
import android.content.Intent;<br />
import android.content.pm.ActivityInfo;<br />
import android.content.res.Configuration;<br />
import android.os.Build;<br />
import android.os.Bundle;<br />
import android.view.View;<br />
import android.view.ViewGroup;<br />
import android.view.Window;<br />
import android.view.WindowManager;<br />
import android.widget.CompoundButton;<br />
import android.widget.LinearLayout;<br />
import android.widget.LinearLayout.LayoutParams;<br />
<br />
/**<br />
* Sample activity showing how to properly enable custom fullscreen behavior.<br />
* <p><br />
* This is the preferred way of handling fullscreen because the default fullscreen implementation<br />
* will cause re-buffering of the video.<br />
*/<br />
public class FullscreenDemoActivity extends YouTubeFailureRecoveryActivity implements<br />
View.OnClickListener,<br />
CompoundButton.OnCheckedChangeListener,<br />
YouTubePlayer.OnFullscreenListener {<br />
<br />
private static final int PORTRAIT_ORIENTATION = Build.VERSION.SDK_INT < 9<br />
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT<br />
: ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;<br />
<br />
private LinearLayout baseLayout;<br />
private YouTubePlayerView playerView;<br />
private YouTubePlayer player;<br />
// private Button fullscreenButton;<br />
private CompoundButton checkbox;<br />
private View otherViews;<br />
<br />
private boolean fullscreen;<br />
<br />
private String videoid;<br />
<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
requestWindowFeature(Window.FEATURE_NO_TITLE);<br />
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);<br />
setContentView(R.layout.fullscreen_demo);<br />
baseLayout = (LinearLayout) findViewById(R.id.layout);<br />
playerView = (YouTubePlayerView) findViewById(R.id.player);<br />
// fullscreenButton = (Button) findViewById(R.id.fullscreen_button);<br />
checkbox = (CompoundButton) findViewById(R.id.landscape_fullscreen_checkbox);<br />
otherViews = findViewById(R.id.other_views);<br />
Intent intent=getIntent();<br />
videoid=intent.getStringExtra("video");<br />
checkbox.setOnCheckedChangeListener(this);<br />
// You can use your own button to switch to fullscreen too<br />
// fullscreenButton.setOnClickListener(this);<br />
<br />
playerView.initialize(DeveloperKey.DEVELOPER_KEY, this);<br />
<br />
doLayout();<br />
}<br />
<br />
@Override<br />
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,<br />
boolean wasRestored) {<br />
this.player = player;<br />
setControlsEnabled();<br />
// Specify that we want to handle fullscreen behavior ourselves.<br />
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);<br />
player.setOnFullscreenListener(this);<br />
if (!wasRestored) {<br />
player.cueVideo(videoid);<br />
}<br />
}<br />
<br />
@Override<br />
protected YouTubePlayer.Provider getYouTubePlayerProvider() {<br />
return playerView;<br />
}<br />
<br />
@Override<br />
public void onClick(View v) {<br />
// player.setFullscreen(!fullscreen);<br />
}<br />
<br />
@Override<br />
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {<br />
int controlFlags = player.getFullscreenControlFlags();<br />
if (isChecked) {<br />
// If you use the FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE, your activity's normal UI<br />
// should never be laid out in landscape mode (since the video will be fullscreen whenever the<br />
// activity is in landscape orientation). Therefore you should set the activity's requested<br />
// orientation to portrait. Typically you would do this in your AndroidManifest.xml, we do it<br />
// programmatically here since this activity demos fullscreen behavior both with and without<br />
// this flag).<br />
setRequestedOrientation(PORTRAIT_ORIENTATION);<br />
controlFlags |= YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;<br />
} else {<br />
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);<br />
controlFlags &= ~YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;<br />
}<br />
player.setFullscreenControlFlags(controlFlags);<br />
}<br />
<br />
private void doLayout() {<br />
LinearLayout.LayoutParams playerParams =<br />
(LinearLayout.LayoutParams) playerView.getLayoutParams();<br />
if (fullscreen) {<br />
// When in fullscreen, the visibility of all other views than the player should be set to<br />
// GONE and the player should be laid out across the whole screen.<br />
playerParams.width = LayoutParams.MATCH_PARENT;<br />
playerParams.height = LayoutParams.MATCH_PARENT;<br />
<br />
otherViews.setVisibility(View.GONE);<br />
} else {<br />
// This layout is up to you - this is just a simple example (vertically stacked boxes in<br />
// portrait, horizontally stacked in landscape).<br />
otherViews.setVisibility(View.VISIBLE);<br />
ViewGroup.LayoutParams otherViewsParams = otherViews.getLayoutParams();<br />
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {<br />
playerParams.width = otherViewsParams.width = 0;<br />
playerParams.height = WRAP_CONTENT;<br />
otherViewsParams.height = MATCH_PARENT;<br />
playerParams.weight = 1;<br />
baseLayout.setOrientation(LinearLayout.HORIZONTAL);<br />
} else {<br />
playerParams.width = otherViewsParams.width = MATCH_PARENT;<br />
playerParams.height = WRAP_CONTENT;<br />
playerParams.weight = 0;<br />
otherViewsParams.height = 0;<br />
baseLayout.setOrientation(LinearLayout.VERTICAL);<br />
}<br />
setControlsEnabled();<br />
}<br />
}<br />
<br />
private void setControlsEnabled() {<br />
checkbox.setEnabled(player != null<br />
&& getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);<br />
// fullscreenButton.setEnabled(player != null);<br />
}<br />
<br />
@Override<br />
public void onFullscreen(boolean isFullscreen) {<br />
fullscreen = isFullscreen;<br />
doLayout();<br />
}<br />
<br />
@Override<br />
public void onConfigurationChanged(Configuration newConfig) {<br />
super.onConfigurationChanged(newConfig);<br />
doLayout();<br />
} <br />
<br />
}</blockquote>
<br />
18)Right Click to <b>com.example.youtube </b>create new java class name it <b><span style="color: blue;">YouTubeFailureRecoveryActivity.java</span></b> and type this code<br />
<blockquote class="tr_bq">
<br />
/*<br />
* Copyright 2012 Google Inc. All Rights Reserved.<br />
*<br />
* Licensed under the Apache License, Version 2.0 (the "License");<br />
* you may not use this file except in compliance with the License.<br />
* You may obtain a copy of the License at<br />
*<br />
* http://www.apache.org/licenses/LICENSE-2.0<br />
*<br />
* Unless required by applicable law or agreed to in writing, software<br />
* distributed under the License is distributed on an "AS IS" BASIS,<br />
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br />
* See the License for the specific language governing permissions and<br />
* limitations under the License.<br />
*/<br />
<br />
package com.example.youtube;<br />
<br />
import com.example.youtube.R;<br />
import com.google.android.youtube.player.YouTubeBaseActivity;<br />
import com.google.android.youtube.player.YouTubeInitializationResult;<br />
import com.google.android.youtube.player.YouTubePlayer;<br />
<br />
import android.content.Intent;<br />
import android.widget.Toast;<br />
<br />
/**<br />
* An abstract activity which deals with recovering from errors which may occur during API<br />
* initialization, but can be corrected through user action.<br />
*/<br />
public abstract class YouTubeFailureRecoveryActivity extends YouTubeBaseActivity implements<br />
YouTubePlayer.OnInitializedListener {<br />
<br />
private static final int RECOVERY_DIALOG_REQUEST = 1;<br />
<br />
@Override<br />
public void onInitializationFailure(YouTubePlayer.Provider provider,<br />
YouTubeInitializationResult errorReason) {<br />
if (errorReason.isUserRecoverableError()) {<br />
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();<br />
} else {<br />
String errorMessage = String.format(getString(R.string.error_player), errorReason.toString());<br />
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();<br />
}<br />
}<br />
<br />
@Override<br />
protected void onActivityResult(int requestCode, int resultCode, Intent data) {<br />
if (requestCode == RECOVERY_DIALOG_REQUEST) {<br />
// Retry initialization if user performed a recovery action<br />
getYouTubePlayerProvider().initialize(DeveloperKey.DEVELOPER_KEY, this);<br />
}<br />
}<br />
<br />
protected abstract YouTubePlayer.Provider getYouTubePlayerProvider();<br />
<br />
}</blockquote>
<br />
19) Right click to source folder,Create new package name it<span style="color: red;"><b> com.example.loadimage<span style="color: black;"> </span></b></span><br />
<span style="color: red;"><b><span style="color: black;"> </span></b><span style="color: black;">Create new class in this package name it as <span style="color: blue;"><b>ImageLoader.java</b></span> </span></span><br />
<span style="color: red;"><span style="color: black;"> </span></span><br />
<span style="color: red;"><span style="color: black;"> // This class is used to cache the image </span></span><br />
<span style="color: red;"><span style="color: black;"><br /></span></span>
<blockquote class="tr_bq">
<span style="color: red;"><span style="color: black;">package com.example.loadimage;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.File;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.FileInputStream;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.FileNotFoundException;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.FileOutputStream;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.InputStream;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.OutputStream;</span></span><br /><span style="color: red;"><span style="color: black;">//import java.net.HttpURLConnection;</span></span><br /><span style="color: red;"><span style="color: black;">import java.net.URL;</span></span><br /><span style="color: red;"><span style="color: black;">import java.util.Collections;</span></span><br /><span style="color: red;"><span style="color: black;">import java.util.Map;</span></span><br /><span style="color: red;"><span style="color: black;">import java.util.WeakHashMap;</span></span><br /><span style="color: red;"><span style="color: black;">import java.util.concurrent.ExecutorService;</span></span><br /><span style="color: red;"><span style="color: black;">import java.util.concurrent.Executors;</span></span><br /><span style="color: red;"><span style="color: black;">import javax.net.ssl.HttpsURLConnection;</span></span><br /><span style="color: red;"><span style="color: black;">import com.example.youtube.R;</span></span><br /><span style="color: red;"><span style="color: black;">import android.app.Activity;</span></span><br /><span style="color: red;"><span style="color: black;">import android.content.Context;</span></span><br /><span style="color: red;"><span style="color: black;">import android.graphics.Bitmap;</span></span><br /><span style="color: red;"><span style="color: black;">import android.graphics.BitmapFactory;</span></span><br /><span style="color: red;"><span style="color: black;">import android.util.Log;</span></span><br /><span style="color: red;"><span style="color: black;">import android.widget.ImageView;</span></span><br /><span style="color: red;"><span style="color: black;">public class ImageLoader {</span></span><br /><span style="color: red;"><span style="color: black;"> MemoryCache memoryCache=new MemoryCache();</span></span><br /><span style="color: red;"><span style="color: black;"> FileCache fileCache;</span></span><br /><span style="color: red;"><span style="color: black;"> private Map<ImageView, String> imageViews=Collections.synchronizedMap(new WeakHashMap<ImageView, String>());</span></span><br /><span style="color: red;"><span style="color: black;"> ExecutorService executorService;</span></span><br /><br /><span style="color: red;"><span style="color: black;"> public ImageLoader(Context context){</span></span><br /><span style="color: red;"><span style="color: black;"> fileCache=new FileCache(context);</span></span><br /><span style="color: red;"><span style="color: black;"> executorService=Executors.newFixedThreadPool(5);</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> int stub_id = R.drawable.ic_launcher;</span></span><br /><span style="color: red;"><span style="color: black;"> public void DisplayImage(String url, int loader, ImageView imageView)</span></span><br /><span style="color: red;"><span style="color: black;"> {</span></span><br /><span style="color: red;"><span style="color: black;"> stub_id = loader;</span></span><br /><span style="color: red;"><span style="color: black;"> imageViews.put(imageView, url);</span></span><br /><span style="color: red;"><span style="color: black;"> Bitmap bitmap=memoryCache.get(url);</span></span><br /><span style="color: red;"><span style="color: black;"> if(bitmap!=null)</span></span><br /><span style="color: red;"><span style="color: black;"> imageView.setImageBitmap(bitmap);</span></span><br /><span style="color: red;"><span style="color: black;"> else</span></span><br /><span style="color: red;"><span style="color: black;"> {</span></span><br /><span style="color: red;"><span style="color: black;"> queuePhoto(url, imageView);</span></span><br /><span style="color: red;"><span style="color: black;"> imageView.setImageResource(loader);</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> private void queuePhoto(String url, ImageView imageView)</span></span><br /><span style="color: red;"><span style="color: black;"> {</span></span><br /><span style="color: red;"><span style="color: black;"> PhotoToLoad p=new PhotoToLoad(url, imageView);</span></span><br /><span style="color: red;"><span style="color: black;"> executorService.submit(new PhotosLoader(p));</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> private Bitmap getBitmap(String url)</span></span><br /><span style="color: red;"><span style="color: black;"> { </span></span><br /><span style="color: red;"><span style="color: black;"> File f=fileCache.getFile(url);</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //from SD cache</span></span><br /><span style="color: red;"><span style="color: black;"> Bitmap b = decodeFile(f);</span></span><br /><span style="color: red;"><span style="color: black;"> if(b!=null)</span></span><br /><span style="color: red;"><span style="color: black;"> return b;</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //from web</span></span><br /><span style="color: red;"><span style="color: black;"> try {</span></span><br /><span style="color: red;"><span style="color: black;"> Log.e("urll",""+url.toString());</span></span><br /><br /><span style="color: red;"><span style="color: black;"> Bitmap bitmap=null;</span></span><br /><span style="color: red;"><span style="color: black;"> URL imageUrl = new URL(url.toString());</span></span><br /><span style="color: red;"><span style="color: black;"> HttpsURLConnection conn = (HttpsURLConnection)imageUrl.openConnection();</span></span><br /><span style="color: red;"><span style="color: black;"> conn.setConnectTimeout(30000);</span></span><br /><span style="color: red;"><span style="color: black;"> conn.setReadTimeout(30000);</span></span><br /><span style="color: red;"><span style="color: black;"> conn.setInstanceFollowRedirects(true);</span></span><br /><span style="color: red;"><span style="color: black;"> InputStream is=conn.getInputStream();</span></span><br /><span style="color: red;"><span style="color: black;"> OutputStream os = new FileOutputStream(f);</span></span><br /><span style="color: red;"><span style="color: black;"> Utils.CopyStream(is, os);</span></span><br /><span style="color: red;"><span style="color: black;"> os.close();</span></span><br /><span style="color: red;"><span style="color: black;"> bitmap = decodeFile(f);</span></span><br /><span style="color: red;"><span style="color: black;"> return bitmap;</span></span><br /><span style="color: red;"><span style="color: black;"> } catch (Exception ex){</span></span><br /><span style="color: red;"><span style="color: black;"> ex.printStackTrace();</span></span><br /><span style="color: red;"><span style="color: black;"> return null;</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //decodes image and scales it to reduce memory consumption</span></span><br /><span style="color: red;"><span style="color: black;"> @SuppressWarnings("static-access")</span></span><br /><span style="color: red;"><span style="color: black;"> private Bitmap decodeFile(File f){</span></span><br /><span style="color: red;"><span style="color: black;"> try {</span></span><br /><span style="color: red;"><span style="color: black;"> //decode image size</span></span><br /><span style="color: red;"><span style="color: black;"> BitmapFactory.Options o = new BitmapFactory.Options();</span></span><br /><span style="color: red;"><span style="color: black;"> o.inJustDecodeBounds = true;</span></span><br /><span style="color: red;"><span style="color: black;"> BitmapFactory.decodeStream(new FileInputStream(f),null,o);</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //Find the correct scale value. It should be the power of 2.</span></span><br /><span style="color: red;"><span style="color: black;"> final int REQUIRED_SIZE=70;</span></span><br /><span style="color: red;"><span style="color: black;"> int width_tmp=o.outWidth, height_tmp=o.outHeight;</span></span><br /><span style="color: red;"><span style="color: black;"> int scale=1;</span></span><br /><span style="color: red;"><span style="color: black;"> while(true){</span></span><br /><span style="color: red;"><span style="color: black;"> if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)</span></span><br /><span style="color: red;"><span style="color: black;"> break;</span></span><br /><span style="color: red;"><span style="color: black;"> width_tmp/=2;</span></span><br /><span style="color: red;"><span style="color: black;"> height_tmp/=2;</span></span><br /><span style="color: red;"><span style="color: black;"> scale*=2;</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //decode with inSampleSize</span></span><br /><span style="color: red;"><span style="color: black;"> BitmapFactory.Options o2 = new BitmapFactory.Options();</span></span><br /><span style="color: red;"><span style="color: black;"> o2.inSampleSize=2;</span></span><br /><span style="color: red;"><span style="color: black;"> Bitmap b=BitmapFactory.decodeStream(new FileInputStream(f), null, o2);</span></span><br /><span style="color: red;"><span style="color: black;"> return b.createScaledBitmap(b,80, 60,true); </span></span><br /><span style="color: red;"><span style="color: black;"> } catch (FileNotFoundException e) {}</span></span><br /><span style="color: red;"><span style="color: black;"> return null;</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //Task for the queue</span></span><br /><span style="color: red;"><span style="color: black;"> private class PhotoToLoad</span></span><br /><span style="color: red;"><span style="color: black;"> {</span></span><br /><span style="color: red;"><span style="color: black;"> public String url;</span></span><br /><span style="color: red;"><span style="color: black;"> public ImageView imageView;</span></span><br /><span style="color: red;"><span style="color: black;"> public PhotoToLoad(String u, ImageView i){</span></span><br /><span style="color: red;"><span style="color: black;"> url=u;</span></span><br /><span style="color: red;"><span style="color: black;"> imageView=i;</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> class PhotosLoader implements Runnable {</span></span><br /><span style="color: red;"><span style="color: black;"> PhotoToLoad photoToLoad;</span></span><br /><span style="color: red;"><span style="color: black;"> PhotosLoader(PhotoToLoad photoToLoad){</span></span><br /><span style="color: red;"><span style="color: black;"> this.photoToLoad=photoToLoad;</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> @Override</span></span><br /><span style="color: red;"><span style="color: black;"> public void run() {</span></span><br /><span style="color: red;"><span style="color: black;"> if(imageViewReused(photoToLoad))</span></span><br /><span style="color: red;"><span style="color: black;"> return;</span></span><br /><span style="color: red;"><span style="color: black;"> Bitmap bmp=getBitmap(photoToLoad.url);</span></span><br /><span style="color: red;"><span style="color: black;"> memoryCache.put(photoToLoad.url, bmp);</span></span><br /><span style="color: red;"><span style="color: black;"> if(imageViewReused(photoToLoad))</span></span><br /><span style="color: red;"><span style="color: black;"> return;</span></span><br /><span style="color: red;"><span style="color: black;"> BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad);</span></span><br /><span style="color: red;"><span style="color: black;"> Activity a=(Activity)photoToLoad.imageView.getContext();</span></span><br /><span style="color: red;"><span style="color: black;"> a.runOnUiThread(bd);</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> boolean imageViewReused(PhotoToLoad photoToLoad){</span></span><br /><span style="color: red;"><span style="color: black;"> String tag=imageViews.get(photoToLoad.imageView);</span></span><br /><span style="color: red;"><span style="color: black;"> if(tag==null || !tag.equals(photoToLoad.url))</span></span><br /><span style="color: red;"><span style="color: black;"> return true;</span></span><br /><span style="color: red;"><span style="color: black;"> return false;</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> //Used to display bitmap in the UI thread</span></span><br /><span style="color: red;"><span style="color: black;"> class BitmapDisplayer implements Runnable</span></span><br /><span style="color: red;"><span style="color: black;"> {</span></span><br /><span style="color: red;"><span style="color: black;"> Bitmap bitmap;</span></span><br /><span style="color: red;"><span style="color: black;"> PhotoToLoad photoToLoad;</span></span><br /><span style="color: red;"><span style="color: black;"> public BitmapDisplayer(Bitmap b, PhotoToLoad p){bitmap=b;photoToLoad=p;}</span></span><br /><span style="color: red;"><span style="color: black;"> public void run()</span></span><br /><span style="color: red;"><span style="color: black;"> {</span></span><br /><span style="color: red;"><span style="color: black;"> if(imageViewReused(photoToLoad))</span></span><br /><span style="color: red;"><span style="color: black;"> return;</span></span><br /><span style="color: red;"><span style="color: black;"> if(bitmap!=null)</span></span><br /><span style="color: red;"><span style="color: black;"> photoToLoad.imageView.setImageBitmap(bitmap);</span></span><br /><span style="color: red;"><span style="color: black;"> else</span></span><br /><span style="color: red;"><span style="color: black;"> photoToLoad.imageView.setImageResource(stub_id);</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> public void clearCache() {</span></span><br /><span style="color: red;"><span style="color: black;"> memoryCache.clear();</span></span><br /><span style="color: red;"><span style="color: black;"> fileCache.clear();</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;">}</span></span></blockquote>
<br />
<span style="color: red;"><span style="color: black;">20) </span></span><span style="color: red;"><b><span style="color: black;"> </span></b><span style="color: black;">Create new class in the above package (</span></span><span style="color: red;"><span style="color: black;"><span style="color: red;"><b>com.example.loadimage</b></span>) name it as <span style="color: blue;"><b>FileCache.java</b></span> </span></span><br />
<span style="color: red;"><span style="color: black;"><br /></span></span>
<blockquote class="tr_bq">
<span style="color: red;"><span style="color: black;">package com.example.loadimage;</span></span><br /><span style="color: red;"><span style="color: black;">import java.io.File;</span></span><br /><span style="color: red;"><span style="color: black;">import android.content.Context;</span></span><br /><span style="color: red;"><span style="color: black;">public class FileCache {</span></span><br /><span style="color: red;"><span style="color: black;"> private File cacheDir;</span></span><br /><br /><span style="color: red;"><span style="color: black;"> public FileCache(Context context){</span></span><br /><span style="color: red;"><span style="color: black;"> //Find the dir to save cached images</span></span><br /><span style="color: red;"><span style="color: black;"> if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))</span></span><br /><span style="color: red;"><span style="color: black;"> cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"youtubeimage");</span></span><br /><span style="color: red;"><span style="color: black;"> else</span></span><br /><span style="color: red;"><span style="color: black;"> cacheDir=context.getCacheDir();</span></span><br /><span style="color: red;"><span style="color: black;"> if(!cacheDir.exists())</span></span><br /><span style="color: red;"><span style="color: black;"> cacheDir.mkdirs();</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> public File getFile(String url){</span></span><br /><span style="color: red;"><span style="color: black;"> String filename=String.valueOf(url.hashCode());</span></span><br /><span style="color: red;"><span style="color: black;"> File f = new File(cacheDir, filename);</span></span><br /><span style="color: red;"><span style="color: black;"> return f;</span></span><br /><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><br /><span style="color: red;"><span style="color: black;"> public void clear(){</span></span><br /><span style="color: red;"><span style="color: black;"> File[] files=cacheDir.listFiles();</span></span><br /><span style="color: red;"><span style="color: black;"> if(files==null)</span></span><br /><span style="color: red;"><span style="color: black;"> return;</span></span><br /><span style="color: red;"><span style="color: black;"> for(File f:files)</span></span><br /><span style="color: red;"><span style="color: black;"> f.delete();</span></span><br /><span style="color: red;"><span style="color: black;"> }</span></span><br /><span style="color: red;"><span style="color: black;">}</span></span></blockquote>
<span style="color: red;"><span style="color: black;"></span></span><br />
<br />
<span style="color: red;"><span style="color: black;">21) </span></span><span style="color: red;"><span style="color: black;"> </span></span><span style="color: red;"><b><span style="color: black;"> </span></b><span style="color: black;">Create new class in the above package (</span></span><span style="color: red;"><span style="color: black;"><span style="color: red;"><b>com.example.loadimage</b></span>) name it as </span></span><span style="color: red;"><span style="color: black;"><span style="color: blue;"><b>MemoryCache.java</b></span></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<blockquote class="tr_bq">
<span style="color: red;"><span style="color: black;">package com.example.loadimage;<br /><br />import java.lang.ref.SoftReference;<br />import java.util.Collections;<br />import java.util.HashMap;<br />import java.util.Map;<br /><br />import android.graphics.Bitmap;<br /><br />public class MemoryCache {<br />
private Map<String, SoftReference<Bitmap>>
cache=Collections.synchronizedMap(new HashMap<String,
SoftReference<Bitmap>>());<br /><br /> public Bitmap get(String id){<br /> if(!cache.containsKey(id))<br /> return null;<br /> SoftReference<Bitmap> ref=cache.get(id);<br /> return ref.get();<br /> }<br /><br /> public void put(String id, Bitmap bitmap){<br /> cache.put(id, new SoftReference<Bitmap>(bitmap));<br /> }<br /><br /> public void clear() {<br /> cache.clear();<br /> }<br />}</span></span></blockquote>
<span style="color: red;"><span style="color: black;"></span></span><br />
<br />
<span style="color: red;"><span style="color: black;">22) </span></span><span style="color: red;"><b><span style="color: black;"> </span></b><span style="color: black;">Create new class in the above package (</span></span><span style="color: red;"><span style="color: black;"><span style="color: red;"><b>com.example.loadimage</b></span>) name it as </span></span><span style="color: red;"><span style="color: black;"><span style="color: blue;"><b>Utils.java</b></span></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<br />
<blockquote class="tr_bq">
<span style="color: red;"><span style="color: black;">package com.example.loadimage;<br /><br />import java.io.InputStream;<br />import java.io.OutputStream;<br /><br />public class Utils {<br /> public static void CopyStream(InputStream is, OutputStream os)<br /> {<br /> final int buffer_size=1024;<br /> try<br /> {<br /> byte[] bytes=new byte[buffer_size];<br /> for(;;)<br /> {<br /> int count=is.read(bytes, 0, buffer_size);<br /> if(count==-1)<br /> break;<br /> os.write(bytes, 0, count);<br /> }<br /> }<br /> catch(Exception ex){}<br /> }<br />}</span></span></blockquote>
<span style="color: red;"><span style="color: black;"></span></span><br />
<br />
<span style="color: red;"><span style="color: black;">23) Open <span style="color: blue;"><b>AndroidManifest.xml</b></span> and type this code</span></span><br />
<br />
<blockquote class="tr_bq">
<blockquote class="tr_bq">
<span style="color: red;"><span style="color: black;"><?xml version="1.0" encoding="utf-8"?></span></span><br />
<span style="color: red;"><span style="color: black;"><manifest xmlns:android="http://schemas.android.com/apk/res/android"</span></span><br />
<span style="color: red;"><span style="color: black;"> package="com.example.youtube"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:versionCode="1"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:versionName="1.0" ></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-sdk</span></span><br />
<span style="color: red;"><span style="color: black;"> android:minSdkVersion="8"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:targetSdkVersion="17" /></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.INTERNET" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.ACCOUNT_MANAGER" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.GET_ACCOUNTS" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.USE_CREDENTIALS" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.READ_CONTACTS" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.READ_PROFILE" /></span></span><br />
<span style="color: red;"><span style="color: black;"> <uses-permission android:name="android.permission.READ_PHONE_STATE" /></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<span style="color: red;"><span style="color: black;"> <application</span></span><br />
<span style="color: red;"><span style="color: black;"> android:allowBackup="true"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:icon="@drawable/ic_launcher"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:label="@string/app_name"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:theme="@style/AppTheme" ></span></span><br />
<span style="color: red;"><span style="color: black;"> <activity</span></span><br />
<span style="color: red;"><span style="color: black;"> android:name="com.example.youtube.MainActivity"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:label="@string/app_name"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:launchMode="singleInstance" ></span></span><br />
<span style="color: red;"><span style="color: black;"> <intent-filter></span></span><br />
<span style="color: red;"><span style="color: black;"> <action android:name="android.intent.action.MAIN" /></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<span style="color: red;"><span style="color: black;"> <category android:name="android.intent.category.LAUNCHER" /></span></span><br />
<span style="color: red;"><span style="color: black;"> </intent-filter></span></span><br />
<span style="color: red;"><span style="color: black;"> </activity></span></span><br />
<span style="color: red;"><span style="color: black;"> <activity</span></span><br />
<span style="color: red;"><span style="color: black;"> android:name="com.example.youtube.FullscreenDemoActivity"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:configChanges="keyboardHidden|orientation|screenSize"</span></span><br />
<span style="color: red;"><span style="color: black;"> android:screenOrientation="sensor" ></span></span><br />
<span style="color: red;"><span style="color: black;"> </activity></span></span><br />
<span style="color: red;"><span style="color: black;"> </application></span></span><br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<span style="color: red;"><span style="color: black;"></manifest></span></span></blockquote>
</blockquote>
<br />
<span style="color: red;"><span style="color: black;">24) </span></span><span style="color: red;"><span style="color: black;"><span style="color: red;"><span style="color: black;">Your done now compile your project and run it.</span></span> </span></span><br />
<br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<br />
<span style="color: red;"><span style="color: black;"></span></span><br />
<div style="text-align: right;">
<span style="color: red;"><span style="color: black;">source: http://androidapphive.blogspot.com/2014/01/how-to-download-playlist-from-youtube.html?showComment=1417574476322#c3839339079216541634</span></span></div>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-14448538510701471832014-11-26T13:56:00.004+07:002014-11-26T13:56:30.862+07:00Installing Google Play Services on GenymotionGenymotion no longer includes Google Apps in virtual device image.
So the new Genymotion 2.0 no longer comes with Google API’s. But you
can install them manually to your virtual devices.<br /> Download <a href="http://wiki.rootzwiki.com/Google_Apps#Universal_Packages_2" title="Google Play Services">Google Apps</a> zip file.<br /> I have Nexus One – 4.3 – API 18 480×800 virtual device. I used the latest Universal package (20130813).<br /> 1. Start the virtual device and once it is up and running drag and drop the downloaded zip file onto the device.<br />
<img alt="Genymotion Emulator" class="lazy alignnone size-medium wp-image-612" data-original="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-1-195x300.png" height="300" src="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-1-195x300.png" style="display: inline;" width="195" /><br /> 2. After file transfer complete, Next you will get a file flashable dialog click ok.<br />
<img alt="Genymotion Emulator" class="lazy alignnone size-medium wp-image-613" data-original="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-2-193x300.png" height="300" src="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-2-193x300.png" style="display: inline;" width="193" /><br />
3. You will continue to see the File Transfer dialog let it run. You
may get errors that pop up just ignore them for now. When you get a file
flashed successful dialog, click ok.<br />
<img alt="Genymotion Emulator" class="lazy alignnone size-medium wp-image-614" data-original="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-3-194x300.png" height="300" src="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-3-194x300.png" style="display: inline;" width="194" /><br /> 4. Errors may be something related to a Google App like Search or Play. Click Ok.<br /> 5. Restart the virtual device. You may still be getting error dialogs like the one below. just click ok and carry on.<br />
<img alt="Genymotion Emulator" class="lazy alignnone size-medium wp-image-615" data-original="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-4-192x300.png" height="300" src="http://www.tushroy.com/wp-content/uploads/2013/12/g-apps-4-192x300.png" style="display: inline;" width="192" /><br />
After that update the Google apps from google play. Now you are able to
use the google play services in you emulator and test google apis.<br />
Now you can get some errors like force close apps when starting the
emulator. To get around this, install ARM Translations for Genymotion
VM. <a href="http://www.tushroy.com/2014/01/android-ndk-development-genymotion-emulator.html" title="Android NDK Development with Genymotion Emulator">Check this post for that</a>.<br />
<h4>
Incoming search terms:</h4>
<ul>
<li>genymotion google play</li>
<li>genymotion instagram</li>
<li>instagram Genymotion</li>
<li>genymotion google play services</li>
<li>genymotion driver</li>
<li>genymotion with google apps</li>
<li>genymotion license</li>
</ul>
<h3 class="sd-title">
<br /></h3>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-89152188992696360822014-11-26T13:16:00.004+07:002014-11-26T13:16:57.966+07:00[GUIDE] Genymotion | Installing ARM Translation and GApps Genymotion
is a Virtual Android Environment built on x86 and Virtualbox. It's not
an ARM emulator so it's performance is way better than the Android SDK
Emulator. However in their latest update they've removed both ARM
Translation and Google Play Apps. (This is what causes the
"INSTALL_FAILED_CPU_ABI_INCOMPATIBLE" errors) Many Devs and Users still
find these features very useful for various reasons and their removal
has forced people to look for alternatives to Genymotion.<br />
<br />
This guide is for getting back both ARM Translation and Google Play apps in your Genymotion VM.<br />
<br />
<span style="font-size: medium;"><b>ATTENTION(April 11th):</b> Sadly Dropbox has informed
me I've surpassed reasonable Bandwidth Usage and has temporarily
disabled my Public Links. I don't blame them considering I've reached a
steady 1400+ downloads per day, which equals an impressive 12.5+GB of
bandwidth per day. Part of this is probably because people started Hot
Linking my file for their guides. So for the foreseeable future I can't
provide direct downloads of the ARM Translation, but I'll have plenty of
Mirrors. I'm sorry to the numerous people that created Guides in
numerous languages, since I have to kill the link in your Guides. Please
don't hesitate to use one of my new links.<br />
<br />
<b>PS:</b> I'm sorry if I haven't been very talkative and helpful
lately. Work has been piling up and sleep is decreasing. Plus my
computer is being "<i>difficult</i>". Haven't had a chance to even update Genymotion to v2.2.0. I hope I'll be able to get back into the dirt soon.</span><br />
<br />
<b>Note(Feb 2nd):</b> Contrary to previous reports, it's been discovered
that Android 4.4 does in fact work with ARM Translation, although it is
buggy. Follow the steps the same as before, just make sure you download
the 4.4 GApps.<br />
<br />
<b>UPDATE-v1.1:</b> I've gotten more up-to-date builds of libhoudini and
have updated the ZIP. This fixes a lot of app crashes and hangs. Just
flash the new one and it should work.<br />
<br />
<ol style="list-style-type: decimal;">
<li>Download the following ZIPs:<ul>
<li><a href="http://goo.gl/tfjjMt" rel="nofollow" target="_blank"><u><b>ARM Translation Installer v1.1 <i><span style="font-size: xx-small;">Hosted by FILETRIP</span></i></b></u></a>(<a href="http://goo.gl/ZLKeKj" rel="nofollow" target="_blank">Mirrors</a>) - <i><b>If you have issues flashing ARM Trnaslation, Try re-downloading from a mirror</b></i></li>
<li>Download the correct GApps for your Android version:<br />
<i><b>If you have issues flashing GApps, Try re-downloading from a mirror</b></i><ul>
<li><a href="http://goo.gl/TVcd93" rel="nofollow" target="_blank">Google Apps for Android 4.4</a>(<a href="http://goo.gl/3EGMm4" rel="nofollow" target="_blank">Mirror</a>)(<a href="http://wiki.cyanogenmod.org/w/Google_Apps#gappsCM11" rel="nofollow" target="_blank">Download from CM11 Links</a>)<i>(4.4 GApps might be buggy)</i></li>
<li><a href="http://goo.im/gapps/gapps-jb-20130813-signed.zip" rel="nofollow" target="_blank">Google Apps for Android 4.3</a>(<a href="http://goo.gl/cC8xHR" rel="nofollow" target="_blank">Mirrors</a>)</li>
<li><a href="http://goo.im/gapps/gapps-jb-20130812-signed.zip" rel="nofollow" target="_blank">Google Apps for Android 4.2</a></li>
<li><a href="http://goo.im/gapps/gapps-jb-20121011-signed.zip" rel="nofollow" target="_blank">Google Apps for Android 4.1</a></li>
</ul>
</li>
</ul>
</li>
<li>Next Open your Genymotion VM and go to the Homescreen</li>
<li>Now Drag&Drop the <b>Genymotion-ARM-Translation.zip</b> onto the Genymotion VM window.</li>
<li>It should say "File transfer in progress", once it asks you to flash it click 'OK'</li>
<li>Now Reboot your VM using ADB or an app like ROM Toolbox. If
nescessary you can simply close the VM window, but I don't recommend it.</li>
<li>Once you're on the Homescreen again Drag&Drop the <b>gapps-jb-20130813-signed.zip</b>(or whatever version you got) onto your VM, and click 'OK' when asked</li>
<li>Once it finishes, again Reboot your VM and open the Google Play Store.</li>
<li>Sign in using your Google account</li>
<li>Once in the Store go to the 'My Apps' menu and let everything update(fixes a lot of issues), also try updating <a href="https://play.google.com/store/apps/details?id=com.google.android.gms" rel="nofollow" target="_blank">Google Play Services</a> directly.</li>
<li>Now try searching for 'Netflix' and 'Google Drive'</li>
<li>If both apps show up in the results and you're able to
Download/Install them, then congrats you now have ARM support and Google
Play fully setup!</li>
</ol>
I've tested this on Genymotion v2.0.1 Using Android 4.3 images.
Feel free to skip the GApps steps if you only want the ARM support.
It'll work perfectly fine by itself.<br />
<br />
If you have any problems please don't hesitate to ask for help below.<br />
<br />
<b>Thanks:</b><br />
<u>Michael Z.</u> - Provided newer system image<br />
<a href="http://forum.xda-developers.com/member.php?u=3065791" target="_blank">taob</a> - Provided Reference Image<br />
<br />
<strike>-----------------------------------------------------------------------</strike><br />
<u>Old Zips:</u>(DON'T DOWNLOAD! Kept for archival purposes, unlikely to solve any issues you might have.)<br />
ARM Translation v1.0 - <a href="http://goo.gl/cPJ84O" rel="nofollow" target="_blank">http://goo.gl/CL4os6 <i><span style="font-size: xx-small;">Hosted by FILETRIP</span></i></a>(<a href="http://goo.gl/5Hc2Cn" rel="nofollow" target="_blank">Mirrors</a>)
<fieldset class="fieldset">
<legend>Attached Files</legend>
<table border="0" cellpadding="0" cellspacing="3">
<tbody>
<tr>
<td><img alt="File Type: zip" border="0" class="inlineimg" height="16" src="http://cdn1.xda-developers.com/images/2015/attach/zip.gif" style="vertical-align: baseline;" title="File Type: zip" width="16" /></td>
<td><a href="http://forum.xda-developers.com/attachment.php?attachmentid=2680937&d=1397258016">Genymotion-ARM-Translation_v1.1.zip</a> -</td></tr>
</tbody></table>
</fieldset>
<br />
Source:http://forum.xda-developers.com/showthread.php?t=25289522http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0tag:blogger.com,1999:blog-8510999914211617643.post-41846027612576556002014-11-20T13:53:00.001+07:002014-11-20T13:53:23.508+07:00How to finish an activity from other activity in android<strong>FIRST WAY</strong><br />
In your first activity, declare one <code>Activity object</code> like this,<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="typ">Activity</span><span class="pln"> fa</span><span class="pun">;</span><span class="pln">
onCreate</span><span class="pun">()</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
fa </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">this</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span></code></pre>
</blockquote>
now use that object in another <code>Activity</code> to finish first-activity like this,<br />
<blockquote class="tr_bq">
<pre class="default prettyprint prettyprinted"><code><span class="pln">onCreate</span><span class="pun">()</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
</span><span class="typ">FirstActivity</span><span class="pun">.</span><span class="pln">fa</span><span class="pun">.</span><span class="pln">finish</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span></code></pre>
</blockquote>
<strong>SECOND WAY</strong><br />
From View<br />
Write below code after startactivity(intent) for finish the activity from the view/class.<br />
<blockquote class="tr_bq">
((Activity_Name1) context).finish();<br />
</blockquote>
<br />
<h3 style="background-color: white; box-sizing: border-box; color: #333333; font-family: Bitter, arial, sans-serif; font-size: 18px; font-weight: normal; line-height: 18px; margin: 0px; position: relative; text-align: right;">
<b><a href="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="-webkit-transition: all 0.4s ease-in-out; box-sizing: border-box; color: #999999; font-family: Verdana, Geneva, sans-serif; font-size: 11px; line-height: 17.59375px; margin-left: 1em; margin-right: 1em; max-width: 100%; text-align: center; text-decoration: none; transition: all 0.4s ease-in-out;"><img border="0" src="http://3.bp.blogspot.com/-Mx5jXXC8eaw/UjpS4_QpGGI/AAAAAAAAAbI/wM6EYAA5D3c/s1600/download.jpg" style="border: 1px solid rgb(213, 211, 211); box-sizing: border-box; height: auto; max-width: 100%; padding: 3px;" /></a></b></h3>
2http://www.blogger.com/profile/15120991490252928328noreply@blogger.com0