Search in sources :

Example 6 with StringRes

use of android.support.annotation.StringRes in project gh4a by slapperwan.

the class EventViewHolder method formatEvent.

private CharSequence formatEvent(final IssueEvent event, final User user, int typefaceValue, boolean isPullRequestEvent) {
    String textBase = null;
    int textResId = 0;
    switch(event.event()) {
        case Closed:
            if (isPullRequestEvent) {
                textResId = event.commitId() != null ? R.string.pull_request_event_closed_with_commit : R.string.pull_request_event_closed;
            } else {
                textResId = event.commitId() != null ? R.string.issue_event_closed_with_commit : R.string.issue_event_closed;
            }
            break;
        case Reopened:
            textResId = isPullRequestEvent ? R.string.pull_request_event_reopened : R.string.issue_event_reopened;
            break;
        case Merged:
            textResId = event.commitId() != null ? R.string.pull_request_event_merged_with_commit : R.string.pull_request_event_merged;
            break;
        case Referenced:
            if (isPullRequestEvent) {
                textResId = event.commitId() != null ? R.string.pull_request_event_referenced_with_commit : R.string.pull_request_event_referenced;
            } else {
                textResId = event.commitId() != null ? R.string.issue_event_referenced_with_commit : R.string.issue_event_referenced;
            }
            break;
        case Assigned:
        case Unassigned:
            {
                boolean isAssign = event.event() == IssueEventType.Assigned;
                String actorLogin = user != null ? user.login() : null;
                String assigneeLogin = event.assignee() != null ? event.assignee().login() : null;
                if (assigneeLogin != null && assigneeLogin.equals(actorLogin)) {
                    if (isAssign) {
                        textResId = isPullRequestEvent ? R.string.pull_request_event_assigned_self : R.string.issue_event_assigned_self;
                    } else {
                        textResId = R.string.issue_event_unassigned_self;
                    }
                } else {
                    textResId = isAssign ? R.string.issue_event_assigned : R.string.issue_event_unassigned;
                    textBase = mContext.getString(textResId, ApiHelpers.getUserLogin(mContext, user), ApiHelpers.getUserLogin(mContext, event.assignee()));
                }
                break;
            }
        case Labeled:
            textResId = R.string.issue_event_labeled;
            break;
        case Unlabeled:
            textResId = R.string.issue_event_unlabeled;
            break;
        case Locked:
            textResId = R.string.issue_event_locked;
            break;
        case Unlocked:
            textResId = R.string.issue_event_unlocked;
            break;
        case Milestoned:
        case Demilestoned:
            textResId = event.event() == IssueEventType.Milestoned ? R.string.issue_event_milestoned : R.string.issue_event_demilestoned;
            textBase = mContext.getString(textResId, ApiHelpers.getUserLogin(mContext, user), event.milestone().title());
            break;
        case Renamed:
            {
                Rename rename = event.rename();
                textBase = mContext.getString(R.string.issue_event_renamed, ApiHelpers.getUserLogin(mContext, user), rename.from(), rename.to());
                break;
            }
        case ReviewRequested:
        case ReviewRequestRemoved:
            {
                final String reviewerNames;
                if (event.requestedReviewers() != null) {
                    ArrayList<String> reviewers = new ArrayList<>();
                    for (User reviewer : event.requestedReviewers()) {
                        reviewers.add(ApiHelpers.getUserLogin(mContext, reviewer));
                    }
                    reviewerNames = TextUtils.join(", ", reviewers);
                } else {
                    reviewerNames = ApiHelpers.getUserLogin(mContext, event.requestedReviewer());
                }
                @StringRes int stringResId = event.event() == IssueEventType.ReviewRequested ? R.string.pull_request_event_review_requested : R.string.pull_request_event_review_request_removed;
                textBase = mContext.getString(stringResId, ApiHelpers.getUserLogin(mContext, event.reviewRequester()), reviewerNames);
                break;
            }
        case HeadRefDeleted:
            textResId = R.string.pull_request_event_ref_deleted;
            break;
        case HeadRefRestored:
            textResId = R.string.pull_request_event_ref_restored;
            break;
        default:
            return null;
    }
    if (textBase == null) {
        textBase = mContext.getString(textResId, ApiHelpers.getUserLogin(mContext, user));
    }
    SpannableStringBuilder text = StringUtils.applyBoldTags(textBase, typefaceValue);
    int pos = text.toString().indexOf("[commit]");
    if (event.commitId() != null && pos >= 0) {
        text.replace(pos, pos + 8, event.commitId().substring(0, 7));
        text.setSpan(new IntentSpan(mContext, context -> {
            // The commit might be in a different repo. The API doesn't provide
            // that information directly, so get it indirectly by parsing the URL
            String repoOwner = mRepoOwner;
            String repoName = mRepoName;
            String url = event.commitUrl();
            if (url != null) {
                Matcher matcher = COMMIT_URL_REPO_NAME_AND_OWNER_PATTERN.matcher(url);
                if (matcher.find()) {
                    repoOwner = matcher.group(1);
                    repoName = matcher.group(2);
                }
            }
            return CommitActivity.makeIntent(context, repoOwner, repoName, event.commitId());
        }), pos, pos + 7, 0);
        text.setSpan(new TypefaceSpan("monospace"), pos, pos + 7, 0);
    }
    pos = text.toString().indexOf("[label]");
    Label label = event.label();
    if (label != null && pos >= 0) {
        int length = label.name().length();
        text.replace(pos, pos + 7, label.name());
        text.setSpan(new IssueLabelSpan(mContext, label, false), pos, pos + length, 0);
    }
    CharSequence time = event.createdAt() != null ? StringUtils.formatRelativeTime(mContext, event.createdAt(), true) : "";
    pos = text.toString().indexOf("[time]");
    if (pos >= 0) {
        text.replace(pos, pos + 6, time);
        if (event.createdAt() != null) {
            text.setSpan(new TimestampToastSpan(event.createdAt()), pos, pos + time.length(), 0);
        }
    }
    return text;
}
Also used : Context(android.content.Context) ImageView(android.widget.ImageView) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) HashMap(java.util.HashMap) Rename(com.meisolsson.githubsdk.model.Rename) TypefaceSpan(android.text.style.TypefaceSpan) UserActivity(com.gh4a.activities.UserActivity) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) IssueEventType(com.meisolsson.githubsdk.model.IssueEventType) User(com.meisolsson.githubsdk.model.User) SpannableStringBuilder(android.text.SpannableStringBuilder) Matcher(java.util.regex.Matcher) AvatarHandler(com.gh4a.utils.AvatarHandler) Label(com.meisolsson.githubsdk.model.Label) R(com.gh4a.R) View(android.view.View) IntentSpan(com.gh4a.widget.IntentSpan) TimestampToastSpan(com.gh4a.widget.TimestampToastSpan) IssueEvent(com.meisolsson.githubsdk.model.IssueEvent) StringUtils(com.gh4a.utils.StringUtils) ApiHelpers(com.gh4a.utils.ApiHelpers) TextUtils(android.text.TextUtils) StyleableTextView(com.gh4a.widget.StyleableTextView) IssueLabelSpan(com.gh4a.widget.IssueLabelSpan) CommitActivity(com.gh4a.activities.CommitActivity) TimelineItem(com.gh4a.model.TimelineItem) Pattern(java.util.regex.Pattern) User(com.meisolsson.githubsdk.model.User) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Label(com.meisolsson.githubsdk.model.Label) Rename(com.meisolsson.githubsdk.model.Rename) IntentSpan(com.gh4a.widget.IntentSpan) TimestampToastSpan(com.gh4a.widget.TimestampToastSpan) IssueLabelSpan(com.gh4a.widget.IssueLabelSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) TypefaceSpan(android.text.style.TypefaceSpan)

