Example usage for android.support.v4.util SparseArrayCompat SparseArrayCompat

List of usage examples for android.support.v4.util SparseArrayCompat SparseArrayCompat

Introduction

In this page you can find the example usage for android.support.v4.util SparseArrayCompat SparseArrayCompat.

Prototype

public SparseArrayCompat() 

Source Link

Usage

From source file:Main.java

public static <T extends View> T get(View view, int id) {
    SparseArrayCompat<View> viewHolder = (SparseArrayCompat<View>) view.getTag();
    if (viewHolder == null) {
        viewHolder = new SparseArrayCompat<>();
        view.setTag(viewHolder);/*from  w  w w  .  ja v  a  2s .co m*/
    }
    View childView = viewHolder.get(id);
    if (childView == null) {
        childView = view.findViewById(id);
        viewHolder.put(id, childView);
    }
    return (T) childView;
}

From source file:com.brotherpowers.cameraview.AspectRatio.java

/**
 * Returns an instance of {@link AspectRatio} specified by {@code x} and {@code y} values.
 * The values {@code x} and {@code} will be reduced by their greatest common divider.
 *
 * @param x The width/*from   w  ww  .j av  a 2s .  co  m*/
 * @param y The height
 * @return An instance of {@link AspectRatio}
 */
public static AspectRatio of(int x, int y) {
    int gcd = gcd(x, y);
    x /= gcd;
    y /= gcd;
    SparseArrayCompat<AspectRatio> arrayX = sCache.get(x);
    if (arrayX == null) {
        AspectRatio ratio = new AspectRatio(x, y);
        arrayX = new SparseArrayCompat<>();
        arrayX.put(y, ratio);
        sCache.put(x, arrayX);
        return ratio;
    } else {
        AspectRatio ratio = arrayX.get(y);
        if (ratio == null) {
            ratio = new AspectRatio(x, y);
            arrayX.put(y, ratio);
        }
        return ratio;
    }
}

From source file:com.mvcoding.financius.data.paging.PageLoader.java

@NonNull
public Observable<PageResult<T>> load(@NonNull DataConverter<T> dataConverter,
        @NonNull DatabaseQuery databaseQuery, @NonNull Observable<Page> pageObservable) {
    final SparseArrayCompat<T> cache = new SparseArrayCompat<>();
    final Observable<Cursor> cursorObservable = database.load(databaseQuery).doOnNext(cursor -> cache.clear());

    return Observable.combineLatest(pageObservable, cursorObservable, (page, cursor) -> {
        final List<T> items = new ArrayList<>();
        for (int i = page.getStart(), size = Math.min(cursor.getCount(),
                page.getStart() + page.getSize()); i < size; i++) {
            T item = cache.get(i);/*ww w. java  2  s . c  om*/
            if (item == null) {
                cursor.moveToPosition(i);
                item = dataConverter.from(cursor);
                cache.put(i, item);
            }
            items.add(item);
        }

        return new PageResult<>(page, items, cache.size() == items.size());
    });
}

From source file:com.dm.material.dashboard.candybar.adapters.IconsSearchAdapter.java

public IconsSearchAdapter(@NonNull Context context, @NonNull SparseArrayCompat<Icon> icons) {
    mContext = context;/*from   w  w  w  .j a  v  a 2  s.  c o  m*/
    mIcons = icons;
    mIconsAll = new SparseArrayCompat<>();
    mIconsAll = mIcons.clone();
    mIsShowIconName = mContext.getResources().getBoolean(R.bool.show_icon_name);
}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

public static void checkForBugs(@NonNull Context context) {
    new AsyncTask<Void, Void, Boolean>() {

        MaterialDialog dialog;//from   www  .ja  va 2s . co m
        StringBuilder sb;
        File folder;
        String file;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            sb = new StringBuilder();
            folder = FileHelper.getCacheDirectory(context);
            file = folder.toString() + "/" + "reportbugs.zip";

            MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
            builder.content(R.string.report_bugs_building).progress(true, 0).progressIndeterminateStyle(true);

            dialog = builder.build();
            dialog.show();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    SparseArrayCompat<String> files = new SparseArrayCompat<>();
                    sb.append(DeviceHelper.getDeviceInfo(context));

                    String brokenAppFilter = buildBrokenAppFilter(context, folder);
                    if (brokenAppFilter != null)
                        files.append(files.size(), brokenAppFilter);

                    String activityList = buildActivityList(context, folder);
                    if (activityList != null)
                        files.append(files.size(), activityList);

                    String stackTrace = Preferences.getPreferences(context).getLatestCrashLog();
                    String crashLog = buildCrashLog(context, folder, stackTrace);
                    if (crashLog != null)
                        files.append(files.size(), crashLog);

                    FileHelper.createZip(files, file);
                    return true;
                } catch (Exception e) {
                    Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            dialog.dismiss();
            if (aBoolean) {
                File zip = new File(file);

                final Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("message/rfc822");
                intent.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { context.getResources().getString(R.string.dev_email) });
                intent.putExtra(Intent.EXTRA_SUBJECT, "Report Bugs " + (context.getString(R.string.app_name)));
                intent.putExtra(Intent.EXTRA_TEXT, sb.toString());
                Uri uri = FileHelper.getUriFromFile(context, context.getPackageName(), zip);
                intent.putExtra(Intent.EXTRA_STREAM, uri);

                context.startActivity(
                        Intent.createChooser(intent, context.getResources().getString(R.string.email_client)));

            } else {
                Toast.makeText(context, R.string.report_bugs_failed, Toast.LENGTH_LONG).show();
            }

            dialog = null;
            sb.setLength(0);
        }
    }.execute();
}

