mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Add swipe to refresh to device pairing activity
This makes it more conform to material design standard REVIEW: 129980
This commit is contained in:
17
res/layout/activity_refresh_list.xml
Normal file
17
res/layout/activity_refresh_list.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/refresh_list_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="16dip"
|
||||
android:paddingRight="16dip"
|
||||
tools:context=".MainActivity"
|
||||
android:id="@+id/listView1"
|
||||
android:addStatesFromChildren="true"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
@@ -9,14 +9,6 @@
|
||||
android:title="@string/refresh"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_progress"
|
||||
android:orderInCategory="200"
|
||||
android:visible="false"
|
||||
kdeconnect:showAsAction="ifRoom"
|
||||
kdeconnect:actionViewClass="android.widget.ProgressBar"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_rename"
|
||||
android:orderInCategory="300"
|
||||
|
@@ -5,16 +5,8 @@
|
||||
android:id="@+id/menu_refresh"
|
||||
android:icon="@drawable/ic_action_refresh"
|
||||
android:orderInCategory="200"
|
||||
kdeconnect:showAsAction="ifRoom"
|
||||
kdeconnect:showAsAction="never"
|
||||
android:title="@string/refresh"
|
||||
/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_progress"
|
||||
android:orderInCategory="200"
|
||||
android:visible="false"
|
||||
kdeconnect:showAsAction="ifRoom"
|
||||
kdeconnect:actionViewClass="android.widget.ProgressBar"
|
||||
/>
|
||||
|
||||
</menu>
|
||||
|
@@ -23,8 +23,9 @@ package org.kde.kdeconnect.Plugins.SharePlugin;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -32,7 +33,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -46,15 +46,14 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class ShareActivity extends ActionBarActivity {
|
||||
public class ShareActivity extends AppCompatActivity {
|
||||
|
||||
private MenuItem menuProgress;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.refresh, menu);
|
||||
menuProgress = menu.findItem(R.id.menu_progress);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -62,28 +61,7 @@ public class ShareActivity extends ActionBarActivity {
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_refresh:
|
||||
updateComputerList();
|
||||
BackgroundService.RunCommand(ShareActivity.this, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
service.onNetworkChange();
|
||||
}
|
||||
});
|
||||
item.setVisible(false);
|
||||
menuProgress.setVisible(true);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try { Thread.sleep(1500); } catch (InterruptedException e) { }
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
menuProgress.setVisible(false);
|
||||
item.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
updateComputerListAction();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -91,6 +69,30 @@ public class ShareActivity extends ActionBarActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateComputerListAction() {
|
||||
updateComputerList();
|
||||
BackgroundService.RunCommand(ShareActivity.this, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
service.onNetworkChange();
|
||||
}
|
||||
});
|
||||
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try { Thread.sleep(1500); } catch (InterruptedException ignored) { }
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void updateComputerList() {
|
||||
|
||||
final Intent intent = getIntent();
|
||||
@@ -179,7 +181,6 @@ public class ShareActivity extends ActionBarActivity {
|
||||
device.sendPackage(np);
|
||||
}
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
@@ -193,13 +194,21 @@ public class ShareActivity extends ActionBarActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_list);
|
||||
setContentView(R.layout.activity_refresh_list);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
|
||||
|
||||
setContentView(R.layout.activity_list);
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_list_layout);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(
|
||||
new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
updateComputerListAction();
|
||||
}
|
||||
}
|
||||
);
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -24,6 +24,7 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -55,10 +56,10 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
private static final int RESULT_PAIRING_SUCCESFUL = Activity.RESULT_FIRST_USER;
|
||||
|
||||
private View rootView;
|
||||
private View listRootView;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private MaterialActivity mActivity;
|
||||
|
||||
private MenuItem menuProgress;
|
||||
|
||||
boolean listRefreshCalledThisFrame = false;
|
||||
|
||||
TextView headerText;
|
||||
@@ -75,12 +76,21 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
rootView = inflater.inflate(R.layout.activity_list, container, false);
|
||||
|
||||
rootView = inflater.inflate(R.layout.activity_refresh_list, container, false);
|
||||
listRootView = rootView.findViewById(R.id.listView1);
|
||||
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_list_layout);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(
|
||||
new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
updateComputerListAction();
|
||||
}
|
||||
}
|
||||
);
|
||||
headerText = new TextView(inflater.getContext());
|
||||
headerText.setText(getString(R.string.pairing_description));
|
||||
headerText.setPadding(0, (int) (16 * getResources().getDisplayMetrics().density), 0, (int) (12 * getResources().getDisplayMetrics().density));
|
||||
((ListView) rootView).addHeaderView(headerText);
|
||||
((ListView) listRootView).addHeaderView(headerText);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
@@ -91,7 +101,30 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
mActivity = ((MaterialActivity) getActivity());
|
||||
}
|
||||
|
||||
void updateComputerList() {
|
||||
private void updateComputerListAction() {
|
||||
updateComputerList();
|
||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
service.onNetworkChange();
|
||||
}
|
||||
});
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try { Thread.sleep(1500); } catch (InterruptedException ignored) { }
|
||||
mActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void updateComputerList() {
|
||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(final BackgroundService service) {
|
||||
@@ -227,33 +260,13 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.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() {
|
||||
menuProgress.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
updateComputerListAction();
|
||||
break;
|
||||
case R.id.menu_rename:
|
||||
mActivity.renameDevice();
|
||||
|
Reference in New Issue
Block a user