Example usage for android.app Activity getText

List of usage examples for android.app Activity getText

Introduction

In this page you can find the example usage for android.app Activity getText.

Prototype

@NonNull
public final CharSequence getText(@StringRes int resId) 

Source Link

Document

Return a localized, styled CharSequence from the application's package's default string table.

Usage

From source file:com.docd.purefm.utils.BookmarksHelper.java

@NonNull
public static BookmarkItem createUserBookmarkItem(@NonNull final Activity activity,
        @NonNull final String path) {
    final BookmarkItem item = new BookmarkItem();
    item.mDisplayName = FilenameUtils.getName(path);
    if (item.mDisplayName.equals(Environment.sRootDirectory.getAbsolutePath())) {
        item.mDisplayName = activity.getText(R.string.root);
    }/*  www .  ja  v a  2 s. c  o m*/
    item.mDisplayPath = path;
    item.mIcon = ThemeUtils.getDrawableNonNull(activity.getTheme(), R.attr.ic_bookmark);
    return item;
}

From source file:edu.cmu.cylab.starslinger.view.ComposeFragment.java

public static AlertDialog.Builder xshowChangeFileOptions(Activity act) {
    final CharSequence[] items = new CharSequence[] { act.getText(R.string.menu_Remove),
            act.getText(R.string.menu_Change) };
    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    ad.setTitle(R.string.title_FileOptions);
    ad.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

        @Override//from ww w  .j  a  va  2s  . c om
        public void onClick(DialogInterface dialog, int item) {
            dialog.dismiss();
            switch (item) {
            case 0: // remove
                doFileRemove();
                break;
            case 1: // change
                doFileSelect();
                break;
            default:
                break;
            }
        }

    });
    ad.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });
    return ad;
}

From source file:org.alfresco.mobile.android.application.manager.ActionManager.java

public static void actionSend(Activity activity, File contentFile) {
    try {// ww w  . jav a  2  s  . c om
        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_SUBJECT, contentFile.getName());
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(contentFile));
        i.setType(MimeTypeManager.getMIMEType(activity, contentFile.getName()));
        activity.startActivity(Intent.createChooser(i, activity.getText(R.string.share_content)));
    } catch (ActivityNotFoundException e) {
        MessengerManager.showToast(activity, R.string.error_unable_share_content);
    }
}

From source file:com.docd.purefm.utils.BookmarksHelper.java

@NonNull
public static List<BookmarkItem> getAllBookmarks(@NonNull final Activity activity) {
    final List<BookmarkItem> items = new ArrayList<>();
    int internalCount = 0;
    int externalCount = 0;
    int usbCount = 0;

    final Resources.Theme theme = activity.getTheme();
    final Drawable iconStorage = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_storage);
    final Drawable iconSdcard = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_sdcard);
    final Drawable iconUsb = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_usb);
    final Drawable iconUser = ThemeUtils.getDrawableNonNull(theme, R.attr.ic_bookmark);

    for (final StorageHelper.StorageVolume v : Environment.getStorageVolumes()) {
        final BookmarkItem item = new BookmarkItem();
        switch (v.getType()) {
        case EXTERNAL:
            externalCount++;/*  ww  w  .  jav a  2  s .  com*/
            item.mIcon = iconSdcard;
            item.mDisplayName = activity.getText(R.string.storage_sdcard);
            if (externalCount > 1) {
                item.mDisplayName = TextUtils.concat(item.mDisplayName, " (" + externalCount + ")");
            }
            break;

        case USB:
            usbCount++;
            item.mIcon = iconUsb;
            item.mDisplayName = activity.getText(R.string.storage_usb);
            if (usbCount > 1) {
                item.mDisplayName = TextUtils.concat(item.mDisplayName, " (" + usbCount + ")");
            }
            break;

        case INTERNAL:
        default:
            internalCount++;
            item.mIcon = iconStorage;
            item.mDisplayName = activity.getText(R.string.storage_internal);
            if (internalCount > 1) {
                item.mDisplayName = TextUtils.concat(item.mDisplayName, " (" + internalCount + ")");
            }
            break;
        }
        item.mDisplayPath = v.file.getAbsolutePath();
        items.add(item);
    }

    for (final String bookmark : Settings.getInstance(activity).getBookmarks()) {
        final BookmarkItem item = new BookmarkItem();
        item.mDisplayName = FilenameUtils.getName(bookmark);
        if (item.mDisplayName.equals(Environment.sRootDirectory.getAbsolutePath())) {
            item.mDisplayName = activity.getText(R.string.root);
        }
        item.mDisplayPath = bookmark;
        item.mIcon = iconUser;
        items.add(item);
    }
    return items;
}

From source file:im.vector.fragments.ContactsListDialogFragment.java

