Search in sources :

Example 16 with Condition

use of android.service.notification.Condition in project platform_frameworks_base by android.

the class ZenModePanel method handleUpdateConditions.

private void handleUpdateConditions() {
    if (mTransitionHelper.isTransitioning()) {
        return;
    }
    final int conditionCount = mConditions == null ? 0 : mConditions.length;
    if (DEBUG)
        Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount);
    // forever
    bind(forever(), mZenRadioGroupContent.getChildAt(FOREVER_CONDITION_INDEX), FOREVER_CONDITION_INDEX);
    // countdown
    if (mCountdownConditionSupported && mTimeCondition != null) {
        bind(mTimeCondition, mZenRadioGroupContent.getChildAt(COUNTDOWN_CONDITION_INDEX), COUNTDOWN_CONDITION_INDEX);
    }
    // countdown until alarm
    if (mCountdownConditionSupported) {
        Condition nextAlarmCondition = getTimeUntilNextAlarmCondition();
        if (nextAlarmCondition != null) {
            mZenRadioGroup.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX).setVisibility(View.VISIBLE);
            mZenRadioGroupContent.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX).setVisibility(View.VISIBLE);
            bind(nextAlarmCondition, mZenRadioGroupContent.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX), COUNTDOWN_ALARM_CONDITION_INDEX);
        } else {
            mZenRadioGroup.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX).setVisibility(View.GONE);
            mZenRadioGroupContent.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX).setVisibility(View.GONE);
        }
    }
    // ensure something is selected
    if (mExpanded && isShown()) {
        ensureSelection();
    }
    mZenConditions.setVisibility(mSessionZen != Global.ZEN_MODE_OFF ? View.VISIBLE : View.GONE);
}
Also used : Condition(android.service.notification.Condition)

Example 17 with Condition

use of android.service.notification.Condition in project platform_frameworks_base by android.

the class ZenModePanel method onClickTimeButton.

private void onClickTimeButton(View row, ConditionTag tag, boolean up, int rowId) {
    MetricsLogger.action(mContext, MetricsEvent.QS_DND_TIME, up);
    Condition newCondition = null;
    final int N = MINUTE_BUCKETS.length;
    if (mBucketIndex == -1) {
        // not on a known index, search for the next or prev bucket by time
        final Uri conditionId = getConditionId(tag.condition);
        final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
        final long now = System.currentTimeMillis();
        for (int i = 0; i < N; i++) {
            int j = up ? i : N - 1 - i;
            final int bucketMinutes = MINUTE_BUCKETS[j];
            final long bucketTime = now + bucketMinutes * MINUTES_MS;
            if (up && bucketTime > time || !up && bucketTime < time) {
                mBucketIndex = j;
                newCondition = ZenModeConfig.toTimeCondition(mContext, bucketTime, bucketMinutes, ActivityManager.getCurrentUser(), false);
                break;
            }
        }
        if (newCondition == null) {
            mBucketIndex = DEFAULT_BUCKET_INDEX;
            newCondition = ZenModeConfig.toTimeCondition(mContext, MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser());
        }
    } else {
        // on a known index, simply increment or decrement
        mBucketIndex = Math.max(0, Math.min(N - 1, mBucketIndex + (up ? 1 : -1)));
        newCondition = ZenModeConfig.toTimeCondition(mContext, MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser());
    }
    mTimeCondition = newCondition;
    bind(mTimeCondition, row, rowId);
    tag.rb.setChecked(true);
    select(mTimeCondition);
    announceConditionSelection(tag);
}
Also used : Condition(android.service.notification.Condition) Uri(android.net.Uri)

Example 18 with Condition

use of android.service.notification.Condition in project platform_frameworks_base by android.

the class ZenModePanel method handleUpdateManualRule.

private void handleUpdateManualRule(ZenRule rule) {
    final int zen = rule != null ? rule.zenMode : Global.ZEN_MODE_OFF;
    handleUpdateZen(zen);
    final Condition c = rule != null ? rule.condition : null;
    handleExitConditionChanged(c);
}
Also used : Condition(android.service.notification.Condition)

Example 19 with Condition

use of android.service.notification.Condition in project platform_frameworks_base by android.

the class ConditionProviders method removeDuplicateConditions.

