Example usage for android.text TextUtils join

List of usage examples for android.text TextUtils join

Introduction

In this page you can find the example usage for android.text TextUtils join.

Prototype

public static String join(@NonNull CharSequence delimiter, @NonNull Iterable tokens) 

Source Link

Document

Returns a string containing the tokens joined by delimiters.

Usage

From source file:org.gnucash.android.ui.account.DeleteAccountDialogFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    String accountName = AccountsDbAdapter.getInstance().getAccountName(mOriginAccountUID);
    getDialog().setTitle(getString(R.string.alert_dialog_ok_delete) + ": " + accountName);
    AccountsDbAdapter accountsDbAdapter = AccountsDbAdapter.getInstance();
    List<String> descendantAccountUIDs = accountsDbAdapter.getDescendantAccountUIDs(mOriginAccountUID, null,
            null);//  ww w .j a v a2 s. c  o m

    String currencyCode = accountsDbAdapter.getCurrencyCode(mOriginAccountUID);
    AccountType accountType = accountsDbAdapter.getAccountType(mOriginAccountUID);

    String transactionDeleteConditions = "(" + DatabaseSchema.AccountEntry.COLUMN_UID + " != ? AND "
            + DatabaseSchema.AccountEntry.COLUMN_CURRENCY + " = ? AND "
            + DatabaseSchema.AccountEntry.COLUMN_TYPE + " = ? AND "
            + DatabaseSchema.AccountEntry.COLUMN_PLACEHOLDER + " = 0 AND "
            + DatabaseSchema.AccountEntry.COLUMN_UID + " NOT IN ('"
            + TextUtils.join("','", descendantAccountUIDs) + "')" + ")";
    Cursor cursor = accountsDbAdapter.fetchAccountsOrderedByFullName(transactionDeleteConditions,
            new String[] { mOriginAccountUID, currencyCode, accountType.name() });

    SimpleCursorAdapter mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), cursor);
    mTransactionsDestinationAccountSpinner.setAdapter(mCursorAdapter);

    //target accounts for transactions and accounts have different conditions
    String accountMoveConditions = "(" + DatabaseSchema.AccountEntry.COLUMN_UID + " != ? AND "
            + DatabaseSchema.AccountEntry.COLUMN_CURRENCY + " = ? AND "
            + DatabaseSchema.AccountEntry.COLUMN_TYPE + " = ? AND " + DatabaseSchema.AccountEntry.COLUMN_UID
            + " NOT IN ('" + TextUtils.join("','", descendantAccountUIDs) + "')" + ")";
    cursor = accountsDbAdapter.fetchAccountsOrderedByFullName(accountMoveConditions,
            new String[] { mOriginAccountUID, currencyCode, accountType.name() });
    mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(), cursor);
    mAccountsDestinationAccountSpinner.setAdapter(mCursorAdapter);

    setListeners();

    //this comes after the listeners because of some useful bindings done there
    if (cursor.getCount() == 0) {
        mMoveAccountsRadioButton.setEnabled(false);
        mMoveAccountsRadioButton.setChecked(false);
        mDeleteAccountsRadioButton.setChecked(true);
        mMoveTransactionsRadioButton.setEnabled(false);
        mMoveTransactionsRadioButton.setChecked(false);
        mDeleteTransactionsRadioButton.setChecked(true);
        mAccountsDestinationAccountSpinner.setVisibility(View.GONE);
        mTransactionsDestinationAccountSpinner.setVisibility(View.GONE);
    }
}

From source file:com.github.gfx.android.orma.migration.SchemaDiffMigration.java

