Search in sources :

Example 36 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project NetGuard by M66B.

the class ActivityMain method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());
    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }
    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    running = true;
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);
    // Upgrade
    Receiver.upgrade(initialized, this);
    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }
    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);
    swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);
    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });
    // Title
    getSupportActionBar().setTitle(null);
    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            int[] location = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivQueue.getLeft(), Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });
    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();
            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view).setCancelable(false).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (running) {
                                    Log.i(TAG, "Start intent=" + prepare);
                                    try {
                                        // com.android.vpndialogs.ConfirmDialog required
                                        startActivityForResult(prepare, REQUEST_VPN);
                                    } catch (Throwable ex) {
                                        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                        onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                        prefs.edit().putBoolean("enabled", false).apply();
                                    }
                                }
                            }
                        }).setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialogInterface) {
                                dialogVpn = null;
                            }
                        }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    prefs.edit().putBoolean("enabled", false).apply();
                }
            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();
    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            int[] location = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivMetered.getLeft(), Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);
    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
    // Application list
    RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    rvApplication.setHasFixedSize(true);
    rvApplication.setLayoutManager(new LinearLayoutManager(this));
    adapter = new AdapterRule(this);
    rvApplication.setAdapter(adapter);
    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            Rule.clearCache(ActivityMain.this);
            ServiceSinkhole.reload("pull", ActivityMain.this);
            updateApplicationList(null);
        }
    });
    // Hint usage
    final LinearLayout llUsage = (LinearLayout) findViewById(R.id.llUsage);
    Button btnUsage = (Button) findViewById(R.id.btnUsage);
    boolean hintUsage = prefs.getBoolean("hint_usage", true);
    llUsage.setVisibility(hintUsage ? View.VISIBLE : View.GONE);
    btnUsage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            prefs.edit().putBoolean("hint_usage", false).apply();
            llUsage.setVisibility(View.GONE);
            showHints();
        }
    });
    showHints();
    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);
    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);
    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);
    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);
    // First use
    boolean admob = prefs.getBoolean("admob", false);
    if (!initialized || !admob) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        TextView tvAdmob = (TextView) view.findViewById(R.id.tvAdmob);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());
        tvAdmob.setMovementMethod(LinkMovementMethod.getInstance());
        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false).setPositiveButton(R.string.app_agree, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (running) {
                    prefs.edit().putBoolean("initialized", true).apply();
                    prefs.edit().putBoolean("admob", true).apply();
                }
            }
        }).setNegativeButton(R.string.app_disagree, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (running)
                    finish();
            }
        }).setOnDismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialogInterface) {
                dialogFirst = null;
            }
        }).create();
        dialogFirst.show();
    }
    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));
    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {

            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();
                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_NOTIFY, ActivityMain.this))
                        prefs.edit().putBoolean("install", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
    // Initialize ads
    initAds();
    // Handle intent
    checkExtras(getIntent());
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Toast(android.widget.Toast) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) IntentFilter(android.content.IntentFilter) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AdView(com.google.android.gms.ads.AdView) RecyclerView(android.support.v7.widget.RecyclerView) LayoutInflater(android.view.LayoutInflater) RecyclerView(android.support.v7.widget.RecyclerView) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout)

Example 37 with SwitchCompat

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

