Skip to content

Commit

Permalink
Add USB Tether Tile (2/2)
Browse files Browse the repository at this point in the history
Change-Id: I3ce5da700181cf7620d476338fc423b07501e7c2
  • Loading branch information
letmedanz committed Mar 14, 2015
1 parent 8a31563 commit 2cd6218
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/java/com/android/internal/util/cm/QSConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ private QSConstants() {}
public static final String TILE_BATTERY_SAVER = "battery_saver";
public static final String TILE_EXPANDED_DESKTOP = "expanded_desktop";
public static final String TILE_SLIMACTION = "slimaction";

public static final String TILE_REBOOT = "reboot";
public static final String TILE_USB_TETHER = "usb_tether";

// Order matters
protected static final ArrayList<String> TILES_DEFAULT = new ArrayList<String>();
Expand Down Expand Up @@ -81,5 +80,6 @@ private QSConstants() {}
TILES_AVAILABLE.add(TILE_BATTERY_SAVER);
TILES_AVAILABLE.add(TILE_EXPANDED_DESKTOP);
TILES_AVAILABLE.add(TILE_SLIMACTION);
TILES_AVAILABLE.add(TILE_USB_TETHER);
}
}
25 changes: 25 additions & 0 deletions packages/SystemUI/res/drawable/ic_qs_usb_tether_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (C) 2015 The CyanogenMod Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="64"
android:viewportHeight="64">

<path
android:fillColor="#4DFFFFFF"
android:pathData="M48.677,29.715h5.255v-7.254h4.401l-7.047-9.612l-7.052,9.612h4.443V29.715z M54.688,46.753l3.645-4.971h-4.401v-7.255 h-5.255v6.215L54.688,46.753z M36.741,28.805v-3.923h2.109v-8.445h-8.444v6.034L36.741,28.805z M23.942,16.007v-1.679h4.562 l-6.547-8.976l-3.656,5.014L23.942,16.007z M28.916,34.699l22.692,22.692l3.324-3.324L7.6,6.734l-3.324,3.323l15.693,15.694 l0.004,10.381l-8.571-3.715v-3.896c1.257-0.734,2.111-2.079,2.111-3.639c0-2.33-1.887-4.222-4.224-4.222 c-2.332,0-4.222,1.892-4.222,4.222c0,1.56,0.854,2.905,2.113,3.639v6.668l12.794,5.547v5.609c-2.518,0.837-4.348,3.185-4.348,5.987 c0,3.495,2.835,6.333,6.332,6.333c3.501,0,6.337-2.838,6.337-6.333c0-2.802-1.83-5.15-4.352-5.987v-9.113L28.916,34.699z M23.938,29.72l1.843,1.843l-1.839,0.93L23.938,29.72z" />
</vector>
25 changes: 25 additions & 0 deletions packages/SystemUI/res/drawable/ic_qs_usb_tether_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (C) 2015 The CyanogenMod Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="64dp"
android:height="64dp"
android:viewportWidth="64"
android:viewportHeight="64">

<path
android:fillColor="#FFFFFF"
android:pathData="M48.677,29.724h5.255V22.47h4.401l-7.047-9.611l-7.052,9.611h4.443V29.724z M48.677,34.537h5.255v7.254h4.401l-7.047,9.611 l-7.052-9.611h4.443V34.537z M38.85,16.447h-8.444v8.445h2.11v3.251l-8.574,4.36V14.337h4.562l-6.547-8.975l-6.545,8.975h4.561 v21.805l-8.571-3.715v-3.896c1.257-0.734,2.111-2.079,2.111-3.639c0-2.33-1.887-4.222-4.224-4.222c-2.332,0-4.222,1.892-4.222,4.222c0,1.56,0.854,2.905,2.113,3.639v6.668l12.794,5.547v5.609c-2.518,0.837-4.348,3.184-4.348,5.987c0,3.495,2.835,6.333,6.332,6.333c3.501,0,6.337-2.838,6.337-6.333c0-2.802-1.83-5.15-4.352-5.987v-9.113l12.798-6.512v-5.839h2.11L38.85,16.447L38.85,16.447z" />
</vector>
14 changes: 7 additions & 7 deletions packages/SystemUI/res/values/slimmod_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
<!-- QS tiles customization -->
<string name="quick_settings_nfc_label">NFC</string>
<string name="quick_settings_compass_label">Compass</string>

