<commit_before>/*
 * Copyright (C) 2014 <NAME> for GravityBox Project (C3C076@xda)
 * 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.ceco.kitkat.gravitybox.quicksettings;

import com.ceco.kitkat.gravitybox.GravityBox;
import com.ceco.kitkat.gravitybox.R;
import com.ceco.kitkat.gravitybox.StatusbarQuietHoursManager;
import com.ceco.kitkat.gravitybox.StatusbarQuietHoursManager.QuietHoursListener;
import com.ceco.kitkat.gravitybox.ledcontrol.QuietHours;
import com.ceco.kitkat.gravitybox.ledcontrol.QuietHoursActivity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

public class QuietHoursTile extends BasicTile implements QuietHoursListener {

    private QuietHours mQh;
    private StatusbarQuietHoursManager mManager;

    public QuietHoursTile(Context context, Context gbContext, Object statusBar, Object panelBar) {
        super(context, gbContext, statusBar, panelBar);

        mOnClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toggleState();
            }
        };

        mOnLongClick = new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (mQh != null) {
                    if (mQh.mode != QuietHours.Mode.AUTO) {
                        mManager.setMode(QuietHours.Mode.AUTO);
                    } else {
                        Intent i = new Intent();
                        i.setClassName(GravityBox.PACKAGE_NAME, QuietHoursActivity.class.getName());
                        startActivity(i);
                    }
                }
                return true;
            }
        };

        mManager = StatusbarQuietHoursManager.getInstance(mContext);
        mQh = mManager.getQuietHours();
    }

    @Override
    protected int onGetLayoutId() {
        return R.layout.quick_settings_tile_quiet_hours;
    }

    @Override
    protected void onTilePostCreate() {
        super.onTilePostCreate();
        mManager.registerListener(this);
    }

    @Override
    public void onQuietHoursChanged() {
        mQh = mManager.getQuietHours();
        updateResources();
    }

    @Override
    public void onTimeTick() {
        updateResources();
    }

    @Override
    protected synchronized void updateTile() {
        if (mQh == null) return;

        if (mQh.uncLocked || !mQh.enabled) {
            mTile.setVisibility(View.GONE);
            return;
        } else {
            mTile.setVisibility(View.VISIBLE);
        }

        switch (mQh.mode) {
            case ON: 
                mLabel = mGbContext.getString(R.string.quick_settings_quiet_hours_on);
                mDrawableId = R.drawable.ic_qs_quiet_hours_on;
                break;
            case OFF:
                mLabel = mGbContext.getString(R.string.quick_settings_quiet_hours_off);
                mDrawableId = R.drawable.ic_qs_quiet_hours_off;
                break;
            case AUTO:
                mLabel = mGbContext.getString(R.string.quick_settings_quiet_hours_auto);
                mDrawableId = mQh.quietHoursActive() ?
                        R.drawable.ic_qs_quiet_hours_auto_on : R.drawable.ic_qs_quiet_hours_auto_off;
                break;
        }

        super.updateTile();
    }

    private void toggleState() {
        if (mQh == null) return;

        switch (mQh.mode) {
            case ON:
            case AUTO:
                mManager.setMode(QuietHours.Mode.OFF);
                break;
            case OFF:
                mManager.setMode(QuietHours.Mode.ON);
                break;
        }
    }
}<commit_msg>QH Tile: toggle from AUTO to ON/OFF depending on current QH state<commit_after>/*
 * Copyright (C) 2014 <NAME> for GravityBox Project (C3C076@xda)
 * 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.ceco.kitkat.gravitybox.quicksettings;

import com.ceco.kitkat.gravitybox.GravityBox;
import com.ceco.kitkat.gravitybox.R;
import com.ceco.kitkat.gravitybox.StatusbarQuietHoursManager;
import com.ceco.kitkat.gravitybox.StatusbarQuietHoursManager.QuietHoursListener;
import com.ceco.kitkat.gravitybox.ledcontrol.QuietHours;
import com.ceco.kitkat.gravitybox.ledcontrol.QuietHoursActivity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

public class QuietHoursTile extends BasicTile implements QuietHoursListener {

    private QuietHours mQh;
    private StatusbarQuietHoursManager mManager;

    public QuietHoursTile(Context context, Context gbContext, Object statusBar, Object panelBar) {
        super(context, gbContext, statusBar, panelBar);

        mOnClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toggleState();
            }
        };

        mOnLongClick = new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (mQh != null) {
                    if (mQh.mode != QuietHours.Mode.AUTO) {
                        mManager.setMode(QuietHours.Mode.AUTO);
                    } else {
                        Intent i = new Intent();
                        i.setClassName(GravityBox.PACKAGE_NAME, QuietHoursActivity.class.getName());
                        startActivity(i);
                    }
                }
                return true;
            }
        };

        mManager = StatusbarQuietHoursManager.getInstance(mContext);
        mQh = mManager.getQuietHours();
    }

    @Override
    protected int onGetLayoutId() {
        return R.layout.quick_settings_tile_quiet_hours;
    }

    @Override
    protected void onTilePostCreate() {
        super.onTilePostCreate();
        mManager.registerListener(this);
    }

    @Override
    public void onQuietHoursChanged() {
        mQh = mManager.getQuietHours();
        updateResources();
    }

    @Override
    public void onTimeTick() {
        updateResources();
    }

    @Override
    protected synchronized void updateTile() {
        if (mQh == null) return;

        if (mQh.uncLocked || !mQh.enabled) {
            mTile.setVisibility(View.GONE);
            return;
        } else {
            mTile.setVisibility(View.VISIBLE);
        }

        switch (mQh.mode) {
            case ON: 
                mLabel = mGbContext.getString(R.string.quick_settings_quiet_hours_on);
                mDrawableId = R.drawable.ic_qs_quiet_hours_on;
                break;
            case OFF:
                mLabel = mGbContext.getString(R.string.quick_settings_quiet_hours_off);
                mDrawableId = R.drawable.ic_qs_quiet_hours_off;
                break;
            case AUTO:
                mLabel = mGbContext.getString(R.string.quick_settings_quiet_hours_auto);
                mDrawableId = mQh.quietHoursActive() ?
                        R.drawable.ic_qs_quiet_hours_auto_on : R.drawable.ic_qs_quiet_hours_auto_off;
                break;
        }

        super.updateTile();
    }

    private void toggleState() {
        if (mQh == null) return;

        switch (mQh.mode) {
            case ON:
                mManager.setMode(QuietHours.Mode.OFF);
                break;
            case AUTO:
                mManager.setMode(mQh.quietHoursActive() ? 
                        QuietHours.Mode.OFF : QuietHours.Mode.ON);
                break;
            case OFF:
                mManager.setMode(QuietHours.Mode.ON);
                break;
        }
    }
}
{'fraction_non_alphanumeric': 0.08424008424008424, 'fraction_numerical': 0.002808002808002808, 'mean_word_length': 2.037668798862829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2275946', 'n_tokens_mistral': 2540, 'n_tokens_neox': 2391, 'n_words': 527}