public void migrate(Database db) {
    if (SQLiteMaster.checkIfTableNameExists(db, MIGRATION_STEPS_TABLE_1)) {
        try {// www.jav  a 2 s.  c o  m
            db.beginTransaction();

            db.execSQL(SCHEMA_DIFF_DDL);
            String[] src = { kId, "0", kVersionName, kVersionCode, kSchemaHash, kSql, kArgs,
                    kCreatedTimestamp };
            String[] dst = { kId, kDbVersion, kVersionName, kVersionCode, kSchemaHash, kSql, kArgs,
                    kCreatedTimestamp };
            db.execSQL("INSERT INTO " + MIGRATION_STEPS_TABLE + " (" + TextUtils.join(", ", dst) + ") SELECT "
                    + TextUtils.join(", ", src) + " FROM " + MIGRATION_STEPS_TABLE_1);
            db.execSQL("DROP TABLE " + MIGRATION_STEPS_TABLE_1);
            db.execSQL(SCHEMA_DIFF_DDL);

            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    } else {
        db.execSQL(SCHEMA_DIFF_DDL);
    }
}

From source file:com.example.android.apprestrictionschema.AppRestrictionSchemaFragment.java

private void updateApprovals(RestrictionEntry entry, Bundle restrictions) {
    String[] approvals;//from w  w w . j  av  a2s.  c o m
    if (restrictions == null || !restrictions.containsKey(KEY_APPROVALS)) {
        approvals = entry.getAllSelectedStrings();
    } else {
        approvals = restrictions.getStringArray(KEY_APPROVALS);
    }
    String text;
    if (approvals == null || approvals.length == 0) {
        text = getString(R.string.none);
    } else {
        text = TextUtils.join(", ", approvals);
    }
    mTextApprovals.setText(getString(R.string.approvals_you_have, text));
}

From source file:ru.gkpromtech.exhibition.events.EventDetailsActivity.java

@Override
public void onFavoriteClicked(int eventId, int state) {
    EventReader.getInstance(context).updateFavorite(eventId, state, SQLiteDatabase.CONFLICT_REPLACE);

    if (!changedItems.contains(eventId)) {
        changedItems.add(eventId);/*  w  w w  .ja va 2 s .  com*/
    }

    final int eventid = eventId;
    Event e = EventReader.getInstance(context).findItem(eventId);
    if (e != null) {

        EventCalendar cal = EventCalendar.getInstance(context);
        cal.setEventCalendarInteractionListener(new EventCalendar.EventCalendarInteraction() {
            @Override
            public void eventInserted(int calEventId) {
                EventReader.getInstance(context).updateCalendarEvent(eventid, calEventId,
                        SQLiteDatabase.CONFLICT_REPLACE);
            }

            @Override
            public void eventRemoved(int calEventId) {
                EventReader.getInstance(context).updateCalendarEvent(eventid, -1,
                        SQLiteDatabase.CONFLICT_REPLACE);
            }
        });

        // add to calendar
        if (state == 1) {
            // get places for event
            List<Place> places = EventReader.getInstance(context).getPlaces(eventId);
            String[] sPlaces = new String[places.size()];
            for (int i = 0; i < places.size(); i++) {
                sPlaces[i] = places.get(i).name;
            }

            EventCalendar.getInstance(context).insertEventToCalendar(e.header, e.details,
                    TextUtils.join(", ", sPlaces), e.date, true);
        }
        // remove from calendar
        else {
            EventFavorite fav = EventReader.getInstance(context).getEventFavorite(eventId);
            if (fav.calendarEventId != null) {
                EventCalendar.getInstance(context).removeEventFromCalendar(fav.calendarEventId);
            }
        }
    }
}

From source file:org.ale.scanner.zotero.web.zotero.ZoteroAPIClient.java

public URI buildURI(Map<String, String> queryTerms, String... pathSections) {
    // Returns:/* w w  w  .ja  v a2  s.c o m*/
    // https://api.zotero.org/<user or group>/<persona>/<action>?key=<key>
    String base;
    StringBuilder queryB = new StringBuilder();
    if (queryTerms == null) {
        queryB.append("key=").append(mAccount.getKey());
    } else {
        for (Entry<String, String> e : queryTerms.entrySet()) {
            queryB.append(e.getKey()).append("=").append(e.getValue()).append("&");
        }
        // Delete the last ampersand
        queryB.deleteCharAt(queryB.length() - 1);
    }

    String persona = pathSections[0];
    if (persona.equals(mAccount.getUid())) {
        base = ZOTERO_USERS_URL;
    } else {
        base = ZOTERO_GROUPS_URL;
    }
    String path = TextUtils.join("/", pathSections);
    return URI.create(base + "/" + path + "?" + queryB.toString());
}

From source file:com.kaixin.connect.Kaixin.java

/**
 * access_token(User-Agent Flow)/*  w  ww.  j  av  a  2 s. c  o m*/
 * 
 * @param context
 * @param permissions
 *            http://wiki.open.kaixin001.com/index.php?id=OAuth%E6%96%
 *            87%E6%A1%A3#REST%E6%
 *            8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85%
 *            A 7%E8%A1%A8
 * @param listener
 * @param redirectUrl
 * @param responseType
 */
private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener,
        final String redirectUrl, String responseType) {

    CookieSyncManager.createInstance(context);

    Bundle params = new Bundle();
    params.putString("client_id", API_KEY);
    params.putString("response_type", responseType);
    params.putString("redirect_uri", redirectUrl);
    params.putString("state", "");
    params.putString("display", "page");
    params.putString("oauth_client", "1");

    if (permissions != null && permissions.length > 0) {
        String scope = TextUtils.join(" ", permissions);
        params.putString("scope", scope);
    }

    String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params);
    if (context
            .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
        Util.showAlert(context, "", "");
    } else {
        new KaixinDialog(context, url, new KaixinDialogListener() {
            @Override
            public int onPageBegin(String url) {
                return KaixinDialogListener.DIALOG_PROCCESS;
            }

            @Override
            public void onPageFinished(String url) {
            }

            @Override
            public boolean onPageStart(String url) {
                return (KaixinDialogListener.PROCCESSED == parseUrl(url));
            }

            @Override
            public void onReceivedError(int errorCode, String description, String failingUrl) {
                listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl));
            }

            private int parseUrl(String url) {
                if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) {
                    Bundle values = Util.parseUrl(url);
                    String error = values.getString("error");// 
                    if (error != null) {
                        if (ACCESS_DENIED.equalsIgnoreCase(error)) {
                            listener.onAuthCancel(values);
                        } else if (LOGIN_DENIED.equalsIgnoreCase(error)) {
                            listener.onAuthCancelLogin();
                        } else {
                            listener.onAuthError(new KaixinAuthError(error, error, url));
                        }

                        Util.clearCookies(context);

                        setAccessToken(null);
                        setRefreshToken(null);
                        setAccessExpires(0L);

                    } else {
                        this.authComplete(values, url);
                    }
                    return KaixinDialogListener.PROCCESSED;
                }
                return KaixinDialogListener.UNPROCCESS;
            }

            private void authComplete(Bundle values, String url) {
                CookieSyncManager.getInstance().sync();
                String accessToken = values.getString(ACCESS_TOKEN);
                String refreshToken = values.getString(REFRESH_TOKEN);
                String expiresIn = values.getString(EXPIRES_IN);
                if (accessToken != null && refreshToken != null && expiresIn != null) {
                    try {
                        setAccessToken(accessToken);
                        setRefreshToken(refreshToken);
                        setAccessExpiresIn(expiresIn);
                        listener.onAuthComplete(values);
                    } catch (Exception e) {
                        listener.onAuthError(
                                new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString()));
                    }
                } else {
                    listener.onAuthError(new KaixinAuthError("", "", url));
                }
            }
        }).show();
    }
}

