Search in sources :

Example 26 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project actor-platform by actorapp.

the class GroupInfoFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    chatId = getArguments().getInt(EXTRA_CHAT_ID);
    groupVM = groups().get(chatId);
    View res = inflater.inflate(R.layout.fragment_group, container, false);
    listView = (RecyclerListView) res.findViewById(R.id.groupList);
    notMemberView = res.findViewById(R.id.notMember);
    res.setBackgroundColor(style.getMainBackgroundColor());
    // listView.setBackgroundColor(style.getMainBackgroundColor());
    notMemberView.setBackgroundColor(style.getMainBackgroundColor());
    ((TextView) notMemberView.findViewById(R.id.not_member_text)).setTextColor(style.getTextPrimaryColor());
    //
    // Header
    //
    // Views
    View header = inflater.inflate(R.layout.fragment_group_header, listView, false);
    TextView title = (TextView) header.findViewById(R.id.title);
    TextView subtitle = (TextView) header.findViewById(R.id.subtitle);
    avatarView = (AvatarView) header.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(48), 22);
    TextView aboutTV = (TextView) header.findViewById(R.id.about);
    View shortNameCont = header.findViewById(R.id.shortNameContainer);
    TextView shortNameView = (TextView) header.findViewById(R.id.shortName);
    TextView shortLinkView = (TextView) header.findViewById(R.id.shortNameLink);
    TextView addMember = (TextView) header.findViewById(R.id.addMemberAction);
    addMember.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
    TextView members = (TextView) header.findViewById(R.id.viewMembersAction);
    TextView leaveAction = (TextView) header.findViewById(R.id.leaveAction);
    TextView administrationAction = (TextView) header.findViewById(R.id.administrationAction);
    View descriptionContainer = header.findViewById(R.id.descriptionContainer);
    SwitchCompat isNotificationsEnabled = (SwitchCompat) header.findViewById(R.id.enableNotifications);
    // Styling
    // ((TextView) header.findViewById(R.id.about_hint)).setTextColor(style.getTextSecondaryColor());
    header.setBackgroundColor(style.getMainBackgroundColor());
    header.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
    title.setTextColor(style.getProfileTitleColor());
    subtitle.setTextColor(style.getProfileSubtitleColor());
    aboutTV.setTextColor(style.getTextPrimaryColor());
    shortNameView.setTextColor(style.getTextPrimaryColor());
    shortLinkView.setTextColor(style.getTextSecondaryColor());
    // settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    ((TintImageView) header.findViewById(R.id.settings_notification_icon)).setTint(style.getSettingsIconColor());
    ((TintImageView) header.findViewById(R.id.settings_about_icon)).setTint(style.getSettingsIconColor());
    ((TextView) header.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
    ((TextView) header.findViewById(R.id.addMemberAction)).setTextColor(style.getTextPrimaryColor());
    members.setTextColor(style.getTextPrimaryColor());
    administrationAction.setTextColor(style.getTextPrimaryColor());
    leaveAction.setTextColor(style.getTextDangerColor());
    if (groupVM.getGroupType() == GroupType.CHANNEL) {
        leaveAction.setText(R.string.group_leave_channel);
    } else {
        leaveAction.setText(R.string.group_leave);
    }
    header.findViewById(R.id.after_settings_divider).setBackgroundColor(style.getBackyardBackgroundColor());
    //
    // Header
    //
    avatarView.bind(groupVM.getAvatar().get(), groupVM.getName().get(), groupVM.getId());
    avatarView.setOnClickListener(view -> {
        if (groupVM.getAvatar().get() != null) {
            startActivity(ViewAvatarActivity.viewGroupAvatar(chatId, getActivity()));
        }
    });
    bind(groupVM.getName(), name -> {
        title.setText(name);
    });
    bind(groupVM.getMembersCount(), val -> {
        subtitle.setText(messenger().getFormatter().formatGroupMembers(val));
    });
    // About
    bind(groupVM.getAbout(), (about) -> {
        aboutTV.setText(about);
        aboutTV.setVisibility(about != null ? View.VISIBLE : View.GONE);
    });
    bind(groupVM.getShortName(), shortName -> {
        if (shortName != null) {
            shortNameView.setText("@" + shortName);
            String prefix = ActorSDK.sharedActor().getGroupInvitePrefix();
            if (prefix != null) {
                shortLinkView.setText(prefix + shortName);
                shortLinkView.setVisibility(View.VISIBLE);
            } else {
                shortLinkView.setVisibility(View.GONE);
            }
        }
        shortNameCont.setVisibility(shortName != null ? View.VISIBLE : View.GONE);
    });
    final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    shortNameCont.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String link = shortLinkView.getText().toString();
            clipboard.setPrimaryClip(ClipData.newPlainText(null, (link.contains("://") ? "" : "https://") + link));
            Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
        }
    });
    bind(groupVM.getAbout(), groupVM.getShortName(), (about, shortName) -> {
        descriptionContainer.setVisibility(about != null || shortName != null ? View.VISIBLE : View.GONE);
    });
    // Notifications
    isNotificationsEnabled.setChecked(messenger().isNotificationsEnabled(Peer.group(chatId)));
    isNotificationsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> {
        messenger().changeNotificationsEnabled(Peer.group(chatId), isChecked);
    });
    header.findViewById(R.id.notificationsCont).setOnClickListener(v -> {
        isNotificationsEnabled.setChecked(!isNotificationsEnabled.isChecked());
    });
    // Add Member
    bind(groupVM.getIsCanInviteMembers(), (canInvite) -> {
        if (canInvite) {
            addMember.setVisibility(View.VISIBLE);
        } else {
            addMember.setVisibility(View.GONE);
        }
    });
    addMember.setOnClickListener(view -> {
        startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
    });
    // Administration
    if (groupVM.getIsCanEditAdministration().get() || groupVM.getIsCanDelete().get()) {
        administrationAction.setOnClickListener(view -> {
            startActivity(new Intent(getActivity(), GroupAdminActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
        });
    } else {
        administrationAction.setVisibility(View.GONE);
    }
    // Async Members
    // Showing member only when members available and async members is enabled
    bind(groupVM.getIsCanViewMembers(), groupVM.getIsAsyncMembers(), (canViewMembers, vm1, isAsync, vm2) -> {
        if (canViewMembers) {
            if (isAsync) {
                members.setVisibility(View.VISIBLE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
            } else {
                members.setVisibility(View.GONE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.VISIBLE);
            }
        } else {
            members.setVisibility(View.GONE);
            header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
        }
    });
    members.setOnClickListener(view -> {
        startActivity(new Intent(getContext(), MembersActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupVM.getId()));
    });
    // Leave
    bind(groupVM.getIsCanLeave(), canLeave -> {
        if (canLeave) {
            leaveAction.setVisibility(View.VISIBLE);
            leaveAction.setOnClickListener(view1 -> {
                new AlertDialog.Builder(getActivity()).setMessage(getString(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.alert_leave_channel_message : R.string.alert_leave_group_message).replace("%1$s", groupVM.getName().get())).setPositiveButton(R.string.alert_leave_group_yes, (dialog2, which) -> {
                    execute(messenger().leaveAndDeleteGroup(chatId).then(aVoid -> ActorSDK.returnToRoot(getActivity())));
                }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
            });
        } else {
            leaveAction.setVisibility(View.GONE);
        }
    });
    listView.addHeaderView(header, null, false);
    //
    // Members
    //
    groupUserAdapter = new MembersAdapter(getActivity(), getArguments().getInt("groupId"));
    listView.setAdapter(groupUserAdapter);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        Object item = parent.getItemAtPosition(position);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    startActivity(Intents.openPrivateDialog(userVM.getId(), true, getActivity()));
                }
            }
        }
    });
    listView.setOnItemLongClickListener((adapterView, view, i, l) -> {
        Object item = adapterView.getItemAtPosition(i);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    groupUserAdapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
                    return true;
                }
            }
        }
        return false;
    });
    //
    // Scroll handling
    //
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem >= 1) {
                updateBar(Integer.MAX_VALUE);
            } else {
                View top = listView.getChildAt(0);
                if (top != null) {
                    updateBar(-top.getTop());
                } else {
                    updateBar(Integer.MAX_VALUE);
                }
            }
        }
    });
    //
    // Placeholder
    //
    bind(groupVM.isMember(), (isMember) -> {
        notMemberView.setVisibility(isMember ? View.GONE : View.VISIBLE);
        getActivity().invalidateOptionsMenu();
    });
    // Menu
    bind(groupVM.getIsCanEditInfo(), canEditInfo -> {
        getActivity().invalidateOptionsMenu();
    });
    return res;
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) Bundle(android.os.Bundle) ViewAvatarActivity(im.actor.sdk.controllers.fragment.preview.ViewAvatarActivity) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) ColorDrawable(android.graphics.drawable.ColorDrawable) Screen(im.actor.sdk.util.Screen) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) ClipboardManager(android.content.ClipboardManager) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Intents(im.actor.sdk.controllers.Intents) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) Void(im.actor.runtime.actors.messages.Void) GroupMember(im.actor.core.entity.GroupMember) UserPhone(im.actor.core.viewmodel.UserPhone) SwitchCompat(android.support.v7.widget.SwitchCompat) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) Peer(im.actor.core.entity.Peer) ActorStyle(im.actor.sdk.ActorStyle) Context(android.content.Context) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) TintImageView(im.actor.sdk.view.TintImageView) Intent(android.content.Intent) GroupVM(im.actor.core.viewmodel.GroupVM) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) AvatarView(im.actor.sdk.view.avatar.AvatarView) ActionBar(android.support.v7.app.ActionBar) GroupType(im.actor.core.entity.GroupType) ActorSDK(im.actor.sdk.ActorSDK) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) AbsListView(android.widget.AbsListView) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) Color(android.graphics.Color) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) GroupMember(im.actor.core.entity.GroupMember) TintImageView(im.actor.sdk.view.TintImageView) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) TextView(android.widget.TextView) TintImageView(im.actor.sdk.view.TintImageView) AvatarView(im.actor.sdk.view.avatar.AvatarView) AbsListView(android.widget.AbsListView) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 27 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project android by owncloud.