/**
 * Init the dialog view.//from  w  w  w . j  a v a2s  .c o  m
 * @param v the dialog view.
 */
void initView(View v) {
    mListView = ((ListView) v.findViewById(R.id.listView_contacts));

    // get the local contacts
    mLocalContacts = new ArrayList<Contact>(ContactsManager.getLocalContactsSnapshot(getActivity()));

    mAdapter = new ContactsListAdapter(getActivity(), R.layout.adapter_item_contact);

    // sort them
    Collections.sort(mLocalContacts, alphaComparator);

    mListView.setFastScrollAlwaysVisible(true);
    mListView.setFastScrollEnabled(true);
    mListView.setAdapter(mAdapter);

    refreshAdapter();

    // a button could be added to filter the contacts to display only the matrix users
    // but the lookup method is too slow (1 address / request).
    // it could be enabled when a batch request will be implemented
    /*
    final Button button = (Button)v.findViewById(R.id.button_matrix_users);
            
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        mDisplayOnlyMatrixUsers = !mDisplayOnlyMatrixUsers;
            
        if (mDisplayOnlyMatrixUsers) {
            button.setBackgroundResource(R.drawable.matrix_user);
        } else {
            button.setBackgroundResource(R.drawable.ic_menu_allfriends);
        }
            
        refreshAdapter();
    }
    });*/

    final EditText editText = (EditText) v.findViewById(R.id.editText_contactBox);

    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(android.text.Editable s) {
            ContactsListDialogFragment.this.mSearchPattern = s.toString();
            refreshAdapter();
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    // tap on one of them
    // if he is a matrix, offer to start a chat
    // it he is not a matrix user, offer to invite him by email or SMS.
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final Contact contact = mAdapter.getItem(position);
            final Activity activity = ContactsListDialogFragment.this.getActivity();

            if (contact.hasMatridIds(ContactsListDialogFragment.this.getActivity())) {
                final Contact.MXID mxid = contact.getFirstMatrixId();
                // The user is trying to leave with unsaved changes. Warn about that
                new AlertDialog.Builder(activity)
                        .setMessage(activity.getText(R.string.chat_with) + " " + mxid.mMatrixId + " ?")
                        .setPositiveButton("YES", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                activity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        CommonActivityUtils.goToOneToOneRoom(mxid.mAccountId, mxid.mMatrixId,
                                                activity, new SimpleApiCallback<Void>(getActivity()) {
                                                });
                                    }
                                });
                                dialog.dismiss();
                                // dismiss the member list
                                ContactsListDialogFragment.this.dismiss();

                            }
                        }).setNegativeButton("NO", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();

            } else {
                // invite the user
                final ArrayList<String> choicesList = new ArrayList<String>();

                if (AdapterUtils.canSendSms(activity)) {
                    choicesList.addAll(contact.mPhoneNumbers);
                }

                choicesList.addAll(contact.mEmails);

                // something to offer
                if (choicesList.size() > 0) {
                    final String[] labels = new String[choicesList.size()];

                    for (int index = 0; index < choicesList.size(); index++) {
                        labels[index] = choicesList.get(index);
                    }

                    new AlertDialog.Builder(activity).setItems(labels, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String value = labels[which];

                            // SMS ?
                            if (contact.mPhoneNumbers.indexOf(value) >= 0) {
                                AdapterUtils.launchSmsIntent(activity, value,
                                        activity.getString(R.string.invitation_message));
                            } else {
                                // emails
                                AdapterUtils.launchEmailIntent(activity, value,
                                        activity.getString(R.string.invitation_message));
                            }

                            // dismiss the member list
                            ContactsListDialogFragment.this.dismiss();
                        }
                    }).setTitle(activity.getString(R.string.invite_this_user_to_use_matrix)).show();
                }
            }
        }
    });
}

From source file:im.vector.activity.CommonActivityUtils.java

/**
 * Offer to send some dedicated intent data to an existing room
 * @param fromActivity the caller activity
 * @param intent the intent param/*w w  w.j a  v  a 2 s.  c o  m*/
 * @param session the session/
 */
