Commit c6e35c34 authored by Romain Hunault's avatar Romain Hunault
Browse files

Merge branch 'issue_1727' into 'master'

Issue 1727

See merge request e/apps/notes!13
parents 89fb3c79 baab5e03
Pipeline #72733 passed with stage
in 2 minutes and 42 seconds
package foundation.e.notes.android.activity; package foundation.e.notes.android.activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import foundation.e.notes.R; import foundation.e.notes.R;
...@@ -15,6 +20,27 @@ public class AboutActivity extends AppCompatActivity { ...@@ -15,6 +20,27 @@ public class AboutActivity extends AppCompatActivity {
setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);
ButterKnife.bind(this); ButterKnife.bind(this);
getFragmentManager().beginTransaction().replace(R.id.container, new AboutFragment()).commit(); getFragmentManager().beginTransaction().replace(R.id.container, new AboutFragment()).commit();
updateAccentColor();
}
private void updateAccentColor(){
//change toolbar color
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(NotesListViewActivity.ACCENT_COLOR));
//change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkenColor(NotesListViewActivity.ACCENT_COLOR));
}
}
@ColorInt
int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return android.graphics.Color.HSVToColor(hsv);
} }
} }
\ No newline at end of file
...@@ -4,10 +4,17 @@ import android.accounts.Account; ...@@ -4,10 +4,17 @@ import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import foundation.e.notes.R; import foundation.e.notes.R;
...@@ -23,7 +30,7 @@ import static foundation.e.notes.android.activity.SettingsActivity.CREDENTIALS_C ...@@ -23,7 +30,7 @@ import static foundation.e.notes.android.activity.SettingsActivity.CREDENTIALS_C
* @author Nihar Thakkar * @author Nihar Thakkar
*/ */
public class AccountActivity extends AppCompatActivity { public class AccountActivity extends AppCompatActivity implements View.OnClickListener {
private final static String key_login_account = "login_account"; private final static String key_login_account = "login_account";
private final static String login_account_eelo = "login_account_eelo"; private final static String login_account_eelo = "login_account_eelo";
...@@ -34,6 +41,8 @@ public class AccountActivity extends AppCompatActivity { ...@@ -34,6 +41,8 @@ public class AccountActivity extends AppCompatActivity {
private AccountManager accountManager; private AccountManager accountManager;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private Button btn_eelo_Login;
private Button btn_manualLogin;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -67,35 +76,19 @@ public class AccountActivity extends AppCompatActivity { ...@@ -67,35 +76,19 @@ public class AccountActivity extends AppCompatActivity {
} }
} }
findViewById(R.id.eelo_account_login_button).setOnClickListener(new View.OnClickListener() { initview();
@Override updateAccentColor();
public void onClick(View view) { }
String[] accountTypes = new String[]{eelo_account_type};
Intent intent = AccountManager.newChooseAccountIntent( private void initview() {
null, btn_eelo_Login=(Button)findViewById(R.id.eelo_account_login_button);
null, btn_eelo_Login.setBackgroundColor(NotesListViewActivity.ACCENT_COLOR);
accountTypes, btn_eelo_Login.setOnClickListener(this);
null,
null, null,null); btn_manualLogin=(Button)findViewById(R.id.manual_account_login_button);
btn_manualLogin.setBackgroundColor(NotesListViewActivity.ACCENT_COLOR);
startActivityForResult(intent, pick_account_request_code); btn_manualLogin.setOnClickListener(this);
}
});
findViewById(R.id.manual_account_login_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (getIntent().getBooleanExtra("preference", false)) {
startActivity(new Intent(AccountActivity.this, SettingsActivity.class));
}
else {
Intent resultIntent = new Intent();
resultIntent.putExtra(key_login_account, login_account_manual);
setResult(RESULT_OK, resultIntent);
}
finish();
}
});
} }
@Override @Override
...@@ -128,4 +121,53 @@ public class AccountActivity extends AppCompatActivity { ...@@ -128,4 +121,53 @@ public class AccountActivity extends AppCompatActivity {
} }
} }
} }
private void updateAccentColor(){
//change toolbar color
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(NotesListViewActivity.ACCENT_COLOR));
//change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkenColor(NotesListViewActivity.ACCENT_COLOR));
}
}
@ColorInt
int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return android.graphics.Color.HSVToColor(hsv);
}
@Override
public void onClick(View view) {
if(view==btn_manualLogin){
if (getIntent().getBooleanExtra("preference", false)) {
startActivity(new Intent(AccountActivity.this, SettingsActivity.class));
}
else {
Intent resultIntent = new Intent();
resultIntent.putExtra(key_login_account, login_account_manual);
setResult(RESULT_OK, resultIntent);
}
finish();
}
else if(view==btn_eelo_Login){
String[] accountTypes = new String[]{eelo_account_type};
Intent intent = AccountManager.newChooseAccountIntent(
null,
null,
accountTypes,
null,
null, null,null);
startActivityForResult(intent, pick_account_request_code);
}
}
} }
...@@ -3,12 +3,17 @@ package foundation.e.notes.android.activity; ...@@ -3,12 +3,17 @@ package foundation.e.notes.android.activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.ColorInt;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
...@@ -48,6 +53,8 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm ...@@ -48,6 +53,8 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
if (actionBar != null) { if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
} }
updateAccentColor();
} }
@Override @Override
...@@ -214,4 +221,25 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm ...@@ -214,4 +221,25 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
} }
} }
} }
private void updateAccentColor(){
//change toolbar color
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(NotesListViewActivity.ACCENT_COLOR));
//change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkenColor(NotesListViewActivity.ACCENT_COLOR));
}
}
@ColorInt
int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return android.graphics.Color.HSVToColor(hsv);
}
} }
...@@ -3,33 +3,42 @@ package foundation.e.notes.android.activity; ...@@ -3,33 +3,42 @@ package foundation.e.notes.android.activity;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager; import android.content.pm.ShortcutManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.Settings; import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.appcompat.view.ActionMode; import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.AppCompatImageView;
...@@ -102,6 +111,8 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap ...@@ -102,6 +111,8 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
private final static String login_account_eelo = "login_account_eelo"; private final static String login_account_eelo = "login_account_eelo";
private final static String key_email_address = "email_address"; private final static String key_email_address = "email_address";
public static int ACCENT_COLOR;
@BindView(R.id.notesListActivityActionBar) @BindView(R.id.notesListActivityActionBar)
Toolbar toolbar; Toolbar toolbar;
...@@ -236,6 +247,11 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap ...@@ -236,6 +247,11 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
// dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.fg_default)); // dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.fg_default));
// dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.fg_default)); // dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.fg_default));
//} //}
ACCENT_COLOR= fetchAccentColor(this);
fabCreate.setBackgroundTintList(ColorStateList.valueOf(darkenColor20(ACCENT_COLOR)));
headerView.setBackgroundColor(ACCENT_COLOR);
} }
private void migrateUrl() { private void migrateUrl() {
...@@ -931,4 +947,48 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap ...@@ -931,4 +947,48 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
} }
/*
* get Accent color from OS
* */
private int fetchAccentColor(Context context) {
TypedValue typedValue = new TypedValue();
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
android.R.style.Theme_DeviceDefault);
contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
typedValue, true);
int color_accent = typedValue.data;
Log.e("TAG", "accent Colour #"+Integer.toHexString(color_accent));
//change toolbar color
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(color_accent));
//change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkenColor(color_accent));
}
return color_accent;
}
@ColorInt
int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return android.graphics.Color.HSVToColor(hsv);
}
@ColorInt int darkenColor20(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.6f;
return android.graphics.Color.HSVToColor(hsv);
}
} }
package foundation.e.notes.android.activity; package foundation.e.notes.android.activity;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
...@@ -21,5 +26,28 @@ public class PreferencesActivity extends AppCompatActivity { ...@@ -21,5 +26,28 @@ public class PreferencesActivity extends AppCompatActivity {
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.replace(android.R.id.content, new PreferencesFragment()) .replace(android.R.id.content, new PreferencesFragment())
.commit(); .commit();
updateAccentColor();
}
private void updateAccentColor(){
//change toolbar color
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(NotesListViewActivity.ACCENT_COLOR));
//change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkenColor(NotesListViewActivity.ACCENT_COLOR));
}
}
@ColorInt
int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return android.graphics.Color.HSVToColor(hsv);
} }
} }
...@@ -4,11 +4,16 @@ import android.app.Activity; ...@@ -4,11 +4,16 @@ import android.app.Activity;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.Menu; import android.view.Menu;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.ColorInt;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import butterknife.BindView; import butterknife.BindView;
...@@ -43,6 +48,8 @@ public class SelectSingleNoteActivity extends NotesListViewActivity { ...@@ -43,6 +48,8 @@ public class SelectSingleNoteActivity extends NotesListViewActivity {
} }
swipeRefreshLayout.setEnabled(false); swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
updateAccentColor();
} }
@Override @Override
...@@ -76,4 +83,25 @@ public class SelectSingleNoteActivity extends NotesListViewActivity { ...@@ -76,4 +83,25 @@ public class SelectSingleNoteActivity extends NotesListViewActivity {
getApplicationContext().sendBroadcast(updateIntent); getApplicationContext().sendBroadcast(updateIntent);
finish(); finish();
} }
private void updateAccentColor(){
//change toolbar color
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(NotesListViewActivity.ACCENT_COLOR));
//change status bar color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(darkenColor(NotesListViewActivity.ACCENT_COLOR));
}
}
@ColorInt
int darkenColor(@ColorInt int color) {
float[] hsv = new float[3];
android.graphics.Color.colorToHSV(color, hsv);
hsv[2] *= 0.8f;
return android.graphics.Color.HSVToColor(hsv);
}
} }
...@@ -2,6 +2,7 @@ package foundation.e.notes.android.activity; ...@@ -2,6 +2,7 @@ package foundation.e.notes.android.activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.http.SslCertificate; import android.net.http.SslCertificate;
import android.net.http.SslError; import android.net.http.SslError;
...@@ -15,6 +16,8 @@ import android.text.TextWatcher; ...@@ -15,6 +16,8 @@ import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.SslErrorHandler; import android.webkit.SslErrorHandler;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
...@@ -35,6 +38,8 @@ import foundation.e.notes.persistence.NoteServerSyncHelper; ...@@ -35,6 +38,8 @@ import foundation.e.notes.persistence.NoteServerSyncHelper;
import foundation.e.notes.util.ExceptionHandler; import foundation.e.notes.util.ExceptionHandler;
import foundation.e.notes.util.NotesClientUtil; import foundation.e.notes.util.NotesClientUtil;
import foundation.e.notes.util.NotesClientUtil.LoginStatus;