Skip to content

Commit 8d43ee9

Browse files
committed
see 06/27 log
1 parent c894a8f commit 8d43ee9

File tree

6 files changed

+69
-47
lines changed

6 files changed

+69
-47
lines changed
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package com.blankj.androidutilcode.activity;
22

33
import android.content.Context;
4-
import android.content.Intent;
5-
import android.net.Uri;
64
import android.os.Bundle;
7-
import android.support.annotation.NonNull;
8-
import android.support.design.widget.NavigationView;
9-
import android.support.v4.widget.DrawerLayout;
10-
import android.support.v7.app.ActionBarDrawerToggle;
11-
import android.support.v7.widget.Toolbar;
12-
import android.view.MenuItem;
5+
import android.support.v4.content.ContextCompat;
136
import android.view.View;
7+
import android.widget.SeekBar;
8+
import android.widget.TextView;
149

1510
import com.blankj.androidutilcode.R;
1611
import com.blankj.androidutilcode.base.BaseDrawerActivity;
1712
import com.blankj.utilcode.util.BarUtils;
1813

14+
import java.util.Random;
15+
1916
/**
2017
* <pre>
2118
* author: Blankj
@@ -26,26 +23,16 @@
2623
*/
2724
public class BarActivity extends BaseDrawerActivity {
2825

29-
NavigationView.OnNavigationItemSelectedListener mListener = new NavigationView.OnNavigationItemSelectedListener() {
30-
@Override
31-
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
32-
switch (item.getItemId()) {
33-
case R.id.action_git_hub:
34-
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/Blankj/AndroidUtilCode")));
35-
break;
36-
case R.id.action_blog:
37-
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.jianshu.com/u/46702d5c6978")));
38-
break;
39-
}
40-
return false;
41-
}
42-
};
43-
44-
int alpha;
26+
private int mColor;
27+
private int mAlpha;
28+
private Random mRandom;
29+
private TextView mTvStatusAlpha;
4530

4631
@Override
4732
public void initData(Bundle bundle) {
48-
33+
mRandom = new Random();
34+
mColor = ContextCompat.getColor(this, R.color.colorPrimary);
35+
mAlpha = 112;
4936
}
5037

5138
@Override
@@ -55,15 +42,30 @@ public int bindLayout() {
5542

5643
@Override
5744
public void initView(Bundle savedInstanceState, View view) {
58-
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
59-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
60-
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
61-
setSupportActionBar(toolbar);
62-
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
63-
mDrawerLayout.addDrawerListener(toggle);
64-
toggle.syncState();
65-
BarUtils.setColor(this, getResources().getColor(R.color.colorPrimary));
66-
navigationView.setNavigationItemSelectedListener(mListener);
45+
findViewById(R.id.btn_set_color).setOnClickListener(this);
46+
mTvStatusAlpha = (TextView) findViewById(R.id.tv_status_alpha);
47+
SeekBar sbChangeAlpha = (SeekBar) findViewById(R.id.sb_change_alpha);
48+
49+
sbChangeAlpha.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
50+
@Override
51+
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
52+
mAlpha = progress;
53+
BarUtils.setColor(BarActivity.this, mColor, mAlpha);
54+
mTvStatusAlpha.setText(String.valueOf(mAlpha));
55+
}
56+
57+
@Override
58+
public void onStartTrackingTouch(SeekBar seekBar) {
59+
60+
}
61+
62+
@Override
63+
public void onStopTrackingTouch(SeekBar seekBar) {
64+
65+
}
66+
});
67+
sbChangeAlpha.setProgress(mAlpha);
68+
updateStatusBar();
6769
}
6870

6971
@Override
@@ -73,6 +75,16 @@ public void doBusiness(Context context) {
7375

7476
@Override
7577
public void onWidgetClick(View view) {
78+
switch (view.getId()) {
79+
case R.id.btn_set_color:
80+
mColor = 0xff000000 | mRandom.nextInt(0xffffff);
81+
updateStatusBar();
82+
break;
83+
}
84+
}
7685

86+
private void updateStatusBar() {
87+
mToolbar.setBackgroundColor(mColor);
88+
BarUtils.setColor(this, mColor, mAlpha);
7789
}
7890
}