public static void sendFilesTo(final Activity fromActivity, final Intent intent, final MXSession session) {
    // sanity check
    if ((null == session) || !session.isActive()) {
        return;
    }

    final ArrayList<RoomSummary> mergedSummaries = new ArrayList<RoomSummary>();
    mergedSummaries.addAll(session.getDataHandler().getStore().getSummaries());

    Collections.sort(mergedSummaries, new Comparator<RoomSummary>() {
        @Override
        public int compare(RoomSummary lhs, RoomSummary rhs) {
            if (lhs == null || lhs.getLatestEvent() == null) {
                return 1;
            } else if (rhs == null || rhs.getLatestEvent() == null) {
                return -1;
            }

            if (lhs.getLatestEvent().getOriginServerTs() > rhs.getLatestEvent().getOriginServerTs()) {
                return -1;
            } else if (lhs.getLatestEvent().getOriginServerTs() < rhs.getLatestEvent().getOriginServerTs()) {
                return 1;
            }
            return 0;
        }
    });

    AlertDialog.Builder builderSingle = new AlertDialog.Builder(fromActivity);
    builderSingle.setTitle(fromActivity.getText(R.string.send_files_in));
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(fromActivity,
            R.layout.dialog_room_selection);

    for (RoomSummary summary : mergedSummaries) {
        arrayAdapter.add(summary.getRoomName());
    }

    builderSingle.setNegativeButton(fromActivity.getText(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, final int which) {
            dialog.dismiss();
            fromActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    RoomSummary summary = mergedSummaries.get(which);
                    CommonActivityUtils.goToRoomPage(session, summary.getRoomId(), fromActivity, intent);
                }
            });
        }
    });
    builderSingle.show();
}

From source file:com.saulcintero.moveon.fragments.History.java

public static void sendAction(final Activity act, int[] idList, String[] nameList, String[] activityList,
        String[] shortDescriptionList, String[] longDescriptionList) {
    ArrayList<Integer> positions = new ArrayList<Integer>();
    for (int p = 0; p < idList.length; p++) {
        String nameToSearch = osmFilesNameFromUploadPosition.get(p).substring(0,
                osmFilesNameFromUploadPosition.get(p).length() - 4);
        positions.add(ArrayUtils.indexOf(listOfFiles, nameToSearch));
    }/*from w  w  w.  ja va 2 s  .c o m*/

    for (int j = 0; j < idList.length; j++) {
        final String name = nameList[j];
        final String activity = activityList[j];
        final String shortDescription = shortDescriptionList[j];
        final String longDescription = longDescriptionList[j];
        final String url = osmUrlsToShare.get(positions.get(j));
        Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        List<ResolveInfo> activities = act.getPackageManager().queryIntentActivities(sendIntent, 0);
        AlertDialog.Builder builder = new AlertDialog.Builder(act);
        builder.setTitle(act.getText(R.string.send_to) + " " + name + " " + act.getText(R.string.share_with));
        final ShareIntentListAdapter adapter = new ShareIntentListAdapter(act, R.layout.social_share,
                activities.toArray());
        builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                ResolveInfo info = (ResolveInfo) adapter.getItem(which);
                if (info.activityInfo.packageName.contains("facebook")) {
                    Intent i = new Intent("android.intent.action.PUBLISH_TO_FB_WALL");
                    i.putExtra("name", activity + " " + name);
                    i.putExtra("msg", String.format("%s", shortDescription));
                    i.putExtra("link", String.format("%s", url));
                    act.sendBroadcast(i);
                } else {
                    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
                    intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                    intent.setType("text/plain");
                    if ((info.activityInfo.packageName.contains("twitter"))
                            || (info.activityInfo.packageName.contains("sms"))
                            || (info.activityInfo.packageName.contains("mms"))) {
                        intent.putExtra(Intent.EXTRA_TEXT, shortDescription + url);
                    } else {
                        intent.putExtra(Intent.EXTRA_TEXT, longDescription + url);
                    }
                    act.startActivity(intent);
                }
            }
        });
        builder.create().show();
    }
}

From source file:im.neon.activity.CommonActivityUtils.java

/**
 * Offer to send some dedicated intent data to an existing room
 *
 * @param fromActivity the caller activity
 * @param intent       the intent param/*from   w  w  w. ja v a 2s. c  o m*/
 * @param session      the session/
 */
