use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.
the class NewsActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
inNightMode = SettingValues.isNight();
disableSwipeBackLayout();
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_news);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
setSupportActionBar(mToolbar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.setStatusBarColor(Palette.getDarkerColor(Palette.getDarkerColor(Palette.getDefaultColor())));
}
mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
header = findViewById(R.id.header);
pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
UserSubscriptions.doNewsSubs(NewsActivity.this);
/**
* int for the current base theme selected.
* 0 = Dark, 1 = Light, 2 = AMOLED, 3 = Dark blue, 4 = AMOLED with contrast, 5 = Sepia
*/
SettingValues.currentTheme = new ColorPreferences(this).getFontStyle().getThemeType();
networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this);
try {
this.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
} catch (Exception e) {
}
}
use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.
the class PostReadLater method onCreate.
@Override
public void onCreate(Bundle savedInstance) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstance);
applyColorTheme();
setContentView(R.layout.activity_read_later);
setupAppBar(R.id.toolbar, "Read later", true, true);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
pager = (ViewPager) findViewById(R.id.content_view);
pager.setAdapter(new ReadLaterAdaptor(getSupportFragmentManager()));
}
use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.
the class Related method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstanceState);
applyColorTheme("");
setContentView(R.layout.activity_search);
Intent intent = getIntent();
if (intent.hasExtra(Intent.EXTRA_TEXT) && !intent.getExtras().getString(Intent.EXTRA_TEXT, "").isEmpty()) {
url = intent.getStringExtra(Intent.EXTRA_TEXT);
}
if (intent.hasExtra(EXTRA_URL)) {
url = intent.getStringExtra(EXTRA_URL);
}
if (url == null || url.isEmpty()) {
new AlertDialogWrapper.Builder(this).setTitle("URL is empty").setMessage("Try again with a different link!").setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
}).show();
} else {
}
setupAppBar(R.id.toolbar, "Related links", true, true);
// it won't be, trust me
assert mToolbar != null;
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
final RecyclerView rv = ((RecyclerView) findViewById(R.id.vertical_content));
final PreCachingLayoutManager mLayoutManager;
mLayoutManager = new PreCachingLayoutManager(this);
rv.setLayoutManager(mLayoutManager);
rv.addOnScrollListener(new ToolbarScrollHideHandler(mToolbar, findViewById(R.id.header)) {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = rv.getLayoutManager().getChildCount();
totalItemCount = rv.getLayoutManager().getItemCount();
if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
} else {
int[] firstVisibleItems = null;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
pastVisiblesItems = firstVisibleItems[0];
}
}
if (!posts.loading && (visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount) {
posts.loading = true;
posts.loadMore(adapter, "", "url:" + url, false);
}
}
});
final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors("", this));
// If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
// So, we estimate the height of the header in dp.
mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
posts = new SubredditSearchPosts("", "url:" + url, this);
adapter = new ContributionAdapter(this, posts, rv);
rv.setAdapter(adapter);
posts.bindAdapter(adapter, mSwipeRefreshLayout);
// TODO catch errors
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
posts.loadMore(adapter, "", "url:" + url, true);
// TODO catch errors
}
});
}
use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.
the class SubredditView method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
overrideSwipeFromAnywhere();
if (SettingValues.commentPager && SettingValues.single) {
disableSwipeBackLayout();
}
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getWindow().getDecorView().setBackgroundDrawable(null);
super.onCreate(savedInstanceState);
if (!restarting) {
overridePendingTransition(R.anim.slideright, 0);
} else {
restarting = false;
}
subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
applyColorTheme(subreddit);
setContentView(R.layout.activity_singlesubreddit);
setupSubredditAppBar(R.id.toolbar, subreddit, true, subreddit);
header = findViewById(R.id.header);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
setResult(3);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
singleMode = SettingValues.single;
commentPager = false;
if (singleMode)
commentPager = SettingValues.commentPager;
if (commentPager) {
adapter = new OverviewPagerAdapterComment(getSupportFragmentManager());
pager.setSwipeLeftOnly(false);
pager.setSwipingEnabled(true);
} else {
adapter = new OverviewPagerAdapter(getSupportFragmentManager());
}
pager.setAdapter(adapter);
pager.setCurrentItem(1);
mToolbar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int[] firstVisibleItems;
int pastVisiblesItems = 0;
firstVisibleItems = ((CatchStaggeredGridLayoutManager) ((SubmissionsView) (adapter.getCurrentFragment())).rv.getLayoutManager()).findFirstVisibleItemPositions(null);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
for (int firstVisibleItem : firstVisibleItems) {
pastVisiblesItems = firstVisibleItem;
}
}
if (pastVisiblesItems > 8) {
((SubmissionsView) (adapter.getCurrentFragment())).rv.scrollToPosition(0);
header.animate().translationY(header.getHeight()).setInterpolator(new LinearInterpolator()).setDuration(180);
} else {
((SubmissionsView) (adapter.getCurrentFragment())).rv.smoothScrollToPosition(0);
}
((SubmissionsView) (adapter.getCurrentFragment())).resetScroll();
}
});
if (!subreddit.equals("random") && !subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.equals("friends") && !subreddit.equals("mod") && !subreddit.equals("myrandom") && !subreddit.equals("randnsfw") && !subreddit.equals("popular") && !subreddit.contains("+")) {
executeAsyncSubreddit(subreddit);
} else {
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);
}
}
use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.
the class Website method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
overrideSwipeFromAnywhere();
super.onCreate(savedInstanceState);
applyColorTheme("");
setContentView(R.layout.activity_web);
url = getIntent().getExtras().getString(EXTRA_URL, "");
subredditColor = getIntent().getExtras().getInt(EXTRA_COLOR, Palette.getDefaultColor());
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
setupAppBar(R.id.toolbar, "", true, subredditColor, R.id.appbar);
mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
p = (ProgressBar) findViewById(R.id.progress);
v = (WebView) findViewById(R.id.web);
client = new MyWebViewClient();
webClient = new AdBlockWebViewClient();
if (!SettingValues.cookies) {
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
try {
cookieManager.removeAllCookies(null);
CookieManager.getInstance().flush();
cookieManager.setAcceptCookie(false);
} catch (NoSuchMethodError e) {
// Although these were added in api 12, some devices don't have this method
}
WebSettings ws = v.getSettings();
ws.setSaveFormData(false);
ws.setSavePassword(false);
}
/* todo in the future, drag left and right to go back and forward in history
IOverScrollDecor decor = new HorizontalOverScrollBounceEffectDecorator(new WebViewOverScrollDecoratorAdapter(v));
decor.setOverScrollStateListener(new IOverScrollStateListener() {
@Override
public void onOverScrollStateChange(IOverScrollDecor decor, int oldState, int newState) {
switch (newState) {
case IOverScrollState.STATE_IDLE:
// No over-scroll is in effect.
break;
case IOverScrollState.STATE_DRAG_START_SIDE:
break;
case IOverScrollState.STATE_DRAG_END_SIDE:
break;
case IOverScrollState.STATE_BOUNCE_BACK:
if (oldState == IOverScrollState.STATE_DRAG_START_SIDE) {
if(v.canGoBack())
v.goBack();
} else { // i.e. (oldState == STATE_DRAG_END_SIDE)
if(v.canGoForward())
v.goForward();
}
break;
}
}
});
*/
v.setWebChromeClient(client);
v.setWebViewClient(webClient);
v.getSettings().setBuiltInZoomControls(true);
v.getSettings().setDisplayZoomControls(false);
v.getSettings().setJavaScriptEnabled(true);
v.getSettings().setLoadWithOverviewMode(true);
v.getSettings().setUseWideViewPort(true);
v.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// Downloads using download manager on default browser
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
v.loadUrl(url);
}
Aggregations