the class RvMediaFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.all_media_filter:
            album.setFilterMode(FilterMode.ALL);
            item.setChecked(true);
            reload();
            return true;
        case R.id.video_media_filter:
            album.setFilterMode(FilterMode.VIDEO);
            item.setChecked(true);
            reload();
            return true;
        case R.id.image_media_filter:
            album.setFilterMode(FilterMode.IMAGES);
            item.setChecked(true);
            reload();
            return true;
        case R.id.gifs_media_filter:
            album.setFilterMode(FilterMode.GIF);
            item.setChecked(true);
            reload();
            return true;
        case R.id.sharePhotos:
            Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
            HashMap<String, Integer> types = new HashMap<>();
            ArrayList<Uri> files = new ArrayList<>();
            for (Media f : adapter.getSelected()) {
                String mimeType = MimeTypeUtils.getTypeMime(f.getMimeType());
                int count = 0;
                if (types.containsKey(mimeType)) {
                    count = types.get(mimeType);
                }
                types.put(mimeType, count);
                files.add(LegacyCompatFileProvider.getUri(getContext(), f.getFile()));
            }
            Set<String> fileTypes = types.keySet();
            if (fileTypes.size() > 1) {
                Toast.makeText(getContext(), R.string.waring_share_multiple_file_types, Toast.LENGTH_SHORT).show();
            }
            int max = -1;
            String type = null;
            for (String fileType : fileTypes) {
                Integer count = types.get(fileType);
                if (count > max) {
                    type = fileType;
                }
            }
            intent.setType(type + "/*");
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to)));
            return true;
        case R.id.set_as_cover:
            String path = adapter.getFirstSelected().getPath();
            album.setCover(path);
            db().setCover(album.getPath(), path);
            adapter.clearSelected();
            return true;
        case R.id.action_palette:
            Intent paletteIntent = new Intent(getActivity(), PaletteActivity.class);
            paletteIntent.setData(adapter.getFirstSelected().getUri());
            startActivity(paletteIntent);
            return true;
        case R.id.rename:
            final EditText editTextNewName = new EditText(getActivity());
            editTextNewName.setText(StringUtils.getPhotoNameByPath(adapter.getFirstSelected().getPath()));
            AlertDialog renameDialog = AlertDialogsHelper.getInsertTextDialog(((ThemedActivity) getActivity()), editTextNewName, R.string.rename_photo_action);
            renameDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), (dialog, which) -> {
                if (editTextNewName.length() != 0) {
                    boolean b = MediaHelper.renameMedia(getActivity(), adapter.getFirstSelected(), editTextNewName.getText().toString());
                    if (!b) {
                        StringUtils.showToast(getActivity(), getString(R.string.rename_error));
                    // adapter.notifyDataSetChanged();
                    } else
                        // Deselect media if rename successful
                        adapter.clearSelected();
                } else
                    StringUtils.showToast(getActivity(), getString(R.string.nothing_changed));
            });
            renameDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel).toUpperCase(), (dialog, which) -> dialog.dismiss());
            renameDialog.show();
            return true;
        case R.id.select_all:
            if (adapter.getSelectedCount() == adapter.getItemCount())
                adapter.clearSelected();
            else
                adapter.selectAll();
            return true;
        case R.id.name_sort_mode:
            adapter.changeSortingMode(SortingMode.NAME);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.NAME.getValue());
            album.setSortingMode(SortingMode.NAME);
            item.setChecked(true);
            return true;
        case R.id.date_taken_sort_mode:
            adapter.changeSortingMode(SortingMode.DATE);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.DATE.getValue());
            album.setSortingMode(SortingMode.DATE);
            item.setChecked(true);
            return true;
        case R.id.size_sort_mode:
            adapter.changeSortingMode(SortingMode.SIZE);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.SIZE.getValue());
            album.setSortingMode(SortingMode.SIZE);
            item.setChecked(true);
            return true;
        case R.id.numeric_sort_mode:
            adapter.changeSortingMode(SortingMode.NUMERIC);
            HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.NUMERIC.getValue());
            album.setSortingMode(SortingMode.NUMERIC);
            item.setChecked(true);
            return true;
        case R.id.ascending_sort_order:
            item.setChecked(!item.isChecked());
            SortingOrder sortingOrder = SortingOrder.fromValue(item.isChecked());
            adapter.changeSortingOrder(sortingOrder);
            HandlingAlbums.getInstance(getContext()).setSortingOrder(album.getPath(), sortingOrder.getValue());
            album.setSortingOrder(sortingOrder);
            return true;
        case R.id.delete:
            ProgressAdapter errorsAdapter = new ProgressAdapter(getContext());
            ArrayList<Media> selected = adapter.getSelected();
            AlertDialog alertDialog = AlertDialogsHelper.getProgressDialogWithErrors(((ThemedActivity) getActivity()), R.string.deleting_images, errorsAdapter, selected.size());
            alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.cancel).toUpperCase(), (dialog, id) -> {
                alertDialog.dismiss();
            });
            alertDialog.show();
            MediaHelper.deleteMedia(getContext(), selected).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(m -> {
                adapter.remove(m);
                errorsAdapter.add(new ProgressAdapter.ListItem(m.getName()), false);
            }, throwable -> {
                if (throwable instanceof DeleteException)
                    errorsAdapter.add(new ProgressAdapter.ListItem((DeleteException) throwable), true);
            }, () -> {
                if (errorsAdapter.getItemCount() == 0)
                    alertDialog.dismiss();
                adapter.clearSelected();
            });
            return true;
        // TODO: 11/21/16 move away from here
        case R.id.affix:
            // region Async MediaAffix
            class affixMedia extends AsyncTask<Affix.Options, Integer, Void> {

                private AlertDialog dialog;

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    dialog = AlertDialogsHelper.getProgressDialog((ThemedActivity) getActivity(), getString(R.string.affix), getString(R.string.affix_text));
                    dialog.show();
                }

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

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

                @Override
                protected void onPostExecute(Void result) {
                    adapter.clearSelected();
                    dialog.dismiss();
                }
            }
            // endregion
            final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), 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 = dialogLayout.findViewById(R.id.affix_vertical_switch);
            final SwitchCompat swSaveHere = dialogLayout.findViewById(R.id.save_here_switch);
            final LinearLayout llSwVertical = dialogLayout.findViewById(R.id.ll_affix_vertical);
            final LinearLayout llSwSaveHere = dialogLayout.findViewById(R.id.ll_affix_save_here);
            final RadioGroup radioFormatGroup = dialogLayout.findViewById(R.id.radio_format);
            final TextView txtQuality = dialogLayout.findViewById(R.id.affix_quality_title);
            final SeekBar seekQuality = dialogLayout.findViewById(R.id.seek_bar_quality);
            // region Example
            final LinearLayout llExample = dialogLayout.findViewById(R.id.affix_example);
            llExample.setBackgroundColor(getBackgroundColor());
            llExample.setVisibility(Hawk.get("show_tips", true) ? View.VISIBLE : View.GONE);
            final LinearLayout llExampleH = dialogLayout.findViewById(R.id.affix_example_horizontal);
            // llExampleH.setBackgroundColor(getCardBackgroundColor());
            final LinearLayout llExampleV = dialogLayout.findViewById(R.id.affix_example_vertical);
            // llExampleV.setBackgroundColor(getCardBackgroundColor());
            // endregion
            // region THEME STUFF
            getThemeHelper().setScrollViewColor(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);
            // Example Stuff
            ((TextView) dialogLayout.findViewById(R.id.affix_example_horizontal_txt1)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_example_horizontal_txt2)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_example_vertical_txt1)).setTextColor(color);
            ((TextView) dialogLayout.findViewById(R.id.affix_example_vertical_txt2)).setTextColor(color);
            /**
             * Sub TextViews *
             */
            color = getThemeHelper().getSubTextColor();
            ((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();
            ((ThemedIcon) dialogLayout.findViewById(R.id.affix_quality_icon)).setColor(color);
            ((ThemedIcon) dialogLayout.findViewById(R.id.affix_format_icon)).setColor(color);
            ((ThemedIcon) dialogLayout.findViewById(R.id.affix_vertical_icon)).setColor(color);
            ((ThemedIcon) dialogLayout.findViewById(R.id.save_here_icon)).setColor(color);
            // Example bg
            color = getCardBackgroundColor();
            dialogLayout.findViewById(R.id.affix_example_horizontal_txt1).setBackgroundColor(color);
            dialogLayout.findViewById(R.id.affix_example_horizontal_txt2).setBackgroundColor(color);
            dialogLayout.findViewById(R.id.affix_example_vertical_txt1).setBackgroundColor(color);
            dialogLayout.findViewById(R.id.affix_example_vertical_txt2).setBackgroundColor(color);
            seekQuality.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
            seekQuality.getThumb().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
            getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_jpeg));
            getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_png));
            getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_webp));
            getThemeHelper().setSwitchCompactColor(swSaveHere, getAccentColor());
            getThemeHelper().setSwitchCompactColor(swVertical, getAccentColor());
            // #endregion
            seekQuality.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    txtQuality.setText(StringUtils.html(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) {
                }
            });
            seekQuality.setProgress(50);
            swVertical.setClickable(false);
            llSwVertical.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    swVertical.setChecked(!swVertical.isChecked());
                    getThemeHelper().setSwitchCompactColor(swVertical, getAccentColor());
                    llExampleH.setVisibility(swVertical.isChecked() ? View.GONE : View.VISIBLE);
                    llExampleV.setVisibility(swVertical.isChecked() ? View.VISIBLE : View.GONE);
                }
            });
            swSaveHere.setClickable(false);
            llSwSaveHere.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    swSaveHere.setChecked(!swSaveHere.isChecked());
                    getThemeHelper().setSwitchCompactColor(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() ? adapter.getFirstSelected().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;
    }
    return super.onOptionsItemSelected(item);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) RadioGroup(android.widget.RadioGroup) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) DeleteException(org.horaapps.leafpic.util.file.DeleteException) ArrayList(java.util.ArrayList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) ThemedActivity(org.horaapps.liz.ThemedActivity) SortingOrder(org.horaapps.leafpic.data.sort.SortingOrder) TextView(android.widget.TextView) EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) Media(org.horaapps.leafpic.data.Media) AsyncTask(android.os.AsyncTask) CardView(android.support.v7.widget.CardView) Intent(android.content.Intent) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Affix(org.horaapps.leafpic.util.Affix) ThemedIcon(org.horaapps.liz.ui.ThemedIcon) ProgressAdapter(org.horaapps.leafpic.adapters.ProgressAdapter) LinearLayout(android.widget.LinearLayout) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 38 with SwitchCompat

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

