1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2025-12-15 08:41:10 +01:00

Merge branch 'master' into poddy_as_podsource

This commit is contained in:
Gregor Santner 2016-10-14 00:44:23 +02:00
commit 110598ea85
56 changed files with 2028 additions and 322 deletions

View file

@ -31,9 +31,10 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
@ -43,10 +44,14 @@ import android.widget.Toast;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.fragment.ThemedFragment;
import com.github.dfa.diaspora_android.ui.HtmlTextView;
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.Log;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
import java.util.Observable;
import java.util.Observer;
@ -57,17 +62,24 @@ import butterknife.ButterKnife;
/**
* Activity that holds some fragments that show information about the app in a tab layout
*/
public class AboutActivity extends AppCompatActivity {
public class AboutActivity extends ThemedActivity
implements IntellihideToolbarActivityListener {
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
@BindView(R.id.about__appbar)
AppBarLayout appBarLayout;
@BindView(R.id.main__topbar)
protected Toolbar toolbar;
@BindView(R.id.appbar_linear_layout)
protected LinearLayout linearLayout;
@BindView(R.id.tabs)
protected TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -87,23 +99,58 @@ public class AboutActivity extends AppCompatActivity {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager = ButterKnife.findById(this, R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
//Apply intellihide
if (!((App) getApplication()).getSettings().isIntellihideToolbars()) {
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams();
params.setScrollFlags(0);
@Override
public void onResume() {
super.onResume();
if(getAppSettings().isIntellihideToolbars()) {
this.enableToolbarHiding();
} else {
this.disableToolbarHiding();
}
}
@Override
protected void applyColorToViews() {
ThemeHelper.updateToolbarColor(toolbar);
ThemeHelper.updateTabLayoutColor(tabLayout);
ThemeHelper.setPrimaryColorAsBackground(linearLayout);
}
@Override
public void enableToolbarHiding() {
AppLog.d(this, "Enable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams();
//scroll|enterAlways|snap
params.setScrollFlags(toolbarDefaultScrollFlags);
appBarLayout.setExpanded(true, true);
}
@Override
public void disableToolbarHiding() {
AppLog.d(this, "Disable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) linearLayout.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
appBarLayout.setExpanded(true, true);
}
/**
* Fragment that shows general information about the app
*/
public static class AboutFragment extends Fragment {
public static class AboutFragment extends ThemedFragment {
public static final String TAG = "com.github.dfa.diaspora_android.AboutActivity.AboutFragment";
@BindView(R.id.fragment_about__about_text)
TextView aboutText;
@BindView(R.id.fragment_about__app_version)
TextView appVersion;
public AboutFragment() {
}
@ -112,8 +159,7 @@ public class AboutActivity extends AppCompatActivity {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.about__fragment_about, container, false);
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_about__app_version);
ButterKnife.bind(this, rootView);
if (isAdded()) {
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
@ -125,18 +171,42 @@ public class AboutActivity extends AppCompatActivity {
}
return rootView;
}
@Override
protected void applyColorToViews() {
ThemeHelper.updateTextViewColor(aboutText);
}
@Override
public String getFragmentTag() {
return TAG;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override
public boolean onBackPressed() {
return false;
}
}
/**
* Fragment that shows information about the license of the app and used 3rd party libraries
*/
public static class LicenseFragment extends Fragment {
public static class LicenseFragment extends ThemedFragment {
public static final String TAG = "com.github.dfa.diaspora_android.AboutActivity.LicenseFragment";
@BindView(R.id.fragment_license__licensetext)
HtmlTextView textLicenseBox;
@BindView(R.id.fragment_license__3rdparty)
HtmlTextView textLicense3partyBox;
private String accentColor;
public LicenseFragment() {
}
@ -146,7 +216,7 @@ public class AboutActivity extends AppCompatActivity {
View rootView = inflater.inflate(R.layout.about__fragment_license, container, false);
ButterKnife.bind(this, rootView);
final Context context = rootView.getContext();
accentColor = Helpers.hexColorFromRessourceColor(context, R.color.colorAccent);
accentColor = Helpers.colorToHex(ThemeHelper.getAccentColor());
textLicenseBox.setTextFormatted(getString(R.string.fragment_license__license_content,
getMaintainersHtml(context),
@ -160,8 +230,6 @@ public class AboutActivity extends AppCompatActivity {
return rootView;
}
private String accentColor;
public String getContributorsHtml(Context context) {
String text = Helpers.readTextfileFromRawRessource(context, R.raw.contributors,
"<font color='" + accentColor + "'><b>*</b></font> ", "<br>");
@ -187,13 +255,52 @@ public class AboutActivity extends AppCompatActivity {
text = text.replace("NEWENTRY", "<font color='" + accentColor + "'><b>*</b></font> ");
return text;
}
@Override
protected void applyColorToViews() {
ThemeHelper.updateTextViewColor(textLicense3partyBox);
ThemeHelper.updateTextViewColor(textLicenseBox);
}
@Override
public String getFragmentTag() {
return TAG;
}
@Override
public void onCreateBottomOptionsMenu(Menu menu, MenuInflater inflater) {
/* Nothing to do */
}
@Override
public boolean onBackPressed() {
return false;
}
}
/**
* Fragment that shows debug information like app version, pod version...
*/
public static class DebugFragment extends Fragment implements Observer {
private TextView logBox;
public static final String TAG = "com.github.dfa.diaspora_android.AboutActivity.DebugFragment";
@BindView(R.id.fragment_debug__package_name)
TextView packageName;
@BindView(R.id.fragment_debug__app_version)
TextView appVersion;
@BindView(R.id.fragment_debug__android_version)
TextView osVersion;
@BindView(R.id.fragment_debug__device_name)
TextView deviceName;
@BindView(R.id.fragment_debug__pod_domain)
TextView podDomain;
@BindView(R.id.fragment_debug__log_box)
TextView logBox;
public DebugFragment() {
}
@ -202,16 +309,11 @@ public class AboutActivity extends AppCompatActivity {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.about__fragment_debug, container, false);
TextView packageName = (TextView) rootView.findViewById(R.id.fragment_debug__package_name);
TextView appVersion = (TextView) rootView.findViewById(R.id.fragment_debug__app_version);
TextView osVersion = (TextView) rootView.findViewById(R.id.fragment_debug__android_version);
TextView deviceName = (TextView) rootView.findViewById(R.id.fragment_debug__device_name);
TextView podDomain = (TextView) rootView.findViewById(R.id.fragment_debug__pod_domain);
logBox = (TextView) rootView.findViewById(R.id.fragment_debug__log_box);
ButterKnife.bind(this, rootView);
App app = (App) getActivity().getApplication();
logBox.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
AppLog.d(this, "Long click registered");
if (isAdded()) {
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("DEBUG_LOG", Log.getLogBuffer());
@ -229,15 +331,16 @@ public class AboutActivity extends AppCompatActivity {
if (isAdded()) {
try {
PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0);
AppSettings settings = ((App) getActivity().getApplication()).getSettings();
AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
DiasporaUrlHelper urls = new DiasporaUrlHelper(appSettings);
packageName.setText(pInfo.packageName);
appVersion.setText(getString(R.string.fragment_debug__app_version, pInfo.versionName + " (" + pInfo.versionCode + ")"));
osVersion.setText(getString(R.string.fragment_debug__android_version, Build.VERSION.RELEASE));
deviceName.setText(getString(R.string.fragment_debug__device_name, Build.MANUFACTURER + " " + Build.MODEL));
if (settings.getPod() != null) {
podDomain.setText(getString(R.string.fragment_debug__pod_domain, settings.getPod().getName()));
podDomain.setText(getString(R.string.fragment_debug__pod_domain, urls.getPodUrl()));
if (app.getSettings().getPod() != null) {
podDomain.setText(getString(R.string.fragment_debug__pod_domain, app.getSettings().getPod().getName()));
}
} catch (PackageManager.NameNotFoundException e) {

View file

@ -54,6 +54,7 @@ import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -68,18 +69,25 @@ import com.github.dfa.diaspora_android.fragment.HashtagListFragment;
import com.github.dfa.diaspora_android.fragment.PodSelectionFragment;
import com.github.dfa.diaspora_android.listener.WebUserProfileChangedListener;
import com.github.dfa.diaspora_android.receiver.OpenExternalLinkReceiver;
import com.github.dfa.diaspora_android.util.ProxyHandler;
import com.github.dfa.diaspora_android.receiver.UpdateTitleReceiver;
import com.github.dfa.diaspora_android.ui.BadgeDrawable;
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
import com.github.dfa.diaspora_android.util.WebHelper;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, WebUserProfileChangedListener, CustomTabActivityHelper.ConnectionCallback {
public class MainActivity extends ThemedActivity
implements NavigationView.OnNavigationItemSelectedListener,
WebUserProfileChangedListener,
CustomTabActivityHelper.ConnectionCallback,
IntellihideToolbarActivityListener {
public static final int REQUEST_CODE_ASK_PERMISSIONS = 123;
@ -92,7 +100,6 @@ public class MainActivity extends AppCompatActivity
public static final String ACTION_CHANGE_ACCOUNT = "com.github.dfa.diaspora_android.MainActivity.change_account";
public static final String ACTION_CLEAR_CACHE = "com.github.dfa.diaspora_android.MainActivity.clear_cache";
public static final String ACTION_UPDATE_TITLE_FROM_URL = "com.github.dfa.diaspora_android.MainActivity.set_title";
public static final String ACTION_RELOAD_ACTIVITY = "com.github.dfa.diaspora_android.MainActivity.reload_activity";
public static final String URL_MESSAGE = "URL_MESSAGE";
public static final String EXTRA_URL = "com.github.dfa.diaspora_android.extra_url";
public static final String CONTENT_HASHTAG = "content://com.github.dfa.diaspora_android.mainactivity/";
@ -113,6 +120,9 @@ public class MainActivity extends AppCompatActivity
/**
* UI Bindings
*/
@BindView(R.id.main__appbar)
AppBarLayout appBarLayout;
@BindView(R.id.main__topbar)
Toolbar toolbarTop;
@ -128,6 +138,9 @@ public class MainActivity extends AppCompatActivity
@BindView(R.id.main__navdrawer)
DrawerLayout navDrawer;
RelativeLayout navDrawerLayout;
LinearLayout navProfilePictureArea;
// NavHeader cannot be bound by Butterknife
private TextView navheaderTitle;
@ -160,6 +173,7 @@ public class MainActivity extends AppCompatActivity
urls = new DiasporaUrlHelper(appSettings);
customTabActivityHelper = new CustomTabActivityHelper();
customTabActivityHelper.setConnectionCallback(this);
ProxyHandler.getInstance().updateProxySettings(this);
fm = getSupportFragmentManager();
setupUI();
@ -169,7 +183,7 @@ public class MainActivity extends AppCompatActivity
@Override
public void setTitle(int rId) {
CustomFragment top = getTopFragment();
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
if(top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
MainActivity.this.setTitle(rId);
}
}
@ -177,7 +191,7 @@ public class MainActivity extends AppCompatActivity
@Override
public void setTitle(String title) {
CustomFragment top = getTopFragment();
if (top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
if(top != null && top.getFragmentTag().equals(DiasporaStreamFragment.TAG)) {
MainActivity.this.setTitle(title);
}
}
@ -229,19 +243,11 @@ public class MainActivity extends AppCompatActivity
// Load app settings
setupNavigationSlider();
if (!appSettings.isIntellihideToolbars()) {
AppLog.v(this, "Disable intelligent hiding of toolbars");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
}
AppLog.v(this, "UI successfully set up");
}
/**
* Show DiasporaStreamFragment if necessary and load URL url
*
* @param url URL to load in the DiasporaStreamFragment
*/
public void openDiasporaUrl(String url) {
@ -255,13 +261,12 @@ public class MainActivity extends AppCompatActivity
* Get an instance of the CustomFragment with the tag fragmentTag.
* If there was no instance so far, create a new one and add it to the FragmentManagers pool.
* If there is no Fragment with the corresponding Tag, return the top fragment.
*
* @param fragmentTag tag
* @return corresponding Fragment
*/
protected CustomFragment getFragment(String fragmentTag) {
CustomFragment fragment = (CustomFragment) fm.findFragmentByTag(fragmentTag);
if (fragment != null) {
if(fragment != null) {
return fragment;
} else {
switch (fragmentTag) {
@ -282,8 +287,8 @@ public class MainActivity extends AppCompatActivity
fm.beginTransaction().add(psf, fragmentTag).commit();
return psf;
default:
AppLog.e(this, "Invalid Fragment Tag: " + fragmentTag
+ "\nAdd Fragments Tag to getFragment()'s switch case.");
AppLog.e(this,"Invalid Fragment Tag: "+fragmentTag
+"\nAdd Fragments Tag to getFragment()'s switch case.");
return getTopFragment();
}
}
@ -291,13 +296,12 @@ public class MainActivity extends AppCompatActivity
/**
* Show the Fragment fragment in R.id.fragment_container. If the fragment was already visible, do nothing.
*
* @param fragment Fragment to show
*/
protected void showFragment(CustomFragment fragment) {
AppLog.v(this, "showFragment()");
CustomFragment currentTop = (CustomFragment) fm.findFragmentById(R.id.fragment_container);
if (currentTop == null || !currentTop.getFragmentTag().equals(fragment.getFragmentTag())) {
if(currentTop == null || !currentTop.getFragmentTag().equals(fragment.getFragmentTag())) {
AppLog.v(this, "Fragment was not visible. Replace it.");
fm.beginTransaction().addToBackStack(null).replace(R.id.fragment_container, fragment, fragment.getFragmentTag()).commit();
invalidateOptionsMenu();
@ -319,9 +323,10 @@ public class MainActivity extends AppCompatActivity
navView.setNavigationItemSelectedListener(this);
View navHeader = navView.getHeaderView(0);
LinearLayout navheaderProfileSection = ButterKnife.findById(navHeader, R.id.nav_profile_picture);
navProfilePictureArea = ButterKnife.findById(navHeader, R.id.nav_profile_picture);
navDrawerLayout = ButterKnife.findById(navHeader, R.id.nav_drawer);
//Handle clicks on profile picture
navheaderProfileSection.setOnClickListener(new View.OnClickListener() {
navProfilePictureArea.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
navDrawer.closeDrawer(GravityCompat.START);
@ -358,11 +363,30 @@ public class MainActivity extends AppCompatActivity
}
}
}
updateNavigationViewEntryVisibilities();
}
protected void updateNavigationViewEntryVisibilities() {
Menu navMenu = navView.getMenu();
navMenu.findItem(R.id.nav_exit).setVisible(appSettings.isVisibleInNavExit());
navMenu.findItem(R.id.nav_activities).setVisible(appSettings.isVisibleInNavActivities());
navMenu.findItem(R.id.nav_aspects).setVisible(appSettings.isVisibleInNavAspects());
navMenu.findItem(R.id.nav_commented).setVisible(appSettings.isVisibleInNavCommented());
navMenu.findItem(R.id.nav_followed_tags).setVisible(appSettings.isVisibleInNavFollowed_tags());
navMenu.findItem(R.id.nav_about).setVisible(appSettings.isVisibleInNavHelp_license());
navMenu.findItem(R.id.nav_liked).setVisible(appSettings.isVisibleInNavLiked());
navMenu.findItem(R.id.nav_mentions).setVisible(appSettings.isVisibleInNavMentions());
navMenu.findItem(R.id.nav_profile).setVisible(appSettings.isVisibleInNavProfile());
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
// Top bar
if (appSettings.getPod() == null) {
navMenu.setGroupVisible(navMenu.findItem(R.id.nav_exit).getGroupId(), false);
}
}
/**
* Forward incoming intents to handleIntent()
*
* @param intent incoming
*/
@Override
@ -373,7 +397,6 @@ public class MainActivity extends AppCompatActivity
/**
* Handle intents and execute intent specific actions
*
* @param intent intent to get handled
*/
private void handleIntent(Intent intent) {
@ -398,7 +421,7 @@ public class MainActivity extends AppCompatActivity
return;
} else {
loadUrl = intent.getDataString();
AppLog.v(this, "Intent has a delicious URL for us: " + loadUrl);
AppLog.v(this, "Intent has a delicious URL for us: "+loadUrl);
}
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
@ -408,10 +431,6 @@ public class MainActivity extends AppCompatActivity
} else if (ACTION_CLEAR_CACHE.equals(action)) {
AppLog.v(this, "Clear WebView cache");
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true);
} else if (ACTION_RELOAD_ACTIVITY.equals(action)) {
AppLog.v(this, "Recreate activity");
recreate();
return;
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
switch (type) {
case "text/plain":
@ -438,25 +457,23 @@ public class MainActivity extends AppCompatActivity
/**
* Handle activity results
*
* @param requestCode reqCode
* @param resultCode resCode
* @param data data
* @param resultCode resCode
* @param data data
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
AppLog.v(this, "onActivityResult(): " + requestCode);
AppLog.v(this, "onActivityResult(): "+requestCode);
super.onActivityResult(requestCode, resultCode, data);
}
/**
* Return the fragment which is currently displayed in R.id.fragment_container
*
* @return top fragment or null if there is none displayed
*/
private CustomFragment getTopFragment() {
Fragment top = fm.findFragmentById(R.id.fragment_container);
if (top != null) {
if(top != null) {
return (CustomFragment) top;
}
return null;
@ -473,12 +490,12 @@ public class MainActivity extends AppCompatActivity
return;
}
CustomFragment top = getTopFragment();
if (top != null) {
if(top != null) {
AppLog.v(this, "Top Fragment is not null");
if (!top.onBackPressed()) {
if(!top.onBackPressed()) {
AppLog.v(this, "Top Fragment.onBackPressed was false");
AppLog.v(this, "BackStackEntryCount: " + fm.getBackStackEntryCount());
if (fm.getBackStackEntryCount() > 0) {
AppLog.v(this, "BackStackEntryCount: "+fm.getBackStackEntryCount());
if(fm.getBackStackEntryCount()>0) {
fm.popBackStack();
} else {
snackbarExitApp.show();
@ -523,12 +540,18 @@ public class MainActivity extends AppCompatActivity
AppLog.v(this, "Register BroadcastReceivers");
LocalBroadcastManager.getInstance(this).registerReceiver(brSetTitle, new IntentFilter(ACTION_UPDATE_TITLE_FROM_URL));
LocalBroadcastManager.getInstance(this).registerReceiver(brOpenExternalLink, new IntentFilter(ACTION_OPEN_EXTERNAL_URL));
this.appSettings = getAppSettings();
if (appSettings.isIntellihideToolbars()) {
this.enableToolbarHiding();
} else {
this.disableToolbarHiding();
}
updateNavigationViewEntryVisibilities();
}
/**
* Clear and repopulate top and bottom toolbar.
* Also add menu items of the displayed fragment
*
* @param menu top toolbar
* @return boolean
*/
@ -541,9 +564,9 @@ public class MainActivity extends AppCompatActivity
toolbarBottom.setVisibility(View.VISIBLE);
CustomFragment top = getTopFragment();
if (top != null) {
if(top != null) {
//Are we displaying a Fragment other than PodSelectionFragment?
if (!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
if(!top.getFragmentTag().equals(PodSelectionFragment.TAG)) {
getMenuInflater().inflate(R.menu.main__menu_top, menu);
getMenuInflater().inflate(R.menu.main__menu_bottom, toolbarBottom.getMenu());
top.onCreateBottomOptionsMenu(toolbarBottom.getMenu(), getMenuInflater());
@ -559,30 +582,13 @@ public class MainActivity extends AppCompatActivity
/**
* Set the notification and messages counter in the top toolbar
*
* @param menu menu
* @return boolean
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Navigation slider
Menu navMenu = navView.getMenu();
navMenu.findItem(R.id.nav_exit).setVisible(appSettings.isVisibleInNavExit());
navMenu.findItem(R.id.nav_activities).setVisible(appSettings.isVisibleInNavActivities());
navMenu.findItem(R.id.nav_aspects).setVisible(appSettings.isVisibleInNavAspects());
navMenu.findItem(R.id.nav_commented).setVisible(appSettings.isVisibleInNavCommented());
navMenu.findItem(R.id.nav_followed_tags).setVisible(appSettings.isVisibleInNavFollowed_tags());
navMenu.findItem(R.id.nav_about).setVisible(appSettings.isVisibleInNavHelp_license());
navMenu.findItem(R.id.nav_liked).setVisible(appSettings.isVisibleInNavLiked());
navMenu.findItem(R.id.nav_mentions).setVisible(appSettings.isVisibleInNavMentions());
navMenu.findItem(R.id.nav_profile).setVisible(appSettings.isVisibleInNavProfile());
navMenu.findItem(R.id.nav_public).setVisible(appSettings.isVisibleInNavPublic_activities());
// Top bar
MenuItem item;
if (appSettings.getPod() == null) {
navMenu.setGroupVisible(navView.getMenu().findItem(R.id.nav_exit).getGroupId(), false);
}
updateNavigationViewEntryVisibilities();
if ((item = menu.findItem(R.id.action_notifications)) != null) {
LayerDrawable icon = (LayerDrawable) item.getIcon();
@ -598,7 +604,6 @@ public class MainActivity extends AppCompatActivity
/**
* Handle clicks on the optionsmenu
*
* @param item item
* @return boolean
*/
@ -697,7 +702,6 @@ public class MainActivity extends AppCompatActivity
/**
* Update the profile name in the navigation slider
*
* @param name name
*/
@Override
@ -708,7 +712,6 @@ public class MainActivity extends AppCompatActivity
/**
* Update the profile picture in the navigation slider
*
* @param avatarUrl url of the new profile pic
*/
@Override
@ -719,7 +722,6 @@ public class MainActivity extends AppCompatActivity
/**
* Handle hashtag clicks. Open the new-post-url and inject the clicked hashtag into the post-editor
*
* @param intent intent
*/
private void handleHashtag(Intent intent) {
@ -734,7 +736,6 @@ public class MainActivity extends AppCompatActivity
/**
* Open the new-post-url and inject text that was shared into the app into the post editors text field
*
* @param intent shareTextIntent
*/
private void handleSendText(Intent intent) {
@ -793,7 +794,6 @@ public class MainActivity extends AppCompatActivity
/**
* Share an image shared to the app via diaspora
*
* @param intent shareImageIntent
*/
//TODO: Implement some day
@ -810,7 +810,6 @@ public class MainActivity extends AppCompatActivity
/**
* Invalidate the top toolbar to update the notification counter
*
* @param notificationCount new notification count
*/
@Override
@ -822,7 +821,6 @@ public class MainActivity extends AppCompatActivity
/**
* Invalidate the top toolbar to update the unread messages counter
*
* @param unreadMessageCount new unread messages count
*/
@Override
@ -834,8 +832,8 @@ public class MainActivity extends AppCompatActivity
@Override
public void onCustomTabsConnected() {
if (customTabsSession == null) {
AppLog.i(this, "CustomTabs warmup: " + customTabActivityHelper.warmup(0));
if(customTabsSession == null) {
AppLog.i(this, "CustomTabs warmup: "+customTabActivityHelper.warmup(0));
customTabsSession = customTabActivityHelper.getSession();
}
}
@ -955,9 +953,8 @@ public class MainActivity extends AppCompatActivity
/**
* React to results of requestPermission
*
* @param requestCode resCode
* @param permissions requested permissions
* @param requestCode resCode
* @param permissions requested permissions
* @param grantResults granted results
*/
@Override
@ -981,7 +978,6 @@ public class MainActivity extends AppCompatActivity
/**
* Return the string that will be shared into the new-post-editor
*
* @return String
*/
public String getTextToBeShared() {
@ -990,10 +986,34 @@ public class MainActivity extends AppCompatActivity
/**
* Set the string that will be shared into the new-post-editor
*
* @param textToBeShared
*/
public void setTextToBeShared(String textToBeShared) {
this.textToBeShared = textToBeShared;
}
}
@Override
protected void applyColorToViews() {
ThemeHelper.updateToolbarColor(toolbarTop);
ThemeHelper.updateActionMenuViewColor(toolbarBottom);
navDrawerLayout.setBackgroundColor(appSettings.getPrimaryColor());
navProfilePictureArea.setBackgroundColor(appSettings.getPrimaryColor());
}
@Override
public void enableToolbarHiding() {
AppLog.d(this, "Enable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
//scroll|enterAlways|snap
params.setScrollFlags(toolbarDefaultScrollFlags);
appBarLayout.setExpanded(true, true);
}
@Override
public void disableToolbarHiding() {
AppLog.d(this, "Disable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbarTop.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
appBarLayout.setExpanded(true, true);
}
}

View file

@ -1,58 +1,85 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.data.DiasporaPodList;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.ui.IntellihideToolbarActivityListener;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
import com.github.dfa.diaspora_android.util.ProxyHandler;
import com.github.dfa.diaspora_android.util.theming.ColorPalette;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
import butterknife.BindView;
import butterknife.ButterKnife;
import uz.shift.colorpicker.LineColorPicker;
import uz.shift.colorpicker.OnColorChangedListener;
/**
* @author vanitas
*/
public class SettingsActivity extends AppCompatActivity {
private boolean activityRestartRequired;
public class SettingsActivity extends ThemedActivity implements IntellihideToolbarActivityListener {
@BindView(R.id.settings__appbar)
protected AppBarLayout appBarLayout;
@BindView(R.id.settings__toolbar)
protected Toolbar toolbar;
private ProxyHandler.ProxySettings oldProxySettings;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar toolbar = getSupportActionBar();
if (toolbar != null)
toolbar.setDisplayHomeAsUpEnabled(true);
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
setContentView(R.layout.settings__activity);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back_white_24px));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SettingsActivity.this.onBackPressed();
}
});
oldProxySettings = getAppSettings().getProxySettings();
getFragmentManager().beginTransaction().replace(R.id.settings__fragment_container, new SettingsFragment()).commit();
}
@Override
@ -66,8 +93,26 @@ public class SettingsActivity extends AppCompatActivity {
}
}
private void setActivityRestartRequired() {
this.activityRestartRequired = true;
@Override
protected void applyColorToViews() {
ThemeHelper.updateToolbarColor(toolbar);
}
@Override
public void enableToolbarHiding() {
AppLog.d(this, "Enable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
//scroll|enterAlways|snap
params.setScrollFlags(toolbarDefaultScrollFlags);
appBarLayout.setExpanded(true, true);
}
@Override
public void disableToolbarHiding() {
AppLog.d(this, "Disable Intellihide");
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
appBarLayout.setExpanded(true, true);
}
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@ -81,12 +126,12 @@ public class SettingsActivity extends AppCompatActivity {
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
setPreferenceSummaries();
sharedPreferences.edit().putBoolean(getString(R.string.pref_key__proxy_was_enabled),
sharedPreferences.getBoolean(getString(R.string.pref_key__proxy_enabled), false)).apply();
sharedPreferences.getBoolean(getString(R.string.pref_key__http_proxy_enabled), false)).apply();
}
private void setPreferenceSummaries() {
String[] editTextKeys = new String[]{
getString(R.string.pref_key__proxy_host), getString(R.string.pref_key__proxy_port)
getString(R.string.pref_key__http_proxy_host), getString(R.string.pref_key__http_proxy_port)
};
for (String key : editTextKeys) {
EditTextPreference p = (EditTextPreference) findPreference(key);
@ -97,14 +142,12 @@ public class SettingsActivity extends AppCompatActivity {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updatePreference(findPreference(key));
if (key != null && isAdded() && (key.equals(getString(R.string.pref_key__font_size)) ||
key.equals(getString(R.string.pref_key__load_images)) ||
key.equals(getString(R.string.pref_key__intellihide_toolbars)) ||
key.equals(getString(R.string.pref_key__proxy_enabled)) ||
key.equals(getString(R.string.pref_key__proxy_host)) ||
key.equals(getString(R.string.pref_key__proxy_port)) ||
key.startsWith("pref_key__visibility_nav__"))) {
((SettingsActivity) getActivity()).setActivityRestartRequired();
if (key.equals(getString(R.string.pref_key__intellihide_toolbars))) {
if (sharedPreferences.getBoolean(getString(R.string.pref_key__intellihide_toolbars), false)) {
((SettingsActivity) getActivity()).enableToolbarHiding();
} else {
((SettingsActivity) getActivity()).disableToolbarHiding();
}
}
}
@ -125,10 +168,31 @@ public class SettingsActivity extends AppCompatActivity {
@Override
public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
Intent intent = new Intent(getActivity(), MainActivity.class);
App app = ((App) getActivity().getApplication());
AppSettings appSettings = app.getSettings();
if (Build.VERSION.SDK_INT >= 21) {
if (preference instanceof PreferenceScreen && ((PreferenceScreen) preference).getDialog() != null) {
Window window = ((PreferenceScreen) preference).getDialog().getWindow();
if (window != null) {
window.setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
}
}
}
Intent intent = new Intent(getActivity(), MainActivity.class);
DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(app.getSettings());
switch (preference.getTitleRes()) {
case R.string.pref_title__primary_color: {
showColorPickerDialog(1);
intent = null;
break;
}
case R.string.pref_title__accent_color: {
showColorPickerDialog(2);
intent = null;
break;
}
case R.string.pref_title__personal_settings: {
intent.setAction(MainActivity.ACTION_OPEN_URL);
intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl());
@ -161,8 +225,13 @@ public class SettingsActivity extends AppCompatActivity {
.show();
return true;
}
case R.string.pref_title__clear_cache:
{
case R.string.pref_title__http_proxy_load_tor_preset: {
((EditTextPreference) findPreference(getString(R.string.pref_key__http_proxy_host))).setText("127.0.0.1");
((EditTextPreference) findPreference(getString(R.string.pref_key__http_proxy_port))).setText("8118");
return true;
}
case R.string.pref_title__clear_cache: {
intent.setAction(MainActivity.ACTION_CLEAR_CACHE);
break;
}
@ -179,6 +248,72 @@ public class SettingsActivity extends AppCompatActivity {
}
return super.onPreferenceTreeClick(screen, preference);
}
/**
* Show a colorPicker Dialog
*
* @param type 1 -> Primary Color, 2 -> Accent Color
*/
public void showColorPickerDialog(final int type) {
final AppSettings appSettings = ((App) getActivity().getApplication()).getSettings();
final Context context = getActivity();
//Inflate dialog layout
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.color_picker__dialog, null);
final android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
builder.setView(dialogLayout);
final FrameLayout titleBackground = (FrameLayout) dialogLayout.findViewById(R.id.color_picker_dialog__title_background);
final TextView title = (TextView) dialogLayout.findViewById(R.id.color_picker_dialog__title);
final LineColorPicker base = (LineColorPicker) dialogLayout.findViewById(R.id.color_picker_dialog__base_picker);
final LineColorPicker shade = (LineColorPicker) dialogLayout.findViewById(R.id.color_picker_dialog__shade_picker);
title.setText(type == 1 ? R.string.pref_title__primary_color : R.string.pref_title__accent_color);
title.setTextColor(getResources().getColor(R.color.white));
final int[] current = (type == 1 ? appSettings.getPrimaryColorSettings() : appSettings.getAccentColorSettings());
base.setColors((type == 1 ? ColorPalette.getBaseColors(context) : ColorPalette.getAccentColors(context)));
base.setSelectedColor(current[0]);
shade.setColors(ColorPalette.getColors(context, current[0]));
shade.setSelectedColor(current[1]);
titleBackground.setBackgroundColor(shade.getColor());
base.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int i) {
AppLog.d(this, "Selected Base color changed: " + i);
shade.setColors(ColorPalette.getColors(context, i));
titleBackground.setBackgroundColor(i);
if (i == current[0]) {
shade.setSelectedColor(current[1]);
titleBackground.setBackgroundColor(shade.getColor());
}
}
});
shade.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int i) {
titleBackground.setBackgroundColor(i);
}
});
//Build dialog
builder
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (type == 1) {
appSettings.setPrimaryColorSettings(base.getColor(), shade.getColor());
if (Build.VERSION.SDK_INT >= 21) {
getActivity().getWindow().setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
}
((ThemedActivity) getActivity()).applyColorToViews();
} else {
appSettings.setAccentColorSettings(base.getColor(), shade.getColor());
}
}
}).show();
}
}
@Override
@ -193,11 +328,21 @@ public class SettingsActivity extends AppCompatActivity {
@Override
protected void onStop() {
super.onStop();
if (activityRestartRequired) {
Intent intent = new Intent(this, MainActivity.class);
intent.setAction(MainActivity.ACTION_RELOAD_ACTIVITY);
startActivity(intent);
ProxyHandler.ProxySettings newProxySettings = getAppSettings().getProxySettings();
if (!oldProxySettings.equals(newProxySettings)) {
AppLog.d(this, "ProxySettings changed.");
//Proxy on-off? => Restart app
if (oldProxySettings.isEnabled() && !newProxySettings.isEnabled()) {
Intent restartActivity = new Intent(SettingsActivity.this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(SettingsActivity.this, 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) SettingsActivity.this.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
System.exit(0);
} //Proxy changed? => Update
else {
ProxyHandler.getInstance().updateProxySettings(this);
}
}
super.onStop();
}
}

View file

@ -0,0 +1,78 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.activity;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
/**
* Activity that supports color schemes
* Created by vanitas on 06.10.16.
*/
public abstract class ThemedActivity extends AppCompatActivity {
protected AppSettings getAppSettings() {
return ((App)getApplication()).getSettings();
}
@Override
protected void onResume() {
super.onResume();
ThemeHelper.getInstance(getAppSettings());
updateStatusBarColor();
updateRecentAppColor();
applyColorToViews();
}
protected abstract void applyColorToViews();
/**
* Update color of the status bar
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void updateStatusBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(ThemeHelper.getPrimaryDarkColor());
}
}
/**
* Update primary color in recent apps overview
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void updateRecentAppColor(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
BitmapDrawable drawable = ((BitmapDrawable) getDrawable(R.drawable.ic_launcher));
if(drawable != null) {
setTaskDescription(new ActivityManager.TaskDescription(
getResources().getString(R.string.app_name),
drawable.getBitmap(),
getAppSettings().getPrimaryColor()));
}
}
}
}

View file

@ -1,19 +1,15 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.data;
@ -23,6 +19,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.util.ProxyHandler;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod;
import com.github.dfa.diaspora_android.data.DiasporaPodList.DiasporaPod.DiasporaPodUrl;
@ -228,7 +225,7 @@ public class AppSettings {
@SuppressLint("CommitPrefEdits")
public void setProxyEnabled(boolean enabled) {
//commit instead of apply because the app is likely to be killed before apply is called.
prefApp.edit().putBoolean(context.getString(R.string.pref_key__proxy_enabled), enabled).commit();
prefApp.edit().putBoolean(context.getString(R.string.pref_key__http_proxy_enabled), enabled).commit();
}
/**
@ -237,7 +234,7 @@ public class AppSettings {
* @return whether proxy is enabled or not
*/
public boolean isProxyEnabled() {
return getBoolean(prefApp, R.string.pref_key__proxy_enabled, false);
return getBoolean(prefApp, R.string.pref_key__http_proxy_enabled, false);
}
public boolean wasProxyEnabled() {
@ -261,9 +258,12 @@ public class AppSettings {
* @return proxy host
*/
public String getProxyHost() {
return getString(prefApp, R.string.pref_key__proxy_host, "");
return getString(prefApp, R.string.pref_key__http_proxy_host, "");
}
public void setProxyHttpHost(String value) {
setString(prefApp, R.string.pref_key__http_proxy_host, value);
}
/**
* Default value: 0
*
@ -271,13 +271,21 @@ public class AppSettings {
*/
public int getProxyPort() {
try {
return Integer.parseInt(getString(prefApp, R.string.pref_key__proxy_port, "0"));
return Integer.parseInt(getString(prefApp, R.string.pref_key__http_proxy_port, "0"));
} catch (Exception e) {
setString(prefApp, R.string.pref_key__proxy_port, "0");
setString(prefApp, R.string.pref_key__http_proxy_port, "0");
return 0;
}
}
public void setProxyHttpPort(int value) {
setInt(prefApp, R.string.pref_key__http_proxy_port, value);
}
public ProxyHandler.ProxySettings getProxySettings() {
return new ProxyHandler.ProxySettings(isProxyEnabled(), getProxyHost(), getProxyPort());
}
public boolean isIntellihideToolbars() {
return getBoolean(prefApp, R.string.pref_key__intellihide_toolbars, false);
}
@ -333,4 +341,36 @@ public class AppSettings {
public boolean isVisibleInNavProfile() {
return getBoolean(prefApp, R.string.pref_key__visibility_nav__profile, false);
}
}
public void setPrimaryColorSettings(int base, int shade) {
setInt(prefApp, R.string.pref_key__primary_color_base, base);
setInt(prefApp, R.string.pref_key__primary_color_shade, shade);
}
public int[] getPrimaryColorSettings() {
return new int[]{
getInt(prefApp, R.string.pref_key__primary_color_base, context.getResources().getColor(R.color.md_blue_500)),
getInt(prefApp, R.string.pref_key__primary_color_shade, context.getResources().getColor(R.color.primary))
};
}
public int getPrimaryColor() {
return getInt(prefApp, R.string.pref_key__primary_color_shade, context.getResources().getColor(R.color.primary));
}
public void setAccentColorSettings(int base, int shade) {
setInt(prefApp, R.string.pref_key__accent_color_base, base);
setInt(prefApp, R.string.pref_key__accent_color_shade, shade);
}
public int[] getAccentColorSettings() {
return new int[]{
getInt(prefApp, R.string.pref_key__accent_color_base, context.getResources().getColor(R.color.md_deep_orange_500)),
getInt(prefApp, R.string.pref_key__accent_color_shade, context.getResources().getColor(R.color.accent))
};
}
public int getAccentColor() {
return getInt(prefApp, R.string.pref_key__accent_color_shade, context.getResources().getColor(R.color.accent));
}
}

View file

@ -1,9 +1,24 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.fragment;
import android.Manifest;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -11,7 +26,6 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
@ -22,16 +36,17 @@ import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.R;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.ProxyHandler;
import com.github.dfa.diaspora_android.ui.ContextMenuWebView;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.webview.CustomWebViewClient;
import com.github.dfa.diaspora_android.webview.ProgressBarWebChromeClient;
import com.github.dfa.diaspora_android.util.AppLog;
import java.io.File;
import java.io.FileOutputStream;
@ -42,16 +57,13 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import info.guardianproject.netcipher.NetCipher;
import info.guardianproject.netcipher.webkit.WebkitProxy;
/**
* Fragment with a webView and a ProgressBar.
* This Fragment retains its instance.
* Created by vanitas on 26.09.16.
*/
public class BrowserFragment extends CustomFragment {
public class BrowserFragment extends ThemedFragment {
public static final String TAG = "com.github.dfa.diaspora_android.BrowserFragment";
protected View rootLayout;
@ -84,21 +96,13 @@ public class BrowserFragment extends CustomFragment {
if(this.webView == null) {
this.webView = (ContextMenuWebView) view.findViewById(R.id.webView);
this.applyWebViewSettings();
ProxyHandler.getInstance().addWebView(webView);
}
if(this.progressBar == null) {
this.progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
}
if (appSettings.isProxyEnabled()) {
if (!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
AppLog.e(this, "Could not enable Proxy");
Toast.makeText(getContext(), R.string.toast_set_proxy_failed, Toast.LENGTH_SHORT).show();
}
} else if (appSettings.wasProxyEnabled()) {
resetProxy();
}
if(pendingUrl != null) {
loadUrl(pendingUrl);
pendingUrl = null;
@ -142,86 +146,15 @@ public class BrowserFragment extends CustomFragment {
webView.setWebChromeClient(new ProgressBarWebChromeClient(webView, progressBar));
}
/**
* Set proxy according to arguments. host must not be "" or null, port must be positive.
* Return true on success and update appSettings' proxy related values.
*
* @param host proxy host (eg. localhost or 127.0.0.1)
* @param port proxy port (eg. 8118)
* @return success
* @throws IllegalArgumentException if arguments do not fit specifications above
*/
private boolean setProxy(final String host, final int port) {
AppLog.i(this, "StreamFragment.setProxy()");
if (host != null && !host.equals("") && port >= 0) {
AppLog.i(this, "Set proxy to "+host+":"+port);
//Temporary change thread policy
AppLog.v(this, "Set temporary ThreadPolicy");
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
AppLog.v(this, "Apply NetCipher proxy settings");
NetCipher.setProxy(host, port); //Proxy for HttpsUrlConnections
try {
//Proxy for the webview
AppLog.v(this, "Apply Webkit proxy settings");
WebkitProxy.setProxy(MainActivity.class.getName(), getContext().getApplicationContext(), null, host, port);
} catch (Exception e) {
AppLog.e(this, "Could not apply WebKit proxy settings:\n"+e.toString());
}
AppLog.v(this, "Save changes in appSettings");
appSettings.setProxyEnabled(true);
appSettings.setProxyWasEnabled(true);
AppLog.v(this, "Reset old ThreadPolicy");
StrictMode.setThreadPolicy(old);
AppLog.i(this, "Success! Reload WebView");
webView.reload();
return true;
} else {
AppLog.e(this, "Invalid proxy configuration. Host: "+host+" Port: "+port+"\nRefuse to set proxy");
return false;
@Override
public void onResume() {
super.onResume();
if(webView != null) {
webSettings.setMinimumFontSize(appSettings.getMinimumFontSize());
webSettings.setLoadsImagesAutomatically(appSettings.isLoadImages());
}
}
@SuppressWarnings("unused")
private boolean setProxy() {
return setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
}
private void resetProxy() {
AppLog.i(this, "StreamFragment.resetProxy()");
AppLog.v(this, "write changes to appSettings");
appSettings.setProxyEnabled(false);
appSettings.setProxyWasEnabled(false);
//Temporary change thread policy
AppLog.v(this, "Set temporary ThreadPolicy");
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
AppLog.v(this, "clear NetCipher proxy");
NetCipher.clearProxy();
try {
AppLog.v(this, "clear WebKit proxy");
WebkitProxy.resetProxy(MainActivity.class.getName(), getContext());
} catch (Exception e) {
AppLog.e(this, "Could not clear WebKit proxy:\n"+e.toString());
}
AppLog.v(this, "Reset old ThreadPolicy");
StrictMode.setThreadPolicy(old);
//Restart app
AppLog.i(this, "Success! Restart app due to proxy reset");
Intent restartActivity = new Intent(getContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent);
System.exit(0);
}
@SuppressWarnings("ResultOfMethodCallIgnored")
protected boolean makeScreenshotOfWebView(boolean hasToShareScreenshot) {
AppLog.i(this, "StreamFragment.makeScreenshotOfWebView()");
@ -350,4 +283,9 @@ public class BrowserFragment extends CustomFragment {
public ContextMenuWebView getWebView() {
return this.webView;
}
@Override
protected void applyColorToViews() {
ThemeHelper.updateProgressBarColor(progressBar);
}
}

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.fragment;
import android.os.Bundle;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.fragment;
import android.Manifest;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.fragment;
import android.os.Bundle;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.fragment;
import android.content.BroadcastReceiver;

View file

@ -0,0 +1,43 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.fragment;
import com.github.dfa.diaspora_android.App;
import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
/**
* Fragment that supports color schemes
* Created by vanitas on 06.10.16.
*/
public abstract class ThemedFragment extends CustomFragment {
protected AppSettings getAppSettings() {
return ((App)getActivity().getApplication()).getSettings();
}
protected abstract void applyColorToViews();
@Override
public void onResume() {
super.onResume();
ThemeHelper.getInstance(getAppSettings());
applyColorToViews();
}
}

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.receiver;
import android.app.Activity;
@ -15,7 +33,7 @@ import com.github.dfa.diaspora_android.data.AppSettings;
import com.github.dfa.diaspora_android.util.AppLog;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.BrowserFallback;
import com.github.dfa.diaspora_android.util.CustomTabHelpers.CustomTabActivityHelper;
import com.github.dfa.diaspora_android.util.Helpers;
import com.github.dfa.diaspora_android.util.theming.ThemeHelper;
/**
* BroadcastReceiver that opens links in a Chrome CustomTab
@ -30,9 +48,10 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context c, Intent receiveIntent) {
AppSettings settings = new AppSettings(c);
AppSettings appSettings = new AppSettings(c);
ThemeHelper.getInstance(appSettings);
AppLog.v(this, "OpenExternalLinkReceiver.onReceive(): url");
AppLog.v(this, "OpenExternalLinkReceiver.onReceive(): url");
Uri url = null;
try {
@ -43,10 +62,10 @@ public class OpenExternalLinkReceiver extends BroadcastReceiver {
return;
}
if (settings.isChromeCustomTabsEnabled()) {
if (appSettings.isChromeCustomTabsEnabled()) {
// Setup Chrome Custom Tab
CustomTabsIntent.Builder customTab = new CustomTabsIntent.Builder();
customTab.setToolbarColor(Helpers.getColorFromRessource(c, R.color.colorPrimary));
customTab.setToolbarColor(ThemeHelper.getPrimaryColor());
customTab.addDefaultShareMenuItem();
Bitmap backButtonIcon = BitmapFactory.decodeResource(c.getResources(), R.drawable.chrome_custom_tab__back);

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.receiver;
import android.content.BroadcastReceiver;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.ui;
import android.content.Context;
@ -30,7 +48,7 @@ public class BadgeDrawable extends Drawable {
float textSize = context.getResources().getDimension(R.dimen.textsize_badge_count);
badgeBackground = new Paint();
badgeBackground.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.accent));
badgeBackground.setColor(ContextCompat.getColor(context.getApplicationContext(), R.color.md_deep_orange_650));
badgeBackground.setAntiAlias(true);
badgeBackground.setStyle(Paint.Style.FILL);
badgeStroke = new Paint();

View file

@ -0,0 +1,14 @@
package com.github.dfa.diaspora_android.ui;
import android.support.design.widget.AppBarLayout;
/**
* interface that adds options to control intellihide of toolbars to the Activity
* Created by vanitas on 08.10.16.
*/
public interface IntellihideToolbarActivityListener {
int toolbarDefaultScrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS | AppBarLayout.LayoutParams.SCROLL_FLAG_SNAP;
void enableToolbarHiding();
void disableToolbarHiding();
}

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.util;
/**

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.util.CustomTabHelpers;
import android.app.Activity;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.util.CustomTabHelpers;
import android.app.Activity;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.util.CustomTabHelpers;
import android.content.Context;

View file

@ -114,6 +114,10 @@ public class Helpers {
return "#" + Integer.toHexString(context.getResources().getColor(idColor) & 0x00ffffff);
}
public static String colorToHex(int color) {
return "#" + Integer.toHexString(color & 0x00ffffff);
}
public static void printBundle(Bundle savedInstanceState, String k) {
if (savedInstanceState != null) {
for (String key : savedInstanceState.keySet()) {

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.util;
import com.github.dfa.diaspora_android.data.AppSettings;

View file

@ -0,0 +1,135 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.util;
import android.content.Context;
import android.os.StrictMode;
import android.webkit.WebView;
import com.github.dfa.diaspora_android.activity.MainActivity;
import com.github.dfa.diaspora_android.data.AppSettings;
import java.util.ArrayList;
import info.guardianproject.netcipher.NetCipher;
import info.guardianproject.netcipher.webkit.WebkitProxy;
/**
* Proxy Handler that applies proxy settings of the app to webviews etc.
* Created by vanitas on 10.10.16.
*/
public class ProxyHandler {
private static ProxyHandler instance;
private ArrayList<WebView> webViews;
private ProxyHandler() {
/* Singleton, yo? */
this.webViews = new ArrayList<>();
}
public static ProxyHandler getInstance() {
if(instance == null) {
instance = new ProxyHandler();
}
return instance;
}
public void updateProxySettings(Context context) {
AppLog.d(this, "UpdateProxySettings()");
AppSettings appSettings = new AppSettings(context);
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
if (appSettings.isProxyEnabled()) {
//Update NetCipher
NetCipher.setProxy(appSettings.getProxyHost(), appSettings.getProxyPort());
//Update webviews
for (WebView wv : webViews) {
if (wv != null) {
try {
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), wv, appSettings.getProxyHost(), appSettings.getProxyPort());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
StrictMode.setThreadPolicy(old);
}
public void addWebView(WebView wv) {
AppLog.d(this, "AddWebView");
if(wv != null && !webViews.contains(wv)) {
webViews.add(wv);
updateWebViewProxySettings(wv, wv.getContext());
}
}
private void updateWebViewProxySettings(WebView wv, Context context) {
AppLog.d(this, "UpdateWebViewProxySettings()");
AppSettings appSettings = new AppSettings(context);
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(tmp);
if(appSettings.isProxyEnabled()) {
if (wv != null) {
try {
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), wv, appSettings.getProxyHost(), appSettings.getProxyPort());
} catch (Exception e) {
e.printStackTrace();
}
}
}
StrictMode.setThreadPolicy(old);
}
public static class ProxySettings {
private final boolean enabled;
private final String host;
private final int port;
public ProxySettings(boolean enabled, String host, int port) {
this.enabled = enabled;
this.host = host;
this.port = port;
}
public boolean isEnabled() {
return enabled;
}
public String getHost() {
return host;
}
public int getPort() {
return port;
}
@Override
public boolean equals(Object other) {
return (other instanceof ProxySettings) &&
enabled == ((ProxySettings) other).isEnabled() &&
host.equals(((ProxySettings) other).getHost()) &&
port == ((ProxySettings) other).getPort();
}
}
}

View file

@ -0,0 +1,288 @@
package com.github.dfa.diaspora_android.util.theming;
import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import com.github.dfa.diaspora_android.R;
/**
* Created by dnld on 24/02/16.
*/
public class ColorPalette {
public static int[] getAccentColors(Context context){
return new int[]{
ContextCompat.getColor(context, R.color.md_red_500),
ContextCompat.getColor(context, R.color.md_purple_500),
ContextCompat.getColor(context, R.color.md_deep_purple_500),
ContextCompat.getColor(context, R.color.md_blue_500),
ContextCompat.getColor(context, R.color.md_light_blue_500),
ContextCompat.getColor(context, R.color.md_cyan_500),
ContextCompat.getColor(context, R.color.md_teal_500),
ContextCompat.getColor(context, R.color.md_green_500),
ContextCompat.getColor(context, R.color.md_yellow_500),
ContextCompat.getColor(context, R.color.md_orange_500),
ContextCompat.getColor(context, R.color.md_deep_orange_500),
ContextCompat.getColor(context, R.color.md_brown_500),
ContextCompat.getColor(context, R.color.md_blue_grey_500),
};
}
public static int getObscuredColor(int c){
float[] hsv = new float[3];
int color = c;
Color.colorToHSV(color, hsv);
hsv[2] *= 0.85f; // value component
color = Color.HSVToColor(hsv);
return color;
}
public static int getTransparentColor(int color, int alpha){
return ColorUtils.setAlphaComponent(color, alpha);
}
public static int[] getTransparencyShadows(int color) {
int[] shadows = new int[10];
for (int i=0; i<10;i++)
shadows[i]= (ColorPalette.getTransparentColor(color, ((100-(i*10))*255) /100));
return shadows;
}
public static int[] getBaseColors(Context context) {
return new int[]{
ContextCompat.getColor(context, R.color.md_red_500),
ContextCompat.getColor(context, R.color.md_pink_500),
ContextCompat.getColor(context, R.color.md_purple_500),
ContextCompat.getColor(context, R.color.md_deep_purple_500),
ContextCompat.getColor(context, R.color.md_indigo_500),
ContextCompat.getColor(context, R.color.md_blue_500),
ContextCompat.getColor(context, R.color.md_light_blue_500),
ContextCompat.getColor(context, R.color.md_cyan_500),
ContextCompat.getColor(context, R.color.md_teal_500),
ContextCompat.getColor(context, R.color.md_green_500),
ContextCompat.getColor(context, R.color.md_light_green_500),
ContextCompat.getColor(context, R.color.md_lime_500),
ContextCompat.getColor(context, R.color.md_yellow_500),
ContextCompat.getColor(context, R.color.md_amber_500),
ContextCompat.getColor(context, R.color.md_orange_500),
ContextCompat.getColor(context, R.color.md_deep_orange_500),
ContextCompat.getColor(context, R.color.md_brown_500),
ContextCompat.getColor(context, R.color.md_blue_grey_500),
ContextCompat.getColor(context, R.color.md_grey_500)
};
}
public static int[] getColors(Context context, int c) {
if (c == ContextCompat.getColor(context, R.color.md_red_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_red_200),
ContextCompat.getColor(context, R.color.md_red_300),
ContextCompat.getColor(context, R.color.md_red_400),
ContextCompat.getColor(context, R.color.md_red_500),
ContextCompat.getColor(context, R.color.md_red_600),
ContextCompat.getColor(context, R.color.md_red_700),
ContextCompat.getColor(context, R.color.md_red_800),
ContextCompat.getColor(context, R.color.md_red_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_pink_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_pink_200),
ContextCompat.getColor(context, R.color.md_pink_300),
ContextCompat.getColor(context, R.color.md_pink_400),
ContextCompat.getColor(context, R.color.md_pink_500),
ContextCompat.getColor(context, R.color.md_pink_600),
ContextCompat.getColor(context, R.color.md_pink_700),
ContextCompat.getColor(context, R.color.md_pink_800),
ContextCompat.getColor(context, R.color.md_pink_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_purple_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_purple_200),
ContextCompat.getColor(context, R.color.md_purple_300),
ContextCompat.getColor(context, R.color.md_purple_400),
ContextCompat.getColor(context, R.color.md_purple_500),
ContextCompat.getColor(context, R.color.md_purple_600),
ContextCompat.getColor(context, R.color.md_purple_700),
ContextCompat.getColor(context, R.color.md_purple_800),
ContextCompat.getColor(context, R.color.md_purple_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_deep_purple_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_deep_purple_200),
ContextCompat.getColor(context, R.color.md_deep_purple_300),
ContextCompat.getColor(context, R.color.md_deep_purple_400),
ContextCompat.getColor(context, R.color.md_deep_purple_500),
ContextCompat.getColor(context, R.color.md_deep_purple_600),
ContextCompat.getColor(context, R.color.md_deep_purple_700),
ContextCompat.getColor(context, R.color.md_deep_purple_800),
ContextCompat.getColor(context, R.color.md_deep_purple_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_indigo_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_indigo_200),
ContextCompat.getColor(context, R.color.md_indigo_300),
ContextCompat.getColor(context, R.color.md_indigo_400),
ContextCompat.getColor(context, R.color.md_indigo_500),
ContextCompat.getColor(context, R.color.md_indigo_600),
ContextCompat.getColor(context, R.color.md_indigo_700),
ContextCompat.getColor(context, R.color.md_indigo_800),
ContextCompat.getColor(context, R.color.md_indigo_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_blue_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_blue_200),
ContextCompat.getColor(context, R.color.md_blue_300),
ContextCompat.getColor(context, R.color.md_blue_400),
ContextCompat.getColor(context, R.color.md_blue_500),
ContextCompat.getColor(context, R.color.md_blue_600),
ContextCompat.getColor(context, R.color.md_blue_650),
ContextCompat.getColor(context, R.color.md_blue_700),
ContextCompat.getColor(context, R.color.md_blue_750),
ContextCompat.getColor(context, R.color.md_blue_800),
ContextCompat.getColor(context, R.color.md_blue_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_light_blue_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_light_blue_200),
ContextCompat.getColor(context, R.color.md_light_blue_300),
ContextCompat.getColor(context, R.color.md_light_blue_400),
ContextCompat.getColor(context, R.color.md_light_blue_500),
ContextCompat.getColor(context, R.color.md_light_blue_600),
ContextCompat.getColor(context, R.color.md_light_blue_700),
ContextCompat.getColor(context, R.color.md_light_blue_800),
ContextCompat.getColor(context, R.color.md_light_blue_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_cyan_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_cyan_200),
ContextCompat.getColor(context, R.color.md_cyan_300),
ContextCompat.getColor(context, R.color.md_cyan_400),
ContextCompat.getColor(context, R.color.md_cyan_500),
ContextCompat.getColor(context, R.color.md_cyan_600),
ContextCompat.getColor(context, R.color.md_cyan_700),
ContextCompat.getColor(context, R.color.md_cyan_800),
ContextCompat.getColor(context, R.color.md_cyan_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_teal_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_teal_200),
ContextCompat.getColor(context, R.color.md_teal_300),
ContextCompat.getColor(context, R.color.md_teal_400),
ContextCompat.getColor(context, R.color.md_teal_500),
ContextCompat.getColor(context, R.color.md_teal_600),
ContextCompat.getColor(context, R.color.md_teal_700),
ContextCompat.getColor(context, R.color.md_teal_800),
ContextCompat.getColor(context, R.color.md_teal_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_green_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_green_200),
ContextCompat.getColor(context, R.color.md_green_300),
ContextCompat.getColor(context, R.color.md_green_400),
ContextCompat.getColor(context, R.color.md_green_500),
ContextCompat.getColor(context, R.color.md_green_600),
ContextCompat.getColor(context, R.color.md_green_700),
ContextCompat.getColor(context, R.color.md_green_800),
ContextCompat.getColor(context, R.color.md_green_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_light_green_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_light_green_200),
ContextCompat.getColor(context, R.color.md_light_green_300),
ContextCompat.getColor(context, R.color.md_light_green_400),
ContextCompat.getColor(context, R.color.md_light_green_500),
ContextCompat.getColor(context, R.color.md_light_green_600),
ContextCompat.getColor(context, R.color.md_light_green_700),
ContextCompat.getColor(context, R.color.md_light_green_800),
ContextCompat.getColor(context, R.color.md_light_green_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_lime_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_lime_200),
ContextCompat.getColor(context, R.color.md_lime_300),
ContextCompat.getColor(context, R.color.md_lime_400),
ContextCompat.getColor(context, R.color.md_lime_500),
ContextCompat.getColor(context, R.color.md_lime_600),
ContextCompat.getColor(context, R.color.md_lime_700),
ContextCompat.getColor(context, R.color.md_lime_800),
ContextCompat.getColor(context, R.color.md_lime_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_yellow_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_yellow_400),
ContextCompat.getColor(context, R.color.md_yellow_500),
ContextCompat.getColor(context, R.color.md_yellow_600),
ContextCompat.getColor(context, R.color.md_yellow_700),
ContextCompat.getColor(context, R.color.md_yellow_800),
ContextCompat.getColor(context, R.color.md_yellow_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_amber_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_amber_200),
ContextCompat.getColor(context, R.color.md_amber_300),
ContextCompat.getColor(context, R.color.md_amber_400),
ContextCompat.getColor(context, R.color.md_amber_500),
ContextCompat.getColor(context, R.color.md_amber_600),
ContextCompat.getColor(context, R.color.md_amber_700),
ContextCompat.getColor(context, R.color.md_amber_800),
ContextCompat.getColor(context, R.color.md_amber_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_orange_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_orange_200),
ContextCompat.getColor(context, R.color.md_orange_300),
ContextCompat.getColor(context, R.color.md_orange_400),
ContextCompat.getColor(context, R.color.md_orange_500),
ContextCompat.getColor(context, R.color.md_orange_600),
ContextCompat.getColor(context, R.color.md_orange_700),
ContextCompat.getColor(context, R.color.md_orange_800),
ContextCompat.getColor(context, R.color.md_orange_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_deep_orange_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_deep_orange_200),
ContextCompat.getColor(context, R.color.md_deep_orange_300),
ContextCompat.getColor(context, R.color.md_deep_orange_400),
ContextCompat.getColor(context, R.color.md_deep_orange_500),
ContextCompat.getColor(context, R.color.md_deep_orange_600),
ContextCompat.getColor(context, R.color.md_deep_orange_650),
ContextCompat.getColor(context, R.color.md_deep_orange_700),
ContextCompat.getColor(context, R.color.md_deep_orange_800),
ContextCompat.getColor(context, R.color.md_deep_orange_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_brown_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_brown_200),
ContextCompat.getColor(context, R.color.md_brown_300),
ContextCompat.getColor(context, R.color.md_brown_400),
ContextCompat.getColor(context, R.color.md_brown_500),
ContextCompat.getColor(context, R.color.md_brown_600),
ContextCompat.getColor(context, R.color.md_brown_700),
ContextCompat.getColor(context, R.color.md_brown_800),
ContextCompat.getColor(context, R.color.md_brown_900)
};
} else if (c == ContextCompat.getColor(context, R.color.md_grey_500)) {
return new int[]{
ContextCompat.getColor(context, R.color.md_grey_400),
ContextCompat.getColor(context, R.color.md_grey_500),
ContextCompat.getColor(context, R.color.md_grey_600),
ContextCompat.getColor(context, R.color.md_grey_700),
ContextCompat.getColor(context, R.color.md_grey_800),
ContextCompat.getColor(context, R.color.md_grey_900),
Color.parseColor("#000000")
};
} else {
return new int[]{
ContextCompat.getColor(context, R.color.md_blue_grey_300),
ContextCompat.getColor(context, R.color.md_blue_grey_400),
ContextCompat.getColor(context, R.color.md_blue_grey_500),
ContextCompat.getColor(context, R.color.md_blue_grey_600),
ContextCompat.getColor(context, R.color.md_blue_grey_700),
ContextCompat.getColor(context, R.color.md_blue_grey_800),
ContextCompat.getColor(context, R.color.md_blue_grey_900)
};
}
}
}

View file

@ -0,0 +1,128 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
This class is inspired by org.horasapps.LeafPic
*/
package com.github.dfa.diaspora_android.util.theming;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.support.design.widget.TabLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.github.dfa.diaspora_android.data.AppSettings;
/**
* Singleton that can be used to color views
* Created by vanitas on 06.10.16.
*/
public class ThemeHelper {
private AppSettings appSettings;
private static ThemeHelper instance;
private ThemeHelper(AppSettings appSettings) {
this.appSettings = appSettings;
}
public static ThemeHelper getInstance(AppSettings appSettings) {
if(instance == null) {
instance = new ThemeHelper(appSettings);
}
return instance;
}
public static ThemeHelper getInstance() {
if(instance == null) throw new IllegalStateException("ThemeHelper must be initialized using getInstance(AppSettings) before it can be used!");
return instance;
}
public static void updateEditTextColor(EditText editText) {
if(editText != null) {
editText.setHighlightColor(getInstance().appSettings.getAccentColor());
}
}
public static void updateCheckBoxColor(CheckBox checkBox) {
if(checkBox != null) {
checkBox.setHighlightColor(getInstance().appSettings.getAccentColor());
}
}
public static void updateTabLayoutColor(TabLayout tabLayout) {
if(tabLayout != null) {
tabLayout.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
tabLayout.setSelectedTabIndicatorColor(getInstance().appSettings.getAccentColor());
}
}
public static void updateTextViewColor(TextView textView) {
if(textView != null) {
textView.setHighlightColor(getInstance().appSettings.getAccentColor());
textView.setLinkTextColor(getInstance().appSettings.getAccentColor());
}
}
public static void updateToolbarColor(Toolbar toolbar) {
if(toolbar != null) {
toolbar.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
}
}
public static void updateActionMenuViewColor(ActionMenuView actionMenuView) {
if(actionMenuView != null) {
actionMenuView.setBackgroundColor(getInstance().appSettings.getPrimaryColor());
}
}
public static int getPrimaryColor() {
return getInstance().appSettings.getPrimaryColor();
}
public static int getAccentColor() {
return getInstance().appSettings.getAccentColor();
}
public static void setPrimaryColorAsBackground(View view) {
if(view != null) {
view.setBackgroundColor(getPrimaryColor());
}
}
public static int getPrimaryDarkColor() {
return ColorPalette.getObscuredColor(getPrimaryColor());
}
public static void updateActionBarColor(ActionBar actionBar) {
if(actionBar != null) {
actionBar.setBackgroundDrawable(new ColorDrawable(getInstance().appSettings.getPrimaryColor()));
}
}
public static void updateProgressBarColor(ProgressBar progressBar) {
if(progressBar != null && progressBar.getProgressDrawable() != null) {
progressBar.getProgressDrawable().setColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN);
}
}
}

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.webview;
import android.webkit.WebView;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.webview;
import android.net.Uri;

View file

@ -1,3 +1,21 @@
/*
This file is part of the Diaspora for Android.
Diaspora for Android is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Diaspora for Android is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Diaspora for Android.
If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.dfa.diaspora_android.webview;
import android.view.View;