From source file:com.github.gfx.android.orma.example.activity.MainActivity.java

void associations() {
    orma.deleteFromCategory().execute();
    orma.deleteFromItem().execute();//from w  w  w  . j  a  va  2s  . c  o m

    Category category = orma.relationOfCategory().getOrCreate(0, new ModelFactory<Category>() {
        @NonNull
        @Override
        public Category call() {
            return new Category("foo");
        }
    });

    Item item = category.createItem(orma, ZonedDateTime.now().toString());
    Log.d(TAG, "created: " + item);

    Log.d(TAG, "A category has many items (" + category.getItems(orma).count() + ")");
    Log.d(TAG, TextUtils.join(", ", category.getItems(orma)));
}

From source file:com.m2team.phuotstory.activity.DirectionActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_direction);
    ButterKnife.bind(this);
    final ArrayList<LatLng> latLngs = new ArrayList<>();
    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);

    textProgress = (TextView) findViewById(R.id.textProgress);
    textProgress.setVisibility(View.GONE);

    buttonAnimate.setColorNormalResId(R.color.white);
    buttonAnimate.setIcon(R.drawable.ic_action_direction);
    buttonAnimate.setTitle(getString(R.string.animation));
    buttonAnimate.setSize(FloatingActionButton.SIZE_NORMAL);
    buttonAnimate.setEnabled(false);/*from  w w  w  . j  a va 2  s . com*/
    buttonAnimate.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            gd.animateDirection(mMap, latLngs, GoogleDirection.SPEED_VERY_FAST, true, false, true, true,
                    new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_motor2)), false,
                    true, null);
        }
    });
    totalDistance = 0;

    if (getIntent() != null && getIntent().getExtras() != null) {
        Bundle extras = getIntent().getExtras();
        locations = extras.getParcelableArrayList(Constant.ARRAY_LOCATION);
        if (locations != null && locations.size() > 0) {
            index = 0;
            final int locSize = locations.size();
            gd = new GoogleDirection(this);

            mMap.clear();
            MyLocation sLoc = locations.get(0);
            MyLocation eLoc = locations.get(locations.size() - 1);
            if (eLoc.equals(sLoc)) {
                eLoc = locations.get(locations.size() - 2);
            }
            mMap.addMarker(new MarkerOptions().position(newLatLong(sLoc))
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_action_start)));

            mMap.addMarker(new MarkerOptions().position(newLatLong(eLoc))
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_action)));

            MyLocation temp1, temp2;
            for (int i = 0; i < locations.size() - 1; i++) {
                temp1 = locations.get(i);
                temp2 = locations.get(i + 1);
                latLngs.add(newLatLong(temp1));
                gd.request(newLatLong(temp1), newLatLong(temp2), GoogleDirection.MODE_DRIVING);
                /*if (i > 0 && i < locations.size() - 1)
                mMap.addMarker(new MarkerOptions().position(newLatLong(temp1))
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_action_between)));*/
            }
            latLngs.add(newLatLong(eLoc));
            latLngs.add(newLatLong(sLoc));
            //request from last to first location
            gd.request(newLatLong(eLoc), newLatLong(sLoc), GoogleDirection.MODE_DRIVING);

            final ArrayList<String> addressList = new ArrayList<>();

            gd.setOnDirectionResponseListener(new OnDirectionResponseListener() {
                public void onResponse(String status, Document doc, GoogleDirection gd) {
                    index++;
                    String startAddress = gd.getStartAddress(doc);

                    if (!addressList.contains(startAddress))
                        addressList.add(startAddress);
                    totalDistance += gd.getTotalDistanceValue(doc);
                    mMap.addPolyline(gd.getPolyline(doc, 5, R.color.md_blue_600));
                    if (index == locSize) {
                        buttonAnimate.setEnabled(true);
                        tv_start_address.setText(TextUtils.join("->", addressList));
                        tv_distance.setText("Total distance: " + (totalDistance / 1000) + " km");
                        LatLngBounds.Builder builder = new LatLngBounds.Builder();
                        for (LatLng latLng : latLngs) {
                            builder.include(latLng);
                        }
                        LatLngBounds bounds = builder.build();
                        mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 300));
                        //clusterMarker(mMap, locations);
                    }
                }
            });

            gd.setOnAnimateListener(new OnAnimateListener() {
                public void onStart() {
                    textProgress.setVisibility(View.VISIBLE);
                }

                public void onProgress(int progress, int total) {
                    textProgress.setText(progress + " / " + total);
                }

                public void onFinish() {
                    buttonAnimate.setEnabled(true);
                    textProgress.setVisibility(View.GONE);
                }
            });

        } else {
            Toast.makeText(this, getString(R.string.fail_data), Toast.LENGTH_SHORT).show();
        }
    } else {
        Toast.makeText(this, getString(R.string.fail_data), Toast.LENGTH_SHORT).show();
    }
}

