Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:theme="@style/CjjBaseTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/CjjBaseTheme.WhiteActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
67 changes: 9 additions & 58 deletions app/src/main/java/com/example/blockcanary/DemoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -13,23 +14,20 @@
import java.io.FileInputStream;
import java.io.IOException;

public class DemoActivity extends Activity implements View.OnClickListener {
public class DemoActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_demo);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("BlockCanary");
// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// toolbar.setTitle("BlockCanary");

Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);

button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
getSupportFragmentManager().beginTransaction()
.add(R.id.container, DemoFragment.newInstance())
.commit();

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
Expand All @@ -44,7 +42,7 @@ private void showTipDlg() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Tip");
builder.setMessage(getResources().getString(R.string.hello_world));
builder.setNegativeButton("cancel",null);
builder.setNegativeButton("ok",null);
builder.show();
}

Expand All @@ -70,52 +68,5 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case R.id.button2:
for (int i = 0; i < 100; ++i) {
readFile();
}
break;
case R.id.button3:
double result = compute();
System.out.println(result);
break;
}
}

private double compute() {
double result = 0;
for (int i = 0; i < 1000000; ++i) {
result += Math.acos(Math.cos(i));
result -= Math.asin(Math.sin(i));
}
return result;
}

private void readFile() {
FileInputStream reader = null;
try {
reader = new FileInputStream("/proc/stat");
while (reader.read() != -1);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
105 changes: 105 additions & 0 deletions app/src/main/java/com/example/blockcanary/DemoFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.example.blockcanary;

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 android.widget.Button;

import java.io.FileInputStream;
import java.io.IOException;


public class DemoFragment extends Fragment implements View.OnClickListener{

public static DemoFragment newInstance()
{
DemoFragment f = new DemoFragment();
return f;
}

@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Nullable
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_main,null);
return v;
}

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Button button1 = (Button) view.findViewById(R.id.button1);
Button button2 = (Button) view.findViewById(R.id.button2);
Button button3 = (Button) view.findViewById(R.id.button3);

button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
}

@Override
public void onDestroyView() {
super.onDestroyView();
}

@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case R.id.button2:
for (int i = 0; i < 100; ++i) {
readFile();
}
break;
case R.id.button3:
double result = compute();
System.out.println(result);
break;
}
}

private double compute() {
double result = 0;
for (int i = 0; i < 1000000; ++i) {
result += Math.acos(Math.cos(i));
result -= Math.asin(Math.sin(i));
}
return result;
}

private void readFile() {
FileInputStream reader = null;
try {
reader = new FileInputStream("/proc/stat");
while (reader.read() != -1);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
SplashActivity.this.setTheme(R.style.CjjBaseTheme_WhiteActivity);
super.onCreate(savedInstanceState);
startActivity(new Intent(this, DemoActivity.class));
SplashActivity.this.finish();
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/background_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@android:color/white"/>

<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>

</layer-list>
31 changes: 31 additions & 0 deletions app/src/main/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
android:orientation="vertical">

<View
android:id="@+id/view_state_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/state_bar_height"
android:background="@color/material_blue" />

<FrameLayout
android:layout_below="@+id/view_state_bar"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@drawable/ic_done"/>
</RelativeLayout>
22 changes: 15 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
android:layout_height="@dimen/top_bar_height"
android:background="@color/material_blue">


<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/app_name"
android:textColor="@android:color/white"
android:textSize="18sp"/>

</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-v19/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<dimen name="state_bar_height">25dp</dimen>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values-v19/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="CjjBaseTheme" parent="Base.Theme.DesignDemo">
<item name="android:windowTranslucentStatus">true</item>
</style>

</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-v21/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<dimen name="state_bar_height">25dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

<dimen name="state_bar_height">0dp</dimen>
<dimen name="top_bar_height">48dp</dimen>
<dimen name="top_bar_btn_wh">48dp</dimen>
<dimen name="divider_height">0.5dp</dimen>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">BlockCanary Demo</string>
<string name="app_name">BlockCanary</string>

<string name="hello_world">点击按钮后,会触发主线程耗时时间,从而被BlockCanary,并记录卡慢日志,弹出notification,可以点击对应消息查看</string>
<string name="thread_waiting">线程\n等待\n阻塞</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<style name="CjjBaseTheme" parent="Base.Theme.DesignDemo">
</style>

<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorAccent">#F44336</item>
Expand All @@ -12,7 +12,7 @@
</style>

<style name="CjjBaseTheme.WhiteActivity">
<item name="android:windowBackground">@color/material_blue</item>
<item name="android:windowBackground">@drawable/background_splash</item>
<item name="android:windowIsTranslucent">false</item>
</style>

Expand Down