app/src/main/java/com/blankj/androidutilcode/base/BaseDrawerActivity.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
public abstract class BaseDrawerActivity extends BaseActivity {
2626

27+
protected Toolbar mToolbar;
28+
2729
NavigationView.OnNavigationItemSelectedListener mListener = new NavigationView.OnNavigationItemSelectedListener() {
2830
@Override
2931
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@@ -40,16 +42,16 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
4042
};
4143

4244
@Override
43-
public void setBaseView() {
45+
protected void setBaseView() {
4446
contentView = LayoutInflater.from(this).inflate(R.layout.activity_drawer, null);
4547
setContentView(contentView);
4648
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.content_view);
4749
frameLayout.addView(LayoutInflater.from(this).inflate(bindLayout(), frameLayout, false));
4850
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
49-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
51+
mToolbar = (Toolbar) findViewById(R.id.toolbar);
5052
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
51-
setSupportActionBar(toolbar);
52-
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
53+
setSupportActionBar(mToolbar);
54+
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
5355
mDrawerLayout.addDrawerListener(toggle);
5456
toggle.syncState();
5557
navigationView.setNavigationItemSelectedListener(mListener);

app/src/main/java/com/blankj/androidutilcode/base/BaseFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* </pre>
1919
*/
2020
public abstract class BaseFragment extends Fragment
21-
implements IView,View.OnClickListener {
21+
implements IView, View.OnClickListener {
2222

2323
private static final String TAG = "BaseFragment";
2424

app/src/main/res/layout/activity_bar.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="match_parent">
56

@@ -17,10 +18,18 @@
1718
android:layout_height="wrap_content"
1819
android:gravity="center"/>
1920

21+
<TextView
22+
android:id="@+id/tv_status_alpha"
23+
style="@style/TextStyle"
24+
android:layout_width="wrap_content"
25+
android:layout_height="wrap_content"
26+
android:layout_gravity="center_horizontal"/>
27+
2028
<SeekBar
2129
android:id="@+id/sb_change_alpha"
2230
android:layout_width="match_parent"
2331
android:layout_height="wrap_content"
32+
android:max="255"
2433
android:padding="@dimen/spacing_8"/>
2534

2635
<Button

app/src/main/res/layout/app_bar_main.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<android.support.design.widget.CoordinatorLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
5-
xmlns:toolbar="http://schemas.android.com/tools"
65
android:layout_width="match_parent"
76
android:layout_height="match_parent"
87
android:fitsSystemWindows="true">
@@ -141,12 +140,12 @@
141140
android:onClick="networkClick"
142141
android:text="@string/demo_network"/>
143142

144-
<Button
145-
style="@style/WideBtnStyle"
146-
android:layout_width="match_parent"
147-
android:layout_height="wrap_content"
148-
android:onClick="permissionClick"
149-
android:text="@string/demo_permission"/>
143+
<!--<Button-->
144+
<!--style="@style/WideBtnStyle"-->
145+
<!--android:layout_width="match_parent"-->
146+
<!--android:layout_height="wrap_content"-->
147+
<!--android:onClick="permissionClick"-->
148+
<!--android:text="@string/demo_permission"/>-->
150149

151150
<Button
152151
style="@style/WideBtnStyle"

app/src/main/res/values/dimens.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<dimen name="spacing_8">8dp</dimen>
55
<dimen name="spacing_16">16dp</dimen>
6-
<dimen name="spacing_24">23dp</dimen>
6+
<dimen name="spacing_24">24dp</dimen>
77

88
<dimen name="font_40">40sp</dimen>
99
<dimen name="font_26">26sp</dimen>

0 commit comments

Comments
 (0)