Commit 4c57bcc2 authored by Ran Ji's avatar Ran Ji Committed by Commit Bot

Set padding dynamically to avoid build creating duplicated resource copy.

Apk size reduces 2kb compare with previous.

Bug: 736039
Change-Id: I4fe73fda4e9771cf34b830c3df16e3bca9a468c8
Reviewed-on: https://chromium-review.googlesource.com/570515Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Ran Ji <ranj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487094}
parent 99937de5
......@@ -13,8 +13,6 @@
android:id="@+id/desc"
android:textColor="@android:color/black"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
......
......@@ -16,12 +16,10 @@
android:contentDescription="@null"
android:layout_width="48dp"
android:layout_height="48dp"
android:paddingStart="20dp"
android:layout_gravity="start" />
<TextView
android:id="@+id/browser_name"
android:paddingStart="20dp"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
......
......@@ -6,7 +6,7 @@
# (including AndroidManifest.xml) is updated. This version should be incremented
# prior to uploading a new ShellAPK to the WebAPK Minting Server.
# Does not affect Chrome.apk
template_shell_apk_version = 14
template_shell_apk_version = 15
# The ShellAPK version expected by Chrome. Chrome will try to update the WebAPK
# if the WebAPK's ShellAPK version is less than |expected_shell_apk_version|.
......
......@@ -95,6 +95,7 @@ public class ChooseHostBrowserDialog {
TextView desc = (TextView) view.findViewById(R.id.desc);
ListView browserList = (ListView) view.findViewById(R.id.browser_list);
desc.setText(R.string.choose_host_browser);
WebApkUtils.setPadding(desc, context, WebApkUtils.PADDING_DP, 0, WebApkUtils.PADDING_DP, 0);
browserList.setAdapter(new BrowserArrayAdapter(context, browserItems));
// The context theme wrapper is needed for pre-L.
......@@ -177,7 +178,9 @@ public class ChooseHostBrowserDialog {
}
TextView name = (TextView) convertView.findViewById(R.id.browser_name);
WebApkUtils.setPadding(name, mContext, WebApkUtils.PADDING_DP, 0, 0, 0);
ImageView icon = (ImageView) convertView.findViewById(R.id.browser_icon);
WebApkUtils.setPadding(icon, mContext, WebApkUtils.PADDING_DP, 0, 0, 0);
BrowserItem item = mBrowsers.get(position);
name.setEnabled(item.supportsWebApks());
......
......@@ -39,7 +39,9 @@ public class InstallHostBrowserDialog {
int hostBrowserIconId) {
View view = LayoutInflater.from(context).inflate(R.layout.host_browser_list_item, null);
TextView name = (TextView) view.findViewById(R.id.browser_name);
WebApkUtils.setPadding(name, context, WebApkUtils.PADDING_DP, 0, 0, 0);
ImageView icon = (ImageView) view.findViewById(R.id.browser_icon);
WebApkUtils.setPadding(icon, context, WebApkUtils.PADDING_DP, 0, 0, 0);
name.setText(hostBrowserApplicationName);
name.setTextColor(Color.BLACK);
......
......@@ -12,8 +12,11 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import org.chromium.webapk.lib.common.WebApkConstants;
import org.chromium.webapk.lib.common.WebApkMetaDataKeys;
......@@ -29,6 +32,7 @@ import java.util.Set;
*/
public class WebApkUtils {
public static final String SHARED_PREF_RUNTIME_HOST = "runtime_host";
public static final int PADDING_DP = 20;
/**
* The package names of the channels of Chrome that support WebAPKs. The most preferred one
......@@ -226,4 +230,27 @@ public class WebApkUtils {
editor.putString(SHARED_PREF_RUNTIME_HOST, hostPackage);
editor.apply();
}
/** Converts a dp value to a px value. */
public static int dpToPx(Context context, int value) {
return Math.round(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, value, context.getResources().getDisplayMetrics()));
}
/**
* Android uses padding_left under API level 17 and uses padding_start after that.
* If we set the padding in resource file, android will create duplicated resource xml
* with the padding to be different.
*/
@SuppressWarnings("deprecation")
public static void setPadding(
View view, Context context, int start, int top, int end, int bottom) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setPaddingRelative(dpToPx(context, start), dpToPx(context, top),
dpToPx(context, end), dpToPx(context, bottom));
} else {
view.setPadding(dpToPx(context, start), dpToPx(context, top), dpToPx(context, end),
dpToPx(context, bottom));
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment