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

Commit 3a4ba0db authored by Isaac Katzenelson's avatar Isaac Katzenelson
Browse files

Use best time formatting for clock - part 2

Bug: 11119295
Change-Id: I72fed7082b13b12863af1b79ce4b0a15ef554216
parent 7ec0bb65
Loading
Loading
Loading
Loading

res/layout/desk_clock_weather.xml

deleted100644 → 0
+0 −99
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 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.
-->

<!-- Weather data from Genie provider -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/weather"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="start"
    >
    <RelativeLayout android:id="@+id/weather_temp_icon_cluster"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="-6dip"
        >
        <ImageView android:id="@+id/weather_icon"
            android:layout_height="60sp"
            android:layout_width="60sp"
            android:gravity="start"
            android:scaleType="centerInside"
            android:layout_marginRight="8dip"
            android:layout_marginEnd="8dip"
            />
        <TextView android:id="@+id/weather_temperature"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textSize="46sp"
            android:textColor="?android:attr/textColorPrimary"
            android:shadowColor="#C0000000"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="3.0"
            android:layout_marginRight="8dip"
            android:layout_marginEnd="8dip"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/weather_icon"
            android:layout_alignBottom="@id/weather_icon"
            />
        <TextView android:id="@+id/weather_low_temperature"
            android:layout_width="40sp"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:shadowColor="#C0000000"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="3.0"
            android:layout_toRightOf="@id/weather_temperature"
            android:layout_alignBaseline="@id/weather_temperature"
            />
        <TextView android:id="@+id/weather_high_temperature"
            android:layout_width="40sp"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textStyle="bold"
            android:textColor="?android:attr/textColorPrimary"
            android:shadowColor="#C0000000"
            android:shadowDx="0"
            android:shadowDy="0"
            android:shadowRadius="3.0"
            android:layout_alignTop="@id/weather_temperature"
            android:layout_marginTop="9sp"
            android:layout_alignLeft="@id/weather_low_temperature"
            android:layout_alignStart="@id/weather_low_temperature"
            />
    </RelativeLayout>
    <TextView android:id="@+id/weather_location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/weather_temp_icon_cluster"
        android:maxWidth="300sp"
        android:gravity="start"
        android:textSize="18sp"
        android:textColor="#ffffffff"
        android:shadowColor="#c0000000"
        android:shadowDx="0"
        android:shadowDy="0"
        android:shadowRadius="3.0"
        />
</RelativeLayout>
+2 −1
Original line number Diff line number Diff line
@@ -1044,7 +1044,8 @@ public class AlarmClockFragment extends DeskClockFragment implements
                itemHolder.alarmItem.setBackgroundResource(mBackgroundColor);
                setItemAlpha(itemHolder, itemHolder.onoff.isChecked());
            }

            itemHolder.clock.setFormat(
                    (int)mContext.getResources().getDimension(R.dimen.alarm_label_size));
            itemHolder.clock.setTime(alarm.hour, alarm.minutes);
            itemHolder.clock.setClickable(true);
            itemHolder.clock.setOnClickListener(new View.OnClickListener() {
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.provider.Settings;
import android.service.dreams.DreamService;
import android.util.Log;
import android.view.View;
import android.widget.TextClock;

import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;

@@ -153,6 +154,9 @@ public class Screensaver extends DreamService {
        mDigitalClock = findViewById(R.id.digital_clock);
        mAnalogClock =findViewById(R.id.analog_clock);
        setClockStyle();
        Utils.setTimeFormat((TextClock)mDigitalClock,
            (int)getResources().getDimension(R.dimen.bottom_text_size));

        mContentView = (View) mSaverView.getParent();
        mSaverView.setAlpha(0);

+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextClock;

import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;

@@ -191,6 +192,9 @@ public class ScreensaverActivity extends Activity {
        mDigitalClock = findViewById(R.id.digital_clock);
        mAnalogClock = findViewById(R.id.analog_clock);
        setClockStyle();
        Utils.setTimeFormat((TextClock)mDigitalClock,
            (int)getResources().getDimension(R.dimen.bottom_text_size));

        mContentView = (View) mSaverView.getParent();
        mContentView.forceLayout();
        mSaverView.forceLayout();
+32 −21
Original line number Diff line number Diff line
@@ -484,14 +484,22 @@ public class Utils {
    }

    /***
     * Formats the 12 hour time in the TextClock according to the Locale with a special
     * Formats the time in the TextClock according to the Locale with a special
     * formatting treatment for the am/pm label.
     * @param clock - TextClock to format
     * @param amPmFormat - a format string to set a specific font for the am/pm
     * @param amPmFontSize - size of the am/pm label since it is usually smaller
     *        than the clock time size.
     */
    public static void setTimeFormat(TextClock clock, int amPmFontSize) {
        if (clock != null) {
          // Get the best format for h:mm am/pm according to the locale
            // Get the best format for 12 hours mode according to the locale
            clock.setFormat12Hour(get12ModeFormet(amPmFontSize));
            // Get the best format for 24 hours mode according to the locale
            clock.setFormat24Hour(get24ModeFormet());
        }
    }

    public static CharSequence get12ModeFormet(int amPmFontSize) {
        String skeleton = "hma";
        String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
        // Replace spaces with "Hair Space"
@@ -499,8 +507,8 @@ public class Utils {
        // Build a spannable so that the am/pm will be formatted
        int amPmPos = pattern.indexOf('a');
        if (amPmPos == -1) {
                clock.setFormat12Hour(pattern);
            } else {
            return pattern;
        }
        Spannable sp = new SpannableString(pattern);
        sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), amPmPos, amPmPos + 1,
                Spannable.SPAN_POINT_MARK);
@@ -508,9 +516,12 @@ public class Utils {
                Spannable.SPAN_POINT_MARK);
        sp.setSpan(new TypefaceSpan("sans-serif-condensed"), amPmPos, amPmPos + 1,
                Spannable.SPAN_POINT_MARK);
                clock.setFormat12Hour(sp);
            }
        return sp;
    }

    public static CharSequence get24ModeFormet() {
        String skeleton = "Hm";
        return DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
    }

    public static CityObj[] loadCitiesFromXml(Context c) {
Loading