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

Commit 9ab581c2 authored by jianzhou's avatar jianzhou Committed by Xiaojing Zhang
Browse files

Apps: Add app search function in ManageApplications activity

In application-manager list, the menu of search is added in
submenu to support the search function.

Change-Id: I46a87738cd58cc8c62624f1b47caf3b03694aa1e
parent 71790e27
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -25,6 +25,33 @@
    android:orientation="vertical"
    android:background="@drawable/default_preference_background">

    <LinearLayout android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="gone">
        <TextView android:id="@+id/search_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:textSize="18sp"
            android:textStyle="bold"
            android:text="@string/show_search_function"
            android:baselineAlignBottom="true"
            android:textAppearance="?android:attr/textAppearanceLarge"
        />
        <EditText android:id="@+id/search_prefix"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textStyle="bold"
            android:imeOptions="actionDone"
            android:textSize="18sp"
            android:layout_marginStart="5dip"
            android:layout_marginEnd="20dip"
            android:textAppearance="?android:attr/textAppearanceLarge"
        />
    </LinearLayout>
    <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
+3 −0
Original line number Diff line number Diff line
@@ -2478,6 +2478,9 @@
    <string name="APN_NAME_CTWAP">中國電信WAP設置 CTWAP</string>
    <string name="APN_NAME_CTLTE">中國電信互聯網設置 ctlte</string>
    <string name="APN_NAME_CTMMS">中國電信彩信設置 CTWAP</string>

    <string name="show_search_function">搜索</string>

    <string name="display_auto_rotate_title" msgid="6176450657107806043">"當裝置旋轉時"</string>
    <string name="display_auto_rotate_rotate" msgid="4544299861233497728">"旋轉畫面內容"</string>
    <string name="display_auto_rotate_stay_in_portrait" msgid="292745182318093651">"保持直向畫面"</string>
+3 −0
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@
    <!-- Whether to show a preference item for mobile plan -->
    <bool name="config_show_mobile_plan">true</bool>

    <!-- Whether to add app search function in ManageApplications activity -->
    <bool name="config_searchapp_enabled">false</bool>

    <!-- Whether enable get network info -->
    <bool name="config_netinfo">false</bool>

+2 −1
Original line number Diff line number Diff line
@@ -6130,7 +6130,8 @@
    <string name="lock_to_app_start_step3">3\t\tPress and hold the recent apps button $</string>
    <!-- Label for whether should use screen lock or not. [CHAR LIMIT=30]-->
    <string name="lock_to_app_screen_lock">Use screen lock</string>

    <!--search function for application settings-->
    <string name="show_search_function">Search</string>
    <string name="usb_charging_title">Charging</string>
    <string name="usb_charging_summary">Lets you disable all data and file transfer connection with computer and put device in charging only mode.</string>
    <string name="primary_sub_select_title">Default 4G/3G Subscription</string>
+97 −5
Original line number Diff line number Diff line
@@ -49,7 +49,13 @@ import android.provider.Settings;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.text.BidiFormatter;
import android.text.Editable;
import android.text.format.Formatter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -57,15 +63,19 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import com.android.internal.app.IMediaContainerService;
import com.android.internal.content.PackageHelper;
@@ -171,6 +181,11 @@ public class ManageApplications extends Fragment implements
    public static final int SHOW_RUNNING_SERVICES = MENU_OPTIONS_BASE + 6;
    public static final int SHOW_BACKGROUND_PROCESSES = MENU_OPTIONS_BASE + 7;
    public static final int RESET_APP_PREFERENCES = MENU_OPTIONS_BASE + 8;
    // add for new feature for search applications
    public static final int SHOW_SEARCH_APPLICATIONS = MENU_OPTIONS_BASE + 9;

    private boolean mSearchappEnabled;

    // sort order
    private int mSortOrder = SORT_ORDER_ALPHA;
    
@@ -486,7 +501,9 @@ public class ManageApplications extends Fragment implements
    private Context mContext;

    AlertDialog mResetDialog;

    private LinearLayout mSearchView;
    public EditText mTextView;
    public TextView mSearchTitle;
    class MyPagerAdapter extends PagerAdapter
            implements ViewPager.OnPageChangeListener {
        int mCurPos = 0;
@@ -568,6 +585,12 @@ public class ManageApplications extends Fragment implements
        private int mWhichSize = SIZE_TOTAL;
        CharSequence mCurFilterPrefix;

        public View mCurrentView = null;

        public View getMyView() {
            return mCurrentView;
        }

        private Filter mFilter = new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
@@ -588,6 +611,14 @@ public class ManageApplications extends Fragment implements
            }
        };

        public void setFilterPrefix(String prefix) {
            Log.d(TAG,"setFilterPrefix:prefix="+prefix);
            mCurFilterPrefix = prefix;
            rebuild(true);
            notifyDataSetChanged();
            mTab.updateStorageUsage();
        }

        public ApplicationsAdapter(ApplicationsState state, TabInfo tab, int filterMode) {
            mState = state;
            mSession = state.newSession(this);
@@ -703,13 +734,12 @@ public class ManageApplications extends Fragment implements
                return origEntries;
            } else {
                String prefixStr = ApplicationsState.normalize(prefix.toString());
                final String spacePrefixStr = " " + prefixStr;
                ArrayList<ApplicationsState.AppEntry> newEntries
                        = new ArrayList<ApplicationsState.AppEntry>();
                for (int i=0; i<origEntries.size(); i++) {
                    ApplicationsState.AppEntry entry = origEntries.get(i);
                    String nlabel = entry.getNormalizedLabel();
                    if (nlabel.startsWith(prefixStr) || nlabel.indexOf(spacePrefixStr) != -1) {
                    if (nlabel.startsWith(prefixStr) || nlabel.indexOf(prefixStr) != -1) {
                        newEntries.add(entry);
                    }
                }
@@ -833,6 +863,7 @@ public class ManageApplications extends Fragment implements
            }
            mActive.remove(convertView);
            mActive.add(convertView);
            mCurrentView = convertView;
            return convertView;
        }

