Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a4e5a624 authored by George Lin's avatar George Lin Committed by Android (Google) Code Review
Browse files

Merge "Clean up unused clock code" into udc-dev

parents 0d92b2ec b40f49b8
Loading
Loading
Loading
Loading

res/layout/clock_option.xml

deleted100644 → 0
+0 −46
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2019 The Android Open Source Project

     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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="2dp"
    android:paddingBottom="@dimen/option_bottom_margin"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:orientation="vertical">

    <TextView
        android:id="@+id/option_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="@dimen/theme_option_label_margin"
        android:textAppearance="@style/OptionTitleTextAppearance"/>
    <FrameLayout
        android:id="@+id/option_tile"
        android:layout_width="@dimen/option_tile_width"
        android:layout_height="@dimen/option_tile_width"
        android:layout_gravity="center_horizontal"
        android:paddingHorizontal="@dimen/option_tile_padding_horizontal"
        android:paddingVertical="@dimen/option_tile_padding_vertical"
        android:background="@drawable/option_border">
        <ImageView
            android:id="@+id/clock_option_thumbnail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </FrameLayout>
</LinearLayout>
+0 −65
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * 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.android.customization.model.clock;

import com.android.customization.model.CustomizationManager;

/**
 * {@link CustomizationManager} for clock faces.
 */
public abstract class BaseClockManager implements CustomizationManager<Clockface> {

    private final ClockProvider mClockProvider;

    public BaseClockManager(ClockProvider provider) {
        mClockProvider = provider;
    }

    @Override
    public boolean isAvailable() {
        return mClockProvider.isAvailable();
    }

    @Override
    public void apply(Clockface option, Callback callback) {
        handleApply(option, callback);
    }

    @Override
    public void fetchOptions(OptionsFetchedListener<Clockface> callback, boolean reload) {
        mClockProvider.fetch(callback, false);
    }

    /** Returns the ID of the current clock face, which may be null for the default clock face. */
    String getCurrentClock() {
        return lookUpCurrentClock();
    }

    /**
     * Implement to apply the clock picked by the user for {@link BaseClockManager#apply}.
     *
     * @param option Clock option, containing ID of the clock, that the user picked.
     * @param callback Report success and failure.
     */
    protected abstract void handleApply(Clockface option, Callback callback);

    /**
     * Implement to look up the current clock face for {@link BaseClockManager#getCurrentClock()}.
     *
     * @return ID of current clock. Can be null for the default clock face.
     */
    protected abstract String lookUpCurrentClock();
}
+0 −78
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * 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.android.customization.model.clock;

import android.content.ContentResolver;
import android.provider.Settings.Secure;
import android.text.TextUtils;

import com.android.customization.module.ThemesUserEventLogger;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * {@link CustomizationManager} for clock faces that implements apply by writing to secure settings.
 */
public class ClockManager extends BaseClockManager {

    // TODO: use constant from Settings.Secure
    static final String CLOCK_FACE_SETTING = "lock_screen_custom_clock_face";
    private static final String CLOCK_FIELD = "clock";
    private static final String TIMESTAMP_FIELD = "_applied_timestamp";
    private final ContentResolver mContentResolver;
    private final ThemesUserEventLogger mEventLogger;

    public ClockManager(ContentResolver resolver, ClockProvider provider,
            ThemesUserEventLogger logger) {
        super(provider);
        mContentResolver = resolver;
        mEventLogger = logger;
    }

    @Override
    protected void handleApply(Clockface option, Callback callback) {
        boolean stored;
        try {
            final JSONObject json = new JSONObject();
            json.put(CLOCK_FIELD, option.getId());
            json.put(TIMESTAMP_FIELD, System.currentTimeMillis());
            stored = Secure.putString(mContentResolver, CLOCK_FACE_SETTING, json.toString());
        } catch (JSONException ex) {
            stored = false;
        }
        if (stored) {
            mEventLogger.logClockApplied(option);
            callback.onSuccess();
        } else {
            callback.onError(null);
        }
    }

    @Override
    protected String lookUpCurrentClock() {
        final String value = Secure.getString(mContentResolver, CLOCK_FACE_SETTING);
        if (TextUtils.isEmpty(value)) {
            return value;
        }
        try {
            final JSONObject json = new JSONObject(value);
            return json.getString(CLOCK_FIELD);
        } catch (JSONException ex) {
            return value;
        }
    }
}
+0 −35
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * 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.android.customization.model.clock;

import com.android.customization.model.CustomizationManager.OptionsFetchedListener;

/**
 * Interface for a class that can retrieve Themes from the system.
 */
public interface ClockProvider {
    /**
     * Returns whether clockfaces are available in the current setup.
     */
    boolean isAvailable();

    /**
     * Retrieve the available clockfaces.
     * @param callback called when the clockfaces have been retrieved (or immediately if cached)
     * @param reload whether to reload clockfaces if they're cached.
     */
    void fetch(OptionsFetchedListener<Clockface> callback, boolean reload);
}
+0 −104
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * 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.android.customization.model.clock;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.android.customization.model.CustomizationManager;
import com.android.customization.model.CustomizationOption;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;

public class Clockface implements CustomizationOption<Clockface> {

    private final String mTitle;
    private final String mId;
    private final Asset mPreview;
    private final Asset mThumbnail;

    private Clockface(String title, String id, Asset preview, Asset thumbnail) {
        mTitle = title;
        mId = id;
        mPreview = preview;
        mThumbnail = thumbnail;
    }

    @Override
    public String getTitle() {
        return mTitle;
    }

    @Override
    public void bindThumbnailTile(View view) {
        ImageView thumbView = view.findViewById(R.id.clock_option_thumbnail);
        mThumbnail.loadDrawableWithTransition(thumbView.getContext(), thumbView, 50, null,
                thumbView.getResources().getColor(android.R.color.transparent, null));
    }

    @Override
    public boolean isActive(CustomizationManager<Clockface> manager) {
        String currentClock = ((BaseClockManager) manager).getCurrentClock();
        // Empty clock Id is the default system clock
        return (TextUtils.isEmpty(currentClock) && TextUtils.isEmpty(mId))
                || (mId != null && mId.equals(currentClock));
    }

    @Override
    public int getLayoutResId() {
        return R.layout.clock_option;
    }

    public Asset getPreviewAsset() {
        return mPreview;
    }

    public String getId() {
        return mId;
    }

    public static class Builder {
        private String mTitle;
        private String mId;
        private Asset mPreview;
        private Asset mThumbnail;

        public Clockface build() {
            return new Clockface(mTitle, mId, mPreview, mThumbnail);
        }

        public Builder setTitle(String title) {
            mTitle = title;
            return this;
        }

        public Builder setId(String id) {
            mId = id;
            return this;
        }

        public Builder setPreview(Asset preview) {
            mPreview = preview;
            return this;
        }

        public Builder setThumbnail(Asset thumbnail) {
            mThumbnail = thumbnail;
            return this;
        }
    }
}
Loading