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 Apr 9, 2024
1 parent 3f10969 commit 5b88488
Show file tree
Hide file tree
Showing 24 changed files with 370 additions and 119 deletions.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,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:configChanges="orientation|screenLayout|screenSize|keyboardHidden"
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 @@ -58,6 +58,7 @@
import com.nextcloud.ui.ChooseAccountDialogFragment;
import com.nextcloud.ui.composeActivity.ComposeActivity;
import com.nextcloud.ui.composeActivity.ComposeDestination;
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 @@ -269,8 +270,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 @@ -18,6 +18,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 @@ -30,13 +31,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 @@ -21,6 +21,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 @@ -861,12 +862,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 @@ -92,8 +92,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 @@ -17,6 +17,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 @@ -31,9 +32,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 @@ -62,6 +65,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 @@ -82,6 +86,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 @@ -98,8 +103,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 @@ -146,22 +153,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 @@ -174,7 +170,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 @@ -271,8 +268,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 @@ -85,7 +85,6 @@ public class PreviewImageActivity extends FileActivity implements
private boolean requestWaitingForBinder;
private DownloadFinishReceiver downloadFinishReceiver;
private UploadFinishReceiver uploadFinishReceiver;
private View fullScreenAnchorView;
private boolean isDownloadWorkStarted = false;

@Inject AppPreferences preferences;
Expand All @@ -112,6 +111,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 @@ -126,7 +126,6 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

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

Expand Down Expand Up @@ -246,7 +245,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 @@ -393,9 +392,7 @@ public void onPageSelected(int position) {
OCFile currentFile = previewImagePagerAdapter.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 @@ -493,22 +490,7 @@ public boolean isSystemUIVisible() {
}

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

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

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

public void startImageEditor(OCFile file) {
Expand All @@ -532,26 +514,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.
);
}
}
Loading

0 comments on commit 5b88488

Please sign in to comment.