@@ -923,6 +954,8 @@ public class ManageApplications extends Fragment implements

        final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mProfileSpinnerAdapter = Utils.createUserSpinnerAdapter(um, mContext);
        mSearchappEnabled = getActivity().getResources().getBoolean(
                          R.bool.config_searchapp_enabled);
    }


@@ -936,6 +969,26 @@ public class ManageApplications extends Fragment implements
        mContentContainer = container;
        mRootView = rootView;

        mSearchView = (LinearLayout) rootView.findViewById(R.id.search);
        mTextView = (EditText) rootView.findViewById(R.id.search_prefix);
        mSearchTitle = (TextView) rootView.findViewById(R.id.search_title);
        mTextView.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (null != mCurTab && (null != mCurTab.mApplications)) {
                    mCurTab.mApplications.setFilterPrefix(mTextView.getText().toString().trim());
                }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
        MyPagerAdapter adapter = new MyPagerAdapter();
        mViewPager.setAdapter(adapter);
@@ -1089,11 +1142,14 @@ public class ManageApplications extends Fragment implements
        mOptionsMenu = menu;
        // note: icons removed for now because the cause the new action
        // bar UI to be very confusing.
        if (mSearchappEnabled) {
            // add for new feature for search applications
            menu.add(0, SHOW_SEARCH_APPLICATIONS, 1, R.string.show_search_function)
                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        }
        menu.add(0, SORT_ORDER_ALPHA, 1, R.string.sort_order_alpha)
                //.setIcon(android.R.drawable.ic_menu_sort_alphabetically)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(0, SORT_ORDER_SIZE, 2, R.string.sort_order_size)
                //.setIcon(android.R.drawable.ic_menu_sort_by_size)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        menu.add(0, SHOW_RUNNING_SERVICES, 3, R.string.show_running_services)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
@@ -1139,12 +1195,20 @@ public class ManageApplications extends Fragment implements
            mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(!showingBackground);
            mOptionsMenu.findItem(RESET_APP_PREFERENCES).setVisible(false);
            mShowBackground = showingBackground;
            if(mSearchappEnabled) {
                //add for new feature for search applications
                mOptionsMenu.findItem(SHOW_SEARCH_APPLICATIONS).setVisible(false);
            }
        } else {
            mOptionsMenu.findItem(SORT_ORDER_ALPHA).setVisible(mSortOrder != SORT_ORDER_ALPHA);
            mOptionsMenu.findItem(SORT_ORDER_SIZE).setVisible(mSortOrder != SORT_ORDER_SIZE);
            mOptionsMenu.findItem(SHOW_RUNNING_SERVICES).setVisible(false);
            mOptionsMenu.findItem(SHOW_BACKGROUND_PROCESSES).setVisible(false);
            mOptionsMenu.findItem(RESET_APP_PREFERENCES).setVisible(true);
            if(mSearchappEnabled) {
                //add for new feature for search applications
                mOptionsMenu.findItem(SHOW_SEARCH_APPLICATIONS).setVisible(true);
            }
        }
    }

@@ -1259,6 +1323,10 @@ public class ManageApplications extends Fragment implements
            }
        } else if (menuId == RESET_APP_PREFERENCES) {
            buildResetDialog();
        } else
            //add for new feature for search applications
            if(menuId == SHOW_SEARCH_APPLICATIONS){
                showInputmethod();
        } else {
            // Handle the home button
            return false;
@@ -1300,6 +1368,20 @@ public class ManageApplications extends Fragment implements
        if (host != null) {
            host.invalidateOptionsMenu();
        }

        if(mCurTab.mListType == LIST_TYPE_RUNNING) {
            mSearchView.setVisibility(View.GONE);
            if (mTextView.hasFocus() == false) {
                InputMethodManager imm = (InputMethodManager)
                        host.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mTextView.getWindowToken(), 0);
            }
        } else {
            if (!TextUtils.isEmpty(mTextView.getText().toString())) {
                mTextView.setText("");
            }
            mCurTab.mApplications.setFilterPrefix("");
        }
    }

    private volatile IMediaContainerService mContainerService;
@@ -1318,4 +1400,14 @@ public class ManageApplications extends Fragment implements
            mContainerService = null;
        }
    };

    // add for new feature for search applications
    private void showInputmethod() {
        if (mSearchView.getVisibility() != View.VISIBLE) {
            if (mCurTab.mListType != LIST_TYPE_RUNNING) {
                mSearchView.setVisibility(View.VISIBLE);
                mTextView.requestFocus();
            }
        }
    }
}