Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e128761

Browse files
committed
Initial 1.0 code
0 parents  commit e128761

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5908
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bin
2+
gen
3+
tmp
4+
local.properties

AndroidManifest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<manifest xmlns:android='http://schemas.android.com/apk/res/android'
3+
android:versionName='1.0'
4+
package='org.rubyandroid.apibrowser'
5+
android:versionCode='1'
6+
android:installLocation="preferExternal">
7+
<application android:label='@string/app_name' android:icon='@drawable/icon'>
8+
<activity android:name='AndroidAPIBrowser' android:label='@string/app_name' android:configChanges="orientation">
9+
<intent-filter>
10+
<action android:name='android.intent.action.MAIN'/>
11+
<category android:name='android.intent.category.LAUNCHER'/>
12+
</intent-filter>
13+
</activity>
14+
<activity android:name='org.ruboto.RubotoActivity' android:configChanges="orientation" />
15+
<activity android:name='org.ruboto.RubotoDialog' android:theme='@android:style/Theme.Dialog'/>
16+
<activity android:name="org.ruboto.RubotoPreferenceActivity" />
17+
</application>
18+
19+
<uses-sdk android:minSdkVersion='3' android:targetSdkVersion='10'/>
20+
21+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
22+
<uses-permission android:name="android.permission.INTERNET"/>
23+
</manifest>

