Search in sources :

Example 61 with SubMenu

use of android.view.SubMenu in project Douya by DreaminginCodeZH.

the class TintHelper method tintMenuItemIcon.

private static void tintMenuItemIcon(Menu menu, ColorStateList menuTintList, ColorStateList subMenuTintList) {
    for (int i = 0, size = menu.size(); i < size; ++i) {
        MenuItem menuItem = menu.getItem(i);
        Drawable icon = menuItem.getIcon();
        if (icon != null) {
            icon = tintDrawable(icon, menuTintList);
            menuItem.setIcon(icon);
        }
        SubMenu subMenu = menuItem.getSubMenu();
        if (subMenu != null) {
            tintMenuItemIcon(subMenu, subMenuTintList, subMenuTintList);
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) SubMenu(android.view.SubMenu)

Example 62 with SubMenu

use of android.view.SubMenu in project XobotOS by xamarin.

the class ShareActionProvider method onPrepareSubMenu.

/**
     * {@inheritDoc}
     */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();
    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);
    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
    }
    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount, mContext.getString(R.string.activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) SubMenu(android.view.SubMenu)

Example 63 with SubMenu

use of android.view.SubMenu in project NetGuard by M66B.

the class AdapterRule method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    // Get rule
    final Rule rule = listFiltered.get(position);
    // Handle expanding/collapsing
    holder.llApplication.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            rule.expanded = !rule.expanded;
            notifyItemChanged(position);
        }
    });
    // Show if non default rules
    holder.itemView.setBackgroundColor(rule.changed ? colorChanged : Color.TRANSPARENT);
    // Show expand/collapse indicator
    holder.ivExpander.setImageLevel(rule.expanded ? 1 : 0);
    // Show application icon
    if (rule.info.applicationInfo == null || rule.info.applicationInfo.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(holder.ivIcon);
    else {
        Uri uri = Uri.parse("android.resource://" + rule.info.packageName + "/" + rule.info.applicationInfo.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(holder.ivIcon);
    }
    // Show application label
    holder.tvName.setText(rule.name);
    // Show application state
    int color = rule.system ? colorOff : colorText;
    if (!rule.internet || !rule.enabled)
        color = Color.argb(128, Color.red(color), Color.green(color), Color.blue(color));
    holder.tvName.setTextColor(color);
    holder.tvHosts.setVisibility(rule.hosts > 0 ? View.VISIBLE : View.GONE);
    holder.tvHosts.setText(Long.toString(rule.hosts));
    // Lockdown settings
    boolean lockdown = prefs.getBoolean("lockdown", false);
    boolean lockdown_wifi = prefs.getBoolean("lockdown_wifi", true);
    boolean lockdown_other = prefs.getBoolean("lockdown_other", true);
    if ((otherActive && !lockdown_other) || (wifiActive && !lockdown_wifi))
        lockdown = false;
    holder.rlLockdown.setVisibility(lockdown && !rule.lockdown ? View.VISIBLE : View.GONE);
    holder.ivLockdown.setEnabled(rule.apply);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivLockdown.getDrawable());
        DrawableCompat.setTint(wrap, rule.apply ? colorOff : colorGrayed);
    }
    boolean screen_on = prefs.getBoolean("screen_on", true);
    // Wi-Fi settings
    holder.cbWifi.setEnabled(rule.apply);
    holder.cbWifi.setAlpha(wifiActive ? 1 : 0.5f);
    holder.cbWifi.setOnCheckedChangeListener(null);
    holder.cbWifi.setChecked(rule.wifi_blocked);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbWifi));
        DrawableCompat.setTint(wrap, rule.apply ? (rule.wifi_blocked ? colorOff : colorOn) : colorGrayed);
    }
    holder.cbWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.wifi_blocked = isChecked;
            updateRule(rule, true, listAll);
        }
    });
    holder.ivScreenWifi.setEnabled(rule.apply);
    holder.ivScreenWifi.setAlpha(wifiActive ? 1 : 0.5f);
    holder.ivScreenWifi.setVisibility(rule.screen_wifi && rule.wifi_blocked ? View.VISIBLE : View.INVISIBLE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivScreenWifi.getDrawable());
        DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed);
    }
    // Mobile settings
    holder.cbOther.setEnabled(rule.apply);
    holder.cbOther.setAlpha(otherActive ? 1 : 0.5f);
    holder.cbOther.setOnCheckedChangeListener(null);
    holder.cbOther.setChecked(rule.other_blocked);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbOther));
        DrawableCompat.setTint(wrap, rule.apply ? (rule.other_blocked ? colorOff : colorOn) : colorGrayed);
    }
    holder.cbOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.other_blocked = isChecked;
            updateRule(rule, true, listAll);
        }
    });
    holder.ivScreenOther.setEnabled(rule.apply);
    holder.ivScreenOther.setAlpha(otherActive ? 1 : 0.5f);
    holder.ivScreenOther.setVisibility(rule.screen_other && rule.other_blocked ? View.VISIBLE : View.INVISIBLE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivScreenOther.getDrawable());
        DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed);
    }
    holder.tvRoaming.setTextColor(rule.apply ? colorOff : colorGrayed);
    holder.tvRoaming.setAlpha(otherActive ? 1 : 0.5f);
    holder.tvRoaming.setVisibility(rule.roaming && (!rule.other_blocked || rule.screen_other) ? View.VISIBLE : View.INVISIBLE);
    // Expanded configuration section
    holder.llConfiguration.setVisibility(rule.expanded ? View.VISIBLE : View.GONE);
    // Show application details
    holder.tvUid.setText(rule.info.applicationInfo == null ? "?" : Integer.toString(rule.info.applicationInfo.uid));
    holder.tvPackage.setText(rule.info.packageName);
    holder.tvVersion.setText(rule.info.versionName + '/' + rule.info.versionCode);
    holder.tvDescription.setVisibility(rule.description == null ? View.GONE : View.VISIBLE);
    holder.tvDescription.setText(rule.description);
    // Show application state
    holder.tvInternet.setVisibility(rule.internet ? View.GONE : View.VISIBLE);
    holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE);
    // Show related
    holder.btnRelated.setVisibility(rule.relateduids ? View.VISIBLE : View.GONE);
    holder.btnRelated.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent main = new Intent(context, ActivityMain.class);
            main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(rule.info.applicationInfo.uid));
            context.startActivity(main);
        }
    });
    // Launch application settings
    holder.ibSettings.setVisibility(rule.settings == null ? View.GONE : View.VISIBLE);
    holder.ibSettings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            context.startActivity(rule.settings);
        }
    });
    // Data saver
    holder.ibDatasaver.setVisibility(rule.datasaver == null ? View.GONE : View.VISIBLE);
    holder.ibDatasaver.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            context.startActivity(rule.datasaver);
        }
    });
    // Launch application
    holder.ibLaunch.setVisibility(rule.launch == null ? View.GONE : View.VISIBLE);
    holder.ibLaunch.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            context.startActivity(rule.launch);
        }
    });
    // Apply
    holder.cbApply.setEnabled(rule.pkg);
    holder.cbApply.setOnCheckedChangeListener(null);
    holder.cbApply.setChecked(rule.apply);
    holder.cbApply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.apply = isChecked;
            updateRule(rule, true, listAll);
        }
    });
    // Show Wi-Fi screen on condition
    holder.llScreenWifi.setVisibility(screen_on ? View.VISIBLE : View.GONE);
    holder.cbScreenWifi.setEnabled(rule.wifi_blocked && rule.apply);
    holder.cbScreenWifi.setOnCheckedChangeListener(null);
    holder.cbScreenWifi.setChecked(rule.screen_wifi);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivWifiLegend.getDrawable());
        DrawableCompat.setTint(wrap, colorOn);
    }
    holder.cbScreenWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.screen_wifi = isChecked;
            updateRule(rule, true, listAll);
        }
    });
    // Show mobile screen on condition
    holder.llScreenOther.setVisibility(screen_on ? View.VISIBLE : View.GONE);
    holder.cbScreenOther.setEnabled(rule.other_blocked && rule.apply);
    holder.cbScreenOther.setOnCheckedChangeListener(null);
    holder.cbScreenOther.setChecked(rule.screen_other);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivOtherLegend.getDrawable());
        DrawableCompat.setTint(wrap, colorOn);
    }
    holder.cbScreenOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.screen_other = isChecked;
            updateRule(rule, true, listAll);
        }
    });
    // Show roaming condition
    holder.cbRoaming.setEnabled((!rule.other_blocked || rule.screen_other) && rule.apply);
    holder.cbRoaming.setOnCheckedChangeListener(null);
    holder.cbRoaming.setChecked(rule.roaming);
    holder.cbRoaming.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        @TargetApi(Build.VERSION_CODES.M)
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.roaming = isChecked;
            updateRule(rule, true, listAll);
            // Request permissions
            if (isChecked && !Util.hasPhoneStatePermission(context))
                context.requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, ActivityMain.REQUEST_ROAMING);
        }
    });
    // Show lockdown
    holder.cbLockdown.setEnabled(rule.apply);
    holder.cbLockdown.setOnCheckedChangeListener(null);
    holder.cbLockdown.setChecked(rule.lockdown);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivLockdownLegend.getDrawable());
        DrawableCompat.setTint(wrap, colorOn);
    }
    holder.cbLockdown.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        @TargetApi(Build.VERSION_CODES.M)
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.lockdown = isChecked;
            updateRule(rule, true, listAll);
        }
    });
    // Reset rule
    holder.btnClear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Util.areYouSure(view.getContext(), R.string.msg_clear_rules, new Util.DoubtListener() {

                @Override
                public void onSure() {
                    holder.cbApply.setChecked(true);
                    holder.cbWifi.setChecked(rule.wifi_default);
                    holder.cbOther.setChecked(rule.other_default);
                    holder.cbScreenWifi.setChecked(rule.screen_wifi_default);
                    holder.cbScreenOther.setChecked(rule.screen_other_default);
                    holder.cbRoaming.setChecked(rule.roaming_default);
                    holder.cbLockdown.setChecked(false);
                }
            });
        }
    });
    holder.llFilter.setVisibility(Util.canFilter(context) ? View.VISIBLE : View.GONE);
    // Live
    holder.ivLive.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            live = !live;
            TypedValue tv = new TypedValue();
            view.getContext().getTheme().resolveAttribute(live ? R.attr.iconPause : R.attr.iconPlay, tv, true);
            holder.ivLive.setImageResource(tv.resourceId);
            if (live)
                AdapterRule.this.notifyDataSetChanged();
        }
    });
    // Show logging/filtering is disabled
    final boolean log_app = prefs.getBoolean("log_app", false);
    final boolean filter = prefs.getBoolean("filter", false);
    holder.tvLogging.setText(log_app && filter ? R.string.title_logging_enabled : R.string.title_logging_disabled);
    holder.btnLogging.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = LayoutInflater.from(context);
            View view = inflater.inflate(R.layout.enable, null, false);
            final CheckBox cbLogging = (CheckBox) view.findViewById(R.id.cbLogging);
            final CheckBox cbFiltering = (CheckBox) view.findViewById(R.id.cbFiltering);
            TextView tvFilter4 = (TextView) view.findViewById(R.id.tvFilter4);
            cbLogging.setChecked(log_app);
            cbFiltering.setChecked(filter);
            cbFiltering.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
            tvFilter4.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? View.GONE : View.VISIBLE);
            cbLogging.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
                    prefs.edit().putBoolean("log_app", checked).apply();
                    AdapterRule.this.notifyDataSetChanged();
                }
            });
            cbFiltering.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
                    if (checked)
                        cbLogging.setChecked(true);
                    prefs.edit().putBoolean("filter", checked).apply();
                    ServiceSinkhole.reload("changed filter", context);
                    AdapterRule.this.notifyDataSetChanged();
                }
            });
            AlertDialog dialog = new AlertDialog.Builder(context).setView(view).setCancelable(true).create();
            dialog.show();
        }
    });
    // Show access rules
    if (rule.expanded) {
        // Access the database when expanded only
        final AdapterAccess badapter = new AdapterAccess(context, DatabaseHelper.getInstance(context).getAccess(rule.info.applicationInfo.uid));
        holder.lvAccess.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int bposition, long bid) {
                PackageManager pm = context.getPackageManager();
                Cursor cursor = (Cursor) badapter.getItem(bposition);
                final long id = cursor.getLong(cursor.getColumnIndex("ID"));
                final int version = cursor.getInt(cursor.getColumnIndex("version"));
                final int protocol = cursor.getInt(cursor.getColumnIndex("protocol"));
                final String daddr = cursor.getString(cursor.getColumnIndex("daddr"));
                final int dport = cursor.getInt(cursor.getColumnIndex("dport"));
                long time = cursor.getLong(cursor.getColumnIndex("time"));
                int block = cursor.getInt(cursor.getColumnIndex("block"));
                PopupMenu popup = new PopupMenu(context, context.findViewById(R.id.vwPopupAnchor));
                popup.inflate(R.menu.access);
                popup.getMenu().findItem(R.id.menu_host).setTitle(Util.getProtocolName(protocol, version, false) + " " + daddr + (dport > 0 ? "/" + dport : ""));
                SubMenu sub = popup.getMenu().findItem(R.id.menu_host).getSubMenu();
                boolean multiple = false;
                Cursor alt = null;
                try {
                    alt = DatabaseHelper.getInstance(context).getAlternateQNames(daddr);
                    while (alt.moveToNext()) {
                        multiple = true;
                        sub.add(Menu.NONE, Menu.NONE, 0, alt.getString(0)).setEnabled(false);
                    }
                } finally {
                    if (alt != null)
                        alt.close();
                }
                popup.getMenu().findItem(R.id.menu_host).setEnabled(multiple);
                markPro(popup.getMenu().findItem(R.id.menu_allow), ActivityPro.SKU_FILTER);
                markPro(popup.getMenu().findItem(R.id.menu_block), ActivityPro.SKU_FILTER);
                // Whois
                final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + daddr));
                if (pm.resolveActivity(lookupIP, 0) == null)
                    popup.getMenu().removeItem(R.id.menu_whois);
                else
                    popup.getMenu().findItem(R.id.menu_whois).setTitle(context.getString(R.string.title_log_whois, daddr));
                // Lookup port
                final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + dport));
                if (dport <= 0 || pm.resolveActivity(lookupPort, 0) == null)
                    popup.getMenu().removeItem(R.id.menu_port);
                else
                    popup.getMenu().findItem(R.id.menu_port).setTitle(context.getString(R.string.title_log_port, dport));
                popup.getMenu().findItem(R.id.menu_time).setTitle(SimpleDateFormat.getDateTimeInstance().format(time));
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        int menu = menuItem.getItemId();
                        boolean result = false;
                        switch(menu) {
                            case R.id.menu_whois:
                                context.startActivity(lookupIP);
                                result = true;
                                break;
                            case R.id.menu_port:
                                context.startActivity(lookupPort);
                                result = true;
                                break;
                            case R.id.menu_allow:
                                if (IAB.isPurchased(ActivityPro.SKU_FILTER, context)) {
                                    DatabaseHelper.getInstance(context).setAccess(id, 0);
                                    ServiceSinkhole.reload("allow host", context);
                                } else
                                    context.startActivity(new Intent(context, ActivityPro.class));
                                result = true;
                                break;
                            case R.id.menu_block:
                                if (IAB.isPurchased(ActivityPro.SKU_FILTER, context)) {
                                    DatabaseHelper.getInstance(context).setAccess(id, 1);
                                    ServiceSinkhole.reload("block host", context);
                                } else
                                    context.startActivity(new Intent(context, ActivityPro.class));
                                result = true;
                                break;
                            case R.id.menu_reset:
                                DatabaseHelper.getInstance(context).setAccess(id, -1);
                                ServiceSinkhole.reload("reset host", context);
                                result = true;
                                break;
                        }
                        if (menu == R.id.menu_allow || menu == R.id.menu_block || menu == R.id.menu_reset)
                            new AsyncTask<Object, Object, Long>() {

                                @Override
                                protected Long doInBackground(Object... objects) {
                                    return DatabaseHelper.getInstance(context).getHostCount(rule.info.applicationInfo.uid, false);
                                }

                                @Override
                                protected void onPostExecute(Long hosts) {
                                    rule.hosts = hosts;
                                    notifyDataSetChanged();
                                }
                            }.execute();
                        return result;
                    }
                });
                if (block == 0)
                    popup.getMenu().removeItem(R.id.menu_allow);
                else if (block == 1)
                    popup.getMenu().removeItem(R.id.menu_block);
                popup.show();
            }
        });
        holder.lvAccess.setAdapter(badapter);
    } else {
        holder.lvAccess.setAdapter(null);
        holder.lvAccess.setOnItemClickListener(null);
    }
    // Clear access log
    holder.btnClearAccess.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Util.areYouSure(view.getContext(), R.string.msg_reset_access, new Util.DoubtListener() {

                @Override
                public void onSure() {
                    DatabaseHelper.getInstance(context).clearAccess(rule.info.applicationInfo.uid, true);
                    if (!live)
                        notifyDataSetChanged();
                    if (rv != null)
                        rv.scrollToPosition(position);
                }
            });
        }
    });
    // Notify on access
    holder.cbNotify.setEnabled(prefs.getBoolean("notify_access", false) && rule.apply);
    holder.cbNotify.setOnCheckedChangeListener(null);
    holder.cbNotify.setChecked(rule.notify);
    holder.cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.notify = isChecked;
            updateRule(rule, true, listAll);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) SpannableStringBuilder(android.text.SpannableStringBuilder) SubMenu(android.view.SubMenu) Cursor(android.database.Cursor) Uri(android.net.Uri) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) SharedPreferences(android.content.SharedPreferences) Drawable(android.graphics.drawable.Drawable) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) TargetApi(android.annotation.TargetApi) CompoundButton(android.widget.CompoundButton) PopupMenu(android.widget.PopupMenu)

