1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 03:11:30 +00:00

Changed code style to use spaces instead of tabs.

It is impossible to add a custom code style in Android Studio that is
stored in the project repository. So change style to something that's
easy to use in practice now rather than later.
This commit is contained in:
Felix Ableitner 2014-08-18 11:30:03 +02:00
parent c3b027e8b5
commit b1749ce7cb
49 changed files with 3611 additions and 3668 deletions

View file

@ -41,6 +41,6 @@ screenshots: *link to file* (only for UI problems)
Always welcome.
Code should follow the [Android Code Style Guidelines](https://source.android.com/source/code-style.html#java-language-rules), with the exception that we use tabs, not spaces for indentation.
Code should follow the [Android Code Style Guidelines](https://source.android.com/source/code-style.html#java-language-rules). This can be done automatically in Android Studio.
Lint warnings should be fixed. If that's not possible, they should be ignored as specifically as possible.

View file

@ -13,18 +13,18 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop" >
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -33,13 +33,12 @@
</activity>
<activity
android:name=".activities.WebGuiActivity"
android:label="@string/web_gui_title" >
android:label="@string/web_gui_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".gui.MainActivity" />
</activity>
<activity
android:name=".activities.SettingsActivity" >
<activity android:name=".activities.SettingsActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".gui.MainActivity" />
@ -49,25 +48,26 @@
<activity
android:name=".activities.FolderPickerActivity"
android:label="@string/folder_picker_title" >
android:label="@string/folder_picker_title">
<meta-data
android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
<receiver android:name=".syncthing.NetworkReceiver" >
<receiver android:name=".syncthing.NetworkReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<receiver android:name=".syncthing.BatteryReceiver" >
<receiver android:name=".syncthing.BatteryReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
<receiver android:name=".syncthing.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>

View file

@ -90,7 +90,8 @@ public class FolderPickerActivity extends SyncthingActivity
public void onClick(DialogInterface dialogInterface, int i) {
createFolder(et.getText().toString());
}
})
}
)
.setNegativeButton(android.R.string.cancel, null)
.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@ -174,8 +175,7 @@ public class FolderPickerActivity extends SyncthingActivity
if (!mLocation.equals(Environment.getExternalStorageDirectory())) {
mLocation = mLocation.getParentFile();
refresh();
}
else {
} else {
setResult(Activity.RESULT_CANCELED);
finish();
}

View file