Rakefile

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# callback_reflection.rb creates the interfaces.txt (JRuby can't do YAML with ruby 1.8, so it's just
2+
# and inspect on the hash) on a device. Bring it off the device and put it in the callback_gen dir.
3+
#
4+
# Move this into a rake task later.
5+
#
6+
7+
8+
raise "Needs JRuby 1.5" unless RUBY_PLATFORM =~ /java/
9+
require 'ant'
10+
require 'rake/clean'
11+
require 'rexml/document'
12+
13+
generated_libs = 'generated_libs'
14+
jars = Dir['libs/*.jar']
15+
stdlib = jars.grep(/stdlib/).first #libs/jruby-stdlib-VERSION.jar
16+
jruby_jar = jars.grep(/core/).first #libs/jruby-core-VERSION.jar
17+
stdlib_precompiled = File.join(generated_libs, 'jruby-stdlib-precompiled.jar')
18+
jruby_ruboto_jar = File.join(generated_libs, 'jruby-ruboto.jar')
19+
ant.property :name=>'external.libs.dir', :value => generated_libs
20+
dirs = ['tmp/ruby', 'tmp/precompiled', generated_libs]
21+
dirs.each { |d| directory d }
22+
23+
CLEAN.include('tmp', 'bin', generated_libs)
24+
25+
ant_import
26+
27+
file stdlib_precompiled => :compile_stdlib
28+
file jruby_ruboto_jar => generated_libs do
29+
ant.zip(:destfile=>jruby_ruboto_jar) do
30+
zipfileset(:src=>jruby_jar) do
31+
exclude(:name=>'jni/**')
32+
# dx chokes on some of the netdb classes, for some reason
33+
exclude(:name=>'jnr/netdb/**')
34+
end
35+
end
36+
end
37+
38+
desc "precompile ruby stdlib"
39+
task :compile_stdlib => [:clean, *dirs] do
40+
ant.unzip(:src=>stdlib, :dest=>'tmp/ruby')
41+
Dir.chdir('tmp/ruby') { sh "jrubyc . -t ../precompiled" }
42+
ant.zip(:destfile=>stdlib_precompiled, :basedir=>'tmp/precompiled')
43+
end
44+
45+
task :generate_libs => [generated_libs, jruby_ruboto_jar] do
46+
cp stdlib, generated_libs
47+
end
48+
49+
task :debug => :generate_libs
50+
task :release => :generate_libs
51+
52+
task :default => :debug
53+
54+
task :tag => :release do
55+
unless `git branch` =~ /^\* master$/
56+
puts "You must be on the master branch to release!"
57+
exit!
58+
end
59+
sh "git commit --allow-empty -a -m 'Release #{version}'"
60+
sh "git tag #{version}"
61+
sh "git push origin master --tags"
62+
#sh "gem push pkg/#{name}-#{version}.gem"
63+
end
64+
65+
task :sign => :release do
66+
sh "jarsigner -keystore #{ENV['RUBOTO_KEYSTORE']} -signedjar bin/#{build_project_name}.apk bin/#{build_project_name}-unsigned.apk #{ENV['RUBOTO_KEY_ALIAS']}"
67+
end
68+
69+
task :align => :sign do
70+
sh "zipalign 4 bin/#{build_project_name}.apk #{build_project_name}.apk"
71+
end
72+
73+
task :publish => :align do
74+
puts "#{build_project_name}.apk is ready for the market!"
75+
end
76+
77+
task :update_scripts do
78+
Dir['assets/scripts/*.rb'].each do |script|
79+
`adb push #{script} /data/data/#{package}/files/scripts`
80+
end
81+
end
82+
83+
task :test do
84+
Dir.chdir('test') do
85+
puts 'Running tests'
86+
system "ant run-tests"
87+
end
88+
end
89+
90+
def manifest
91+
@manifest ||= REXML::Document.new(File.read('AndroidManifest.xml'))
92+
end
93+
94+
def strings(name)
95+
@strings ||= REXML::Document.new(File.read('res/values/strings.xml'))
96+
value = @strings.elements["//string[@name='#{name.to_s}']"] or raise "string '#{name}' not found in strings.xml"
97+
value.text
98+
end
99+
100+
def package() manifest.root.attribute('package') end
101+
def version() strings :version_name end
102+
def app_name() strings :app_name end
103+
def build_project_name() @build_project_name ||= REXML::Document.new(File.read('build.xml')).elements['project'].attribute(:name).value end
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
ruboto_import "#{$callbacks_package}.RubotoRunnable"
2+
ruboto_import "#{$callbacks_package}.RubotoDialogOnClickListener"
3+
4+
java_import "android.os.Message"
5+
java_import "android.os.Handler"
6+
java_import "android.app.ProgressDialog"
7+
java_import "java.net.URL"
8+
java_import "java.io.BufferedInputStream"
9+
java_import "java.util.zip.GZIPInputStream"
10+
11+
class Activity
12+
def alert_dialog(options)
13+
dialog = Java::android.app::AlertDialog::Builder.new(self)
14+
options.each do |k, v|
15+
if v.is_a?(Array)
16+
if v[-1].is_a?(Proc)
17+
proc = v[-1]
18+
v[-1] = RubotoDialogOnClickListener.new.handle_click{|d, w| proc.call(d,w)}
19+
end
20+
dialog.send("set#{k.to_s.gsub(/(^|_)([a-z])/) {$2.upcase}}", *v)
21+
else
22+
dialog.send("set#{k.to_s.gsub(/(^|_)([a-z])/) {$2.upcase}}", v)
23+
end
24+
end
25+
dialog.create.show
26+
end
27+
28+
def launch_list(a_title, query_or_array, &block)
29+
self.start_ruboto_activity "$list" do
30+
setTitle a_title
31+
32+
setup_content do
33+
if query_or_array.is_a?(Array)
34+
@lv = list_view :list => query_or_array
35+
else
36+
if query_or_array.is_a?(String)
37+
@cursor = $db.rawQuery(query_or_array, nil)
38+
startManagingCursor(@cursor)
39+
else
40+
@cursor = query_or_array
41+
end
42+
43+
setTitle "#{a_title} (#{@cursor.getCount})"
44+
45+
merge_adapter = MergeAdapter.new
46+
47+
merge_adapter.addView(
48+
text_view(:text => "Limiting view (API #{SQLiteModel.get_api_limit})",
49+
:gravity => Gravity::CENTER_HORIZONTAL,
50+
:text_size => 20,
51+
:background_color => Color::WHITE,
52+
:text_color => Color::BLACK)
53+
) unless SQLiteModel::get_api_limit.nil?
54+
55+
adapter = SimpleCursorAdapter.new(self, Ruboto::R::layout::list_item_single, @cursor,
56+
["name"].to_java(:string), [Ruboto::Id::text1].to_java(:int));
57+
adapter.setViewBinder(RubotoCursorViewBinder.main)
58+
merge_adapter.addAdapter adapter
59+
60+
@lv = list_view :adapter => merge_adapter
61+
end
62+
end
63+
64+
handle_item_click do |adapter_view, view, pos, item_id|
65+
block.call(self, adapter_view, view, pos, item_id)
66+
end
67+
end
68+
end
69+
70+
def progress_dialog(argh={})
71+
pd = ProgressDialog.new(self)
72+
pd.setTitle(argh[:title]) if argh[:title]
73+
pd.setMessage(argh[:message]) if argh[:message]
74+
pd.setProgressStyle((argh[:style] and argh[:style] == :horizontal) ?
75+
ProgressDialog::STYLE_HORIZONTAL : ProgressDialog::STYLE_SPINNER)
76+
pd.setMax(argh[:max]) if argh[:max]
77+
pd.setIndeterminate argh[:indeterminate] if argh[:indeterminate]
78+
pd.show
79+
pd
80+
end
81+
82+
def do_in_thread(argh = {}, &block)
83+
handler = Handler.new()
84+
85+
Thread.new do
86+
begin
87+
block.call
88+
handler.post(RubotoRunnable.new.handle_run{argh[:when_done].call if argh[:when_done]})
89+
rescue
90+
handler.post(RubotoRunnable.new.handle_run{argh[:when_failed].call if argh[:when_failed]})
91+
end
92+
end
93+
end
94+
95+
def download_in_thread(args)
96+
gzipped = args[:from][-3..-1] == ".gz"
97+
base_file_name = args[:from].split("/")[-1]
98+
base_file_name = base_file_name[0..-4] if gzipped
99+
100+
progress_dialog(:style => :horizontal, :title => "Downloading...",
101+
:max => args[:size]).do_in_thread(args[:when_done], args[:when_failed]) do
102+
args[:when_starting].call if args[:when_starting]
103+
f = nil
104+
105+
begin
106+
connection = URL.new(args[:from]).openConnection
107+
FileUtils.makedirs args[:to] unless File.directory? args[:to]
108+
f = File.open("#{args[:to]}/#{base_file_name}", "w")
109+
buff_size = 0x2000
110+
buff = Java::byte[buff_size].new
111+
112+
i = connection.getInputStream
113+
i = GZIPInputStream.new(i) if gzipped
114+
i = BufferedInputStream.new(i, buff_size)
115+
x = i.read(buff, 0, buff_size)
116+
117+
while x != -1
118+
f << String.from_java_bytes(x == buff_size ? buff : buff[0..(x-1)])
119+
$progress_dialog.increment_progress(x)
120+
x = i.read(buff, 0, buff_size)
121+
end
122+
$progress_dialog.success = true
123+
rescue
124+
$progress_dialog.success = false
125+
FileUtils.rm "#{args[:to]}/#{base_file_name}" if f and File.exists?("#{args[:to]}/#{base_file_name}")
126+
ensure
127+
connection.disconnect
128+
f.close
129+
args[:when_ending].call if args[:when_ending]
130+
end
131+
end
132+
end
133+
end
134+
135+
class ProgressDialog
136+
attr_reader :handler
137+
attr_writer :success
138+
139+
def success?
140+
@success.nil? ? true : @success
141+
end
142+
143+
def increment_progress(amount)
144+
@handler.post(RubotoRunnable.new.handle_run{$progress_dialog.incrementProgressBy(amount)})
145+
end
146+
147+
def do_in_thread(when_done=nil, when_failed=nil, &block)
148+
$progress_dialog = self
149+
@handler = Handler.new()
150+
151+
Thread.new do
152+
block.call
153+
154+
$progress_dialog.handler.post(RubotoRunnable.new.handle_run do
155+
$progress_dialog.dismiss
156+
finish_with = $progress_dialog.success? ? when_done : when_failed
157+
finish_with.call if finish_with
158+
$progress_dialog = nil
159+
end)
160+
end
161+
end
162+
end

0 commit comments

Comments
 (0)