Search in sources :

Example 1 with Result

use of fr.neamar.kiss.result.Result in project KISS by Neamar.

the class MainActivity method displayFavorites.

public void displayFavorites() {
    int[] favoritesIds = favoritesKissBar.getVisibility() == View.VISIBLE ? favsIds : favBarIds;
    ArrayList<Pojo> favoritesPojo = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
    if (favoritesPojo.size() == 0) {
        int noFavCnt = prefs.getInt("no-favorites-tip", 0);
        if (noFavCnt < 3 && !prefs.getBoolean("enable-favorites-bar", false)) {
            Toast toast = Toast.makeText(MainActivity.this, getString(R.string.no_favorites), Toast.LENGTH_SHORT);
            toast.show();
            prefs.edit().putInt("no-favorites-tip", ++noFavCnt).apply();
        }
    }
    // Don't look for items after favIds length, we won't be able to display them
    for (int i = 0; i < Math.min(favoritesIds.length, favoritesPojo.size()); i++) {
        Pojo pojo = favoritesPojo.get(i);
        ImageView image = (ImageView) findViewById(favoritesIds[i]);
        Result result = Result.fromPojo(MainActivity.this, pojo);
        Drawable drawable = result.getDrawable(MainActivity.this);
        if (drawable != null) {
            image.setImageDrawable(drawable);
        } else {
            Log.e(TAG, "Falling back to default image for favorite.");
            // Use the default contact image otherwise
            image.setImageResource(R.drawable.ic_contact);
        }
        image.setVisibility(View.VISIBLE);
        image.setContentDescription(pojo.displayName);
    }
    // Hide empty favorites (not enough favorites yet)
    for (int i = favoritesPojo.size(); i < favoritesIds.length; i++) {
        findViewById(favoritesIds[i]).setVisibility(View.GONE);
    }
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) Toast(android.widget.Toast) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) SuppressLint(android.annotation.SuppressLint) Result(fr.neamar.kiss.result.Result)

Example 2 with Result

use of fr.neamar.kiss.result.Result in project KISS by Neamar.

the class RecordAdapter method onClick.

public void onClick(final int position, View v) {
    final Result result;
    try {
        result = results.get(position);
        result.launch(getContext(), v);
    } catch (ArrayIndexOutOfBoundsException ignored) {
        return;
    }
    // Record the launch after some period,
    // * to ensure the animation runs smoothly
    // * to avoid a flickering -- launchOccurred will refresh the list
    // Thus TOUCH_DELAY * 3
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            parent.launchOccurred(results.size() - position, result);
        }
    }, KissApplication.TOUCH_DELAY * 3);
}
Also used : Handler(android.os.Handler) ShortcutsResult(fr.neamar.kiss.result.ShortcutsResult) PhoneResult(fr.neamar.kiss.result.PhoneResult) Result(fr.neamar.kiss.result.Result) SettingsResult(fr.neamar.kiss.result.SettingsResult) AppResult(fr.neamar.kiss.result.AppResult) SearchResult(fr.neamar.kiss.result.SearchResult) ContactsResult(fr.neamar.kiss.result.ContactsResult) TogglesResult(fr.neamar.kiss.result.TogglesResult)

Example 3 with Result

use of fr.neamar.kiss.result.Result in project KISS by Neamar.

the class MainActivity method registerLongClickOnFavorites.

private void registerLongClickOnFavorites() {
    View.OnLongClickListener listener = new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            int favNumber = Integer.parseInt((String) view.getTag());
            ArrayList<Pojo> favorites = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
            if (favNumber >= favorites.size()) {
                // Clicking on a favorite before everything is loaded.
                Log.i(TAG, "Long clicking on an unitialized favorite.");
                return false;
            }
            // Favorites handling
            Pojo pojo = favorites.get(favNumber);
            final Result result = Result.fromPojo(MainActivity.this, pojo);
            result.getPopupMenu(MainActivity.this, adapter, view).show();
            return true;
        }
    };
    for (int id : favBarIds) {
        findViewById(id).setOnLongClickListener(listener);
    }
    for (int id : favsIds) {
        findViewById(id).setOnLongClickListener(listener);
    }
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) 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) SuppressLint(android.annotation.SuppressLint) Result(fr.neamar.kiss.result.Result)

Example 4 with Result

use of fr.neamar.kiss.result.Result in project KISS by Neamar.

the class MainActivity method onFavoriteButtonClicked.

public void onFavoriteButtonClicked(View favorite) {
    // The bar is shown due to dispatchTouchEvent, hide it again to stop the bad ux.
    displayKissBar(false);
    int favNumber = Integer.parseInt((String) favorite.getTag());
    ArrayList<Pojo> favorites = KissApplication.getDataHandler(MainActivity.this).getFavorites(tryToRetrieve);
    if (favNumber >= favorites.size()) {
        // Clicking on a favorite before everything is loaded.
        Log.i(TAG, "Clicking on an unitialized favorite.");
        return;
    }
    // Favorites handling
    Pojo pojo = favorites.get(favNumber);
    final Result result = Result.fromPojo(MainActivity.this, pojo);
    result.fastLaunch(MainActivity.this, favorite);
}
Also used : Pojo(fr.neamar.kiss.pojo.Pojo) SuppressLint(android.annotation.SuppressLint) Result(fr.neamar.kiss.result.Result)

Aggregations

Result (fr.neamar.kiss.result.Result)4 SuppressLint (android.annotation.SuppressLint)3 Pojo (fr.neamar.kiss.pojo.Pojo)3 ImageView (android.widget.ImageView)2 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 AppResult (fr.neamar.kiss.result.AppResult)1 ContactsResult (fr.neamar.kiss.result.ContactsResult)1 PhoneResult (fr.neamar.kiss.result.PhoneResult)1 SearchResult (fr.neamar.kiss.result.SearchResult)1 SettingsResult (fr.neamar.kiss.result.SettingsResult)1 ShortcutsResult (fr.neamar.kiss.result.ShortcutsResult)1 TogglesResult (fr.neamar.kiss.result.TogglesResult)1 BlockableListView (fr.neamar.kiss.ui.BlockableListView)1 BottomPullEffectView (fr.neamar.kiss.ui.BottomPullEffectView)1