Skip to content

Commit

Permalink
Customized theme of toolbar and action mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Feb 14, 2024
1 parent f59caa7 commit fc2bb76
Show file tree
Hide file tree
Showing 19 changed files with 342 additions and 102 deletions.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@
<activity
android:name=".ui.activity.SettingsActivity"
android:exported="false"
android:theme="@style/PreferenceTheme" />
android:theme="@style/Theme.ownCloud" />
<activity
android:name=".ui.preview.PreviewImageActivity"
android:exported="false"
android:theme="@style/Theme.ownCloud.Overlay" />
android:exported="false" />
<activity
android:name=".ui.preview.PreviewMediaActivity"
android:exported="false"
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/nmc/android/utils/DrawableThemeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nmc.android.utils

import android.graphics.drawable.Drawable
import androidx.annotation.ColorInt
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import androidx.core.graphics.drawable.DrawableCompat

object DrawableThemeUtils {
@JvmStatic
fun tintDrawable(drawable: Drawable, @ColorInt color: Int): Drawable {
val wrap: Drawable = DrawableCompat.wrap(drawable)
wrap.colorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
color, BlendModeCompat.SRC_ATOP
)
return wrap
}
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/nmc/android/utils/ToolbarThemeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.nmc.android.utils

import android.content.Context
import android.graphics.Typeface
import android.text.Spannable
import android.text.style.StyleSpan
import androidx.appcompat.app.ActionBar
import com.owncloud.android.R
import com.owncloud.android.utils.StringUtils

