Skip to content

Commit

Permalink
搜索关键字变红
Browse files Browse the repository at this point in the history
  • Loading branch information
qiushi123 committed Feb 15, 2016
1 parent e45c52f commit 44bf0c0
Show file tree
Hide file tree
Showing 53 changed files with 4,373 additions and 37 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ repositories {
jcenter()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile files('libs/brokenview.jar')
}
15 changes: 15 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@
</intent-filter>
</activity>
<activity android:name=".MainActivity2">
<!--模糊背景界面-->
</activity>
<activity android:name=".MainActivity_Blur">
</activity>
<activity android:name=".MainActivity_Broken">
</activity>

<!--textview中制定字段变红-->
<activity android:name=".MainActivityColor">
</activity>

<!--3d滚动的listview-->
<activity android:name=".MainActivity3DListview">
</activity>
<!--搜索结果中指定字段变色-->
<activity android:name=".MainActivitySearchTextColor"/>
</application>

</manifest>
54 changes: 35 additions & 19 deletions app/src/main/java/com/testdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,46 @@
import android.os.Bundle;
import android.view.View;

import com.testdemo.blurbehind.BlurBehind;
import com.testdemo.blurbehind.OnBlurCompleteListener;

public class MainActivity extends Activity {
public class MainActivity extends Activity implements View.OnClickListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.dummy_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

BlurBehind.getInstance().execute(MainActivity.this, new OnBlurCompleteListener() {
@Override
public void onBlurComplete() {
Intent intent = new Intent(MainActivity.this, MainActivity2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

startActivity(intent);
}
});
}
});

findViewById(R.id.button1).setOnClickListener(this);
findViewById(R.id.button2).setOnClickListener(this);
findViewById(R.id.button3).setOnClickListener(this);
findViewById(R.id.button4).setOnClickListener(this);
findViewById(R.id.button5).setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
Intent intent = new Intent(this, MainActivity_Blur.class);
startActivity(intent);
break;

case R.id.button2:
intent = new Intent(this, MainActivity_Broken.class);
startActivity(intent);
break;

case R.id.button3:
intent = new Intent(this, MainActivityColor.class);
startActivity(intent);
break;

case R.id.button4:
intent = new Intent(this, MainActivity3DListview.class);
startActivity(intent);
break;
case R.id.button5:
intent = new Intent(this, MainActivitySearchTextColor.class);
startActivity(intent);
break;
}
}
}
148 changes: 148 additions & 0 deletions app/src/main/java/com/testdemo/MainActivity2.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package com.testdemo;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import com.testdemo.blurbehind.BlurBehind;
import com.testdemo.broken_lib.BrokenCallback;
import com.testdemo.broken_lib.BrokenTouchListener;
import com.testdemo.broken_lib.BrokenView;

public class MainActivity2 extends Activity {

private RelativeLayout background;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -17,5 +29,141 @@ protected void onCreate(Bundle savedInstanceState) {
.withAlpha(50)
.withFilterColor(Color.parseColor("#0075c0"))
.setBackground(this);
background = (RelativeLayout) findViewById(R.id.background);
initBroken();
}

public static class MyView extends View {
private Paint paint;
private final float DENSITY = Resources.getSystem().getDisplayMetrics().density;

public MyView(Context context) {
this(context, null);
}

public MyView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// If don't close hardware acceleration int Android 4.4,
// the ViewGroup will not clip canvas for child when create bitmap from it(R.id.demo_parent)
// therefore the canvas has wrong width and height.
setLayerType(View.LAYER_TYPE_HARDWARE, null);
paint = new Paint();
}

@Override
protected void onDraw(Canvas canvas) {

int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
paint.setStyle(Paint.Style.FILL);
paint.setColor(0xffff0000);
canvas.drawRect(dp2px(16), dp2px(16), dp2px(50), dp2px(50), paint);
paint.setColor(0xffcc9900);
canvas.drawRect(dp2px(100), dp2px(16), dp2px(133), dp2px(50), paint);
paint.setColor(0xff00ff00);
canvas.drawRect(dp2px(16), dp2px(106), dp2px(50), dp2px(140), paint);
paint.setColor(0xff6600ff);
canvas.drawRect(dp2px(100), dp2px(106), dp2px(133), dp2px(140), paint);

canvas.translate(canvasWidth / 2, canvasHeight / 2);
paint.setStrokeWidth(3);
paint.setStyle(Paint.Style.STROKE);
paint.setTextSize(dp2px(18));
paint.setColor(0xffffff00);
canvas.drawText("Custom View", -dp2px(53), dp2px(3), paint);
}

private int dp2px(int dp) {
return Math.round(dp * DENSITY);
}


}

// 下面是破冰效果
private BrokenView mBrokenView;
private BrokenTouchListener colorfulListener;
private BrokenTouchListener whiteListener;
private Paint whitePaint;

// mBrokenView.setEnable(false);//设置不具备破冰效果
private void initBroken() {
mBrokenView = BrokenView.add2Window(this);

whitePaint = new Paint();
whitePaint.setColor(0xffffffff);//裂缝颜色

colorfulListener = new BrokenTouchListener.Builder(mBrokenView).
build();

whiteListener = new BrokenTouchListener.Builder(mBrokenView).
setComplexity(50).//破裂成8块
setBreakDuration(500).//破裂持续事件
setFallDuration(1000).//掉下时间
setCircleRiftsRadius(100).//裂纹宽度
// setEnableArea(button).//作用域,只有点击button按钮时才会有破冰效果
// setEnableArea(back).//作用域,只有点击button按钮时才会有破冰效果
setPaint(whitePaint).
build();
// cancel.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// return false;
// }
// });
// cancel.setClickable(false);
/*下面代码用来设置一些自定义破冰事件
BrokenTouchListener.Builder(brokenView).
setComplexity(...). // default 12
setBreakDuration(...). // in milliseconds, default 700ms
setFallDuration(...). // in milliseconds, default 2000ms
setCircleRiftsRadius(...). // in dp, default 66dp, you can disable circle-rifts effect by set it to 0
setEnableArea(...). // set the region or childview that can enable break effect,
// be sure the childView or childView in region doesn't intercept any touch event
setPaint(...). build(); // the paint to draw rifts*/


background.setOnTouchListener(whiteListener);

mBrokenView.setCallback(new MyCallBack());

}

// 下面是用来监听破冰效果的进度
private class MyCallBack extends BrokenCallback {
@Override
public void onStart(View v) {
// showCallback(v, "onStart");
}

@Override
public void onCancel(View v) {
// showCallback(v, "onCancel");
}

@Override
public void onRestart(View v) {
// showCallback(v, "onRestart");
}

@Override
public void onFalling(View v) {
// showCallback(v, "onFalling");
}

@Override
public void onFallingEnd(View v) {
// showCallback(v, "onFallingEnd");
finish();
}

@Override
public void onCancelEnd(View v) {
// showCallback(v, "onCancelEnd");
}
}
}
Loading

0 comments on commit 44bf0c0

Please sign in to comment.