Skip to content

Commit

Permalink
1.2发布 新增主题切换
Browse files Browse the repository at this point in the history
  • Loading branch information
iMeiji committed Nov 26, 2016
1 parent 0671b6e commit e157951
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 23 deletions.
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.1"
versionName '1.2'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -31,21 +31,21 @@ android {
debuggable true
}
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.afollestad.material-dialogs:commons:0.9.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.afollestad.material-dialogs:core:0.9.1.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'de.psdev.licensesdialog:licensesdialog:1.8.1'
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/meiji/daily/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.meiji.daily;

import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.afollestad.materialdialogs.color.CircleView;
import com.meiji.daily.utils.ColorUtil;

/**
* Created by Meiji on 2016/11/27.
*/

public class BaseActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
protected void onResume() {
super.onResume();
int color = ColorUtil.getColor(this);
if (getSupportActionBar() != null)
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(CircleView.shiftColorDown(color));
getWindow().setNavigationBarColor(color);
}
}
}
59 changes: 55 additions & 4 deletions app/src/main/java/com/meiji/daily/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
package com.meiji.daily;

import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.color.CircleView;
import com.afollestad.materialdialogs.color.ColorChooserDialog;
import com.meiji.daily.mvp.zhuanlan.ZhuanlanModel;
import com.meiji.daily.mvp.zhuanlan.ZhuanlanView;
import com.meiji.daily.utils.ColorUtil;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
import de.psdev.licensesdialog.LicensesDialog;
import de.psdev.licensesdialog.licenses.ApacheSoftwareLicense20;
import de.psdev.licensesdialog.licenses.MITLicense;
import de.psdev.licensesdialog.model.Notice;
import de.psdev.licensesdialog.model.Notices;