From source file:im.neon.adapters.VectorUnifiedSearchFragmentPagerAdapter.java

/**
 * Constructor/*  w ww.  j a  va 2s.  c  om*/
 *
 * @param fm      the fragment manager
 * @param context the context
 * @param session the session
 * @param roomId  the room id
 */
public VectorUnifiedSearchFragmentPagerAdapter(FragmentManager fm, Context context, MXSession session,
        String roomId) {
    super(fm);
    mContext = context;
    mSession = session;
    mRoomId = roomId;

    mFragmentsData = new SparseArrayCompat<>();

    final boolean searchInRoom = !TextUtils.isEmpty(roomId);

    int pos = 0;
    if (!searchInRoom) {
        mFragmentsData.put(pos, new Pair<Integer, Fragment>(R.string.tab_title_search_rooms, null));
        pos++;
    }

    mFragmentsData.put(pos, new Pair<Integer, Fragment>(R.string.tab_title_search_messages, null));
    pos++;

    if (!searchInRoom) {
        mFragmentsData.put(pos, new Pair<Integer, Fragment>(R.string.tab_title_search_people, null));
        pos++;
    }

    mFragmentsData.put(pos, new Pair<Integer, Fragment>(R.string.tab_title_search_files, null));
}

From source file:com.dm.material.dashboard.candybar.helpers.MuzeiHelper.java

@Nullable
public Wallpaper getRandomDownloadedWallpaper() throws Exception {
    SparseArrayCompat<Wallpaper> downloaded = new SparseArrayCompat<>();
    List<Wallpaper> wallpapers = mDatabase.getWallpapers();
    for (Wallpaper wallpaper : wallpapers) {
        File file = new File(mDirectory + File.separator + wallpaper.getName() + FileHelper.IMAGE_EXTENSION);
        if (file.exists()) {
            downloaded.append(downloaded.size(), wallpaper);
        }//from  w  w  w.j  a  v  a 2s. c o  m
    }

    wallpapers.clear();
    int size = downloaded.size();
    if (size > 0) {
        int position = getRandomInt(size);
        return new Wallpaper(downloaded.get(position).getName(), downloaded.get(position).getAuthor(),
                downloaded.get(position).getURL(), downloaded.get(position).getThumbUrl());
    }
    return null;
}

From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java

public BGAViewHolderHelper(ViewGroup adapterView, View convertView) {
    mViews = new SparseArrayCompat<>();
    mAdapterView = (AdapterView) adapterView;
    mConvertView = convertView;/* w ww . j  a v  a 2 s  . co  m*/
    mContext = convertView.getContext();
}

From source file:com.hao.common.adapter.BaseViewHolderHelper.java

public BaseViewHolderHelper(ViewGroup adapterView, View convertView) {
    mViews = new SparseArrayCompat<>();
    mAdapterView = (AdapterView) adapterView;
    mConvertView = convertView;//w w  w . j av a 2  s  .  c o m
    mContext = convertView.getContext();
}

From source file:net.xisberto.phonetodesktop.ui.LinkListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from  w  w w .  ja  v a 2  s. c  o m*/
    setContentView(R.layout.activity_link_list);

    selectedItems = new SparseArrayCompat<>();

    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    swipeRefreshLayout.setOnRefreshListener(this);
    list_view = (ListView) findViewById(android.R.id.list);
    list_view.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    if ((savedInstanceState != null) && savedInstanceState.containsKey(Utils.EXTRA_TITLES)) {
        taskList = savedInstanceState.getParcelable(Utils.EXTRA_TITLES);
        boolean updating = savedInstanceState.getBoolean(Utils.EXTRA_UPDATING, false);
        swipeRefreshLayout.setRefreshing(updating);
        ArrayList<Integer> selection = savedInstanceState.getIntegerArrayList(SELECTED_ITEMS);

        if (list_view.getAdapter() == null) {
            adapter = new TasksArrayAdapter(this, taskList.items, this);
            list_view.setAdapter(adapter);
        } else {
            adapter = (TasksArrayAdapter) list_view.getAdapter();
        }
        if (selection != null) {
            Log.w("LinkList", String.format("Read selection with %s items", selection.size()));
            for (int i = 0; i < selection.size(); i++) {
                selectedItems.put(selection.get(i), adapter.getItem(i).getId());
                adapter.setChecked(selectedItems.keyAt(i), true);
                onItemChecked(selectedItems.keyAt(i), true);
            }
            adapter.notifyDataSetChanged();
        }

    } else {
        taskList = new TaskList();
        refreshTasks();
    }
}