the class ShareFileFragment method initShareViaLinkListener.

/**
     * Binds listener for user actions to create or delete a public share
     * to the views receiving the user events.
     *
     * @param shareView Root view in the fragment.
     */
private void initShareViaLinkListener(View shareView) {
    mOnShareViaLinkSwitchCheckedChangeListener = new OnShareViaLinkListener();
    SwitchCompat shareViaLinkSwitch = (SwitchCompat) shareView.findViewById(R.id.shareViaLinkSectionSwitch);
    shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener);
}
Also used : SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 28 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project AndroidChromium by JackyAndroid.

the class ChromeSwitchPreference method onBindView.

@Override
protected void onBindView(View view) {
    super.onBindView(view);
    if (mDrawDivider) {
        int left = view.getPaddingLeft();
        int right = view.getPaddingRight();
        int top = view.getPaddingTop();
        int bottom = view.getPaddingBottom();
        view.setBackground(DividerDrawable.create(getContext()));
        view.setPadding(left, top, right, bottom);
    }
    SwitchCompat switchView = (SwitchCompat) view.findViewById(R.id.switch_widget);
    // null check below. http://crbug.com/451447
    if (switchView != null) {
        switchView.setChecked(isChecked());
    }
    TextView title = (TextView) view.findViewById(android.R.id.title);
    title.setSingleLine(false);
    if (!mDontUseSummaryAsTitle && TextUtils.isEmpty(getTitle())) {
        TextView summary = (TextView) view.findViewById(android.R.id.summary);
        title.setText(summary.getText());
        title.setVisibility(View.VISIBLE);
        summary.setVisibility(View.GONE);
    }
    if (mManagedPrefDelegate != null)
        mManagedPrefDelegate.onBindViewToPreference(this, view);
}
Also used : TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 29 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project LeafPic by HoraApps.

