Android Open Source - FAST App Info Adapter






From Project

Back to project page FAST.

License

The source code is released under:

GNU General Public License

If you think the Android project FAST listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.ligi.fast.ui;
//from  ww w . j ava  2 s  . co m
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.ligi.fast.App;
import org.ligi.fast.R;
import org.ligi.fast.model.AppInfo;
import org.ligi.fast.model.AppInfoList;
import org.ligi.fast.model.DynamicAppInfoList;
import org.ligi.fast.util.StringUtils;

import java.util.ArrayList;
import java.util.Locale;

/**
 * Adapter to provide the AppInfo to the user - also care for the filtering of the query
 */
public class AppInfoAdapter extends BaseAdapter {

    private final String highlightPrefix;
    private final static String highlightSuffix = "</font>";

    private final DynamicAppInfoList appInfoList;
    private final LayoutInflater layoutInflater;
    private final IconDimensions iconDimensions;

    public AppInfoAdapter(Context ctx, DynamicAppInfoList appInfoList) {
        this.appInfoList = appInfoList;

        int color = (ctx.getResources().getColor(R.color.divider_color));
        final String hexColorString = Integer.toHexString(color).toUpperCase(Locale.ENGLISH).substring(2);
        highlightPrefix = "<font color='#" + hexColorString +"'>";
        layoutInflater = LayoutInflater.from(ctx);
        iconDimensions = new IconDimensions(ctx);
    }


    public int getCount() {
        return appInfoList.size();
    }

    public AppInfo getItem(int position) {
        return appInfoList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) { // || ((ViewHolder)convertView.getTag()).isTextOnlyActive == getSettings().isTextOnlyActive()) { // if it's not recycled, initialize some
            if (App.getSettings().isTextOnlyActivated()) {
                convertView = layoutInflater.inflate(R.layout.item_textonly, null);
            } else {

                convertView = layoutInflater.inflate(R.layout.item_icon, null);
                convertView.setLayoutParams(new AbsListView.LayoutParams(iconDimensions.outerSizeInPx, ViewGroup.LayoutParams.WRAP_CONTENT));

                ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
                imageView.getLayoutParams().height = iconDimensions.innerSizeInPx;
                imageView.getLayoutParams().width = iconDimensions.innerSizeInPx;
            }
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.textView);
            holder.image = (ImageView) convertView.findViewById(R.id.imageView);
            convertView.setTag(holder);
        }

        holder = (ViewHolder) convertView.getTag();
        ImageView imageView = holder.image;
        TextView labelView= holder.text;

        AppInfo actAppInfo = appInfoList.get(position);

        if (imageView != null) {
            Drawable drawable = actAppInfo.getIcon();
            holder.image.setImageDrawable(drawable);
        }

        final int maxLines = App.getSettings().getMaxLines();

        if (maxLines==0) {
            labelView.setVisibility(View.GONE);
        } else {
            labelView.setMaxLines(maxLines);
            labelView.setVisibility(View.VISIBLE);
        }

        String label = actAppInfo.getLabel();
        String highlight_label = label;

        int query_index = label.toLowerCase(Locale.ENGLISH).indexOf(appInfoList.getCurrentQuery());

        if (appInfoList.getCurrentQuery().length() == 0) {
            labelView.setText(label);
            return convertView;
        }

        if (query_index == -1) { // search not App-Name - hope it is in Package Name - why else we want to show the app?
            label = actAppInfo.getPackageName();
            label = label.replace("com.google.android.apps.", "");
            query_index = label.toLowerCase(Locale.ENGLISH).indexOf(appInfoList.getCurrentQuery());
        }


        if (query_index != -1) {
            highlight_label = label.substring(0, query_index)
                    + highlightPrefix
                    + label.substring(query_index,query_index + appInfoList.getCurrentQuery().length())
                    + highlightSuffix
                    + label.substring(query_index + appInfoList.getCurrentQuery().length(),
                    label.length());
        } else if (App.getSettings().isGapSearchActivated()) {

            final ArrayList<Integer> matchedIndices = StringUtils.getMatchedIndices(actAppInfo.getLabel(),appInfoList.getCurrentQuery());
            if (matchedIndices.size()==appInfoList.getCurrentQuery().length()) {
                // highlight single characters of query in label for gap matched strings
                label = actAppInfo.getLabel();
            } // otherwise must be in package

            highlight_label="";
            int i=0;
            for (char chr:label.toCharArray()) {
                if (matchedIndices.contains(i++)) {
                    highlight_label+=highlightPrefix+chr+highlightSuffix;
                } else {
                    highlight_label+=chr;
                }
            }
        }

        labelView.setText(Html.fromHtml(highlight_label));
        return convertView;
    }


    public void setActQuery(String act_query) {
        appInfoList.setQuery(act_query);
        notifyDataSetChanged();
    }

    private static class ViewHolder {
        public TextView text;
        public ImageView image;
    }

    public void setSortMode(final DynamicAppInfoList.SortMode sortMode) {
        appInfoList.setSortMode(sortMode);
        notifyDataSetChanged();
    }

    public void updateList(AppInfoList list) {
        appInfoList.update(list);
        notifyDataSetChanged();
    }
}




Java Source Code List

org.ligi.axt.helpers.ActivityHelper.java
org.ligi.axt.helpers.ContextHelper.java
org.ligi.axt.helpers.FileHelper.java
org.ligi.axt.helpers.ResolveInfoHelper.java
org.ligi.axt.helpers.ViewHelper.java
org.ligi.axt.simplifications.SimpleTextWatcher.java
org.ligi.fast.App.java
org.ligi.fast.TargetStore.java
org.ligi.fast.TargetStore.java
org.ligi.fast.TargetStore.java
org.ligi.fast.background.AppInstallOrRemoveReceiver.java
org.ligi.fast.background.BackgroundGatherAsyncTask.java
org.ligi.fast.background.BaseAppGatherAsyncTask.java
org.ligi.fast.model.AppIconCache.java
org.ligi.fast.model.AppInfoList.java
org.ligi.fast.model.AppInfoSortByLabelComparator.java
org.ligi.fast.model.AppInfoSortByMostUsedComparator.java
org.ligi.fast.model.AppInfo.java
org.ligi.fast.model.DynamicAppInfoList.java
org.ligi.fast.settings.AndroidFASTSettings.java
org.ligi.fast.settings.FASTSettings.java
org.ligi.fast.testing.AppInfoTestBase.java
org.ligi.fast.testing.MutableFastSettings.java
org.ligi.fast.testing.TheAppIconCache.java
org.ligi.fast.testing.TheAppInfoStore.java
org.ligi.fast.testing.TheAppInfo.java
org.ligi.fast.testing.TheSearchActivity.java
org.ligi.fast.ui.AppActionDialogBuilder.java
org.ligi.fast.ui.AppInfoAdapter.java
org.ligi.fast.ui.FASTSettingsActivity.java
org.ligi.fast.ui.HelpDialog.java
org.ligi.fast.ui.HelpDialog.java
org.ligi.fast.ui.IconDimensions.java
org.ligi.fast.ui.LoadingDialog.java
org.ligi.fast.ui.SearchActivity.java
org.ligi.fast.util.AppInfoListStore.java
org.ligi.fast.util.PackageListSerializer.java
org.ligi.fast.util.StringUtils.java
org.ligi.fast.util.UmlautConverter.java