@ -53,8 +53,7 @@ public class MainActivity extends SyncthingActivity
mLoadingDialog.dismiss();
}
SyncthingService.showDisabledDialog(this);
}
else if (mLoadingDialog == null) {
} else if (mLoadingDialog == null) {
final SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
@ -102,9 +101,12 @@ public class MainActivity extends SyncthingActivity
@Override
public Fragment getItem(int position) {
switch (position) {
case 0: return mRepositoriesFragment;
case 1: return mNodesFragment;
default: return null;
case 0:
return mRepositoriesFragment;
case 1:
return mNodesFragment;
default:
return null;
}
}
@ -177,8 +179,7 @@ public class MainActivity extends SyncthingActivity
mLocalNodeInfoFragment = (LocalNodeInfoFragment) fm.getFragment(
savedInstanceState, LocalNodeInfoFragment.class.getName());
mViewPager.setCurrentItem(savedInstanceState.getInt("currentTab"));
}
else {
} else {
mRepositoriesFragment = new ReposFragment();
mNodesFragment = new NodesFragment();
mLocalNodeInfoFragment = new LocalNodeInfoFragment();

View file

@ -24,7 +24,7 @@ public class SettingsActivity extends SyncthingActivity {
* Must be set for {@link #ACTION_NODE_SETTINGS_FRAGMENT} and
* {@link #ACTION_REPO_SETTINGS_FRAGMENT} to determine if an existing repo/node should be
* edited or a new one created.
*
* <p/>
* If this is false, {@link com.nutomic.syncthingandroid.fragments.RepoSettingsFragment#EXTRA_REPO_ID} or
* {@link com.nutomic.syncthingandroid.fragments.NodeSettingsFragment#EXTRA_NODE_ID} must be set (according to the selected fragment).
*/
@ -42,8 +42,7 @@ public class SettingsActivity extends SyncthingActivity {
if (savedInstanceState != null) {
mFragment = fm.getFragment(savedInstanceState,
savedInstanceState.getString("fragment_name"));
}
else {
} else {
switch (getIntent().getAction()) {
case ACTION_APP_SETTINGS_FRAGMENT:
setTitle(R.string.settings_title);

View file

@ -64,8 +64,7 @@ public class SyncthingActivity extends ActionBarActivity implements ServiceConne
public void registerOnServiceConnectedListener(OnServiceConnectedListener listener) {
if (mSyncthingService != null) {
listener.onServiceConnected();
}
else {
} else {
mServiceConnectedListeners.addLast(listener);
}
}

View file

@ -35,7 +35,7 @@ public class WebGuiActivity extends SyncthingActivity implements SyncthingServic
/**
* Initialize WebView.
*
* <p/>
* Ignore lint javascript warning as js is loaded only from our known, local service.
*/
@Override

View file

@ -66,7 +66,9 @@ public class LocalNodeInfoFragment extends Fragment
super.onDrawerOpened(drawerView);
LocalNodeInfoFragment.this.onDrawerOpened();
}
};
}
;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -143,8 +145,7 @@ public class LocalNodeInfoFragment extends Fragment
if (info.extAnnounceOK) {
mAnnounceServer.setText("Online");
mAnnounceServer.setTextColor(getResources().getColor(R.color.text_green));
}
else {
} else {
mAnnounceServer.setText("Offline");
mAnnounceServer.setTextColor(getResources().getColor(R.color.text_red));
}

View file

@ -1,6 +1,5 @@
package com.nutomic.syncthingandroid.fragments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
@ -64,8 +63,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
if (mIsCreate) {
addPreferencesFromResource(R.xml.node_settings_create);
}
else {
} else {
addPreferencesFromResource(R.xml.node_settings_edit);
}
@ -106,8 +104,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
mNode.NodeID = "";
mNode.Addresses = "dynamic";
((EditTextPreference) mNodeId).setText(mNode.NodeID);
}
else {
} else {
getActivity().setTitle(R.string.edit_node);
List<RestApi.Node> nodes = mSyncthingService.getApi().getNodes();
for (int i = 0; i < nodes.size(); i++) {
@ -192,13 +189,11 @@ public class NodeSettingsFragment extends PreferenceFragment implements
mNode.NodeID = (String) o;
nodeUpdated();
return true;
}
else if (preference.equals(mName)) {
} else if (preference.equals(mName)) {
mNode.Name = (String) o;
nodeUpdated();
return true;
}
else if (preference.equals(mAddresses)) {
} else if (preference.equals(mAddresses)) {
mNode.Addresses = (String) o;
nodeUpdated();
return true;
@ -217,7 +212,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
/**
* Sets version and current address of the node.
*
* <p/>
* NOTE: This is only called once on startup, should be called more often to properly display
* version/address changes.
*/
@ -248,8 +243,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
try {
startActivityForResult(intentScan, SCAN_QR_REQUEST_CODE);
}
catch (ActivityNotFoundException e) {
} catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(), R.string.no_qr_scanner_installed,
Toast.LENGTH_LONG).show();
}
@ -278,8 +272,7 @@ public class NodeSettingsFragment extends PreferenceFragment implements
public void onNodeIdNormalized(String normalizedId, String error) {
if (error != null) {
Toast.makeText(getActivity(), error, Toast.LENGTH_LONG).show();
}
else if (mIsCreate) {
} else if (mIsCreate) {
getActivity().finish();
}
}

View file

@ -81,8 +81,7 @@ public class NodesFragment extends ListFragment implements SyncthingService.OnAp
}
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
}
else if (mTimer != null) {
} else if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}

View file

@ -74,8 +74,7 @@ public class RepoSettingsFragment extends PreferenceFragment
if (mIsCreate) {
addPreferencesFromResource(R.xml.repo_settings_create);
}
else {
} else {
addPreferencesFromResource(R.xml.repo_settings_edit);
}
@ -110,8 +109,7 @@ public class RepoSettingsFragment extends PreferenceFragment
mRepo.Directory = "";
mRepo.Nodes = new ArrayList<RestApi.Node>();
mRepo.Versioning = new RestApi.Versioning();
}
else {
} else {
getActivity().setTitle(R.string.edit_repo);
List<RestApi.Repo> repos = mSyncthingService.getApi().getRepos();
for (int i = 0; i < repos.size(); i++) {
@ -146,8 +144,7 @@ public class RepoSettingsFragment extends PreferenceFragment
mVersioningKeep.setText(mRepo.Versioning.getParams().get("keep"));
mVersioningKeep.setSummary(mRepo.Versioning.getParams().get("keep"));
mVersioningKeep.setEnabled(true);
}
else {
} else {
mVersioningKeep.setEnabled(false);
}
}
@ -218,24 +215,20 @@ public class RepoSettingsFragment extends PreferenceFragment
mRepo.ID = (String) o;
repoUpdated();
return true;
}
else if (preference.equals(mDirectory)) {
} else if (preference.equals(mDirectory)) {
mRepo.Directory = (String) o;
repoUpdated();
return true;
}
else if (preference.equals(mRepoMaster)) {
} else if (preference.equals(mRepoMaster)) {
mRepo.ReadOnly = (Boolean) o;
repoUpdated();
return true;
}
else if (preference.getKey().equals(KEY_NODE_SHARED)) {
} else if (preference.getKey().equals(KEY_NODE_SHARED)) {
ExtendedCheckBoxPreference pref = (ExtendedCheckBoxPreference) preference;
RestApi.Node node = (RestApi.Node) pref.getObject();
if ((Boolean) o) {
mRepo.Nodes.add(node);
}
else {
} else {
for (RestApi.Node n : mRepo.Nodes) {
if (n.NodeID.equals(node.NodeID)) {
mRepo.Nodes.remove(n);
@ -244,8 +237,7 @@ public class RepoSettingsFragment extends PreferenceFragment
}
repoUpdated();
return true;
}
else if (preference.equals(mVersioning)) {
} else if (preference.equals(mVersioning)) {
mVersioningKeep.setEnabled((Boolean) o);
if ((Boolean) o) {
RestApi.SimpleVersioning v = new RestApi.SimpleVersioning();
@ -253,14 +245,12 @@ public class RepoSettingsFragment extends PreferenceFragment
v.setParams(5);
mVersioningKeep.setText("5");
mVersioningKeep.setSummary("5");
}
else {
} else {
mRepo.Versioning = new RestApi.Versioning();
}
repoUpdated();
return true;
}
else if (preference.equals(mVersioningKeep)) {
} else if (preference.equals(mVersioningKeep)) {
((RestApi.SimpleVersioning) mRepo.Versioning)
.setParams(Integer.parseInt((String) o));
repoUpdated();
@ -277,10 +267,10 @@ public class RepoSettingsFragment extends PreferenceFragment
.putExtra(FolderPickerActivity.EXTRA_INITIAL_DIRECTORY,
(mRepo.Directory.length() != 0)
? mRepo.Directory
: Environment.getExternalStorageDirectory().getAbsolutePath());
: Environment.getExternalStorageDirectory().getAbsolutePath()
);
startActivityForResult(intent, DIRECTORY_REQUEST_CODE);
}
else if (preference.equals(mNodes) && mSyncthingService.getApi().getNodes().isEmpty()) {
} else if (preference.equals(mNodes) && mSyncthingService.getApi().getNodes().isEmpty()) {
Toast.makeText(getActivity(), R.string.no_nodes, Toast.LENGTH_SHORT)
.show();
}

View file

@ -79,8 +79,7 @@ public class ReposFragment extends ListFragment implements SyncthingService.OnAp
}
}, 0, SyncthingService.GUI_UPDATE_INTERVAL);
}
else if (mTimer != null) {
} else if (mTimer != null) {
mTimer.cancel();
mTimer = null;
}

