From 64694aed0f359aa4b44f58c61f8b5557479ed442 Mon Sep 17 00:00:00 2001 From: leon Date: Wed, 8 Jan 2020 16:08:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7androidx=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=9C=A8android=20studio=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 +++---- .../java/org/wuhenzhizao/ApplicationTest.java | 13 -------- .../java/org/wuhenzhizao/MainActivity.java | 4 +-- .../org/wuhenzhizao/QuickPreviewActivity.java | 3 +- .../org/wuhenzhizao/SwipeBackActivity.java | 6 ++-- .../java/org/wuhenzhizao/TabFragment.java | 5 +-- .../org/wuhenzhizao/TabFragmentAdapter.java | 6 ++-- .../res/layout/activity_quick_preview.xml | 3 +- .../layout/content_center_custom_layout.xml | 2 +- build.gradle | 2 +- gradle.properties | 4 ++- library/build.gradle | 31 +++++++++---------- .../wuhenzhizao/ExampleInstrumentedTest.java | 26 ---------------- .../titlebar/statusbar/StatusBarUtils.java | 3 +- .../titlebar/widget/CommonTitleBar.java | 19 +++++++++--- library/src/main/res/values/attrs.xml | 1 + 16 files changed, 59 insertions(+), 81 deletions(-) delete mode 100755 app/src/androidTest/java/org/wuhenzhizao/ApplicationTest.java delete mode 100644 library/src/androidTest/java/com/wuhenzhizao/ExampleInstrumentedTest.java diff --git a/app/build.gradle b/app/build.gradle index 42e14b7..818ce8e 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 26 - buildToolsVersion "26.0.2" + compileSdkVersion 28 defaultConfig { applicationId "org.wuhenzhizao" minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 28 versionCode 2 versionName "1.1" @@ -27,10 +26,9 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'com.jude:swipebackhelper:2.1.5' - implementation 'com.ogaclejapan.smarttablayout:library:1.6.1' + implementation 'com.ogaclejapan.smarttablayout:library:2.0.0' implementation project(':library') -// compile 'com.wuhenzhizao:titlebar:1.1.4' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13' } diff --git a/app/src/androidTest/java/org/wuhenzhizao/ApplicationTest.java b/app/src/androidTest/java/org/wuhenzhizao/ApplicationTest.java deleted file mode 100755 index 4e4e5f4..0000000 --- a/app/src/androidTest/java/org/wuhenzhizao/ApplicationTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.wuhenzhizao; - -import android.app.Application; -import android.test.ApplicationTestCase; - -/** - * Testing Fundamentals - */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); - } -} \ No newline at end of file diff --git a/app/src/main/java/org/wuhenzhizao/MainActivity.java b/app/src/main/java/org/wuhenzhizao/MainActivity.java index 6f53a67..8061106 100755 --- a/app/src/main/java/org/wuhenzhizao/MainActivity.java +++ b/app/src/main/java/org/wuhenzhizao/MainActivity.java @@ -2,12 +2,12 @@ import android.graphics.Color; import android.os.Bundle; -import android.support.v4.view.ViewPager; import android.view.View; import android.widget.Toast; +import androidx.viewpager.widget.ViewPager; + import com.ogaclejapan.smarttablayout.SmartTabLayout; -import com.wuhenzhizao.titlebar.utils.KeyboardConflictCompat; import com.wuhenzhizao.titlebar.utils.ScreenUtils; import com.wuhenzhizao.titlebar.widget.CommonTitleBar; diff --git a/app/src/main/java/org/wuhenzhizao/QuickPreviewActivity.java b/app/src/main/java/org/wuhenzhizao/QuickPreviewActivity.java index 3cd60e2..28667fa 100644 --- a/app/src/main/java/org/wuhenzhizao/QuickPreviewActivity.java +++ b/app/src/main/java/org/wuhenzhizao/QuickPreviewActivity.java @@ -1,9 +1,10 @@ package org.wuhenzhizao; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.View; +import androidx.annotation.Nullable; + import com.wuhenzhizao.titlebar.utils.KeyboardConflictCompat; import com.wuhenzhizao.titlebar.widget.CommonTitleBar; diff --git a/app/src/main/java/org/wuhenzhizao/SwipeBackActivity.java b/app/src/main/java/org/wuhenzhizao/SwipeBackActivity.java index 087b550..738bfe9 100644 --- a/app/src/main/java/org/wuhenzhizao/SwipeBackActivity.java +++ b/app/src/main/java/org/wuhenzhizao/SwipeBackActivity.java @@ -2,11 +2,13 @@ import android.os.Build; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import com.jude.swipbackhelper.SwipeBackHelper; + /** * Created by liufei on 2017/12/18. */ diff --git a/app/src/main/java/org/wuhenzhizao/TabFragment.java b/app/src/main/java/org/wuhenzhizao/TabFragment.java index 90e8433..b81ea1c 100644 --- a/app/src/main/java/org/wuhenzhizao/TabFragment.java +++ b/app/src/main/java/org/wuhenzhizao/TabFragment.java @@ -1,12 +1,13 @@ package org.wuhenzhizao; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + /** * Created by liufei on 2017/12/1. */ diff --git a/app/src/main/java/org/wuhenzhizao/TabFragmentAdapter.java b/app/src/main/java/org/wuhenzhizao/TabFragmentAdapter.java index 6a606ff..4916280 100644 --- a/app/src/main/java/org/wuhenzhizao/TabFragmentAdapter.java +++ b/app/src/main/java/org/wuhenzhizao/TabFragmentAdapter.java @@ -1,8 +1,8 @@ package org.wuhenzhizao; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; /** * Created by liufei on 2017/12/1. diff --git a/app/src/main/res/layout/activity_quick_preview.xml b/app/src/main/res/layout/activity_quick_preview.xml index 0cd13a3..0e445ec 100644 --- a/app/src/main/res/layout/activity_quick_preview.xml +++ b/app/src/main/res/layout/activity_quick_preview.xml @@ -22,7 +22,7 @@ android:background="#eeeeee" android:overScrollMode="never"> - @@ -121,6 +121,7 @@ titlebar:fillStatusBar="false" titlebar:leftType="imageButton" titlebar:rightText="确定" + titlebar:centerSearchHint="搜索" titlebar:rightType="textView" /> - Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.wuhenzhizao.test", appContext.getPackageName()); - } -} diff --git a/library/src/main/java/com/wuhenzhizao/titlebar/statusbar/StatusBarUtils.java b/library/src/main/java/com/wuhenzhizao/titlebar/statusbar/StatusBarUtils.java index 5d71b38..15d4322 100644 --- a/library/src/main/java/com/wuhenzhizao/titlebar/statusbar/StatusBarUtils.java +++ b/library/src/main/java/com/wuhenzhizao/titlebar/statusbar/StatusBarUtils.java @@ -5,11 +5,12 @@ import android.content.res.Resources; import android.graphics.Color; import android.os.Build; -import android.support.annotation.ColorInt; import android.view.View; import android.view.Window; import android.view.WindowManager; +import androidx.annotation.ColorInt; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.UUID; diff --git a/library/src/main/java/com/wuhenzhizao/titlebar/widget/CommonTitleBar.java b/library/src/main/java/com/wuhenzhizao/titlebar/widget/CommonTitleBar.java index b1b2557..4564c02 100755 --- a/library/src/main/java/com/wuhenzhizao/titlebar/widget/CommonTitleBar.java +++ b/library/src/main/java/com/wuhenzhizao/titlebar/widget/CommonTitleBar.java @@ -178,6 +178,7 @@ public class CommonTitleBar extends RelativeLayout implements View.OnClickListen private static final int TYPE_CENTER_SEARCH_RIGHT_VOICE = 0; private static final int TYPE_CENTER_SEARCH_RIGHT_DELETE = 1; + private String centerSearchHint; public CommonTitleBar(Context context, AttributeSet attrs) { super(context, attrs); @@ -242,6 +243,7 @@ private void loadAttributes(Context context, AttributeSet attrs) { centerSearchEditable = array.getBoolean(R.styleable.CommonTitleBar_centerSearchEditable, true); centerSearchBgResource = array.getResourceId(R.styleable.CommonTitleBar_centerSearchBg, R.drawable.comm_titlebar_search_gray_shape); centerSearchRightType = array.getInt(R.styleable.CommonTitleBar_centerSearchRightType, TYPE_CENTER_SEARCH_RIGHT_VOICE); + centerSearchHint = array.getString(R.styleable.CommonTitleBar_centerSearchHint); } else if (centerType == TYPE_CENTER_CUSTOM_VIEW) { centerCustomViewRes = array.getResourceId(R.styleable.CommonTitleBar_centerCustomView, 0); } @@ -261,7 +263,10 @@ private void initGlobalViews(Context context) { ViewGroup.LayoutParams globalParams = new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT); setLayoutParams(globalParams); - boolean transparentStatusBar = StatusBarUtils.supportTransparentStatusBar(); + boolean transparentStatusBar = false; + if (!isInEditMode()) { + transparentStatusBar = StatusBarUtils.supportTransparentStatusBar(); + } // 构建标题栏填充视图 if (fillStatusBar && transparentStatusBar && !isInEditMode()) { @@ -455,7 +460,11 @@ private void initMainCenterViews(Context context) { tvCenter.setGravity(Gravity.CENTER); tvCenter.setSingleLine(true); // 设置跑马灯效果 - tvCenter.setMaxWidth((int) (ScreenUtils.getScreenPixelSize(context)[0] * 3 / 5.0)); + int maxWidth = 100; + if (!isInEditMode()) { + maxWidth = (int) (ScreenUtils.getScreenPixelSize(context)[0] * 3 / 5.0); + } + tvCenter.setMaxWidth(maxWidth); if (centerTextMarquee){ tvCenter.setEllipsize(TextUtils.TruncateAt.MARQUEE); tvCenter.setMarqueeRepeatLimit(-1); @@ -557,7 +566,7 @@ private void initMainCenterViews(Context context) { etSearchHint = new EditText(context); etSearchHint.setBackgroundColor(Color.TRANSPARENT); etSearchHint.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); - etSearchHint.setHint(getResources().getString(R.string.titlebar_search_hint)); + etSearchHint.setHint(centerSearchHint); etSearchHint.setTextColor(Color.parseColor("#666666")); etSearchHint.setHintTextColor(Color.parseColor("#999999")); etSearchHint.setTextSize(TypedValue.COMPLEX_UNIT_PX, ScreenUtils.dp2PxInt(context, 14)); @@ -621,7 +630,9 @@ public void onClick(View v) { @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - setUpImmersionTitleBar(); + if (!isInEditMode()) { + setUpImmersionTitleBar(); + } } private void setUpImmersionTitleBar() { diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index f6fe422..7fb3683 100755 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -72,6 +72,7 @@ +