From source file:com.ds.kaixin.Kaixin.java

/**
 * access_token(User-Agent Flow)/* www .  j ava 2 s  .  com*/
 * 
 * @param context
 * @param permissions
 *            ?http://wiki.open.kaixin001.com/index.php?id=OAuth%E6%
 *            96% 87%E6%A1%A3#REST%E6%
 *            8E%A5%E5%8F%A3%E5%92%8COAuth%E6%9D%83%E9%99%90%E5%AF%B9%E7%85%
 *            A 7%E8%A1%A8
 * @param listener
 * @param redirectUrl
 * @param responseType
 */
private void authorize(final Context context, String[] permissions, final KaixinAuthListener listener,
        final String redirectUrl, String responseType) {

    CookieSyncManager.createInstance(context);

    Bundle params = new Bundle();
    params.putString("client_id", API_KEY);
    params.putString("response_type", responseType);
    params.putString("redirect_uri", redirectUrl);
    params.putString("state", "");
    params.putString("display", "page");
    params.putString("oauth_client", "1");

    if (permissions != null && permissions.length > 0) {
        String scope = TextUtils.join(" ", permissions);
        params.putString("scope", scope);
    }

    String url = KX_AUTHORIZE_URL + "?" + Util.encodeUrl(params);
    if (context
            .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
        Util.showAlert(context, "", "??");
    } else {
        new KaixinDialog(context, url, new KaixinDialogListener() {

            public int onPageBegin(String url) {
                return KaixinDialogListener.DIALOG_PROCCESS;
            }

            public void onPageFinished(String url) {
            }

            public boolean onPageStart(String url) {
                return (KaixinDialogListener.PROCCESSED == parseUrl(url));
            }

            public void onReceivedError(int errorCode, String description, String failingUrl) {
                listener.onAuthError(new KaixinAuthError(String.valueOf(errorCode), description, failingUrl));
            }

            private int parseUrl(String url) {
                if (url.startsWith(KX_AUTHORIZE_CALLBACK_URL)) {
                    Bundle values = Util.parseUrl(url);
                    String error = values.getString("error");// 
                    if (error != null) {
                        if (ACCESS_DENIED.equalsIgnoreCase(error)) {
                            listener.onAuthCancel(values);
                        } else if (LOGIN_DENIED.equalsIgnoreCase(error)) {
                            listener.onAuthCancelLogin();
                        } else {
                            listener.onAuthError(new KaixinAuthError(error, error, url));
                        }

                        Util.clearCookies(context);

                        setAccessToken(null);
                        setRefreshToken(null);
                        setAccessExpires(0L);

                    } else {
                        this.authComplete(values, url);
                    }
                    return KaixinDialogListener.PROCCESSED;
                }
                return KaixinDialogListener.UNPROCCESS;
            }

            private void authComplete(Bundle values, String url) {
                CookieSyncManager.getInstance().sync();
                String accessToken = values.getString(ACCESS_TOKEN);
                String refreshToken = values.getString(REFRESH_TOKEN);
                String expiresIn = values.getString(EXPIRES_IN);
                if (accessToken != null && refreshToken != null && expiresIn != null) {
                    try {
                        setAccessToken(accessToken);
                        setRefreshToken(refreshToken);
                        setAccessExpiresIn(expiresIn);
                        listener.onAuthComplete(values);
                    } catch (Exception e) {
                        listener.onAuthError(
                                new KaixinAuthError(e.getClass().getName(), e.getMessage(), e.toString()));
                    }
                } else {
                    listener.onAuthError(new KaixinAuthError("",
                            "", url));
                }
            }
        }).show();
    }
}

From source file:com.secupwn.aimsicd.ui.fragments.CellInfoFragment.java

void updateCipheringIndicator() {
    final List<String> list = rilExecutor.getCipheringInfo();
    getActivity().runOnUiThread(new Runnable() {
        @Override/*w  ww. jav a  2s. c o m*/
        public void run() {
            if (list != null) {
                mCipheringIndicatorLabel.setVisibility(View.VISIBLE);
                mCipheringIndicator.setVisibility(View.VISIBLE);
                mCipheringIndicator.setText(TextUtils.join("\n", list));
            }
        }
    });
}