Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
527d8f40
Commit
527d8f40
authored
May 13, 2013
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine app manager
parent
1fafe1e2
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
128 additions
and
438 deletions
+128
-438
build.sbt
build.sbt
+2
-1
project/Build.scala
project/Build.scala
+2
-2
src/main/scala/com/github/shadowsocks/AppManager.scala
src/main/scala/com/github/shadowsocks/AppManager.scala
+103
-109
src/main/scala/com/github/shadowsocks/ImageLoader.scala
src/main/scala/com/github/shadowsocks/ImageLoader.scala
+0
-215
src/main/scala/com/github/shadowsocks/ProxiedApp.scala
src/main/scala/com/github/shadowsocks/ProxiedApp.scala
+0
-107
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
...ain/scala/com/github/shadowsocks/ShadowsocksService.scala
+2
-2
src/main/scala/com/github/shadowsocks/Utils.scala
src/main/scala/com/github/shadowsocks/Utils.scala
+19
-2
No files found.
build.sbt
View file @
527d8f40
...
...
@@ -5,7 +5,8 @@ javacOptions in doc ++= Seq("-source", "1.6")
libraryDependencies
++=
Seq
(
"com.google.android"
%
"support-v4"
%
"r12"
,
"com.google.android.analytics"
%
"analytics"
%
"2.0beta4"
,
"dnsjava"
%
"dnsjava"
%
"2.1.5"
"dnsjava"
%
"dnsjava"
%
"2.1.5"
,
"com.nostra13.universalimageloader"
%
"universal-image-loader"
%
"1.8.4"
)
libraryDependencies
++=
Seq
(
...
...
project/Build.scala
View file @
527d8f40
...
...
@@ -5,8 +5,8 @@ import org.scalasbt.androidplugin._
import
org.scalasbt.androidplugin.AndroidKeys._
object
App
{
val
version
=
"1.4.
3
"
val
versionCode
=
2
5
val
version
=
"1.4.
4
"
val
versionCode
=
2
6
}
object
General
{
...
...
src/main/scala/com/github/shadowsocks/AppManager.scala
View file @
527d8f40
This diff is collapsed.
Click to expand it.
src/main/scala/com/github/shadowsocks/ImageLoader.scala
deleted
100644 → 0
View file @
1fafe1e2
/* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2012 <max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* ___====-_ _-====___
* _--^^^#####// \\#####^^^--_
* _-^##########// ( ) \\##########^-_
* -############// |\^^/| \\############-
* _/############// (@::@) \\############\_
* /#############(( \\// ))#############\
* -###############\\ (oo) //###############-
* -#################\\ / VV \ //#################-
* -###################\\/ \//###################-
* _#/|##########/\######( /\ )######/\##########|\#_
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
* ` ` ` ` / | | | | \ ' ' ' '
* ( | | | | )
* __\ | | | | /__
* (vvv(VVV)(VVV)vvv)
*
* HERE BE DRAGONS
*
*/
package
com.github.shadowsocks
import
android.app.Activity
import
android.content.Context
import
android.graphics.Bitmap
import
android.graphics.BitmapFactory
import
android.graphics.drawable.BitmapDrawable
import
android.widget.ImageView
import
java.io.File
import
java.io.FileInputStream
import
java.io.FileNotFoundException
import
scala.collection.mutable
object
ImageLoader
{
def
getImageLoader
(
context
:
Context
)
:
ImageLoader
=
{
if
(
il
==
null
)
{
il
=
new
ImageLoader
(
context
)
}
il
}
class
PhotosQueue
{
def
clean
(
image
:
ImageView
)
{
photosToLoad
synchronized
{
{
photosToLoad
filterNot
(
photo
=>
photo
.
imageView
eq
image
)
}
}
}
val
photosToLoad
:
mutable.Stack
[
PhotoToLoad
]
=
new
mutable
.
Stack
[
PhotoToLoad
]
}
class
PhotoToLoad
{
def
this
(
u
:
Int
,
i
:
ImageView
)
{
this
()
uid
=
u
imageView
=
i
}
var
uid
:
Int
=
0
var
imageView
:
ImageView
=
null
}
class
BitmapDisplayer
(
bitmap
:
Bitmap
,
imageView
:
ImageView
)
extends
Runnable
{
def
run
()
{
if
(
bitmap
!=
null
)
{
imageView
.
setImageBitmap
(
bitmap
)
}
else
{
imageView
.
setImageResource
(
stub_id
)
}
}
}
var
il
:
ImageLoader
=
null
val
stub_id
:
Int
=
android
.
R
.
drawable
.
sym_def_app_icon
}
class
ImageLoader
{
def
this
(
c
:
Context
)
{
this
()
photoLoaderThread
.
setPriority
(
Thread
.
NORM_PRIORITY
-
1
)
context
=
c
cacheDir
=
context
.
getCacheDir
}
def
clearCache
()
{
cache
.
clear
()
val
files
:
Array
[
File
]
=
cacheDir
.
listFiles
for
(
f
<-
files
)
f
.
delete
}
private
def
decodeFile
(
f
:
File
)
:
Bitmap
=
{
try
{
val
o
:
BitmapFactory.Options
=
new
BitmapFactory
.
Options
o
.
inJustDecodeBounds
=
true
BitmapFactory
.
decodeStream
(
new
FileInputStream
(
f
),
null
,
o
)
val
REQUIRED_SIZE
:
Int
=
70
var
width_tmp
:
Int
=
o
.
outWidth
var
height_tmp
:
Int
=
o
.
outHeight
var
scale
:
Int
=
1
while
(
true
)
{
if
(
width_tmp
/
2
>=
REQUIRED_SIZE
&&
height_tmp
/
2
>=
REQUIRED_SIZE
)
{
width_tmp
/=
2
height_tmp
/=
2
scale
*=
2
}
}
val
o2
:
BitmapFactory.Options
=
new
BitmapFactory
.
Options
o2
.
inSampleSize
=
scale
return
BitmapFactory
.
decodeStream
(
new
FileInputStream
(
f
),
null
,
o2
)
}
catch
{
case
ignored
:
FileNotFoundException
=>
{
}
}
null
}
def
DisplayImage
(
uid
:
Int
,
activity
:
Activity
,
imageView
:
ImageView
)
{
cache
.
get
(
uid
)
map
{
bitmap
=>
imageView
.
setImageBitmap
(
bitmap
)
}
getOrElse
{
queuePhoto
(
uid
,
activity
,
imageView
)
imageView
.
setImageResource
(
ImageLoader
.
stub_id
)
}
}
private
def
getBitmap
(
uid
:
Int
)
:
Bitmap
=
{
val
filename
=
String
.
valueOf
(
uid
)
val
f
:
File
=
new
File
(
cacheDir
,
filename
)
val
b
:
Bitmap
=
decodeFile
(
f
)
if
(
b
!=
null
)
return
b
try
{
val
icon
:
BitmapDrawable
=
Utils
.
getAppIcon
(
context
,
uid
).
asInstanceOf
[
BitmapDrawable
]
icon
.
getBitmap
}
catch
{
case
ex
:
Exception
=>
{
return
null
}
}
}
def
queuePhoto
(
uid
:
Int
,
activity
:
Activity
,
imageView
:
ImageView
)
{
photosQueue
.
clean
(
imageView
)
val
p
:
ImageLoader.PhotoToLoad
=
new
ImageLoader
.
PhotoToLoad
(
uid
,
imageView
)
photosQueue
.
photosToLoad
synchronized
{
photosQueue
.
photosToLoad
.
push
(
p
)
photosQueue
.
photosToLoad
.
notifyAll
()
}
if
(
photoLoaderThread
.
getState
eq
Thread
.
State
.
NEW
)
photoLoaderThread
.
start
()
}
def
stopThread
()
{
photoLoaderThread
.
interrupt
()
}
val
photosQueue
:
ImageLoader.PhotosQueue
=
new
ImageLoader
.
PhotosQueue
val
photoLoaderThread
:
PhotosLoader
=
new
PhotosLoader
var
cache
:
mutable.HashMap
[
Int
,
Bitmap
]
=
new
mutable
.
HashMap
[
Int
,
Bitmap
]
var
cacheDir
:
File
=
null
var
context
:
Context
=
null
class
PhotosLoader
extends
Thread
{
override
def
run
()
{
try
{
while
(
true
)
{
if
(
photosQueue
.
photosToLoad
.
size
==
0
)
{
photosQueue
.
photosToLoad
synchronized
{
photosQueue
.
photosToLoad
.
wait
()
}
}
if
(
photosQueue
.
photosToLoad
.
size
!=
0
)
{
var
photoToLoad
:
ImageLoader.PhotoToLoad
=
null
photosQueue
.
photosToLoad
synchronized
{
photoToLoad
=
photosQueue
.
photosToLoad
.
pop
()
}
val
bmp
:
Bitmap
=
getBitmap
(
photoToLoad
.
uid
)
cache
.
put
(
photoToLoad
.
uid
,
bmp
)
val
tag
:
AnyRef
=
photoToLoad
.
imageView
.
getTag
if
(
tag
!=
null
&&
tag
.
asInstanceOf
[
Int
]
==
photoToLoad
.
uid
)
{
val
bd
:
ImageLoader.BitmapDisplayer
=
new
ImageLoader
.
BitmapDisplayer
(
bmp
,
photoToLoad
.
imageView
)
val
a
:
Activity
=
photoToLoad
.
imageView
.
getContext
.
asInstanceOf
[
Activity
]
a
.
runOnUiThread
(
bd
)
}
}
if
(
Thread
.
interrupted
)
return
}
}
catch
{
case
e
:
InterruptedException
=>
{
}
}
}
}
}
\ No newline at end of file
src/main/scala/com/github/shadowsocks/ProxiedApp.scala
deleted
100644 → 0
View file @
1fafe1e2
/* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 2012 <max.c.lv@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* ___====-_ _-====___
* _--^^^#####// \\#####^^^--_
* _-^##########// ( ) \\##########^-_
* -############// |\^^/| \\############-
* _/############// (@::@) \\############\_
* /#############(( \\// ))#############\
* -###############\\ (oo) //###############-
* -#################\\ / VV \ //#################-
* -###################\\/ \//###################-
* _#/|##########/\######( /\ )######/\##########|\#_
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
* ` ` ` ` / | | | | \ ' ' ' '
* ( | | | | )
* __\ | | | | /__
* (vvv(VVV)(VVV)vvv)
*
* HERE BE DRAGONS
*
*/
package
com.github.shadowsocks
class
ProxiedApp
{
/** @return the name */
def
getName
:
String
=
{
name
}
/** @param name the name to set */
def
setName
(
name
:
String
)
{
this
.
name
=
name
}
/** @return the procname */
def
getProcname
:
String
=
{
procname
}
/** @param procname the procname to set */
def
setProcname
(
procname
:
String
)
{
this
.
procname
=
procname
}
/** @return the uid */
def
getUid
:
Int
=
{
uid
}
/** @param uid the uid to set */
def
setUid
(
uid
:
Int
)
{
this
.
uid
=
uid
}
/** @return the username */
def
getUsername
:
String
=
{
username
}
/** @param username the username to set */
def
setUsername
(
username
:
String
)
{
this
.
username
=
username
}
/** @return the enabled */
def
isEnabled
:
Boolean
=
{
enabled
}
/** @param enabled the enabled to set */
def
setEnabled
(
enabled
:
Boolean
)
{
this
.
enabled
=
enabled
}
/** @return the proxied */
def
isProxied
:
Boolean
=
{
proxied
}
/** @param proxied the proxied to set */
def
setProxyed
(
proxied
:
Boolean
)
{
this
.
proxied
=
proxied
}
private
var
enabled
:
Boolean
=
false
private
var
uid
:
Int
=
0
private
var
username
:
String
=
null
private
var
procname
:
String
=
null
private
var
name
:
String
=
null
private
var
proxied
:
Boolean
=
false
}
\ No newline at end of file
src/main/scala/com/github/shadowsocks/ShadowsocksService.scala
View file @
527d8f40
...
...
@@ -433,8 +433,8 @@ class ShadowsocksService extends Service {
if
(
apps
==
null
||
apps
.
length
<=
0
)
apps
=
AppManager
.
getProxiedApps
(
this
)
val
uidSet
:
mutable.HashSet
[
Int
]
=
new
mutable
.
HashSet
[
Int
]
for
(
app
<-
apps
)
{
if
(
app
.
isP
roxied
)
{
uidSet
.
add
(
app
.
getU
id
)
if
(
app
.
p
roxied
)
{
uidSet
.
add
(
app
.
u
id
)
}
}
for
(
uid
<-
uidSet
)
{
...
...
src/main/scala/com/github/shadowsocks/Utils.scala
View file @
527d8f40
...
...
@@ -40,7 +40,7 @@ package com.github.shadowsocks
import
android.content.Context
import
android.content.pm.ApplicationInfo
import
android.content.pm.PackageManager
import
android.graphics.drawable.
Drawable
import
android.graphics.drawable.
{
BitmapDrawable
,
Drawable
}
import
android.os.Environment
import
android.util.Log
import
java.io._
...
...
@@ -49,6 +49,7 @@ import org.apache.http.conn.util.InetAddressUtils
import
scala.collection.mutable.ArrayBuffer
import
org.xbill.DNS._
import
scala.Some
import
android.graphics.
{
Canvas
,
Bitmap
}
object
Utils
{
...
...
@@ -245,12 +246,28 @@ object Utils {
}
}
def
drawableToBitmap
(
drawable
:
Drawable
)
:
Bitmap
=
{
if
(
drawable
.
isInstanceOf
[
BitmapDrawable
])
{
return
drawable
.
asInstanceOf
[
BitmapDrawable
].
getBitmap
}
val
width
=
if
(
drawable
.
getIntrinsicWidth
>
0
)
drawable
.
getIntrinsicWidth
else
1
val
height
=
if
(
drawable
.
getIntrinsicWidth
>
0
)
drawable
.
getIntrinsicWidth
else
1
val
bitmap
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
)
val
canvas
=
new
Canvas
(
bitmap
)
drawable
.
setBounds
(
0
,
0
,
canvas
.
getWidth
,
canvas
.
getHeight
)
drawable
.
draw
(
canvas
)
bitmap
}
def
getAppIcon
(
c
:
Context
,
uid
:
Int
)
:
Drawable
=
{
val
pm
:
PackageManager
=
c
.
getPackageManager
var
appIcon
:
Drawable
=
c
.
getResources
.
getDrawable
(
android
.
R
.
drawable
.
sym_def_app_icon
)
val
packages
:
Array
[
String
]
=
pm
.
getPackagesForUid
(
uid
)
if
(
packages
!=
null
)
{
if
(
packages
.
length
=
=
1
)
{
if
(
packages
.
length
>
=
1
)
{
try
{
val
appInfo
:
ApplicationInfo
=
pm
.
getApplicationInfo
(
packages
(
0
),
0
)
appIcon
=
pm
.
getApplicationIcon
(
appInfo
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment