use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class NewsActivity method setDataSet.
public void setDataSet(List<String> data) {
if (data != null && !data.isEmpty()) {
usedArray = new CaseInsensitiveArrayList(data);
if (adapter == null) {
adapter = new NewsPagerAdapter(getSupportFragmentManager());
} else {
adapter.notifyDataSetChanged();
}
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(1);
if (toGoto == -1) {
toGoto = 0;
}
if (toGoto >= usedArray.size()) {
toGoto -= 1;
}
shouldLoad = usedArray.get(toGoto);
selectedSub = (usedArray.get(toGoto));
themeSystemBars(usedArray.get(toGoto));
final String USEDARRAY_0 = usedArray.get(0);
mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(NewsActivity.this).getColor(USEDARRAY_0));
pager.setCurrentItem(toGoto);
mTabLayout.setupWithViewPager(pager);
if (mTabLayout != null) {
mTabLayout.setupWithViewPager(pager);
LayoutUtils.scrollToTabAfterLayout(mTabLayout, toGoto);
}
setToolbarClick();
} else if (NetworkUtil.isConnected(this)) {
UserSubscriptions.doNewsSubs(this);
}
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class RedditGallery method onCreate.
public void onCreate(Bundle savedInstanceState) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstanceState);
getTheme().applyStyle(new ColorPreferences(this).getDarkThemeSubreddit(ColorPreferences.FONT_STYLE), true);
setContentView(R.layout.album);
// Keep the screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (getIntent().hasExtra(SUBREDDIT)) {
this.subreddit = getIntent().getExtras().getString(SUBREDDIT);
}
if (getIntent().hasExtra(EXTRA_SUBMISSION_TITLE)) {
this.submissionTitle = getIntent().getExtras().getString(EXTRA_SUBMISSION_TITLE);
}
final ViewPager pager = (ViewPager) findViewById(R.id.images);
album = new RedditGalleryPagerAdapter(getSupportFragmentManager());
pager.setAdapter(album);
pager.setCurrentItem(1);
pager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (position == 0 && positionOffsetPixels == 0) {
finish();
}
if (position == 0 && ((RedditGalleryPagerAdapter) pager.getAdapter()).blankPage != null) {
if (((RedditGalleryPagerAdapter) pager.getAdapter()).blankPage != null) {
((RedditGalleryPagerAdapter) pager.getAdapter()).blankPage.doOffset(positionOffset);
}
((RedditGalleryPagerAdapter) pager.getAdapter()).blankPage.realBack.setBackgroundColor(Palette.adjustAlpha(positionOffset * 0.7f));
}
}
});
if (!Reddit.appRestart.contains("tutorialSwipe")) {
startActivityForResult(new Intent(this, SwipeTutorial.class), 3);
}
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class Shortcut method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
getTheme().applyStyle(new ColorPreferences(this).getFontStyle().getBaseId(), true);
super.onCreate(savedInstanceState);
doShortcut();
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class TumblrPager method onCreate.
public void onCreate(Bundle savedInstanceState) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstanceState);
getTheme().applyStyle(new ColorPreferences(this).getDarkThemeSubreddit(ColorPreferences.FONT_STYLE), true);
setContentView(R.layout.album_pager);
// Keep the screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle(R.string.type_album);
ToolbarColorizeHelper.colorizeToolbar(mToolbar, Color.WHITE, this);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (getIntent().hasExtra(SUBREDDIT)) {
this.subreddit = getIntent().getStringExtra(SUBREDDIT);
}
mToolbar.setPopupTheme(new ColorPreferences(this).getDarkThemeSubreddit(ColorPreferences.FONT_STYLE));
adapterPosition = getIntent().getIntExtra(MediaView.ADAPTER_POSITION, -1);
String url = getIntent().getExtras().getString("url", "");
setShareUrl(url);
new LoadIntoPager(url, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (!Reddit.appRestart.contains("tutorialSwipe")) {
startActivityForResult(new Intent(this, SwipeTutorial.class), 3);
}
}
use of me.ccrama.redditslide.Visuals.ColorPreferences in project Slide by ccrama.
the class DoEditorActions method doActions.
public static void doActions(final EditText editText, final View baseView, final FragmentManager fm, final Activity a, final String oldComment, @Nullable final String[] authors) {
baseView.findViewById(R.id.bold).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("**", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "**");
editText.getText().insert(pos + 1, "**");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
if (baseView.findViewById(R.id.author) != null) {
if (authors != null && authors.length > 0) {
baseView.findViewById(R.id.author).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (authors.length == 1) {
String author = "/u/" + authors[0];
insertBefore(author, editText);
} else {
new AlertDialog.Builder(a).setTitle(R.string.authors_above).setItems(authors, (dialog, which) -> {
String author = "/u/" + authors[which];
insertBefore(author, editText);
}).setNeutralButton(R.string.btn_cancel, null).show();
}
}
});
} else {
baseView.findViewById(R.id.author).setVisibility(View.GONE);
}
}
baseView.findViewById(R.id.italics).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("*", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "*");
editText.getText().insert(pos + 1, "*");
// put the cursor between the symbols
editText.setSelection(pos + 1);
}
}
});
baseView.findViewById(R.id.strike).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
wrapString("~~", // If the user has text selected, wrap that text in the symbols
editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, "~~");
editText.getText().insert(pos + 2, "~~");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
baseView.findViewById(R.id.spoiler).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editText.hasSelection()) {
// If the user has text selected, wrap that text in the symbols
wrapString(">!", "!<", editText);
} else {
// If the user doesn't have text selected, put the symbols around the cursor's position
int pos = editText.getSelectionStart();
editText.getText().insert(pos, ">!");
editText.getText().insert(pos + 2, "!<");
// put the cursor between the symbols
editText.setSelection(pos + 2);
}
}
});
baseView.findViewById(R.id.savedraft).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Drafts.addDraft(editText.getText().toString());
Snackbar s = Snackbar.make(baseView.findViewById(R.id.savedraft), "Draft saved", Snackbar.LENGTH_SHORT);
View view = s.getView();
TextView tv = view.findViewById(com.google.android.material.R.id.snackbar_text);
tv.setTextColor(Color.WHITE);
s.setAction(R.string.btn_discard, new View.OnClickListener() {
@Override
public void onClick(View view) {
Drafts.deleteDraft(Drafts.getDrafts().size() - 1);
}
});
s.show();
}
});
baseView.findViewById(R.id.draft).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ArrayList<String> drafts = Drafts.getDrafts();
Collections.reverse(drafts);
final String[] draftText = new String[drafts.size()];
for (int i = 0; i < drafts.size(); i++) {
draftText[i] = drafts.get(i);
}
if (drafts.isEmpty()) {
new AlertDialog.Builder(a).setTitle(R.string.dialog_no_drafts).setMessage(R.string.dialog_no_drafts_msg).setPositiveButton(R.string.btn_ok, null).show();
} else {
new AlertDialog.Builder(a).setTitle(R.string.choose_draft).setItems(draftText, (dialog, which) -> editText.setText(editText.getText().toString() + draftText[which])).setNeutralButton(R.string.btn_cancel, null).setPositiveButton(R.string.manage_drafts, (dialog, which) -> {
final boolean[] selected = new boolean[drafts.size()];
new AlertDialog.Builder(a).setTitle(R.string.choose_draft).setNeutralButton(R.string.btn_cancel, null).setNegativeButton(R.string.btn_delete, (dialog1, which1) -> new AlertDialog.Builder(a).setTitle(R.string.really_delete_drafts).setCancelable(false).setPositiveButton(R.string.btn_yes, (dialog11, which11) -> {
ArrayList<String> draf = new ArrayList<>();
for (int i = 0; i < draftText.length; i++) {
if (!selected[i]) {
draf.add(draftText[i]);
}
}
Drafts.save(draf);
}).setNegativeButton(R.string.btn_no, null).show()).setMultiChoiceItems(draftText, selected, (dialog12, which12, isChecked) -> selected[which12] = isChecked).show();
}).show();
}
}
});
baseView.findViewById(R.id.imagerep).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
e = editText.getText();
sStart = editText.getSelectionStart();
sEnd = editText.getSelectionEnd();
TedBottomPicker tedBottomPicker = new TedBottomPicker.Builder(editText.getContext()).setOnImageSelectedListener(new TedBottomPicker.OnImageSelectedListener() {
@Override
public void onImageSelected(List<Uri> uri) {
handleImageIntent(uri, editText, a);
}
}).setLayoutResource(R.layout.image_sheet_dialog).setTitle("Choose a photo").create();
tedBottomPicker.show(fm);
KeyboardUtil.hideKeyboard(editText.getContext(), editText.getWindowToken(), 0);
}
});
baseView.findViewById(R.id.draw).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (SettingValues.isPro) {
doDraw(a, editText, fm);
} else {
final AlertDialog.Builder b = ProUtil.proUpgradeMsg(a, R.string.general_cropdraw_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
if (SettingValues.previews > 0) {
b.setNeutralButton(a.getString(R.string.pro_previews, SettingValues.previews), (dialog, which) -> {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
doDraw(a, editText, fm);
});
}
b.show();
}
}
});
/*todo baseView.findViewById(R.id.superscript).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("^", editText);
}
});*/
baseView.findViewById(R.id.size).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertBefore("#", editText);
}
});
baseView.findViewById(R.id.quote).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (oldComment != null) {
final TextView showText = new TextView(a);
// text we get is escaped, we don't want that
showText.setText(StringEscapeUtils.unescapeHtml4(oldComment));
showText.setTextIsSelectable(true);
int sixteen = DisplayUtil.dpToPxVertical(24);
showText.setPadding(sixteen, 0, sixteen, 0);
MaterialDialog.Builder builder = new MaterialDialog.Builder(a);
builder.customView(showText, false).title(R.string.editor_actions_quote_comment).cancelable(true).positiveText(a.getString(R.string.btn_select)).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
String selected = showText.getText().toString().substring(showText.getSelectionStart(), showText.getSelectionEnd());
if (selected.isEmpty()) {
selected = StringEscapeUtils.unescapeHtml4(oldComment);
}
insertBefore("> " + selected.replaceAll("\n", "\n> ") + "\n\n", editText);
}
}).negativeText(a.getString(R.string.btn_cancel)).show();
KeyboardUtil.hideKeyboard(editText.getContext(), editText.getWindowToken(), 0);
} else {
insertBefore("> ", editText);
}
}
});
baseView.findViewById(R.id.bulletlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
String selected = editText.getText().toString().substring(Math.min(start, end), Math.max(start, end));
if (!selected.isEmpty()) {
selected = selected.replaceFirst("^[^\n]", "* $0").replaceAll("\n", "\n* ");
editText.getText().replace(Math.min(start, end), Math.max(start, end), selected);
} else {
insertBefore("* ", editText);
}
}
});
baseView.findViewById(R.id.numlist).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
String selected = editText.getText().toString().substring(Math.min(start, end), Math.max(start, end));
if (!selected.isEmpty()) {
selected = selected.replaceFirst("^[^\n]", "1. $0").replaceAll("\n", "\n1. ");
editText.getText().replace(Math.min(start, end), Math.max(start, end), selected);
} else {
insertBefore("1. ", editText);
}
}
});
baseView.findViewById(R.id.preview).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Extension> extensions = Arrays.asList(TablesExtension.create(), StrikethroughExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
Node document = parser.parse(editText.getText().toString());
String html = renderer.render(document);
LayoutInflater inflater = a.getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.parent_comment_dialog, null);
setViews(html, "NO sub", dialoglayout.findViewById(R.id.firstTextView), dialoglayout.findViewById(R.id.commentOverflow));
new AlertDialog.Builder(a).setView(dialoglayout).show();
}
});
baseView.findViewById(R.id.link).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final LayoutInflater inflater = LayoutInflater.from(a);
final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.insert_link, null);
int[] attrs = { R.attr.fontColor };
TypedArray ta = baseView.getContext().obtainStyledAttributes(new ColorPreferences(baseView.getContext()).getFontStyle().getBaseId(), attrs);
ta.recycle();
String selectedText = "";
// if the user highlighted text before inputting a URL, use that text for the descriptionBox
if (editText.hasSelection()) {
final int startSelection = editText.getSelectionStart();
final int endSelection = editText.getSelectionEnd();
selectedText = editText.getText().toString().substring(startSelection, endSelection);
}
final boolean selectedTextNotEmpty = !selectedText.isEmpty();
final MaterialDialog dialog = new MaterialDialog.Builder(editText.getContext()).title(R.string.editor_title_link).customView(layout, false).positiveColorAttr(R.attr.tintColor).positiveText(R.string.editor_action_link).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
final EditText urlBox = (EditText) dialog.findViewById(R.id.url_box);
final EditText textBox = (EditText) dialog.findViewById(R.id.text_box);
dialog.dismiss();
final String s = "[" + textBox.getText().toString() + "](" + urlBox.getText().toString() + ")";
int start = Math.max(editText.getSelectionStart(), 0);
int end = Math.max(editText.getSelectionEnd(), 0);
editText.getText().insert(Math.max(start, end), s);
// delete the selected text to avoid duplication
if (selectedTextNotEmpty) {
editText.getText().delete(start, end);
}
}
}).build();
// Tint the hint text if the base theme is Sepia
if (SettingValues.currentTheme == 5) {
((EditText) dialog.findViewById(R.id.url_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
((EditText) dialog.findViewById(R.id.text_box)).setHintTextColor(ContextCompat.getColor(dialog.getContext(), R.color.md_grey_600));
}
// use the selected text as the text for the link
if (!selectedText.isEmpty()) {
((EditText) dialog.findViewById(R.id.text_box)).setText(selectedText);
}
dialog.show();
}
});
try {
((ImageInsertEditText) editText).setImageSelectedCallback(new ImageInsertEditText.ImageSelectedCallback() {
@Override
public void onImageSelected(final Uri content, String mimeType) {
e = editText.getText();
sStart = editText.getSelectionStart();
sEnd = editText.getSelectionEnd();
handleImageIntent(new ArrayList<Uri>() {
{
add(content);
}
}, editText, a);
}
});
} catch (Exception e) {
// if thrown, there is likely an issue implementing this on the user's version of Android. There shouldn't be an issue, but just in case
}
}
Aggregations