Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-client-android
Commits
53357790
Commit
53357790
authored
Feb 25, 2021
by
Adrien Béraud
Committed by
Sébastien Blin
Jun 11, 2021
Browse files
refresh conversation details
Change-Id: Ic77b0b89f76f2eed0e9fe37db42a4f78cb5b245f
parent
1c2d95b8
Changes
20
Expand all
Hide whitespace changes
Inline
Side-by-side
ring-android/app/src/main/AndroidManifest.xml
View file @
53357790
...
...
@@ -422,7 +422,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:label=
"@string/conversation_details"
android:icon=
"@mipmap/ic_launcher"
android:resizeableActivity=
"true"
android:theme=
"@style/AppTheme.
DarkToolbar
"
android:theme=
"@style/AppTheme.
Fullscreen
"
android:windowSoftInputMode=
"adjustResize"
/>
<activity
android:name=
".client.ConversationSelectionActivity"
...
...
ring-android/app/src/main/java/cx/ring/client/ContactDetailsActivity.java
View file @
53357790
This diff is collapsed.
Click to expand it.
ring-android/app/src/main/java/cx/ring/client/ConversationActivity.java
View file @
53357790
...
...
@@ -46,14 +46,11 @@ public class ConversationActivity extends AppCompatActivity implements Colorable
private
Intent
mPendingIntent
=
null
;
private
ActivityConversationBinding
binding
;
private
boolean
mIsBubble
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
Intent
intent
=
getIntent
();
String
action
=
intent
==
null
?
null
:
intent
.
getAction
();
if
(
intent
!=
null
)
{
conversationPath
=
ConversationPath
.
fromIntent
(
intent
);
}
else
if
(
savedInstanceState
!=
null
)
{
...
...
@@ -63,7 +60,7 @@ public class ConversationActivity extends AppCompatActivity implements Colorable
finish
();
return
;
}
mI
sBubble
=
getIntent
().
getBooleanExtra
(
NotificationServiceImpl
.
EXTRA_BUBBLE
,
false
);
boolean
i
sBubble
=
getIntent
().
getBooleanExtra
(
NotificationServiceImpl
.
EXTRA_BUBBLE
,
false
);
JamiApplication
.
getInstance
().
startDaemon
();
binding
=
ActivityConversationBinding
.
inflate
(
getLayoutInflater
());
...
...
@@ -74,9 +71,14 @@ public class ConversationActivity extends AppCompatActivity implements Colorable
if
(
ab
!=
null
)
ab
.
setDisplayHomeAsUpEnabled
(
true
);
binding
.
contactImage
.
setOnClickListener
(
v
->
{
if
(
mConversationFragment
!=
null
)
mConversationFragment
.
openContact
();
});
if
(
mConversationFragment
==
null
)
{
Bundle
bundle
=
conversationPath
.
toBundle
();
bundle
.
putBoolean
(
NotificationServiceImpl
.
EXTRA_BUBBLE
,
mI
sBubble
);
bundle
.
putBoolean
(
NotificationServiceImpl
.
EXTRA_BUBBLE
,
i
sBubble
);
mConversationFragment
=
new
ConversationFragment
();
mConversationFragment
.
setArguments
(
bundle
);
...
...
ring-android/app/src/main/java/cx/ring/client/HomeActivity.java
View file @
53357790
...
...
@@ -147,8 +147,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
private
final
CompositeDisposable
mDisposable
=
new
CompositeDisposable
();
private
boolean
conversationSelected
=
false
;
/* called before activity is killed, e.g. rotation */
@Override
protected
void
onSaveInstanceState
(
@NonNull
Bundle
bundle
)
{
...
...
@@ -191,6 +189,14 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
mBinding
.
spinnerToolbar
.
setOnItemSelectedListener
(
this
);
mBinding
.
accountSwitch
.
setOnCheckedChangeListener
((
buttonView
,
isChecked
)
->
enableAccount
(
isChecked
));
if
(
mBinding
.
contactImage
!=
null
)
{
mBinding
.
contactImage
.
setOnClickListener
(
v
->
{
if
(
fConversation
!=
null
)
{
fConversation
.
openContact
();
}
});
}
// if app opened from notification display trust request fragment when mService will connected
Intent
intent
=
getIntent
();
Bundle
extra
=
intent
.
getExtras
();
...
...
@@ -375,7 +381,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
if
(
DeviceUtils
.
isTablet
(
this
))
{
selectNavigationItem
(
R
.
id
.
navigation_home
);
showTabletToolbar
();
conversationSelected
=
true
;
}
}
}
...
...
@@ -405,14 +410,13 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
fConversation
=
new
ConversationFragment
();
fConversation
.
setArguments
(
bundle
);
//getSupportFragmentManager().get
if
(!(
fContent
instanceof
ContactRequestsFragment
))
{
selectNavigationItem
(
R
.
id
.
navigation_home
);
}
showTabletToolbar
();
conversationSelected
=
true
;
getSupportFragmentManager
()
.
beginTransaction
()
.
replace
(
R
.
id
.
conversation_container
,
fConversation
,
ConversationFragment
.
class
.
getSimpleName
())
...
...
@@ -457,7 +461,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
for
(
int
i
=
0
;
i
<
entryCount
;
++
i
)
{
fragmentManager
.
popBackStack
();
}
fContent
=
fragmentManager
.
findFragmentById
(
R
.
id
.
main_frame
);
//
fContent = fragmentManager.findFragmentById(R.id.main_frame);
hideTabletToolbar
();
setToolbarElevation
(
false
);
}
...
...
@@ -523,7 +527,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
.
setReorderingAllowed
(
true
)
.
addToBackStack
(
CONTACT_REQUESTS_TAG
)
.
commit
();
conversationSelected
=
false
;
showProfileInfo
();
showToolbarSpinner
();
break
;
...
...
@@ -538,7 +541,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
.
replace
(
R
.
id
.
main_frame
,
fContent
,
HOME_TAG
)
.
setReorderingAllowed
(
true
)
.
commit
();
conversationSelected
=
false
;
showProfileInfo
();
showToolbarSpinner
();
break
;
...
...
@@ -566,7 +568,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
.
replace
(
getFragmentContainerId
(),
fContent
,
ACCOUNTS_TAG
)
.
addToBackStack
(
ACCOUNTS_TAG
)
.
commit
();
conversationSelected
=
false
;
showProfileInfo
();
showToolbarSpinner
();
break
;
...
...
@@ -614,7 +615,7 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
}
private
void
hideTabletToolbar
()
{
if
(
mBinding
!=
null
)
{
if
(
mBinding
!=
null
&&
mBinding
.
tabletToolbar
!=
null
)
{
mBinding
.
contactTitle
.
setText
(
null
);
mBinding
.
contactSubtitle
.
setText
(
null
);
mBinding
.
contactImage
.
setImageDrawable
(
null
);
...
...
@@ -623,17 +624,19 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
}
private
void
showTabletToolbar
()
{
if
(
mBinding
!=
null
&&
DeviceUtils
.
isTablet
(
this
))
{
if
(
mBinding
!=
null
&&
mBinding
.
tabletToolbar
!=
null
&&
DeviceUtils
.
isTablet
(
this
))
{
mBinding
.
tabletToolbar
.
setVisibility
(
View
.
VISIBLE
);
}
}
public
void
setTabletTitle
(
@StringRes
int
titleRes
)
{
mBinding
.
tabletToolbar
.
setVisibility
(
View
.
VISIBLE
);
mBinding
.
contactTitle
.
setText
(
titleRes
);
mBinding
.
contactTitle
.
setTextSize
(
19
);
mBinding
.
contactTitle
.
setTypeface
(
null
,
Typeface
.
BOLD
);
mBinding
.
contactImage
.
setVisibility
(
View
.
GONE
);
if
(
mBinding
.
tabletToolbar
!=
null
)
{
mBinding
.
tabletToolbar
.
setVisibility
(
View
.
VISIBLE
);
mBinding
.
contactTitle
.
setText
(
titleRes
);
mBinding
.
contactTitle
.
setTextSize
(
19
);
mBinding
.
contactTitle
.
setTypeface
(
null
,
Typeface
.
BOLD
);
mBinding
.
contactImage
.
setVisibility
(
View
.
GONE
);
}
/*RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.contactTitle.getLayoutParams();
params.removeRule(RelativeLayout.ALIGN_TOP);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
...
...
@@ -662,10 +665,6 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
}
}
public
boolean
isConversationSelected
(){
return
conversationSelected
;
}
private
int
getFragmentContainerId
()
{
if
(
DeviceUtils
.
isTablet
(
HomeActivity
.
this
))
{
return
R
.
id
.
conversation_container
;
...
...
ring-android/app/src/main/java/cx/ring/fragments/ConversationFragment.java
View file @
53357790
...
...
@@ -24,6 +24,7 @@ import android.animation.LayoutTransition;
import
android.animation.ValueAnimator
;
import
android.annotation.SuppressLint
;
import
android.app.Activity
;
import
android.app.ActivityOptions
;
import
android.content.ActivityNotFoundException
;
import
android.content.ClipData
;
import
android.content.ComponentName
;
...
...
@@ -860,6 +861,10 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
mVideoCallBtn
=
menu
.
findItem
(
R
.
id
.
conv_action_videocall
);
}
public
void
openContact
()
{
presenter
.
openContact
();
}
@Override
public
boolean
onOptionsItemSelected
(
MenuItem
item
)
{
int
itemId
=
item
.
getItemId
();
...
...
@@ -1021,8 +1026,11 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
@Override
public
void
goToContactActivity
(
String
accountId
,
Uri
uri
)
{
Toolbar
toolbar
=
requireActivity
().
findViewById
(
R
.
id
.
main_toolbar
);
ImageView
logo
=
toolbar
.
findViewById
(
R
.
id
.
contact_image
);
startActivity
(
new
Intent
(
Intent
.
ACTION_VIEW
,
ConversationPath
.
toUri
(
accountId
,
uri
))
.
setClass
(
requireActivity
().
getApplicationContext
(),
ContactDetailsActivity
.
class
));
.
setClass
(
requireActivity
().
getApplicationContext
(),
ContactDetailsActivity
.
class
),
ActivityOptions
.
makeSceneTransitionAnimation
(
getActivity
(),
logo
,
"conversationIcon"
).
toBundle
());
}
@Override
...
...
@@ -1039,61 +1047,35 @@ public class ConversationFragment extends BaseSupportFragment<ConversationPresen
if
(!
isVisible
())
{
return
;
}
ActionBar
actionBar
=
((
AppCompatActivity
)
requireActivity
()).
getSupportActionBar
();
if
(
actionBar
==
null
)
{
return
;
}
Context
context
=
actionBar
.
getThemedContext
();
Activity
activity
=
requireActivity
();
String
displayName
=
conversation
.
getTitle
();
String
identity
=
conversation
.
getUriTitle
();
Activity
activity
=
getActivity
();
if
(
activity
instanceof
HomeActivity
)
{
Toolbar
toolbar
=
getActivity
().
findViewById
(
R
.
id
.
main_toolbar
);
TextView
title
=
toolbar
.
findViewById
(
R
.
id
.
contact_title
);
TextView
subtitle
=
toolbar
.
findViewById
(
R
.
id
.
contact_subtitle
);
ImageView
logo
=
toolbar
.
findViewById
(
R
.
id
.
contact_image
);
/*if (!((HomeActivity) activity).isConversationSelected()) {
title.setText("");
subtitle.setText("");
logo.setImageDrawable(null);
return;
}*/
logo
.
setVisibility
(
View
.
VISIBLE
);
title
.
setText
(
displayName
);
title
.
setTextSize
(
15
);
title
.
setTypeface
(
null
,
Typeface
.
NORMAL
);
if
(
identity
!=
null
&&
!
identity
.
equals
(
displayName
))
{
subtitle
.
setText
(
identity
);
RelativeLayout
.
LayoutParams
params
=
(
RelativeLayout
.
LayoutParams
)
title
.
getLayoutParams
();
params
.
addRule
(
RelativeLayout
.
ALIGN_TOP
,
R
.
id
.
contact_image
);
title
.
setLayoutParams
(
params
);
}
else
{
subtitle
.
setText
(
""
);
RelativeLayout
.
LayoutParams
params
=
(
RelativeLayout
.
LayoutParams
)
title
.
getLayoutParams
();
params
.
removeRule
(
RelativeLayout
.
ALIGN_TOP
);
params
.
addRule
(
RelativeLayout
.
CENTER_VERTICAL
,
RelativeLayout
.
TRUE
);
title
.
setLayoutParams
(
params
);
}
logo
.
setImageDrawable
(
mConversationAvatar
);
Toolbar
toolbar
=
activity
.
findViewById
(
R
.
id
.
main_toolbar
);
TextView
title
=
toolbar
.
findViewById
(
R
.
id
.
contact_title
);
TextView
subtitle
=
toolbar
.
findViewById
(
R
.
id
.
contact_subtitle
);
ImageView
logo
=
toolbar
.
findViewById
(
R
.
id
.
contact_image
);
logo
.
setImageDrawable
(
mConversationAvatar
);
logo
.
setVisibility
(
View
.
VISIBLE
);
title
.
setText
(
displayName
);
title
.
setTextSize
(
15
);
title
.
setTypeface
(
null
,
Typeface
.
NORMAL
);
if
(
identity
!=
null
&&
!
identity
.
equals
(
displayName
))
{
subtitle
.
setText
(
identity
);
subtitle
.
setVisibility
(
View
.
VISIBLE
);
/*RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) title.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_TOP, R.id.contact_image);
title.setLayoutParams(params);*/
}
else
{
if
(
identity
!=
null
&&
!
identity
.
equals
(
displayName
))
{
actionBar
.
setSubtitle
(
identity
);
}
actionBar
.
setTitle
(
displayName
);
int
targetSize
=
(
int
)
(
AvatarFactory
.
SIZE_AB
*
context
.
getResources
().
getDisplayMetrics
().
density
);
mConversationAvatar
.
setInSize
(
targetSize
);
actionBar
.
setLogo
(
null
);
actionBar
.
setLogo
(
mConversationAvatar
);
subtitle
.
setText
(
""
);
subtitle
.
setVisibility
(
View
.
GONE
);
/*RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) title.getLayoutParams();
params.removeRule(RelativeLayout.ALIGN_TOP);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
title.setLayoutParams(params);*/
}
}
...
...
ring-android/app/src/main/java/cx/ring/services/DeviceRuntimeServiceImpl.java
View file @
53357790
...
...
@@ -34,6 +34,12 @@ import android.util.Log;
import
androidx.core.content.ContextCompat
;
import
net.jami.daemon.IntVect
;
import
net.jami.daemon.StringVect
;
import
net.jami.services.DeviceRuntimeService
;
import
net.jami.utils.FileUtils
;
import
net.jami.utils.StringUtils
;
import
java.io.File
;
import
java.util.concurrent.ScheduledExecutorService
;
...
...
@@ -41,15 +47,9 @@ import javax.inject.Inject;
import
javax.inject.Named
;
import
cx.ring.application.JamiApplication
;
import
net.jami.daemon.IntVect
;
import
net.jami.daemon.StringVect
;
import
cx.ring.utils.AndroidFileUtils
;
import
cx.ring.utils.NetworkUtils
;
import
net.jami.services.DeviceRuntimeService
;
import
net.jami.utils.FileUtils
;
import
net.jami.utils.StringUtils
;
public
class
DeviceRuntimeServiceImpl
extends
DeviceRuntimeService
{
private
static
final
String
TAG
=
DeviceRuntimeServiceImpl
.
class
.
getSimpleName
();
...
...
ring-android/app/src/main/java/cx/ring/utils/ConversationPath.java
View file @
53357790
...
...
@@ -97,6 +97,9 @@ public class ConversationPath {
public
static
Bundle
toBundle
(
String
accountId
,
net
.
jami
.
model
.
Uri
uri
)
{
return
toBundle
(
accountId
,
uri
.
getUri
());
}
public
static
Bundle
toBundle
(
@NonNull
Conversation
conversation
)
{
return
toBundle
(
conversation
.
getAccountId
(),
conversation
.
getUri
());
}
public
static
String
toKey
(
String
accountId
,
String
uri
)
{
return
TextUtils
.
join
(
","
,
Arrays
.
asList
(
accountId
,
uri
));
...
...
ring-android/app/src/main/java/cx/ring/viewholders/SmartListViewHolder.java
View file @
53357790
...
...
@@ -19,19 +19,6 @@
*/
package
cx.ring.viewholders
;
import
cx.ring.R
;
import
cx.ring.databinding.ItemSmartlistBinding
;
import
cx.ring.databinding.ItemSmartlistHeaderBinding
;
import
net.jami.model.ContactEvent
;
import
net.jami.model.Interaction
;
import
net.jami.model.Call
;
import
net.jami.smartlist.SmartListViewModel
;
import
cx.ring.utils.ResourceMapper
;
import
cx.ring.views.AvatarDrawable
;
import
io.reactivex.Observable
;
import
io.reactivex.disposables.CompositeDisposable
;
import
android.content.Context
;
import
android.graphics.Typeface
;
import
android.text.format.DateUtils
;
...
...
@@ -40,12 +27,24 @@ import android.view.View;
import
androidx.annotation.NonNull
;
import
androidx.recyclerview.widget.RecyclerView
;
import
net.jami.model.Call
;
import
net.jami.model.ContactEvent
;
import
net.jami.model.Interaction
;
import
net.jami.smartlist.SmartListViewModel
;
import
java.util.concurrent.TimeUnit
;
import
cx.ring.R
;
import
cx.ring.databinding.ItemSmartlistBinding
;
import
cx.ring.databinding.ItemSmartlistHeaderBinding
;
import
cx.ring.utils.ResourceMapper
;
import
cx.ring.views.AvatarDrawable
;
import
io.reactivex.Observable
;
import
io.reactivex.disposables.CompositeDisposable
;
public
class
SmartListViewHolder
extends
RecyclerView
.
ViewHolder
{
public
final
ItemSmartlistBinding
binding
;
public
final
ItemSmartlistHeaderBinding
headerBinding
;
private
final
CompositeDisposable
compositeDisposable
=
new
CompositeDisposable
();
public
SmartListViewHolder
(
@NonNull
ItemSmartlistBinding
b
)
{
...
...
ring-android/app/src/main/java/cx/ring/views/SwitchButton.java
View file @
53357790
...
...
@@ -24,6 +24,7 @@ import android.content.res.TypedArray;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Paint
;
import
android.graphics.PointF
;
import
android.graphics.RectF
;
import
android.graphics.drawable.LayerDrawable
;
import
android.graphics.drawable.RotateDrawable
;
...
...
@@ -46,23 +47,18 @@ import androidx.core.content.res.ResourcesCompat;
import
cx.ring.R
;
public
class
SwitchButton
extends
CompoundButton
{
public
static
final
float
DEFAULT_THUMB_RANGE_RATIO
=
3
f
;
public
static
final
int
DEFAULT_THUMB_SIZE_DP
=
20
;
public
static
final
int
DEFAULT_THUMB_MARGIN_DP
=
2
;
public
static
final
int
DEFAULT_ANIMATION_DURATION
=
250
;
public
static
final
int
DEFAULT_EXTRA_MARGIN
=
10
;
public
static
final
int
DEFAULT_SWITCH_WIDTH
=
150
;
public
static
final
int
DEFAULT_SWITCH_WIDTH
=
72
;
private
int
mBackColor
;
private
int
mThumbWidth
=
0
;
private
int
mThumbHeight
=
0
;
private
final
int
mThumbSize
;
private
int
mBackWidth
;
private
int
mBackHeight
;
private
final
int
mTouchSlop
;
private
final
int
mClickTimeout
;
private
float
mThumbRadius
,
mBackRadius
;
private
float
mThumbRangeRatio
;
private
float
mTextWidth
;
private
float
mTextHeight
;
private
float
mProgress
;
...
...
@@ -70,13 +66,13 @@ public class SwitchButton extends CompoundButton {
private
boolean
mReady
=
false
;
private
boolean
mCatch
=
false
;
private
boolean
mShowImage
=
false
;
private
final
RectF
mThumbRectF
=
new
RectF
(),
mBackRectF
=
new
RectF
(),
private
final
PointF
mThumbPos
=
new
PointF
(),
mPresentThumbPos
=
new
PointF
();
private
final
RectF
mBackRectF
=
new
RectF
(),
mSafeRectF
=
new
RectF
(),
mTextOnRectF
=
new
RectF
(),
mTextOnRectF
=
new
RectF
(),
mTextOffRectF
=
new
RectF
(),
mThumbMargin
=
new
RectF
(),
mPresentThumbRectF
=
new
RectF
();
mThumbMargin
=
new
RectF
();
private
final
Paint
mPaint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
private
final
ValueAnimator
mProgressAnimator
=
ValueAnimator
.
ofFloat
(
0
,
0
);
private
CharSequence
mStatus
;
...
...
@@ -124,10 +120,11 @@ public class SwitchButton extends CompoundButton {
float
margin
=
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
DEFAULT_THUMB_MARGIN_DP
,
getResources
().
getDisplayMetrics
());
mThumbMargin
.
set
(
margin
,
margin
,
margin
,
margin
);
mThumbSize
=
(
int
)
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
DEFAULT_THUMB_SIZE_DP
,
getResources
().
getDisplayMetrics
());
// size & measure params must larger than 1
float
thumbRangeRatio
=
DEFAULT_THUMB_RANGE_RATIO
;
mThumbRangeRatio
=
mThumbMargin
.
width
()
>=
0
?
Math
.
max
(
thumbRangeRatio
,
1
)
:
thumbRangeRatio
;
//
float thumbRangeRatio = DEFAULT_THUMB_RANGE_RATIO;
//
mThumbRangeRatio = mThumbMargin.width() >= 0 ? Math.max(thumbRangeRatio, 1) : thumbRangeRatio;
// sync checked status
setProgress
(
isChecked
()
?
1
.
f
:
0
.
f
);
...
...
@@ -153,15 +150,17 @@ public class SwitchButton extends CompoundButton {
mOffLayout
=
makeLayout
(
mStatus
);
}
float
onWidth
=
DEFAULT_SWITCH_WIDTH
;
float
defaultWidth
=
TypedValue
.
applyDimension
(
TypedValue
.
COMPLEX_UNIT_DIP
,
DEFAULT_SWITCH_WIDTH
,
getResources
().
getDisplayMetrics
());
//float onWidth = DEFAULT_SWITCH_WIDTH;
// mOnLayout != null ? mOnLayout.getWidth() : 0;
float
offWidth
=
DEFAULT_SWITCH_WIDTH
;
//
float offWidth = DEFAULT_SWITCH_WIDTH;
// mOffLayout != null ? mOffLayout.getWidth() : 0;
if
(
onWidth
!=
0
||
offWidth
!=
0
)
{
/*
if (onWidth != 0 || offWidth != 0) {
mTextWidth = Math.max(onWidth, offWidth);
} else {
mTextWidth = 0;
}
}*/
mTextWidth
=
defaultWidth
;
float
onHeight
=
mOnLayout
!=
null
?
mOnLayout
.
getHeight
()
:
0
;
float
offHeight
=
mOffLayout
!=
null
?
mOffLayout
.
getHeight
()
:
0
;
...
...
@@ -189,67 +188,19 @@ public class SwitchButton extends CompoundButton {
private
int
measureWidth
(
int
widthMeasureSpec
)
{
int
widthSize
=
MeasureSpec
.
getSize
(
widthMeasureSpec
);
int
widthMode
=
MeasureSpec
.
getMode
(
widthMeasureSpec
);
int
measuredWidth
=
widthSize
;
int
moveRange
;
int
textWidth
=
ceil
(
mTextWidth
);
// how much the background should extend to fit text.
int
textExtraSpace
;
int
contentSize
;
if
(
mThumbRangeRatio
==
0
)
{
mThumbRangeRatio
=
DEFAULT_THUMB_RANGE_RATIO
;
}
int
measuredWidth
;
if
(
widthMode
==
MeasureSpec
.
EXACTLY
)
{
contentSize
=
widthSize
-
getPaddingLeft
()
-
getPaddingRight
();
moveRange
=
ceil
(
contentSize
-
Math
.
max
(
mThumbMargin
.
left
,
0
)
-
Math
.
max
(
mThumbMargin
.
right
,
0
));
if
(
moveRange
<
0
)
{
mThumbWidth
=
0
;
mBackWidth
=
0
;
return
measuredWidth
;
}
mThumbWidth
=
ceil
(
moveRange
/
mThumbRangeRatio
);
mBackWidth
=
ceil
(
moveRange
+
mThumbMargin
.
left
+
mThumbMargin
.
right
)
+
DEFAULT_EXTRA_MARGIN
;
if
(
mBackWidth
<
0
)
{
mThumbWidth
=
0
;
mBackWidth
=
0
;
return
measuredWidth
;
}
textExtraSpace
=
textWidth
-
(
moveRange
-
mThumbWidth
+
ceil
(
Math
.
max
(
mThumbMargin
.
left
,
mThumbMargin
.
right
)));
if
(
textExtraSpace
>
0
)
{
// since backWidth is determined by view width, so we can only reduce thumbSize.
mThumbWidth
=
mThumbWidth
-
textExtraSpace
;
}
if
(
mThumbWidth
<
0
)
{
mThumbWidth
=
0
;
mBackWidth
=
0
;
return
measuredWidth
;
}
measuredWidth
=
widthSize
;
mBackWidth
=
widthSize
-
getPaddingLeft
()
-
getPaddingRight
();
}
else
{
/*
If parent view want SwitchButton to determine it's size itself, we calculate the minimal
size of it's content. Further more, we ignore the limitation of widthSize since we want
to display SwitchButton in its actual size rather than compress the shape.
*/
mThumbWidth
=
ceil
(
getResources
().
getDisplayMetrics
().
density
*
DEFAULT_THUMB_SIZE_DP
);
if
(
mThumbRangeRatio
==
0
)
{
mThumbRangeRatio
=
DEFAULT_THUMB_RANGE_RATIO
;
}
moveRange
=
ceil
(
mThumbWidth
*
mThumbRangeRatio
);
textExtraSpace
=
ceil
(
textWidth
-
(
moveRange
-
mThumbWidth
+
Math
.
max
(
mThumbMargin
.
left
,
mThumbMargin
.
right
)));
mBackWidth
=
ceil
(
moveRange
+
mThumbMargin
.
left
+
mThumbMargin
.
right
+
Math
.
max
(
0
,
textExtraSpace
))
+
DEFAULT_EXTRA_MARGIN
;
if
(
mBackWidth
<
0
)
{
mThumbWidth
=
0
;
mBackWidth
=
0
;
return
measuredWidth
;
}
contentSize
=
ceil
(
moveRange
+
Math
.
max
(
0
,
mThumbMargin
.
left
)
+
Math
.
max
(
0
,
mThumbMargin
.
right
)
+
Math
.
max
(
0
,
textExtraSpace
));
measuredWidth
=
Math
.
max
(
contentSize
,
contentSize
+
getPaddingLeft
()
+
getPaddingRight
());
mBackWidth
=
Math
.
max
(
ceil
(
mThumbSize
+
mThumbMargin
.
left
+
mThumbMargin
.
right
+
mTextWidth
),
0
);
measuredWidth
=
mBackWidth
+
getPaddingLeft
()
+
getPaddingRight
();
}
return
measuredWidth
;
}
...
...
@@ -262,19 +213,19 @@ public class SwitchButton extends CompoundButton {
int
contentSize
;
int
textExtraSpace
;
if
(
heightMode
==
MeasureSpec
.
EXACTLY
)
{
if
(
mThumb
Height
!=
0
)
{
//
if (mThumb
Size
!= 0) {
/*
If thumbHeight has been set, we calculate backHeight and check if there is enough room.
*/
mBackHeight
=
ceil
(
mThumb
Height
+
mThumbMargin
.
top
+
mThumbMargin
.
bottom
);
mBackHeight
=
ceil
(
mThumb
Size
+
mThumbMargin
.
top
+
mThumbMargin
.
bottom
);
mBackHeight
=
ceil
(
Math
.
max
(
mBackHeight
,
mTextHeight
));
if
(
mBackHeight
+
getPaddingTop
()
+
getPaddingBottom
()
-
Math
.
min
(
0
,
mThumbMargin
.
top
)
-
Math
.
min
(
0
,
mThumbMargin
.
bottom
)
>
heightSize
)
{
/*
if (mBackHeight + getPaddingTop() + getPaddingBottom() - Math.min(0, mThumbMargin.top) - Math.min(0, mThumbMargin.bottom) > heightSize) {
// No enough room, we set thumbHeight to zero to calculate these value again.
mThumbHeight = 0;
}
}
}
*/
//
}
if
(
mThumbHeight
==
0
)
{
/*
if (mThumbHeight == 0) {
mBackHeight = ceil(heightSize - getPaddingTop() - getPaddingBottom() + Math.min(0, mThumbMargin.top) + Math.min(0, mThumbMargin.bottom));
if (mBackHeight < 0) {
mBackHeight = 0;
...
...
@@ -287,23 +238,23 @@ public class SwitchButton extends CompoundButton {
mBackHeight = 0;
mThumbHeight = 0;
return measuredHeight;
}
}
*/
}
else
{
if
(
mThumbHeight
==
0
)
{
/*
if (mThumbHeight == 0) {
mThumbHeight = ceil(getResources().getDisplayMetrics().density * DEFAULT_THUMB_SIZE_DP);
}
mBackHeight
=
ceil
(
mThumb
Height
+
mThumbMargin
.
top
+
mThumbMargin
.
bottom
);
if
(
mBackHeight
<
0
)
{
}
*/
mBackHeight