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

Commit 17a6170c authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Fix AnalogClock rendering

1. Change calls to java.lang.System.log* since they don't exist on the
host.
2. Clean up method rewrite mechanism in ReplaceMethodCallsAdapter.
3. Stub out creation of uninitialized GregorianCalendar.
4. Memory map the time zone data base file and provide a custom
implementation of BufferIterator for use by ZoneInfoDB
5. Delete unused Time_Delegate

Also fixed a comment in BridgeAssetManager and an error message in
FontFamily_Delegate.

Bug: http://b.android.com/79160
Change-Id: Iae5ef65678f0e6c7c5af520c45bd15980ce3fa55
parent cb09bc45
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.content.res.AssetManager;
public class BridgeAssetManager extends AssetManager {

    /**
     * This initializes the static field {@link AssetManager#mSystem} which is used
     * This initializes the static field {@link AssetManager#sSystem} which is used
     * by methods who get a global asset manager using {@link AssetManager#getSystem()}.
     * <p/>
     * They will end up using our bridge asset manager.
+1 −1
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ public class FontFamily_Delegate {
    @LayoutlibDelegate
    /*package*/ static boolean nAddFontFromAsset(long nativeFamily, AssetManager mgr, String path) {
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "FontFamily.addFontFromAsset is not supported.", null, null);
                "Typeface.createFromAsset is not supported.", null, null);
        return false;
    }

+0 −75
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 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 android.text.format;

import java.util.Calendar;
import java.util.TimeZone;
import java.util.UnknownFormatConversionException;
import java.util.regex.Pattern;

import com.android.ide.common.rendering.api.LayoutLog;
import com.android.layoutlib.bridge.Bridge;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

/**
 * Delegate used to provide new implementation for native methods of {@link Time}
 *
 * Through the layoutlib_create tool, some native methods of Time have been replaced by calls to
 * methods of the same name in this delegate class.
 */
public class Time_Delegate {

    // Regex to match odd number of '%'.
    private static final Pattern p = Pattern.compile("(?<!%)(%%)*%(?!%)");

    // Format used by toString()
    private static final String FORMAT = "%1$tY%1$tm%1$tdT%1$tH%1$tM%1$tS<%1$tZ>";

    // ---- private helper methods ----

    private static Calendar timeToCalendar(Time time) {
        Calendar calendar = getCalendarInstance(time);
        calendar.set(time.year, time.month, time.monthDay, time.hour, time.minute, time.second);
        return calendar;
    }

    private static void calendarToTime(Calendar c, Time time) {
        time.timezone = c.getTimeZone().getID();
        time.set(c.get(Calendar.SECOND), c.get(Calendar.MINUTE), c.get(Calendar.HOUR_OF_DAY),
                c.get(Calendar.DATE), c.get(Calendar.MONTH), c.get(Calendar.YEAR));
        time.weekDay = c.get(Calendar.DAY_OF_WEEK);
        time.yearDay = c.get(Calendar.DAY_OF_YEAR);
        time.isDst = c.getTimeZone().inDaylightTime(c.getTime()) ? 1 : 0;
        // gmtoff is in seconds and TimeZone.getOffset() returns milliseconds.
        time.gmtoff = c.getTimeZone().getOffset(c.getTimeInMillis()) / DateUtils.SECOND_IN_MILLIS;
    }

    /**
     * Return a calendar instance with the correct timezone.
     *
     * @param time Time to obtain the timezone from.
     */
    private static Calendar getCalendarInstance(Time time) {
        // TODO: Check platform code to make sure the behavior is same for null/invalid timezone.
        if (time == null || time.timezone == null) {
            // Default to local timezone.
            return Calendar.getInstance();
        }
        // If timezone is invalid, use GMT.
        return Calendar.getInstance(TimeZone.getTimeZone(time.timezone));
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.tools.layoutlib.create.MethodAdapter;
import com.android.tools.layoutlib.create.OverrideMethod;
import com.android.util.Pair;
import com.ibm.icu.util.ULocale;
import libcore.io.MemoryMappedFile_Delegate;

import android.content.res.BridgeAssetManager;
import android.graphics.Bitmap;
@@ -252,6 +253,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {

        // load the fonts.
        FontFamily_Delegate.setFontLocation(fontLocation.getAbsolutePath());
        MemoryMappedFile_Delegate.setDataDir(fontLocation.getAbsoluteFile().getParentFile());

        // now parse com.android.internal.R (and only this one as android.R is a subset of
        // the internal version), and put the content in the maps.
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.layoutlib.bridge.libcore.io;

import java.nio.MappedByteBuffer;

import libcore.io.BufferIterator;

/**
 * Provides an implementation of {@link BufferIterator} over a {@link MappedByteBuffer}.
 */
public class BridgeBufferIterator extends BufferIterator {

    private int mPosition;
    private final long mSize;
    private final MappedByteBuffer mMappedByteBuffer;

    public BridgeBufferIterator(long size, MappedByteBuffer buffer) {
        mSize = size;
        mMappedByteBuffer = buffer;
    }

    @Override
    public void seek(int offset) {
        assert offset < mSize;
       mPosition = offset;
    }

    @Override
    public void skip(int byteCount) {
        assert mPosition + byteCount <= mSize;
        mPosition += byteCount;
    }

    @Override
    public void readByteArray(byte[] dst, int dstOffset, int byteCount) {
        assert dst.length >= dstOffset + byteCount;
        mMappedByteBuffer.position(mPosition);
        mMappedByteBuffer.get(dst, dstOffset, byteCount);
        mPosition = mMappedByteBuffer.position();
    }

    @Override
    public byte readByte() {
        mMappedByteBuffer.position(mPosition);
        byte b = mMappedByteBuffer.get();
        mPosition = mMappedByteBuffer.position();
        return b;
    }

    @Override
    public int readInt() {
        mMappedByteBuffer.position(mPosition);
        int i = mMappedByteBuffer.getInt();
        mPosition = mMappedByteBuffer.position();
        return i;
    }

    @Override
    public void readIntArray(int[] dst, int dstOffset, int intCount) {
        mMappedByteBuffer.position(mPosition);
        while (--intCount >= 0) {
            dst[dstOffset++] = mMappedByteBuffer.getInt();
        }
        mPosition = mMappedByteBuffer.position();
    }

    @Override
    public short readShort() {
        mMappedByteBuffer.position(mPosition);
        short s = mMappedByteBuffer.getShort();
        mPosition = mMappedByteBuffer.position();
        return s;
    }
}
Loading