Skip to content

Commit

Permalink
Clean up, simplify and fix AlarmTile class and logic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
veeti authored and GodFox committed Oct 19, 2013
1 parent 6bb0132 commit 1ff134d
Showing 1 changed file with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
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.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
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 AlarmTile extends QuickSettingsTile{

private boolean enabled = false;
public class AlarmTile extends QuickSettingsTile {

public AlarmTile(Context context, LayoutInflater inflater,
QuickSettingsContainerView container,
QuickSettingsController qsc, Handler handler) {
super(context, inflater, container, qsc);

mDrawable = R.drawable.ic_qs_alarm_on;
String nextAlarmTime = Settings.System.getString(mContext.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED);
if(nextAlarmTime != null){
mLabel = nextAlarmTime;
}

mOnClick = new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent();
Expand All @@ -42,36 +34,30 @@ public void onClick(View v) {
startSettingsActivity(intent);
}
};
qsc.registerAction(Intent.ACTION_ALARM_CHANGED, this);

qsc.registerObservedContent(Settings.System.getUriFor(
Settings.System.NEXT_ALARM_FORMATTED), this);
}

@Override
public void onReceive(Context context, Intent intent) {
onAlarmChanged(intent);
updateStatus();
}

@Override
public void onChangeUri(ContentResolver resolver, Uri uri) {
onNextAlarmChanged();
}

void onAlarmChanged(Intent intent) {
enabled = intent.getBooleanExtra("alarmSet", false);
updateQuickSettings();
}

void onNextAlarmChanged() {
mLabel = Settings.System.getString(mContext.getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
updateStatus();
updateQuickSettings();
}

@Override
void updateQuickSettings() {
mTile.setVisibility(enabled ? View.VISIBLE : View.GONE);
public void updateQuickSettings() {
mTile.setVisibility(!TextUtils.isEmpty(mLabel) ? View.VISIBLE : View.GONE);
super.updateQuickSettings();
}

/**
* Updates the alarm status shown on the tile.
*/
private void updateStatus() {
mLabel = Settings.System.getString(mContext.getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED);
}

}

0 comments on commit 1ff134d

Please sign in to comment.