include app icons in the SelectLocalApps view
Since we have the packageName, we can just fetch the Drawables directly. This uses some shortcuts to try to make things run faster. For example, the ImageView does not have an ID, instead it is references by the index number within the LinearLayout.
This commit is contained in:
parent
107eab5eac
commit
efacc22c10
56
res/layout/select_local_apps_list_item.xml
Normal file
56
res/layout/select_local_apps_list_item.xml
Normal file
@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2010 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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/activatedBackgroundIndicator"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingBottom="2dip"
|
||||
android:paddingTop="2dip"
|
||||
tools:ignore="NewApi" >
|
||||
|
||||
<!-- TODO remove NewApi ignore when appcompat-v7 is in place -->
|
||||
|
||||
<ImageView
|
||||
android:layout_width="48dip"
|
||||
android:layout_height="48dip"
|
||||
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:layout_marginTop="6dip"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TwoLineListItem
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:mode="twoLine" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/application_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:layout_marginTop="6dip"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/package_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignStart="@+id/application_label"
|
||||
android:layout_below="@+id/application_label"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
</TwoLineListItem>
|
||||
|
||||
</LinearLayout>
|
@ -19,15 +19,19 @@ import android.app.ListFragment;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.Loader;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.ActionMode;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
import android.widget.*;
|
||||
import android.widget.SearchView.OnQueryTextListener;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.SimpleCursorAdapter.ViewBinder;
|
||||
|
||||
import org.fdroid.fdroid.FDroidApp;
|
||||
import org.fdroid.fdroid.R;
|
||||
@ -42,6 +46,8 @@ import java.util.HashSet;
|
||||
public class SelectLocalAppsFragment extends ListFragment
|
||||
implements LoaderCallbacks<Cursor>, OnQueryTextListener {
|
||||
|
||||
private PackageManager packageManager;
|
||||
private Drawable defaultAppIcon;
|
||||
private SelectLocalAppsActivity selectLocalAppsActivity;
|
||||
private ActionMode mActionMode = null;
|
||||
private String mCurrentFilterString;
|
||||
@ -57,21 +63,48 @@ public class SelectLocalAppsFragment extends ListFragment
|
||||
|
||||
setEmptyText(getString(R.string.no_applications_found));
|
||||
|
||||
packageManager = getActivity().getPackageManager();
|
||||
defaultAppIcon = getActivity().getResources()
|
||||
.getDrawable(android.R.drawable.sym_def_app_icon);
|
||||
|
||||
selectLocalAppsActivity = (SelectLocalAppsActivity) getActivity();
|
||||
ListView listView = getListView();
|
||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(),
|
||||
android.R.layout.simple_list_item_activated_2,
|
||||
R.layout.select_local_apps_list_item,
|
||||
null,
|
||||
new String[] {
|
||||
InstalledAppProvider.DataColumns.APPLICATION_LABEL,
|
||||
InstalledAppProvider.DataColumns.APP_ID,
|
||||
},
|
||||
new int[] {
|
||||
android.R.id.text1,
|
||||
android.R.id.text2,
|
||||
R.id.application_label,
|
||||
R.id.package_name,
|
||||
},
|
||||
0);
|
||||
adapter.setViewBinder(new ViewBinder() {
|
||||
|
||||
@Override
|
||||
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
||||
Log.i("SelectLocalAppsFragment", "ViewBinder " + columnIndex);
|
||||
if (columnIndex == cursor.getColumnIndex(InstalledAppProvider.DataColumns.APP_ID)) {
|
||||
String packageName = cursor.getString(columnIndex);
|
||||
TextView textView = (TextView) view.findViewById(R.id.package_name);
|
||||
textView.setText(packageName);
|
||||
LinearLayout ll = (LinearLayout) view.getParent().getParent();
|
||||
ImageView iconView = (ImageView) ll.getChildAt(0);
|
||||
Drawable icon;
|
||||
try {
|
||||
icon = packageManager.getApplicationIcon(packageName);
|
||||
} catch (NameNotFoundException e) {
|
||||
icon = defaultAppIcon;
|
||||
}
|
||||
iconView.setImageDrawable(icon);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
setListAdapter(adapter);
|
||||
setListShown(false); // start out with a progress indicator
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user