Quick change colors
This commit is contained in:
parent
441d66cf97
commit
798b05ad3d
|
@ -74,5 +74,6 @@ dependencies {
|
|||
implementation 'com.github.stom79:mytransl:1.5'
|
||||
implementation "com.koushikdutta.async:androidasync:2.+"
|
||||
implementation 'com.vanniktech:emoji-one:0.6.0-SNAPSHOT'
|
||||
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
|
||||
playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion"
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
@ -118,6 +119,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayScheduledTootsFragment;
|
|||
import fr.gouv.etalab.mastodon.fragments.WhoToFollowFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.helper.MenuFloating;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnFilterActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiAccountInterface;
|
||||
|
@ -204,6 +206,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
private PopupMenu popup;
|
||||
private String instance_id;
|
||||
private int style;
|
||||
private Activity activity;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -240,7 +243,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
activity = this;
|
||||
rateThisApp();
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
@ -1335,7 +1338,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
updateHeaderAccountInfo(BaseMainActivity.this, account, headerLayout);
|
||||
MenuFloating.tags = new ArrayList<>();
|
||||
updateHeaderAccountInfo(activity, account, headerLayout);
|
||||
//Locked account can see follow request
|
||||
if (account.isLocked()) {
|
||||
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);
|
||||
|
@ -2111,7 +2115,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}else {
|
||||
SQLiteDatabase db = Sqlite.getInstance(BaseMainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||
updateHeaderAccountInfo(BaseMainActivity.this, account, headerLayout);
|
||||
updateHeaderAccountInfo(activity, account, headerLayout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.provider.MediaStore;
|
|||
import android.provider.OpenableColumns;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.media.ExifInterface;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
@ -114,6 +115,9 @@ import com.bumptech.glide.request.target.Target;
|
|||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
|
||||
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionMenu;
|
||||
import com.oguzdev.circularfloatingactionmenu.library.SubActionButton;
|
||||
|
||||
import org.conscrypt.Conscrypt;
|
||||
|
||||
|
@ -1333,11 +1337,122 @@ public class Helper {
|
|||
* @param account Account - new account in use
|
||||
* @param headerLayout View - the menu header
|
||||
*/
|
||||
public static void updateHeaderAccountInfo(final Activity activity, final Account account, final View headerLayout){
|
||||
public static void updateHeaderAccountInfo(Activity activity, final Account account, final View headerLayout){
|
||||
ImageView profilePicture = headerLayout.findViewById(R.id.profilePicture);
|
||||
|
||||
TextView username = headerLayout.findViewById(R.id.username);
|
||||
TextView displayedName = headerLayout.findViewById(R.id.displayedName);
|
||||
LinearLayout more_option_container = headerLayout.findViewById(R.id.more_option_container);
|
||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
ImageView icon = new ImageView(activity);
|
||||
|
||||
|
||||
FloatingActionButton.LayoutParams layoutparmans = new FloatingActionButton.LayoutParams((int)Helper.convertDpToPixel(35,activity),(int)Helper.convertDpToPixel(35,activity));
|
||||
FloatingActionButton.LayoutParams layoutparmanImg = new FloatingActionButton.LayoutParams((int)Helper.convertDpToPixel(25,activity),(int)Helper.convertDpToPixel(25,activity));
|
||||
layoutparmans.setMargins((int)Helper.convertDpToPixel(20, activity),0,0,0);
|
||||
MenuFloating actionButton = null;
|
||||
if( theme == THEME_LIGHT) {
|
||||
icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush));
|
||||
actionButton = new MenuFloating.Builder(activity)
|
||||
.setContentView(icon, layoutparmanImg)
|
||||
.setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular))
|
||||
.setLayoutParams(layoutparmans)
|
||||
.setTag("THEME")
|
||||
.intoView(more_option_container)
|
||||
.build();
|
||||
}else if( theme == THEME_DARK) {
|
||||
icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
|
||||
actionButton = new MenuFloating.Builder(activity)
|
||||
.setContentView(icon, layoutparmanImg)
|
||||
.setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_dark))
|
||||
.setLayoutParams(layoutparmans)
|
||||
.setTag("THEME")
|
||||
.intoView(more_option_container)
|
||||
.build();
|
||||
}else if( theme == THEME_BLACK) {
|
||||
icon.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
|
||||
actionButton = new MenuFloating.Builder(activity)
|
||||
.setContentView(icon, layoutparmanImg)
|
||||
.setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_black))
|
||||
.setLayoutParams(layoutparmans)
|
||||
.setTag("THEME")
|
||||
.intoView(more_option_container)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
SubActionButton.Builder itemBuilder = new SubActionButton.Builder(activity);
|
||||
|
||||
// repeat many times:
|
||||
ImageView itemIconLight = new ImageView(activity);
|
||||
itemIconLight.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush));
|
||||
SubActionButton buttonLight = itemBuilder
|
||||
.setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular))
|
||||
.setContentView(itemIconLight).build();
|
||||
|
||||
|
||||
ImageView itemDark = new ImageView(activity);
|
||||
itemDark.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
|
||||
SubActionButton buttonDark = itemBuilder
|
||||
.setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_dark))
|
||||
.setContentView(itemDark).build();
|
||||
|
||||
ImageView itemBlack = new ImageView(activity);
|
||||
itemBlack.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_brush_white));
|
||||
SubActionButton buttonBlack = itemBuilder
|
||||
.setBackgroundDrawable(activity.getResources().getDrawable( R.drawable.circular_black))
|
||||
.setContentView(itemBlack).build();
|
||||
|
||||
FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(activity)
|
||||
.addSubActionView(buttonLight)
|
||||
.addSubActionView(buttonDark)
|
||||
.addSubActionView(buttonBlack)
|
||||
.attachTo(actionButton)
|
||||
.setStartAngle(0)
|
||||
.setEndAngle(90)
|
||||
.build();
|
||||
|
||||
buttonLight.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
actionMenu.close(true);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putInt(Helper.SET_THEME, Helper.THEME_LIGHT);
|
||||
editor.apply();
|
||||
activity.recreate();
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.finish();
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
buttonDark.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
actionMenu.close(true);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
editor.apply();
|
||||
activity.recreate();
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.finish();
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
buttonBlack.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
actionMenu.close(true);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putInt(Helper.SET_THEME, Helper.THEME_BLACK);
|
||||
editor.apply();
|
||||
activity.recreate();
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.finish();
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
if( account == null ) {
|
||||
Helper.logout(activity);
|
||||
Intent myIntent = new Intent(activity, LoginActivity.class);
|
||||
|
@ -1360,8 +1475,6 @@ public class Helper {
|
|||
urlHeader = Helper.getLiveInstanceWithProtocol(activity) + account.getHeader();
|
||||
}
|
||||
LinearLayout main_header_container = headerLayout.findViewById(R.id.main_header_container);
|
||||
final SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
if( theme == Helper.THEME_LIGHT){
|
||||
main_header_container.setBackgroundDrawable( activity.getResources().getDrawable(R.drawable.side_nav_bar_dark));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package fr.gouv.etalab.mastodon.helper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
|
||||
import com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
|
||||
public class MenuFloating extends com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton {
|
||||
|
||||
public static List<String> tags;
|
||||
|
||||
public MenuFloating(Activity activity, LayoutParams layoutParams, int theme, Drawable backgroundDrawable, int position, View contentView, FrameLayout.LayoutParams contentParams, View attachedTo, String tag) {
|
||||
super(activity, layoutParams, theme, backgroundDrawable, position, null, contentParams);
|
||||
super.detach();
|
||||
setPosition(position, layoutParams);
|
||||
// If no custom backgroundDrawable is specified, use the background drawable of the theme.
|
||||
if(backgroundDrawable == null) {
|
||||
if(theme == THEME_LIGHT)
|
||||
backgroundDrawable = activity.getResources().getDrawable(R.drawable.button_action_selector);
|
||||
else
|
||||
backgroundDrawable = activity.getResources().getDrawable(R.drawable.button_action_dark_selector);
|
||||
}
|
||||
setBackgroundResource(backgroundDrawable);
|
||||
|
||||
if(tags == null || !tags.contains(tag)) {
|
||||
if( tags == null)
|
||||
tags = new ArrayList<>();
|
||||
if (contentView != null) {
|
||||
setContentView(contentView, contentParams);
|
||||
}
|
||||
setClickable(true);
|
||||
attach(attachedTo, layoutParams);
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attaches it to the content view with specified LayoutParams.
|
||||
* @param layoutParams
|
||||
*/
|
||||
public void attach(View view, ViewGroup.LayoutParams layoutParams) {
|
||||
if(this.getParent()!=null)
|
||||
((ViewGroup)this.getParent()).removeView(this);
|
||||
((ViewGroup)view).addView(this, layoutParams);
|
||||
}
|
||||
|
||||
private void setBackgroundResource(Drawable drawable) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
setBackground(drawable);
|
||||
}
|
||||
else {
|
||||
setBackgroundDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder for {@link MenuFloating} in conventional Java Builder format
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
private Activity activity;
|
||||
private FloatingActionButton.LayoutParams layoutParams;
|
||||
private int theme;
|
||||
private Drawable backgroundDrawable;
|
||||
private int position;
|
||||
private View contentView;
|
||||
private LayoutParams contentParams;
|
||||
private View targetedView;
|
||||
private String tag;
|
||||
|
||||
public Builder(Activity activity) {
|
||||
this.activity = activity;
|
||||
|
||||
// Default MenuFloating settings
|
||||
int size = activity.getResources().getDimensionPixelSize(R.dimen.action_button_size);
|
||||
int margin = activity.getResources().getDimensionPixelSize(R.dimen.action_button_margin);
|
||||
FloatingActionButton.LayoutParams layoutParams = new LayoutParams(size, size, Gravity.BOTTOM | Gravity.RIGHT);
|
||||
layoutParams.setMargins(margin, margin, margin, margin);
|
||||
setLayoutParams(layoutParams);
|
||||
setTheme(FloatingActionButton.THEME_LIGHT);
|
||||
setPosition(FloatingActionButton.POSITION_BOTTOM_RIGHT);
|
||||
}
|
||||
|
||||
public Builder intoView(View view){
|
||||
this.targetedView = view;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLayoutParams(FloatingActionButton.LayoutParams params) {
|
||||
this.layoutParams = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTheme(int theme) {
|
||||
this.theme = theme;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBackgroundDrawable(Drawable backgroundDrawable) {
|
||||
this.backgroundDrawable = backgroundDrawable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBackgroundDrawable(int drawableId) {
|
||||
return setBackgroundDrawable(activity.getResources().getDrawable(drawableId));
|
||||
}
|
||||
|
||||
public Builder setPosition(int position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setContentView(View contentView) {
|
||||
return setContentView(contentView, null);
|
||||
}
|
||||
|
||||
public Builder setContentView(View contentView, LayoutParams contentParams) {
|
||||
this.contentView = contentView;
|
||||
this.contentParams = contentParams;
|
||||
return this;
|
||||
}
|
||||
public Builder setTag(String tag) {
|
||||
this.tag = tag;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MenuFloating build() {
|
||||
return new MenuFloating(activity,
|
||||
layoutParams,
|
||||
theme,
|
||||
backgroundDrawable,
|
||||
position,
|
||||
contentView,
|
||||
contentParams,
|
||||
targetedView, tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M7,14c-1.66,0 -3,1.34 -3,3 0,1.31 -1.16,2 -2,2 0.92,1.22 2.49,2 4,2 2.21,0 4,-1.79 4,-4 0,-1.66 -1.34,-3 -3,-3zM20.71,4.63l-1.34,-1.34c-0.39,-0.39 -1.02,-0.39 -1.41,0L9,12.25 11.75,15l8.96,-8.96c0.39,-0.39 0.39,-1.02 0,-1.41z"/>
|
||||
</vector>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M7,14c-1.66,0 -3,1.34 -3,3 0,1.31 -1.16,2 -2,2 0.92,1.22 2.49,2 4,2 2.21,0 4,-1.79 4,-4 0,-1.66 -1.34,-3 -3,-3zM20.71,4.63l-1.34,-1.34c-0.39,-0.39 -1.02,-0.39 -1.41,0L9,12.25 11.75,15l8.96,-8.96c0.39,-0.39 0.39,-1.02 0,-1.41z"/>
|
||||
</vector>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
android:shape="oval"
|
||||
android:thicknessRatio="1.9"
|
||||
android:useLevel="false" >
|
||||
<solid android:color="@color/white" />
|
||||
|
||||
<stroke
|
||||
android:width="10dp"
|
||||
android:color="@android:color/white" />
|
||||
</shape>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
android:shape="oval"
|
||||
android:thicknessRatio="1.9"
|
||||
android:useLevel="false" >
|
||||
<solid android:color="@color/black" />
|
||||
|
||||
<stroke
|
||||
android:width="10dp"
|
||||
android:color="@android:color/black" />
|
||||
</shape>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
android:shape="oval"
|
||||
android:thicknessRatio="1.9"
|
||||
android:useLevel="false" >
|
||||
<solid android:color="@color/notif_dark_3" />
|
||||
|
||||
<stroke
|
||||
android:width="10dp"
|
||||
android:color="@color/notif_dark_3" />
|
||||
</shape>
|
|
@ -50,10 +50,13 @@
|
|||
android:layout_height="60dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:id="@+id/more_option_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="UselessLeaf" />
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UselessLeaf" >
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:gravity="center_vertical|end"
|
||||
android:src="@drawable/ic_more_vert"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
|
|
Loading…
Reference in New Issue