-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
s2: parts: Introduce Dirac preferences
Add a frontend for Dirac sound optimization settings. Inject into sound preferences through settings IA. Change-Id: I37f6e64fa440c43dbe238cc65af5f9b0bbd60d83 Signed-off-by: Joey <joey@lineageos.org> Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
- Loading branch information
1 parent
3a66314
commit b6e3106
Showing
7 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
/* | ||
** Copyright 2014, The Android Open Source Project | ||
** | ||
** Licensed under the Apache License, Version 2.0 (the "License"); | ||
** you may not use this file except in compliance with the License. | ||
** You may obtain a copy of the License at | ||
** | ||
** http://www.apache.org/licenses/LICENSE-2.0 | ||
** | ||
** Unless required by applicable law or agreed to in writing, software | ||
** distributed under the License is distributed on an "AS IS" BASIS, | ||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
** See the License for the specific language governing permissions and | ||
** limitations under the License. | ||
*/ | ||
--> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_height="match_parent" | ||
android:layout_width="match_parent"> | ||
|
||
<include layout="@layout/switch_bar" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2018 The LineageOS Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<resources> | ||
<!-- Dirac settings --> | ||
<string name="dirac_title">Dirac sound enhancer</string> | ||
<string name="dirac_headset_title">Headset type</string> | ||
<string name="dirac_preset_title">Sound preset</string> | ||
|
||
<!-- TODO: change the string values accordingly --> | ||
<string name="dirac_headset_0">Headset 0</string> | ||
<string name="dirac_headset_1">Headset 1</string> | ||
<string name="dirac_headset_2">Headset 2</string> | ||
<string name="dirac_headset_3">Headset 3</string> | ||
|
||
<!-- TODO: change the string values accordingly --> | ||
<string name="dirac_preset_0">Preset 0</string> | ||
<string name="dirac_preset_1">Preset 1</string> | ||
<string name="dirac_preset_2">Preset 2</string> | ||
<string name="dirac_preset_3">Preset 3</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2018 The LineageOS Project | ||
Licensed under the Apache License, Version 2.0 (the "License" | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<ListPreference | ||
android:key="dirac_headset_pref" | ||
android:defaultValue="0" | ||
android:title="@string/dirac_headset_title" | ||
android:summary="%s" /> | ||
|
||
<ListPreference | ||
android:key="dirac_preset_pref" | ||
android:defaultValue="0" | ||
android:title="@string/dirac_preset_title" | ||
android:summary="%s" /> | ||
|
||
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2018 The LineageOS Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.lineageos.settings.dirac; | ||
|
||
import android.os.Bundle; | ||
import android.preference.PreferenceActivity; | ||
|
||
public class DiracActivity extends PreferenceActivity { | ||
|
||
private static final String TAG_DIRAC = "dirac"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
getFragmentManager().beginTransaction().replace(android.R.id.content, | ||
new DiracSettingsFragment(), TAG_DIRAC).commit(); | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
parts/src/org/lineageos/settings/dirac/DiracSettingsFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright (C) 2018 The LineageOS Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.lineageos.settings.dirac; | ||
|
||
import android.app.ActionBar; | ||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.support.v14.preference.PreferenceFragment; | ||
import android.support.v14.preference.SwitchPreference; | ||
import android.support.v7.preference.ListPreference; | ||
import android.support.v7.preference.Preference; | ||
import android.support.v7.preference.PreferenceCategory; | ||
import android.support.v7.preference.Preference.OnPreferenceChangeListener; | ||
import android.view.LayoutInflater; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CompoundButton; | ||
import android.widget.Switch; | ||
import android.widget.TextView; | ||
|
||
import org.lineageos.settings.R; | ||
|
||
public class DiracSettingsFragment extends PreferenceFragment implements | ||
OnPreferenceChangeListener, CompoundButton.OnCheckedChangeListener { | ||
|
||
private static final String PREF_HEADSET = "dirac_headset_pref"; | ||
private static final String PREF_PRESET = "dirac_preset_pref"; | ||
|
||
private TextView mTextView; | ||
private View mSwitchBar; | ||
|
||
private ListPreference mHeadsetType; | ||
private ListPreference mPreset; | ||
|
||
@Override | ||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { | ||
addPreferencesFromResource(R.xml.dirac_settings); | ||
final ActionBar actionBar = getActivity().getActionBar(); | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
|
||
boolean enhancerEnabled = DiracUtils.isDiracEnabled(getActivity()); | ||
|
||
mHeadsetType = (ListPreference) findPreference(PREF_HEADSET); | ||
mHeadsetType.setOnPreferenceChangeListener(this); | ||
mHeadsetType.setEnabled(enhancerEnabled); | ||
// TODO: adapt to real values | ||
String[] headsetEntries = new String[] { | ||
getString(R.string.dirac_headset_0), | ||
getString(R.string.dirac_headset_1), | ||
getString(R.string.dirac_headset_2), | ||
getString(R.string.dirac_headset_3) | ||
}; | ||
String[] headsetValues = new String[] { | ||
"0", "1", "2", "3" | ||
}; | ||
mHeadsetType.setEntries(headsetEntries); | ||
mHeadsetType.setEntryValues(headsetValues); | ||
|
||
mPreset = (ListPreference) findPreference(PREF_PRESET); | ||
mPreset.setOnPreferenceChangeListener(this); | ||
mPreset.setEnabled(enhancerEnabled); | ||
// TODO: adapt to real values | ||
String[] presetEntries = new String[] { | ||
getString(R.string.dirac_preset_0), | ||
getString(R.string.dirac_preset_1), | ||
getString(R.string.dirac_preset_2), | ||
getString(R.string.dirac_preset_3) | ||
}; | ||
String[] presetValues = new String[] { | ||
"0", "1", "2", "3" | ||
}; | ||
mPreset.setEntries(presetEntries); | ||
mPreset.setEntryValues(presetValues); | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
final View view = LayoutInflater.from(getContext()).inflate(R.layout.dirac, | ||
container, false); | ||
((ViewGroup) view).addView(super.onCreateView(inflater, container, savedInstanceState)); | ||
return view; | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
|
||
boolean enhancerEnabled = DiracUtils.isDiracEnabled(getActivity()); | ||
|
||
mTextView = view.findViewById(R.id.switch_text); | ||
mTextView.setText(getString(enhancerEnabled ? | ||
R.string.switch_bar_on : R.string.switch_bar_off)); | ||
|
||
mSwitchBar = view.findViewById(R.id.switch_bar); | ||
Switch switchWidget = mSwitchBar.findViewById(android.R.id.switch_widget); | ||
switchWidget.setChecked(enhancerEnabled); | ||
switchWidget.setOnCheckedChangeListener(this); | ||
mSwitchBar.setActivated(enhancerEnabled); | ||
mSwitchBar.setOnClickListener(v -> { | ||
switchWidget.setChecked(!switchWidget.isChecked()); | ||
mSwitchBar.setActivated(switchWidget.isChecked()); | ||
}); | ||
} | ||
|
||
@Override | ||
public boolean onPreferenceChange(Preference preference, Object newValue) { | ||
switch (preference.getKey()) { | ||
case PREF_HEADSET: | ||
// TODO: on Headset changed | ||
return true; | ||
case PREF_PRESET: | ||
// TODO: on Preset changed | ||
return true; | ||
default: return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { | ||
// TODO: Toggle enhancer | ||
|
||
mTextView.setText(getString(isChecked ? R.string.switch_bar_on : R.string.switch_bar_off)); | ||
mSwitchBar.setActivated(isChecked); | ||
|
||
mHeadsetType.setEnabled(isChecked); | ||
mPreset.setEnabled(isChecked); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (item.getItemId() == android.R.id.home) { | ||
getActivity().onBackPressed(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2018 The LineageOS Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.lineageos.settings.dirac; | ||
|
||
import android.content.Context; | ||
|
||
public final class DiracUtils { | ||
|
||
protected static boolean isDiracEnabled(Context context) { | ||
return false; | ||
} | ||
} |