private Condition[] removeDuplicateConditions(String pkg, Condition[] conditions) {
    if (conditions == null || conditions.length == 0)
        return null;
    final int N = conditions.length;
    final ArrayMap<Uri, Condition> valid = new ArrayMap<Uri, Condition>(N);
    for (int i = 0; i < N; i++) {
        final Uri id = conditions[i].id;
        if (valid.containsKey(id)) {
            Slog.w(TAG, "Ignoring condition from " + pkg + " for duplicate id: " + id);
            continue;
        }
        valid.put(id, conditions[i]);
    }
    if (valid.size() == 0)
        return null;
    if (valid.size() == N)
        return conditions;
    final Condition[] rt = new Condition[valid.size()];
    for (int i = 0; i < rt.length; i++) {
        rt[i] = valid.valueAt(i);
    }
    return rt;
}
Also used : Condition(android.service.notification.Condition) ArrayMap(android.util.ArrayMap) Uri(android.net.Uri)

Example 20 with Condition

use of android.service.notification.Condition in project android_frameworks_base by AOSPA.

the class ZenModePanel method bind.

private void bind(final Condition condition, final View row, final int rowId) {
    if (condition == null)
        throw new IllegalArgumentException("condition must not be null");
    final boolean enabled = condition.state == Condition.STATE_TRUE;
    final ConditionTag tag = row.getTag() != null ? (ConditionTag) row.getTag() : new ConditionTag();
    row.setTag(tag);
    final boolean first = tag.rb == null;
    if (tag.rb == null) {
        tag.rb = (RadioButton) mZenRadioGroup.getChildAt(rowId);
    }
    tag.condition = condition;
    final Uri conditionId = getConditionId(tag.condition);
    if (DEBUG)
        Log.d(mTag, "bind i=" + mZenRadioGroupContent.indexOfChild(row) + " first=" + first + " condition=" + conditionId);
    tag.rb.setEnabled(enabled);
    tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mExpanded && isChecked) {
                tag.rb.setChecked(true);
                if (DEBUG)
                    Log.d(mTag, "onCheckedChanged " + conditionId);
                MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT);
                select(tag.condition);
                announceConditionSelection(tag);
            }
        }
    });
    if (tag.lines == null) {
        tag.lines = row.findViewById(android.R.id.content);
    }
    if (tag.line1 == null) {
        tag.line1 = (TextView) row.findViewById(android.R.id.text1);
        mSpTexts.add(tag.line1);
    }
    if (tag.line2 == null) {
        tag.line2 = (TextView) row.findViewById(android.R.id.text2);
        mSpTexts.add(tag.line2);
    }
    final String line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary;
    final String line2 = condition.line2;
    tag.line1.setText(line1);
    if (TextUtils.isEmpty(line2)) {
        tag.line2.setVisibility(GONE);
    } else {
        tag.line2.setVisibility(VISIBLE);
        tag.line2.setText(line2);
    }
    tag.lines.setEnabled(enabled);
    tag.lines.setAlpha(enabled ? 1 : .4f);
    final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, false, /*down*/
            rowId);
        }
    });
    final ImageView button2 = (ImageView) row.findViewById(android.R.id.button2);
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, true, /*up*/
            rowId);
        }
    });
    tag.lines.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tag.rb.setChecked(true);
        }
    });
    final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
    if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) {
        button1.setVisibility(VISIBLE);
        button2.setVisibility(VISIBLE);
        if (mBucketIndex > -1) {
            button1.setEnabled(mBucketIndex > 0);
            button2.setEnabled(mBucketIndex < MINUTE_BUCKETS.length - 1);
        } else {
            final long span = time - System.currentTimeMillis();
            button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS);
            final Condition maxCondition = ZenModeConfig.toTimeCondition(mContext, MAX_BUCKET_MINUTES, ActivityManager.getCurrentUser());
            button2.setEnabled(!Objects.equals(condition.summary, maxCondition.summary));
        }
        button1.setAlpha(button1.isEnabled() ? 1f : .5f);
        button2.setAlpha(button2.isEnabled() ? 1f : .5f);
    } else {
        button1.setVisibility(GONE);
        button2.setVisibility(GONE);
    }
    // wire up interaction callbacks for newly-added condition rows
    if (first) {
        Interaction.register(tag.rb, mInteractionCallback);
        Interaction.register(tag.lines, mInteractionCallback);
        Interaction.register(button1, mInteractionCallback);
        Interaction.register(button2, mInteractionCallback);
    }
    row.setVisibility(VISIBLE);
}
Also used : Condition(android.service.notification.Condition) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Aggregations

Condition (android.service.notification.Condition)41 Uri (android.net.Uri)20 EventInfo (android.service.notification.ZenModeConfig.EventInfo)5 ArrayMap (android.util.ArrayMap)5 View (android.view.View)5 CompoundButton (android.widget.CompoundButton)5 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 CheckEventResult (com.android.server.notification.CalendarTracker.CheckEventResult)5 ArrayList (java.util.ArrayList)5 AudioManager (android.media.AudioManager)1