Search in sources :

Example 1 with BottomPullEffectView

use of fr.neamar.kiss.ui.BottomPullEffectView 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);
}
Also used : ArrayList(java.util.ArrayList) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) KeyboardScrollHider(fr.neamar.kiss.ui.KeyboardScrollHider) Context(android.content.Context) IntentFilter(android.content.IntentFilter) BlockableListView(fr.neamar.kiss.ui.BlockableListView) BottomPullEffectView(fr.neamar.kiss.ui.BottomPullEffectView) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) BottomPullEffectView(fr.neamar.kiss.ui.BottomPullEffectView) ListView(android.widget.ListView) BlockableListView(fr.neamar.kiss.ui.BlockableListView) DataSetObserver(android.database.DataSetObserver) SuppressLint(android.annotation.SuppressLint) RecordAdapter(fr.neamar.kiss.adapter.RecordAdapter) AdapterView(android.widget.AdapterView) OnEditorActionListener(android.widget.TextView.OnEditorActionListener)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 DataSetObserver (android.database.DataSetObserver)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)1 RecordAdapter (fr.neamar.kiss.adapter.RecordAdapter)1 BlockableListView (fr.neamar.kiss.ui.BlockableListView)1 BottomPullEffectView (fr.neamar.kiss.ui.BottomPullEffectView)1 KeyboardScrollHider (fr.neamar.kiss.ui.KeyboardScrollHider)1 ArrayList (java.util.ArrayList)1