Example 7 with StringRes

use of android.support.annotation.StringRes in project gh4a by slapperwan.

the class RxUtils method wrapWithProgressDialog.

public static <T> SingleTransformer<T, T> wrapWithProgressDialog(final FragmentActivity activity, @StringRes final int messageResId) {
    return new SingleTransformer<T, T>() {

        private ProgressDialogFragment mFragment;

        @Override
        public SingleSource<T> apply(Single<T> upstream) {
            return upstream.doOnSubscribe(disposable -> showDialog()).doOnError(throwable -> hideDialog()).doOnSuccess(result -> hideDialog());
        }

        private void showDialog() {
            Bundle args = new Bundle();
            args.putInt("message_res", messageResId);
            mFragment = new ProgressDialogFragment();
            mFragment.setArguments(args);
            mFragment.show(activity.getSupportFragmentManager(), "progressdialog");
        }

        private void hideDialog() {
            if (mFragment.getActivity() != null) {
                mFragment.dismissAllowingStateLoss();
            }
            mFragment = null;
        }
    };
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Bundle(android.os.Bundle) SingleSource(io.reactivex.SingleSource) Dialog(android.app.Dialog) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) DialogFragment(android.support.v4.app.DialogFragment) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Page(com.meisolsson.githubsdk.model.Page) R(com.gh4a.R) Schedulers(io.reactivex.schedulers.Schedulers) ApiRequestException(com.gh4a.ApiRequestException) Predicate(io.reactivex.functions.Predicate) List(java.util.List) SingleTransformer(io.reactivex.SingleTransformer) FragmentActivity(android.support.v4.app.FragmentActivity) Function(io.reactivex.functions.Function) Snackbar(android.support.design.widget.Snackbar) SearchPage(com.meisolsson.githubsdk.model.SearchPage) Comparator(java.util.Comparator) PublishProcessor(io.reactivex.processors.PublishProcessor) BaseActivity(com.gh4a.BaseActivity) Collections(java.util.Collections) SingleTransformer(io.reactivex.SingleTransformer) Single(io.reactivex.Single) Bundle(android.os.Bundle)

