mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-02-08 10:04:42 +00:00
Allow copying node ID to clipboard in Drawer and node settings (closes #53).
This commit is contained in:
parent
20d1fcf3e8
commit
3ce26dafb2
5 changed files with 53 additions and 8 deletions
|
@ -1,15 +1,21 @@
|
||||||
package com.nutomic.syncthingandroid.gui;
|
package com.nutomic.syncthingandroid.gui;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ActionBarDrawerToggle;
|
import android.support.v4.app.ActionBarDrawerToggle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
import com.nutomic.syncthingandroid.syncthing.RestApi;
|
||||||
|
@ -136,6 +142,14 @@ public class LocalNodeInfoFragment extends Fragment
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mNodeId.setText(info.myID);
|
mNodeId.setText(info.myID);
|
||||||
|
mNodeId.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||||
|
mActivity.getApi().copyNodeId(mNodeId.getText().toString());
|
||||||
|
view.performClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
mCpuUsage.setText(new DecimalFormat("0.00").format(info.cpuPercent) + "%");
|
mCpuUsage.setText(new DecimalFormat("0.00").format(info.cpuPercent) + "%");
|
||||||
mRamUsage.setText(RestApi.readableFileSize(mActivity, info.sys));
|
mRamUsage.setText(RestApi.readableFileSize(mActivity, info.sys));
|
||||||
if (info.extAnnounceOK) {
|
if (info.extAnnounceOK) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
|
|
||||||
private RestApi.Node mNode;
|
private RestApi.Node mNode;
|
||||||
|
|
||||||
private EditTextPreference mNodeId;
|
private Preference mNodeId;
|
||||||
|
|
||||||
private EditTextPreference mName;
|
private EditTextPreference mName;
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressLint("AppCompatMethod")
|
@SuppressLint("AppCompatMethod")
|
||||||
@TargetApi(11)
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
addPreferencesFromResource(R.xml.node_settings_edit);
|
addPreferencesFromResource(R.xml.node_settings_edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
mNodeId = (EditTextPreference) findPreference("node_id");
|
mNodeId = findPreference("node_id");
|
||||||
mNodeId.setOnPreferenceChangeListener(this);
|
mNodeId.setOnPreferenceChangeListener(this);
|
||||||
mName = (EditTextPreference) findPreference("name");
|
mName = (EditTextPreference) findPreference("name");
|
||||||
mName.setOnPreferenceChangeListener(this);
|
mName.setOnPreferenceChangeListener(this);
|
||||||
|
@ -117,6 +116,7 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
mNode.Name = "";
|
mNode.Name = "";
|
||||||
mNode.NodeID = "";
|
mNode.NodeID = "";
|
||||||
mNode.Addresses = "dynamic";
|
mNode.Addresses = "dynamic";
|
||||||
|
((EditTextPreference) mNodeId).setText(mNode.NodeID);
|
||||||
}
|
}
|
||||||
else if (getIntent().getAction().equals(ACTION_EDIT)) {
|
else if (getIntent().getAction().equals(ACTION_EDIT)) {
|
||||||
setTitle(R.string.edit_node);
|
setTitle(R.string.edit_node);
|
||||||
|
@ -127,10 +127,10 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mNodeId.setOnPreferenceClickListener(this);
|
||||||
}
|
}
|
||||||
mSyncthingService.getApi().getConnections(NodeSettingsActivity.this);
|
mSyncthingService.getApi().getConnections(NodeSettingsActivity.this);
|
||||||
|
|
||||||
mNodeId.setText(mNode.NodeID);
|
|
||||||
mNodeId.setSummary(mNode.NodeID);
|
mNodeId.setSummary(mNode.NodeID);
|
||||||
mName.setText((mNode.Name));
|
mName.setText((mNode.Name));
|
||||||
mName.setSummary(mNode.Name);
|
mName.setSummary(mNode.Name);
|
||||||
|
@ -224,6 +224,10 @@ public class NodeSettingsActivity extends PreferenceActivity implements
|
||||||
.show();
|
.show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (preference.equals(mNodeId)) {
|
||||||
|
mSyncthingService.getApi().copyNodeId(mNode.NodeID);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
package com.nutomic.syncthingandroid.syncthing;
|
package com.nutomic.syncthingandroid.syncthing;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nutomic.syncthingandroid.R;
|
import com.nutomic.syncthingandroid.R;
|
||||||
|
|
||||||
|
@ -729,4 +733,26 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener {
|
||||||
shareIntent, activity.getString(R.string.send_node_id_to)));
|
shareIntent, activity.getString(R.string.send_node_id_to)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the given node ID to the clipboard (and shows a Toast telling about it).
|
||||||
|
*
|
||||||
|
* @param id The node ID to copy.
|
||||||
|
*/
|
||||||
|
@TargetApi(11)
|
||||||
|
public void copyNodeId(String id) {
|
||||||
|
int sdk = android.os.Build.VERSION.SDK_INT;
|
||||||
|
if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
android.text.ClipboardManager clipboard = (android.text.ClipboardManager)
|
||||||
|
mSyncthingService.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
clipboard.setText(id);
|
||||||
|
} else {
|
||||||
|
ClipboardManager clipboard = (ClipboardManager)
|
||||||
|
mSyncthingService.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clip = ClipData.newPlainText(mSyncthingService.getString(R.string.node_id), id);
|
||||||
|
clipboard.setPrimaryClip(clip);
|
||||||
|
}
|
||||||
|
Toast.makeText(mSyncthingService, R.string.node_id_copied_to_clipboard, Toast.LENGTH_SHORT)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,6 +223,9 @@ Please report any problems you encounter.</string>
|
||||||
<!-- Text for the dismiss button of the restart Activity -->
|
<!-- Text for the dismiss button of the restart Activity -->
|
||||||
<string name="restart_later">Restart Later</string>
|
<string name="restart_later">Restart Later</string>
|
||||||
|
|
||||||
|
<!-- Shown when a node ID is copied to the clipboard -->
|
||||||
|
<string name="node_id_copied_to_clipboard">Node ID copied to clipboard</string>
|
||||||
|
|
||||||
<!-- Strings representing units for file sizes, from smallest to largest -->
|
<!-- Strings representing units for file sizes, from smallest to largest -->
|
||||||
<string-array name="file_size_units">
|
<string-array name="file_size_units">
|
||||||
<item>B</item>
|
<item>B</item>
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:persistent="false" >
|
android:persistent="false" >
|
||||||
|
|
||||||
<EditTextPreference
|
<Preference
|
||||||
android:key="node_id"
|
android:key="node_id"
|
||||||
android:title="@string/node_id"
|
android:title="@string/node_id"/>
|
||||||
android:enabled="false"
|
|
||||||
style="?android:preferenceInformationStyle" />
|
|
||||||
|
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:key="name"
|
android:key="name"
|
||||||
|
|
Loading…
Reference in a new issue