mirror of
https://github.com/jlengrand/jlengrand.github.io.git
synced 2026-03-10 08:31:22 +00:00
Removes some of the strange html characters
This commit is contained in:
@@ -82,8 +82,8 @@ To run on startup, this module had to be added to the list of apps to be started
|
||||
On my Openbox based Crunchbang, the solution was to edit my autostart.sh to add a new line :
|
||||
|
||||
[bash]
|
||||
$ echo "(sleep 5s && numlock) &" \
|
||||
>> ~/.config/openbox/autostart.sh
|
||||
$ echo "(sleep 5s && numlock) &" \
|
||||
>> ~/.config/openbox/autostart.sh
|
||||
[/bash]
|
||||
|
||||
<div>That's all !</div>
|
||||
|
||||
@@ -29,7 +29,7 @@ Here is an example :
|
||||
|
||||
import cv
|
||||
|
||||
img = cv.LoadImage("test.jpg")
|
||||
img = cv.LoadImage("test.jpg")
|
||||
dims = cv.GetSize(img)
|
||||
roi = [0, 0, dims[0] / 2, dims[1] / 2 ]
|
||||
cv.SetImageROI(img, roi)
|
||||
@@ -39,7 +39,7 @@ You will get this result:
|
||||
|
||||
[python]
|
||||
Traceback (most recent call last):
|
||||
File "newfile.py", line 8, in <module>
|
||||
File "newfile.py", line 8, in <module>
|
||||
cv.SetImageROI(img, roi)
|
||||
TypeError: CvRect argument 'rect' expects four integers
|
||||
[/python]
|
||||
|
||||
@@ -208,38 +208,38 @@ import cv
|
||||
import numpy
|
||||
|
||||
def simple_region_growing(img, seed, threshold=1):
|
||||
"""
|
||||
"""
|
||||
A (very) simple implementation of region growing.
|
||||
Extracts a region of the input image depending on a start position and a stop condition.
|
||||
The input should be a single channel 8 bits image and the seed a pixel position (x, y).
|
||||
The threshold corresponds to the difference between outside pixel intensity and mean intensity of region.
|
||||
In case no new pixel is found, the growing stops.
|
||||
Outputs a single channel 8 bits binary (0 or 255) image. Extracted region is highlighted in white.
|
||||
"""
|
||||
"""
|
||||
|
||||
try:
|
||||
dims = cv.GetSize(img)
|
||||
except TypeError:
|
||||
raise TypeError("(%s) img : IplImage expected!" % (sys._getframe().f_code.co_name))
|
||||
raise TypeError("(%s) img : IplImage expected!" % (sys._getframe().f_code.co_name))
|
||||
|
||||
# img test
|
||||
if not(img.depth == cv.IPL_DEPTH_8U):
|
||||
raise TypeError("(%s) 8U image expected!" % (sys._getframe().f_code.co_name))
|
||||
raise TypeError("(%s) 8U image expected!" % (sys._getframe().f_code.co_name))
|
||||
elif not(img.nChannels is 1):
|
||||
raise TypeError("(%s) 1C image expected!" % (sys._getframe().f_code.co_name))
|
||||
raise TypeError("(%s) 1C image expected!" % (sys._getframe().f_code.co_name))
|
||||
# threshold tests
|
||||
if (not isinstance(threshold, int)) :
|
||||
raise TypeError("(%s) Int expected!" % (sys._getframe().f_code.co_name))
|
||||
elif threshold < 0:
|
||||
raise ValueError("(%s) Positive value expected!" % (sys._getframe().f_code.co_name))
|
||||
raise TypeError("(%s) Int expected!" % (sys._getframe().f_code.co_name))
|
||||
elif threshold < 0:
|
||||
raise ValueError("(%s) Positive value expected!" % (sys._getframe().f_code.co_name))
|
||||
# seed tests
|
||||
if not((isinstance(seed, tuple)) and (len(seed) is 2) ) :
|
||||
raise TypeError("(%s) (x, y) variable expected!" % (sys._getframe().f_code.co_name))
|
||||
raise TypeError("(%s) (x, y) variable expected!" % (sys._getframe().f_code.co_name))
|
||||
|
||||
if (seed[0] or seed[1] ) < 0 :
|
||||
raise ValueError("(%s) Seed should have positive values!" % (sys._getframe().f_code.co_name))
|
||||
elif ((seed[0] > dims[0]) or (seed[1] > dims[1])):
|
||||
raise ValueError("(%s) Seed values greater than img size!" % (sys._getframe().f_code.co_name))
|
||||
if (seed[0] or seed[1] ) < 0 :
|
||||
raise ValueError("(%s) Seed should have positive values!" % (sys._getframe().f_code.co_name))
|
||||
elif ((seed[0] > dims[0]) or (seed[1] > dims[1])):
|
||||
raise ValueError("(%s) Seed values greater than img size!" % (sys._getframe().f_code.co_name))
|
||||
|
||||
reg = cv.CreateImage( dims, cv.IPL_DEPTH_8U, 1)
|
||||
cv.Zero(reg)
|
||||
@@ -257,14 +257,14 @@ def simple_region_growing(img, seed, threshold=1):
|
||||
cur_pix = [seed[0], seed[1]]
|
||||
|
||||
#Spreading
|
||||
while(dist<threshold and size<pix_area):
|
||||
while(dist<threshold and size<pix_area):
|
||||
#adding pixels
|
||||
for j in range(4):
|
||||
#select new candidate
|
||||
temp_pix = [cur_pix[0] +orient[j][0], cur_pix[1] +orient[j][1]]
|
||||
|
||||
#check if it belongs to the image
|
||||
is_in_img = dims[0]>temp_pix[0]>0 and dims[1]>temp_pix[1]>0 #returns boolean
|
||||
is_in_img = dims[0]>temp_pix[0]>0 and dims[1]>temp_pix[1]>0 #returns boolean
|
||||
#candidate is taken if not already selected before
|
||||
if (is_in_img and (reg[temp_pix[1], temp_pix[0]]==0)):
|
||||
contour.append(temp_pix)
|
||||
@@ -303,18 +303,18 @@ import tippy.display_operations as do
|
||||
|
||||
user_input = 0
|
||||
|
||||
img_name = "tippy/data/gnu.jpg"
|
||||
img_name = "tippy/data/gnu.jpg"
|
||||
threshold = 20
|
||||
img = cv.LoadImage(img_name, cv.CV_LOAD_IMAGE_GRAYSCALE)
|
||||
|
||||
if user_input:
|
||||
seed = bo.mouse_point(img, mode="S") # waits for user click to get seed
|
||||
seed = bo.mouse_point(img, mode="S") # waits for user click to get seed
|
||||
else:
|
||||
seed = (70, 106)
|
||||
|
||||
out_img = se.simple_region_growing(img, seed, threshold)
|
||||
|
||||
do.display_single_image(out_img, "Region Growing result")
|
||||
do.display_single_image(out_img, "Region Growing result")
|
||||
[/python]
|
||||
|
||||
As you can see, the implementation is rather short in code.
|
||||
|
||||
@@ -56,13 +56,13 @@ Let's say I want to create a (dum) function calculating the square value of a
|
||||
</ul>
|
||||
[python]
|
||||
def square_value(a):
|
||||
"""
|
||||
"""
|
||||
Returns the square value of a.
|
||||
"""
|
||||
"""
|
||||
try:
|
||||
out = a*a
|
||||
except TypeError:
|
||||
raise TypeError("Input should be a string:")
|
||||
raise TypeError("Input should be a string:")
|
||||
|
||||
return out
|
||||
[/python]
|
||||
@@ -73,19 +73,19 @@ def square_value(a):
|
||||
import dum_function as df # import function module
|
||||
import unittest
|
||||
class Test(unittest.TestCase):
|
||||
"""
|
||||
"""
|
||||
The class inherits from unittest
|
||||
"""
|
||||
"""
|
||||
def setUp(self):
|
||||
"""
|
||||
"""
|
||||
This method is called before each test
|
||||
"""
|
||||
self.false_int = "A"
|
||||
"""
|
||||
self.false_int = "A"
|
||||
|
||||
def tearDown(self):
|
||||
"""
|
||||
"""
|
||||
This method is called after each test
|
||||
"""
|
||||
"""
|
||||
pass
|
||||
#---
|
||||
## TESTS
|
||||
@@ -93,7 +93,7 @@ class Test(unittest.TestCase):
|
||||
# assertRaises(excClass, callableObj) prototype
|
||||
self.assertRaises(TypeError, df.square_value(self.false_int))
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
[/python]
|
||||
<ul>
|
||||
@@ -104,10 +104,10 @@ if __name__ == "__main__":
|
||||
ERROR: test_square_value (__main__.Test)
|
||||
----------------------------------------------------------------------
|
||||
Traceback (most recent call last):
|
||||
File "test_dum_function.py", line 22, in test_square_value
|
||||
File "test_dum_function.py", line 22, in test_square_value
|
||||
self.assertRaises(TypeError, df.square_value(self.false_int))
|
||||
File "/home/jlengrand/Desktop/function.py", line 8, in square_value
|
||||
raise TypeError("Input should be a string:")
|
||||
File "/home/jlengrand/Desktop/function.py", line 8, in square_value
|
||||
raise TypeError("Input should be a string:")
|
||||
TypeError: Input should be a string:
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
@@ -64,8 +64,8 @@ To do this, you need two things :
|
||||
</ul>
|
||||
<div>[javascript]
|
||||
|
||||
<!-- Script créé par KevBrok ;-) -->
|
||||
<script type="text/javascript">// <![CDATA[
|
||||
<!-- Script créé par KevBrok ;-) -->
|
||||
<script type="text/javascript">// <![CDATA[
|
||||
/*
|
||||
* Montre / Cache un div
|
||||
*/
|
||||
@@ -132,7 +132,7 @@ To do this, you need two things :
|
||||
}
|
||||
}
|
||||
}
|
||||
// ]]></script>
|
||||
// ]]></script>
|
||||
[/javascript]
|
||||
|
||||
</div>
|
||||
@@ -140,14 +140,14 @@ To do this, you need two things :
|
||||
<li>Then, <strong>Write down your article in both languages</strong>, one after the other in you editor. Each language should be placed in a separate div; and a button placed to switch from one language to the other. Here is an example :</li>
|
||||
</ul>
|
||||
<div>[javascript]
|
||||
<a href="javascript:InverseTout( 'mondiv' )">Français / English</a></pre>
|
||||
<div id="mondiv1" class="cachediv">
|
||||
<div style="border: 1px solid black; background-color: whitesmoke; margin-bottom: 2px;">My article in english</div>
|
||||
</div>
|
||||
<div id="mondiv2">
|
||||
<div style="border: 1px solid black; background-color: whitesmoke; margin-bottom: 2px;">Mon article en français</div>
|
||||
</div>
|
||||
<pre>
|
||||
<a href="javascript:InverseTout( 'mondiv' )">Français / English</a></pre>
|
||||
<div id="mondiv1" class="cachediv">
|
||||
<div style="border: 1px solid black; background-color: whitesmoke; margin-bottom: 2px;">My article in english</div>
|
||||
</div>
|
||||
<div id="mondiv2">
|
||||
<div style="border: 1px solid black; background-color: whitesmoke; margin-bottom: 2px;">Mon article en français</div>
|
||||
</div>
|
||||
<pre>
|
||||
[/javascript]
|
||||
|
||||
</div>
|
||||
|
||||
@@ -43,7 +43,7 @@ As a bonus, the script automatically detects whether an image is in landscape or
|
||||
|
||||
Here is an example of the result :
|
||||
|
||||
[caption id="attachment_424" align="aligncenter" width="200" caption="picture of the "jardin des plantes" in Nantes"]<a href="http://www.lengrand.fr/wp-content/uploads/2011/12/pourquoi_le_bitume__by_jlengrand-d4dp4ha.jpg"><img class="size-medium wp-image-424" title="Pourquoi le bitume?" src="http://www.lengrand.fr/wp-content/uploads/2011/12/pourquoi_le_bitume__by_jlengrand-d4dp4ha-200x300.jpg" alt="picture of the "jardin des plantes" in Nantes" width="200" height="300" /></a>[/caption]
|
||||
[caption id="attachment_424" align="aligncenter" width="200" caption="picture of the "jardin des plantes" in Nantes"]<a href="http://www.lengrand.fr/wp-content/uploads/2011/12/pourquoi_le_bitume__by_jlengrand-d4dp4ha.jpg"><img class="size-medium wp-image-424" title="Pourquoi le bitume?" src="http://www.lengrand.fr/wp-content/uploads/2011/12/pourquoi_le_bitume__by_jlengrand-d4dp4ha-200x300.jpg" alt="picture of the "jardin des plantes" in Nantes" width="200" height="300" /></a>[/caption]
|
||||
|
||||
This script is in an early stage for now, and should be upgraded with time. You can check out the <strong><a title="TODO list" href="https://github.com/jlengrand/batchWaterMarking">TODO list here. </a></strong>
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ The command to search for is<strong> start-stop-daemon</strong>, with start opti
|
||||
To avoid any output in stdout, use redirection:
|
||||
|
||||
[bash]
|
||||
$ command &> /dev/null&
|
||||
$ command &> /dev/null&
|
||||
[/bash]
|
||||
|
||||
<hr />
|
||||
@@ -166,7 +166,7 @@ Simply add the line
|
||||
|
||||
[bash]
|
||||
|
||||
trap " 2 3
|
||||
trap " 2 3
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -188,7 +188,7 @@ The operations can be performed with bc :
|
||||
|
||||
[bash]
|
||||
|
||||
$ VAR=$(echo "2.2/ 10.65" | bc -l)
|
||||
$ VAR=$(echo "2.2/ 10.65" | bc -l)
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -206,7 +206,7 @@ $ (ceil) INT=${VAR/.*}
|
||||
|
||||
[bash]
|
||||
|
||||
$ "find ./ -name .svn -prune -o -type f -print | xargs grep -Hi" //pattern//
|
||||
$ "find ./ -name .svn -prune -o -type f -print | xargs grep -Hi" //pattern//
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -239,7 +239,7 @@ Simply add a new line at the end of the file :
|
||||
|
||||
[bash]
|
||||
|
||||
alias_name = "my_one_line_command"
|
||||
alias_name = "my_one_line_command"
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -251,7 +251,7 @@ Restart your terminal, you're done!
|
||||
|
||||
[bash]
|
||||
|
||||
$ date -d "$FIRST_TIME" +"%s"
|
||||
$ date -d "$FIRST_TIME" +"%s"
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -261,7 +261,7 @@ $ date -d "$FIRST_TIME" +"%s"
|
||||
|
||||
[bash]
|
||||
|
||||
$ which //language// > my_script
|
||||
$ which //language// > my_script
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -269,7 +269,7 @@ $ which //language// > my_script
|
||||
|
||||
[bash]
|
||||
|
||||
$ which bash > my_script.sh
|
||||
$ which bash > my_script.sh
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -291,7 +291,7 @@ $ file -i //unkown_file_type//
|
||||
|
||||
$ cd //my_folder///
|
||||
|
||||
$ find -name ".svn" -exec rm -rf {} \;
|
||||
$ find -name ".svn" -exec rm -rf {} \;
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -407,7 +407,7 @@ in your <strong>.bashrc. </strong>It can be done simply in running the followin
|
||||
|
||||
[bash]
|
||||
|
||||
$ echo "complete -cf sudo" > ~/.bashrc
|
||||
$ echo "complete -cf sudo" > ~/.bashrc
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -533,7 +533,7 @@ file.open(file_name, 'a')
|
||||
try:
|
||||
print variable
|
||||
except NameError:
|
||||
print "Error!"
|
||||
print "Error!"
|
||||
[/python]
|
||||
|
||||
<hr />
|
||||
@@ -563,9 +563,9 @@ a = b = c = 1+1
|
||||
import sys
|
||||
|
||||
def tutut():
|
||||
"""
|
||||
"""
|
||||
Dum function displaying its name!
|
||||
"""
|
||||
"""
|
||||
print sys._getframe().f_code.co_name
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -613,13 +613,13 @@ with
|
||||
|
||||
<span style="text-decoration: underline;">About variables</span> :
|
||||
<ul>
|
||||
<li>age -> value</li>
|
||||
<li>&age -> pointer</li>
|
||||
<li>age -> value</li>
|
||||
<li>&age -> pointer</li>
|
||||
</ul>
|
||||
<span style="text-decoration: underline;">About pointers</span> :
|
||||
<ul>
|
||||
<li>ptr -> ptr value(which is an address)</li>
|
||||
<li>*ptr -> variable value placed in the address.</li>
|
||||
<li>ptr -> ptr value(which is an address)</li>
|
||||
<li>*ptr -> variable value placed in the address.</li>
|
||||
</ul>
|
||||
<span style="text-decoration: underline;"> If <strong><em>age</em></strong> is a variable</span> :
|
||||
<ul>
|
||||
@@ -645,7 +645,7 @@ int age = 10;
|
||||
|
||||
<span style="color: #ff9900;">Those two are equivalent (used for structures):</span>
|
||||
<ul>
|
||||
<li>a->b</li>
|
||||
<li>a->b</li>
|
||||
<li>*(a.b)</li>
|
||||
</ul>
|
||||
|
||||
@@ -796,7 +796,7 @@ Memos and Tips about the <strong><a title="External link to http://opencv.willow
|
||||
Can be used to naviguate through pixels easily (and more efficiently than some openCV functions).
|
||||
|
||||
[c]
|
||||
char *pImage = iplImage->ImageData
|
||||
char *pImage = iplImage->ImageData
|
||||
[/c]
|
||||
|
||||
<hr />
|
||||
@@ -876,7 +876,7 @@ It should solve the problem.
|
||||
</ul>
|
||||
[bash]
|
||||
|
||||
$ svn cp trunk -> new_branch
|
||||
$ svn cp trunk -> new_branch
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -958,7 +958,7 @@ $ sudo apt-get install gprof
|
||||
</ul>
|
||||
[bash]
|
||||
|
||||
$ gprof your_binary gmon.out >> saved_report
|
||||
$ gprof your_binary gmon.out >> saved_report
|
||||
|
||||
$ vim saved_report
|
||||
|
||||
@@ -988,7 +988,7 @@ Some very simple tips and hints for wordpress.
|
||||
|
||||
<span style="color: #ff9900;">Insert an horizontal line in a post :</span>
|
||||
|
||||
Simply insert the <strong><hr/> tag</strong> while in <strong>html</strong> edition mode .
|
||||
Simply insert the <strong><hr/> tag</strong> while in <strong>html</strong> edition mode .
|
||||
|
||||
<hr />
|
||||
|
||||
@@ -998,7 +998,7 @@ This is done in two different steps :
|
||||
<ul>
|
||||
<li><strong>Define the anchor</strong>. You should place the following code where you want the user to be redirected.</li>
|
||||
</ul>
|
||||
[html]your article <a name= "name_of_the_anchor"></a> here.[/html]
|
||||
[html]your article <a name= "name_of_the_anchor"></a> here.[/html]
|
||||
|
||||
|
||||
<ul>
|
||||
@@ -1006,11 +1006,11 @@ This is done in two different steps :
|
||||
</ul>
|
||||
|
||||
<div><span style="text-decoration: underline;">If the anchor is placed in the same page :</span></div>
|
||||
[html]<a href= »#name_of_the_anchor »>my highlighted text</a>[/html]
|
||||
[html]<a href= »#name_of_the_anchor »>my highlighted text</a>[/html]
|
||||
|
||||
<div><span style="text-decoration: underline;">If the anchor is in another page :</span></div>
|
||||
[html]<a href= »http://www.website.fr/#name_of_the_anchor »>my highlighted text</a>
|
||||
<a href= »#name_of_the_anchor »>my highlighted text</a>
|
||||
[html]<a href= »http://www.website.fr/#name_of_the_anchor »>my highlighted text</a>
|
||||
<a href= »#name_of_the_anchor »>my highlighted text</a>
|
||||
[/html]
|
||||
|
||||
<strong>You can see the result everywhere on this page, in the topic listing :).</strong>
|
||||
|
||||
@@ -30,9 +30,9 @@ Here is how to <strong>print your function name as a string</strong> in Python :
|
||||
import sys
|
||||
|
||||
def tutut():
|
||||
"""
|
||||
"""
|
||||
Dum function displaying its name!
|
||||
"""
|
||||
"""
|
||||
print sys._getframe().f_code.co_name
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -35,7 +35,7 @@ Problem solved in 3 simple lines of code :
|
||||
|
||||
[php]
|
||||
|
||||
post_func = loadstring("param = printf(\"Hello ! \")")
|
||||
post_func = loadstring("param = printf(\"Hello ! \")")
|
||||
post_func()
|
||||
appli_repo = os.execute(param)
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ If you want to avoid using a command line, or you don't have the profile module
|
||||
|
||||
[python]
|
||||
import timeit
|
||||
t1 = timeit.Timer("function()", "from __main__ import function")
|
||||
t1 = timeit.Timer("function()", "from __main__ import function")
|
||||
print t1.timeit(1)
|
||||
[/python]
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Simply open a console and run this line
|
||||
|
||||
[bash]
|
||||
|
||||
sed -e $"s/,/\ /g" myfile > newfile
|
||||
sed -e $"s/,/\ /g" myfile > newfile
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -38,7 +38,7 @@ or more generally,
|
||||
|
||||
[bash]
|
||||
|
||||
sed -e $"s/old_separator/new_separator/g" myfile > newfile
|
||||
sed -e $"s/old_separator/new_separator/g" myfile > newfile
|
||||
|
||||
[/bash]
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ I found this simple command that will pop out the number of lines of code for a
|
||||
|
||||
[bash]
|
||||
|
||||
cat `find . -name "*.py"` | wc -l
|
||||
cat `find . -name "*.py"` | wc -l
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -34,6 +34,6 @@ You can also do it for a whole folder
|
||||
|
||||
[bash]
|
||||
|
||||
find . -name "*.py" | xargs wc -l
|
||||
find . -name "*.py" | xargs wc -l
|
||||
|
||||
[/bash]
|
||||
|
||||
@@ -33,7 +33,7 @@ So here is the magic solution to get rid of those parasites :
|
||||
|
||||
[bash]
|
||||
|
||||
$ sudo find any_folder -name "Thumbs.db" -exec rm {} \;
|
||||
$ sudo find any_folder -name "Thumbs.db" -exec rm {} \;
|
||||
|
||||
[/bash]
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ import os
|
||||
import sys
|
||||
|
||||
def scan_rep(repertoir, extension):
|
||||
"""scanne le rep courant pour trouver des tex"""
|
||||
"""scanne le rep courant pour trouver des tex"""
|
||||
for racine, reps, fichiers in os.walk(repertoir, topdown=True):
|
||||
for fichier in fichiers:
|
||||
if fichier.endswith('.%s' % extension):
|
||||
|
||||
@@ -53,14 +53,14 @@ Here is what my Activity would look like :
|
||||
[java]
|
||||
|
||||
public class DisplayGPSInfoActivity extends BaseActivity implements LocationListener {
|
||||
private static final String TAG = "DisplayGPSInfoActivity";
|
||||
private static final String TAG = "DisplayGPSInfoActivity";
|
||||
|
||||
private ViewFlipper vf;
|
||||
|
||||
private LocationManager locationManager;
|
||||
private String provider;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -82,10 +82,10 @@ Location location = locationManager.getLastKnownLocation(provider);
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.d(TAG, "GPS LocationChanged");
|
||||
Log.d(TAG, "GPS LocationChanged");
|
||||
double lat = location.getLatitude();
|
||||
double lng = location.getLongitude();
|
||||
Log.d(TAG, "Received GPS request for " + String.valueOf(lat) + "," + String.valueOf(lng) + " , ready to rumble!");
|
||||
Log.d(TAG, "Received GPS request for " + String.valueOf(lat) + "," + String.valueOf(lng) + " , ready to rumble!");
|
||||
|
||||
// Do clever stuff here
|
||||
}
|
||||
@@ -102,8 +102,8 @@ Problem is, it is not. never. Ever. . .
|
||||
After having verified hundred times that I had
|
||||
|
||||
[xml]
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
[/xml]
|
||||
|
||||
@@ -117,7 +117,7 @@ Something like that would do the job :
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Log.v(TAG, "Resuming");
|
||||
Log.v(TAG, "Resuming");
|
||||
locationManager.requestLocationUpdates(provider, 400, 1, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,11 @@ I started by creating a dedicated filter on the twitter account of BresTram.
|
||||
|
||||
This gives me two lines of code to integrate into the website of my choice :
|
||||
|
||||
[html]
|
||||
<a class="twitter-timeline" href="https://twitter.com/search?q=%23BresTram" data-widget-id="394415351972114432">Tweets about "#BresTram"</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
||||
[/html]
|
||||
{% highlight html %}
|
||||
|
||||
<a class="twitter-timeline" href="https://twitter.com/search?q=%23BresTram" data-widget-id="394415351972114432">Tweets about "#BresTram"</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
||||
{% endhighlight %}
|
||||
|
||||
Then, I simply created a new Activity in my Application, that contains a webview.
|
||||
|
||||
@@ -51,12 +52,12 @@ import android.os.Bundle;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class TimeLineActivity extends BaseActivity {
|
||||
public static final String TAG = "TimeLineActivity";
|
||||
public static final String TAG = "TimeLineActivity";
|
||||
|
||||
private static final String baseURl = "https://twitter.com";
|
||||
private static final String baseURl = "https://twitter.com";
|
||||
|
||||
private static final String widgetInfo = "<a class=\"twitter-timeline\" href=\"https://twitter.com/search?q=%23BresTram\" data-widget-id=\"394415351972114432\">Tweets about \"#BresTram\"</a> " +
|
||||
"<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\"://platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>";
|
||||
private static final String widgetInfo = "<a class=\"twitter-timeline\" href=\"https://twitter.com/search?q=%23BresTram\" data-widget-id=\"394415351972114432\">Tweets about \"#BresTram\"</a> " +
|
||||
"<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\"://platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -69,7 +70,7 @@ public class TimeLineActivity extends BaseActivity {
|
||||
webView.getSettings().setDomStorageEnabled(true);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
|
||||
webView.loadDataWithBaseURL(baseURl, widgetInfo, "text/html", "UTF-8", null);
|
||||
webView.loadDataWithBaseURL(baseURl, widgetInfo, "text/html", "UTF-8", null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,22 +92,22 @@ The background color method is needed to avoid the ugly white background behind
|
||||
And here is the layout file :
|
||||
|
||||
[xml]
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".TimeLineActivity" >
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".TimeLineActivity" >
|
||||
|
||||
<WebView
|
||||
android:id="@+id/timeline_webview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
<WebView
|
||||
android:id="@+id/timeline_webview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
[/xml]
|
||||
|
||||
I used fill_parent because I wanted to give as much space as possible to the Webview.
|
||||
|
||||
@@ -32,73 +32,73 @@ I decided to go for XML, for all the reasons above, and also because android sup
|
||||
|
||||
Here is how my update file would look like :
|
||||
|
||||
[xml]
|
||||
{% highlight xml %}
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- This file contains all the update messages displayed to the user-->
|
||||
<!-- To create a new update message:
|
||||
<?xml version="1.0" encoding="utf-8">
|
||||
<resources>
|
||||
<!-- This file contains all the update messages displayed to the user-->
|
||||
<!-- To create a new update message:
|
||||
- Create a new update array, with a incremented update number
|
||||
- Add a reference to this new array in the updates array
|
||||
-->
|
||||
-->
|
||||
|
||||
<!-- Template is : -->
|
||||
<!-- Template is : -->
|
||||
|
||||
<!--
|
||||
<array name="update0">
|
||||
<item>update title</item>
|
||||
<item>update message</item>
|
||||
</array>
|
||||
-->
|
||||
<!--
|
||||
<array name="update0">
|
||||
<item>update title</item>
|
||||
<item>update message</item>
|
||||
</array>
|
||||
-->
|
||||
|
||||
<string-array name="update0">
|
||||
<item>
|
||||
"Mise à jour du site Bibus"
|
||||
</item>
|
||||
<item>
|
||||
"Bibus a récemment changé son protocole de communication pour les horaires temps réel.\n
|
||||
<string-array name="update0">
|
||||
<item>
|
||||
"Mise à jour du site Bibus"
|
||||
</item>
|
||||
<item>
|
||||
"Bibus a récemment changé son protocole de communication pour les horaires temps réel.\n
|
||||
Il est donc en ce moment impossible pour BresTram de fonctionner correctement.\n
|
||||
(Merci Lucas de m'avoir prévenu!)\n
|
||||
Ceci est totalement indépendant de BresTram, et je fais mon possible pour corriger ceci au plus vite!\n
|
||||
En attendant, si vous trouvez l'application utile, aidez-moi en votant sur le play store!\n
|
||||
Merci d'avance, et désolé pour le dérangement."
|
||||
</item>
|
||||
</string-array>
|
||||
Merci d'avance, et désolé pour le dérangement."
|
||||
</item>
|
||||
</string-array>
|
||||
. . .
|
||||
|
||||
<array name="update12">
|
||||
<!-- French -->
|
||||
<item>
|
||||
"Mise à jour du 27 Janvier"
|
||||
</item>
|
||||
<item>
|
||||
"BresTram vient d'être mis à jour.\n\n"
|
||||
"Un nouvel onglet a été ajouté pour vous permettre de faire des recherches par ligne de bus.\n"
|
||||
"Il vous est maintenant possible de voir la liste de toutes les lignes possibles dans l'onglet lignes.\n\n"
|
||||
"Cette nouvelle fonctionnalité est pour le moment encore en beta, il est donc possible que vous rencontriez des bugs."
|
||||
"Faites moi part de vos remarques sur le play store où sur le Twitter de l'application!"
|
||||
</item>
|
||||
<!-- English -->
|
||||
<item>
|
||||
"BresTram was updated to version 1.5"
|
||||
</item>
|
||||
<item>
|
||||
"BresTram has been updated to the latest version.\n\n"
|
||||
"A new tab has been added, that lists all bus lines and their associated bus stops.\n"
|
||||
"This functionality is currently still in beta, and you might find bugs.\n\n"
|
||||
"Let me know your suggestions on the playstore or the twitter of the application!"
|
||||
</item>
|
||||
</array>
|
||||
<array name="update12">
|
||||
<!-- French -->
|
||||
<item>
|
||||
"Mise à jour du 27 Janvier"
|
||||
</item>
|
||||
<item>
|
||||
"BresTram vient d'être mis à jour.\n\n"
|
||||
"Un nouvel onglet a été ajouté pour vous permettre de faire des recherches par ligne de bus.\n"
|
||||
"Il vous est maintenant possible de voir la liste de toutes les lignes possibles dans l'onglet lignes.\n\n"
|
||||
"Cette nouvelle fonctionnalité est pour le moment encore en beta, il est donc possible que vous rencontriez des bugs."
|
||||
"Faites moi part de vos remarques sur le play store où sur le Twitter de l'application!"
|
||||
</item>
|
||||
<!-- English -->
|
||||
<item>
|
||||
"BresTram was updated to version 1.5"
|
||||
</item>
|
||||
<item>
|
||||
"BresTram has been updated to the latest version.\n\n"
|
||||
"A new tab has been added, that lists all bus lines and their associated bus stops.\n"
|
||||
"This functionality is currently still in beta, and you might find bugs.\n\n"
|
||||
"Let me know your suggestions on the playstore or the twitter of the application!"
|
||||
</item>
|
||||
</array>
|
||||
|
||||
<!-- Array containing a reference to all the messages -->
|
||||
<array name="updates">
|
||||
<item>@array/update0</item>
|
||||
<!-- Array containing a reference to all the messages -->
|
||||
<array name="updates">
|
||||
<item>@array/update0</item>
|
||||
. . .
|
||||
<item>@array/update12</item>
|
||||
</array>
|
||||
</resources>
|
||||
<item>@array/update12</item>
|
||||
</array>
|
||||
</resources>
|
||||
|
||||
[/xml]
|
||||
{% endhighlight %}
|
||||
|
||||
Basically, my update mechanism rely on two different things :
|
||||
<ul>
|
||||
@@ -115,7 +115,7 @@ The updater <strong>compares the value of the latest update</strong> <strong>wit
|
||||
|
||||
But basically, the java code of interest can be summarized in the few following lines :
|
||||
|
||||
[java]
|
||||
{% highlight java %}
|
||||
private Resources res;
|
||||
// gets a reference to the array of updates
|
||||
res = ctx.getResources();
|
||||
@@ -130,7 +130,7 @@ But basically, the java code of interest can be summarized in the few following
|
||||
public int getLatestVersion(){
|
||||
return update_messages.length();
|
||||
}
|
||||
[/java]
|
||||
{% endhighlight %}
|
||||
|
||||
|
||||
But for some strange reason, things started acted weird last month. <strong>My 11th update wouldn't show up. Instead, it was the 8th being displayed!</strong>
|
||||
|
||||
Reference in New Issue
Block a user