Search in sources :

Example 41 with ActionMode

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

the class StatusBarWindowView method startActionMode.

private ActionMode startActionMode(View originatingView, ActionMode.Callback callback, int type) {
    ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
    ActionMode mode = createFloatingActionMode(originatingView, wrappedCallback);
    if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
        setHandledFloatingActionMode(mode);
    } else {
        mode = null;
    }
    return mode;
}
Also used : ActionMode(android.view.ActionMode) FloatingActionMode(com.android.internal.view.FloatingActionMode)

Example 42 with ActionMode

use of android.view.ActionMode in project android_frameworks_base by DirtyUnicorns.

the class DecorView method startActionMode.

private ActionMode startActionMode(View originatingView, ActionMode.Callback callback, int type) {
    ActionMode.Callback2 wrappedCallback = new ActionModeCallback2Wrapper(callback);
    ActionMode mode = null;
    if (mWindow.getCallback() != null && !mWindow.isDestroyed()) {
        try {
            mode = mWindow.getCallback().onWindowStartingActionMode(wrappedCallback, type);
        } catch (AbstractMethodError ame) {
            // Older apps might not implement the typed version of this method.
            if (type == ActionMode.TYPE_PRIMARY) {
                try {
                    mode = mWindow.getCallback().onWindowStartingActionMode(wrappedCallback);
                } catch (AbstractMethodError ame2) {
                // Older apps might not implement this callback method at all.
                }
            }
        }
    }
    if (mode != null) {
        if (mode.getType() == ActionMode.TYPE_PRIMARY) {
            cleanupPrimaryActionMode();
            mPrimaryActionMode = mode;
        } else if (mode.getType() == ActionMode.TYPE_FLOATING) {
            if (mFloatingActionMode != null) {
                mFloatingActionMode.finish();
            }
            mFloatingActionMode = mode;
        }
    } else {
        mode = createActionMode(type, wrappedCallback, originatingView);
        if (mode != null && wrappedCallback.onCreateActionMode(mode, mode.getMenu())) {
            setHandledActionMode(mode);
        } else {
            mode = null;
        }
    }
    if (mode != null && mWindow.getCallback() != null && !mWindow.isDestroyed()) {
        try {
            mWindow.getCallback().onActionModeStarted(mode);
        } catch (AbstractMethodError ame) {
        // Older apps might not implement this callback method.
        }
    }
    return mode;
}
Also used : ActionMode(android.view.ActionMode) StandaloneActionMode(com.android.internal.view.StandaloneActionMode) FloatingActionMode(com.android.internal.view.FloatingActionMode)

Example 43 with ActionMode

use of android.view.ActionMode in project ocreader by schaal.