View file

@ -65,7 +65,7 @@ public class SettingsFragment extends PreferenceFragment
/**
* Applies the given value to the preference.
*
* <p/>
* If pref is an EditTextPreference, setText is used and the value shown as summary. If pref is
* a CheckBoxPreference, setChecked is used (by parsing value as Boolean).
*/
@ -73,8 +73,7 @@ public class SettingsFragment extends PreferenceFragment
if (pref instanceof EditTextPreference) {
((EditTextPreference) pref).setText(value);
pref.setSummary(value);
}
else if (pref instanceof CheckBoxPreference) {
} else if (pref instanceof CheckBoxPreference) {
((CheckBoxPreference) pref).setChecked(Boolean.parseBoolean(value));
}
}
@ -82,7 +81,7 @@ public class SettingsFragment extends PreferenceFragment
/**
* Loads layout, sets version from Rest API.
*
* <p/>
* Manual target API as we manually check if ActionBar is available (for ActionBar back button).
*/
@Override
@ -139,12 +138,10 @@ public class SettingsFragment extends PreferenceFragment
if (preference.equals(mStopNotCharging) || preference.equals(mStopMobileData)) {
mSyncthingService.updateState();
}
else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
} else if (mOptionsScreen.findPreference(preference.getKey()) != null) {
mSyncthingService.getApi().setValue(RestApi.TYPE_OPTIONS, preference.getKey(), o,
preference.getKey().equals("ListenAddress"), getActivity());
}
else if (mGuiScreen.findPreference(preference.getKey()) != null) {
} else if (mGuiScreen.findPreference(preference.getKey()) != null) {
mSyncthingService.getApi().setValue(
RestApi.TYPE_GUI, preference.getKey(), o, false, getActivity());
}