<string name="quick_settings_compass_value" translatable="false"><xliff:g id="degrees">%1$.0f</xliff:g>\u00b0 <xliff:g id="direction">%2$s</xliff:g></string>
<string name="quick_settings_compass_init">Initializing\u2026</string>
<!-- QuickSettings: Location -->
<!-- Content description of the location tile in quick settings when on, battery saving mode (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_quick_settings_location_battery_saving">Location reporting: battery saving mode.</string>
<!-- Content description of the location tile in quick settings when on, sensors only mode (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_quick_settings_location_gps_only">Location reporting: sensors only mode.</string>
<!-- Content description of the location tile in quick settings when on, high accuracy mode (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_quick_settings_location_high_accuracy">Location reporting: high accuracy mode.</string>

<!-- QuickSettings: Location detail panel title [CHAR LIMIT=NONE] -->
<string name="quick_settings_location_detail_title">Location mode</string>
<!-- QuickSettings: Location (On, low-power) [CHAR LIMIT=NONE] -->
Expand All @@ -38,15 +38,10 @@
<string name="quick_settings_location_gps_only_label">Device only</string>
<!-- QuickSettings: Location (On, high-accuracy) [CHAR LIMIT=NONE] -->
<string name="quick_settings_location_high_accuracy_label">High accuracy</string>

<string name="quick_settings_screen_timeout_detail_title">Screen timeout</string>

<string name="quick_settings_lockscreen_label">Lock screen</string>

<string name="quick_settings_lte_tile_title">LTE</string>

<string name="quick_settings_visualizer_label">AudioFX</string>

<string name="quick_settings_reboot_label">Reboot</string>
<string name="quick_settings_reboot_recovery_label">Recovery</string>

Expand Down Expand Up @@ -85,6 +80,11 @@
<string name="select_application">Select application</string>
<string name="lockscreen_target_empty">Empty</string>

<string name="quick_settings_screenshot">Screenshot</string>
<string name="quick_settings_sync">Sync</string>
<string name="quick_settings_sync_off">Sync off</string>
<string name="quick_settings_usb_tether">USB tethering</string>

<!-- Brightness tile -->
<string name="quick_settings_brightness">Brightness</string>
<string name="quick_settings_battery_saver">Battery saver</string>
Expand Down
108 changes: 108 additions & 0 deletions packages/SystemUI/src/com/android/systemui/qs/tiles/UsbTetherTile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.systemui.qs.tiles;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbManager;
import android.provider.Settings;
import android.net.ConnectivityManager;

import com.android.systemui.R;
import com.android.systemui.qs.QSTile;

/**
* USB Tether quick settings tile
*/
public class UsbTetherTile extends QSTile<QSTile.BooleanState> {
private static final Intent WIRELESS_SETTINGS = new Intent(Settings.ACTION_WIRELESS_SETTINGS);

private final ConnectivityManager cm =
(ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

private boolean mListening;

private boolean mUsbTethered = false;
private boolean mUsbConnected = false;

public UsbTetherTile(Host host) {
super(host);
}

protected BooleanState newTileState() {
return new BooleanState();
}

@Override
public void setListening(boolean listening) {
if (mListening == listening)
return;
mListening = listening;
if (listening) {
final IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_STATE);
mContext.registerReceiver(mReceiver, filter);
} else {
mContext.unregisterReceiver(mReceiver);
}
}

@Override
protected void handleClick() {
cm.setUsbTethering(!mUsbTethered);
}

@Override
protected void handleLongClick() {
mHost.startSettingsActivity(WIRELESS_SETTINGS);
}

private void updateState() {
String[] tethered = cm.getTetheredIfaces();
String[] mUsbRegexs = cm.getTetherableUsbRegexs();

mUsbTethered = false;
for (String s : tethered) {
for (String regex : mUsbRegexs) {
if (s.matches(regex)) {
mUsbTethered = true;
break;
}
}
}
}

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mUsbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
updateState();
refreshState();
}
};

@Override
protected void handleUpdateState(BooleanState state, Object arg) {
state.visible = mUsbConnected && cm.isTetheringSupported();
state.value = mUsbTethered;
state.label = mContext.getString(R.string.quick_settings_usb_tether);
state.iconId = mUsbTethered ? R.drawable.ic_qs_usb_tether_on
: R.drawable.ic_qs_usb_tether_off;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.android.systemui.qs.tiles.RotationLockTile;
import com.android.systemui.qs.tiles.ScreenshotTile;
import com.android.systemui.qs.tiles.ScreenTimeoutTile;
import com.android.systemui.qs.tiles.UsbTetherTile;
import com.android.systemui.qs.tiles.SyncTile;
import com.android.systemui.qs.tiles.SlimActionTile;
import com.android.systemui.qs.tiles.WifiTile;
Expand Down Expand Up @@ -307,6 +308,9 @@ private QSTile<?> createTile(String tileSpec) {
return new ExpandedDesktopTile(this);
case QSConstants.TILE_SLIMACTION:
return new SlimActionTile(this);
default:
case QSConstants.TILE_USB_TETHER:
return new UsbTetherTile(this);
default:
throw new IllegalArgumentException("Bad tile spec: " + tileSpec);
}
Expand Down

0 comments on commit 2cd6218

Please sign in to comment.