the class ListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_list);
    setSupportActionBar(binding.toolbarLayout.toolbar);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    binding.swipeRefreshLayout.setColorSchemeResources(R.color.primary);
    binding.swipeRefreshLayout.setOnRefreshListener(this);
    profileDrawerItem = new ProfileDrawerItem().withName(preferences.getString(Preferences.USERNAME.getKey(), getString(R.string.app_name))).withEmail(Preferences.URL.getString(preferences));
    updateUserProfile();
    IProfile profileSettingsItem = new ProfileSettingDrawerItem().withName(getString(R.string.account_settings)).withIconTinted(true).withIcon(R.drawable.ic_settings).withTag((Runnable) () -> {
        Intent loginIntent = new Intent(ListActivity.this, LoginActivity.class);
        startActivityForResult(loginIntent, LoginActivity.REQUEST_CODE);
    });
    accountHeader = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header_background).addProfiles(profileDrawerItem, profileSettingsItem).withCurrentProfileHiddenInList(true).withProfileImagesClickable(false).withSavedInstance(savedInstanceState).withOnAccountHeaderListener((view, profile, current) -> {
        if (profile instanceof Tagable) {
            Tagable tagable = (Tagable) profile;
            if (tagable.getTag() instanceof Runnable) {
                ((Runnable) tagable.getTag()).run();
                return false;
            }
        }
        return true;
    }).build();
    refreshDrawerItem = new PrimaryDrawerItem().withName(getString(R.string.action_sync)).withSelectable(false).withIconTintingEnabled(true).withIcon(R.drawable.ic_refresh).withIdentifier(REFRESH_DRAWER_ITEM_ID).withTag((Runnable) () -> SyncService.startSync(ListActivity.this));
    IDrawerItem settingsDrawerItem = new PrimaryDrawerItem().withName(R.string.settings).withIcon(R.drawable.ic_settings).withIconTintingEnabled(true).withSelectable(false).withTag((Runnable) () -> {
        startDrawer.closeDrawer();
        Intent settingsIntent = new Intent(ListActivity.this, SettingsActivity.class);
        startActivity(settingsIntent);
    });
    DrawerBuilder startDrawerBuilder = new DrawerBuilder().withActivity(this).withAccountHeader(accountHeader).addStickyDrawerItems(settingsDrawerItem, refreshDrawerItem).withOnDrawerListener(new Drawer.OnDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            drawerManager.getStartAdapter().updateUnreadCount(getRealm(), isShowOnlyUnread());
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    }).withOnDrawerItemClickListener((view, position, drawerItem) -> {
        if (drawerItem.getTag() instanceof TreeItem) {
            TreeItem item = (TreeItem) drawerItem.getTag();
            onStartDrawerItemClicked(item);
            return false;
        } else if (drawerItem.getTag() instanceof Runnable) {
            ((Runnable) drawerItem.getTag()).run();
        }
        return true;
    }).withSavedInstance(savedInstanceState);
    DrawerBuilder endDrawerBuilder = new DrawerBuilder().withActivity(this).withDrawerGravity(Gravity.END).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).withOnDrawerListener(new Drawer.OnDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            drawerManager.getEndAdapter().updateUnreadCount(getRealm(), isShowOnlyUnread());
        }

        @Override
        public void onDrawerClosed(View drawerView) {
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    }).withOnDrawerItemClickListener((view, position, drawerItem) -> {
        if (drawerItem.getTag() instanceof Feed) {
            Feed feed = (Feed) drawerItem.getTag();
            onEndDrawerItemClicked(feed);
            return false;
        }
        return true;
    });
    startDrawerBuilder.withToolbar(binding.toolbarLayout.toolbar);
    startDrawer = startDrawerBuilder.build();
    drawerManager = new DrawerManager(this, startDrawer, endDrawerBuilder.append(startDrawer), unreadSwitchListener);
    layoutManager = new LinearLayoutManager(this);
    adapter = new ErrorAdapter(this, getRealm(), drawerManager.getState(), this, this);
    binding.fabMarkAllAsRead.setOnClickListener(new View.OnClickListener() {

        private void onCompletion(View view) {
            adapter.updateItems(false);
            view.setEnabled(true);
            binding.fabMarkAllAsRead.toggleSync();
        }

        @Override
        public void onClick(final View view) {
            if (binding.fabMarkAllAsRead.isSync()) {
                SyncService.startSync(ListActivity.this);
                binding.fabMarkAllAsRead.toggleSync();
            } else {
                Queries.markTemporaryFeedAsRead(getRealm(), () -> onCompletion(view), error -> {
                    Log.e(TAG, "Failed to mark temporary feed as read", error);
                    onCompletion(view);
                });
            }
        }
    });
    binding.fabMarkAllAsRead.setOnLongClickListener(v -> {
        Toast.makeText(ListActivity.this, R.string.mark_all_as_read, Toast.LENGTH_SHORT).show();
        return true;
    });
    binding.itemsRecyclerview.setAdapter(adapter);
    binding.itemsRecyclerview.setLayoutManager(layoutManager);
    if (savedInstanceState == null && getIntent().hasExtra(SyncService.EXTRA_ID)) {
        drawerManager.getState().restore(getRealm(), getIntent().getIntExtra(SyncService.EXTRA_ID, -10), null, false);
    } else {
        drawerManager.getState().restoreInstanceState(getRealm(), getPreferences(MODE_PRIVATE));
    }
    binding.itemsRecyclerview.addItemDecoration(new DividerItemDecoration(this, R.dimen.divider_inset));
    adapter.updateItems(false);
    if (savedInstanceState != null) {
        layoutManager.onRestoreInstanceState(savedInstanceState.getParcelable(LAYOUT_MANAGER_STATE));
        adapter.onRestoreInstanceState(savedInstanceState);
        if (adapter.getSelectedItemsCount() > 0) {
            actionMode = startActionMode(this);
        }
    }
    drawerManager.reloadAdapters(getRealm(), isShowOnlyUnread());
    // noinspection ConstantConditions
    getSupportActionBar().setTitle(drawerManager.getState().getTreeItem().getName());
}
Also used : ActionMode(android.view.ActionMode) Bundle(android.os.Bundle) OnCheckedChangeListener(com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener) Libs(com.mikepenz.aboutlibraries.Libs) DividerItemDecoration(email.schaal.ocreader.view.DividerItemDecoration) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) ActivityListBinding(email.schaal.ocreader.databinding.ActivityListBinding) Tagable(com.mikepenz.materialdrawer.model.interfaces.Tagable) Base64InputStream(android.util.Base64InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Item(email.schaal.ocreader.database.model.Item) TemporaryFeed(email.schaal.ocreader.database.model.TemporaryFeed) View(android.view.View) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) PreferenceManager(android.preference.PreferenceManager) SyncType(email.schaal.ocreader.service.SyncType) Log(android.util.Log) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) ContextCompat(android.support.v4.content.ContextCompat) AllUnreadFolder(email.schaal.ocreader.database.model.AllUnreadFolder) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) BroadcastReceiver(android.content.BroadcastReceiver) Queries(email.schaal.ocreader.database.Queries) ErrorAdapter(email.schaal.ocreader.view.ErrorAdapter) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Nullable(android.support.annotation.Nullable) Snackbar(android.support.design.widget.Snackbar) Context(android.content.Context) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) NonNull(android.support.annotation.NonNull) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) TreeItem(email.schaal.ocreader.database.model.TreeItem) MenuItem(android.view.MenuItem) SyncService(email.schaal.ocreader.service.SyncService) Drawer(com.mikepenz.materialdrawer.Drawer) Toast(android.widget.Toast) Menu(android.view.Menu) User(email.schaal.ocreader.database.model.User) DrawerManager(email.schaal.ocreader.view.drawer.DrawerManager) DrawerLayout(android.support.v4.widget.DrawerLayout) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) Feed(email.schaal.ocreader.database.model.Feed) LoadMoreAdapter(email.schaal.ocreader.view.LoadMoreAdapter) CompoundButton(android.widget.CompoundButton) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Bitmap(android.graphics.Bitmap) DataBindingUtil(android.databinding.DataBindingUtil) Base64(android.util.Base64) ItemViewHolder(email.schaal.ocreader.view.ItemViewHolder) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Activity(android.app.Activity) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) ErrorAdapter(email.schaal.ocreader.view.ErrorAdapter) TreeItem(email.schaal.ocreader.database.model.TreeItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) TemporaryFeed(email.schaal.ocreader.database.model.TemporaryFeed) Feed(email.schaal.ocreader.database.model.Feed) DrawerManager(email.schaal.ocreader.view.drawer.DrawerManager) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) DividerItemDecoration(email.schaal.ocreader.view.DividerItemDecoration) View(android.view.View) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Tagable(com.mikepenz.materialdrawer.model.interfaces.Tagable)

