Example usage for android.util Pair Pair

List of usage examples for android.util Pair Pair

Introduction

In this page you can find the example usage for android.util Pair Pair.

Prototype

public Pair(F first, S second) 

Source Link

Document

Constructor for a Pair.

Usage

From source file:org.sufficientlysecure.keychain.ui.adapter.NestedLogAdapter.java

public void setLog(OperationResult.OperationLog log) {
    List<OperationResult.LogEntryParcel> list = log.toList();

    if (mLogEntries != null) {
        mLogEntries.clear();//from www.ja v  a 2s  . co m
    } else {
        mLogEntries = new ArrayList<>(list.size());
    }

    int lastSection = 0;
    for (int i = 0; i < list.size(); i++) {
        OperationResult.LogEntryParcel parcel = list.get(i);
        if (parcel.mIndent < LOG_ENTRY_ITEM_INDENT) {
            lastSection = i;
        }

        mLogEntries.add(new Pair<>(parcel, lastSection));
    }

    notifyDataSetChanged();
}

From source file:org.sufficientlysecure.keychain.ui.CreateYubiKeyPinFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.create_yubi_key_pin_fragment, container, false);

    mPin = (TextView) view.findViewById(R.id.create_yubi_key_pin);
    mAdminPin = (TextView) view.findViewById(R.id.create_yubi_key_admin_pin);
    mBackButton = view.findViewById(R.id.create_key_back_button);
    mNextButton = view.findViewById(R.id.create_key_next_button);

    if (mCreateKeyActivity.mYubiKeyPin == null) {
        new AsyncTask<Void, Void, Pair<Passphrase, Passphrase>>() {
            @Override/*from   w  w  w  .  j  av a  2  s.c  om*/
            protected Pair<Passphrase, Passphrase> doInBackground(Void... unused) {
                SecureRandom secureRandom = new SecureRandom();
                // min = 6, we choose 6
                String pin = "" + secureRandom.nextInt(9) + secureRandom.nextInt(9) + secureRandom.nextInt(9)
                        + secureRandom.nextInt(9) + secureRandom.nextInt(9) + secureRandom.nextInt(9);
                // min = 8, we choose 10, but 6 are equals the PIN
                String adminPin = pin + secureRandom.nextInt(9) + secureRandom.nextInt(9)
                        + secureRandom.nextInt(9) + secureRandom.nextInt(9);

                return new Pair<>(new Passphrase(pin), new Passphrase(adminPin));
            }

            @Override
            protected void onPostExecute(Pair<Passphrase, Passphrase> pair) {
                mCreateKeyActivity.mYubiKeyPin = pair.first;
                mCreateKeyActivity.mYubiKeyAdminPin = pair.second;

                mPin.setText(mCreateKeyActivity.mYubiKeyPin.toStringUnsafe());
                mAdminPin.setText(mCreateKeyActivity.mYubiKeyAdminPin.toStringUnsafe());
            }
        }.execute();
    } else {
        mPin.setText(mCreateKeyActivity.mYubiKeyPin.toStringUnsafe());
        mAdminPin.setText(mCreateKeyActivity.mYubiKeyAdminPin.toStringUnsafe());
    }

    mBackButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            back();
        }
    });
    mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nextClicked();
        }
    });

    return view;
}

From source file:com.fbartnitzek.tasteemall.mainpager.ProducerPagerFragment.java

@Nullable
@Override//from   w  w  w .j av  a2 s  . c  o  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    Log.v(LOG_TAG, "onCreateView, hashCode=" + this.hashCode() + ", " + "inflater = [" + inflater
            + "], container = [" + container + "], savedInstanceState = [" + savedInstanceState + "]");
    mProducerAdapter = new ProducerAdapter(new ProducerAdapter.ProducerAdapterClickHandler() {
        @Override
        public void onClick(String producerName, Uri contentUri, ProducerAdapter.ViewHolder vh) {
            Bundle bundle = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                bundle = ActivityOptions
                        .makeSceneTransitionAnimation(getActivity(),
                                new Pair<View, String>(vh.nameView, vh.nameView.getTransitionName()))
                        .toBundle();
            }
            Intent intent = new Intent(getActivity(), ShowProducerActivity.class).setData(contentUri);
            startActivity(intent, bundle);
        }
    }, getActivity());

    mProducerHeading = (TextView) mRootView.findViewById(R.id.heading_entities);
    mProducerHeading
            .setText(getString(R.string.label_list_entries_preview, getString(R.string.label_producers)));
    RecyclerView reviewRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerview_entities);
    reviewRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    reviewRecyclerView.setAdapter(mProducerAdapter);

    return mRootView;
}

