OmniLib: cleanup obssolete
Change-Id: Ie546f2963936badebcb65f012ad3eaa47b977deb
diff --git a/src/org/omnirom/omnilib/actions/OmniAction.java b/src/org/omnirom/omnilib/actions/OmniAction.java
deleted file mode 100644
index 781d751..0000000
--- a/src/org/omnirom/omnilib/actions/OmniAction.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2014 The OmniROM Project
- *
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-package org.omnirom.omnilib.actions;
-
-import android.content.Context;
-import android.content.Intent;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.util.AttributeSet;
-import android.util.Log;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-
-public class OmniAction {
- private static final String TAG = "OmniAction";
-
- public String key = null;
- public String title = null;
- public String broadcast = null;
- public String value = null;
- public String value_type = null;
- public String value_key = null;
- public String type = null;
- public String setting = null;
- public String setting_type = null;
- public String runner = null;
-
- private Context mContext;
-
- public OmniAction(Context context, AttributeSet attrs) {
- mContext = context;
- parseAttrs(attrs);
- }
-
- private void parseAttrs(AttributeSet attrs) {
- for (int i = 0; i < attrs.getAttributeCount(); i++) {
- String attr = attrs.getAttributeName(i);
- switch (attr) {
- case "setting":
- setting = attrs.getAttributeValue(i);
- break;
- case "setting_type":
- setting_type = attrs.getAttributeValue(i);
- break;
- case "broadcast":
- broadcast = attrs.getAttributeValue(i);
- break;
- case "key":
- key = attrs.getAttributeValue(i);
- break;
- case "value":
- value = attrs.getAttributeValue(i);
- break;
- case "value_type":
- value_type = attrs.getAttributeValue(i);
- break;
- case "value_key":
- value_key = attrs.getAttributeValue(i);
- break;
- case "title":
- title = mContext.getString(attrs.getAttributeResourceValue(i, 0));
- break;
- case "runner":
- runner = attrs.getAttributeValue(i);
- break;
- }
- }
- }
-
- public void execute() {
- if (runner != null) {
- executeRunner();
- return;
- }
-
- if (broadcast != null) {
- executeBroadcast();
- return;
- }
-
- if (setting != null && setting_type != null) {
- executeSetting();
- return;
- }
- }
-
- private void executeBroadcast() {
- Intent i = new Intent(broadcast);
-
- if (value != null) {
- switch (value_type) {
- case "boolean":
- i.putExtra(value_key, Boolean.parseBoolean(value));
- break;
- default:
- i.putExtra(value_key, value);
- }
- }
-
- mContext.sendBroadcastAsUser(i, UserHandle.CURRENT);
- }
-
- private void executeSetting() {
- switch (setting_type) {
- case "Secure":
- switch (value_type) {
- case "int":
- Settings.Secure.putInt(mContext.getContentResolver(), setting, Integer.parseInt(value));
- break;
- default:
- Settings.Secure.putString(mContext.getContentResolver(), setting, value);
- break;
- }
- break;
- case "Global":
- switch (value_type) {
- case "int":
- Settings.Global.putInt(mContext.getContentResolver(), setting, Integer.parseInt(value));
- break;
- default:
- Settings.Global.putString(mContext.getContentResolver(), setting, value);
- break;
- }
- break;
- }
- }
-
- private void executeRunner() {
- try {
- Class mRunner = Class.forName(runner);
- Constructor<?> constructor = mRunner.getDeclaredConstructor(new Class[]{Context.class});
- Object object = constructor.newInstance(mContext);
- Method run = mRunner.getDeclaredMethod("run", new Class[]{String.class});
- run.invoke(object, value);
- } catch (Exception e) {
- Log.e(TAG, "Runner", e);
- }
- }
-}
diff --git a/src/org/omnirom/omnilib/actions/OmniActionsInflate.java b/src/org/omnirom/omnilib/actions/OmniActionsInflate.java
deleted file mode 100644
index 8cc378f..0000000
--- a/src/org/omnirom/omnilib/actions/OmniActionsInflate.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2014 The OmniROM Project
- *
- * 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, see <http://www.gnu.org/licenses/>.
- */
-
-package org.omnirom.omnilib.actions;
-
-import android.content.Context;
-import android.content.res.XmlResourceParser;
-import android.util.AttributeSet;
-
-import org.xmlpull.v1.XmlPullParser;
-
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-
-public class OmniActionsInflate {
- public static ArrayList<OmniAction> inflate(Context context, int xmlFileResId) throws Exception {
- int token;
- ArrayList<OmniAction> actions = new ArrayList<OmniAction>();
- XmlResourceParser parser = context.getResources().getXml(xmlFileResId);
-
- while ((token = parser.next()) != XmlPullParser.END_DOCUMENT) {
- if (token == XmlPullParser.START_TAG) {
- if ("action".equals(parser.getName())) {
- actions.add(new OmniAction(context, parser));
- }
- }
- }
- return actions;
- }
-}
diff --git a/src/org/omnirom/omnilib/preference/OmniActionsListPreference.java b/src/org/omnirom/omnilib/preference/OmniActionsListPreference.java
deleted file mode 100644
index 71ce35b..0000000
--- a/src/org/omnirom/omnilib/preference/OmniActionsListPreference.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2016 The OmniROM Project
- *
- * 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, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.omnirom.omnilib.preference;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.CheckBox;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import org.omnirom.omnilib.actions.OmniAction;
-import org.omnirom.omnilib.actions.OmniActionsInflate;
-
-import org.omnirom.omnilib.R;
-import com.android.settingslib.CustomDialogPreferenceCompat;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-public class OmniActionsListPreference extends CustomDialogPreferenceCompat {
- private static final String TAG = "OmniActionsList";
- private static final boolean DEBUG = true;
-
- private ArrayList<OmniAction> oActionInfoList;
- private ActionListAdapter mAdapter;
- private List<String> mValues = new ArrayList<String>();
- private Context mContext;
-
- public OmniActionsListPreference(Context context) {
- this(context, null);
- }
-
- public OmniActionsListPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- setDialogLayoutResource(R.layout.preference_action_list);
- mContext = context;
- setPositiveButtonText(R.string.action_save);
- setNegativeButtonText(android.R.string.cancel);
- }
-
- public void setValues(Collection<String> values) {
- mValues.clear();
- mValues.addAll(values);
- }
-
- public Collection<String> getValues() {
- return mValues;
- }
-
- public boolean loadActions(int xml_id) {
- try {
- oActionInfoList = OmniActionsInflate.inflate(mContext, xml_id);
- } catch (Exception e) {
- if (DEBUG) Log.e(TAG, "Load omni actions ", e);
- return false;
- }
- return true;
- }
-
- @Override
- protected void onBindDialogView(View view) {
- super.onBindDialogView(view);
-
- mAdapter = new ActionListAdapter(getContext());
- final ListView listView = (ListView) view.findViewById(R.id.action_list);
- listView.setAdapter(mAdapter);
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- final AppViewHolder holder = (AppViewHolder) view.getTag();
- final boolean isChecked = !holder.checkBox.isChecked();
-
- holder.checkBox.setChecked(isChecked);
- OmniAction info = mAdapter.getItem(position);
-
- if (isChecked) {
- mValues.add(info.key);
- } else {
- mValues.remove(info.key);
- }
- }
- });
- }
-
- @Override
- protected void onDialogClosed(boolean positiveResult) {
- super.onDialogClosed(positiveResult);
- if (positiveResult) {
- callChangeListener(mValues.size() > 0 ? mValues : null);
- }
- }
-
- public class ActionListAdapter extends ArrayAdapter<OmniAction> {
- private final LayoutInflater mInflater;
-
- public ActionListAdapter(Context context) {
- super(context, 0);
- mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- addAll(oActionInfoList);
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- AppViewHolder holder = AppViewHolder.createOrRecycle(mInflater, convertView);
- convertView = holder.rootView;
- OmniAction info = getItem(position);
- holder.title.setText(info.title);
- holder.checkBox.setChecked(mValues.contains(info.key));
- return convertView;
- }
-
- @Override
- public OmniAction getItem(int position) {
- return oActionInfoList.get(position);
- }
- }
-
- public static class AppViewHolder {
- public View rootView;
- public TextView title;
- public CheckBox checkBox;
-
- public static AppViewHolder createOrRecycle(LayoutInflater inflater, View convertView) {
- if (convertView == null) {
- convertView = inflater.inflate(R.layout.action_item, null);
-
- // Creates a ViewHolder and store references to the two children views
- // we want to bind data to.
- AppViewHolder holder = new AppViewHolder();
- holder.rootView = convertView;
- holder.title = (TextView) convertView.findViewById(R.id.action_title);
- holder.checkBox = (CheckBox) convertView.findViewById(android.R.id.checkbox);
- convertView.setTag(holder);
- return holder;
- } else {
- // Get the ViewHolder back to get fast access to the TextView
- // and the ImageView.
- return (AppViewHolder) convertView.getTag();
- }
- }
- }
-}
-