Skip to content

Commit 1ff134d

Browse files
veetiGodFox
authored andcommitted
Clean up, simplify and fix AlarmTile class and logic
This commit cleans up the AlarmTile class by removing the unnecessary listener on the alarm intent. It now listens only to the next alarm setting value, which was fetched after receiving the intent anyway. These changes also fix a bug that would cause the tile to not show up after some actions, like reordering the tiles due to the visibility not being set on tile creation. Lastly, some minor code styling issues have been fixed. Patch set CyanogenDefy#2: collapse onNextAlarmChanged into onChangeUri, remove mEnabled, use TextUtils to check for string emptiness and mark updateQuickSettings explicitly as public. Change-Id: Ic5871a9cc4874f33181dfac14e25a89499c182f2
1 parent 6bb0132 commit 1ff134d

File tree

1 file changed

+15
-29
lines changed
  • packages/SystemUI/src/com/android/systemui/quicksettings

1 file changed

+15
-29
lines changed
Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
package com.android.systemui.quicksettings;
22

3-
import android.content.BroadcastReceiver;
43
import android.content.ComponentName;
54
import android.content.ContentResolver;
65
import android.content.Context;
76
import android.content.Intent;
8-
import android.content.IntentFilter;
97
import android.net.Uri;
108
import android.os.Handler;
119
import android.provider.Settings;
10+
import android.text.TextUtils;
1211
import android.view.LayoutInflater;
1312
import android.view.View;
1413

1514
import com.android.systemui.R;
1615
import com.android.systemui.statusbar.phone.QuickSettingsController;
1716
import com.android.systemui.statusbar.phone.QuickSettingsContainerView;
1817

19-
public class AlarmTile extends QuickSettingsTile{
20-
21-
private boolean enabled = false;
18+
public class AlarmTile extends QuickSettingsTile {
2219

2320
public AlarmTile(Context context, LayoutInflater inflater,
2421
QuickSettingsContainerView container,
2522
QuickSettingsController qsc, Handler handler) {
2623
super(context, inflater, container, qsc);
2724

2825
mDrawable = R.drawable.ic_qs_alarm_on;
29-
String nextAlarmTime = Settings.System.getString(mContext.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED);
30-
if(nextAlarmTime != null){
31-
mLabel = nextAlarmTime;
32-
}
3326

3427
mOnClick = new View.OnClickListener() {
35-
3628
@Override
3729
public void onClick(View v) {
3830
Intent intent = new Intent();
@@ -42,36 +34,30 @@ public void onClick(View v) {
4234
startSettingsActivity(intent);
4335
}
4436
};
45-
qsc.registerAction(Intent.ACTION_ALARM_CHANGED, this);
37+
4638
qsc.registerObservedContent(Settings.System.getUriFor(
4739
Settings.System.NEXT_ALARM_FORMATTED), this);
48-
}
49-
50-
@Override
51-
public void onReceive(Context context, Intent intent) {
52-
onAlarmChanged(intent);
40+
updateStatus();
5341
}
5442

5543
@Override
5644
public void onChangeUri(ContentResolver resolver, Uri uri) {
57-
onNextAlarmChanged();
58-
}
59-
60-
void onAlarmChanged(Intent intent) {
61-
enabled = intent.getBooleanExtra("alarmSet", false);
62-
updateQuickSettings();
63-
}
64-
65-
void onNextAlarmChanged() {
66-
mLabel = Settings.System.getString(mContext.getContentResolver(),
67-
Settings.System.NEXT_ALARM_FORMATTED);
45+
updateStatus();
6846
updateQuickSettings();
6947
}
7048

7149
@Override
72-
void updateQuickSettings() {
73-
mTile.setVisibility(enabled ? View.VISIBLE : View.GONE);
50+
public void updateQuickSettings() {
51+
mTile.setVisibility(!TextUtils.isEmpty(mLabel) ? View.VISIBLE : View.GONE);
7452
super.updateQuickSettings();
7553
}
7654

55+
/**
56+
* Updates the alarm status shown on the tile.
57+
*/
58+
private void updateStatus() {
59+
mLabel = Settings.System.getString(mContext.getContentResolver(),
60+
Settings.System.NEXT_ALARM_FORMATTED);
61+
}
62+
7763
}

0 commit comments

Comments
 (0)