You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.4 KiB
104 lines
3.4 KiB
/*
|
|
* Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
package com.arialyy.simple.activity;
|
|
|
|
import android.Manifest;
|
|
import android.content.Intent;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.support.v7.widget.Toolbar;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import butterknife.Bind;
|
|
import com.arialyy.frame.permission.OnPermissionCallback;
|
|
import com.arialyy.frame.permission.PermissionManager;
|
|
import com.arialyy.frame.util.show.T;
|
|
import com.arialyy.simple.R;
|
|
import com.arialyy.simple.base.BaseActivity;
|
|
import com.arialyy.simple.databinding.ActivityMainBinding;
|
|
import com.arialyy.simple.dialog.DownloadDialog;
|
|
import com.arialyy.simple.pop.DownloadPopupWindow;
|
|
|
|
/**
|
|
* Created by Lyy on 2016/10/13.
|
|
*/
|
|
public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
|
@Bind(R.id.toolbar) Toolbar mBar;
|
|
@Bind(R.id.single_task) Button mSigleBt;
|
|
@Bind(R.id.multi_task) Button mMultiBt;
|
|
@Bind(R.id.dialog_task) Button mDialogBt;
|
|
@Bind(R.id.pop_task) Button mPopBt;
|
|
|
|
@Override protected int setLayoutId() {
|
|
return R.layout.activity_main;
|
|
}
|
|
|
|
@Override protected void init(Bundle savedInstanceState) {
|
|
super.init(savedInstanceState);
|
|
setSupportActionBar(mBar);
|
|
mBar.setTitle("多线程多任务下载");
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
setEnable(true);
|
|
} else { //6.0处理
|
|
boolean hasPermission = PermissionManager.getInstance()
|
|
.checkPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
if (hasPermission) {
|
|
setEnable(true);
|
|
} else {
|
|
setEnable(false);
|
|
PermissionManager.getInstance().requestPermission(this, new OnPermissionCallback() {
|
|
@Override public void onSuccess(String... permissions) {
|
|
setEnable(true);
|
|
}
|
|
|
|
@Override public void onFail(String... permissions) {
|
|
T.showShort(MainActivity.this, "没有文件读写权限");
|
|
setEnable(false);
|
|
}
|
|
}, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void setEnable(boolean enable) {
|
|
mSigleBt.setEnabled(enable);
|
|
mMultiBt.setEnabled(enable);
|
|
mDialogBt.setEnabled(enable);
|
|
mPopBt.setEnabled(enable);
|
|
}
|
|
|
|
public void onClick(View view) {
|
|
switch (view.getId()) {
|
|
case R.id.single_task:
|
|
startActivity(new Intent(this, SingleTaskActivity.class));
|
|
break;
|
|
case R.id.multi_task:
|
|
startActivity(new Intent(this, MultiTaskActivity.class));
|
|
break;
|
|
case R.id.dialog_task:
|
|
DownloadDialog dialog = new DownloadDialog(this);
|
|
dialog.show();
|
|
break;
|
|
case R.id.pop_task:
|
|
DownloadPopupWindow pop = new DownloadPopupWindow(this);
|
|
//pop.showAsDropDown(mRootView);
|
|
pop.showAtLocation(mRootView, Gravity.CENTER_VERTICAL, 0, 0);
|
|
break;
|
|
}
|
|
}
|
|
} |