From source file:com.fbartnitzek.tasteemall.mainpager.DrinkPagerFragment.java

@Nullable
@Override/*  w ww .  java 2s  . com*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    Log.v(LOG_TAG, "onCreateView, hashCode=" + this.hashCode() + ", " + "inflater = [" + inflater
            + "], container = [" + container + "], savedInstanceState = [" + savedInstanceState + "]");
    mDrinkAdapter = new DrinkAdapter(new DrinkAdapter.DrinkAdapterClickHandler() {
        @Override
        public void onClick(String drinkName, Uri contentUri, DrinkAdapter.ViewHolder vh) {
            Bundle bundle = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                bundle = ActivityOptions.makeSceneTransitionAnimation(getActivity(),
                        new Pair<View, String>(vh.drinkNameView, vh.drinkNameView.getTransitionName()),
                        new Pair<View, String>(vh.producerNameView, vh.producerNameView.getTransitionName()))
                        .toBundle();
            }
            Intent intent = new Intent(getActivity(), ShowDrinkActivity.class).setData(contentUri);
            startActivity(intent, bundle);
        }
    }, getActivity());

    mDrinksHeading = (TextView) mRootView.findViewById(R.id.heading_entities);
    mDrinksHeading.setText(getString(R.string.label_list_entries_preview, getString(R.string.label_drinks)));
    RecyclerView reviewRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerview_entities);
    reviewRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    reviewRecyclerView.setAdapter(mDrinkAdapter);

    return mRootView;
}

From source file:net.illusor.swipeplayer.fragments.AboutDialog.java

/**
 * Parses version info/*from   w  w  w.  j a v a 2 s.co m*/
 * @param manifestVersionName VersionName from manifest (version:build string)
 * @return Pair of strings (version, build number)
 */
private Pair<String, String> getVersionInfo(String manifestVersionName) {
    int separator = manifestVersionName.indexOf(":");
    String version = manifestVersionName.substring(0, separator);
    String build = manifestVersionName.substring(separator + 1, manifestVersionName.length());
    return new Pair<>(version, build);
}

From source file:com.fbartnitzek.tasteemall.mainpager.ReviewPagerFragment.java

@Nullable
@Override//  w  w  w.j  av a2  s  . c o  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    Log.v(LOG_TAG, "onCreateView, hashCode=" + this.hashCode() + ", " + "inflater = [" + inflater
            + "], container = [" + container + "], savedInstanceState = [" + savedInstanceState + "]");
    mReviewAdapter = new ReviewAdapter(new ReviewAdapter.ReviewAdapterClickHandler() {

        @Override
        public void onClick(Uri contentUri, ReviewAdapter.ViewHolder vh) {
            Bundle bundle = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                bundle = ActivityOptions.makeSceneTransitionAnimation(getActivity(),
                        new Pair<View, String>(vh.drinkNameView, vh.drinkNameView.getTransitionName()),
                        new Pair<View, String>(vh.producerNameView, vh.producerNameView.getTransitionName()))
                        .toBundle();
            }

            startActivity(new Intent(getActivity(), ShowReviewActivity.class).setData(contentUri), bundle);
        }
    }, getActivity());

    mReviewsHeading = (TextView) mRootView.findViewById(R.id.heading_entities);
    mReviewsHeading.setText(getString(R.string.label_list_entries_preview, getString(R.string.label_reviews)));
    RecyclerView reviewRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerview_entities);
    reviewRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    reviewRecyclerView.setAdapter(mReviewAdapter);

    return mRootView;
}

From source file:com.jefftharris.passwdsafe.sync.GDriveLaunchActivity.java

