mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +00:00
Implemented the context menu for PairingFragment
This commit is contained in:
@@ -30,7 +30,6 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/add_host"
|
||||
android:onClick="addNewIp"
|
||||
android:id="@android:id/button1"/>
|
||||
|
||||
|
||||
|
@@ -5,8 +5,8 @@
|
||||
android:id="@+id/menu_refresh"
|
||||
android:icon="@drawable/ic_action_refresh"
|
||||
android:orderInCategory="200"
|
||||
kdeconnect:showAsAction="ifRoom"
|
||||
android:title="@string/reconnect"
|
||||
kdeconnect:showAsAction="never"
|
||||
android:title="@string/refresh"
|
||||
/>
|
||||
|
||||
<item
|
||||
@@ -18,16 +18,14 @@
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_settings"
|
||||
android:icon="@drawable/ic_action_settings"
|
||||
android:id="@+id/menu_rename"
|
||||
android:orderInCategory="300"
|
||||
android:title="@string/settings"
|
||||
android:title="@string/device_rename_title"
|
||||
kdeconnect:showAsAction="never"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_custom_device_list"
|
||||
android:icon="@drawable/ic_action_settings"
|
||||
android:orderInCategory="900"
|
||||
android:title="@string/custom_device_list"
|
||||
kdeconnect:showAsAction="never"
|
||||
|
@@ -146,9 +146,10 @@
|
||||
<string name="send_files">Send files</string>
|
||||
|
||||
<string name="pairing_title">KDE Connect Devices</string>
|
||||
<string name="pairing_description">"Other devices running KDE Connect in your same network should appear here</string>
|
||||
<string name="pairing_description">Other devices running KDE Connect in your same network should appear here.</string>
|
||||
<string name="device_paired">Device paired</string>
|
||||
<string name="device_rename_title">Rename device</string>
|
||||
<string name="device_rename_confirm">Rename</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -64,32 +64,13 @@ public class MaterialActivity extends AppCompatActivity {
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
|
||||
|
||||
String deviceName = DeviceHelper.getDeviceName(this);
|
||||
final TextView nameView = (TextView) mDrawerLayout.findViewById(R.id.device_name);
|
||||
TextView nameView = (TextView) mDrawerLayout.findViewById(R.id.device_name);
|
||||
nameView.setText(deviceName);
|
||||
|
||||
nameView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final EditText deviceNameEdit = new EditText(MaterialActivity.this);
|
||||
String deviceName = DeviceHelper.getDeviceName(MaterialActivity.this);
|
||||
deviceNameEdit.setText(deviceName);
|
||||
new AlertDialog.Builder(MaterialActivity.this)
|
||||
.setView(deviceNameEdit)
|
||||
.setPositiveButton(R.string.device_rename_confirm, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String deviceName = deviceNameEdit.getText().toString();
|
||||
DeviceHelper.setDeviceName(MaterialActivity.this, deviceName);
|
||||
nameView.setText(deviceName);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.device_rename_title)
|
||||
.show();
|
||||
renameDevice();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -263,6 +244,29 @@ public class MaterialActivity extends AppCompatActivity {
|
||||
default:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
void renameDevice() {
|
||||
final TextView nameView = (TextView) mDrawerLayout.findViewById(R.id.device_name);
|
||||
final EditText deviceNameEdit = new EditText(MaterialActivity.this);
|
||||
String deviceName = DeviceHelper.getDeviceName(MaterialActivity.this);
|
||||
deviceNameEdit.setText(deviceName);
|
||||
new AlertDialog.Builder(MaterialActivity.this)
|
||||
.setView(deviceNameEdit)
|
||||
.setPositiveButton(R.string.device_rename_confirm, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String deviceName = deviceNameEdit.getText().toString();
|
||||
DeviceHelper.setDeviceName(MaterialActivity.this, deviceName);
|
||||
nameView.setText(deviceName);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.setTitle(R.string.device_rename_title)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
@@ -51,19 +51,20 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
|
||||
private static final int RESULT_PAIRING_SUCCESFUL = Activity.RESULT_FIRST_USER;
|
||||
|
||||
/**
|
||||
* The fragment argument representing the section number for this
|
||||
* fragment.
|
||||
*/
|
||||
private View rootView;
|
||||
private MaterialActivity mActivity;
|
||||
|
||||
private MenuItem menuProgress;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
mActivity.getSupportActionBar().setTitle(R.string.pairing_title);
|
||||
|
||||
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
rootView = inflater.inflate(R.layout.activity_main, container, false);
|
||||
|
||||
TextView text = new TextView(inflater.getContext());
|
||||
@@ -181,4 +182,49 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.new_pairing, menu);
|
||||
menuProgress = menu.findItem(R.id.menu_progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_refresh:
|
||||
updateComputerList();
|
||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
service.onNetworkChange();
|
||||
}
|
||||
});
|
||||
menuProgress.setVisible(true);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try { Thread.sleep(1500); } catch (InterruptedException e) { }
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
item.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
break;
|
||||
case R.id.menu_rename:
|
||||
mActivity.renameDevice();
|
||||
break;
|
||||
case R.id.menu_custom_device_list:
|
||||
startActivity(new Intent(mActivity, CustomDevicesActivity.class));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -21,16 +21,17 @@
|
||||
package org.kde.kdeconnect.UserInterface;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
@@ -40,12 +41,14 @@ import org.kde.kdeconnect_tp.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CustomDevicesActivity extends ListActivity {
|
||||
public class CustomDevicesActivity extends ActionBarActivity {
|
||||
|
||||
private static final String LOG_ID = "CustomDevicesActivity";
|
||||
public static final String KEY_CUSTOM_DEVLIST_PREFERENCE = "device_list_preference";
|
||||
private static final String IP_DELIM = ",";
|
||||
|
||||
private ListView list;
|
||||
|
||||
private ArrayList<String> ipAddressList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
@@ -53,14 +56,24 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
initializeDeviceList(this);
|
||||
setContentView(R.layout.custom_ip_list);
|
||||
setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList));
|
||||
|
||||
list = (ListView)findViewById(android.R.id.list);
|
||||
list.setOnItemClickListener(onClickListener);
|
||||
|
||||
list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList));
|
||||
|
||||
findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
addNewDevice();
|
||||
}
|
||||
});
|
||||
|
||||
EditText ipEntryBox = (EditText)findViewById(R.id.ip_edittext);
|
||||
ipEntryBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
addNewIp();
|
||||
addNewDevice();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -68,8 +81,9 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, final int position, final long id) {
|
||||
public void onItemClick(AdapterView<?> parent, View view, final int position, final long id) {
|
||||
Log.i(LOG_ID, "Item clicked pos: " + position + " id: " + id);
|
||||
// remove touched item after confirmation
|
||||
DialogInterface.OnClickListener confirmationListener = new DialogInterface.OnClickListener() {
|
||||
@@ -86,18 +100,19 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
}
|
||||
}
|
||||
};
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this);
|
||||
builder.setMessage("Delete " + ipAddressList.get(position) + " ?");
|
||||
builder.setPositiveButton("Yes", confirmationListener);
|
||||
builder.setNegativeButton("No", confirmationListener);
|
||||
builder.show();
|
||||
((ArrayAdapter)getListAdapter()).notifyDataSetChanged();
|
||||
((ArrayAdapter) list.getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
|
||||
private void addNewIp() {
|
||||
private void addNewDevice() {
|
||||
EditText ipEntryBox = (EditText)findViewById(R.id.ip_edittext);
|
||||
String enteredText = ipEntryBox.getText().toString().trim();
|
||||
if (!enteredText.equals("")) {
|
||||
if (!enteredText.isEmpty()) {
|
||||
// don't add empty string (after trimming)
|
||||
ipAddressList.add(enteredText);
|
||||
}
|
||||
@@ -121,9 +136,9 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
if (!ipAddressList.isEmpty()) {
|
||||
serialized = serializeIpList(ipAddressList);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().putString(
|
||||
PreferenceManager.getDefaultSharedPreferences(CustomDevicesActivity.this).edit().putString(
|
||||
KEY_CUSTOM_DEVLIST_PREFERENCE, serialized).commit();
|
||||
((ArrayAdapter)getListAdapter()).notifyDataSetChanged();
|
||||
((ArrayAdapter)list.getAdapter()).notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
@@ -150,8 +165,7 @@ public class CustomDevicesActivity extends ListActivity {
|
||||
|
||||
private void initializeDeviceList(Context context){
|
||||
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(
|
||||
KEY_CUSTOM_DEVLIST_PREFERENCE,
|
||||
"");
|
||||
KEY_CUSTOM_DEVLIST_PREFERENCE, "");
|
||||
if(deviceListPrefs.isEmpty()){
|
||||
Log.i(LOG_ID, "Initialising empty custom device list");
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
|
||||
|
Reference in New Issue
Block a user