use of fr.neamar.kiss.adapter.RecordAdapter in project KISS by Neamar.
the class MainActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
// Initialize UI
prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "light");
switch(theme) {
case "dark":
setTheme(R.style.AppThemeDark);
break;
case "transparent":
setTheme(R.style.AppThemeTransparent);
break;
case "semi-transparent":
setTheme(R.style.AppThemeSemiTransparent);
break;
case "semi-transparent-dark":
setTheme(R.style.AppThemeSemiTransparentDark);
break;
case "transparent-dark":
setTheme(R.style.AppThemeTransparentDark);
break;
}
super.onCreate(savedInstanceState);
IntentFilter intentFilter = new IntentFilter(START_LOAD);
IntentFilter intentFilterBis = new IntentFilter(LOAD_OVER);
IntentFilter intentFilterTer = new IntentFilter(FULL_LOAD_OVER);
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(LOAD_OVER)) {
updateRecords(searchEditText.getText().toString());
} else if (intent.getAction().equalsIgnoreCase(FULL_LOAD_OVER)) {
// Run GC once to free all the garbage accumulated during provider initialization
System.gc();
displayQuickFavoritesBar(true, false);
displayLoader(false);
} else if (intent.getAction().equalsIgnoreCase(START_LOAD)) {
displayLoader(true);
}
}
};
this.registerReceiver(mReceiver, intentFilter);
this.registerReceiver(mReceiver, intentFilterBis);
this.registerReceiver(mReceiver, intentFilterTer);
KissApplication.initDataHandler(this);
// Initialize preferences
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Do it here (before initializing the view) to make the transition as smooth as possible
if (prefs.getBoolean("force-portrait", true)) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}
setContentView(R.layout.main);
this.list = (ListView) this.findViewById(android.R.id.list);
this.listContainer = (View) this.list.getParent();
this.listEmpty = this.findViewById(android.R.id.empty);
// Create adapter for records
this.adapter = new RecordAdapter(this, this, R.layout.item_app, new ArrayList<Result>());
this.list.setAdapter(this.adapter);
this.list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
adapter.onClick(position, v);
}
});
this.adapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
if (adapter.isEmpty()) {
listContainer.setVisibility(View.GONE);
listEmpty.setVisibility(View.VISIBLE);
} else {
listContainer.setVisibility(View.VISIBLE);
listEmpty.setVisibility(View.GONE);
}
}
});
registerLongClickOnFavorites();
searchEditText = (EditText) findViewById(R.id.searchEditText);
// Listen to changes
searchEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// Auto left-trim text.
if (s.length() > 0 && s.charAt(0) == ' ')
s.delete(0, 1);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = s.toString();
adjustInputType(text);
updateRecords(text);
displayClearOnInput();
}
});
// On validate, launch first record
searchEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
RecordAdapter adapter = ((RecordAdapter) list.getAdapter());
adapter.onClick(adapter.getCount() - 1, v);
return true;
}
});
kissBar = findViewById(R.id.main_kissbar);
favoritesKissBar = findViewById(R.id.favoritesKissBar);
menuButton = findViewById(R.id.menuButton);
registerForContextMenu(menuButton);
this.list.setLongClickable(true);
this.list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int pos, long id) {
((RecordAdapter) parent.getAdapter()).onLongClick(pos, v);
return true;
}
});
this.hider = new KeyboardScrollHider(this, (BlockableListView) this.list, (BottomPullEffectView) this.findViewById(R.id.listEdgeEffect));
this.hider.start();
// Check whether user enabled spell check and adjust input type accordingly
searchEditTextWorkaround = prefs.getBoolean("enable-keyboard-workaround", false);
adjustInputType(null);
//enable/disable phone/sms broadcast receiver
PackageManagerUtils.enableComponent(this, IncomingSmsHandler.class, prefs.getBoolean("enable-sms-history", false));
PackageManagerUtils.enableComponent(this, IncomingCallHandler.class, prefs.getBoolean("enable-phone-history", false));
// Hide the "X" after the text field, instead displaying the menu button
displayClearOnInput();
UiTweaks.updateThemePrimaryColor(this);
UiTweaks.tintResources(this);
}
Aggregations