App grid preview for screen zoom

Change-Id: I718468dc03800d125eea1c57c8e5dfbc84aa3367
This commit is contained in:
Alan Viverette
2016-02-04 10:12:05 -05:00
parent b9c70a11f2
commit 1912725628
4 changed files with 198 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
<!-- Copyright (C) 2016 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.
@@ -14,72 +14,7 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.settings.display.AppGridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:orientation="horizontal"
android:theme="?android:attr/actionBarTheme"
style="?android:attr/actionBarStyle">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="16dp"
android:text="@string/screen_zoom_preview_title"
android:textAppearance="@android:style/TextAppearance.Material.Widget.ActionBar.Title" />
<ImageView
android:layout_width="36dp"
android:layout_height="48dp"
style="?android:attr/actionOverflowButtonStyle" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:background="?android:attr/colorBackgroundFloating">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@android:style/TextAppearance.Material.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:text="@string/permissions_label" />
<include layout="@layout/screen_zoom_preview_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="62dp"
android:layout_marginRight="8dp"
android:background="#36000000" />
<include layout="@layout/screen_zoom_preview_item" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="62dp"
android:layout_marginRight="8dp"
android:background="#36000000" />
<include layout="@layout/screen_zoom_preview_item" />
</LinearLayout>
</ScrollView>
</LinearLayout>
android:layout_height="match_parent" />

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="@dimen/screen_zoom_preview_app_icon_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="8dp">
<ImageView
android:id="@android:id/icon1"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginBottom="4dp"
android:scaleType="centerInside" />
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_horizontal|top"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Material.Caption" />
</LinearLayout>
</FrameLayout>

View File

@@ -261,6 +261,7 @@
<!-- Display, Screen zoom -->
<dimen name="screen_zoom_preview_height">240dp</dimen>
<dimen name="screen_zoom_preview_app_icon_width">88dp</dimen>
<!-- Accessibility Settings -->
<dimen name="accessibility_layout_margin_start_end">24dp</dimen>
@@ -275,4 +276,5 @@
<dimen name="screen_magnification_video_width">170dp</dimen>
<dimen name="screen_magnification_video_height">311dp</dimen>
<dimen name="screen_magnification_video_margin_top">40dp</dimen>
</resources>

View File

@@ -0,0 +1,146 @@
/*
* Copyright (C) 2016 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.settings.display;
import com.android.settings.R;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class AppGridView extends GridView {
public AppGridView(Context context) {
this(context, null);
}
public AppGridView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public AppGridView(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr);
}
public AppGridView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleResId) {
super(context, attrs, defStyleAttr, defStyleResId);
setNumColumns(AUTO_FIT);
final int columnWidth = getResources().getDimensionPixelSize(
R.dimen.screen_zoom_preview_app_icon_width);
setColumnWidth(columnWidth);
setAdapter(new AppsAdapter(context, R.layout.screen_zoom_preview_app_icon,
android.R.id.text1, android.R.id.icon1));
}
/**
* Loads application labels and icons.
*/
private static class AppsAdapter extends ArrayAdapter<ActivityEntry> {
private final PackageManager mPackageManager;
private final int mIconResId;
public AppsAdapter(Context context, int layout, int textResId, int iconResId) {
super(context, layout, textResId);
mIconResId = iconResId;
mPackageManager = context.getPackageManager();
loadAllApps();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view = super.getView(position, convertView, parent);
final ActivityEntry entry = getItem(position);
final ImageView iconView = (ImageView) view.findViewById(mIconResId);
final Drawable icon = entry.info.loadIcon(mPackageManager);
iconView.setImageDrawable(icon);
return view;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public boolean isEnabled(int position) {
return false;
}
private void loadAllApps() {
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final PackageManager pm = mPackageManager;
final ArrayList<ActivityEntry> results = new ArrayList<>();
final List<ResolveInfo> infos = pm.queryIntentActivities(mainIntent, 0);
for (ResolveInfo info : infos) {
final CharSequence label = info.loadLabel(pm);
if (label != null) {
results.add(new ActivityEntry(info, label.toString()));
}
}
Collections.sort(results);
addAll(results);
}
}
/**
* Class used for caching the activity label and icon.
*/
private static class ActivityEntry implements Comparable<ActivityEntry> {
public final ResolveInfo info;
public final String label;
public ActivityEntry(ResolveInfo info, String label) {
this.info = info;
this.label = label;
}
@Override
public int compareTo(ActivityEntry entry) {
return label.compareToIgnoreCase(entry.label);
}
@Override
public String toString() {
return label;
}
}
}