Android Open Source - Pimp_my_Z1 Card Double Seek Bar P A






From Project

Back to project page Pimp_my_Z1.

License

The source code is released under:

GNU General Public License

If you think the Android project Pimp_my_Z1 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**   Copyright (C) 2013  Louis Teboul (a.k.a Androguide)
 */*  www  .j av a  2 s . c  o m*/
 *    admin@pimpmyrom.org  || louisteboul@gmail.com
 *    http://pimpmyrom.org || http://androguide.fr
 *    71 quai Clmenceau, 69300 Caluire-et-Cuire, FRANCE.
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License along
 *      with this program; if not, write to the Free Software Foundation, Inc.,
 *      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **/

package com.androguide.honamicontrol.cards;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.androguide.honamicontrol.R;
import com.androguide.honamicontrol.soundcontrol.SoundFragment;
import com.androguide.honamicontrol.helpers.Helpers;
import com.androguide.honamicontrol.soundcontrol.SoundControlInterface;
import com.fima.cardsui.objects.Card;

public class CardDoubleSeekBarPA extends Card implements SoundControlInterface {

    private SharedPreferences prefs, soundPrefs;
    private Boolean isLinked = true;
    private String location;

    public CardDoubleSeekBarPA(String title, String desc, String color, String unit, String prop, int seekBarMax, int seekBarProgress, int seekBarProgress2, ActionBarActivity fa, ActionMode.Callback callback) {
        super(title, desc, color, unit, prop, seekBarMax, seekBarProgress, seekBarProgress2, fa, callback);
        location = prop;
    }

    @Override
    public View getCardContent(Context context) {
        final View v = LayoutInflater.from(context).inflate(R.layout.card_double_seekbar, null);
        assert v != null;
        final TextView valueLeft = (TextView) v.findViewById(R.id.unit_left);
        final TextView valueRight = (TextView) v.findViewById(R.id.unit_right);
        final TextView titleView = (TextView) v.findViewById(R.id.title);
        titleView.setText(title);
        titleView.setTextColor(Color.parseColor(color));
        ((TextView) v.findViewById(R.id.desc)).setText(desc);

        final SeekBar seekBarLeft = (SeekBar) v.findViewById(R.id.seek_left);
        final SeekBar seekBarRight = (SeekBar) v.findViewById(R.id.seek_right);

        seekBarLeft.setMax(12);
        seekBarRight.setMax(12);
//        Toast.makeText(fa, "raw values: " + seekBarProgress + " / " + seekBarProgress2, Toast.LENGTH_LONG).show();
        seekBarLeft.setProgress(getSeekbarValue(seekBarProgress));
        seekBarRight.setProgress(getSeekbarValue(seekBarProgress2));

        valueLeft.setText(getSeekbarLabel(seekBarProgress) + unit);
        valueRight.setText(getSeekbarLabel(seekBarProgress2) + unit);

        prefs = fa.getSharedPreferences(prop.replaceAll("/", "_"), 0);
        soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
        isLinked = soundPrefs.getBoolean("LINKED", true);

        seekBarLeft.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                seekBarProgress = i;
                valueLeft.setText(i - 6 + unit);
                if (soundPrefs.getBoolean("LINKED", true)) {
                    seekBarProgress2 = i;
                    seekBarRight.setProgress(i);
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                fa.startSupportActionMode(new ActionMode.Callback() {
                    private Boolean isApplied = false;

                    @Override
                    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                        MenuInflater inflater = actionMode.getMenuInflater();
                        inflater.inflate(R.menu.contextual_menu, menu);
                        return true;
                    }

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

                    @Override
                    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
                        switch (menuItem.getItemId()) {
                            case R.id.apply:
                                isApplied = true;
                                int toApplyLeft = getSysfsValue(seekBarProgress);
                                int toApplyRight = getSysfsValue(seekBarProgress2);
                                Toast.makeText(fa, "Left: " + toApplyLeft + " / Right: " + toApplyRight, Toast.LENGTH_LONG).show();
                                Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + " && "
                                                + "busybox echo " + toApplyLeft + " " + toApplyRight + " "
                                                + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + location + " && "
                                                + "busybox echo 1 > " + FAUX_SC_LOCKED
                                );
                                SharedPreferences bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);
                                bootPrefs.edit().putString(
                                        prop.replaceAll("/", "_"), toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
                                ).commit();
                                actionMode.finish();
                                break;
                        }
                        return false;
                    }

                    @Override
                    public void onDestroyActionMode(ActionMode actionMode) {
                        if (!isApplied)
                            SoundFragment.recreateCards();
                    }
                });
                prefs.edit().putInt("VALUE_LEFT", getSysfsValue(seekBarProgress)).commit();
            }
        });

        seekBarRight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                seekBarProgress2 = i;
                valueRight.setText(i - 6 + unit);
                if (soundPrefs.getBoolean("LINKED", true)) {
                    seekBarProgress = i;
                    seekBarLeft.setProgress(i);
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(final SeekBar seekBar) {
                fa.startSupportActionMode(new ActionMode.Callback() {
                    @Override
                    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
                        MenuInflater inflater = actionMode.getMenuInflater();
                        inflater.inflate(R.menu.contextual_menu, menu);
                        return true;
                    }

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

                    @Override
                    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
                        switch (menuItem.getItemId()) {
                            case R.id.apply:
                                int toApplyLeft = getSysfsValue(seekBarProgress);
                                int toApplyRight = getSysfsValue(seekBarProgress2);
                                Toast.makeText(fa, "Left: " + toApplyLeft + " / Right: " + toApplyRight, Toast.LENGTH_LONG).show();
                                Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + " && "
                                        + "busybox echo " + toApplyLeft + " " + toApplyRight + " "
                                        + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + location + " && "
                                        + "busybox echo 1 > " + FAUX_SC_LOCKED
                                );
                                SharedPreferences bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);
                                bootPrefs.edit().putString(
                                        prop.replaceAll("/", "_"), toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)
                                ).commit();
                                actionMode.finish();
                                break;
                        }
                        return false;
                    }

                    @Override
                    public void onDestroyActionMode(ActionMode actionMode) {

                    }
                });

                prefs.edit().putInt("VALUE_RIGHT", getSysfsValue(seekBarProgress2)).commit();
            }
        });

        return v;
    }

    public int getCardContentId() {
        return R.layout.card_double_seekbar;
    }

    private int getSysfsValue(int progress) {
        switch (progress) {
            case 0:
                return 44;
            case 1:
                return 43;
            case 2:
                return 42;
            case 3:
                return 41;
            case 4:
                return 40;
            case 5:
                return 39;
            case 6:
                return 38;
            case 7:
                return 37;
            case 8:
                return 36;
            case 9:
                return 35;
            case 10:
                return 34;
            case 11:
                return 33;
            case 12:
                return 32;
            case 13:
                return 31;
            default:
                return 38;
        }
    }

    private int getSeekbarValue(int progress) {
        switch (progress) {
            case 44:
                return 0;
            case 43:
                return 1;
            case 42:
                return 2;
            case 41:
                return 3;
            case 40:
                return 4;
            case 39:
                return 5;
            case 38:
                return 6;
            case 37:
                return 7;
            case 36:
                return 8;
            case 35:
                return 9;
            case 34:
                return 10;
            case 33:
                return 11;
            case 32:
                return 12;
            case 31:
                return 13;
            default:
                return 6;
        }
    }

    private int getSeekbarLabel(int progress) {
        switch (progress) {
            case 44:
                return -6;
            case 43:
                return -5;
            case 42:
                return -4;
            case 41:
                return -3;
            case 40:
                return -2;
            case 39:
                return -1;
            case 38:
                return 0;
            case 37:
                return 1;
            case 36:
                return 2;
            case 35:
                return 2;
            case 34:
                return 3;
            case 33:
                return 4;
            case 32:
                return 5;
            case 31:
                return 6;
            default:
                return 0;
        }
    }

    @Override
    public boolean convert(View convertCardView) {
        return true;
    }
}




Java Source Code List

com.androguide.honamicontrol.MainActivity.java
com.androguide.honamicontrol.PresentationActivity.java
com.androguide.honamicontrol.SettingsActivity.java
com.androguide.honamicontrol.bootservice.BootHelper.java
com.androguide.honamicontrol.bootservice.BootReceiver.java
com.androguide.honamicontrol.cards.CardDoubleSeekBarPA.java
com.androguide.honamicontrol.cards.CardDoubleSeekBar.java
com.androguide.honamicontrol.cards.CardImageLocal.java
com.androguide.honamicontrol.cards.CardSeekBarGeneric.java
com.androguide.honamicontrol.cards.CardSeekBarReadahead.java
com.androguide.honamicontrol.cards.CardSeekBarSC.java
com.androguide.honamicontrol.cards.CardSeekBarSysctl.java
com.androguide.honamicontrol.cards.CardSeekBarVibrator.java
com.androguide.honamicontrol.cards.CardSeekBar.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMCDisabled.java
com.androguide.honamicontrol.cards.CardSpinnerSchedMC.java
com.androguide.honamicontrol.cards.CardSpinnerVoltage.java
com.androguide.honamicontrol.cards.CardSpinner.java
com.androguide.honamicontrol.cards.CardSwitchDisabled.java
com.androguide.honamicontrol.cards.CardSwitchPlugin.java
com.androguide.honamicontrol.cards.CardTopImageLocal.java
com.androguide.honamicontrol.fragments.CardsFragment.java
com.androguide.honamicontrol.fragments.HelpFragment.java
com.androguide.honamicontrol.fragments.WelcomeFragment.java
com.androguide.honamicontrol.helpers.CPUHelper.java
com.androguide.honamicontrol.helpers.FileHelper.java
com.androguide.honamicontrol.helpers.Helpers.java
com.androguide.honamicontrol.helpers.NegativeSeekBar.java
com.androguide.honamicontrol.helpers.ShellInterface.java
com.androguide.honamicontrol.helpers.SystemPropertiesReflection.java
com.androguide.honamicontrol.helpers.CMDProcessor.AbstractAsyncSuCMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.CMDProcessor.java
com.androguide.honamicontrol.helpers.CMDProcessor.ChildProcess.java
com.androguide.honamicontrol.helpers.CMDProcessor.CommandResult.java
com.androguide.honamicontrol.helpers.CMDProcessor.Constants.java
com.androguide.honamicontrol.helpers.CMDProcessor.Shell.java
com.androguide.honamicontrol.kernel.KernelFragment.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlActivity.java
com.androguide.honamicontrol.kernel.colorcontrol.ColorControlInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUFragment.java
com.androguide.honamicontrol.kernel.cpucontrol.CPUInterface.java
com.androguide.honamicontrol.kernel.cpucontrol.GovernorDialog.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUActivity.java
com.androguide.honamicontrol.kernel.gpucontrol.GPUInterface.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksActivity.java
com.androguide.honamicontrol.kernel.iotweaks.IOTweaksInterface.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementActivity.java
com.androguide.honamicontrol.kernel.memory.MemoryManagementInterface.java
com.androguide.honamicontrol.kernel.misc.MiscActivity.java
com.androguide.honamicontrol.kernel.misc.MiscInterface.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementActivity.java
com.androguide.honamicontrol.kernel.powermanagement.PowerManagementInterface.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageActivity.java
com.androguide.honamicontrol.kernel.voltagecontrol.VoltageInterface.java
com.androguide.honamicontrol.profiles.BalancedProfile.java
com.androguide.honamicontrol.profiles.BatteryMaxProfile.java
com.androguide.honamicontrol.profiles.BatteryProfile.java
com.androguide.honamicontrol.profiles.BenchmarkProfile.java
com.androguide.honamicontrol.profiles.PerformanceProfile.java
com.androguide.honamicontrol.profiles.ProfileEnabler.java
com.androguide.honamicontrol.profiles.Profile.java
com.androguide.honamicontrol.soundcontrol.SoundControlActivity.java
com.androguide.honamicontrol.soundcontrol.SoundControlFragment.java
com.androguide.honamicontrol.soundcontrol.SoundControlInterface.java
com.androguide.honamicontrol.soundcontrol.SoundFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenFragment.java
com.androguide.honamicontrol.touchscreen.TouchScreenInterface.java
com.astuetz.viewpager.extensions.PagerSlidingTabStrip.java
com.echo.holographlibrary.BarGraph.java
com.echo.holographlibrary.Bar.java
com.echo.holographlibrary.LineGraph.java
com.echo.holographlibrary.LinePoint.java
com.echo.holographlibrary.Line.java
com.echo.holographlibrary.PieGraph.java
com.echo.holographlibrary.PieSlice.java
com.fima.cardsui.StackAdapter.java
com.fima.cardsui.SwipeDismissTouchListener.java
com.fima.cardsui.Utils.java
com.fima.cardsui.objects.AbstractCard.java
com.fima.cardsui.objects.CardStack.java
com.fima.cardsui.objects.Card.java
com.fima.cardsui.views.CardCategory.java
com.fima.cardsui.views.CardDownload.java
com.fima.cardsui.views.CardEditText.java
com.fima.cardsui.views.CardEdit.java
com.fima.cardsui.views.CardImage.java
com.fima.cardsui.views.CardPresentation.java
com.fima.cardsui.views.CardSeekBar.java
com.fima.cardsui.views.CardSpinner.java
com.fima.cardsui.views.CardTextStripe.java
com.fima.cardsui.views.CardText.java
com.fima.cardsui.views.CardTopImage.java
com.fima.cardsui.views.CardUI.java
com.fima.cardsui.views.QuickReturnListView.java