Example 8 with StringRes

use of android.support.annotation.StringRes in project butter-android by butterproject.

the class TVMediaGridActivity method onCreate.

@SuppressLint("MissingSuperCall")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.activity_movie_media_grid);
    Bundle extras = getIntent().getExtras();
    final Filter filter = extras.getParcelable(EXTRA_FILTER);
    @StringRes int title = extras.getInt(EXTRA_TITLE);
    final int providerId = extras.getInt(EXTRA_PROVIDER);
    // add media fragment
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment, TVMediaGridFragment.newInstance(providerId, title, filter)).commit();
}
Also used : Filter(butter.droid.provider.base.filter.Filter) Bundle(android.os.Bundle) StringRes(android.support.annotation.StringRes) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 9 with StringRes

use of android.support.annotation.StringRes in project MaxLock by Maxr1998.

the class MaxLockPreferenceFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    setTitle();
    if (screen == Screen.MAIN) {
        findPreference(Common.ABOUT).setTitle(getName() + " " + BuildConfig.VERSION_NAME);
        if (prefs.getBoolean(Common.DONATED, false)) {
            Preference donate = findPreference(Common.DONATE);
            donate.setTitle(R.string.pref_donate_thanks_for_donation);
            donate.setSummary(R.string.pref_donate_again_on_pro_summary);
            Preference pro = findPreference(Common.ENABLE_PRO);
            pro.setEnabled(false);
            pro.setSummary("");
            if (!prefs.getBoolean(Common.ENABLE_PRO, false)) {
                prefs.edit().putBoolean(Common.ENABLE_PRO, true).putBoolean(Common.ENABLE_LOGGING, true).apply();
            }
        }
        if (((SettingsActivity) getActivity()).isDeviceAdminActive()) {
            Preference protectOrUninstall = findPreference(Common.UNINSTALL);
            protectOrUninstall.setTitle(R.string.pref_uninstall);
            protectOrUninstall.setSummary("");
        }
    }
    // Show Snackbars if no password and/or packages set up
    if (screen == Screen.MAIN && isFirstPane()) {
        @StringRes int stringId = 0;
        Fragment fragment = null;
        if (prefs.getString(Common.LOCKING_TYPE, "").equals("")) {
            stringId = R.string.sb_no_locking_type;
            fragment = Screen.TYPE.getScreen();
        } else if (!new File(Util.dataDir(getContext()) + "shared_prefs" + File.separator + Common.PREFS_APPS + ".xml").exists()) {
            stringId = R.string.sb_no_locked_apps;
            fragment = new AppListFragment();
        }
        if (stringId != 0 && fragment != null) {
            final Fragment copyFragment = fragment;
            snackCache = Snackbar.make(getActivity().findViewById(android.R.id.content), stringId, Snackbar.LENGTH_INDEFINITE).setAction(R.string.sb_action_setup, v -> launchFragment(this, copyFragment, true));
            snackCache.show();
        }
    }
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) BuildConfig(de.Maxr1998.xposed.maxlock.BuildConfig) Uri(android.net.Uri) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) LockPatternActivity(com.haibison.android.lockpattern.LockPatternActivity) ColorDrawable(android.graphics.drawable.ColorDrawable) PreferenceScreen(android.preference.PreferenceScreen) SDK_INT(android.os.Build.VERSION.SDK_INT) VisibleForTesting(android.support.annotation.VisibleForTesting) Util(de.Maxr1998.xposed.maxlock.util.Util) PreferenceFragmentCompat(android.support.v4.preference.PreferenceFragmentCompat) CheckBox(android.widget.CheckBox) MLImplementation(de.Maxr1998.xposed.maxlock.MLImplementation) WebViewClient(android.webkit.WebViewClient) View(android.view.View) BUTTON_NEUTRAL(android.content.DialogInterface.BUTTON_NEUTRAL) WebView(android.webkit.WebView) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) FileProvider.getUriForFile(android.support.v4.content.FileProvider.getUriForFile) PorterDuff(android.graphics.PorterDuff) ActivityCompat(android.support.v4.app.ActivityCompat) AppCompatActivity(android.support.v7.app.AppCompatActivity) IOUtils(org.apache.commons.io.IOUtils) ListPreference(android.preference.ListPreference) TextView(android.widget.TextView) ActivityNotFoundException(android.content.ActivityNotFoundException) Snackbar(android.support.design.widget.Snackbar) SettingsActivity(de.Maxr1998.xposed.maxlock.ui.SettingsActivity) ZipOutputStream(java.util.zip.ZipOutputStream) Context(android.content.Context) PreferenceCategory(android.preference.PreferenceCategory) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) XmlRes(android.support.annotation.XmlRes) BufferedOutputStream(java.io.BufferedOutputStream) FingerprintManagerCompat(android.support.v4.hardware.fingerprint.FingerprintManagerCompat) SuppressLint(android.annotation.SuppressLint) KUtil(de.Maxr1998.xposed.maxlock.util.KUtil) Charset(java.nio.charset.Charset) DevicePolicyManager(android.app.admin.DevicePolicyManager) READ_EXTERNAL_STORAGE(android.Manifest.permission.READ_EXTERNAL_STORAGE) Toast(android.widget.Toast) Build(android.os.Build) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) DialogInterface(android.content.DialogInterface) BUTTON_POSITIVE(android.content.DialogInterface.BUTTON_POSITIVE) ImplementationPreference(de.Maxr1998.xposed.maxlock.preference.ImplementationPreference) MLPreferences(de.Maxr1998.xposed.maxlock.util.MLPreferences) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) FileOutputStream(java.io.FileOutputStream) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Common(de.Maxr1998.xposed.maxlock.Common) File(java.io.File) R(de.Maxr1998.xposed.maxlock.R) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) Activity(android.app.Activity) FragmentTransaction(android.support.v4.app.FragmentTransaction) InputStream(java.io.InputStream) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) ImplementationPreference(de.Maxr1998.xposed.maxlock.preference.ImplementationPreference) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) StringRes(android.support.annotation.StringRes) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) Fragment(android.support.v4.app.Fragment) AppListFragment(de.Maxr1998.xposed.maxlock.ui.settings.applist.AppListFragment) FileProvider.getUriForFile(android.support.v4.content.FileProvider.getUriForFile) File(java.io.File) SettingsActivity(de.Maxr1998.xposed.maxlock.ui.SettingsActivity) SuppressLint(android.annotation.SuppressLint)