Example 44 with ActionMode

use of android.view.ActionMode in project Pix-Art-Messenger by kriztan.

the class ChooseContactActivity method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    filterContacts = new HashSet<>();
    String[] contacts = getIntent().getStringArrayExtra("filter_contacts");
    if (contacts != null) {
        Collections.addAll(filterContacts, contacts);
    }
    if (getIntent().getBooleanExtra("multiple", false)) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.select_multiple, menu);
                selected = new HashSet<>();
                return true;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch(item.getItemId()) {
                    case R.id.selection_submit:
                        final Intent request = getIntent();
                        final Intent data = new Intent();
                        data.putExtra("conversation", request.getStringExtra("conversation"));
                        String[] selection = getSelectedContactJids();
                        data.putExtra("contacts", selection);
                        data.putExtra("multiple", true);
                        data.putExtra(EXTRA_ACCOUNT, request.getStringExtra(EXTRA_ACCOUNT));
                        data.putExtra("subject", request.getStringExtra("subject"));
                        setResult(RESULT_OK, data);
                        finish();
                        return true;
                }
                return false;
            }

            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                Contact item = (Contact) getListItems().get(position);
                if (checked) {
                    selected.add(item);
                } else {
                    selected.remove(item);
                }
                int numSelected = selected.size();
                MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
                String buttonText = getResources().getQuantityString(R.plurals.select_contact, numSelected, numSelected);
                selectButton.setTitle(buttonText);
            }
        });
    }
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
            final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
            final Intent request = getIntent();
            final Intent data = new Intent();
            final ListItem mListItem = getListItems().get(position);
            data.putExtra("contact", mListItem.getJid().toString());
            String account = request.getStringExtra(EXTRA_ACCOUNT);
            if (account == null && mListItem instanceof Contact) {
                account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
            }
            data.putExtra(EXTRA_ACCOUNT, account);
            data.putExtra("conversation", request.getStringExtra("conversation"));
            data.putExtra("multiple", false);
            data.putExtra("subject", request.getStringExtra("subject"));
            setResult(RESULT_OK, data);
            finish();
        }
    });
}
Also used : MenuInflater(android.view.MenuInflater) InputMethodManager(android.view.inputmethod.InputMethodManager) MenuItem(android.view.MenuItem) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Contact(de.pixart.messenger.entities.Contact) ActionMode(android.view.ActionMode) AdapterView(android.widget.AdapterView) Menu(android.view.Menu) ListItem(de.pixart.messenger.entities.ListItem) MultiChoiceModeListener(android.widget.AbsListView.MultiChoiceModeListener) HashSet(java.util.HashSet)

