Use custom Logging methods
(also, code formatting, add final modifiers)
This commit is contained in:
parent
278f1e0684
commit
80f7d0e601
@ -40,7 +40,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
private static int mDeletedPlugins = 0;
|
||||
|
||||
@Override
|
||||
public void setListAdapter(ListAdapter adapter) {
|
||||
public void setListAdapter(final ListAdapter adapter) {
|
||||
if (adapter == null) {
|
||||
super.setListAdapter(null);
|
||||
} else {
|
||||
@ -49,11 +49,11 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBuildHeaders(List<Header> target) {
|
||||
public void onBuildHeaders(final List<Header> target) {
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// notify about external plugins
|
||||
IITC_NotificationHelper nh = new IITC_NotificationHelper(this);
|
||||
final IITC_NotificationHelper nh = new IITC_NotificationHelper(this);
|
||||
nh.showNotice(IITC_NotificationHelper.NOTICE_EXTPLUGINS);
|
||||
|
||||
mHeaders = target;
|
||||
@ -70,7 +70,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
// on tablets, select a default fragment BEFORE calling super onCreate
|
||||
// otherwise the application will crash, because the first header (the
|
||||
// category) does not have a fragment assigned
|
||||
@ -104,7 +104,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home: // exit settings when home button (iitc icon) is pressed
|
||||
onBackPressed();
|
||||
@ -115,23 +115,23 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String s) {
|
||||
protected boolean isValidFragment(final String s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// called by Plugins Fragment
|
||||
public static ArrayList<IITC_PluginPreference> getPluginPreference(String key, boolean userPlugin) {
|
||||
public static ArrayList<IITC_PluginPreference> getPluginPreference(final String key, final boolean userPlugin) {
|
||||
if (userPlugin) return sUserPlugins.get(key);
|
||||
else return sAssetPlugins.get(key);
|
||||
|
||||
return sAssetPlugins.get(key);
|
||||
}
|
||||
|
||||
private String[] getAssetPlugins() {
|
||||
AssetManager am = getAssets();
|
||||
final AssetManager am = getAssets();
|
||||
String[] asset_array = null;
|
||||
try {
|
||||
asset_array = am.list("plugins");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
} catch (final IOException e) {
|
||||
Log.w(e);
|
||||
}
|
||||
if (asset_array == null) {
|
||||
@ -141,9 +141,9 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
private File[] getUserPlugins() {
|
||||
String iitc_path = Environment.getExternalStorageDirectory().getPath()
|
||||
final String iitc_path = Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/IITC_Mobile/";
|
||||
File directory = new File(iitc_path + "plugins/");
|
||||
final File directory = new File(iitc_path + "plugins/");
|
||||
File[] files = directory.listFiles();
|
||||
if (files == null) {
|
||||
files = new File[0];
|
||||
@ -152,13 +152,13 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
void checkForNewPlugins() {
|
||||
File[] userPlugins = getUserPlugins();
|
||||
String[] officialPlugins = getAssetPlugins();
|
||||
final File[] userPlugins = getUserPlugins();
|
||||
final String[] officialPlugins = getAssetPlugins();
|
||||
int numPlugins = 0;
|
||||
for (Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sUserPlugins.entrySet()) {
|
||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sUserPlugins.entrySet()) {
|
||||
numPlugins += entry.getValue().size();
|
||||
}
|
||||
for (Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
||||
numPlugins += entry.getValue().size();
|
||||
}
|
||||
if ((userPlugins.length + officialPlugins.length) != (numPlugins + mDeletedPlugins)) {
|
||||
@ -170,41 +170,38 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
void setUpPluginPreferenceScreen() {
|
||||
// get all plugins from asset manager
|
||||
String[] assets = getAssetPlugins();
|
||||
for (String asset : assets) {
|
||||
final String[] assets = getAssetPlugins();
|
||||
for (final String asset : assets) {
|
||||
// find user plugin name for user readable entries
|
||||
try {
|
||||
InputStream is = getAssets().open("plugins/" + asset);
|
||||
final InputStream is = getAssets().open("plugins/" + asset);
|
||||
addPluginPreference(IITC_FileManager.readStream(is), asset, false);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(asset + " not found");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("couldn't read plugin " + asset);
|
||||
} catch (final FileNotFoundException e) {
|
||||
Log.e(asset + " not found", e);
|
||||
} catch (final IOException e) {
|
||||
Log.e("couldn't read plugin " + asset, e);
|
||||
}
|
||||
}
|
||||
|
||||
// load user plugins from <storage-path>/IITC_Mobile/plugins/
|
||||
File[] files = getUserPlugins();
|
||||
for (File file : files) {
|
||||
final File[] files = getUserPlugins();
|
||||
for (final File file : files) {
|
||||
try {
|
||||
InputStream is = new FileInputStream(file);
|
||||
final InputStream is = new FileInputStream(file);
|
||||
addPluginPreference(IITC_FileManager.readStream(is), file.toString(), true);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("couldn't read plugin " + file.toString());
|
||||
} catch (final FileNotFoundException e) {
|
||||
Log.e("couldn't read plugin " + file.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addPluginPreference(String src, String plugin_key, boolean userPlugin) {
|
||||
void addPluginPreference(final String src, final String plugin_key, final boolean userPlugin) {
|
||||
// parse plugin name, description and category
|
||||
// we need default versions here otherwise iitcm may crash
|
||||
HashMap<String, String> info = IITC_FileManager.getScriptInfo(src);
|
||||
final HashMap<String, String> info = IITC_FileManager.getScriptInfo(src);
|
||||
String plugin_name = info.get("name");
|
||||
String plugin_cat = info.get("category");
|
||||
String plugin_desc = info.get("description");
|
||||
final String plugin_cat = info.get("category");
|
||||
final String plugin_desc = info.get("description");
|
||||
|
||||
// remove IITC plugin prefix from plugin_name
|
||||
plugin_name = plugin_name.replace("IITC Plugin: ", "");
|
||||
@ -231,40 +228,41 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
// now build a new checkable preference for the plugin
|
||||
IITC_PluginPreference plugin_pref = new IITC_PluginPreference(this);
|
||||
final IITC_PluginPreference plugin_pref = new IITC_PluginPreference(this);
|
||||
plugin_pref.setKey(plugin_key);
|
||||
plugin_pref.setTitle(plugin_name);
|
||||
plugin_pref.setSummary(plugin_desc);
|
||||
plugin_pref.setDefaultValue(false);
|
||||
plugin_pref.setPersistent(true);
|
||||
ArrayList<IITC_PluginPreference> list = (userPlugin) ? sUserPlugins.get(plugin_cat) : sAssetPlugins.get(plugin_cat);
|
||||
final ArrayList<IITC_PluginPreference> list =
|
||||
userPlugin ? sUserPlugins.get(plugin_cat) : sAssetPlugins.get(plugin_cat);
|
||||
list.add(plugin_pref);
|
||||
}
|
||||
|
||||
void addHeaders() {
|
||||
if (sUserPlugins.size() > 0) {
|
||||
Header category = new Header();
|
||||
final Header category = new Header();
|
||||
category.title = "User Plugins";
|
||||
mHeaders.add(category);
|
||||
for(Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sUserPlugins.entrySet()) {
|
||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sUserPlugins.entrySet()) {
|
||||
addHeader(entry.getKey(), true);
|
||||
}
|
||||
}
|
||||
if (sAssetPlugins.size() > 0) {
|
||||
Header category = new Header();
|
||||
final Header category = new Header();
|
||||
category.title = "Official Plugins";
|
||||
mHeaders.add(category);
|
||||
for(Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
||||
addHeader(entry.getKey(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addHeader(String title, boolean userPlugin) {
|
||||
Bundle bundle = new Bundle();
|
||||
private void addHeader(final String title, final boolean userPlugin) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString("category", title);
|
||||
bundle.putBoolean("userPlugin", userPlugin);
|
||||
Header newHeader = new Header();
|
||||
final Header newHeader = new Header();
|
||||
newHeader.title = title;
|
||||
newHeader.fragmentArguments = bundle;
|
||||
newHeader.fragment = "com.cradle.iitc_mobile.fragments.PluginsFragment";
|
||||
@ -287,7 +285,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
static int getHeaderType(Header header) {
|
||||
static int getHeaderType(final Header header) {
|
||||
if (header.fragment == null && header.intent == null) {
|
||||
return HEADER_TYPE_CATEGORY;
|
||||
} else {
|
||||
@ -296,8 +294,8 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Header header = getItem(position);
|
||||
public int getItemViewType(final int position) {
|
||||
final Header header = getItem(position);
|
||||
return getHeaderType(header);
|
||||
}
|
||||
|
||||
@ -307,7 +305,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
public boolean isEnabled(final int position) {
|
||||
return getItemViewType(position) != HEADER_TYPE_CATEGORY;
|
||||
}
|
||||
|
||||
@ -321,37 +319,32 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
public HeaderAdapter(Context context, List<Header> objects) {
|
||||
public HeaderAdapter(final Context context, final List<Header> objects) {
|
||||
super(context, 0, objects);
|
||||
|
||||
mInflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
public View getView(final int position, final View convertView, final ViewGroup parent) {
|
||||
HeaderViewHolder holder;
|
||||
Header header = getItem(position);
|
||||
int headerType = getHeaderType(header);
|
||||
final Header header = getItem(position);
|
||||
final int headerType = getHeaderType(header);
|
||||
View view = null;
|
||||
|
||||
if (convertView == null) {
|
||||
holder = new HeaderViewHolder();
|
||||
switch (headerType) {
|
||||
case HEADER_TYPE_CATEGORY:
|
||||
view = new TextView(getContext(), null,
|
||||
android.R.attr.listSeparatorTextViewStyle);
|
||||
view = new TextView(getContext(), null, android.R.attr.listSeparatorTextViewStyle);
|
||||
holder.title = (TextView) view;
|
||||
break;
|
||||
|
||||
case HEADER_TYPE_NORMAL:
|
||||
view = mInflater.inflate(R.layout.preference_header_item,
|
||||
parent, false);
|
||||
holder.title = (TextView) view
|
||||
.findViewById(R.id.plug_pref_title);
|
||||
holder.summary = (TextView) view
|
||||
.findViewById(R.id.plug_pref_summary);
|
||||
view = mInflater.inflate(R.layout.preference_header_item, parent, false);
|
||||
holder.title = (TextView) view.findViewById(R.id.plug_pref_title);
|
||||
holder.summary = (TextView) view.findViewById(R.id.plug_pref_summary);
|
||||
break;
|
||||
}
|
||||
view.setTag(holder);
|
||||
@ -360,18 +353,14 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
||||
holder = (HeaderViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
// All view fields must be updated every time, because the view may
|
||||
// be recycled
|
||||
// All view fields must be updated every time, because the view may be recycled
|
||||
switch (headerType) {
|
||||
case HEADER_TYPE_CATEGORY:
|
||||
holder.title.setText(header.getTitle(getContext()
|
||||
.getResources()));
|
||||
holder.title.setText(header.getTitle(getContext().getResources()));
|
||||
break;
|
||||
case HEADER_TYPE_NORMAL:
|
||||
holder.title.setText(header.getTitle(getContext()
|
||||
.getResources()));
|
||||
CharSequence summary = header.getSummary(getContext()
|
||||
.getResources());
|
||||
holder.title.setText(header.getTitle(getContext().getResources()));
|
||||
final CharSequence summary = header.getSummary(getContext().getResources());
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
holder.summary.setText(summary);
|
||||
|
Loading…
x
Reference in New Issue
Block a user