Example 10 with StringRes

use of android.support.annotation.StringRes in project MaxLock by Maxr1998.

the class AppListFragment method filterIcon.

@SuppressWarnings("deprecation")
private void filterIcon(MenuItem item) {
    if (prefs == null) {
        return;
    }
    String filter = prefs.getString("app_list_filter", "");
    Drawable icon;
    @StringRes int filterTypeString;
    switch(filter) {
        case "@*activated*":
            icon = getResources().getDrawable(R.drawable.ic_checked_24dp);
            filterTypeString = R.string.content_description_applist_filter_locked;
            break;
        case "@*deactivated*":
            icon = getResources().getDrawable(R.drawable.ic_unchecked_24dp);
            filterTypeString = R.string.content_description_applist_filter_unlocked;
            break;
        default:
            icon = getResources().getDrawable(R.drawable.ic_apps_24dp);
            filterTypeString = R.string.content_description_applist_filter_all_apps;
            break;
    }
    item.setIcon(icon);
    item.setTitle(getString(R.string.content_description_applist_filter, getString(filterTypeString)));
}
Also used : StringRes(android.support.annotation.StringRes) Drawable(android.graphics.drawable.Drawable) SuppressLint(android.annotation.SuppressLint)

Aggregations

StringRes (android.support.annotation.StringRes)22 SuppressLint (android.annotation.SuppressLint)7 View (android.view.View)6 Intent (android.content.Intent)5 ApiHelpers (com.gh4a.utils.ApiHelpers)4 ArrayList (java.util.ArrayList)4 Bundle (android.os.Bundle)3 Snackbar (android.support.design.widget.Snackbar)3 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 DrawableRes (android.support.annotation.DrawableRes)2 NonNull (android.support.annotation.NonNull)2 FragmentManager (android.support.v4.app.FragmentManager)2 ActionBar (android.support.v7.app.ActionBar)2 TextView (android.widget.TextView)2 R (com.gh4a.R)2 File (java.io.File)2