private static void sendFilesTo(final Activity fromActivity, final Intent intent, final MXSession session) {
    // sanity check
    if ((null == session) || !session.isAlive()) {
        return;
    }

    ArrayList<RoomSummary> mergedSummaries = new ArrayList<>(
            session.getDataHandler().getStore().getSummaries());

    // keep only the joined room
    for (int index = 0; index < mergedSummaries.size(); index++) {
        RoomSummary summary = mergedSummaries.get(index);
        Room room = session.getDataHandler().getRoom(summary.getRoomId());

        if ((null == room) || room.isInvited() || room.isConferenceUserRoom()) {
            mergedSummaries.remove(index);
            index--;
        }
    }

    Collections.sort(mergedSummaries, new Comparator<RoomSummary>() {
        @Override
        public int compare(RoomSummary lhs, RoomSummary rhs) {
            if (lhs == null || lhs.getLatestReceivedEvent() == null) {
                return 1;
            } else if (rhs == null || rhs.getLatestReceivedEvent() == null) {
                return -1;
            }

            if (lhs.getLatestReceivedEvent().getOriginServerTs() > rhs.getLatestReceivedEvent()
                    .getOriginServerTs()) {
                return -1;
            } else if (lhs.getLatestReceivedEvent().getOriginServerTs() < rhs.getLatestReceivedEvent()
                    .getOriginServerTs()) {
                return 1;
            }
            return 0;
        }
    });

    AlertDialog.Builder builderSingle = new AlertDialog.Builder(fromActivity);
    builderSingle.setTitle(fromActivity.getText(R.string.send_files_in));

    VectorRoomsSelectionAdapter adapter = new VectorRoomsSelectionAdapter(fromActivity,
            R.layout.adapter_item_vector_recent_room, session);
    adapter.addAll(mergedSummaries);

    builderSingle.setNegativeButton(fromActivity.getText(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    final ArrayList<RoomSummary> fMergedSummaries = mergedSummaries;

    builderSingle.setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, final int which) {
            dialog.dismiss();
            fromActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    RoomSummary summary = fMergedSummaries.get(which);

                    HashMap<String, Object> params = new HashMap<>();
                    params.put(VectorRoomActivity.EXTRA_MATRIX_ID, session.getMyUserId());
                    params.put(VectorRoomActivity.EXTRA_ROOM_ID, summary.getRoomId());
                    params.put(VectorRoomActivity.EXTRA_ROOM_INTENT, intent);

                    CommonActivityUtils.goToRoomPage(fromActivity, session, params);
                }
            });
        }
    });
    builderSingle.show();
}

From source file:org.allseen.lsf.sampleapp.view.MainFragment.java

private void wifiConnectionStateUpdate(boolean connected) {
    final Activity activity = getActivity();

    postUpdateControllerDisplay();//from   w  w  w. j  a v a2s.c o m

    if (connected) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                //                   Log.d(SampleAppActivity.TAG, "wifi connected");

                postInForeground(new Runnable() {
                    @Override
                    public void run() {
                        //                         Log.d(SampleAppActivity.TAG_TRACE, "Starting system");

                        LightingDirector.get().setNetworkConnectionStatus(true);

                        if (isControllerServiceEnabled()) {
                            //                           Log.d(SampleAppActivity.TAG_TRACE, "Starting bundled controller service");
                            setControllerServiceStarted(true);
                        }

                        if (wifiDisconnectAlertDialog != null) {
                            wifiDisconnectAlertDialog.dismiss();
                            wifiDisconnectAlertDialog = null;
                        }
                    }
                });
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {
                //             Log.d(SampleAppActivity.TAG, "wifi disconnected");

                postInForeground(new Runnable() {
                    @Override
                    public void run() {
                        if (wifiDisconnectAlertDialog == null) {
                            //                       Log.d(SampleAppActivity.TAG, "Stopping system");

                            LightingDirector.get().setNetworkConnectionStatus(false);

                            setControllerServiceStarted(false);

                            View view = activity.getLayoutInflater().inflate(R.layout.view_loading, null);
                            ((TextView) view.findViewById(R.id.loadingText1))
                                    .setText(activity.getText(R.string.no_wifi_message));
                            ((TextView) view.findViewById(R.id.loadingText2))
                                    .setText(activity.getText(R.string.searching_wifi));

                            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                            alertDialogBuilder.setView(view);
                            alertDialogBuilder.setTitle(R.string.no_wifi);
                            alertDialogBuilder.setCancelable(false);
                            wifiDisconnectAlertDialog = alertDialogBuilder.create();
                            wifiDisconnectAlertDialog.show();
                        }
                    }
                });
            }
        });
    }
}

From source file:org.kontalk.ui.ComposeMessageFragment.java

private void showKeyWarning(int textId, final int dialogTitleId, final int dialogMessageId) {
    Activity context = getActivity();
    if (context != null) {
        showWarning(context.getText(textId), new View.OnClickListener() {
            @Override//from  www.jav a  2  s .  c  o m
            public void onClick(View v) {
                DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                        case DialogInterface.BUTTON_POSITIVE:
                            // hide warning bar
                            hideWarning();
                            // trust new key
                            trustKeyChange();
                            break;
                        case DialogInterface.BUTTON_NEUTRAL:
                            showIdentityDialog(false, dialogTitleId);
                            break;
                        case DialogInterface.BUTTON_NEGATIVE:
                            // hide warning bar
                            hideWarning();
                            // block user immediately
                            setPrivacy(PRIVACY_BLOCK);
                            break;
                        }
                    }
                };
                new AlertDialogWrapper.Builder(getActivity()).setTitle(dialogTitleId)
                        .setMessage(dialogMessageId).setPositiveButton(R.string.button_accept, listener)
                        .setNeutralButton(R.string.button_identity, listener)
                        .setNegativeButton(R.string.button_block, listener).show();
            }
        }, WarningType.FATAL);
    }
}