Skip to content

Commit

Permalink
Fix typo and reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Sep 16, 2019
1 parent 0b5bcd2 commit 5f4de7f
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 423 deletions.
24 changes: 9 additions & 15 deletions app/src/main/java/com/github/shadowsocks/BaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,23 @@
@SuppressLint("Registered")
public abstract class BaseService extends Service {

public static final String protectPath = ShadowsocksApplication.app.getApplicationInfo().dataDir + "/protect_path";
private static final String TAG = BaseService.class.getSimpleName();

private int state = Constants.State.STOPPED;
private static final Handler handler = new Handler(Looper.getMainLooper());
private final RemoteCallbackList<IShadowsocksServiceCallback> callbacks;
protected Profile profile;

private int state = Constants.State.STOPPED;
private Timer timer;
private TrafficMonitorThread trafficMonitorThread;

private final RemoteCallbackList<IShadowsocksServiceCallback> callbacks;
private int callbacksCount;
private static final Handler handler = new Handler(Looper.getMainLooper());
public static final String protectPath = ShadowsocksApplication.app.getApplicationInfo().dataDir + "/protect_path";

public BaseService() {
callbacks = new RemoteCallbackList<>();
}

private boolean closeReceiverRegistered;
private BroadcastReceiver closeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ToastUtils.showShort(R.string.stopping);
stopRunner(true);
}
};

private boolean closeReceiverRegistered;

public IShadowsocksService.Stub binder = new IShadowsocksService.Stub() {
@Override
public int getState() {
Expand Down Expand Up @@ -196,6 +186,10 @@ public void useSync(int profileId) {
}
};

public BaseService() {
callbacks = new RemoteCallbackList<>();
}

private boolean checkProfile(Profile profile) {
if (TextUtils.isEmpty(profile.host) || TextUtils.isEmpty(profile.password)) {
stopRunner(true, getString(R.string.proxy_empty));
Expand Down
22 changes: 8 additions & 14 deletions app/src/main/java/com/github/shadowsocks/BaseVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,23 @@
@SuppressLint("Registered")
public abstract class BaseVpnService extends VpnService {

public static final String protectPath = ShadowsocksApplication.app.getApplicationInfo().dataDir + "/protect_path";
private static final String TAG = BaseVpnService.class.getSimpleName();

private int state = Constants.State.STOPPED;
private final RemoteCallbackList<IShadowsocksServiceCallback> callbacks;
protected Profile profile;

private int state = Constants.State.STOPPED;
private Timer timer;
private TrafficMonitorThread trafficMonitorThread;

private final RemoteCallbackList<IShadowsocksServiceCallback> callbacks;
private int callbacksCount;
private Handler handler = new Handler(Looper.getMainLooper());
public static final String protectPath = ShadowsocksApplication.app.getApplicationInfo().dataDir + "/protect_path";

public BaseVpnService() {
callbacks = new RemoteCallbackList<>();
}

private boolean closeReceiverRegistered;
private BroadcastReceiver closeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ToastUtils.showShort(R.string.stopping);
stopRunner(true);
}
};

private boolean closeReceiverRegistered;

public IShadowsocksService.Stub binder = new IShadowsocksService.Stub() {
@Override
public int getState() {
Expand Down Expand Up @@ -200,6 +190,10 @@ public void useSync(int profileId) {
}
};

public BaseVpnService() {
callbacks = new RemoteCallbackList<>();
}

private boolean checkProfile(Profile profile) {
if (TextUtils.isEmpty(profile.host) || TextUtils.isEmpty(profile.password)) {
stopRunner(true, getString(R.string.proxy_empty));
Expand Down
101 changes: 49 additions & 52 deletions app/src/main/java/com/github/shadowsocks/ProfileManagerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@

import net.glxn.qrgen.android.QRCode;

import org.jetbrains.annotations.NotNull;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -113,6 +115,50 @@ public class ProfileManagerActivity extends AppCompatActivity implements View.On
private boolean is_sort = false;

private ServiceBoundContext mServiceBoundContext;
/**
* progress handler
*/
private Handler mProgressHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_FULL_TEST_FINISH:
if (testProgressDialog != null) {
testProgressDialog.dismiss();
testProgressDialog = null;
}

finish();
startActivity(new Intent(getIntent()));
break;
default:
break;
}
}
};

/**
* use string divider list value
*
* @param list list
* @param divider divider string
* @return list is empty, return null.
*/
public static String makeString(List<Profile> list, String divider) {
if (list == null || list.isEmpty()) {
return null;
}

StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
Profile item = list.get(i);
if (i > 0) {
sb.append(divider);
}
sb.append(item);
}
return sb.toString();
}

@Override
protected void attachBaseContext(Context newBase) {
Expand Down Expand Up @@ -204,7 +250,6 @@ public void trafficUpdated(long txRate, long rxRate, long txTotal, long rxTotal)
}
}