the class SecurityActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_security);
    llroot = (LinearLayout) findViewById(R.id.root);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    swActiveSecurity = (SwitchCompat) findViewById(R.id.active_security_switch);
    swApplySecurityDelete = (SwitchCompat) findViewById(R.id.security_body_apply_delete_switch);
    swApplySecurityHidden = (SwitchCompat) findViewById(R.id.security_body_apply_hidden_switch);
    swFingerPrint = (SwitchCompat) findViewById(R.id.active_security_fingerprint_switch);
    llFingerprint = (LinearLayout) findViewById(R.id.ll_active_security_fingerprint);
    initUi();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        fingerprintHandler = new FingerprintHandler(this, null);
        if (fingerprintHandler.isFingerprintSupported()) {
            llFingerprint.setVisibility(View.VISIBLE);
        } else {
            llFingerprint.setVisibility(View.GONE);
        }
    } else {
        llFingerprint.setVisibility(View.GONE);
    }
    /**
     * - SWITCHES - *
     */
    /**
     * - ACTIVE SECURITY - *
     */
    swActiveSecurity.setChecked(Security.isPasswordSet());
    swActiveSecurity.setClickable(false);
    findViewById(R.id.ll_active_security).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            swActiveSecurity.setChecked(!swActiveSecurity.isChecked());
            setSwitchColor(getAccentColor(), swActiveSecurity);
            if (swActiveSecurity.isChecked())
                setPasswordDialog();
            else {
                Security.clearPassword();
                swApplySecurityHidden.setChecked(false);
                swApplySecurityDelete.setChecked(false);
                swFingerPrint.setChecked(false);
                Security.setFingerprintUnlock(swFingerPrint.isChecked());
                Security.setPasswordOnDelete(swApplySecurityDelete.isChecked());
                Security.setPasswordOnHidden(swApplySecurityHidden.isChecked());
                setSwitchColor(getAccentColor(), swApplySecurityHidden);
                setSwitchColor(getAccentColor(), swApplySecurityDelete);
                setSwitchColor(getAccentColor(), swFingerPrint);
            }
            toggleEnabledChild(swActiveSecurity.isChecked());
        }
    });
    /**
     * - ACTIVE SECURITY ON HIDDEN FOLDER - *
     */
    swApplySecurityHidden.setChecked(Hawk.get("password_on_hidden", false));
    swApplySecurityHidden.setClickable(false);
    findViewById(R.id.ll_security_body_apply_hidden).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            swApplySecurityHidden.setChecked(!swApplySecurityHidden.isChecked());
            Security.setPasswordOnHidden(swApplySecurityHidden.isChecked());
            setSwitchColor(getAccentColor(), swApplySecurityHidden);
        }
    });
    /**
     *ACTIVE SECURITY ON DELETE ACTION*
     */
    swApplySecurityDelete.setChecked(Hawk.get("password_on_delete", false));
    swApplySecurityDelete.setClickable(false);
    findViewById(R.id.ll_security_body_apply_delete).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            swApplySecurityDelete.setChecked(!swApplySecurityDelete.isChecked());
            Security.setPasswordOnDelete(swApplySecurityDelete.isChecked());
            setSwitchColor(getAccentColor(), swApplySecurityDelete);
        }
    });
    /**
     * - FINGERPRINT - *
     */
    swFingerPrint.setChecked(Hawk.get("fingerprint_security", false));
    swFingerPrint.setClickable(false);
    findViewById(R.id.ll_active_security_fingerprint).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            swFingerPrint.setChecked(!swFingerPrint.isChecked());
            Security.setFingerprintUnlock(swFingerPrint.isChecked());
            setSwitchColor(getAccentColor(), swFingerPrint);
        }
    });
}
Also used : FingerprintHandler(org.horaapps.leafpic.util.FingerprintHandler) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) View(android.view.View)

