Commit 3d664377 authored by Max Lv's avatar Max Lv

clean up

parent a74c3fde
......@@ -19,9 +19,9 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/btn_cab_done_pressed_shadow" />
android:drawable="@drawable/btn_cab_done_pressed_shadow"/>
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_cab_done_focused_shadow" />
android:drawable="@drawable/btn_cab_done_focused_shadow"/>
<item android:state_enabled="true"
android:drawable="@drawable/btn_cab_done_default_shadow" />
android:drawable="@drawable/btn_cab_done_default_shadow"/>
</selector>
......@@ -18,5 +18,5 @@
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/pressed_shadow" />
<solid android:color="@color/pressed_shadow"/>
</shape>
......@@ -20,16 +20,16 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/progress_bg_shadow" />
android:drawable="@drawable/progress_bg_shadow"/>
<item android:id="@android:id/secondaryProgress">
<scale android:scaleWidth="100%"
android:drawable="@drawable/progress_secondary_shadow" />
android:drawable="@drawable/progress_secondary_shadow"/>
</item>
<item android:id="@android:id/progress">
<scale android:scaleWidth="100%"
android:drawable="@drawable/progress_primary_shadow" />
android:drawable="@drawable/progress_primary_shadow"/>
</item>
</layer-list>
......@@ -18,8 +18,9 @@
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
<item android:state_pressed="false" android:state_focused="true" android:drawable="@drawable/list_focused_shadow" />
<item android:state_pressed="true" android:drawable="@drawable/pressed_background_shadow" />
<item android:drawable="@android:color/transparent" />
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_pressed="false" android:state_focused="true"
android:drawable="@drawable/list_focused_shadow"/>
<item android:state_pressed="true" android:drawable="@drawable/pressed_background_shadow"/>
<item android:drawable="@android:color/transparent"/>
</selector>
\ No newline at end of file
......@@ -19,10 +19,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="@drawable/spinner_ab_disabled_shadow" />
android:drawable="@drawable/spinner_ab_disabled_shadow"/>
<item android:state_pressed="true"
android:drawable="@drawable/spinner_ab_pressed_shadow" />
android:drawable="@drawable/spinner_ab_pressed_shadow"/>
<item android:state_pressed="false" android:state_focused="true"
android:drawable="@drawable/spinner_ab_focused_shadow" />
<item android:drawable="@drawable/spinner_ab_default_shadow" />
android:drawable="@drawable/spinner_ab_focused_shadow"/>
<item android:drawable="@drawable/spinner_ab_default_shadow"/>
</selector>
......@@ -19,19 +19,27 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_shadow" />
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false"
android:drawable="@android:color/transparent"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/tab_selected_shadow"/>
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected_focused_shadow" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected_focused_shadow" />
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false"
android:drawable="@drawable/tab_unselected_focused_shadow"/>
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false"
android:drawable="@drawable/tab_selected_focused_shadow"/>
<!-- Pressed -->
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_shadow" />
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_shadow" />
<item android:state_focused="false" android:state_selected="false" android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed_shadow"/>
<item android:state_focused="false" android:state_selected="true" android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_shadow"/>
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true" android:drawable="@drawable/tab_unselected_pressed_shadow" />
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_selected_pressed_shadow" />
<item android:state_focused="true" android:state_selected="false" android:state_pressed="true"
android:drawable="@drawable/tab_unselected_pressed_shadow"/>
<item android:state_focused="true" android:state_selected="true" android:state_pressed="true"
android:drawable="@drawable/tab_selected_pressed_shadow"/>
</selector>
......@@ -3,4 +3,4 @@
android:minWidth="80dp" android:maxWidth="80dp" android:gravity="center"
android:textSize="70sp" android:textColor="#ffffffff"
android:background="#99000088" android:padding="10dp"
android:visibility="invisible" />
\ No newline at end of file
android:visibility="invisible"/>
\ No newline at end of file
......@@ -35,7 +35,8 @@
</style>
<style name="ActionBar.Solid.Shadow" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<style name="ActionBar.Solid.Shadow"
parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/ab_solid_shadow</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_shadow</item>
<item name="android:backgroundSplit">@drawable/ab_bottom_solid_shadow</item>
......
......@@ -35,7 +35,8 @@
</style>
<style name="ActionBar.Solid.Shadow" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<style name="ActionBar.Solid.Shadow"
parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">@drawable/ab_solid_shadow</item>
<item name="backgroundStacked">@drawable/ab_stacked_solid_shadow</item>
<item name="backgroundSplit">@drawable/ab_bottom_solid_shadow</item>
......@@ -69,7 +70,8 @@
<item name="android:progressDrawable">@drawable/progress_horizontal_shadow</item>
</style>
<style name="ActionButton.CloseMode.Shadow" parent="@style/Widget.Sherlock.ActionButton.CloseMode">
<style name="ActionButton.CloseMode.Shadow"
parent="@style/Widget.Sherlock.ActionButton.CloseMode">
<item name="android:background">@drawable/btn_cab_done_shadow</item>
</style>
......
<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
<preference-headers
xmlns:unified="http://schemas.android.com/apk/res-auto">
<header
......
This diff is collapsed.
......@@ -31,9 +31,7 @@ public class Exec {
java.lang.System.loadLibrary("exec");
}
/**
* Close a given file descriptor.
*/
/** Close a given file descriptor. */
public static native void close(FileDescriptor fd);
/**
......@@ -53,13 +51,10 @@ public class Exec {
* process will be written.
* @return File descriptor
*/
public static native FileDescriptor createSubprocess(int rdt, String cmd,
String[] args, String[] envVars,
String scripts, int[] processId);
public static native FileDescriptor createSubprocess(int rdt, String cmd, String[] args,
String[] envVars, String scripts, int[] processId);
/**
* Send SIGHUP to a process group.
*/
/** Send SIGHUP to a process group. */
public static native void hangupProcessGroup(int processId);
/**
......
......@@ -45,7 +45,6 @@ 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;
......@@ -72,7 +71,6 @@ public class ImageLoader {
// Find the dir to save cached images
cacheDir = context.getCacheDir();
}
public void clearCache() {
......@@ -98,9 +96,7 @@ public class ImageLoader {
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE
|| height_tmp / 2 < REQUIRED_SIZE)
break;
if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
......@@ -116,9 +112,9 @@ public class ImageLoader {
}
public void DisplayImage(int uid, Activity activity, ImageView imageView) {
if (cache.containsKey(uid))
if (cache.containsKey(uid)) {
imageView.setImageBitmap(cache.get(uid));
else {
} else {
queuePhoto(uid, activity, imageView);
imageView.setImageResource(stub_id);
}
......@@ -132,13 +128,11 @@ public class ImageLoader {
// from SD cache
Bitmap b = decodeFile(f);
if (b != null)
return b;
if (b != null) return b;
// from web
try {
BitmapDrawable icon = (BitmapDrawable) Utils.getAppIcon(context,
uid);
BitmapDrawable icon = (BitmapDrawable) Utils.getAppIcon(context, uid);
return icon.getBitmap();
} catch (Exception ex) {
return null;
......@@ -156,8 +150,7 @@ public class ImageLoader {
}
// start thread if it's not started yet
if (photoLoaderThread.getState() == Thread.State.NEW)
photoLoaderThread.start();
if (photoLoaderThread.getState() == Thread.State.NEW) photoLoaderThread.start();
}
public void stopThread() {
......@@ -176,12 +169,13 @@ public class ImageLoader {
@Override
public void run() {
if (bitmap != null)
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
else
} else {
imageView.setImageResource(stub_id);
}
}
}
class PhotosLoader extends Thread {
@Override
......@@ -190,10 +184,11 @@ public class ImageLoader {
while (true) {
// thread waits until there are any images to load in the
// queue
if (photosQueue.photosToLoad.size() == 0)
if (photosQueue.photosToLoad.size() == 0) {
synchronized (photosQueue.photosToLoad) {
photosQueue.photosToLoad.wait();
}
}
if (photosQueue.photosToLoad.size() != 0) {
PhotoToLoad photoToLoad;
synchronized (photosQueue.photosToLoad) {
......@@ -203,15 +198,12 @@ public class ImageLoader {
cache.put(photoToLoad.uid, bmp);
Object tag = photoToLoad.imageView.getTag();
if (tag != null && ((Integer) tag) == photoToLoad.uid) {
BitmapDisplayer bd = new BitmapDisplayer(bmp,
photoToLoad.imageView);
Activity a = (Activity) photoToLoad.imageView
.getContext();
BitmapDisplayer bd = new BitmapDisplayer(bmp, photoToLoad.imageView);
Activity a = (Activity) photoToLoad.imageView.getContext();
a.runOnUiThread(bd);
}
}
if (Thread.interrupted())
break;
if (Thread.interrupted()) break;
}
} catch (InterruptedException e) {
// allow thread to exit
......@@ -227,8 +219,11 @@ public class ImageLoader {
public void Clean(ImageView image) {
synchronized (photosToLoad) {
for (int j = 0; j < photosToLoad.size(); ) {
if (photosToLoad.get(j).imageView == image) photosToLoad.remove(j);
else ++j;
if (photosToLoad.get(j).imageView == image) {
photosToLoad.remove(j);
} else {
++j;
}
}
}
}
......@@ -244,5 +239,4 @@ public class ImageLoader {
imageView = i;
}
}
}
......@@ -47,86 +47,62 @@ public class ProxyedApp {
private String name;
private boolean proxyed = false;
/**
* @return the name
*/
/** @return the name */
public String getName() {
return name;
}
/**
* @param name the name to set
*/
/** @param name the name to set */
public void setName(String name) {
this.name = name;
}
/**
* @return the procname
*/
/** @return the procname */
public String getProcname() {
return procname;
}
/**
* @param procname the procname to set
*/
/** @param procname the procname to set */
public void setProcname(String procname) {
this.procname = procname;
}
/**
* @return the uid
*/
/** @return the uid */
public int getUid() {
return uid;
}
/**
* @param uid the uid to set
*/
/** @param uid the uid to set */
public void setUid(int uid) {
this.uid = uid;
}
/**
* @return the username
*/
/** @return the username */
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
/** @param username the username to set */
public void setUsername(String username) {
this.username = username;
}
/**
* @return the enabled
*/
/** @return the enabled */
public boolean isEnabled() {
return enabled;
}
/**
* @param enabled the enabled to set
*/
/** @param enabled the enabled to set */
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* @return the proxyed
*/
/** @return the proxyed */
public boolean isProxyed() {
return proxyed;
}
/**
* @param proxyed the proxyed to set
*/
/** @param proxyed the proxyed to set */
public void setProxyed(boolean proxyed) {
this.proxyed = proxyed;
}
......
This diff is collapsed.
......@@ -54,5 +54,4 @@ public class ShadowsocksApplication extends Application {
EasyTracker.getInstance().setContext(this);
sTmpDir = getCacheDir().getAbsolutePath();
}
}
......@@ -63,7 +63,8 @@ public class ShadowsocksReceiver extends BroadcastReceiver {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
String versionName;
try {
versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
versionName =
context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
versionName = "NONE";
}
......@@ -89,5 +90,4 @@ public class ShadowsocksReceiver extends BroadcastReceiver {
context.startService(it);
}
}
}
......@@ -45,14 +45,19 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.util.Log;
import org.apache.http.conn.util.InetAddressUtils;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.http.conn.util.InetAddressUtils;
public class Utils {
......@@ -76,9 +81,7 @@ public class Utils {
private static String iptables = null;
private static String data_path = null;
/**
* Get IP address from first non-localhost interface
*/
/** Get IP address from first non-localhost interface */
public static boolean isIPv6Support() {
try {
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
......@@ -158,13 +161,11 @@ public class Utils {
boolean version = false;
StringBuilder sb = new StringBuilder();
String command = iptables + " --version\n" + iptables
+ " -L -t nat -n\n" + "exit\n";
String command = iptables + " --version\n" + iptables + " -L -t nat -n\n" + "exit\n";
int exitcode = runScript(command, sb, 10 * 1000, true);
if (exitcode == TIME_OUT)
return;
if (exitcode == TIME_OUT) return;
lines = sb.toString();
......@@ -177,27 +178,22 @@ public class Utils {
if (!compatible || !version) {
iptables = ALTERNATIVE_IPTABLES;
if (!new File(iptables).exists())
iptables = "iptables";
if (!new File(iptables).exists()) iptables = "iptables";
}
}
public static Drawable getAppIcon(Context c, int uid) {
PackageManager pm = c.getPackageManager();
Drawable appIcon = c.getResources().getDrawable(
android.R.drawable.sym_def_app_icon);
Drawable appIcon = c.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
String[] packages = pm.getPackagesForUid(uid);
if (packages != null) {
if (packages.length == 1) {
try {
ApplicationInfo appInfo = pm.getApplicationInfo(
packages[0], 0);
ApplicationInfo appInfo = pm.getApplicationInfo(packages[0], 0);
appIcon = pm.getApplicationIcon(appInfo);
} catch (NameNotFoundException e) {
Log.e(c.getPackageName(),
"No package found matching with the uid " + uid);
Log.e(c.getPackageName(), "No package found matching with the uid " + uid);
}
}
} else {
......@@ -211,10 +207,8 @@ public class Utils {
if (data_path == null) {
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
data_path = Environment.getExternalStorageDirectory()
.getAbsolutePath();
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
data_path = Environment.getExternalStorageDirectory().getAbsolutePath();
} else {
data_path = ctx.getFilesDir().getAbsolutePath();
}
......@@ -226,34 +220,30 @@ public class Utils {
}
public static boolean getHasRedirectSupport() {
if (hasRedirectSupport == -1)
initHasRedirectSupported();
if (hasRedirectSupport == -1) initHasRedirectSupported();
return hasRedirectSupport == 1;
}
public static String getIptables() {
if (iptables == null)
checkIptables();
if (iptables == null) checkIptables();
return iptables;
}
private static String getShell() {
if (shell == null) {
shell = DEFAULT_SHELL;
if (!new File(shell).exists())
shell = "sh";
if (!new File(shell).exists()) shell = "sh";
}
return shell;
}
public static void initHasRedirectSupported() {
if (!Utils.isRoot())
return;
if (!Utils.isRoot()) return;
StringBuilder sb = new StringBuilder();
String command = Utils.getIptables()
+ " -t nat -A OUTPUT -p udp --dport 54 -j REDIRECT --to 8154";
String command =
Utils.getIptables() + " -t nat -A OUTPUT -p udp --dport 54 -j REDIRECT --to 8154";
int exitcode = runScript(command, sb, 10 * 1000, true);
......@@ -264,8 +254,7 @@ public class Utils {
// flush the check command
Utils.runRootCommand(command.replace("-A", "-D"));
if (exitcode == TIME_OUT)
return;
if (exitcode == TIME_OUT) return;
if (lines.contains("No chain/target/match")) {
hasRedirectSupport = 0;
......@@ -273,19 +262,17 @@ public class Utils {
}
public static boolean isInitialized() {
if (initialized)
if (initialized) {
return true;
else {
} else {
initialized = true;
return false;
}
}
public static boolean isRoot() {
if (isRoot != -1)
return isRoot == 1;
if (isRoot != -1) return isRoot == 1;
// switch between binaries
if (new File(DEFAULT_ROOT).exists()) {
......@@ -319,7 +306,6 @@ public class Utils {
public static boolean runCommand(String command) {
return runCommand(command, 10 * 1000);
}
public static boolean runCommand(String command, int timeout) {
......@@ -334,7 +320,6 @@ public class Utils {
public static boolean runRootCommand(String command) {
return runRootCommand(command, 10 * 1000);
}
public static boolean runRootCommand(String command, int timeout) {
......@@ -351,8 +336,8 @@ public class Utils {
return true;
}
private synchronized static int runScript(String script, StringBuilder result,
long timeout, boolean asroot) {
private synchronized static int runScript(String script, StringBuilder result, long timeout,
boolean asroot) {
final ScriptRunner runner = new ScriptRunner(script, result, asroot);
runner.start();
try {
......@@ -373,9 +358,7 @@ public class Utils {
return runner.exitcode;
}
/**
* Internal thread used to execute scripts (as root or not).
*/
/** Internal thread used to execute scripts (as root or not). */
private static final class ScriptRunner extends Thread {
private final String scripts;
private final StringBuilder result;
......@@ -404,8 +387,7 @@ public class Utils {
* @param result result output
* @param asroot if true, executes the script as root
*/
public ScriptRunner(String script, StringBuilder result,
boolean asroot) {
public ScriptRunner(String script, StringBuilder result, boolean asroot) {
this.scripts = script;
this.result = result;
this.asroot = asroot;
......@@ -416,8 +398,8 @@ public class Utils {
String arg0 = argList.get(0);
String[] args = argList.toArray(new String[1]);
return Exec.createSubprocess(result != null ? 1 : 0, arg0, args, null,
scripts + "\nexit\n", processId);
return Exec.createSubprocess(result != null ? 1 : 0, arg0, args, null, scripts + "\nexit\n",
processId);
}
private ArrayList<String> parse(String cmd) {
......@@ -497,11 +479,9 @@ public class Utils {
read = stdout.read(buf);
result.append(new String(buf, 0, read));
}
} catch (Exception ex) {
Log.e(TAG, "Cannot execute command", ex);
if (result != null)
result.append("\n").append(ex);
if (result != null) result.append("\n").append(ex);
} finally {
if (pipe != null) {
Exec.close(pipe);
......
......@@ -3,7 +3,6 @@ package com.github.shadowsocks.preferences;
import android.content.Context;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
import com.github.shadowsocks.R;
public class SummaryEditTextPreference extends EditTextPreference {
......@@ -24,15 +23,11 @@ public class SummaryEditTextPreference extends EditTextPreference {
}
@Override
public void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
String value = getEditText().getText().toString();
if (value.isEmpty()) {
setSummary(mDefaultSummary);
public void setSummary(CharSequence summary) {
if (summary.toString().isEmpty()) {
super.setSummary(mDefaultSummary);
} else {
setSummary(value);
}
super.setSummary(summary);
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment