Android Open Source - Pimp_my_Z1 Sound Fragment






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)
 */*from  w  w w.  j  ava 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.soundcontrol;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.view.ViewGroup;
import android.widget.LinearLayout;

import com.androguide.honamicontrol.R;
import com.androguide.honamicontrol.cards.CardDoubleSeekBar;
import com.androguide.honamicontrol.cards.CardDoubleSeekBarPA;
import com.androguide.honamicontrol.cards.CardSeekBarSC;
import com.androguide.honamicontrol.helpers.CPUHelper;
import com.androguide.honamicontrol.helpers.Helpers;
import com.androguide.honamicontrol.soundcontrol.SoundControlInterface;
import com.fima.cardsui.objects.Card;
import com.fima.cardsui.objects.CardStack;
import com.fima.cardsui.views.CardTextStripe;
import com.fima.cardsui.views.CardUI;

import java.util.ArrayList;

public class SoundFragment extends Fragment implements SoundControlInterface {

    private static ActionBarActivity fa;
    private static ArrayList<Card> mCards = new ArrayList<Card>();
    private static CardUI mCardUI;
    private static SharedPreferences bootPrefs;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        setHasOptionsMenu(true);
        LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.cardsui, container, false);
        fa = (ActionBarActivity) super.getActivity();
        fa.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        fa.getSupportActionBar().setHomeButtonEnabled(true);
        bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0);

        assert ll != null;
        mCardUI = (CardUI) (ll.findViewById(R.id.cardsui));
        createCards();
        return ll;
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.sound_control, menu);
        SharedPreferences p = fa.getSharedPreferences("SOUND_CONTROL", 0);
        if (p.getBoolean("LINKED", true))
            menu.getItem(0).setChecked(true);
        else
            menu.getItem(0).setChecked(false);
    }

    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.link_seekbars:
                SharedPreferences soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
                if (item.isChecked()) {
                    item.setChecked(false);
                    soundPrefs.edit().putBoolean("LINKED", false).commit();
                } else {
                    item.setChecked(true);
                    soundPrefs.edit().putBoolean("LINKED", true).commit();
                }
                break;

        }
        return super.onOptionsItemSelected(item);
    }

    public static void recreateCards() {
        mCardUI.clearCards();
        createCards();
    }

    private static void createCards() {
        String sectionColor = fa.getString(R.string.sound_control_color);
        mCardUI.addStack(new CardStack(""));

        if (!Helpers.doesFileExist(FAUX_SC_VERSION)) {
            mCardUI.addCard(new CardTextStripe(
                            fa.getString(R.string.unsupported),
                            fa.getString(R.string.sound_control_unsupported),
                            "#C74B46",
                            "#C74B46",
                            false)
            );

        } else {

            String[] headphoneGains = CPUHelper.readOneLineNotRoot(FAUX_SC_HEADPHONE).split(" ");
            int headphoneGainLeft = Integer.valueOf(headphoneGains[0]);
            if (headphoneGainLeft > 100)
                headphoneGainLeft -= 256;

            int headphoneGainRight = Integer.valueOf(headphoneGains[1]);
            if (headphoneGainRight > 100)
                headphoneGainRight -= 256;

            final CardDoubleSeekBar headphoneCard = new CardDoubleSeekBar(
                    fa.getString(R.string.sc_headphone_digital_gain),
                    fa.getString(R.string.sc_headphone_digital_gain_desc),
                    sectionColor,
                    "",
                    FAUX_SC_HEADPHONE,
                    40,
                    headphoneGainLeft + 30,
                    headphoneGainRight + 30,
                    fa,
                    null
            );
            mCards.add(headphoneCard);
            mCardUI.addCard(headphoneCard);

            String[] headphonePAGains = CPUHelper.readOneLineNotRoot(FAUX_SC_HEADPHONE_POWERAMP).split(" ");
            int headphonePAGainLeft = Integer.valueOf(headphonePAGains[0]);
            int headphonePAGainRight = Integer.valueOf(headphonePAGains[1]);
            CardDoubleSeekBarPA headphonePaCard = new CardDoubleSeekBarPA(
                    fa.getString(R.string.sc_headphone_analog_gain),
                    fa.getString(R.string.sc_headphone_analog_gain_desc),
                    sectionColor,
                    "",
                    FAUX_SC_HEADPHONE_POWERAMP,
                    12,
                    headphonePAGainLeft ,
                    headphonePAGainRight,
                    fa,
                    null
            );
            mCards.add(headphonePaCard);
            mCardUI.addCard(headphonePaCard);

            String[] speakerGains = CPUHelper.readOneLineNotRoot(FAUX_SC_SPEAKER).split(" ");
            int speakerGainLeft = Integer.valueOf(speakerGains[0]);
            if (speakerGainLeft > 100)
                speakerGainLeft -= 256;

            int speakerGainRight = Integer.valueOf(speakerGains[1]);
            if (speakerGainRight > 100)
                speakerGainRight -= 256;

            CardDoubleSeekBar speakerCard = new CardDoubleSeekBar(
                    fa.getString(R.string.sc_speaker_gain),
                    fa.getString(R.string.sc_speaker_gain_desc),
                    fa.getString(R.string.sound_control_color),
                    "",
                    FAUX_SC_SPEAKER,
                    40,
                    speakerGainLeft + 30,
                    speakerGainRight + 30,
                    fa,
                    null
            );

            mCards.add(speakerCard);
            mCardUI.addCard(speakerCard);

            int micGain = Integer.valueOf(CPUHelper.readOneLine(FAUX_SC_MIC));
            if (micGain > 100)
                micGain -= 256;

            CardSeekBarSC micCard = new CardSeekBarSC(
                    fa.getString(R.string.sc_mic_gain),
                    fa.getString(R.string.sc_mic_gain_desc),
                    fa.getString(R.string.sound_control_color),
                    "",
                    FAUX_SC_MIC,
                    40,
                    micGain + 30,
                    fa,
                    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.cancel:
                                    actionMode.finish();
                                    break;
                                case R.id.apply:
                                    isApplied = true;
                                    SharedPreferences prefs = fa.getSharedPreferences("syskernelsound_control_3gpl_mic_gain", 0);
                                    int toApply = prefs.getInt("VALUE", 0);
                                    Helpers.CMDProcessorWrapper.runSuCommand(
                                            "busybox echo 0 > " + FAUX_SC_LOCKED + "\n" +
                                                    "busybox echo " + toApply + " " + Helpers.getSoundCountrolBitRepresentation(toApply, 0) + " > " + FAUX_SC_MIC + "\n" +
                                                    "busybox echo 1 > " + FAUX_SC_LOCKED);
                                    bootPrefs.edit().putString("SC_MIC", toApply + " " + Helpers.getSoundCountrolBitRepresentation(toApply, 0)).commit();
                                    actionMode.finish();
                            }
                            return false;
                        }

                        @Override
                        public void onDestroyActionMode(ActionMode actionMode) {
                            if (!isApplied) {
                                mCardUI.clearCards();
                                createCards();
                            }
                        }
                    }
            );
            mCards.add(micCard);
            mCardUI.addCard(micCard);

            int camMicGain = Integer.valueOf(CPUHelper.readOneLine(FAUX_SC_CAM_MIC));
            if (camMicGain > 100)
                camMicGain -= 256;

            CardSeekBarSC camCard = new CardSeekBarSC(
                    fa.getString(R.string.sc_cam_mic_gain),
                    fa.getString(R.string.sc_cam_mic_gain_desc),
                    fa.getString(R.string.sound_control_color),
                    "",
                    FAUX_SC_CAM_MIC,
                    40,
                    camMicGain + 30,
                    fa,
                    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.cancel:
                                    actionMode.finish();
                                    break;
                                case R.id.apply:
                                    isApplied = true;
                                    SharedPreferences prefs = fa.getSharedPreferences("syskernelsound_control_3gpl_cam_mic_gain", 0);
                                    int toApply = prefs.getInt("VALUE", 0);
                                    Helpers.CMDProcessorWrapper.runSuCommand(
                                            "busybox echo 0 > " + FAUX_SC_LOCKED + "\n" +
                                                    "busybox echo " + toApply + " " + Helpers.getSoundCountrolBitRepresentation(toApply, 0) + " > " + FAUX_SC_CAM_MIC + "\n" +
                                                    "busybox echo 1 > " + FAUX_SC_LOCKED);
                                    bootPrefs.edit().putString("SC_CAM_MIC", toApply + " " + Helpers.getSoundCountrolBitRepresentation(toApply, 0)).commit();
                                    actionMode.finish();
                                    break;
                            }
                            return false;
                        }

                        @Override
                        public void onDestroyActionMode(ActionMode actionMode) {
                            if (!isApplied) {
                                mCardUI.clearCards();
                                createCards();
                            }
                        }
                    }
            );
            mCards.add(camCard);
            mCardUI.addCard(camCard);
        }
        mCardUI.refresh();
    }
}




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