Search in sources :

Example 16 with DataSetObserver

use of android.database.DataSetObserver 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)

Example 17 with DataSetObserver

use of android.database.DataSetObserver in project materialistic by hidroh.

the class SpinnerPreference method onBindViewHolder.

@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
    super.onBindViewHolder(holder);
    final Spinner spinner = (Spinner) holder.findViewById(R.id.spinner);
    holder.itemView.setOnClickListener(v -> spinner.performClick());
    spinner.setAdapter(new SpinnerAdapter() {

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = createDropDownView(position, parent);
            }
            bindDropDownView(position, convertView);
            return convertView;
        }

        @Override
        public void registerDataSetObserver(DataSetObserver observer) {
        // no op
        }

        @Override
        public void unregisterDataSetObserver(DataSetObserver observer) {
        // no op
        }

        @Override
        public int getCount() {
            return mEntries.length;
        }

        @Override
        public Object getItem(int position) {
            // not applicable
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public boolean hasStableIds() {
            return true;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getDropDownView(position, convertView, parent);
        }

        @Override
        public int getItemViewType(int position) {
            return 0;
        }

        @Override
        public int getViewTypeCount() {
            return 1;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    });
    spinner.setSelection(mSelection);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            mSelection = position;
            persistString(mEntryValues[position]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // no op
        }
    });
}
Also used : SpinnerAdapter(android.widget.SpinnerAdapter) Spinner(android.widget.Spinner) ViewGroup(android.view.ViewGroup) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) DataSetObserver(android.database.DataSetObserver)

Example 18 with DataSetObserver

use of android.database.DataSetObserver in project android_frameworks_base by AOSPA.

the class CalendarViewLegacyDelegate method setUpAdapter.

/**
     * Creates a new adapter if necessary and sets up its parameters.
     */
private void setUpAdapter() {
    if (mAdapter == null) {
        mAdapter = new WeeksAdapter(mContext);
        mAdapter.registerDataSetObserver(new DataSetObserver() {

            @Override
            public void onChanged() {
                if (mOnDateChangeListener != null) {
                    Calendar selectedDay = mAdapter.getSelectedDay();
                    mOnDateChangeListener.onSelectedDayChange(mDelegator, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH), selectedDay.get(Calendar.DAY_OF_MONTH));
                }
            }
        });
        mListView.setAdapter(mAdapter);
    }
    // refresh the view with the new parameters
    mAdapter.notifyDataSetChanged();
}
Also used : Calendar(android.icu.util.Calendar) DataSetObserver(android.database.DataSetObserver)

Example 19 with DataSetObserver

use of android.database.DataSetObserver in project apps-android-commons by commons-app.

the class ContributionsActivity method notifyAndMigrateDataSetObservers.

private void notifyAndMigrateDataSetObservers() {
    Adapter adapter = contributionsList.getAdapter();
    // First, move the observers over to the adapter now that we have it.
    for (DataSetObserver observer : observersWaitingForLoad) {
        adapter.registerDataSetObserver(observer);
    }
    observersWaitingForLoad.clear();
    // Now fire off a first notification...
    for (DataSetObserver observer : observersWaitingForLoad) {
        observer.onChanged();
    }
}
Also used : Adapter(android.widget.Adapter) CursorAdapter(android.support.v4.widget.CursorAdapter) DataSetObserver(android.database.DataSetObserver)

Example 20 with DataSetObserver

use of android.database.DataSetObserver in project apps-android-commons by commons-app.

the class MediaDetailFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    Media media = detailProvider.getMediaAtPosition(index);
    if (media == null) {
        // Ask the detail provider to ping us when we're ready
        Timber.d("MediaDetailFragment not yet ready to display details; registering observer");
        dataObserver = new DataSetObserver() {

            @Override
            public void onChanged() {
                if (!isAdded()) {
                    return;
                }
                Timber.d("MediaDetailFragment ready to display delayed details!");
                detailProvider.unregisterDataSetObserver(dataObserver);
                dataObserver = null;
                displayMediaDetails(detailProvider.getMediaAtPosition(index));
            }
        };
        detailProvider.registerDataSetObserver(dataObserver);
    } else {
        Timber.d("MediaDetailFragment ready to display details");
        displayMediaDetails(media);
    }
}
Also used : Media(fr.free.nrw.commons.Media) DataSetObserver(android.database.DataSetObserver)

Aggregations

DataSetObserver (android.database.DataSetObserver)36 View (android.view.View)14 AdapterView (android.widget.AdapterView)9 ImageView (android.widget.ImageView)9 TextView (android.widget.TextView)9 OnClickListener (android.view.View.OnClickListener)8 ListView (android.widget.ListView)8 Calendar (android.icu.util.Calendar)5 PrintManager (android.print.PrintManager)5 PrinterInfo (android.print.PrinterInfo)5 PrintServiceInfo (android.printservice.PrintServiceInfo)5 SearchView (android.widget.SearchView)5 Intent (android.content.Intent)3 Calendar (java.util.Calendar)3 Bitmap (android.graphics.Bitmap)2 DisplayMetrics (android.util.DisplayMetrics)2 ViewGroup (android.view.ViewGroup)2 ScrollView (android.widget.ScrollView)2 HowaboutApplication (io.recom.howabout.HowaboutApplication)2 ArrayList (java.util.ArrayList)2