the class MainActivity method onOptionsItemSelected.

//endregion
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.select_all:
            if (albumsMode) {
                if (getAlbums().getSelectedCount() == albumsAdapter.getItemCount()) {
                    editMode = false;
                    getAlbums().clearSelectedAlbums();
                } else
                    getAlbums().selectAllAlbums();
                albumsAdapter.notifyDataSetChanged();
            } else {
                if (getAlbum().getSelectedCount() == mediaAdapter.getItemCount()) {
                    editMode = false;
                    getAlbum().clearSelectedPhotos();
                } else
                    getAlbum().selectAllPhotos();
                mediaAdapter.notifyDataSetChanged();
            }
            invalidateOptionsMenu();
            return true;
        case R.id.set_pin_album:
            getAlbums().getSelectedAlbum(0).settings.togglePin(getApplicationContext());
            getAlbums().sortAlbums(getApplicationContext());
            getAlbums().clearSelectedAlbums();
            albumsAdapter.swapDataSet(getAlbums().dispAlbums);
            invalidateOptionsMenu();
            return true;
        case R.id.settings:
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            return true;
        case R.id.installShortcut:
            getAlbums().installShortcutForSelectedAlbums(this.getApplicationContext());
            finishEditMode();
            return true;
        case R.id.hideAlbumButton:
            final AlertDialog.Builder hideDialogBuilder = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
            AlertDialogsHelper.getTextDialog(MainActivity.this, hideDialogBuilder, hidden ? R.string.unhide : R.string.hide, hidden ? R.string.unhide_album_message : R.string.hide_album_message);
            hideDialogBuilder.setPositiveButton(getString(hidden ? R.string.unhide : R.string.hide).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    if (albumsMode) {
                        if (hidden)
                            getAlbums().unHideSelectedAlbums(getApplicationContext());
                        else
                            getAlbums().hideSelectedAlbums(getApplicationContext());
                        albumsAdapter.notifyDataSetChanged();
                        invalidateOptionsMenu();
                    } else {
                        if (hidden)
                            getAlbums().unHideAlbum(getAlbum().getPath(), getApplicationContext());
                        else
                            getAlbums().hideAlbum(getAlbum().getPath(), getApplicationContext());
                        displayAlbums(true);
                    }
                }
            });
            if (!hidden) {
                hideDialogBuilder.setNeutralButton(this.getString(R.string.exclude).toUpperCase(), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (albumsMode) {
                            getAlbums().excludeSelectedAlbums(getApplicationContext());
                            albumsAdapter.notifyDataSetChanged();
                            invalidateOptionsMenu();
                        } else {
                            customAlbumsHelper.excludeAlbum(getAlbum().getPath());
                            displayAlbums(true);
                        }
                    }
                });
            }
            hideDialogBuilder.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            hideDialogBuilder.show();
            return true;
        case R.id.delete_action:
            class DeletePhotos extends AsyncTask<String, Integer, Boolean> {

                @Override
                protected void onPreExecute() {
                    swipeRefreshLayout.setRefreshing(true);
                    super.onPreExecute();
                }

                @Override
                protected Boolean doInBackground(String... arg0) {
                    if (albumsMode)
                        return getAlbums().deleteSelectedAlbums(MainActivity.this);
                    else {
                        if (editMode)
                            return getAlbum().deleteSelectedMedia(getApplicationContext());
                        else {
                            boolean succ = getAlbums().deleteAlbum(getAlbum(), getApplicationContext());
                            getAlbum().getMedia().clear();
                            return succ;
                        }
                    }
                }

                @Override
                protected void onPostExecute(Boolean result) {
                    if (result) {
                        if (albumsMode) {
                            getAlbums().clearSelectedAlbums();
                            albumsAdapter.notifyDataSetChanged();
                        } else {
                            if (getAlbum().getMedia().size() == 0) {
                                getAlbums().removeCurrentAlbum();
                                albumsAdapter.notifyDataSetChanged();
                                displayAlbums();
                            } else
                                mediaAdapter.swapDataSet(getAlbum().getMedia());
                        }
                    } else
                        requestSdCardPermissions();
                    invalidateOptionsMenu();
                    checkNothing();
                    swipeRefreshLayout.setRefreshing(false);
                }
            }
            AlertDialog.Builder deleteDialog = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
            AlertDialogsHelper.getTextDialog(this, deleteDialog, R.string.delete, albumsMode || !editMode ? R.string.delete_album_message : R.string.delete_photos_message);
            deleteDialog.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            deleteDialog.setPositiveButton(this.getString(R.string.delete).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    if (securityObj.isActiveSecurity() && securityObj.isPasswordOnDelete()) {
                        AlertDialog.Builder passwordDialogBuilder = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
                        final EditText editTextPassword = securityObj.getInsertPasswordDialog(MainActivity.this, passwordDialogBuilder);
                        passwordDialogBuilder.setNegativeButton(getString(R.string.cancel).toUpperCase(), null);
                        passwordDialogBuilder.setPositiveButton(getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            //This should br empty it will be overwrite later
                            //to avoid dismiss of the dialog on wrong password
                            }
                        });
                        final AlertDialog passwordDialog = passwordDialogBuilder.create();
                        passwordDialog.show();
                        passwordDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (securityObj.checkPassword(editTextPassword.getText().toString())) {
                                    passwordDialog.dismiss();
                                    new DeletePhotos().execute();
                                } else {
                                    Toast.makeText(getApplicationContext(), R.string.wrong_password, Toast.LENGTH_SHORT).show();
                                    editTextPassword.getText().clear();
                                    editTextPassword.requestFocus();
                                }
                            }
                        });
                    } else
                        new DeletePhotos().execute();
                }
            });
            deleteDialog.show();
            return true;
        case R.id.excludeAlbumButton:
            final AlertDialog.Builder excludeDialogBuilder = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
            final View excludeDialogLayout = getLayoutInflater().inflate(R.layout.dialog_exclude, null);
            TextView textViewExcludeTitle = (TextView) excludeDialogLayout.findViewById(R.id.text_dialog_title);
            TextView textViewExcludeMessage = (TextView) excludeDialogLayout.findViewById(R.id.text_dialog_message);
            final Spinner spinnerParents = (Spinner) excludeDialogLayout.findViewById(R.id.parents_folder);
            spinnerParents.getBackground().setColorFilter(getIconColor(), PorterDuff.Mode.SRC_ATOP);
            ((CardView) excludeDialogLayout.findViewById(R.id.message_card)).setCardBackgroundColor(getCardBackgroundColor());
            textViewExcludeTitle.setBackgroundColor(getPrimaryColor());
            textViewExcludeTitle.setText(getString(R.string.exclude));
            if ((albumsMode && getAlbums().getSelectedCount() > 1)) {
                textViewExcludeMessage.setText(R.string.exclude_albums_message);
                spinnerParents.setVisibility(View.GONE);
            } else {
                textViewExcludeMessage.setText(R.string.exclude_album_message);
                spinnerParents.setAdapter(getSpinnerAdapter(albumsMode ? getAlbums().getSelectedAlbum(0).getParentsFolders() : getAlbum().getParentsFolders()));
            }
            textViewExcludeMessage.setTextColor(getTextColor());
            excludeDialogBuilder.setView(excludeDialogLayout);
            excludeDialogBuilder.setPositiveButton(this.getString(R.string.exclude).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    if ((albumsMode && getAlbums().getSelectedCount() > 1)) {
                        getAlbums().excludeSelectedAlbums(getApplicationContext());
                        albumsAdapter.notifyDataSetChanged();
                        invalidateOptionsMenu();
                    } else {
                        customAlbumsHelper.excludeAlbum(spinnerParents.getSelectedItem().toString());
                        finishEditMode();
                        displayAlbums(true);
                    }
                }
            });
            excludeDialogBuilder.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            excludeDialogBuilder.show();
            return true;
        case R.id.sharePhotos:
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND_MULTIPLE);
            intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sent_to_action));
            ArrayList<Uri> files = new ArrayList<Uri>();
            for (Media f : getAlbum().getSelectedMedia()) files.add(f.getUri());
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
            intent.setType(StringUtils.getGenericMIME(getAlbum().getSelectedMedia(0).getMimeType()));
            finishEditMode();
            startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to)));
            return true;
        case R.id.all_media_filter:
            if (!albumsMode) {
                getAlbum().filterMedias(getApplicationContext(), FilterMode.ALL);
                mediaAdapter.swapDataSet(getAlbum().getMedia());
                item.setChecked(true);
                checkNothing();
            }
            return true;
        case R.id.video_media_filter:
            if (!albumsMode) {
                getAlbum().filterMedias(getApplicationContext(), FilterMode.VIDEO);
                mediaAdapter.swapDataSet(getAlbum().getMedia());
                item.setChecked(true);
                checkNothing();
            }
            return true;
        case R.id.image_media_filter:
            if (!albumsMode) {
                getAlbum().filterMedias(getApplicationContext(), FilterMode.IMAGES);
                mediaAdapter.swapDataSet(getAlbum().getMedia());
                item.setChecked(true);
                checkNothing();
            }
            return true;
        case R.id.gifs_media_filter:
            if (!albumsMode) {
                getAlbum().filterMedias(getApplicationContext(), FilterMode.GIF);
                mediaAdapter.swapDataSet(getAlbum().getMedia());
                item.setChecked(true);
                checkNothing();
            }
            return true;
        case R.id.name_sort_action:
            if (albumsMode) {
                getAlbums().setDefaultSortingMode(SortingMode.NAME);
                getAlbums().sortAlbums(getApplicationContext());
                albumsAdapter.swapDataSet(getAlbums().dispAlbums);
            } else {
                getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.NAME);
                getAlbum().sortPhotos();
                mediaAdapter.swapDataSet(getAlbum().getMedia());
            }
            item.setChecked(true);
            return true;
        case R.id.date_taken_sort_action:
            if (albumsMode) {
                getAlbums().setDefaultSortingMode(SortingMode.DATE);
                getAlbums().sortAlbums(getApplicationContext());
                albumsAdapter.swapDataSet(getAlbums().dispAlbums);
            } else {
                getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.DATE);
                getAlbum().sortPhotos();
                mediaAdapter.swapDataSet(getAlbum().getMedia());
            }
            item.setChecked(true);
            return true;
        case R.id.size_sort_action:
            if (albumsMode) {
                getAlbums().setDefaultSortingMode(SortingMode.SIZE);
                getAlbums().sortAlbums(getApplicationContext());
                albumsAdapter.swapDataSet(getAlbums().dispAlbums);
            } else {
                getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.SIZE);
                getAlbum().sortPhotos();
                mediaAdapter.swapDataSet(getAlbum().getMedia());
            }
            item.setChecked(true);
            return true;
        case R.id.type_sort_action:
            if (!albumsMode) {
                getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.TYPE);
                getAlbum().sortPhotos();
                mediaAdapter.swapDataSet(getAlbum().getMedia());
                item.setChecked(true);
            }
            return true;
        case R.id.numeric_sort_action:
            if (albumsMode) {
                getAlbums().setDefaultSortingMode(SortingMode.NUMERIC);
                getAlbums().sortAlbums(getApplicationContext());
                albumsAdapter.swapDataSet(getAlbums().dispAlbums);
            } else {
                getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.NUMERIC);
                getAlbum().sortPhotos();
                mediaAdapter.swapDataSet(getAlbum().getMedia());
            }
            item.setChecked(true);
            return true;
        case R.id.ascending_sort_action:
            if (albumsMode) {
                getAlbums().setDefaultSortingAscending(item.isChecked() ? SortingOrder.DESCENDING : SortingOrder.ASCENDING);
                getAlbums().sortAlbums(getApplicationContext());
                albumsAdapter.swapDataSet(getAlbums().dispAlbums);
            } else {
                getAlbum().setDefaultSortingAscending(getApplicationContext(), item.isChecked() ? SortingOrder.DESCENDING : SortingOrder.ASCENDING);
                getAlbum().sortPhotos();
                mediaAdapter.swapDataSet(getAlbum().getMedia());
            }
            item.setChecked(!item.isChecked());
            return true;
        //region Affix
        case R.id.affixPhoto:
            //region Async MediaAffix
            class affixMedia extends AsyncTask<Affix.Options, Integer, Void> {

                private AlertDialog dialog;

                @Override
                protected void onPreExecute() {
                    AlertDialog.Builder progressDialog = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
                    dialog = AlertDialogsHelper.getProgressDialog(MainActivity.this, progressDialog, getString(R.string.affix), getString(R.string.affix_text));
                    dialog.show();
                    super.onPreExecute();
                }

                @Override
                protected Void doInBackground(Affix.Options... arg0) {
                    ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
                    for (int i = 0; i < getAlbum().getSelectedCount(); i++) {
                        if (!getAlbum().getSelectedMedia(i).isVideo())
                            bitmapArray.add(getAlbum().getSelectedMedia(i).getBitmap());
                    }
                    if (bitmapArray.size() > 1)
                        Affix.AffixBitmapList(getApplicationContext(), bitmapArray, arg0[0]);
                    else
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(), R.string.affix_error, Toast.LENGTH_SHORT).show();
                            }
                        });
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    editMode = false;
                    getAlbum().clearSelectedPhotos();
                    dialog.dismiss();
                    invalidateOptionsMenu();
                    mediaAdapter.notifyDataSetChanged();
                    new PreparePhotosTask().execute();
                }
            }
            //endregion
            final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
            final View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_affix, null);
            dialogLayout.findViewById(R.id.affix_title).setBackgroundColor(getPrimaryColor());
            ((CardView) dialogLayout.findViewById(R.id.affix_card)).setCardBackgroundColor(getCardBackgroundColor());
            //ITEMS
            final SwitchCompat swVertical = (SwitchCompat) dialogLayout.findViewById(R.id.affix_vertical_switch);
            final SwitchCompat swSaveHere = (SwitchCompat) dialogLayout.findViewById(R.id.save_here_switch);
            final RadioGroup radioFormatGroup = (RadioGroup) dialogLayout.findViewById(R.id.radio_format);
            final TextView txtQuality = (TextView) dialogLayout.findViewById(R.id.affix_quality_title);
            final SeekBar seekQuality = (SeekBar) dialogLayout.findViewById(R.id.seek_bar_quality);
            //region THEME STUFF
            setScrollViewColor((ScrollView) dialogLayout.findViewById(R.id.affix_scrollView));
            /** TextViews **/
            int color = getTextColor();
            ((TextView) dialogLayout.findViewById(R.id.affix_vertical_title)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.compression_settings_title)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.save_here_title)).setTextColor(color);
            /** Sub TextViews **/
            color = getTextColor();
            ((TextView) dialogLayout.findViewById(R.id.save_here_sub)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_vertical_sub)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_format_sub)).setTextColor(color);
            txtQuality.setTextColor(color);
            /** Icons **/
            color = getIconColor();
            ((IconicsImageView) dialogLayout.findViewById(R.id.affix_quality_icon)).setColor(color);
            ((IconicsImageView) dialogLayout.findViewById(R.id.affix_format_icon)).setColor(color);
            ((IconicsImageView) dialogLayout.findViewById(R.id.affix_vertical_icon)).setColor(color);
            ((IconicsImageView) dialogLayout.findViewById(R.id.save_here_icon)).setColor(color);
            seekQuality.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
            seekQuality.getThumb().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
            updateRadioButtonColor((RadioButton) dialogLayout.findViewById(R.id.radio_jpeg));
            updateRadioButtonColor((RadioButton) dialogLayout.findViewById(R.id.radio_png));
            updateRadioButtonColor((RadioButton) dialogLayout.findViewById(R.id.radio_webp));
            updateSwitchColor(swVertical, getAccentColor());
            updateSwitchColor(swSaveHere, getAccentColor());
            //endregion
            seekQuality.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    txtQuality.setText(Html.fromHtml(String.format(Locale.getDefault(), "%s <b>%d</b>", getString(R.string.quality), progress)));
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }
            });
            //DEFAULT
            seekQuality.setProgress(90);
            swVertical.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    updateSwitchColor(swVertical, getAccentColor());
                }
            });
            swSaveHere.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    updateSwitchColor(swSaveHere, getAccentColor());
                }
            });
            builder.setView(dialogLayout);
            builder.setPositiveButton(this.getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {
                    Bitmap.CompressFormat compressFormat;
                    switch(radioFormatGroup.getCheckedRadioButtonId()) {
                        case R.id.radio_jpeg:
                        default:
                            compressFormat = Bitmap.CompressFormat.JPEG;
                            break;
                        case R.id.radio_png:
                            compressFormat = Bitmap.CompressFormat.PNG;
                            break;
                        case R.id.radio_webp:
                            compressFormat = Bitmap.CompressFormat.WEBP;
                            break;
                    }
                    Affix.Options options = new Affix.Options(swSaveHere.isChecked() ? getAlbum().getPath() : Affix.getDefaultDirectoryPath(), compressFormat, seekQuality.getProgress(), swVertical.isChecked());
                    new affixMedia().execute(options);
                }
            });
            builder.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
            builder.show();
            return true;
        case R.id.action_move:
            bottomSheetDialogFragment = new SelectAlbumBottomSheet();
            bottomSheetDialogFragment.setTitle(getString(R.string.move_to));
            bottomSheetDialogFragment.setSelectAlbumInterface(new SelectAlbumBottomSheet.SelectAlbumInterface() {

                @Override
                public void folderSelected(String path) {
                    swipeRefreshLayout.setRefreshing(true);
                    if (getAlbum().moveSelectedMedia(getApplicationContext(), path) > 0) {
                        if (getAlbum().getMedia().size() == 0) {
                            getAlbums().removeCurrentAlbum();
                            albumsAdapter.notifyDataSetChanged();
                            displayAlbums();
                        }
                        mediaAdapter.swapDataSet(getAlbum().getMedia());
                        finishEditMode();
                        invalidateOptionsMenu();
                    } else
                        requestSdCardPermissions();
                    swipeRefreshLayout.setRefreshing(false);
                    bottomSheetDialogFragment.dismiss();
                }
            });
            bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
            return true;
        case R.id.action_copy:
            bottomSheetDialogFragment = new SelectAlbumBottomSheet();
            bottomSheetDialogFragment.setTitle(getString(R.string.copy_to));
            bottomSheetDialogFragment.setSelectAlbumInterface(new SelectAlbumBottomSheet.SelectAlbumInterface() {

                @Override
                public void folderSelected(String path) {
                    boolean success = getAlbum().copySelectedPhotos(getApplicationContext(), path);
                    finishEditMode();
                    bottomSheetDialogFragment.dismiss();
                    if (!success)
                        requestSdCardPermissions();
                }
            });
            bottomSheetDialogFragment.show(getSupportFragmentManager(), bottomSheetDialogFragment.getTag());
            return true;
        case R.id.renameAlbum:
            AlertDialog.Builder renameDialogBuilder = new AlertDialog.Builder(MainActivity.this, getDialogStyle());
            final EditText editTextNewName = new EditText(getApplicationContext());
            editTextNewName.setText(albumsMode ? getAlbums().getSelectedAlbum(0).getName() : getAlbum().getName());
            AlertDialogsHelper.getInsertTextDialog(MainActivity.this, renameDialogBuilder, editTextNewName, R.string.rename_album);
            renameDialogBuilder.setNegativeButton(getString(R.string.cancel).toUpperCase(), null);
            renameDialogBuilder.setPositiveButton(getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                //This should br empty it will be overwrite later
                //to avoid dismiss of the dialog
                }
            });
            final AlertDialog renameDialog = renameDialogBuilder.create();
            renameDialog.show();
            renameDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View dialog) {
                    if (editTextNewName.length() != 0) {
                        swipeRefreshLayout.setRefreshing(true);
                        boolean success;
                        if (albumsMode) {
                            int index = getAlbums().dispAlbums.indexOf(getAlbums().getSelectedAlbum(0));
                            getAlbums().getAlbum(index).updatePhotos(getApplicationContext());
                            success = getAlbums().getAlbum(index).renameAlbum(getApplicationContext(), editTextNewName.getText().toString());
                            albumsAdapter.notifyItemChanged(index);
                        } else {
                            success = getAlbum().renameAlbum(getApplicationContext(), editTextNewName.getText().toString());
                            toolbar.setTitle(getAlbum().getName());
                            mediaAdapter.notifyDataSetChanged();
                        }
                        renameDialog.dismiss();
                        if (!success)
                            requestSdCardPermissions();
                        swipeRefreshLayout.setRefreshing(false);
                    } else {
                        StringUtils.showToast(getApplicationContext(), getString(R.string.insert_something));
                        editTextNewName.requestFocus();
                    }
                }
            });
            return true;
        case R.id.clear_album_preview:
            if (!albumsMode) {
                getAlbum().removeCoverAlbum(getApplicationContext());
            }
            return true;
        case R.id.setAsAlbumPreview:
            if (!albumsMode) {
                getAlbum().setSelectedPhotoAsPreview(getApplicationContext());
                finishEditMode();
            }
            return true;
        default:
            // Invoke the superclass to handle it.
            return super.onOptionsItemSelected(item);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) RadioGroup(android.widget.RadioGroup) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Uri(android.net.Uri) SelectAlbumBottomSheet(org.horaapps.leafpic.SelectAlbumBottomSheet) Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) AsyncTask(android.os.AsyncTask) CardView(android.support.v7.widget.CardView) Media(org.horaapps.leafpic.data.Media) Intent(android.content.Intent) SearchView(android.support.v7.widget.SearchView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) Affix(org.horaapps.leafpic.util.Affix) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 30 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project LeafPic by HoraApps.