Example 64 with SubMenu

use of android.view.SubMenu in project android_frameworks_base by AOSPA.

the class ShareActionProvider method onPrepareSubMenu.

/**
     * {@inheritDoc}
     */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();
    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);
    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
    }
    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount, mContext.getString(R.string.activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager)).setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) SubMenu(android.view.SubMenu)

Example 65 with SubMenu

use of android.view.SubMenu in project android_frameworks_base by AOSPA.

the class Editor method onCreateContextMenu.

void onCreateContextMenu(ContextMenu menu) {
    if (mIsBeingLongClicked || Float.isNaN(mContextMenuAnchorX) || Float.isNaN(mContextMenuAnchorY)) {
        return;
    }
    final int offset = mTextView.getOffsetForPosition(mContextMenuAnchorX, mContextMenuAnchorY);
    if (offset == -1) {
        return;
    }
    stopTextActionModeWithPreservingSelection();
    final boolean isOnSelection = mTextView.hasSelection() && offset >= mTextView.getSelectionStart() && offset <= mTextView.getSelectionEnd();
    if (!isOnSelection) {
        // Right clicked position is not on the selection. Remove the selection and move the
        // cursor to the right clicked position.
        Selection.setSelection((Spannable) mTextView.getText(), offset);
        stopTextActionMode();
    }
    if (shouldOfferToShowSuggestions()) {
        final SuggestionInfo[] suggestionInfoArray = new SuggestionInfo[SuggestionSpan.SUGGESTIONS_MAX_SIZE];
        for (int i = 0; i < suggestionInfoArray.length; i++) {
            suggestionInfoArray[i] = new SuggestionInfo();
        }
        final SubMenu subMenu = menu.addSubMenu(Menu.NONE, Menu.NONE, MENU_ITEM_ORDER_REPLACE, com.android.internal.R.string.replace);
        final int numItems = mSuggestionHelper.getSuggestionInfo(suggestionInfoArray, null);
        for (int i = 0; i < numItems; i++) {
            final SuggestionInfo info = suggestionInfoArray[i];
            subMenu.add(Menu.NONE, Menu.NONE, i, info.mText).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    replaceWithSuggestion(info);
                    return true;
                }
            });
        }
    }
    menu.add(Menu.NONE, TextView.ID_UNDO, MENU_ITEM_ORDER_UNDO, com.android.internal.R.string.undo).setAlphabeticShortcut('z').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canUndo());
    menu.add(Menu.NONE, TextView.ID_REDO, MENU_ITEM_ORDER_REDO, com.android.internal.R.string.redo).setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canRedo());
    menu.add(Menu.NONE, TextView.ID_CUT, MENU_ITEM_ORDER_CUT, com.android.internal.R.string.cut).setAlphabeticShortcut('x').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canCut());
    menu.add(Menu.NONE, TextView.ID_COPY, MENU_ITEM_ORDER_COPY, com.android.internal.R.string.copy).setAlphabeticShortcut('c').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canCopy());
    menu.add(Menu.NONE, TextView.ID_PASTE, MENU_ITEM_ORDER_PASTE, com.android.internal.R.string.paste).setAlphabeticShortcut('v').setEnabled(mTextView.canPaste()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    menu.add(Menu.NONE, TextView.ID_PASTE, MENU_ITEM_ORDER_PASTE_AS_PLAIN_TEXT, com.android.internal.R.string.paste_as_plain_text).setEnabled(mTextView.canPaste()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    menu.add(Menu.NONE, TextView.ID_SHARE, MENU_ITEM_ORDER_SHARE, com.android.internal.R.string.share).setEnabled(mTextView.canShare()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    menu.add(Menu.NONE, TextView.ID_SELECT_ALL, MENU_ITEM_ORDER_SELECT_ALL, com.android.internal.R.string.selectAll).setAlphabeticShortcut('a').setEnabled(mTextView.canSelectAllText()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
    mPreserveSelection = true;
}
Also used : SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) Paint(android.graphics.Paint)

Aggregations

SubMenu (android.view.SubMenu)80 MenuItem (android.view.MenuItem)38 View (android.view.View)11 LayoutInflater (android.view.LayoutInflater)10 PackageManager (android.content.pm.PackageManager)9 Bundle (android.os.Bundle)9 Nullable (android.support.annotation.Nullable)9 ViewGroup (android.view.ViewGroup)9 R (com.simplecity.amp_library.R)9 UpgradeDialog (com.simplecity.amp_library.ui.dialog.UpgradeDialog)9 SelectableViewModel (com.simplecity.amp_library.ui.modelviews.SelectableViewModel)9 ContextualToolbar (com.simplecity.amp_library.ui.views.ContextualToolbar)9 ContextualToolbarHelper (com.simplecity.amp_library.utils.ContextualToolbarHelper)9 MenuUtils (com.simplecity.amp_library.utils.MenuUtils)9 PlaylistUtils (com.simplecity.amp_library.utils.PlaylistUtils)9 ViewModel (com.simplecityapps.recycler_adapter.model.ViewModel)9 Disposable (io.reactivex.disposables.Disposable)9 ResolveInfo (android.content.pm.ResolveInfo)8 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)8 RecyclerListener (com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener)8