Skip to content

Commit

Permalink
s2: parts: Introduce Dirac preferences
Browse files Browse the repository at this point in the history
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
bvlj authored and Akash98Sky committed Aug 25, 2019
1 parent 3a66314 commit b6e3106
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 0 deletions.
11 changes: 11 additions & 0 deletions parts/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
</intent-filter>
</receiver>

<activity
android:name=".dirac.DiracActivity"
android:label="@string/dirac_title"
android:theme="@style/Theme.Main">
<intent-filter>
<action android:name="com.android.settings.action.IA_SETTINGS" />
</intent-filter>
<meta-data android:name="com.android.settings.category"
android:value="com.android.settings.category.ia.sound" />
</activity>

<service android:name=".doze.DozeService"
android:permission="LeEcoDozeService">
</service>
Expand Down
27 changes: 27 additions & 0 deletions parts/res/layout/dirac.xml
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>
34 changes: 34 additions & 0 deletions parts/res/values/strings.xml
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>
31 changes: 31 additions & 0 deletions parts/res/xml/dirac_settings.xml
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>
33 changes: 33 additions & 0 deletions parts/src/org/lineageos/settings/dirac/DiracActivity.java
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 parts/src/org/lineageos/settings/dirac/DiracSettingsFragment.java
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;
}
}
26 changes: 26 additions & 0 deletions parts/src/org/lineageos/settings/dirac/DiracUtils.java
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;
}
}

0 comments on commit b6e3106

Please sign in to comment.