object ToolbarThemeUtils {
@JvmStatic
fun setColoredTitle(context: Context, actionBar: ActionBar?, title: String) {
if (actionBar != null) {
val text: Spannable = StringUtils.getColorSpan(title, context.resources.getColor(R.color.fontAppbar, null))

//bold the magenta from MagentaCLOUD title
if (title.contains(context.resources.getString(R.string.app_name))) {
val textToBold = context.resources.getString(R.string.splashScreenBold)
val indexStart = title.indexOf(textToBold)
val indexEnd = indexStart + textToBold.length
text.setSpan(StyleSpan(Typeface.BOLD), indexStart, indexEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
actionBar.title = text
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.java.util.Optional;
import com.nextcloud.ui.ChooseAccountDialogFragment;
import com.nmc.android.utils.DrawableThemeUtils;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.PassCodeManager;
Expand Down Expand Up @@ -283,8 +284,11 @@ public void onDrawerOpened(View drawerView) {
Drawable backArrow = ResourcesCompat.getDrawable(getResources(),
R.drawable.ic_arrow_back,
null);

viewThemeUtils.platform.tintToolbarArrowDrawable(this, mDrawerToggle, backArrow);
// custom color for back arrow required for NMC
if (backArrow != null) {
mDrawerToggle.setHomeAsUpIndicator(DrawableThemeUtils.tintDrawable(backArrow, getResources().getColor(R.color.fontAppbar, null)));
mDrawerToggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.fontAppbar, null));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.nextcloud.client.di.Injectable
import com.nextcloud.client.preferences.AppPreferences
import com.owncloud.android.R
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.utils.theme.ViewThemeUtils
import java.io.File
import javax.inject.Inject
import kotlin.system.exitProcess
Expand All @@ -43,13 +44,17 @@ class ManageSpaceActivity : AppCompatActivity(), Injectable {
@Inject
lateinit var userAccountManager: UserAccountManager

@Inject
lateinit var viewThemeUtils: ViewThemeUtils

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_manage_space)
val actionBar = supportActionBar
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true)
actionBar.setTitle(R.string.manage_space_title)
//NMC Customisation
viewThemeUtils.files.themeActionBar(this, actionBar, R.string.manage_space_title)
}
val descriptionTextView = findViewById<TextView>(R.id.general_description)
descriptionTextView.text = getString(R.string.manage_space_description, getString(R.string.app_name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
Expand Down Expand Up @@ -874,12 +875,10 @@ private void setupActionBar() {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
if (this.getResources() != null) {
viewThemeUtils.androidx.themeActionBar(this,
actionBar,
getString(R.string.actionbar_settings),
ResourcesCompat.getDrawable(this.getResources(),
R.drawable.ic_arrow_back,
null));
//custom color for back arrow for NMC
viewThemeUtils.files.themeActionBar(this, actionBar, getResources().getString(R.string.actionbar_settings));
//required for NMC
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.bg_default, null)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ protected void onCreate(Bundle savedInstanceState) {
// Name
binding.shareFileName.setText(getResources().getString(R.string.share_file, file.getFileName()));

viewThemeUtils.platform.colorViewBackground(binding.shareHeaderDivider);

// Size
binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.FrameLayout;
Expand All @@ -42,9 +43,11 @@
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.textview.MaterialTextView;
import com.nextcloud.client.di.Injectable;
import com.nmc.android.utils.ToolbarThemeUtils;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.utils.StringUtils;
import com.owncloud.android.utils.theme.ThemeColorUtils;
import com.owncloud.android.utils.theme.ThemeUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;
Expand Down Expand Up @@ -73,6 +76,7 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable
private LinearLayout mInfoBox;
private TextView mInfoBoxMessage;
protected AppCompatSpinner mToolbarSpinner;
private View mDefaultToolbarDivider;
private boolean isHomeSearchToolbarShow = false;

@Inject public ThemeColorUtils themeColorUtils;
Expand All @@ -93,6 +97,7 @@ private void setupToolbar(boolean isHomeSearchToolbarShow, boolean showSortListB
mMenuButton = findViewById(R.id.menu_button);
mSearchText = findViewById(R.id.search_text);
mSwitchAccountButton = findViewById(R.id.switch_account_button);
mDefaultToolbarDivider = findViewById(R.id.default_toolbar_divider);

if (showSortListButtonGroup) {
findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE);
Expand All @@ -109,8 +114,10 @@ private void setupToolbar(boolean isHomeSearchToolbarShow, boolean showSortListB

mToolbarSpinner = findViewById(R.id.toolbar_spinner);

viewThemeUtils.material.themeToolbar(mToolbar);
viewThemeUtils.material.colorToolbarOverflowIcon(mToolbar);
// custom color for overflow icon required for NMC
if (mToolbar.getOverflowIcon() != null) {
mToolbar.getOverflowIcon().setColorFilter(getResources().getColor(R.color.fontAppbar, null), PorterDuff.Mode.SRC_ATOP);
}
viewThemeUtils.platform.themeStatusBar(this);
viewThemeUtils.material.colorMaterialTextButton(mSwitchAccountButton);
}
Expand Down Expand Up @@ -157,22 +164,11 @@ private void showHomeSearchToolbar(String title, boolean isRoot) {

@SuppressLint("PrivateResource")
private void showHomeSearchToolbar(boolean isShow) {
viewThemeUtils.material.themeToolbar(mToolbar);
if (isShow) {
viewThemeUtils.platform.resetStatusBar(this);
mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(),
R.animator.appbar_elevation_off));
mDefaultToolbar.setVisibility(View.GONE);
mHomeSearchToolbar.setVisibility(View.VISIBLE);
viewThemeUtils.material.themeCardView(mHomeSearchToolbar);
viewThemeUtils.material.themeSearchBarText(mSearchText);
} else {
mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(),
R.animator.appbar_elevation_on));
viewThemeUtils.platform.themeStatusBar(this);
mDefaultToolbar.setVisibility(View.VISIBLE);
mHomeSearchToolbar.setVisibility(View.GONE);
}
mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(),
R.animator.appbar_elevation_on));
viewThemeUtils.platform.themeStatusBar(this);
mDefaultToolbar.setVisibility(View.VISIBLE);
mHomeSearchToolbar.setVisibility(View.GONE);
}

/**
Expand All @@ -185,7 +181,8 @@ public void updateActionBarTitleAndHomeButtonByString(String title) {
// set home button properties
if (actionBar != null) {
if (title != null) {
actionBar.setTitle(title);
//custom styling for action bar title required for NMC
ToolbarThemeUtils.setColoredTitle(this, actionBar, title);
actionBar.setDisplayShowTitleEnabled(true);
} else {
actionBar.setDisplayShowTitleEnabled(false);
Expand Down Expand Up @@ -282,8 +279,8 @@ public FrameLayout getPreviewImageContainer() {
public void updateToolbarSubtitle(@NonNull String subtitle) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setSubtitle(subtitle);
viewThemeUtils.androidx.themeActionBarSubtitle(this, actionBar);
//required for NMC
actionBar.setSubtitle(StringUtils.getColorSpan(subtitle, getResources().getColor(R.color.fontAppbar, null)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public class PreviewImageActivity extends FileActivity implements
private boolean mRequestWaitingForBinder;
private DownloadFinishReceiver mDownloadFinishReceiver;
private UploadFinishReceiver mUploadFinishReceiver;
private View mFullScreenAnchorView;
private boolean isDownloadWorkStarted = false;

@Inject AppPreferences preferences;
Expand All @@ -123,6 +122,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

setContentView(R.layout.preview_image_activity);
setupToolbar();

livePhotoFile = IntentExtensionsKt.getParcelableArgument(getIntent(), EXTRA_LIVE_PHOTO_FILE, OCFile.class);

Expand All @@ -137,7 +137,6 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

mFullScreenAnchorView = getWindow().getDecorView();
// to keep our UI controls visibility in line with system bars visibility
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

Expand Down Expand Up @@ -257,7 +256,7 @@ public void onStart() {
if (file != null) {
/// Refresh the activity according to the Account and OCFile set
setFile(file); // reset after getting it fresh from storageManager
getSupportActionBar().setTitle(getFile().getFileName());
updateActionBarTitleAndHomeButton(getFile());
//if (!stateWasRecovered) {
initViewPager(optionalUser.get());
//}
Expand Down Expand Up @@ -404,9 +403,7 @@ public void onPageSelected(int position) {
OCFile currentFile = mPreviewImagePagerAdapter.getFileAt(position);

if (currentFile != null) {
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(currentFile.getFileName());
}
updateActionBarTitleAndHomeButton(currentFile);
setDrawerIndicatorEnabled(false);

if (currentFile.isEncrypted() && !currentFile.isDown() &&
Expand Down Expand Up @@ -504,22 +501,7 @@ public boolean isSystemUIVisible() {
}

public void toggleFullScreen() {
boolean visible = (mFullScreenAnchorView.getSystemUiVisibility()
& View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;

if (visible) {
hideSystemUI(mFullScreenAnchorView);
// actionBar.hide(); // propagated through
// OnSystemUiVisibilityChangeListener()
} else {
showSystemUI(mFullScreenAnchorView);
// actionBar.show(); // propagated through
// OnSystemUiVisibilityChangeListener()
}
}

public void switchToFullScreen() {
hideSystemUI(mFullScreenAnchorView);
// do nothing for NMC
}

public void startImageEditor(OCFile file) {
Expand All @@ -543,26 +525,4 @@ public void onTransferStateChanged(OCFile file, boolean downloading, boolean upl
// TODO Auto-generated method stub

}


@SuppressLint("InlinedApi")
private void hideSystemUI(View anchorView) {
anchorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hides NAVIGATION BAR; Android >= 4.0
| View.SYSTEM_UI_FLAG_FULLSCREEN // hides STATUS BAR; Android >= 4.1
| View.SYSTEM_UI_FLAG_IMMERSIVE // stays interactive; Android >= 4.4
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE // draw full window; Android >= 4.1
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // draw full window; Android >= 4.1
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // draw full window; Android >= 4.1
);
}

@SuppressLint("InlinedApi")
private void showSystemUI(View anchorView) {
anchorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE // draw full window; Android >= 4.1
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // draw full window; Android >= 4.1
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // draw full window; Android >= 4.
);
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/owncloud/android/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
package com.owncloud.android.utils;


import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -69,6 +73,15 @@ String searchAndColor(@Nullable String text, @Nullable String searchText,
}
}

public static Spannable getColorSpan(@NonNull String title, @ColorInt int color) {
Spannable text = new SpannableString(title);
text.setSpan(new ForegroundColorSpan(color),
0,
text.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return text;
}

public static
@NonNull
String removePrefix(@NonNull String s, @NonNull String prefix) {
Expand Down
Loading

0 comments on commit fc2bb76

Please sign in to comment.