提交 a5a74204 编写于 作者: B Blankj

see 06/28 log

上级 8d43ee95
......@@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "com.blankj.androidutilcode"
minSdkVersion 14
targetSdkVersion 16
targetSdkVersion 25
versionCode 41
versionName "1.7.1"
}
......@@ -57,6 +57,8 @@ dependencies {
compile "com.android.support:support-v4:$SUPPORT_VERSION"
compile "com.android.support:design:$SUPPORT_VERSION"
compile 'com.r0adkll:slidableactivity:2.0.5'
// LeakCanary
debugCompile "com.squareup.leakcanary:leakcanary-android:$LEAKCANARY_VERSION"
releaseCompile leakCanary
......
......@@ -52,6 +52,7 @@
<activity android:name=".activity.ActivityActivity"/>
<activity android:name=".activity.AppActivity"/>
<activity android:name=".activity.BarActivity"/>
<activity android:name=".activity.BarBranchActivity"/>
<activity android:name=".activity.CleanActivity"/>
<activity android:name=".activity.DeviceActivity"/>
<activity android:name=".activity.FragmentActivity"/>
......
......@@ -7,7 +7,7 @@ import android.widget.TextView;
import com.blankj.androidutilcode.Config;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.ActivityUtils;
/**
......@@ -18,7 +18,7 @@ import com.blankj.utilcode.util.ActivityUtils;
* desc : Activity工具类Demo
* </pre>
*/
public class ActivityActivity extends BaseDrawerActivity {
public class ActivityActivity extends BaseBackActivity {
private String imageActivityClassName;
......@@ -32,8 +32,11 @@ public class ActivityActivity extends BaseDrawerActivity {
return R.layout.activity_activity;
}
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_activity));
findViewById(R.id.btn_launch_image_activity).setOnClickListener(this);
TextView tvAboutActivity = (TextView) findViewById(R.id.tv_about_activity);
tvAboutActivity.setText("Is ImageActivity Exists: " + ActivityUtils.isActivityExists(Config.PKG, imageActivityClassName)
......
......@@ -7,7 +7,7 @@ import android.widget.TextView;
import com.blankj.androidutilcode.Config;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.blankj.utilcode.util.ToastUtils;
......@@ -21,7 +21,7 @@ import com.blankj.utilcode.util.ToastUtils;
* </pre>
*/
public class AppActivity extends BaseDrawerActivity {
public class AppActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -35,6 +35,8 @@ public class AppActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_app));
findViewById(R.id.btn_install_app).setOnClickListener(this);
findViewById(R.id.btn_install_app_silent).setOnClickListener(this);
findViewById(R.id.btn_uninstall_app).setOnClickListener(this);
......@@ -44,12 +46,12 @@ public class AppActivity extends BaseDrawerActivity {
TextView tvAboutApp = (TextView) findViewById(R.id.tv_about_app);
tvAboutApp.setText(
new SpanUtils()
.append("app icon: ").appendImage(AppUtils.getAppIcon(), SpanUtils.ALIGN_CENTER)
.appendLine("app icon: ").appendImage(AppUtils.getAppIcon(), SpanUtils.ALIGN_CENTER)
.appendLine(AppUtils.getAppInfo().toString())
.appendLine("isAppRoot: " + AppUtils.isAppRoot())
.appendLine("isAppDebug: " + AppUtils.isAppDebug())
.appendLine("AppSignatureSHA1: " + AppUtils.getAppSignatureSHA1())
.appendLine("isAppForeground: " + AppUtils.isAppForeground())
.append("isAppForeground: " + AppUtils.isAppForeground())
.create());
}
......
package com.blankj.androidutilcode.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.utilcode.util.BarUtils;
import java.util.Random;
import com.blankj.androidutilcode.base.BaseBackActivity;
/**
* <pre>
......@@ -21,18 +16,11 @@ import java.util.Random;
* desc :
* </pre>
*/
public class BarActivity extends BaseDrawerActivity {
private int mColor;
private int mAlpha;
private Random mRandom;
private TextView mTvStatusAlpha;
public class BarActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
mRandom = new Random();
mColor = ContextCompat.getColor(this, R.color.colorPrimary);
mAlpha = 112;
}
@Override
......@@ -42,30 +30,9 @@ public class BarActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
findViewById(R.id.btn_set_color).setOnClickListener(this);
mTvStatusAlpha = (TextView) findViewById(R.id.tv_status_alpha);
SeekBar sbChangeAlpha = (SeekBar) findViewById(R.id.sb_change_alpha);
sbChangeAlpha.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mAlpha = progress;
BarUtils.setColor(BarActivity.this, mColor, mAlpha);
mTvStatusAlpha.setText(String.valueOf(mAlpha));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
getSupportActionBar().setTitle(getString(R.string.demo_bar));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
sbChangeAlpha.setProgress(mAlpha);
updateStatusBar();
findViewById(R.id.btn_bar_color).setOnClickListener(this);
}
@Override
......@@ -76,15 +43,11 @@ public class BarActivity extends BaseDrawerActivity {
@Override
public void onWidgetClick(View view) {
switch (view.getId()) {
case R.id.btn_set_color:
mColor = 0xff000000 | mRandom.nextInt(0xffffff);
updateStatusBar();
case R.id.btn_bar_color:
Intent intent = new Intent(this, BarBranchActivity.class);
intent.putExtra("branch", BarBranchActivity.BRANCH_BAR_COLOR);
startActivity(intent);
break;
}
}
private void updateStatusBar() {
mToolbar.setBackgroundColor(mColor);
BarUtils.setColor(this, mColor, mAlpha);
}
}
package com.blankj.androidutilcode.activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.BarUtils;
import java.util.Random;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2017/05/27
* desc :
* </pre>
*/
public class BarBranchActivity extends BaseBackActivity
implements SeekBar.OnSeekBarChangeListener {
public static final String BRANCH_BAR_COLOR = "branch_bar_color";
private int mColor;
private int mAlpha;
private Random mRandom;
private TextView mTvStatusAlpha;
private String branch;
@Override
public void initData(Bundle bundle) {
branch = bundle.getString("branch");
mRandom = new Random();
mColor = ContextCompat.getColor(this, R.color.colorPrimary);
mAlpha = 112;
}
@Override
public int bindLayout() {
int layoutId = 0;
if (branch.equals(BRANCH_BAR_COLOR)) {
layoutId = R.layout.activity_bar_color;
}
return layoutId;
}
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_bar));
if (branch.equals(BRANCH_BAR_COLOR)) {
findViewById(R.id.btn_set_color).setOnClickListener(this);
mTvStatusAlpha = (TextView) findViewById(R.id.tv_status_alpha);
SeekBar sbChangeAlpha = (SeekBar) findViewById(R.id.sb_change_alpha);
sbChangeAlpha.setOnSeekBarChangeListener(this);
sbChangeAlpha.setProgress(mAlpha);
updateStatusBar();
}
}
@Override
public void doBusiness(Context context) {
}
@Override
public void onWidgetClick(View view) {
switch (view.getId()) {
case R.id.btn_set_color:
mColor = 0xff000000 | mRandom.nextInt(0xffffff);
updateStatusBar();
break;
}
}
private void updateStatusBar() {
mToolbar.setBackgroundColor(mColor);
BarUtils.setColor(this, mColor, mAlpha);
}
///////////////////////////////////////////////////////////////////////////
// OnSeekBarChangeListener
///////////////////////////////////////////////////////////////////////////
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mAlpha = progress;
BarUtils.setColor(BarBranchActivity.this, mColor, mAlpha);
mTvStatusAlpha.setText(String.valueOf(mAlpha));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
///////////////////////////////////////////////////////////////////////////
// OnSeekBarChangeListener
///////////////////////////////////////////////////////////////////////////
}
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.Button;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.CleanUtils;
import com.blankj.utilcode.util.ToastUtils;
......@@ -20,7 +20,7 @@ import java.io.File;
* desc : Clean工具类Demo
* </pre>
*/
public class CleanActivity extends BaseDrawerActivity {
public class CleanActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -34,6 +34,8 @@ public class CleanActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_clean));
Button btnCleanInternalCache = (Button) findViewById(R.id.btn_clean_internal_cache);
Button btnCleanInternalFiles = (Button) findViewById(R.id.btn_clean_internal_files);
Button btnCleanInternalDbs = (Button) findViewById(R.id.btn_clean_internal_databases);
......
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.DeviceUtils;
/**
......@@ -17,7 +17,7 @@ import com.blankj.utilcode.util.DeviceUtils;
* desc : Device工具类Demo
* </pre>
*/
public class DeviceActivity extends BaseDrawerActivity {
public class DeviceActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -31,6 +31,8 @@ public class DeviceActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_device));
findViewById(R.id.btn_shutdown).setOnClickListener(this);
findViewById(R.id.btn_reboot).setOnClickListener(this);
findViewById(R.id.btn_reboot_to_recovery).setOnClickListener(this);
......
......@@ -6,7 +6,7 @@ import android.support.v4.app.Fragment;
import android.view.View;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.androidutilcode.fragment.Demo0Fragment;
import com.blankj.utilcode.util.FragmentUtils;
......@@ -20,7 +20,7 @@ import java.util.ArrayList;
* desc : Fragment工具类Demo
* </pre>
*/
public class FragmentActivity extends BaseDrawerActivity {
public class FragmentActivity extends BaseBackActivity {
public Fragment rootFragment;
......@@ -36,7 +36,7 @@ public class FragmentActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_fragment));
}
@Override
......
......@@ -8,7 +8,7 @@ import android.view.View;
import android.widget.ImageView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.ImageUtils;
import com.blankj.utilcode.util.SizeUtils;
......@@ -20,7 +20,7 @@ import com.blankj.utilcode.util.SizeUtils;
* desc : Image工具类Demo
* </pre>
*/
public class ImageActivity extends BaseDrawerActivity {
public class ImageActivity extends BaseBackActivity {
private ImageView ivSrc;
private ImageView ivView2Bitmap;
......@@ -37,6 +37,8 @@ public class ImageActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_image));
ivSrc = (ImageView) findViewById(R.id.iv_src);
ivView2Bitmap = (ImageView) findViewById(R.id.iv_view2Bitmap);
ImageView ivRound = (ImageView) findViewById(R.id.iv_round);
......
......@@ -12,7 +12,7 @@ import android.widget.EditText;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.androidutilcode.dialog.KeyboardDialog;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
......@@ -25,7 +25,7 @@ import com.blankj.utilcode.util.LogUtils;
* desc : Keyboard工具类Demo
* </pre>
*/
public class KeyboardActivity extends BaseDrawerActivity {
public class KeyboardActivity extends BaseBackActivity {
TextView tvAboutKeyboard;
EditText etInput;
......@@ -43,6 +43,7 @@ public class KeyboardActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_keyboard));
etInput = (EditText) findViewById(R.id.et_input);
findViewById(R.id.btn_hide_soft_input).setOnClickListener(this);
findViewById(R.id.btn_show_soft_input).setOnClickListener(this);
......
......@@ -10,7 +10,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.androidutilcode.service.LocationService;
/**
......@@ -21,7 +21,7 @@ import com.blankj.androidutilcode.service.LocationService;
* desc : Location工具类Demo
* </pre>
*/
public class LocationActivity extends BaseDrawerActivity {
public class LocationActivity extends BaseBackActivity {
TextView tvAboutLocation;
LocationService mLocationService;
......@@ -38,6 +38,8 @@ public class LocationActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_location));
tvAboutLocation = (TextView) findViewById(R.id.tv_about_location);
tvAboutLocation.setText("lastLatitude: unknown"
+ "\nlastLongitude: unknown"
......
......@@ -8,7 +8,7 @@ import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.UtilsApp;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.LogUtils;
......@@ -21,7 +21,7 @@ import com.blankj.utilcode.util.LogUtils;
* </pre>
*/
public class LogActivity extends BaseDrawerActivity {
public class LogActivity extends BaseBackActivity {
private static final String TAG = "CMJ";
......@@ -85,6 +85,8 @@ public class LogActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_log));
findViewById(R.id.btn_toggle_log).setOnClickListener(this);
findViewById(R.id.btn_toggle_console).setOnClickListener(this);
findViewById(R.id.btn_toggle_tag).setOnClickListener(this);
......
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.NetworkUtils;
/**
......@@ -17,7 +17,7 @@ import com.blankj.utilcode.util.NetworkUtils;
* desc : Network工具类Demo
* </pre>
*/
public class NetworkActivity extends BaseDrawerActivity {
public class NetworkActivity extends BaseBackActivity {
private TextView tvAboutNetwork;
......@@ -33,6 +33,8 @@ public class NetworkActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_network));
tvAboutNetwork = (TextView) findViewById(R.id.tv_about_network);
findViewById(R.id.btn_open_wireless_settings).setOnClickListener(this);
findViewById(R.id.btn_set_wifi_enabled).setOnClickListener(this);
......
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.PhoneUtils;
/**
......@@ -17,7 +17,7 @@ import com.blankj.utilcode.util.PhoneUtils;
* desc : Phone工具类Demo
* </pre>
*/
public class PhoneActivity extends BaseDrawerActivity {
public class PhoneActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -31,6 +31,8 @@ public class PhoneActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_phone));
findViewById(R.id.btn_dial).setOnClickListener(this);
findViewById(R.id.btn_call).setOnClickListener(this);
findViewById(R.id.btn_send_sms).setOnClickListener(this);
......
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.PinyinUtils;
/**
......@@ -17,7 +17,7 @@ import com.blankj.utilcode.util.PinyinUtils;
* desc : Pinyin工具类Demo
* </pre>
*/
public class PinyinActivity extends BaseDrawerActivity {
public class PinyinActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -31,6 +31,8 @@ public class PinyinActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_pinyin));
TextView tvAboutPinyin = (TextView) findViewById(R.id.tv_about_pinyin);
tvAboutPinyin.setText("测试拼音工具类"
+ "\n转拼音: " + PinyinUtils.ccs2Pinyin("测试拼音工具类", " ")
......
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.ProcessUtils;
import java.util.Iterator;
......@@ -20,7 +20,7 @@ import java.util.Set;
* desc : Process工具类Demo
* </pre>
*/
public class ProcessActivity extends BaseDrawerActivity {
public class ProcessActivity extends BaseBackActivity {
private TextView tvAboutProcess;
......@@ -36,6 +36,8 @@ public class ProcessActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_process));
findViewById(R.id.btn_kill_all_background_processes).setOnClickListener(this);
tvAboutProcess = (TextView) findViewById(R.id.tv_about_process);
Set<String> set = ProcessUtils.getAllBackgroundProcesses();
......
......@@ -6,7 +6,7 @@ import android.view.View;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.SDCardUtils;
/**
......@@ -17,7 +17,7 @@ import com.blankj.utilcode.util.SDCardUtils;
* desc : SDCard工具类Demo
* </pre>
*/
public class SDCardActivity extends BaseDrawerActivity {
public class SDCardActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -31,6 +31,8 @@ public class SDCardActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_sdcard));
TextView tvAboutSdcard = (TextView) findViewById(R.id.tv_about_sdcard);
tvAboutSdcard.setText("isSDCardEnable: " + SDCardUtils.isSDCardEnable()
+ "\ngetDataPath: " + SDCardUtils.getDataPath()
......
......@@ -10,7 +10,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.SnackbarUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.blankj.utilcode.util.ToastUtils;
......@@ -23,7 +23,7 @@ import com.blankj.utilcode.util.ToastUtils;
* desc : Snackbar工具类Demo
* </pre>
*/
public class SnackbarActivity extends BaseDrawerActivity {
public class SnackbarActivity extends BaseBackActivity {
private View snackBarRootView;
......@@ -39,6 +39,8 @@ public class SnackbarActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_snackbar));
snackBarRootView = findViewById(android.R.id.content);
findViewById(R.id.btn_short_snackbar).setOnClickListener(this);
findViewById(R.id.btn_short_snackbar_with_action).setOnClickListener(this);
......
......@@ -21,7 +21,7 @@ import android.view.animation.LinearInterpolator;
import android.widget.TextView;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.androidutilcode.span.BlurMaskFilterSpan;
import com.blankj.androidutilcode.span.ForegroundAlphaColorSpan;
import com.blankj.androidutilcode.span.ForegroundAlphaColorSpanGroup;
......@@ -37,7 +37,7 @@ import com.blankj.utilcode.util.ToastUtils;
* desc : Span工具类Demo
* </pre>
*/
public class SpanActivity extends BaseDrawerActivity {
public class SpanActivity extends BaseBackActivity {
SpanUtils mSpanUtils;
SpannableStringBuilder animSsb;
......@@ -76,6 +76,8 @@ public class SpanActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_span));
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
......
......@@ -7,7 +7,7 @@ import android.view.Gravity;
import android.view.View;
import com.blankj.androidutilcode.R;
import com.blankj.androidutilcode.base.BaseDrawerActivity;
import com.blankj.androidutilcode.base.BaseBackActivity;
import com.blankj.utilcode.util.SpanUtils;
import com.blankj.utilcode.util.ToastUtils;
......@@ -19,7 +19,7 @@ import com.blankj.utilcode.util.ToastUtils;
* desc : Toast工具类Demo
* </pre>
*/
public class ToastActivity extends BaseDrawerActivity {
public class ToastActivity extends BaseBackActivity {
@Override
public void initData(Bundle bundle) {
......@@ -33,6 +33,8 @@ public class ToastActivity extends BaseDrawerActivity {
@Override
public void initView(Bundle savedInstanceState, View view) {
getSupportActionBar().setTitle(getString(R.string.demo_toast));
view.findViewById(R.id.btn_show_short_toast_safe).setOnClickListener(this);
view.findViewById(R.id.btn_show_short_toast).setOnClickListener(this);
view.findViewById(R.id.btn_show_long_toast_safe).setOnClickListener(this);
......
package com.blankj.androidutilcode.base;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
......@@ -14,7 +15,7 @@ import android.view.View;
* </pre>
*/
public abstract class BaseActivity extends AppCompatActivity
implements IView, View.OnClickListener {
implements IBaseView, View.OnClickListener {
/**
* 当前Activity渲染的视图View
......@@ -36,6 +37,7 @@ public abstract class BaseActivity extends AppCompatActivity
setBaseView();
initView(savedInstanceState, contentView);
doBusiness(this);
contentView.setBackgroundColor(Color.WHITE);
}
protected void setBaseView() {
......
package com.blankj.androidutilcode.base;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.widget.FrameLayout;
import com.blankj.androidutilcode.R;
import com.r0adkll.slidr.Slidr;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2017/06/27
* desc : DrawerActivity基类
* </pre>
*/
public abstract class BaseBackActivity extends BaseActivity {
protected Toolbar mToolbar;
@Override
protected void setBaseView() {
Slidr.attach(this);
contentView = LayoutInflater.from(this).inflate(R.layout.activity_back, null);
setContentView(contentView);
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.content_view);
frameLayout.addView(LayoutInflater.from(this).inflate(bindLayout(), frameLayout, false));
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
}
......@@ -18,7 +18,7 @@ import android.view.ViewGroup;
* </pre>
*/
public abstract class BaseFragment extends Fragment
implements IView, View.OnClickListener {
implements IBaseView, View.OnClickListener {
private static final String TAG = "BaseFragment";
......
......@@ -12,7 +12,7 @@ import android.view.View;
* desc :
* </pre>
*/
public interface IView {
interface IBaseView {
/**
* 初始化数据
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
......@@ -11,29 +10,8 @@
android:orientation="vertical"
android:padding="@dimen/spacing_16">
<TextView
android:id="@+id/tv_about_bar"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:id="@+id/tv_status_alpha"
style="@style/TextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<SeekBar
android:id="@+id/sb_change_alpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:padding="@dimen/spacing_8"/>
<Button
android:id="@+id/btn_set_color"
android:id="@+id/btn_bar_color"
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......@@ -12,18 +11,32 @@
android:padding="@dimen/spacing_16">
<TextView
android:id="@+id/tv_about_handler"
android:id="@+id/tv_about_bar"
style="@style/TextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:id="@+id/tv_status_alpha"
style="@style/TextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<SeekBar
android:id="@+id/sb_change_alpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:padding="@dimen/spacing_8"/>
<Button
android:id="@+id/btn_send_msg_after_3s"
android:id="@+id/btn_set_color"
style="@style/WideBtnStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/handler_send_msg_after_3s"/>
android:text="@string/bar_set_color"/>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......
......@@ -6,13 +6,9 @@
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
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">
......@@ -27,8 +23,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll"/>
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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">
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/fragment_container"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......
......@@ -6,8 +6,6 @@
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
......@@ -20,6 +18,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
app:headerLayout="@layout/nav_header"
app:menu="@menu/activity_main_drawer"/>
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
......
......@@ -3,8 +3,7 @@
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:fitsSystemWindows="true">
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
......@@ -141,11 +140,11 @@
android:text="@string/demo_network"/>
<!--<Button-->
<!--style="@style/WideBtnStyle"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:onClick="permissionClick"-->
<!--android:text="@string/demo_permission"/>-->
<!--style="@style/WideBtnStyle"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:onClick="permissionClick"-->
<!--android:text="@string/demo_permission"/>-->
<Button
style="@style/WideBtnStyle"
......@@ -187,7 +186,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="spannableClick"
android:text="@string/demo_spannable"/>
android:text="@string/demo_span"/>
<Button
style="@style/WideBtnStyle"
......
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#34A48E</color>
<color name="colorPrimaryDark">#1F8384</color>
<color name="colorPrimaryDark">#1D4B3F</color>
<color name="colorAccent">#FF4081</color>
<color name="white">#FFFFFF</color>
......
......@@ -30,7 +30,7 @@
<string name="demo_process">ProcessUtils Demo</string>
<string name="demo_sdcard">SDCardUtils Demo</string>
<string name="demo_snackbar">SnackbarUtils Demo</string>
<string name="demo_spannable">SpanUtils Demo</string>
<string name="demo_span">SpanUtils Demo</string>
<string name="demo_toast">ToastUtils Demo</string>
<!--Activity相关-->
......
......@@ -7,6 +7,10 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowAnimationStyle">@style/AnimationActivity</item>
<!--slider-->
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
......
* 17/06/28 增加返回键及右划返回
* 17/06/27 增加Toolbar
* 17/06/26 增加final参数
* 17/06/23 修改Demo主页
......
......@@ -64,5 +64,5 @@ dependencies {
testCompile "com.google.truth:truth:$TRUTH_VERSION"
testCompile "org.robolectric:robolectric:$ROBOLECTRIC_VERSION"
}
apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//gradlew bintrayUpload
......@@ -144,42 +144,36 @@ public final class EncodeUtils {
* @return Html编码后的字符串
*/
public static String htmlEncode(final CharSequence input) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return Html.escapeHtml(input);
} else {
// 参照Html.escapeHtml()中代码
StringBuilder out = new StringBuilder();
for (int i = 0, len = input.length(); i < len; i++) {
char c = input.charAt(i);
if (c == '<') {
out.append("&lt;");
} else if (c == '>') {
out.append("&gt;");
} else if (c == '&') {
out.append("&amp;");
} else if (c >= 0xD800 && c <= 0xDFFF) {
if (c < 0xDC00 && i + 1 < len) {
char d = input.charAt(i + 1);
if (d >= 0xDC00 && d <= 0xDFFF) {
i++;
int codepoint = 0x010000 | (int) c - 0xD800 << 10 | (int) d - 0xDC00;
out.append("&#").append(codepoint).append(";");
}
}
} else if (c > 0x7E || c < ' ') {
out.append("&#").append((int) c).append(";");
} else if (c == ' ') {
while (i + 1 < len && input.charAt(i + 1) == ' ') {
out.append("&nbsp;");
i++;
}
out.append(' ');
} else {
out.append(c);
}
StringBuilder sb = new StringBuilder();
char c;
for (int i = 0, len = input.length(); i < len; i++) {
c = input.charAt(i);
switch (c) {
case '<':
sb.append("&lt;"); //$NON-NLS-1$
break;
case '>':
sb.append("&gt;"); //$NON-NLS-1$
break;
case '&':
sb.append("&amp;"); //$NON-NLS-1$
break;
case '\'':
//http://www.w3.org/TR/xhtml1
// The named character reference &apos; (the apostrophe, U+0027) was
// introduced in XML 1.0 but does not appear in HTML. Authors should
// therefore use &#39; instead of &apos; to work as expected in HTML 4
// user agents.
sb.append("&#39;"); //$NON-NLS-1$
break;
case '"':
sb.append("&quot;"); //$NON-NLS-1$
break;
default:
sb.append(c);
}
return out.toString();
}
return sb.toString();
}
/**
......
......@@ -30,7 +30,7 @@ public class EncodeUtilsTest {
"<p>title 元素的内容会显示在浏览器的标题栏中。</p>" +
"</body>" +
"</html>";
String encodeHtml = "&lt;html&gt;&lt;head&gt;&lt;title&gt;&#25105;&#30340;&#31532;&#19968;&#20010; HTML &#39029;&#38754;&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;body &#20803;&#32032;&#30340;&#20869;&#23481;&#20250;&#26174;&#31034;&#22312;&#27983;&#35272;&#22120;&#20013;&#12290;&lt;/p&gt;&lt;p&gt;title &#20803;&#32032;&#30340;&#20869;&#23481;&#20250;&#26174;&#31034;&#22312;&#27983;&#35272;&#22120;&#30340;&#26631;&#39064;&#26639;&#20013;&#12290;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;";
String encodeHtml = "&lt;html&gt;&lt;head&gt;&lt;title&gt;我的第一个 HTML 页面&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;body 元素的内容会显示在浏览器中。&lt;/p&gt;&lt;p&gt;title 元素的内容会显示在浏览器的标题栏中。&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;";
@Test
public void testUrlEncode() throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册