Example 45 with ActionMode

use of android.view.ActionMode in project FileExplorer by MiCode.

the class FileViewInteractionHub method onListItemClick.

public void onListItemClick(AdapterView<?> parent, View view, int position, long id) {
    FileInfo lFileInfo = mFileViewListener.getItem(position);
    showDropdownNavigation(false);
    if (lFileInfo == null) {
        Log.e(LOG_TAG, "file does not exist on position:" + position);
        return;
    }
    if (isInSelection()) {
        boolean selected = lFileInfo.Selected;
        ActionMode actionMode = ((FileExplorerTabActivity) mContext).getActionMode();
        ImageView checkBox = (ImageView) view.findViewById(R.id.file_checkbox);
        if (selected) {
            mCheckedFileNameList.remove(lFileInfo);
            checkBox.setImageResource(R.drawable.btn_check_off_holo_light);
        } else {
            mCheckedFileNameList.add(lFileInfo);
            checkBox.setImageResource(R.drawable.btn_check_on_holo_light);
        }
        if (actionMode != null) {
            if (mCheckedFileNameList.size() == 0)
                actionMode.finish();
            else
                actionMode.invalidate();
        }
        lFileInfo.Selected = !selected;
        Util.updateActionModeTitle(actionMode, mContext, mCheckedFileNameList.size());
        return;
    }
    if (!lFileInfo.IsDir) {
        if (mCurrentMode == Mode.Pick) {
            mFileViewListener.onPick(lFileInfo);
        } else {
            viewFile(lFileInfo);
        }
        return;
    }
    mCurrentPath = getAbsoluteName(mCurrentPath, lFileInfo.fileName);
    ActionMode actionMode = ((FileExplorerTabActivity) mContext).getActionMode();
    if (actionMode != null) {
        actionMode.finish();
    }
    refreshFileList();
}
Also used : ActionMode(android.view.ActionMode) ImageView(android.widget.ImageView)

Aggregations

ActionMode (android.view.ActionMode)99 UiThreadTest (android.test.UiThreadTest)30 FloatingActionMode (com.android.internal.view.FloatingActionMode)15 StandaloneActionMode (com.android.internal.view.StandaloneActionMode)10 Menu (android.view.Menu)9 MenuItem (android.view.MenuItem)9 Animator (android.animation.Animator)6 Context (android.content.Context)6 Paint (android.graphics.Paint)6 View (android.view.View)6 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)5 ObjectAnimator (android.animation.ObjectAnimator)5 Resources (android.content.res.Resources)5 TypedValue (android.util.TypedValue)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 ViewStub (android.view.ViewStub)5 PopupWindow (android.widget.PopupWindow)5 ActionBarContextView (com.android.internal.widget.ActionBarContextView)5 MenuInflater (android.view.MenuInflater)4 AdapterView (android.widget.AdapterView)3