private void initGroupSpinner() {
Spinner spinner = findViewById(R.id.group_choose_spinner);
List<String> groups_name = ShadowsocksApplication.app.profileManager.getGroupNames();
Expand All @@ -225,7 +270,6 @@ public void onNothingSelected(AdapterView<?> parent) {
});
}


/**
* init toolbar
*/
Expand Down Expand Up @@ -325,7 +369,6 @@ public void qrcodeScan() {
}
}


@Override
public void onClick(View v) {
switch (v.getId()) {
Expand Down Expand Up @@ -779,28 +822,6 @@ public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
return new NdefMessage(new NdefRecord[]{new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI, nfcShareItem, new byte[]{}, nfcShareItem)});
}

/**
* progress handler
*/
private Handler mProgressHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_FULL_TEST_FINISH:
if (testProgressDialog != null) {
testProgressDialog.dismiss();
testProgressDialog = null;
}

finish();
startActivity(new Intent(getIntent()));
break;
default:
break;
}
}
};

@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
Expand Down Expand Up @@ -940,30 +961,6 @@ public void onFinished(Profile profile) {

}


/**
* use string divider list value
*
* @param list list
* @param divider divider string
* @return list is empty, return null.
*/
public static String makeString(List<Profile> list, String divider) {
if (list == null || list.isEmpty()) {
return null;
}

StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
Profile item = list.get(i);
if (i > 0) {
sb.append(divider);
}
sb.append(item);
}
return sb.toString();
}

private class ProfileViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnKeyListener {

private Profile item;
Expand Down Expand Up @@ -1041,7 +1038,7 @@ private void initPingBtn() {
final ProgressDialog singleTestProgressDialog = ProgressDialog.show(ProfileManagerActivity.this, getString(R.string.tips_testing), getString(R.string.tips_testing), false, true);
PingHelper.Companion.instance().ping(ProfileManagerActivity.this, item, new PingCallback() {
@Override
public void onSuccess(Profile profile, long elapsed) {
public void onSuccess(@NotNull Profile profile, long elapsed) {
if (profile.elapsed == 0) {
profile.elapsed = elapsed;
} else if (profile.elapsed > elapsed) {
Expand Down Expand Up @@ -1084,9 +1081,9 @@ private void initTcpPingBtn() {
pingBtn.setOnClickListener(v -> {
item.elapsed = 0;
final ProgressDialog singleTestProgressDialog = ProgressDialog.show(ProfileManagerActivity.this, getString(R.string.tips_testing), getString(R.string.tips_testing), false, true);
PingHelper.Companion.instance().tcp_ping(ProfileManagerActivity.this, item, new PingCallback() {
PingHelper.Companion.instance().tcpPing(ProfileManagerActivity.this, item, new PingCallback() {
@Override
public void onSuccess(Profile profile, long tcpdelay) {
public void onSuccess(@NotNull Profile profile, long tcpdelay) {
if (profile.tcpdelay == 0) {
profile.tcpdelay = tcpdelay;
} else if (profile.tcpdelay > tcpdelay) {
Expand Down
50 changes: 24 additions & 26 deletions app/src/main/java/com/github/shadowsocks/ServiceBoundContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@
public class ServiceBoundContext extends ContextWrapper implements IBinder.DeathRecipient {

private static final String TAG = ServiceBoundContext.class.getSimpleName();

private IBinder binder;
protected IShadowsocksService bgService;

private IBinder binder;
private IShadowsocksServiceCallback callback;
private ShadowsocksServiceConnection connection;
private boolean callbackRegistered;
Expand All @@ -69,29 +67,6 @@ public ServiceBoundContext(Context base) {
super(base);
}

public class ShadowsocksServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
binder = service;
service.linkToDeath(ServiceBoundContext.this, 0);
bgService = IShadowsocksService.Stub.asInterface(service);
registerCallback();
ServiceBoundContext.this.onServiceConnected();
} catch (RemoteException e) {
VayLog.e(TAG, "onServiceConnected", e);
}
}

@Override
public void onServiceDisconnected(ComponentName name) {
unregisterCallback();
ServiceBoundContext.this.onServiceDisconnected();
bgService = null;
binder = null;
}
}

/**
* register callback
*/
Expand Down Expand Up @@ -170,4 +145,27 @@ public void detachService() {

bgService = null;
}

public class ShadowsocksServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
try {
binder = service;
service.linkToDeath(ServiceBoundContext.this, 0);
bgService = IShadowsocksService.Stub.asInterface(service);
registerCallback();
ServiceBoundContext.this.onServiceConnected();
} catch (RemoteException e) {
VayLog.e(TAG, "onServiceConnected", e);
}
}

@Override
public void onServiceDisconnected(ComponentName name) {
unregisterCallback();
ServiceBoundContext.this.onServiceDisconnected();
bgService = null;
binder = null;
}
}
}
Loading

0 comments on commit 5f4de7f

Please sign in to comment.