the class SettingsActivity method onPostCreate.

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    SP = PreferenceUtil.getInstance(getApplicationContext());
    securityObj = new SecurityHelper(SettingsActivity.this);
    txtTT = (TextView) findViewById(R.id.theme_setting_title);
    txtGT = (TextView) findViewById(R.id.general_setting_title);
    txtPT = (TextView) findViewById(R.id.picture_setting_title);
    txtVT = (TextView) findViewById(R.id.video_setting_title);
    txtAT = (TextView) findViewById(R.id.advanced_setting_title);
    scr = (ScrollView) findViewById(R.id.settingAct_scrollView);
    /*** BASIC THEME ***/
    findViewById(R.id.ll_basic_theme).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            baseThemeDialog();
        }
    });
    /*** SECURITY ***/
    findViewById(R.id.ll_security).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!securityObj.isActiveSecurity())
                startActivity(new Intent(getApplicationContext(), SecurityActivity.class));
            else
                askPasswordDialog();
        }
    });
    /*** PRIMARY COLOR PIKER ***/
    findViewById(R.id.ll_primaryColor).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            primaryColorPiker();
        }
    });
    /*** ACCENT COLOR PIKER ***/
    findViewById(R.id.ll_accentColor).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            accentColorPiker();
        }
    });
    /*** EXCLUDED ALBUMS INTENT ***/
    findViewById(R.id.ll_excluded_album).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(SettingsActivity.this, ExcludedAlbumsActivity.class));
        }
    });
    /*** CUSTOMIZE PICTURE VIEWER DIALOG ***/
    findViewById(R.id.ll_custom_thirdAct).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            customizePictureViewer();
        }
    });
    /*** MAP PROVIDER DIALOG ***/
    findViewById(R.id.ll_map_provider).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mapProviderDialog();
        }
    });
    /*** MULTI COLUMN DIALOG ***/
    findViewById(R.id.ll_n_columns).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            multiColumnsDialog();
        }
    });
    /*** SW Show Fab ***/
    swShowFab = (SwitchCompat) findViewById(R.id.sw_show_fab);
    swShowFab.setChecked(SP.getBoolean(getString(R.string.preference_show_fab), false));
    swShowFab.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_show_fab), isChecked);
            updateSwitchColor(swShowFab, getAccentColor());
        }
    });
    /*** SW Show Fab ***/
    swSubScaling = (SwitchCompat) findViewById(R.id.sw_sub_scaling);
    swSubScaling.setChecked(SP.getBoolean(getString(R.string.preference_sub_scaling), false));
    swSubScaling.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_sub_scaling), isChecked);
            updateSwitchColor(swSubScaling, getAccentColor());
        }
    });
    /*** SW Internal Player ***/
    swInternalBrowser = (SwitchCompat) findViewById(R.id.set_internal_player);
    swInternalBrowser.setChecked(SP.getBoolean(getString(R.string.preference_internal_player), false));
    swInternalBrowser.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_internal_player), isChecked);
            new Thread(new Runnable() {

                @Override
                public void run() {
                    ((MyApplication) getApplicationContext()).updateAlbums();
                }
            }).start();
            updateSwitchColor(swInternalBrowser, getAccentColor());
        }
    });
    /*** SW INCLUDE VIDEO ***/
    swIncludeVideo = (SwitchCompat) findViewById(R.id.set_include_video);
    swIncludeVideo.setChecked(SP.getBoolean(getString(R.string.preference_include_video), true));
    swIncludeVideo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_include_video), isChecked);
            updateSwitchColor(swIncludeVideo, getAccentColor());
        }
    });
    /*** SW SWIPE DIRECTION ***/
    swSwipeDirection = (SwitchCompat) findViewById(R.id.Set_media_viewer_swipe_direction);
    swSwipeDirection.setChecked(SP.getBoolean(getString(R.string.preference_swipe_direction_inverted), false));
    swSwipeDirection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_swipe_direction_inverted), isChecked);
            updateSwitchColor(swSwipeDirection, getAccentColor());
        }
    });
    /*** SW AUTO UPDATE MEDIA ***/
    swAutoUpdate = (SwitchCompat) findViewById(R.id.SetAutoUpdateMedia);
    swAutoUpdate.setChecked(SP.getBoolean(getString(R.string.preference_auto_update_media), false));
    swAutoUpdate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_auto_update_media), isChecked);
            updateSwitchColor(swAutoUpdate, getAccentColor());
        }
    });
    /*** SW MEDIA STORE ***/
    swUseMediaStore = (SwitchCompat) findViewById(R.id.sw_use_media_mediastore);
    swUseMediaStore.setChecked(SP.getBoolean(getString(R.string.preference_use_alternative_provider), false));
    swUseMediaStore.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_use_alternative_provider), isChecked);
            updateSwitchColor(swUseMediaStore, getAccentColor());
        }
    });
    /*** SW DELAY FULL-SIZE IMAGE ***/
    swDelayFullImage = (SwitchCompat) findViewById(R.id.set_full_resolution);
    swDelayFullImage.setChecked(SP.getBoolean(getString(R.string.preference_delay_full_image), true));
    swDelayFullImage.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_delay_full_image), isChecked);
            updateSwitchColor(swDelayFullImage, getAccentColor());
        }
    });
    /*** SW PICTURE ORIENTATION ***/
    swPictureOrientation = (SwitchCompat) findViewById(R.id.set_picture_orientation);
    swPictureOrientation.setChecked(SP.getBoolean(getString(R.string.preference_auto_rotate), false));
    swPictureOrientation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_auto_rotate), isChecked);
            updateSwitchColor(swPictureOrientation, getAccentColor());
        }
    });
    /*** SW MAX LUMINOSITY ***/
    swMaxLuminosity = (SwitchCompat) findViewById(R.id.set_max_luminosity);
    swMaxLuminosity.setChecked(SP.getBoolean(getString(R.string.preference_max_brightness), false));
    swMaxLuminosity.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_max_brightness), isChecked);
            updateSwitchColor(swMaxLuminosity, getAccentColor());
        }
    });
    /*** SW TRANSLUCENT STATUS BAR ***/
    swStatusBar = (SwitchCompat) findViewById(R.id.SetTraslucentStatusBar);
    swStatusBar.setChecked(SP.getBoolean(getString(R.string.preference_translucent_status_bar), true));
    swStatusBar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_translucent_status_bar), isChecked);
            updateTheme();
            setStatusBarColor();
            updateSwitchColor(swStatusBar, getAccentColor());
        }
    });
    /*** SW COLORED NAV BAR ***/
    swNavBar = (SwitchCompat) findViewById(R.id.SetColoredNavBar);
    swNavBar.setChecked(SP.getBoolean(getString(R.string.preference_colored_nav_bar), false));
    swNavBar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SP.putBoolean(getString(R.string.preference_colored_nav_bar), isChecked);
            updateTheme();
            updateSwitchColor(swNavBar, getAccentColor());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                getWindow().setNavigationBarColor(isNavigationBarColored() ? getPrimaryColor() : ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));
        }
    });
}
Also used : Intent(android.content.Intent) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) IconicsImageView(com.mikepenz.iconics.view.IconicsImageView) CompoundButton(android.widget.CompoundButton) SecurityHelper(org.horaapps.leafpic.util.SecurityHelper)

Aggregations

SwitchCompat (android.support.v7.widget.SwitchCompat)33 TextView (android.widget.TextView)25 View (android.view.View)24 CompoundButton (android.widget.CompoundButton)20 Intent (android.content.Intent)10 AlertDialog (android.support.v7.app.AlertDialog)8 ImageView (android.widget.ImageView)8 DialogInterface (android.content.DialogInterface)7 CardView (android.support.v7.widget.CardView)6 MenuItem (android.view.MenuItem)6 ScrollView (android.widget.ScrollView)6 AdapterView (android.widget.AdapterView)5 LinearLayout (android.widget.LinearLayout)5 SeekBar (android.widget.SeekBar)5 SearchView (android.support.v7.widget.SearchView)4 Button (android.widget.Button)4 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)4 ArrayList (java.util.ArrayList)4 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3 Uri (android.net.Uri)3