WIP: More work on UI for initial swap screen.

This commit is contained in:
Peter Serwylo 2015-06-21 10:05:38 +10:00
parent 4a8ff47fce
commit a48deb9160
10 changed files with 258 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

View File

@ -1,23 +1,174 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<org.fdroid.fdroid.views.swap.StartSwapView <org.fdroid.fdroid.views.swap.StartSwapView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="120dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_info_white"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:padding="20dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:textAlignment="center"
tools:text="Connect and trade apps with people near you."
android:textSize="18sp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/bluetooth_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:weightSum="1">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
tools:src="@drawable/ic_bluetooth_white" />
<TextView
android:paddingStart="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Visible via Bluetooth"
android:textSize="18sp" />
<TextView
android:id="@+id/device_id_bluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="SP-120"
android:layout_weight="1.00"
android:paddingStart="10dp"
android:paddingEnd="10dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch_bluetooth" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:weightSum="1">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
tools:src="@drawable/ic_network_wifi_white" />
<LinearLayout
android:paddingStart="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Not visible via WiFi"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="wifi network name"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Device Name"
android:layout_weight="1.00"
android:paddingStart="10dp"
android:paddingEnd="10dp" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch_wifi" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="15dp"
android:paddingEnd="15dp"
android:paddingBottom="15dp"
android:paddingTop="35dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="People Nearby"
android:layout_weight="1.00"/>
<ProgressBar
android:layout_width="24dp"
android:layout_height="24dp"
android:indeterminate="true" />
</LinearLayout>
<TextView <TextView
android:id="@+id/text_description" android:layout_width="wrap_content"
android:text="@string/swap_introduction" android:layout_height="wrap_content"
style="@style/SwapTheme.StartSwap.MainText" tools:text="Can't find who you're looking for?" />
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button <LinearLayout
android:id="@+id/button_start_swap" android:orientation="horizontal"
android:text="@string/swap_start" android:layout_width="match_parent"
style="@style/SwapTheme.StartSwap.StartButton" android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent"/> android:layout_weight="1.00"
android:drawableStart="@drawable/ic_launcher"
tools:text="SEND F-DROID"
android:gravity="start|center_vertical" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:drawableStart="@drawable/ic_launcher"
tools:text="SCAN QR CODE"
android:gravity="start|center_vertical" />
</LinearLayout>
</org.fdroid.fdroid.views.swap.StartSwapView> </org.fdroid.fdroid.views.swap.StartSwapView>

View File

@ -317,8 +317,6 @@
<string name="open_qr_code_scanner">Open QR Scanner</string> <string name="open_qr_code_scanner">Open QR Scanner</string>
<string name="swap_welcome">Welcome to F-Droid!</string> <string name="swap_welcome">Welcome to F-Droid!</string>
<string name="swap_confirm_connect">Do you want to get apps from %1$s now?</string> <string name="swap_confirm_connect">Do you want to get apps from %1$s now?</string>
<string name="swap_introduction">Your mobile device becomes an app store with Swap!</string>
<string name="swap_start">START A SWAP</string>
<string name="swap_reciprocate_failed">An error occurred while attempting to swap with another device. We will still try to get apps from them, but they may not be able to get apps from us.</string> <string name="swap_reciprocate_failed">An error occurred while attempting to swap with another device. We will still try to get apps from them, but they may not be able to get apps from us.</string>
<string name="swap_tap_to_select_apps">Tap to select the apps you want to swap.</string> <string name="swap_tap_to_select_apps">Tap to select the apps you want to swap.</string>
<string name="swap_dont_show_again">Don\'t show this again</string> <string name="swap_dont_show_again">Don\'t show this again</string>
@ -333,4 +331,5 @@
<string name="wifi_warning_personal">Best bet</string> <string name="wifi_warning_personal">Best bet</string>
<string name="swap_choose_apps">Choose Apps</string> <string name="swap_choose_apps">Choose Apps</string>
<string name="swap_scan_qr">Scan QR Code</string> <string name="swap_scan_qr">Scan QR Code</string>
<string name="swap_nearby">Nearby Swap</string>
</resources> </resources>

View File

@ -1,5 +1,6 @@
package org.fdroid.fdroid.localrepo; package org.fdroid.fdroid.localrepo;
import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -222,4 +223,37 @@ public class SwapManager {
public boolean isEnabled() { public boolean isEnabled() {
return service != null && service.isEnabled(); return service != null && service.isEnabled();
} }
// ==========================================
// Interacting with Bluetooth adapter
// ==========================================
@Nullable /* Emulators tend not to have bluetooth adapters. */
private final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
public boolean isBluetoothDiscoverable() {
return bluetooth != null &&
bluetooth.getScanMode() == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
}
public void ensureBluetoothDiscoverable() {
if (bluetooth == null) {
return;
}
if (!bluetooth.isEnabled()) {
if (!bluetooth.enable()) {
}
}
if (bluetooth.isEnabled()) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
context.startActivity(discoverableIntent);
}
}
} }

View File

@ -1,17 +1,24 @@
package org.fdroid.fdroid.views.swap; package org.fdroid.fdroid.views.swap;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.support.annotation.ColorRes; import android.support.annotation.ColorRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.compat.SwitchCompat;
import org.fdroid.fdroid.localrepo.SwapManager; import org.fdroid.fdroid.localrepo.SwapManager;
public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.InnerView { public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.InnerView {
@ -45,17 +52,52 @@ public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.
return (SwapWorkflowActivity)getContext(); return (SwapWorkflowActivity)getContext();
} }
private SwapManager getManager() {
return getActivity().getState();
}
@Nullable /* Emulators typically don't have bluetooth adapters */
private final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
private TextView viewBluetoothId;
@Override @Override
protected void onFinishInflate() { protected void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
findViewById(R.id.button_start_swap).setOnClickListener(new View.OnClickListener() { if (bluetooth != null) {
viewBluetoothId = (TextView)findViewById(R.id.device_id_bluetooth);
viewBluetoothId.setText(bluetooth.getName());
Switch bluetoothSwitch = ((Switch) findViewById(R.id.switch_bluetooth));
bluetoothSwitch.setChecked(getManager().isBluetoothDiscoverable());
bluetoothSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
getManager().ensureBluetoothDiscoverable();
} else {
// disableBluetooth();
}
}
});
} else {
findViewById(R.id.bluetooth_info).setVisibility(View.GONE);
}
((Switch)findViewById(R.id.switch_wifi)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onClick(View v) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
getActivity().showSelectApps(); if (isChecked) {
enableWifi();
} else {
disableWifi();
}
} }
}); });
} }
@Override @Override
@ -85,6 +127,19 @@ public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.
@Override @Override
public String getToolbarTitle() { public String getToolbarTitle() {
return getResources().getString(R.string.swap_start); return getResources().getString(R.string.swap_nearby);
}
// ========================================================================
// Wifi stuff
// ========================================================================
private void enableWifi() {
}
private void disableWifi() {
} }
} }