Skip to content

Commit

Permalink
QuickSettings : Add torch tile
Browse files Browse the repository at this point in the history
Patchset 2 : New torch drawables (Björn Lundén)

Change-Id: I0831266d503195ee249a85d0d728bdae321e56cd
  • Loading branch information
Danesh committed Dec 15, 2012
1 parent 5f86de8 commit 8d5af9f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 1 deletion.
Binary file modified packages/SystemUI/res/drawable-hdpi/ic_qs_flashlight_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/SystemUI/res/drawable-hdpi/ic_qs_flashlight_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/SystemUI/res/drawable-mdpi/ic_qs_flashlight_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/SystemUI/res/drawable-mdpi/ic_qs_flashlight_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/SystemUI/res/drawable-xhdpi/ic_qs_flashlight_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/SystemUI/res/drawable-xhdpi/ic_qs_flashlight_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.android.systemui.quicksettings;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;

import com.android.systemui.R;
import com.android.systemui.statusbar.phone.QuickSettingsController;
import com.android.systemui.statusbar.phone.QuickSettingsContainerView;

public class FlashLightTile extends QuickSettingsTile {

public FlashLightTile(Context context, LayoutInflater inflater,
QuickSettingsContainerView container,
QuickSettingsController qsc, Handler handler) {
super(context, inflater, container, qsc);
TorchObserver observer = new TorchObserver(handler);
observer.startObserving();
updateTileState();

onClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent("net.cactii.flash2.TOGGLE_FLASHLIGHT");
mContext.sendBroadcast(i);
}
};
}

private void updateTileState() {
boolean enabled = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.TORCH_STATE, 0) == 1;
if(enabled) {
mDrawable = R.drawable.ic_qs_flashlight_on;
} else {
mDrawable = R.drawable.ic_qs_flashlight_off;
}
}

private class TorchObserver extends ContentObserver {
public TorchObserver(Handler handler) {
super(handler);
}

@Override
public void onChange(boolean selfChange) {
updateTileState();
updateQuickSettings();
}

public void startObserving() {
final ContentResolver cr = mContext.getContentResolver();
cr.registerContentObserver(
Settings.System.getUriFor(Settings.System.TORCH_STATE), false, this);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.android.systemui.quicksettings.BluetoothTile;
import com.android.systemui.quicksettings.BrightnessTile;
import com.android.systemui.quicksettings.BugReportTile;
import com.android.systemui.quicksettings.FlashLightTile;
import com.android.systemui.quicksettings.GPSTile;
import com.android.systemui.quicksettings.InputMethodTile;
import com.android.systemui.quicksettings.MobileNetworkTile;
Expand Down Expand Up @@ -121,6 +122,7 @@ public class QuickSettingsController {
public static final int ALARM_TILE = 16;
public static final int BUG_REPORT_TILE = 17;
public static final int WIFI_DISPLAY_TILE = 18;
public static final int FLASHLIGHT_TILE = 19;
public static final int USER_TILE = 99;
private InputMethodTile IMETile;

Expand Down Expand Up @@ -184,7 +186,7 @@ void loadTiles() {
} else if (tile.equals(TILE_AIRPLANE)) {
mQuickSettings.add(AIRPLANE_MODE_TILE);
} else if (tile.equals(TILE_FLASHLIGHT)) {
// Not available yet
mQuickSettings.add(FLASHLIGHT_TILE);
} else if (tile.equals(TILE_SLEEP)) {
mQuickSettings.add(SLEEP_TILE);
} else if (tile.equals(TILE_MEDIA_PLAY_PAUSE)) {
Expand Down Expand Up @@ -320,6 +322,10 @@ void addQuickSettings(LayoutInflater inflater){
qs = new UserTile(mContext, inflater,
(QuickSettingsContainerView) mContainerView, this);
break;
case FLASHLIGHT_TILE:
qs = new FlashLightTile(mContext, inflater,
(QuickSettingsContainerView) mContainerView, this, mHandler);
break;
}
if (qs != null) {
qs.setupQuickSettingsTile();
Expand Down

0 comments on commit 8d5af9f

Please sign in to comment.