diff options
author | Roman Birg <roman@cyngn.com> | 2016-08-29 16:26:56 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-08-29 16:26:56 -0700 |
commit | 33b5c82b68ecf8c18f284214b65db0c2e80589ce (patch) | |
tree | 41741e034f2057289f485f49761ebe6bc2135532 /src/org/cyanogenmod/audiofx/activity/ControlPanelPicker.java | |
parent | 10fc11011278db3da38e3d28f729887426c1c3a1 (diff) | |
parent | 71e5da3c38e5a7e79d5c1f94a13f239cc7ca7458 (diff) | |
download | android_packages_apps_AudioFX-33b5c82b68ecf8c18f284214b65db0c2e80589ce.tar.gz android_packages_apps_AudioFX-33b5c82b68ecf8c18f284214b65db0c2e80589ce.tar.bz2 android_packages_apps_AudioFX-33b5c82b68ecf8c18f284214b65db0c2e80589ce.zip |
Merge "AudioFX: finish rename; persist process" into cm-13.0
Diffstat (limited to 'src/org/cyanogenmod/audiofx/activity/ControlPanelPicker.java')
-rw-r--r-- | src/org/cyanogenmod/audiofx/activity/ControlPanelPicker.java | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/org/cyanogenmod/audiofx/activity/ControlPanelPicker.java b/src/org/cyanogenmod/audiofx/activity/ControlPanelPicker.java new file mode 100644 index 0000000..03e6b06 --- /dev/null +++ b/src/org/cyanogenmod/audiofx/activity/ControlPanelPicker.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2011 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. + */ + +package org.cyanogenmod.audiofx.activity; + +import com.android.internal.app.AlertActivity; +import com.android.internal.app.AlertController; +import com.android.internal.app.AlertController.AlertParams.OnPrepareListViewListener; +import org.cyanogenmod.audiofx.Compatibility; +import org.cyanogenmod.audiofx.Compatibility.Service; + +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.media.audiofx.AudioEffect; +import android.os.Bundle; +import android.widget.ListView; +import org.cyanogenmod.audiofx.R; + +import java.util.List; + +/** + * shows a dialog that lets the user switch between control panels + */ +public class ControlPanelPicker extends AlertActivity implements OnClickListener, OnPrepareListViewListener { + + + + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + String [] cols = new String [] { "_id", "title", "package", "name" }; + MatrixCursor c = new MatrixCursor(cols); + + PackageManager pmgr = getPackageManager(); + Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); + List<ResolveInfo> ris = pmgr.queryIntentActivities(i, PackageManager.GET_DISABLED_COMPONENTS); + SharedPreferences pref = getSharedPreferences("musicfx", MODE_PRIVATE); + String savedDefPackage = pref.getString("defaultpanelpackage", null); + String savedDefName = pref.getString("defaultpanelname", null); + int cnt = -1; + int defpanelidx = 0; + for (ResolveInfo foo: ris) { + if (foo.activityInfo.name.equals(Compatibility.Redirector.class.getName())) { + continue; + } + CharSequence name = pmgr.getApplicationLabel(foo.activityInfo.applicationInfo); + c.addRow(new Object [] { 0, name, foo.activityInfo.packageName, foo.activityInfo.name }); + cnt += 1; + if (foo.activityInfo.name.equals(savedDefName) && + foo.activityInfo.packageName.equals(savedDefPackage) && + foo.activityInfo.enabled) { + // mark as default in the list + defpanelidx = cnt; + } + } + + final AlertController.AlertParams p = mAlertParams; + p.mCursor = c; + p.mOnClickListener = mItemClickListener; + p.mLabelColumn = "title"; + p.mIsSingleChoice = true; + p.mPositiveButtonText = getString(getOkStringResId()); + p.mPositiveButtonListener = this; + p.mNegativeButtonText = getString(getCancelStringResId()); + p.mOnPrepareListViewListener = this; + p.mTitle = getString(R.string.picker_title); + p.mCheckedItem = defpanelidx; + + setupAlert(); + } + + private int getOkStringResId() { + return getResources().getIdentifier("ok", "string", "android"); + } + + private int getCancelStringResId() { + return getResources().getIdentifier("cancel", "string", "android"); + } + + private DialogInterface.OnClickListener mItemClickListener = + new DialogInterface.OnClickListener() { + + public void onClick(DialogInterface dialog, int which) { + // Save the position of most recently clicked item + mAlertParams.mCheckedItem = which; + } + + }; + + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == DialogInterface.BUTTON_POSITIVE) { + // set new default + Intent updateIntent = new Intent(this, Service.class); + Cursor c = mAlertParams.mCursor; + c.moveToPosition(mAlertParams.mCheckedItem); + updateIntent.putExtra("defPackage", c.getString(2)); + updateIntent.putExtra("defName", c.getString(3)); + startService(updateIntent); + } + } + + @Override + public void onPrepareListView(ListView listView) { + //mAlertParams.mCheckedItem = mDefPanelPos; + } +} |