Cleanup (android studio was notifying a lot)

-Removed unnecessary casts
-Removed unnecessary setTexts (are set from the xml)
-Changed Preferences#commit() with Preferences#apply()
This commit is contained in:
TrianguloY 2019-04-09 23:40:26 +02:00
parent 96c9b3ffef
commit ee92464f1e

View file

@ -42,7 +42,6 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.pierrox.lightning_launcher.LLApp; import net.pierrox.lightning_launcher.LLApp;
@ -305,49 +304,41 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
mLeftPaneAnimOut = AnimationUtils.makeOutAnimation(this, false); mLeftPaneAnimOut = AnimationUtils.makeOutAnimation(this, false);
// mCompletionsListView = (ListView) findViewById(R.id.completions); // mCompletionsListView = (ListView) findViewById(R.id.completions);
mCompletionsViewGroup = (ViewGroup) findViewById(R.id.completions); mCompletionsViewGroup = findViewById(R.id.completions);
initializeShortcuts((ViewGroup) findViewById(R.id.shortcuts)); initializeShortcuts((ViewGroup) findViewById(R.id.shortcuts));
Button btn; Button btn;
btn = (Button)findViewById(R.id.sc_import); btn = findViewById(R.id.sc_import);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setText(R.string.sc_import); btn = findViewById(R.id.sc_new);
btn = (Button)findViewById(R.id.sc_new);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setText(R.string.sc_new); btn = findViewById(R.id.sc_delete);
btn = (Button)findViewById(R.id.sc_delete);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setText(R.string.sc_delete); btn = findViewById(R.id.sc_edit);
btn = (Button)findViewById(R.id.sc_edit);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setText(R.string.sc_edit); btn = findViewById(R.id.sc_help);
btn = (Button)findViewById(R.id.sc_help);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setText(R.string.sc_help); btn = findViewById(R.id.sc_send);
btn = (Button)findViewById(R.id.sc_send);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setText(R.string.sc_send);
mScriptAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mAllScripts); mScriptAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mAllScripts);
mScriptAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mScriptAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
((TextView)findViewById(R.id.sc_path)).setText(R.string.sc_path); mScriptSpinner = findViewById(R.id.sc_spinner);
((TextView)findViewById(R.id.sc_name)).setText(R.string.sc_name);
mScriptSpinner = (Spinner) findViewById(R.id.sc_spinner);
mScriptSpinner.setLongClickable(true); mScriptSpinner.setLongClickable(true);
mScriptSpinner.setOnItemSelectedListener(this); mScriptSpinner.setOnItemSelectedListener(this);
mScriptSpinner.setAdapter(mScriptAdapter); mScriptSpinner.setAdapter(mScriptAdapter);
updateScriptsSpinner(); updateScriptsSpinner();
btn = (Button)findViewById(R.id.sc_edit_name); btn = findViewById(R.id.sc_edit_name);
btn.setOnClickListener(this); btn.setOnClickListener(this);
btn.setTypeface(LLApp.get().getIconsTypeface()); btn.setTypeface(LLApp.get().getIconsTypeface());
if(sAutoCompleteTokens == null) { if(sAutoCompleteTokens == null) {
buildAutoCompleteTokens(); buildAutoCompleteTokens();
} }
mScriptText = (AdvancedEditText) findViewById(R.id.sc_text); mScriptText = findViewById(R.id.sc_text);
mScriptText.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL)); mScriptText.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL));
mScriptText.addTextChangedListener(mScriptTextWatcher); mScriptText.addTextChangedListener(mScriptTextWatcher);
mScriptText.setListener(new AdvancedEditText.OnAdvancedEditTextEvent() { mScriptText.setListener(new AdvancedEditText.OnAdvancedEditTextEvent() {
@ -385,19 +376,12 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
mIndentation = new Indentation(); mIndentation = new Indentation();
mSearch = new Search(this, mScriptText); mSearch = new Search(this, mScriptText);
((TextView)findViewById(R.id.sc_ma)).setText(R.string.sc_ma); mMenuLightning = findViewById(R.id.sc_ml);
((TextView)findViewById(R.id.sc_a)).setText(R.string.sc_a); mMenuItem = findViewById(R.id.sc_mi);
((TextView)findViewById(R.id.sc_h)).setText(R.string.sc_h); mMenuCustom = findViewById(R.id.sc_mc);
mMenuLightning = (CheckBox) findViewById(R.id.sc_ml);
mMenuLightning.setText(R.string.sc_ml);
mMenuItem = (CheckBox) findViewById(R.id.sc_mi);
mMenuItem.setText(R.string.sc_mi);
mMenuCustom = (CheckBox) findViewById(R.id.sc_mc);
mMenuCustom.setText(R.string.sc_mc);
mShowSubDirs = mSharedPrefs.getBoolean(PREF_SUB_DIRS, true); mShowSubDirs = mSharedPrefs.getBoolean(PREF_SUB_DIRS, true);
CheckBox showSubDirs = (CheckBox) findViewById(R.id.sc_sd); CheckBox showSubDirs = findViewById(R.id.sc_sd);
showSubDirs.setText(R.string.sc_all);
showSubDirs.setChecked(mShowSubDirs); showSubDirs.setChecked(mShowSubDirs);
showSubDirs.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { showSubDirs.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
@ -411,7 +395,7 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
} }
}); });
mSelectDirectoryButton = (Button) findViewById(R.id.sc_d); mSelectDirectoryButton = findViewById(R.id.sc_d);
mSelectDirectoryButton.setOnClickListener(new View.OnClickListener() { mSelectDirectoryButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -438,13 +422,10 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
if(autoindent) mIndentation.register(mScriptText); if(autoindent) mIndentation.register(mScriptText);
float text_size = mSharedPrefs.getFloat(PREF_FONT_SIZE, mScriptText.getTextSize() / mScaledDensity); float text_size = mSharedPrefs.getFloat(PREF_FONT_SIZE, mScriptText.getTextSize() / mScaledDensity);
mScriptText.setTextSize(text_size); mScriptText.setTextSize(text_size);
((TextView)findViewById(R.id.sc_o)).setText(R.string.sc_o); CheckBox wordwrap_checkbox = findViewById(R.id.sc_w);
CheckBox wordwrap_checkbox = (CheckBox) findViewById(R.id.sc_w);
wordwrap_checkbox.setText(R.string.sc_w);
wordwrap_checkbox.setChecked(wordwrap); wordwrap_checkbox.setChecked(wordwrap);
wordwrap_checkbox.setOnCheckedChangeListener(this); wordwrap_checkbox.setOnCheckedChangeListener(this);
CheckBox autoindent_checkbox = findViewById(R.id.sc_ind); CheckBox autoindent_checkbox = findViewById(R.id.sc_ind);
autoindent_checkbox.setText(R.string.sc_ind);
autoindent_checkbox.setChecked(autoindent); autoindent_checkbox.setChecked(autoindent);
autoindent_checkbox.setOnCheckedChangeListener(this); autoindent_checkbox.setOnCheckedChangeListener(this);
@ -586,7 +567,7 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
.putFloat(PREF_FONT_SIZE, mScriptText.getTextSize()/mScaledDensity) .putFloat(PREF_FONT_SIZE, mScriptText.getTextSize()/mScaledDensity)
.putString(PREF_DIRECTORY, mCurrentDirectory.getAbsolutePath()) .putString(PREF_DIRECTORY, mCurrentDirectory.getAbsolutePath())
.putBoolean(PREF_SUB_DIRS, mShowSubDirs) .putBoolean(PREF_SUB_DIRS, mShowSubDirs)
.commit(); .apply();
if(mScript.id >= 0) { if(mScript.id >= 0) {
setLastScriptId(); setLastScriptId();
@ -634,12 +615,12 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
View content = getLayoutInflater().inflate(R.layout.edit_script_dialog, null); View content = getLayoutInflater().inflate(R.layout.edit_script_dialog, null);
final EditText nameEditText = (EditText) content.findViewById(R.id.sc_name); final EditText nameEditText = content.findViewById(R.id.sc_name);
nameEditText.setText(mScript.name); nameEditText.setText(mScript.name);
nameEditText.setSelection(mScript.name.length()); nameEditText.setSelection(mScript.name.length());
final EditText pathEditText = (EditText) content.findViewById(R.id.sc_path); final EditText pathEditText = content.findViewById(R.id.sc_path);
final Button pickPathButton = (Button) content.findViewById(R.id.sc_pick_path); final Button pickPathButton = content.findViewById(R.id.sc_pick_path);
pickPathButton.setTypeface(LLApp.get().getIconsTypeface()); pickPathButton.setTypeface(LLApp.get().getIconsTypeface());
pickPathButton.setOnClickListener(new View.OnClickListener() { pickPathButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -854,7 +835,7 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
switch (buttonView.getId()) { switch (buttonView.getId()) {
case R.id.sc_w: case R.id.sc_w:
mScriptText.setWordWrap(isChecked); mScriptText.setWordWrap(isChecked);
mSharedPrefs.edit().putBoolean(PREF_WORDWRAP, isChecked).commit(); mSharedPrefs.edit().putBoolean(PREF_WORDWRAP, isChecked).apply();
break; break;
case R.id.sc_ind: case R.id.sc_ind:
// toggled autoindentation // toggled autoindentation
@ -863,7 +844,7 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
} else { } else {
mIndentation.unregister(mScriptText); mIndentation.unregister(mScriptText);
} }
mSharedPrefs.edit().putBoolean(PREF_AUTOINDENT, isChecked).commit(); mSharedPrefs.edit().putBoolean(PREF_AUTOINDENT, isChecked).apply();
break; break;
} }
} }
@ -941,8 +922,8 @@ public class ScriptEditor extends ResourceWrapperActivity implements View.OnClic
} }
private void setLastScriptId() { private void setLastScriptId() {
mSharedPrefs.edit().putInt(PREF_LAST_SCRIPT_ID, mScript.id).commit(); mSharedPrefs.edit().putInt(PREF_LAST_SCRIPT_ID, mScript.id).apply();
mSharedPrefs.edit().putInt(PREF_LAST_SCRIPT_LINE, mScriptText.getSelectionLine()).commit(); mSharedPrefs.edit().putInt(PREF_LAST_SCRIPT_LINE, mScriptText.getSelectionLine()).apply();
} }
private void showLeftPane() { private void showLeftPane() {