diff --git a/README_EN.md b/README_EN.md index 6c660b7..373ff9b 100644 --- a/README_EN.md +++ b/README_EN.md @@ -2,25 +2,6 @@ [中文版](https://github.com/xcc3641/SeeWeather/blob/master/README.md)丨[English](https://github.com/xcc3641/SeeWeather/blob/master/README_EN.md) - -### Foreword - -SeeWeather is my first relatively mature application,going on-line in the October 2015.And then I answered this question [how to learn Android by oneself](https://www.zhihu.com/question/26417244/answer/70193822) in the ZhiHu platform - -Because my code was poorly written, I decided to refactor the whole project and made a new look to show SeeWeather Version 2.0. - -If you find any problems and suggestion,you can e-mail me or open issues at any time. - - -**Attention** - -**If you want to pull the project to run, you should apply for API at [和风天气](http://www.heweather.com/) and add it in Setting.java** - -**If the application crashes, pleace e-mail the log(`/Android/data/com.xiecc.seeWeather/cache/Log`) to me** - -- **open-source project is valuable, hope to give me a star for support** - - ### Brief introduction SeeWeather is an following ** Material Design** Weather application.Use the least Permission to do the best with the least experience. @@ -70,7 +51,7 @@ Kuan:http://www.coolapk.com/apk/com.xiecc.seeWeather ### TODO -I am a little busy in this semester,preparing for the job interview, but I will still complete to-do. + - [ ] Widget - [ ] Notification - [ ] Prettier Weather Icons @@ -91,6 +72,7 @@ City Data:CSDN City Orientation: 高德地图 #### Open-source project + 1. [Rxjava](https://github.com/ReactiveX/RxJava) 2. [RxAndroid](https://github.com/ReactiveX/RxAndroid) 3. [Retrofit](https://github.com/square/retrofit) @@ -138,8 +120,9 @@ _ _ _ ### LICENSE Copyright 2016 HugoXie Licensed under the Apache License, Version 2.0 (the \"License\") - you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ** Pictures from the network, the copyright belongs to the original author.** diff --git a/app/app.iml b/app/app.iml index 762fe23..454760b 100644 --- a/app/app.iml +++ b/app/app.iml @@ -96,14 +96,6 @@ - - - - - - - - @@ -118,7 +110,6 @@ - @@ -133,14 +124,12 @@ - - @@ -149,30 +138,24 @@ - - - - - + - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 2e1304d..5ca8478 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,7 +74,7 @@ dependencies { compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2' compile 'com.squareup.okhttp3:okhttp:3.0.1' compile 'com.squareup.okhttp3:logging-interceptor:3.0.1' -// compile 'com.squareup.okio:okio:1.6.0' + compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' compile 'com.jakewharton:butterknife:7.0.1' @@ -89,6 +89,6 @@ dependencies { debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' - compile 'com.google.firebase:firebase-core:9.0.0' + } diff --git a/app/src/main/java/com/xiecc/seeWeather/base/BaseActivity.java b/app/src/main/java/com/xiecc/seeWeather/base/BaseActivity.java index e3292d9..5b77438 100644 --- a/app/src/main/java/com/xiecc/seeWeather/base/BaseActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/base/BaseActivity.java @@ -2,9 +2,8 @@ import android.os.Build; import android.os.Bundle; -import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; -import android.view.View; +import android.support.v7.app.AppCompatDelegate; import android.view.WindowManager; import com.readystatesoftware.systembartint.SystemBarTintManager; import com.xiecc.seeWeather.common.ACache; @@ -26,23 +25,11 @@ public class BaseActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //overridePendingTransition(R.anim.zoom_enter,R.anim.zoom_exit); + if (savedInstanceState==null){ + setTheme(this); + } aCache = ACache.get(getApplication()); mSetting = Setting.getInstance(); - /** - * http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/1122/3712.html - * 在BaseActivity.java里:我们通过判断当前sdk_int大于4.4(kitkat),则通过代码的形式设置status bar为透明 - * (这里其实可以通过values-v19 的sytle.xml里设置windowTranslucentStatus属性为true来进行设置,但是在某些手机会不起效,所以采用代码的形式进行设置)。 - * 还需要注意的是我们这里的AppCompatAcitivity是android.support.v7.app.AppCompatActivity支持包中的AppCompatAcitivity, - * 也是为了在低版本的android系统中兼容toolbar。 - */ - //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - // Window window = getWindow(); - // // Translucent status bar - // window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, - // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - // window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, - // WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - //} } public CompositeSubscription getCompositeSubscription() { @@ -68,6 +55,7 @@ public void setContentView(int layoutResID) { * 设置状态栏颜色 * 也就是所谓沉浸式状态栏 */ + @Deprecated public void setStatusBarColor(int color) { /** * Android4.4以上 但是抽屉有点冲突,目前就重写一个方法暂时解决4.4的问题 @@ -92,14 +80,6 @@ public void setStatusBarColorForKitkat(int color) { } } - public void showSnackbar(View view, String s) { - Snackbar.make(view, s, Snackbar.LENGTH_SHORT).show(); - } - - public void showSnackbar(View view, String s, boolean ture) { - Snackbar.make(view, s, Snackbar.LENGTH_LONG).show(); - } - @Override protected void onStop() { super.onStop(); @@ -112,4 +92,36 @@ protected void onDestroy() { this.mCompositeSubscription.unsubscribe(); } } + + public static void setDayTheme(AppCompatActivity activity) { + AppCompatDelegate.setDefaultNightMode( + AppCompatDelegate.MODE_NIGHT_NO); + activity.getDelegate().setLocalNightMode( + AppCompatDelegate.MODE_NIGHT_NO); + // 调用 recreate() 使设置生效 + activity.recreate(); + } + + public static void setNightTheme(AppCompatActivity activity) { + AppCompatDelegate.setDefaultNightMode( + AppCompatDelegate.MODE_NIGHT_YES); + activity.getDelegate().setLocalNightMode( + AppCompatDelegate.MODE_NIGHT_YES); + // 调用 recreate() 使设置生效 + activity.recreate(); + } + + public void setTheme(boolean isNights, AppCompatActivity activity) { + if (isNights) { + setNightTheme(activity); + } else { + setDayTheme(activity); + } + } + + public void setTheme(AppCompatActivity activity) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); + activity.getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); + activity.recreate(); + } } diff --git a/app/src/main/java/com/xiecc/seeWeather/base/BaseApplication.java b/app/src/main/java/com/xiecc/seeWeather/base/BaseApplication.java index b59dd3f..6b6472a 100644 --- a/app/src/main/java/com/xiecc/seeWeather/base/BaseApplication.java +++ b/app/src/main/java/com/xiecc/seeWeather/base/BaseApplication.java @@ -2,6 +2,7 @@ import android.app.Application; import android.content.Context; +import android.support.v7.app.AppCompatDelegate; import com.github.moduth.blockcanary.BlockCanary; import com.squareup.leakcanary.LeakCanary; import com.tencent.bugly.crashreport.CrashReport; @@ -17,6 +18,11 @@ public class BaseApplication extends Application { public static String cacheDir = ""; public static Context mAppContext = null; + static { + AppCompatDelegate.setDefaultNightMode( + AppCompatDelegate.MODE_NIGHT_NO); + } + @Override public void onCreate() { super.onCreate(); @@ -37,6 +43,8 @@ public void onCreate() { } else { cacheDir = getApplicationContext().getCacheDir().toString(); } + + } private boolean ExistSDCard() { diff --git a/app/src/main/java/com/xiecc/seeWeather/base/ToolbarActivity.java b/app/src/main/java/com/xiecc/seeWeather/base/ToolbarActivity.java index eda84a6..801bf41 100644 --- a/app/src/main/java/com/xiecc/seeWeather/base/ToolbarActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/base/ToolbarActivity.java @@ -58,7 +58,12 @@ protected void setAppBarAlpha(float alpha) { mAppBar.setAlpha(alpha); } - @Override public boolean onOptionsItemSelected(MenuItem item) { + public Toolbar getToolbar() { + return mToolbar; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { onBackPressed(); return true; @@ -74,5 +79,4 @@ protected void hideOrShowToolbar() { .start(); mIsHidden = !mIsHidden; } - } diff --git a/app/src/main/java/com/xiecc/seeWeather/common/utils/RevealAnimUtil.java b/app/src/main/java/com/xiecc/seeWeather/common/utils/RevealAnimUtil.java new file mode 100644 index 0000000..79ace7b --- /dev/null +++ b/app/src/main/java/com/xiecc/seeWeather/common/utils/RevealAnimUtil.java @@ -0,0 +1,94 @@ +package com.xiecc.seeWeather.common.utils; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.support.annotation.ColorRes; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.content.ContextCompat; +import android.view.View; +import android.view.ViewAnimationUtils; +import android.view.animation.AccelerateDecelerateInterpolator; + +/** + * Created by HugoXie on 16/7/7. + * + * Email: Hugo3641@gamil.com + * GitHub: https://github.com/xcc3641 + * Info: 焦点在 fab 上的 reveal 动画,切换 activity 使用 + */ +public class RevealAnimUtil { + + public interface OnRevealAnimationListener { + void onRevealHide(); + + void onRevealShow(); + } + + // 显示 + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static void animateRevealShow(final Context context, final View view, final FloatingActionButton fab, + final int startRadius, @ColorRes final int color, + final OnRevealAnimationListener listener) { + // 获得开始焦点 fab 中心 + int cx = (fab.getLeft() + fab.getRight()) / 2; + int cy = (fab.getTop() + fab.getBottom()) / 2; + + float finalRadius = (float) Math.hypot(view.getWidth(), view.getHeight()); + + // 设置圆形显示动画 + Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, startRadius, finalRadius); + anim.setDuration(500); + anim.setInterpolator(new AccelerateDecelerateInterpolator()); + anim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + view.setVisibility(View.INVISIBLE); + //切换代码在动画开始时执行比较好 + listener.onRevealShow(); + } + + @Override + public void onAnimationStart(Animator animation) { + super.onAnimationStart(animation); + view.setBackgroundColor(ContextCompat.getColor(context, color)); + view.setVisibility(View.VISIBLE); + } + }); + anim.start(); + } + + // 圆圈凝聚效果 + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static void animateRevealHide( + final Context context, final View view, + final int finalRadius, @ColorRes final int color, + final OnRevealAnimationListener listener + ) { + int cx = (view.getLeft() + view.getRight()) / 2; + int cy = (view.getTop() + view.getBottom()) / 2; + int initialRadius = view.getWidth(); + // 与入场动画的区别就是圆圈起始和终止的半径相反 + Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, finalRadius); + anim.setDuration(300); + anim.setInterpolator(new AccelerateDecelerateInterpolator()); + anim.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationStart(Animator animation) { + super.onAnimationStart(animation); + view.setBackgroundColor(ContextCompat.getColor(context, color)); + } + + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationEnd(animation); + listener.onRevealHide(); + view.setVisibility(View.INVISIBLE); + } + }); + anim.start(); + } +} diff --git a/app/src/main/java/com/xiecc/seeWeather/component/ImageLoader.java b/app/src/main/java/com/xiecc/seeWeather/component/ImageLoader.java index a8c0cab..e2e2413 100644 --- a/app/src/main/java/com/xiecc/seeWeather/component/ImageLoader.java +++ b/app/src/main/java/com/xiecc/seeWeather/component/ImageLoader.java @@ -18,8 +18,6 @@ public static void load(Context context, @DrawableRes int imageRes, ImageView vi Glide.with(context).load(imageRes).crossFade().into(view); } - - public static void clear(Context context) { Glide.get(context).clearMemory(); } diff --git a/app/src/main/java/com/xiecc/seeWeather/modules/about/ui/AboutActivity.java b/app/src/main/java/com/xiecc/seeWeather/modules/about/ui/AboutActivity.java index eb310e5..a11ed51 100644 --- a/app/src/main/java/com/xiecc/seeWeather/modules/about/ui/AboutActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/modules/about/ui/AboutActivity.java @@ -3,7 +3,6 @@ import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; -import android.support.v4.content.ContextCompat; import com.xiecc.seeWeather.R; import com.xiecc.seeWeather.base.ToolbarActivity; @@ -22,12 +21,7 @@ protected int provideContentViewId() { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - getSupportActionBar().setTitle("关于"); - setStatusBarColor(R.color.colorPrimary); - if (mSetting.getCurrentHour() < 6 || mSetting.getCurrentHour() > 18) { - mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.colorSunset)); - setStatusBarColor(R.color.colorSunset); - } + getToolbar().setTitle("关于"); mFragmentTransaction = getFragmentManager().beginTransaction(); mFragmentTransaction.replace(R.id.framelayout, mAboutFragment); mFragmentTransaction.commit(); diff --git a/app/src/main/java/com/xiecc/seeWeather/modules/city/ui/ChoiceCityActivity.java b/app/src/main/java/com/xiecc/seeWeather/modules/city/ui/ChoiceCityActivity.java index c57bd9f..d081431 100644 --- a/app/src/main/java/com/xiecc/seeWeather/modules/city/ui/ChoiceCityActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/modules/city/ui/ChoiceCityActivity.java @@ -1,22 +1,16 @@ package com.xiecc.seeWeather.modules.city.ui; import android.os.Bundle; -import android.support.design.widget.AppBarLayout; -import android.support.design.widget.CollapsingToolbarLayout; -import android.support.design.widget.CoordinatorLayout; -import android.support.v4.content.ContextCompat; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.ImageView; import android.widget.ProgressBar; import com.xiecc.seeWeather.R; -import com.xiecc.seeWeather.base.BaseActivity; import com.xiecc.seeWeather.base.RxBus; +import com.xiecc.seeWeather.base.ToolbarActivity; import com.xiecc.seeWeather.common.PLog; import com.xiecc.seeWeather.common.utils.RxUtils; -import com.xiecc.seeWeather.component.ImageLoader; import com.xiecc.seeWeather.modules.city.adapter.CityAdapter; import com.xiecc.seeWeather.modules.city.db.DBManager; import com.xiecc.seeWeather.modules.city.db.WeatherDB; @@ -31,13 +25,8 @@ /** * Created by hugo on 2016/2/19 0019. */ -public class ChoiceCityActivity extends BaseActivity { +public class ChoiceCityActivity extends ToolbarActivity { - private CoordinatorLayout mCoord; - private AppBarLayout mAppBar; - private CollapsingToolbarLayout mToolbarLayout; - private ImageView mBanner; - private Toolbar mToolbar; private RecyclerView mRecyclerview; private ProgressBar mProgressBar; private ImageView mIvErro; @@ -51,16 +40,25 @@ public class ChoiceCityActivity extends BaseActivity { private List cityList; private CityAdapter mAdapter; + public static final int LEVEL_PROVINCE = 1; public static final int LEVEL_CITY = 2; private int currentLevel; + @Override + protected int provideContentViewId() { + return R.layout.activity_choice_city; + } + + @Override + public boolean canBack() { + return true; + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_choice_city); initView(); - addSubscription( Observable.defer(() -> { mDBManager = new DBManager(ChoiceCityActivity.this); @@ -74,25 +72,9 @@ protected void onCreate(Bundle savedInstanceState) { } private void initView() { - - mCoord = (CoordinatorLayout) findViewById(R.id.coord); - mAppBar = (AppBarLayout) findViewById(R.id.app_bar); - mToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout); - mBanner = (ImageView) findViewById(R.id.banner); - mToolbar = (Toolbar) findViewById(R.id.toolbar); mRecyclerview = (RecyclerView) findViewById(R.id.recyclerview); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mIvErro = (ImageView) findViewById(R.id.iv_erro); - - setStatusBarColorForKitkat(R.color.colorSunrise); - if (mBanner != null) { - ImageLoader.load(this, R.mipmap.city_day, mBanner); - if (mSetting.getCurrentHour() < 6 || mSetting.getCurrentHour() > 18) { - mToolbarLayout.setContentScrimColor(ContextCompat.getColor(this, R.color.colorSunset)); - ImageLoader.load(this, R.mipmap.city_night, mBanner); - setStatusBarColorForKitkat(R.color.colorSunset); - } - } if (mProgressBar != null) { mProgressBar.setVisibility(View.VISIBLE); } @@ -123,7 +105,7 @@ private void initRecyclerView() { * 查询全国所有的省,从数据库查询 */ private void queryProvinces() { - mToolbarLayout.setTitle("选择省份"); + getToolbar().setTitle("选择省份"); addSubscription(Observable.defer(() -> { if (provincesList.isEmpty()) { provincesList.addAll(WeatherDB.loadProvinces(mDBManager.getDatabase())); @@ -150,9 +132,9 @@ private void queryProvinces() { * 查询选中省份的所有城市,从数据库查询 */ private void queryCities() { + getToolbar().setTitle("选择城市"); dataList.clear(); mAdapter.notifyDataSetChanged(); - mToolbarLayout.setTitle(selectedProvince.ProName); addSubscription(Observable.defer(() -> { cityList = WeatherDB.loadCities(mDBManager.getDatabase(), selectedProvince.ProSort); return Observable.from(cityList); @@ -185,5 +167,4 @@ protected void onDestroy() { super.onDestroy(); mDBManager.closeDatabase(); } - } diff --git a/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java b/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java index dd44e4f..c55c7d9 100644 --- a/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/modules/main/ui/MainActivity.java @@ -69,7 +69,6 @@ import rx.Observer; import rx.android.schedulers.AndroidSchedulers; -// TODO: 16/5/18 config.gradle 未提示 整合 retrofit 的使用 public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, AMapLocationListener { @@ -101,6 +100,7 @@ protected void onCreate(Bundle savedInstanceState) { initDrawer(); initDataObserver(); initIcon(); + startService(new Intent(this, AutoUpdateService.class)); CheckVersion.checkVersion(this); // https://github.com/tbruyelle/RxPermissions @@ -128,7 +128,6 @@ protected void onCreate(Bundle savedInstanceState) { protected void onStart() { super.onStart(); PLog.i("onStart"); - showEggs(); } @Override @@ -145,6 +144,7 @@ protected void onRestart() { protected void onResume() { super.onResume(); PLog.i("onResume"); + PLog.d(toolbar.getHeight() + ""); } @Override @@ -195,91 +195,83 @@ private void initView() { //fab fab = (FloatingActionButton) findViewById(R.id.fab); - if (fab != null) { - fab.setOnClickListener(v -> showFabDialog()); - if (Util.checkDeviceHasNavigationBar(this) || BuildConfig.DEBUG) { - CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); - Resources res = getResources(); - int fabMargin = Util.dip2px(this, res.getDimension(R.dimen.fab_margin)) / 3; - lp.setMargins(fabMargin, fabMargin, fabMargin, Util.getNavigationBarHeight(this) + fabMargin); - } - //recclerview - mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview); - mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this)); - mRecyclerView.setHasFixedSize(true); - //mRecyclerView.addOnScrollListener(new HidingScrollListener() { - // @Override - // public void onHide() { - // fab.animate() - // .translationY(fab.getHeight() + fabBottomMargin) - // .setInterpolator(new AccelerateInterpolator(2)) - // .start(); - // } - // - // @Override - // public void onShow() { - // fab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start(); - // } - //}); - mAdapter = new WeatherAdapter(MainActivity.this, mWeather); - mRecyclerView.setAdapter(mAdapter); - - mAdapter.setOnItemClickListener(mWeather1 -> { - LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View dialogLayout = inflater.inflate(R.layout.weather_dialog, (ViewGroup) this.findViewById( - R.id.weather_dialog_root)); - AlertDialog.Builder builder = new AlertDialog.Builder(this) - .setView(dialogLayout); - final AlertDialog alertDialog = builder.create(); - - RelativeLayout root = (RelativeLayout) dialogLayout.findViewById(R.id.weather_dialog_root); - switch (Util.getWeatherType(Integer.parseInt(mWeather1.now.cond.code))) { - case "晴": - root.setBackgroundResource(R.mipmap.dialog_bg_sunny); - break; - case "阴": - root.setBackgroundResource(R.mipmap.dialog_bg_cloudy); - break; - case "雨": - root.setBackgroundResource(R.mipmap.dialog_bg_rainy); - break; - default: - break; - } + fab.setOnClickListener(v -> showFabDialog()); + // 与抽屉结合实现效果不好 除非背景不是白色 + //fab.setOnClickListener(v -> showRevealAnim()); + //recclerview + mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview); + mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this)); + mRecyclerView.setHasFixedSize(true); + mAdapter = new WeatherAdapter(MainActivity.this, mWeather); + mRecyclerView.setAdapter(mAdapter); + + if (Util.checkDeviceHasNavigationBar(this) || BuildConfig.DEBUG) { + CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + Resources res = getResources(); + int fabMargin = Util.dip2px(this, res.getDimension(R.dimen.fab_margin)) / 4; + lp.setMargins(fabMargin, fabMargin, fabMargin, Util.getNavigationBarHeight(this) + fabMargin); - TextView city = (TextView) dialogLayout.findViewById(R.id.dialog_city); - city.setText(mWeather1.basic.city); - TextView temp = (TextView) dialogLayout.findViewById(R.id.dialog_temp); - temp.setText(String.format("%s°", mWeather1.now.tmp)); - ImageView icon = (ImageView) dialogLayout.findViewById(R.id.dialog_icon); - - Glide.with(this) - .load(mSetting.getInt(mWeather1.now.cond.txt, R.mipmap.none)) - .asBitmap() - .into(new SimpleTarget() { - @Override - public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { - icon.setImageBitmap(resource); - icon.setColorFilter(Color.WHITE); - } - }); - - alertDialog.show(); - }); } + + mAdapter.setOnItemClickListener(mWeather1 -> { + LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View dialogLayout = inflater.inflate(R.layout.weather_dialog, (ViewGroup) this.findViewById( + R.id.weather_dialog_root)); + AlertDialog.Builder builder = new AlertDialog.Builder(this) + .setView(dialogLayout); + final AlertDialog alertDialog = builder.create(); + + RelativeLayout root = (RelativeLayout) dialogLayout.findViewById(R.id.weather_dialog_root); + switch (Util.getWeatherType(Integer.parseInt(mWeather1.now.cond.code))) { + case "晴": + root.setBackgroundResource(R.mipmap.dialog_bg_sunny); + break; + case "阴": + root.setBackgroundResource(R.mipmap.dialog_bg_cloudy); + break; + case "雨": + root.setBackgroundResource(R.mipmap.dialog_bg_rainy); + break; + default: + break; + } + + TextView city = (TextView) dialogLayout.findViewById(R.id.dialog_city); + city.setText(mWeather1.basic.city); + TextView temp = (TextView) dialogLayout.findViewById(R.id.dialog_temp); + temp.setText(String.format("%s°", mWeather1.now.tmp)); + ImageView icon = (ImageView) dialogLayout.findViewById(R.id.dialog_icon); + + Glide.with(this) + .load(mSetting.getInt(mWeather1.now.cond.txt, R.mipmap.none)) + .asBitmap() + .into(new SimpleTarget() { + @Override + public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { + icon.setImageBitmap(resource); + icon.setColorFilter(Color.WHITE); + } + }); + + alertDialog.show(); + }); } + /** + * 已经替换为 DayNight 主题切换日/夜间 + */ + @Deprecated private void showEggs() { //彩蛋-夜间模式 Calendar calendar = Calendar.getInstance(); mSetting.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY)); setStatusBarColorForKitkat(R.color.colorSunrise); - ImageLoader.load(this, R.mipmap.sunrise, bannner); + ImageLoader.load(this, R.mipmap.sun_main, bannner); if (mSetting.getCurrentHour() < 6 || mSetting.getCurrentHour() > 18) { - ImageLoader.load(this, R.mipmap.sunset, bannner); + ImageLoader.load(this, R.mipmap.sun_main, bannner); mCollapsingToolbarLayout.setContentScrimColor(ContextCompat.getColor(this, R.color.colorSunset)); setStatusBarColorForKitkat(R.color.colorSunset); - headerBackground.setBackground(ContextCompat.getDrawable(this, R.mipmap.header_back_night)); + headerBackground.setBackground(ContextCompat.getDrawable(this, R.mipmap.header_back)); } } @@ -451,6 +443,20 @@ private void showFabDialog() { }) .show(); } + // TODO: 16/7/8 波澜效果 与 抽屉 状态栏会有冲突 实现效果不佳 + //private void showRevealAnim() { + // RevealAnimUtil.animateRevealShow(this, findViewById(R.id.bg1), fab, fab.getWidth() / 2, R.color.colorSunrise, + // new RevealAnimUtil.OnRevealAnimationListener() { + // @Override + // public void onRevealHide() { + // } + // + // @Override + // public void onRevealShow() { + // startActivity(new Intent(MainActivity.this, SettingActivity.class)); + // } + // }); + //} /** * Called when an item in the navigation menu is selected. diff --git a/app/src/main/java/com/xiecc/seeWeather/modules/setting/ui/SettingActivity.java b/app/src/main/java/com/xiecc/seeWeather/modules/setting/ui/SettingActivity.java index 14a80d4..68b506f 100644 --- a/app/src/main/java/com/xiecc/seeWeather/modules/setting/ui/SettingActivity.java +++ b/app/src/main/java/com/xiecc/seeWeather/modules/setting/ui/SettingActivity.java @@ -1,7 +1,6 @@ package com.xiecc.seeWeather.modules.setting.ui; import android.os.Bundle; -import android.support.v4.content.ContextCompat; import com.xiecc.seeWeather.R; import com.xiecc.seeWeather.base.ToolbarActivity; @@ -19,13 +18,14 @@ protected int provideContentViewId() { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //mToolbar.setTitle("设置"); don't work and i find this - //http://stackoverflow.com/questions/26486730/in-android-app-toolbar-settitle-method-has-no-effect-application-name-is-shown + //http://stackoverflow.com/questions/26486730/in-android-app-toolbar-settitle-method-has-no-effect-application-name-is + // -shown getSupportActionBar().setTitle("设置"); - setStatusBarColor(R.color.colorPrimary); - if (mSetting.getCurrentHour() < 6 || mSetting.getCurrentHour() > 18) { - mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.colorSunset)); - setStatusBarColor(R.color.colorSunset); - } + setStatusBarColorForKitkat(R.color.colorSunrise); + //if (mSetting.getCurrentHour() < 6 || mSetting.getCurrentHour() > 18) { + // mToolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.colorSunset)); + // setStatusBarColorForKitkat(R.color.colorSunset); + //} getFragmentManager().beginTransaction().replace(R.id.framelayout, new SettingFragment()).commit(); } @@ -34,4 +34,8 @@ public boolean canBack() { return true; } + @Override + protected void onResume() { + super.onResume(); + } } diff --git a/app/src/main/res/layout/activity_choice_city.xml b/app/src/main/res/layout/activity_choice_city.xml index 732f151..85f9264 100644 --- a/app/src/main/res/layout/activity_choice_city.xml +++ b/app/src/main/res/layout/activity_choice_city.xml @@ -6,46 +6,7 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - - - - - - - - - - - + - + android:layout_height="match_parent" + > @@ -82,4 +84,6 @@ android:fitsSystemWindows="true" app:menu="@menu/activity_main_drawer"/> - \ No newline at end of file + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index eab98fe..b148398 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -12,7 +12,7 @@ android:id="@+id/swiprefresh" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_margin="8dp"> + > diff --git a/app/src/main/res/mipmap-xhdpi/city_night.jpg b/app/src/main/res/mipmap-night/city_header.jpg similarity index 100% rename from app/src/main/res/mipmap-xhdpi/city_night.jpg rename to app/src/main/res/mipmap-night/city_header.jpg diff --git a/app/src/main/res/mipmap-xhdpi/header_back_night.png b/app/src/main/res/mipmap-night/header_back.png similarity index 100% rename from app/src/main/res/mipmap-xhdpi/header_back_night.png rename to app/src/main/res/mipmap-night/header_back.png diff --git a/app/src/main/res/mipmap-xhdpi/sunset.png b/app/src/main/res/mipmap-night/sun_main.png similarity index 100% rename from app/src/main/res/mipmap-xhdpi/sunset.png rename to app/src/main/res/mipmap-night/sun_main.png diff --git a/app/src/main/res/mipmap-xhdpi/city_day.jpg b/app/src/main/res/mipmap-xhdpi/city_header.jpg similarity index 100% rename from app/src/main/res/mipmap-xhdpi/city_day.jpg rename to app/src/main/res/mipmap-xhdpi/city_header.jpg diff --git a/app/src/main/res/mipmap-xhdpi/header_about.png b/app/src/main/res/mipmap-xhdpi/header_about.png deleted file mode 100644 index 017e855..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/header_about.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/header_back_day.png b/app/src/main/res/mipmap-xhdpi/header_back.png similarity index 100% rename from app/src/main/res/mipmap-xhdpi/header_back_day.png rename to app/src/main/res/mipmap-xhdpi/header_back.png diff --git a/app/src/main/res/mipmap-xhdpi/sunrise.png b/app/src/main/res/mipmap-xhdpi/sun_main.png similarity index 100% rename from app/src/main/res/mipmap-xhdpi/sunrise.png rename to app/src/main/res/mipmap-xhdpi/sun_main.png diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml new file mode 100644 index 0000000..80ed63b --- /dev/null +++ b/app/src/main/res/values-night/colors.xml @@ -0,0 +1,6 @@ + + + #201D45 + #201D45 + @android:color/background_light + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 7255bf1..440d49d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,12 +1,11 @@ #106c99 - #00FFFFFF + #0D4A6A #FF4081 #0D4A6A #201D45 - #5c8392 -#8C8C8C + #8C8C8C diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f959f34..969fb79 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -14,10 +14,8 @@ -