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 Jun 26, 2024
1 parent 0a642ee commit e8dba1a
Show file tree
Hide file tree
Showing 24 changed files with 374 additions and 138 deletions.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,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 @@ -59,6 +59,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 @@ -271,8 +272,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 @@ -162,22 +169,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 @@ -190,7 +186,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 @@ -287,8 +284,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 @@ -17,12 +17,8 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import androidx.appcompat.app.ActionBar
import androidx.drawerlayout.widget.DrawerLayout
import androidx.localbroadcastmanager.content.LocalBroadcastManager
Expand Down Expand Up @@ -73,7 +69,6 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
private var hasSavedPosition = false
private var requestWaitingForBinder = false
private var downloadFinishReceiver: DownloadFinishReceiver? = null
private var fullScreenAnchorView: View? = null
private var isDownloadWorkStarted = false

@Inject
Expand All @@ -98,6 +93,7 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
}

setContentView(R.layout.preview_image_activity)
setupToolbar()

livePhotoFile = intent.getParcelableArgument(EXTRA_LIVE_PHOTO_FILE, OCFile::class.java)

Expand All @@ -111,7 +107,6 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
actionBar?.setDisplayHomeAsUpEnabled(true)
}

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

Expand Down Expand Up @@ -227,7 +222,8 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
if (file != null) {
// / Refresh the activity according to the Account and OCFile set
setFile(file) // reset after getting it fresh from storageManager
updateActionBarTitle(getFile().fileName)
// NMC Customization
updateActionBarTitleAndHomeButton(getFile())
// if (!stateWasRecovered) {
initViewPager(optionalUser.get())

Expand Down Expand Up @@ -371,15 +367,12 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
}

if (currentFile != null) {
updateActionBarTitle(currentFile.fileName)
// NMC Customization
updateActionBarTitleAndHomeButton(currentFile)
setDrawerIndicatorEnabled(false)
}
}

private fun updateActionBarTitle(title: String?) {
supportActionBar?.title = title
}

/**
* Class waiting for broadcast events from the [FileDownloadWorker] service.
*
Expand Down Expand Up @@ -442,17 +435,7 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
get() = supportActionBar == null || supportActionBar?.isShowing == true

fun toggleFullScreen() {
if (fullScreenAnchorView == null) return
val visible = (
fullScreenAnchorView!!.systemUiVisibility
and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
) == 0

if (visible) {
hideSystemUI(fullScreenAnchorView!!)
} else {
showSystemUI(fullScreenAnchorView!!)
}
// do nothing for NMC
}

fun startImageEditor(file: OCFile) {
Expand All @@ -473,44 +456,6 @@ class PreviewImageActivity : FileActivity(), FileFragment.ContainerActivity, OnR
// TODO Auto-generated method stub
}

private fun hideSystemUI(anchorView: View) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.let { controller ->
controller.hide(WindowInsets.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
@Suppress("DEPRECATION")
anchorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hides NAVIGATION BAR; Android >= 4.0
or View.SYSTEM_UI_FLAG_FULLSCREEN // hides STATUS BAR; Android >= 4.1
or View.SYSTEM_UI_FLAG_IMMERSIVE // stays interactive; Android >= 4.4
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE // draw full window; Android >= 4.1
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // draw full window; Android >= 4.1
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
)
}
}

private fun showSystemUI(anchorView: View) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.let { controller ->
controller.show(WindowInsets.Type.systemBars())

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
controller.systemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT
}
}
} else {
@Suppress("DEPRECATION")
anchorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE // draw full window; Android >= 4.1
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // draw full window; Android >= 4.1
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
)
}
}

companion object {
val TAG: String = PreviewImageActivity::class.java.simpleName
const val EXTRA_VIRTUAL_TYPE: String = "EXTRA_VIRTUAL_TYPE"
Expand Down
Loading

0 comments on commit e8dba1a

Please sign in to comment.