/** Get the database info for the drive file */
private Pair<DbProvider, DbFile> getFile(String fileId) {
    Pair<DbProvider, DbFile> rc = null;
    SyncDb syncDb = SyncDb.acquire();//from   w w w . ja  va  2 s  .c  o m
    try {
        SQLiteDatabase db = syncDb.beginTransaction();
        List<DbProvider> providers = SyncDb.getProviders(db);
        for (DbProvider provider : providers) {
            if (provider.itsType == ProviderType.GDRIVE) {
                DbFile file = SyncDb.getFileByRemoteId(provider.itsId, fileId, db);
                if (file != null) {
                    rc = new Pair<>(provider, file);
                }
                break;
            }
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        Log.e(TAG, "Error opening Google Drive file: " + fileId, e);
    } finally {
        syncDb.endTransactionAndRelease();
    }
    return rc;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.VideoObj.java

@Override
public Pair<JSONObject, byte[]> splitRaw(JSONObject json) {
    byte[] raw = Base64.decode(json.optString(DATA));
    json.remove(DATA);/*from  ww  w.  j a v a2 s  .co m*/
    return new Pair<JSONObject, byte[]>(json, raw);
}

From source file:com.rastating.droidbeard.net.SickbeardAsyncTask.java

protected Bitmap getShowBanner(long tvdbid, int cachedInSB) {
    Bitmap banner;/*from  ww w. j  a va  2  s  .  co m*/
    File cachedBanner = new File(getContext().getCacheDir(), String.valueOf(tvdbid) + ".png");
    if (cachedBanner.exists() && !cachedBanner.isDirectory()) {
        banner = BitmapFactory.decodeFile(cachedBanner.getAbsolutePath());
    } else {
        ArrayList<Pair<String, Object>> params = new ArrayList<Pair<String, Object>>();
        params.add(new Pair<String, Object>("tvdbid", tvdbid));
        banner = getBitmap("show.getbanner", params);

        if (cachedInSB == 1) {
            if (banner != null) {
                try {
                    FileOutputStream stream = new FileOutputStream(cachedBanner);
                    banner.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    stream.flush();
                    stream.close();
                } catch (Exception e) {
                    banner = getDefaultBanner();
                }
            }
        }

        if (banner == null) {
            banner = getDefaultBanner();
        }
    }

    return banner;
}

From source file:com.codestation.henkakuserver.HenkakuServer.java

private Pair<ArrayList<Integer>, List<Byte>> preprocessRop(byte[] urop) throws Exception {

    byte[] loader = new byte[urop.length + ((-urop.length) & 3)];
    System.arraycopy(urop, 0, loader, 0, urop.length);

    ByteBuffer buf = ByteBuffer.wrap(loader).order(ByteOrder.LITTLE_ENDIAN);

    int header_size = 0x40;

    int dsize = buf.getInt(0x10);
    int csize = buf.getInt(0x20);
    int reloc_size = buf.getInt(0x30);
    int symtab_size = buf.getInt(0x38);

    if (csize % 4 != 0) {
        throw new Exception("csize % 4 != 0???");
    }//from w w w.j  a  va2s.c o m

    int reloc_offset = header_size + dsize + csize;
    int symtab = reloc_offset + reloc_size;
    int symtab_n = symtab_size / 8;

    Map<Integer, String> reloc_map = new HashMap<>();

    for (int x = 0; x < symtab_n; ++x) {
        int sym_id = buf.getInt(symtab + 8 * x);
        int str_offset = buf.getInt(symtab + 8 * x + 4);
        int end = str_offset;

        while (loader[end] != 0) {
            end += 1;
        }

        String name = new String(Arrays.copyOfRange(loader, str_offset, end));
        reloc_map.put(sym_id, name);
    }

    Map<Pair<String, Integer>, Integer> reloc_type_map = new HashMap<>();

    reloc_type_map.put(new Pair<>("rop.data", 0), 1);
    reloc_type_map.put(new Pair<>("SceWebKit", 0), 2);
    reloc_type_map.put(new Pair<>("SceLibKernel", 0), 3);
    reloc_type_map.put(new Pair<>("SceLibc", 0), 4);
    reloc_type_map.put(new Pair<>("SceLibHttp", 0), 5);
    reloc_type_map.put(new Pair<>("SceNet", 0), 6);
    reloc_type_map.put(new Pair<>("SceAppMgr", 0), 7);

    int want_len = 0x40 + dsize + csize;

    ArrayList<Integer> urop_js = new ArrayList<>();
    byte[] relocs = new byte[want_len / 4];

    int reloc_n = reloc_size / 8;
    for (int x = 0; x < reloc_n; ++x) {
        int reloc_type = buf.getShort(reloc_offset + 8 * x);
        int sym_id = buf.getShort(reloc_offset + 8 * x + 2);
        int offset = buf.getInt(reloc_offset + 8 * x + 4);

        if (offset % 4 != 0) {
            throw new Exception("offset % 4 != 0???");
        }

        if (relocs[offset / 4] != 0) {
            throw new Exception("symbol relocated twice, not supported");
        }

        Integer wk_reloc_type = reloc_type_map.get(new Pair<>(reloc_map.get(sym_id), reloc_type));

        if (wk_reloc_type == null) {
            throw new Exception("unsupported relocation type");
        }

        relocs[offset / 4] = wk_reloc_type.byteValue();
    }

    for (int x = 0; x < want_len; x += 4) {
        urop_js.add(buf.getInt(x));
    }

    List<Byte> relocsArray = Arrays.asList(ArrayUtils.toObject(relocs));

    return new Pair<>(urop_js, relocsArray);
}