View file

@ -8,7 +8,7 @@ import android.os.BatteryManager;
/**
* Holds information about the current wifi and charging state of the device.
*
* <p/>
* This information is actively read on construction, and then updated from intents that are passed
* to {@link #update(android.content.Intent)}.
*/

View file

@ -68,14 +68,13 @@ public class GetTask extends AsyncTask<String, Void, String> {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
String result = "";
while((line = br.readLine()) != null) {
while ((line = br.readLine()) != null) {
result += line;
}
br.close();
return result;
}
}
catch (IOException e) {
} catch (IOException e) {
Log.w(TAG, "Failed to call Rest API at " + fullUri, e);
}
return null;

View file

@ -42,8 +42,7 @@ public class PostTask extends AsyncTask<String, Void, Void> {
post.setEntity(new StringEntity(params[3]));
}
httpclient.execute(post);
}
catch (IOException e) {
} catch (IOException e) {
Log.w(TAG, "Failed to call Rest API at " + fullUri, e);
}
return null;

View file

@ -80,9 +80,11 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
public static class Versioning {
protected final Map<String, String> mParams = new HashMap<>();
public String getType() {
return "";
}
public Map<String, String> getParams() {
return mParams;
}
@ -93,6 +95,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
public String getType() {
return "simple";
}
public void setParams(int keep) {
mParams.put("keep", Integer.toString(keep));
}
@ -211,8 +214,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
try {
mConfig = new JSONObject(config);
tryIsAvailable();
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to parse config", e);
}
}
@ -257,7 +259,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
/**
* Gets a value from config,
*
* <p/>
* Booleans are returned as {@link }Boolean#toString}, arrays as space seperated string.
*
* @param name {@link #TYPE_OPTIONS} or {@link #TYPE_GUI}
@ -270,8 +272,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
return (value instanceof JSONArray)
? ((JSONArray) value).join(" ").replace("\"", "")
: String.valueOf(value);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to get value for " + key, e);
return null;
}
@ -279,7 +280,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
/**
* Sets a value to config and sends it via Rest API.
*
* <p/>
* Booleans must be passed as {@link Boolean}, arrays as space seperated string
* with isArray true.
*
@ -294,8 +295,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
? listToJson(((String) value).split(" "))
: value);
configUpdated(activity);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to set value for " + key, e);
}
}
@ -380,8 +380,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
try {
return getNodes(mConfig.getJSONArray("Nodes"));
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to read nodes", e);
return new ArrayList<Node>();
}
@ -416,8 +415,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
si.myID = system.getString("myID");
si.sys = system.getLong("sys");
listener.onReceiveSystemInfo(si);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to read system info", e);
}
}
@ -462,17 +460,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
r.Directory = json.getString("Directory");
r.ID = json.getString("ID");
r.Invalid = json.getString("Invalid");
r.Nodes = new ArrayList<Node>();
JSONArray nodes = json.getJSONArray("Nodes");
for (int j = 0; j < nodes.length(); j++) {
JSONObject n = nodes.getJSONObject(j);
String id = n.getString("NodeID");
for (Node n2 : getNodes()) {
if (n2.NodeID.equals(id)) {
r.Nodes.add(n2);
}
}
}
r.Nodes = getNodes(json.getJSONArray("Nodes"));
r.ReadOnly = json.getBoolean("ReadOnly");
JSONObject versioning = json.getJSONObject("Versioning");
@ -481,15 +469,13 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
JSONObject params = versioning.getJSONObject("Params");
sv.setParams(params.getInt("keep"));
r.Versioning = sv;
}
else {
} else {
r.Versioning = new Versioning();
}
ret.add(r);
}
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to read nodes", e);
}
return ret;
@ -501,9 +487,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
public static String readableFileSize(Context context, long bytes) {
final String[] units = context.getResources().getStringArray(R.array.file_size_units);
if (bytes <= 0) return "0 " + units[0];
int digitGroups = (int) (Math.log10(bytes)/Math.log10(1024));
int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024));
return new DecimalFormat("#,##0.#")
.format(bytes/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
.format(bytes / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
/**
@ -512,9 +498,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
public static String readableTransferRate(Context context, long bits) {
final String[] units = context.getResources().getStringArray(R.array.transfer_rate_units);
if (bits <= 0) return "0 " + units[0];
int digitGroups = (int) (Math.log10(bits)/Math.log10(1024));
int digitGroups = (int) (Math.log10(bits) / Math.log10(1024));
return new DecimalFormat("#,##0.#")
.format(bits/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
.format(bits / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
/**
@ -524,7 +510,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
/**
* @param connections Map from Node ID to {@link Connection}.
*
* <p/>
* NOTE: The parameter connections is cached internally. Do not modify it or
* any of its contents.
*/
@ -533,7 +519,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
/**
* Returns connection info for the local node and all connected nodes.
*
* <p/>
* Use the key {@link #LOCAL_NODE_CONNECTIONS} to get connection info for the local node.
*/
public void getConnections(final OnReceiveConnectionsListener listener) {
@ -581,8 +567,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
}
mPreviousConnections = connections;
listener.onReceiveConnections(mPreviousConnections);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to parse connections", e);
}
}
@ -656,8 +641,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
m.invalid = json.optString("invalid");
mCachedModelInfo.put(repoId, m);
listener.onReceiveModel(repoId, m);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to read repository info", e);
}
}
@ -695,8 +679,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
if (create) {
n = new JSONObject();
nodes.put(n);
}
else {
} else {
for (int i = 0; i < nodes.length(); i++) {
JSONObject json = nodes.getJSONObject(i);
if (node.NodeID.equals(json.getString("NodeID"))) {
@ -709,12 +692,12 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
n.put("Name", node.Name);
n.put("Addresses", listToJson(node.Addresses.split(" ")));
configUpdated(mSyncthingService);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to read nodes", e);
}
}
});
}
);
}
/**
@ -733,8 +716,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
}
}
configUpdated(activity);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to edit repo", e);
}
}
@ -749,8 +731,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
if (create) {
r = new JSONObject();
repos.put(r);
}
else {
} else {
for (int i = 0; i < repos.length(); i++) {
JSONObject json = repos.getJSONObject(i);
if (repo.ID.equals(json.getString("ID"))) {
@ -781,8 +762,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
}
r.put("Versioning", versioning);
configUpdated(context);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to edit repo " + repo.ID + " at " + repo.Directory, e);
}
}
@ -803,8 +783,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
}
}
configUpdated(activity);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.w(TAG, "Failed to edit repo", e);
}
}
@ -849,8 +828,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
JSONObject json = new JSONObject(s);
normalized = json.optString("id", null);
error = json.optString("error", null);
}
catch (JSONException e) {
} catch (JSONException e) {
Log.d(TAG, "Failed to parse normalized node ID JSON", e);
}
listener.onNodeIdNormalized(normalized, error);
@ -878,7 +856,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
@TargetApi(11)
public void copyNodeId(String id) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)
mSyncthingService.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(id);

View file

@ -57,15 +57,12 @@ public class SyncthingRunnable implements Runnable {
log(process.getInputStream());
ret = process.waitFor();
}
catch(IOException | InterruptedException e) {
} catch (IOException | InterruptedException e) {
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
}
finally {
} finally {
try {
dos.close();
}
catch (IOException e) {
} catch (IOException e) {
Log.w(TAG, "Failed to close shell stream", e);
}
process.destroy();
@ -95,7 +92,8 @@ public class SyncthingRunnable implements Runnable {
int i) {
System.exit(0);
}
})
}
)
.create();
dialog.getWindow()
.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
@ -120,8 +118,7 @@ public class SyncthingRunnable implements Runnable {
while ((line = br.readLine()) != null) {
Log.i(TAG_NATIVE, line);
}
}
catch (IOException e) {
} catch (IOException e) {
// NOTE: This is sometimes called on shutdown, as
// Process.destroy() closes the stream.
Log.w(TAG, "Failed to read syncthing command line output", e);

View file

@ -123,8 +123,7 @@ public class SyncthingService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
// Just catch the empty intent and return.
if (intent == null) {
}
else if (ACTION_RESTART.equals(intent.getAction()) && mCurrentState == State.ACTIVE) {
} else if (ACTION_RESTART.equals(intent.getAction()) && mCurrentState == State.ACTIVE) {
new PostTask() {
@Override
protected void onPostExecute(Void aVoid) {
@ -136,8 +135,7 @@ public class SyncthingService extends Service {
new PollWebGuiAvailableTask().execute();
}
}.execute(mApi.getUrl(), PostTask.URI_RESTART, mApi.getApiKey());
}
else if (mCurrentState != State.INIT) {
} else if (mCurrentState != State.INIT) {
mDeviceStateHolder.update(intent);
updateState();
}
@ -147,7 +145,7 @@ public class SyncthingService extends Service {
/**
* Checks according to preferences and charging/wifi state, whether syncthing should be enabled
* or not.
*
* <p/>
* Depending on the result, syncthing is started or stopped, and {@link #onApiChange()} is
* called.
*/
@ -203,18 +201,15 @@ public class SyncthingService extends Service {
// NOTE: status is not really needed, as HttpHostConnectException is thrown
// earlier.
status = response.getStatusLine().getStatusCode();
}
catch (HttpHostConnectException e) {
} catch (HttpHostConnectException e) {
// We catch this in every call, as long as the service is not online,
// so we ignore and continue.
}
catch (IOException e) {
} catch (IOException e) {
Log.w(TAG, "Failed to poll for web interface", e);
} catch (InterruptedException e) {
Log.w(TAG, "Failed to poll for web interface", e);
}
catch (InterruptedException e) {
Log.w(TAG, "Failed to poll for web interface", e);
}
} while(status != HttpStatus.SC_OK);
} while (status != HttpStatus.SC_OK);
return null;
}
@ -238,7 +233,7 @@ public class SyncthingService extends Service {
/**
* Move config file, keys, and index files to "official" folder
*
* <p/>
* Intended to bring the file locations in older installs in line with
* newer versions.
*/
@ -340,22 +335,21 @@ public class SyncthingService extends Service {
/**
* Register a listener for the web gui becoming available..
*
* <p/>
* If the web gui is already available, listener will be called immediately.
* Listeners are unregistered automatically after being called.
*/
public void registerOnWebGuiAvailableListener(OnWebGuiAvailableListener listener) {
if (mCurrentState == State.ACTIVE) {
listener.onWebGuiAvailable();
}
else {
} else {
mOnWebGuiAvailableListeners.add(listener);
}
}
/**
* Returns true if this service has not been started before (ie config.xml does not exist).
*
* <p/>
* This will return true until the public key file has been generated.
*/
public boolean isFirstStart() {
@ -368,7 +362,7 @@ public class SyncthingService extends Service {
/**
* Register a listener for the syncthing API state changing.
*
* <p/>
* The listener is called immediately with the current state, and again whenever the state
* changes.
*/
@ -381,7 +375,7 @@ public class SyncthingService extends Service {
/**
* Called to notifiy listeners of an API change.
*
* <p/>
* Must only be called from SyncthingService or {@link RestApi}.
*/
public void onApiChange() {
@ -390,8 +384,7 @@ public class SyncthingService extends Service {
WeakReference<OnApiChangeListener> listener = i.next();
if (listener.get() != null) {
listener.get().onApiChange(mCurrentState);
}
else {
} else {
i.remove();
}
}
@ -414,7 +407,8 @@ public class SyncthingService extends Service {
.setAction(SettingsActivity.ACTION_APP_SETTINGS_FRAGMENT);
activity.startActivity(intent);
}
})
}
)
.setNegativeButton(R.string.exit,
new DialogInterface.OnClickListener() {
@Override

View file

@ -28,7 +28,7 @@ import javax.xml.transform.stream.StreamResult;
/**
* Provides direct access to the config.xml file in the file system.
*
* <p/>
* This class should only be used if the syncthing API is not available (usually during startup).
*/
public class ConfigXml {
@ -67,10 +67,10 @@ public class ConfigXml {
/**
* Updates the config file.
*
* <p/>
* Coming from 0.2.0 and earlier, globalAnnounceServer value "announce.syncthing.net:22025" is
* replaced with "194.126.249.5:22025" (as domain resolve is broken).
*
* <p/>
* Coming from 0.3.0 and earlier, the ignorePerms flag is set to true on every repository.
*/
@SuppressWarnings("SdCardPath")
@ -172,8 +172,7 @@ public class ConfigXml {
DOMSource domSource = new DOMSource(mConfig);
StreamResult streamResult = new StreamResult(mConfigFile);
transformer.transform(domSource, streamResult);
}
catch (TransformerException e) {
} catch (TransformerException e) {
Log.w(TAG, "Failed to save updated config", e);
}
}
@ -193,16 +192,13 @@ public class ConfigXml {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
}
catch (IOException e) {
} catch (IOException e) {
throw new RuntimeException("Failed to write config file", e);
}
finally {
} finally {
try {
in.close();
out.close();
}
catch (IOException e) {
} catch (IOException e) {
Log.w(TAG, "Failed to close stream while copying config", e);
}
}

View file

@ -51,15 +51,13 @@ public class NodesAdapter extends ArrayAdapter<RestApi.Node>
if (conn.Completion == 100) {
status.setText(res.getString(R.string.node_up_to_date));
status.setTextColor(res.getColor(R.color.text_green));
}
else {
} else {
status.setText(res.getString(R.string.node_syncing, conn.Completion));
status.setTextColor(res.getColor(R.color.text_blue));
}
download.setText(RestApi.readableTransferRate(getContext(), conn.InBits));
upload.setText(RestApi.readableTransferRate(getContext(), conn.OutBits));
}
else {
} else {
download.setText("0 " + res.getStringArray(R.array.transfer_rate_units)[0]);
upload.setText("0 " + res.getStringArray(R.array.transfer_rate_units)[0]);
status.setText(res.getString(R.string.node_disconnected));
@ -83,7 +81,7 @@ public class NodesAdapter extends ArrayAdapter<RestApi.Node>
*/
public void updateConnections(RestApi api, ListView listView) {
for (int i = 0; i < getCount(); i++) {
if ( i >= listView.getFirstVisiblePosition() &&
if (i >= listView.getFirstVisiblePosition() &&
i <= listView.getLastVisiblePosition()) {
api.getConnections(this);
}

View file

@ -50,15 +50,15 @@ public class ReposAdapter extends ArrayAdapter<RestApi.Repo>
state.setText(getContext().getString(R.string.repo_progress_format, model.state,
(model.globalBytes <= 0)
? 100
: (int) ((model.localBytes / (float) model.globalBytes) * 100)));
: (int) ((model.localBytes / (float) model.globalBytes) * 100)
));
items.setText(getContext()
.getString(R.string.files, model.localFiles, model.globalFiles));
size.setText(RestApi.readableFileSize(getContext(), model.localBytes) + " / " +
RestApi.readableFileSize(getContext(), model.globalBytes));
invalid.setText(model.invalid);
invalid.setVisibility((model.invalid.equals("")) ? View.GONE : View.VISIBLE);
}
else {
} else {
invalid.setVisibility(View.GONE);
}
@ -79,7 +79,7 @@ public class ReposAdapter extends ArrayAdapter<RestApi.Repo>
*/
public void updateModel(RestApi api, ListView listView) {
for (int i = 0; i < getCount(); i++) {
if ( i >= listView.getFirstVisiblePosition() &&
if (i >= listView.getFirstVisiblePosition() &&
i <= listView.getLastVisiblePosition()) {
api.getModel(getItem(i).ID, this);
}

View file

@ -1,6 +1,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
@ -12,6 +12,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/directory_empty"
android:layout_centerInParent="true"/>
android:layout_centerInParent="true" />
</RelativeLayout>

View file

@ -4,7 +4,7 @@
android:layout_gravity="center"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<ProgressBar
style="?android:attr/progressBarStyleLarge"

View file

@ -4,16 +4,17 @@
android:orientation="vertical"
android:padding="10dip"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/node_id_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
<TextView
android:id="@+id/node_id"
@ -26,7 +27,8 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<TextView
android:id="@+id/cpu_usage_title"
android:text="@string/cpu_usage"
@ -44,7 +46,8 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<TextView
android:id="@+id/ram_usage_title"
android:text="@string/ram_usage"
@ -62,7 +65,8 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<TextView
android:id="@+id/download_title"
android:text="@string/download_title"
@ -80,7 +84,8 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<TextView
android:id="@+id/upload_title"
android:text="@string/upload_title"
@ -98,7 +103,8 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<TextView
android:id="@+id/announce_server_title"
android:text="@string/announce_server"

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

View file

@ -3,7 +3,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip" >
android:padding="4dip">
<TextView
android:id="@+id/name"
@ -21,8 +21,7 @@
android:layout_alignBottom="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end" />
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/download_title"
@ -55,5 +54,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
>>>>>>> Changed code style to use spaces instead of tabs.
</RelativeLayout>

View file

@ -3,7 +3,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip" >
android:padding="4dip">
<TextView
android:id="@+id/id"

View file

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
@ -15,7 +14,7 @@
android:id="@+id/loading"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progress"

View file

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/select"

View file

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/share_node_id"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/create"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/create"

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar" />
</resources>

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@style/Theme.AppCompat" />
</resources>

View file

@ -14,7 +14,7 @@
<PreferenceScreen
android:key="syncthing_options"
android:title="Syncthing Options"
android:persistent="false" >
android:persistent="false">
<EditTextPreference
android:key="ListenAddress"
@ -68,7 +68,7 @@
<PreferenceScreen
android:key="syncthing_gui"
android:title="Syncthing GUI"
android:persistent="false" >
android:persistent="false">
<EditTextPreference
android:key="Address"
@ -92,7 +92,7 @@
<Preference
android:title="@string/report_issue_title"
android:summary="@string/report_issue_summary" >
android:summary="@string/report_issue_summary">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/issue_tracker_url" />

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:persistent="false" >
android:persistent="false">
<EditTextPreference
android:key="node_id"

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:persistent="false" >
android:persistent="false">
<Preference
android:key="node_id"
android:title="@string/node_id"/>
android:title="@string/node_id" />
<EditTextPreference
android:key="name"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:persistent="false" >
android:persistent="false">
<EditTextPreference
android:key="repo_id"

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:persistent="false" >
android:persistent="false">
<EditTextPreference
android:key="repo_id"