Commit 96799136 authored by Max Lv's avatar Max Lv

rework layout

parent f2d129ab
...@@ -37,7 +37,12 @@ ...@@ -37,7 +37,12 @@
<activity <activity
android:name=".AppManager" android:name=".AppManager"
android:theme="@style/Theme.GAEProxy" android:theme="@style/Theme.GAEProxy"
android:label="@string/app_name"/> android:label="@string/app_name">
<intent-filter>
<action android:name="com.github.shadowsocks.AppManager" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service <service
android:name=".ShadowsocksService" android:name=".ShadowsocksService"
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.github.shadowsocks</groupId> <groupId>com.github.shadowsocks</groupId>
...@@ -35,6 +35,13 @@ ...@@ -35,6 +35,13 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.3.0</version>
<type>apklib</type>
</dependency>
<dependency> <dependency>
<groupId>com.google.android.analytics</groupId> <groupId>com.google.android.analytics</groupId>
<artifactId>analytics</artifactId> <artifactId>analytics</artifactId>
...@@ -47,6 +54,20 @@ ...@@ -47,6 +54,20 @@
<version>1.5</version> <version>1.5</version>
</dependency> </dependency>
<dependency>
<groupId>net.saik0.android.unifiedpreference</groupId>
<artifactId>unifiedpreference</artifactId>
<version>0.0.2</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>org.jraf</groupId>
<artifactId>android-switch-backport</artifactId>
<version>1.0</version>
<type>apklib</type>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" <LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:duplicateParentState="false"> android:orientation="vertical" android:duplicateParentState="false">
<TextView android:text="@string/proxyed_help" <TextView android:text="@string/proxied_help"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="16sp" android:padding="3px" /> android:textSize="16sp" android:padding="3dp"/>
<ListView android:layout_width="fill_parent" <ListView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/applistview"></ListView> android:layout_height="wrap_content" android:id="@+id/applistview"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -13,6 +13,5 @@ ...@@ -13,6 +13,5 @@
<CheckBox android:layout_width="wrap_content" <CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/itemcheck"></CheckBox> android:layout_height="wrap_content" android:id="@+id/itemcheck"></CheckBox>
</TableRow> </TableRow>
</TableLayout> </TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.jraf.android.backport.switchwidget.Switch
android:id="@+id/switchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
Zirco Browser for Android
Copyright (C) 2010 - 2011 J. Devauchelle and contributors.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 3 as published by the Free Software Foundation.
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.
-->
<resources>
<!-- Variation on the Light theme that turns off the title -->
<style name="Theme.GAEProxy" parent="android:Theme.Holo.Light"/>
</resources>
\ No newline at end of file
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
</array> </array>
<!-- feature category --> <!-- feature category -->
<string name="fearute_cat">Feature Settings</string> <string name="feature_cat">Feature Settings</string>
<string name="http_proxy">HTTP Proxy</string> <string name="http_proxy">HTTP Proxy</string>
<string name="http_proxy_summary">Local HTTP Proxy</string> <string name="http_proxy_summary">Local HTTP Proxy</string>
<string name="dns_proxy">DNS Proxy</string> <string name="dns_proxy">DNS Proxy</string>
...@@ -40,10 +40,10 @@ ...@@ -40,10 +40,10 @@
<string name="auto_set_proxy">Global Proxy</string> <string name="auto_set_proxy">Global Proxy</string>
<string name="auto_set_proxy_summary">Set up system wide proxy <string name="auto_set_proxy_summary">Set up system wide proxy
</string> </string>
<string name="proxyed_apps">Individual Proxy</string> <string name="proxied_apps">Individual Proxy</string>
<string name="proxyed_apps_summary">Set individual proxy for apps <string name="proxied_apps_summary">Set individual proxy for apps
</string> </string>
<string name="proxyed_help">Select apps to use with Shadowsocks:</string> <string name="proxied_help">Select apps to use with Shadowsocks:</string>
<string name="bypass_apps">Bypass Mode</string> <string name="bypass_apps">Bypass Mode</string>
<string name="bypass_apps_summary">Enable this option to bypass selected apps</string> <string name="bypass_apps_summary">Enable this option to bypass selected apps</string>
<string name="auto_connect">Auto Connect</string> <string name="auto_connect">Auto Connect</string>
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
<resources> <resources>
<!-- Variation on the Light theme that turns off the title --> <!-- Variation on the Light theme that turns off the title -->
<style name="Theme.GAEProxy" parent="android:Theme.Light"/> <style name="Theme.GAEProxy" parent="@style/Theme.Sherlock.Light">
<item name="switchStyle">@style/Widget.Holo.Light.CompoundButton.Switch</item>
</style>
</resources> </resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="false"
android:key="isHTTPProxy"
android:summary="@string/http_proxy_summary"
android:title="@string/http_proxy">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="isDNSProxy"
android:summary="@string/dns_proxy_summary"
android:title="@string/dns_proxy">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="isGFWList"
android:summary="@string/auto_set_gfwlist_summary"
android:title="@string/auto_set_gfwlist">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="isGlobalProxy"
android:disableDependentsState="true"
android:summary="@string/auto_set_proxy_summary"
android:title="@string/auto_set_proxy">
</CheckBoxPreference>
<CheckBoxPreference
android:defaultValue="false"
android:dependency="isGlobalProxy"
android:key="isBypassApps"
android:summary="@string/bypass_apps_summary"
android:title="@string/bypass_apps">
</CheckBoxPreference>
<Preference
android:key="proxyedApps"
android:dependency="isGlobalProxy"
android:summary="@string/proxied_apps_summary"
android:title="@string/proxied_apps">
<intent android:action="com.github.shadowsocks.AppManager"/>
</Preference>
<CheckBoxPreference
android:key="isAutoConnect"
android:summary="@string/auto_connect_summary"
android:title="@string/auto_connect">
</CheckBoxPreference>
</PreferenceScreen>
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue="198.199.101.152"
android:key="proxy"
android:summary="@string/proxy_summary"
android:title="@string/proxy">
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue="443"
android:key="remotePort"
android:summary="@string/remote_port_summary"
android:title="@string/remote_port">
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue="1080"
android:key="port"
android:summary="@string/port_summary"
android:title="@string/port">
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
<com.github.shadowsocks.preferences.SummaryEditTextPreference
android:defaultValue="u1rRWTssNv0p"
android:key="sitekey"
android:summary="@string/sitekey_summary"
android:title="@string/sitekey">
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
<ListPreference
android:defaultValue="rc4"
android:key="encMethod"
android:entries="@array/enc_method_entry"
android:entryValues="@array/enc_method_value"
android:title="@string/enc_method">
</ListPreference>
</PreferenceScreen>
<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:unified="http://schemas.android.com/apk/res-auto">
<header
unified:fragment="com.github.shadowsocks.Shadowsocks$ProxyFragment"
unified:title="@string/proxy_cat"
unified:preferenceRes="@xml/pref_proxy"/>
<header
unified:fragment="com.github.shadowsocks.Shadowsocks$FeatureFragment"
unified:title="@string/feature_cat"
unified:preferenceRes="@xml/pref_feature"/>
</preference-headers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/function_cat">
<CheckBoxPreference
android:key="isRunning"
android:disableDependentsState="true"
android:summary="@string/service_summary"
android:title="@string/service_controller">
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/proxy_cat">
<EditTextPreference
android:dependency="isRunning"
android:defaultValue="198.199.101.152"
android:key="proxy"
android:summary="@string/proxy_summary"
android:title="@string/proxy">
</EditTextPreference>
<EditTextPreference
android:dependency="isRunning"
android:defaultValue="443"
android:key="remotePort"
android:summary="@string/remote_port_summary"
android:title="@string/remote_port">
</EditTextPreference>
<EditTextPreference
android:dependency="isRunning"
android:defaultValue="1080"
android:key="port"
android:summary="@string/port_summary"
android:title="@string/port">
</EditTextPreference>
<EditTextPreference
android:dependency="isRunning"
android:defaultValue="u1rRWTssNv0p"
android:key="sitekey"
android:summary="@string/sitekey_summary"
android:title="@string/sitekey">
</EditTextPreference>
<ListPreference
android:dependency="isRunning"
android:defaultValue="rc4"
android:key="encMethod"
android:entries="@array/enc_method_entry"
android:entryValues="@array/enc_method_value"
android:title="@string/enc_method">
</ListPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/fearute_cat">
<CheckBoxPreference
android:dependency="isRunning"
android:defaultValue="false"
android:key="isHTTPProxy"
android:summary="@string/http_proxy_summary"
android:title="@string/http_proxy">
</CheckBoxPreference>
<CheckBoxPreference
android:dependency="isRunning"
android:defaultValue="true"
android:key="isDNSProxy"
android:summary="@string/dns_proxy_summary"
android:title="@string/dns_proxy">
</CheckBoxPreference>
<CheckBoxPreference
android:dependency="isRunning"
android:defaultValue="true"
android:key="isGFWList"
android:summary="@string/auto_set_gfwlist_summary"
android:title="@string/auto_set_gfwlist">
</CheckBoxPreference>
<CheckBoxPreference
android:dependency="isRunning"
android:defaultValue="true"
android:key="isGlobalProxy"
android:summary="@string/auto_set_proxy_summary"
android:title="@string/auto_set_proxy">
</CheckBoxPreference>
<CheckBoxPreference
android:dependency="isRunning"
android:defaultValue="false"
android:key="isBypassApps"
android:summary="@string/bypass_apps_summary"
android:title="@string/bypass_apps">
</CheckBoxPreference>
<Preference
android:dependency="isRunning"
android:key="proxyedApps"
android:summary="@string/proxyed_apps_summary"
android:title="@string/proxyed_apps">
</Preference>
<CheckBoxPreference
android:dependency="isRunning"
android:key="isAutoConnect"
android:summary="@string/auto_connect_summary"
android:title="@string/auto_connect">
</CheckBoxPreference>
</PreferenceCategory>
</PreferenceScreen>
...@@ -53,20 +53,29 @@ import android.os.Message; ...@@ -53,20 +53,29 @@ import android.os.Message;
import android.preference.*; import android.preference.*;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.widget.CompoundButton;
import android.view.MenuItem; import android.widget.RelativeLayout;
import android.widget.Toast; import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.google.analytics.tracking.android.EasyTracker; import com.google.analytics.tracking.android.EasyTracker;
import net.saik0.android.unifiedpreference.UnifiedPreferenceFragment;
import net.saik0.android.unifiedpreference.UnifiedSherlockPreferenceActivity;
import org.jraf.android.backport.switchwidget.Switch;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
public class Shadowsocks extends PreferenceActivity implements public class Shadowsocks extends UnifiedSherlockPreferenceActivity
OnSharedPreferenceChangeListener { implements CompoundButton.OnCheckedChangeListener, OnSharedPreferenceChangeListener {
public static final String PREFS_NAME = "Shadowsocks"; public static final String PREFS_NAME = "Shadowsocks";
public static final String[] PROXY_PREFS = {"proxy", "remotePort", "port"
, "sitekey", "encMethod"};
public static final String[] FEATRUE_PREFS = {"isHTTPProxy", "isDNSProxy", "isGFWList", "isGlobalProxy", "isBypassApps"
, "proxyedApps", "isAutoConnect"};
private static final String TAG = "Shadowsocks"; private static final String TAG = "Shadowsocks";
private static final int MSG_CRASH_RECOVER = 1; private static final int MSG_CRASH_RECOVER = 1;
private static final int MSG_INITIAL_FINISH = 2; private static final int MSG_INITIAL_FINISH = 2;
...@@ -94,14 +103,7 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -94,14 +103,7 @@ public class Shadowsocks extends PreferenceActivity implements
super.handleMessage(msg); super.handleMessage(msg);
} }
}; };
private EditTextPreference proxyText; private Switch switchButton;
private EditTextPreference portText;
private EditTextPreference remotePortText;
private EditTextPreference sitekeyText;
private ListPreference encMethodText;
private Preference proxyedApps;
private CheckBoxPreference isBypassAppsCheck;
private CheckBoxPreference isRunningCheck;
private void copyAssets(String path) { private void copyAssets(String path) {
...@@ -161,67 +163,43 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -161,67 +163,43 @@ public class Shadowsocks extends PreferenceActivity implements
return false; return false;
} }
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (compoundButton == switchButton) {
if (!serviceStart()) {
switchButton.setChecked(false);
}
}
}
/** /**
* Called when the activity is first created. * Called when the activity is first created.
*/ */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
setHeaderRes(R.xml.shadowsocks_headers);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.shadowsocks_preference); RelativeLayout switchLayout = (RelativeLayout)
getLayoutInflater().inflate(R.layout.layout_switch, null);
proxyText = (EditTextPreference) findPreference("proxy");
portText = (EditTextPreference) findPreference("port");
remotePortText = (EditTextPreference) findPreference("remotePort");
sitekeyText = (EditTextPreference) findPreference("sitekey");
encMethodText = (ListPreference) findPreference("encMethod");
proxyedApps = findPreference("proxyedApps");
isBypassAppsCheck = (CheckBoxPreference) findPreference("isBypassApps");
isRunningCheck = (CheckBoxPreference) findPreference("isRunning");
if (mProgressDialog == null) {
mProgressDialog = ProgressDialog.show(this, "",
getString(R.string.initializing), true, true);
}
new Thread() {
@Override
public void run() {
Utils.isRoot();
String versionName;
try {
versionName = getPackageManager().getPackageInfo(
getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
versionName = "NONE";
}
final SharedPreferences settings = PreferenceManager getSupportActionBar().setCustomView(switchLayout);
.getDefaultSharedPreferences(Shadowsocks.this); getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayShowCustomEnabled(true);
if (!settings.getBoolean(versionName, false)) { switchButton = (Switch) switchLayout.findViewById(R.id.switchButton);
Editor edit = settings.edit();
edit.putBoolean(versionName, true);
edit.commit();
reset();
}
handler.sendEmptyMessage(MSG_INITIAL_FINISH);
}
}.start();
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, Menu.FIRST + 1, 1, getString(R.string.recovery)) menu.add(0, 0, 0, R.string.recovery)
.setIcon(android.R.drawable.ic_menu_delete); .setIcon(android.R.drawable.ic_menu_revert)
menu.add(Menu.NONE, Menu.FIRST + 2, 2, getString(R.string.about)) .setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
.setIcon(android.R.drawable.ic_menu_info_details); menu.add(0, 1, 1, R.string.about)
.setIcon(android.R.drawable.ic_menu_info_details)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true; return true;
} }
/** /**
...@@ -235,11 +213,6 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -235,11 +213,6 @@ public class Shadowsocks extends PreferenceActivity implements
editor.putBoolean("isConnected", ShadowsocksService.isServiceStarted()); editor.putBoolean("isConnected", ShadowsocksService.isServiceStarted());
editor.commit(); editor.commit();
if (mProgressDialog != null) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
super.onDestroy(); super.onDestroy();
} }
...@@ -256,14 +229,13 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -256,14 +229,13 @@ public class Shadowsocks extends PreferenceActivity implements
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
// 菜单项被选择事件
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case Menu.FIRST + 1: case 0:
recovery(); recovery();
break; break;
case Menu.FIRST + 2: case 1:
String versionName = ""; String versionName = "";
try { try {
versionName = getPackageManager().getPackageInfo( versionName = getPackageManager().getPackageInfo(
...@@ -276,57 +248,27 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -276,57 +248,27 @@ public class Shadowsocks extends PreferenceActivity implements
break; break;
} }
return true; return super.onOptionsItemSelected(item);
} }
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
PreferenceManager.getDefaultSharedPreferences(this)
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this); .unregisterOnSharedPreferenceChangeListener(this);
} }
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
Preference preference) {
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(this);
if (preference.getKey() != null
&& preference.getKey().equals("proxyedApps")) {
Intent intent = new Intent(this, AppManager.class);
startActivity(intent);
} else if (preference.getKey() != null
&& preference.getKey().equals("isRunning")) {
if (!serviceStart()) {
Editor edit = settings.edit();
edit.putBoolean("isRunning", false);
edit.commit();
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
SharedPreferences settings = PreferenceManager SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(this); .getDefaultSharedPreferences(this);
if (settings.getBoolean("isGlobalProxy", false)) {
proxyedApps.setEnabled(false);
isBypassAppsCheck.setEnabled(false);
} else {
proxyedApps.setEnabled(true);
isBypassAppsCheck.setEnabled(true);
}
Editor edit = settings.edit(); Editor edit = settings.edit();
if (ShadowsocksService.isServiceStarted()) { if (ShadowsocksService.isServiceStarted()) {
edit.putBoolean("isRunning", true); edit.putBoolean("isRunning", true);
switchButton.setChecked(true);
} else { } else {
if (settings.getBoolean("isRunning", false)) { if (settings.getBoolean("isRunning", false)) {
new Thread() { new Thread() {
...@@ -338,33 +280,44 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -338,33 +280,44 @@ public class Shadowsocks extends PreferenceActivity implements
}.start(); }.start();
} }
edit.putBoolean("isRunning", false); edit.putBoolean("isRunning", false);
switchButton.setChecked(false);
} }
edit.commit(); edit.commit();
// Setup the initial values setPreferenceEnabled();
if (!settings.getString("sitekey", "").equals("")) switchButton.setOnCheckedChangeListener(this);
sitekeyText.setSummary(settings.getString("sitekey", "")); PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
if (!settings.getString("encMethod", "").equals(""))
encMethodText.setSummary(settings.getString("encMethod", ""));
if (!settings.getString("port", "").equals("")) }
portText.setSummary(settings.getString("port",
getString(R.string.port_summary)));
if (!settings.getString("remotePort", "").equals("")) private void setPreferenceEnabled() {
remotePortText.setSummary(settings.getString("remotePort", SharedPreferences settings = PreferenceManager
getString(R.string.remote_port_summary))); .getDefaultSharedPreferences(Shadowsocks.this);
if (!settings.getString("proxy", "").equals("")) boolean enabled = !settings.getBoolean("isRunning", false)
proxyText.setSummary(settings.getString("proxy", && !settings.getBoolean("isConnecting", false);
getString(R.string.proxy_summary)));
// Set up a listener whenever a key changes for (String name : PROXY_PREFS) {
getPreferenceScreen().getSharedPreferences() Preference pref = findPreference(name);
.registerOnSharedPreferenceChangeListener(this); if (pref != null) {
pref.setEnabled(enabled);
}
}
for (String name : FEATRUE_PREFS) {
Preference pref = findPreference(name);
if (pref != null) {
if (name.equals("isBypassApps")
|| name.equals("proxyedApps")) {
boolean isGlobalProxy = settings.getBoolean("isGlobalProxy", false);
pref.setEnabled(enabled && !isGlobalProxy);
} else {
pref.setEnabled(enabled);
}
}
}
} }
@Override @Override
...@@ -376,9 +329,9 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -376,9 +329,9 @@ public class Shadowsocks extends PreferenceActivity implements
if (key.equals("isRunning")) { if (key.equals("isRunning")) {
if (settings.getBoolean("isRunning", false)) { if (settings.getBoolean("isRunning", false)) {
isRunningCheck.setChecked(true); switchButton.setChecked(true);
} else { } else {
isRunningCheck.setChecked(false); switchButton.setChecked(false);
} }
} }
...@@ -397,44 +350,8 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -397,44 +350,8 @@ public class Shadowsocks extends PreferenceActivity implements
} }
} }
if (key.equals("isGlobalProxy")) { if (key.equals("isRunning") || key.equals("isGlobalProxy")) {
if (settings.getBoolean("isGlobalProxy", false)) { setPreferenceEnabled();
proxyedApps.setEnabled(false);
isBypassAppsCheck.setEnabled(false);
} else {
proxyedApps.setEnabled(true);
isBypassAppsCheck.setEnabled(true);
}
}
if (key.equals("remotePort")) {
if (settings.getString("remotePort", "").equals("")) {
remotePortText.setSummary(getString(R.string.remote_port_summary));
} else {
remotePortText.setSummary(settings.getString("remotePort", ""));
}
} else if (key.equals("port")) {
if (settings.getString("port", "").equals("")) {
portText.setSummary(getString(R.string.port_summary));
} else {
portText.setSummary(settings.getString("port", ""));
}
} else if (key.equals("sitekey")) {
if (settings.getString("sitekey", "").equals("")) {
sitekeyText.setSummary(getString(R.string.sitekey_summary));
} else {
sitekeyText.setSummary(settings.getString("sitekey", ""));
}
} else if (key.equals("encMethod")) {
if (!settings.getString("encMethod", "").equals("")) {
encMethodText.setSummary(settings.getString("encMethod", ""));
}
} else if (key.equals("proxy")) {
if (settings.getString("proxy", "").equals("")) {
proxyText.setSummary(getString(R.string.proxy_summary));
} else {
proxyText.setSummary(settings.getString("proxy", ""));
}
} }
} }
...@@ -442,12 +359,56 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -442,12 +359,56 @@ public class Shadowsocks extends PreferenceActivity implements
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
EasyTracker.getInstance().activityStart(this); EasyTracker.getInstance().activityStart(this);
final SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(Shadowsocks.this);
boolean init = !settings.getBoolean("isRunning", false)
&& !settings.getBoolean("isConnecting", false);
if (init) {
if (mProgressDialog == null) {
mProgressDialog = ProgressDialog.show(this, "",
getString(R.string.initializing), true, true);
}
new Thread() {
@Override
public void run() {
Utils.isRoot();
String versionName;
try {
versionName = getPackageManager().getPackageInfo(
getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
versionName = "NONE";
}
if (!settings.getBoolean(versionName, false)) {
Editor edit = settings.edit();
edit.putBoolean(versionName, true);
edit.commit();
reset();
}
handler.sendEmptyMessage(MSG_INITIAL_FINISH);
}
}.start();
}
} }
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
EasyTracker.getInstance().activityStop(this); EasyTracker.getInstance().activityStop(this);
if (mProgressDialog != null) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
} }
public void reset() { public void reset() {
...@@ -560,4 +521,97 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -560,4 +521,97 @@ public class Shadowsocks extends PreferenceActivity implements
alert.show(); alert.show();
} }
public static class ProxyFragment extends UnifiedPreferenceFragment
implements OnSharedPreferenceChangeListener {
private void setPreferenceEnabled() {
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(getActivity());
boolean enabled = !settings.getBoolean("isRunning", false)
&& !settings.getBoolean("isConnecting", false);
for (String name : PROXY_PREFS) {
Preference pref = findPreference(name);
if (pref != null) {
pref.setEnabled(enabled);
}
}
}
@Override
public void onResume() {
super.onResume();
setPreferenceEnabled();
// Set up a listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("isRunning") || key.equals("isGlobalProxy")) {
setPreferenceEnabled();
}
}
}
public static class FeatureFragment extends UnifiedPreferenceFragment
implements OnSharedPreferenceChangeListener {
private void setPreferenceEnabled() {
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(getActivity());
boolean enabled = !settings.getBoolean("isRunning", false)
&& !settings.getBoolean("isConnecting", false);
for (String name : FEATRUE_PREFS) {
Preference pref = findPreference(name);
if (pref != null) {
if (name.equals("isBypassApps")
|| name.equals("proxyedApps")) {
boolean isGlobalProxy = settings.getBoolean("isGlobalProxy", false);
pref.setEnabled(enabled && !isGlobalProxy);
} else {
pref.setEnabled(enabled);
}
}
}
}
@Override
public void onResume() {
super.onResume();
setPreferenceEnabled();
// Set up a listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
// Unregister the listener whenever a key changes
getPreferenceScreen().getSharedPreferences()
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("isRunning") || key.equals("isGlobalProxy")) {
setPreferenceEnabled();
}
}
}
} }
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 {
private CharSequence mDefaultSummary;
public SummaryEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mDefaultSummary = getSummary();
}
public SummaryEditTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mDefaultSummary = getSummary();
}
public SummaryEditTextPreference(Context context) {
super(context);
}
@Override
public void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult) {
String value = getEditText().getText().toString();
if (value.isEmpty()) {
setSummary(mDefaultSummary);
} else {
setSummary(value);
}
}
}
}
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