public class MainActivity extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener, ColorChooserDialog.ColorCallback {

private DrawerLayout drawerLayout;
private NavigationView navigationView;
Expand Down Expand Up @@ -122,7 +133,11 @@ public boolean onNavigationItemSelected(MenuItem item) {
} else if (id == R.id.nav_user_define) {


} else if (id == R.id.nav_color_chooser) {
createColorChooserDialog();

} else if (id == R.id.nav_about) {
createLicenseDialog();

}

Expand All @@ -132,12 +147,48 @@ public boolean onNavigationItemSelected(MenuItem item) {

private void replaceFragment(int type) {
ZhuanlanView fragment = ZhuanlanView.newInstance(type);
// getSupportFragmentManager().beginTransaction().replace(R.id.content_main, fragment).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.app_bar_main, fragment).commit();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

private void createColorChooserDialog() {
new ColorChooserDialog.Builder(this, R.string.color_chooser_title)
.doneButton(R.string.md_done)
.cancelButton(R.string.md_cancel)
.allowUserColorInput(true)
.customButton(R.string.md_custom)
.show();
}

@Override
public void onColorSelection(@NonNull ColorChooserDialog dialog, @ColorInt int selectedColor) {
if (getSupportActionBar() != null)
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(selectedColor));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(CircleView.shiftColorDown(selectedColor));
getWindow().setNavigationBarColor(selectedColor);
}
if (!dialog.isAccentMode()) {
ColorUtil.setColor(this, selectedColor);
}
}

private void createLicenseDialog() {
Notices notices = new Notices();
notices.addNotice(new Notice("material-dialogs", "https://github.com/afollestad/material-dialogs", "Copyright (c) 2014-2016 Aidan Michael Follestad", new MITLicense()));
notices.addNotice(new Notice("okhttp", "https://github.com/square/okhttp", "Copyright 2016 Square, Inc.", new ApacheSoftwareLicense20()));
notices.addNotice(new Notice("gson", "https://github.com/google/gson", "Copyright 2008 Google Inc.", new ApacheSoftwareLicense20()));
notices.addNotice(new Notice("glide", "https://github.com/bumptech/glide", "Sam Judd - @sjudd on GitHub, @samajudd on Twitter", new ApacheSoftwareLicense20()));
notices.addNotice(new Notice("CircleImageView", "https://github.com/hdodenhof/CircleImageView", "Copyright 2014 - 2016 Henning Dodenhof", new ApacheSoftwareLicense20()));

new LicensesDialog.Builder(this)
.setNotices(notices)
.setIncludeOwnLicense(true)
.build()
.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.KeyEvent;
Expand All @@ -21,6 +20,7 @@

import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.meiji.daily.BaseActivity;
import com.meiji.daily.R;
import com.meiji.daily.utils.Api;

Expand All @@ -32,7 +32,7 @@
* Created by Meiji on 2016/11/22.
*/

public class PostsContentView extends AppCompatActivity implements View.OnClickListener, IPostsContent.View {
public class PostsContentView extends BaseActivity implements View.OnClickListener, IPostsContent.View {

private ImageView iv_header;
private Toolbar toolbar_title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.meiji.daily.BaseActivity;
import com.meiji.daily.R;
import com.meiji.daily.adapter.PostsListAdapter;
import com.meiji.daily.interfaces.IOnItemClickListener;
Expand All @@ -27,7 +27,7 @@
* Created by Meiji on 2016/11/18.
*/

public class PostsListView extends AppCompatActivity implements IPostsList.View, SwipeRefreshLayout.OnRefreshListener {
public class PostsListView extends BaseActivity implements IPostsList.View, SwipeRefreshLayout.OnRefreshListener {

private Toolbar toolbar; // 双击 toolbar 返回顶部 待写
private SwipeRefreshLayout refresh_layout;
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/meiji/daily/utils/ColorUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.meiji.daily.utils;

import android.content.Context;
import android.content.SharedPreferences;

import static android.content.Context.MODE_PRIVATE;

/**
* Created by Meiji on 2016/11/26.
*/

public class ColorUtil {

public static void setColor(Context context, int color) {
SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
prefs.edit().putInt("color", color).apply();
}

public static int getColor(Context context) {
SharedPreferences prefs = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
int defaultColor = -14776091;
return prefs.getInt("color", defaultColor);
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable-v21/ic_photo_color_chooser.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- drawable/autorenew.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#000"
android:pathData="M12,6V9L16,5L12,1V4A8,8 0 0,0 4,12C4,13.57 4.46,15.03 5.24,16.26L6.7,14.8C6.25,13.97 6,13 6,12A6,6 0 0,1 12,6M18.76,7.74L17.3,9.2C17.74,10.04 18,11 18,12A6,6 0 0,1 12,18V15L8,19L12,23V20A8,8 0 0,0 20,12C20,10.43 19.54,8.97 18.76,7.74Z"/>
</vector>
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_postscontent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

<ImageView
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/menu/activity_main_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@

<item android:title="@string/others">
<menu>
<item
android:id="@+id/nav_color_chooser"
android:icon="@drawable/ic_photo_color_chooser"
android:title="@string/nav_color_chooser"/>
<item
android:id="@+id/nav_about"
android:icon="@drawable/ic_photo_info"
android:title="@string/title_activity_about"/>
</menu>
</item>

</menu>
7 changes: 3 additions & 4 deletions app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:navigationBarColor">@color/primary</item>
<!--<item name="colorPrimary">@color/primary</item>-->
<!--<item name="colorPrimaryDark">@color/primary_dark</item>-->
<!--<item name="colorAccent">@color/accent</item>-->
</style>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,11 @@
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="network_error">网络不给力</string>
<string name="title_imageview">title image</string>
<string name="color_palette">选择颜色</string>
<string name="nav_color_chooser">切换主题</string>
<string name="color_chooser_title">选择主题颜色</string>
<string name="md_done">完成</string>
<string name="md_cancel">取消</string>
<string name="md_custom">自定义</string>

</resources>
7 changes: 3 additions & 4 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:navigationBarColor">@color/primary</item>
<!--<item name="colorPrimary">@color/primary</item>-->
<!--<item name="colorPrimaryDark">@color/primary_dark</item>-->
<!--<item name="colorAccent">@color/accent</item>-->
</style>

<style name="AppTheme.NoActionBar">
Expand Down

0 comments on commit e157951

Please sign in to comment.