Example 39 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project SharedPreferenceInspector by PrashamTrivedi.

the class SharedPreferencesItem method onItemClick.

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 * <p/>
 * Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.
 *
 * @param parent
 * 		The AdapterView where the click happened.
 * @param view
 * 		The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position
 * 		The position of the view in the adapter.
 * @param id
 * 		The row id of the item that was clicked.
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    String cancel = "Cancel";
    /**
     * Checks if entered in test mode. If not, clicking on preferences will prompt user to enter test mode first. If already entered in
     * test mode,
     * it will present the UI to change the value. Once it's changed, it will store original value
     */
    if (preferenceUtils.getBoolean(testModeOpened, false)) {
        final Pair<String, Object> keyValue = (Pair<String, Object>) parent.getItemAtPosition(position);
        Object second = keyValue.second;
        final String valueType = second.getClass().getSimpleName();
        AlertDialog.Builder builder = new Builder(getActivity());
        View editView = LayoutInflater.from(getActivity()).inflate(R.layout.edit_mode, null);
        final EditText et_value = (EditText) editView.findViewById(R.id.value);
        final SwitchCompat booleanSwitch = (SwitchCompat) editView.findViewById(R.id.switchBoolean);
        Spinner type = (Spinner) editView.findViewById(R.id.type);
        final String value = second.toString();
        et_value.setText(value);
        OnItemSelectedListener listener = new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (typePosition != position) {
                    et_value.setText("");
                    typePosition = position;
                }
                booleanSwitch.setVisibility(View.GONE);
                et_value.setVisibility(View.VISIBLE);
                if (typePosition == SharedPreferenceUtils.SPINNER_STRING) {
                    et_value.setInputType(InputType.TYPE_CLASS_TEXT);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_INT || typePosition == SharedPreferenceUtils.SPINNER_LONG) {
                    et_value.setInputType(InputType.TYPE_CLASS_NUMBER);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_FLOAT) {
                    et_value.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
                } else if (typePosition == SharedPreferenceUtils.SPINNER_BOOLEAN) {
                    et_value.setVisibility(View.GONE);
                    booleanSwitch.setVisibility(View.VISIBLE);
                    boolean isPreferenceTrue = !ConstantMethods.isEmptyString(value) && value.equalsIgnoreCase("true");
                    booleanSwitch.setText(isPreferenceTrue ? "true" : "false");
                    booleanSwitch.setChecked(isPreferenceTrue);
                    booleanSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            buttonView.setText(isChecked ? "true" : "false");
                        }
                    });
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                typePosition = 0;
            }
        };
        type.setOnItemSelectedListener(listener);
        OnClickListener listener2 = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
            // TODO: Hell nothing right now.
            }
        };
        OnClickListener clearListener = new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                storeOriginal(keyValue);
                preferenceUtils.clear(keyValue.first);
                refreshKeyValues();
            }
        };
        if (valueType.equalsIgnoreCase(SharedPreferenceUtils.INT)) {
            typePosition = SharedPreferenceUtils.SPINNER_INT;
            type.setSelection(SharedPreferenceUtils.SPINNER_INT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.LONG)) {
            typePosition = SharedPreferenceUtils.SPINNER_LONG;
            type.setSelection(SharedPreferenceUtils.SPINNER_LONG);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.FLOAT)) {
            typePosition = SharedPreferenceUtils.SPINNER_FLOAT;
            type.setSelection(SharedPreferenceUtils.SPINNER_FLOAT);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.BOOLEAN)) {
            typePosition = SharedPreferenceUtils.SPINNER_BOOLEAN;
            type.setSelection(SharedPreferenceUtils.SPINNER_BOOLEAN);
        } else if (valueType.equalsIgnoreCase(SharedPreferenceUtils.STRING)) {
            typePosition = SharedPreferenceUtils.SPINNER_STRING;
            type.setSelection(SharedPreferenceUtils.SPINNER_STRING);
        }
        final AlertDialog dialog = builder.setTitle("Change Value").setView(editView).setPositiveButton("Set", null).setNegativeButton(cancel, listener2).setNeutralButton("Clear", clearListener).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog1) {
                Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        storeOriginal(keyValue);
                        Editable text = et_value.getText();
                        switch(typePosition) {
                            case SharedPreferenceUtils.SPINNER_STRING:
                                preferenceUtils.putString(keyValue.first, String.valueOf(text));
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_INT:
                                int number = SharedPreferenceUtils.getNumber(text);
                                preferenceUtils.putInt(keyValue.first, number);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_LONG:
                                long numberLong = SharedPreferenceUtils.getNumberLong(text);
                                preferenceUtils.putLong(keyValue.first, numberLong);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_BOOLEAN:
                                boolean value = booleanSwitch.isChecked();
                                preferenceUtils.putBoolean(keyValue.first, value);
                                dialog.dismiss();
                                break;
                            case SharedPreferenceUtils.SPINNER_FLOAT:
                                float numberFloat = SharedPreferenceUtils.getNumberFloat(text);
                                preferenceUtils.putFloat(keyValue.first, numberFloat);
                                dialog.dismiss();
                                break;
                        }
                        refreshKeyValues();
                    }
                });
            }
        });
        dialog.show();
    } else {
        AlertDialog.Builder builder = new Builder(getActivity());
        builder.setTitle("Test mode not enabled").setMessage("If you want to edit value for testing, testing mode should be enabled. It's available in options menu").setPositiveButton("Enable test mode", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                getActivity().supportInvalidateOptionsMenu();
                changeTestMode();
                onItemClick(parent, view, position, id);
            }
        }).setNegativeButton(cancel, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                dialog.cancel();
            }
        }).show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) Builder(android.support.v7.app.AlertDialog.Builder) Builder(android.support.v7.app.AlertDialog.Builder) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Editable(android.text.Editable) Pair(android.support.v4.util.Pair) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SearchView(android.support.v7.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) OnClickListener(android.content.DialogInterface.OnClickListener) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

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