Skip to content

Commit

Permalink
1.新增rx式带返回值的页面跳转
Browse files Browse the repository at this point in the history
  • Loading branch information
ychxx committed Oct 8, 2018
1 parent e2b5a86 commit 9cc69ad
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 19 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/yc/ycutils/SelectActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yc.ycutils;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
Expand All @@ -9,6 +11,8 @@
import com.yc.ycutilslibrary.action.YcActionTypeEnum;
import com.yc.ycutilslibrary.action.YcAction;

import java.io.File;

import butterknife.OnClick;

/**
Expand Down Expand Up @@ -39,6 +43,30 @@ void onClick(View view) {
TestPermissionActivity.newInstance(getActivity());
break;
case R.id.selectAction:
YcAction action= YcAction.newInstance(getActivity());
action.newActionSelector().setOpenFileType("*/*");
action.setResultSuccess((Intent path, YcActionTypeEnum actionTypeEnum)->{
// Intent intent = new Intent();
// ComponentName cn = new ComponentName("cn.wps.moffice_eng", "cn.wps.moffice.documentmanager.PreStartActivity2");
// intent.setAction(Intent.ACTION_MAIN);
// intent.setComponent(cn);
// intent.putExtra("aaa","lalla");
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// startActivity(intent);

Intent intent2 = new Intent();
Bundle bundle = new Bundle();
bundle.putString("OpenMode", "ReadOnly");//打开模式
// bundle.putBoolean("SendCloseBroad", true);//关闭是否发送广播
bundle.putString("ThirdPackage",getPackageName());//输入自己应用包名
bundle.putBoolean("ClearTrace", true);//删除打开记录
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent2.setAction(android.content.Intent.ACTION_VIEW);
intent2.setClassName("cn.wps.moffice_eng", "cn.wps.moffice.documentmanager.PreStartActivity");
intent2.setData(path.getData());
intent2.putExtras(bundle);
startActivity(intent2);
}).start();
// YcAction.newInstance(getActivity())
//// .newAction(YcActionTypeEnum.CAMERA)
// .newAction(YcActionTypeEnum.CROP)
Expand Down
10 changes: 6 additions & 4 deletions ycutilslibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.yc.ycutilslibrary" >
package="com.yc.ycutilslibrary">

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<application android:allowBackup="true">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<activity android:name=".action.YcCropActivity"/>

<activity android:name=".action.YcCropActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.yc.ycutilslibrary;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.support.annotation.IdRes;

import com.yc.ycutilslibrary.common.YcLog;
Expand All @@ -13,7 +15,7 @@
*/

public class YcUtilsInit {
public static Application mApplication = null;
private static Application mApplication = null;

/**
* 使用PrefHelper、下载必须先初始化
Expand All @@ -38,7 +40,18 @@ public static void setReloadImgNum(int num) {
}
YcImgUtils.IMG_FAIL_RELOAD_NUM = num;
}
public static void setLoadImgFail(@IdRes int imgIdRes){

public static void setLoadImgFail(@IdRes int imgIdRes) {
YcImgUtils.IMG_FAIL_ID_RES = imgIdRes;
}
public static Application getApplication(){
return mApplication;
}
public static Resources getResources() {
if (mApplication == null) {
return Resources.getSystem();
} else {
return mApplication.getResources();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.yc.ycutilslibrary.action.bean.YcActionSelectorBean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand Down Expand Up @@ -64,9 +65,10 @@ public void onExe(Fragment fragment) {
}, new YcActionFragment.Result() {
@Override
public void onCall(Fragment fragment, int requestCode, int resultCode, Intent data) {

if (resultCode == Activity.RESULT_OK && requestCode == currentActionBean.getRequestCode() || requestCode == EMPTY_REQUEST_CODE) {
if (mResultSuccess != null)
mResultSuccess.onSuccess(currentActionBean.result(data, fragment.getActivity()), currentActionBean.getActionType());
mResultSuccess.onSuccess(data, currentActionBean.getActionType());
} else {
if (mResultFail != null) {
mResultFail.onFail(currentActionBean.getActionType());
Expand All @@ -92,6 +94,7 @@ public interface ResultFail {
}

public interface ResultSuccess {
void onSuccess(String path, YcActionTypeEnum actionTypeEnum);
void onSuccess(Intent path, YcActionTypeEnum actionTypeEnum);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.yc.ycutilslibrary.action.YcActionUtils;
import com.yc.ycutilslibrary.common.YcTransform;

import java.util.Date;

/**
*
*/
Expand All @@ -27,7 +29,9 @@ public void setOpenFileType(String openFileType) {
public void start(Fragment fragment) {
YcActionUtils.openFileManager(fragment, openFileType, getActionType().getRequestCode());
}

public Intent result(Intent data) {
return data;
}
@Override
public String result(Intent data, Context context) {
return YcTransform.imgUriToAbsolutePath(context, data.getData());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.yc.ycutilslibrary.common;

import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;

import com.yc.yclibrary.YcInit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* 用于获取资源(需初始化YcUtilsInit.init(x))
*/

public class YcResources {

private static Resources getResources() {
return YcInit.getContext().getResources();
}

/**
* 获取颜色值
*
* @param resId 颜色资源id
* @return 颜色值
*/
public static int getColor(int resId) {
return getResources().getColor(resId);
}

/**
* 获取颜色值
*
* @param color 十六进制
* @return
*/
public static int getColor(String color) {
return Color.parseColor(color);
}

/**
* 获取Drawable
*
* @param resTd Drawable资源id
* @return Drawable
*/
public static Drawable getDrawable(int resTd) {
return getResources().getDrawable(resTd);
}

/**
* 获取字符串
*
* @param resId 字符串资源id
* @return 字符串
*/
public static String getString(int resId) {
return getResources().getString(resId);
}

/**
* 获取字符串数组
*
* @param resId 数组资源id
* @return 字符串数组
*/
public static String[] getStringArray(int resId) {
return getResources().getStringArray(resId);
}

/**
* 获取字符串数组
*
* @param resId 数组资源id
* @return 字符串数组
*/
public static List<String> getStringList(int resId) {
return Arrays.asList(getResources().getStringArray(resId));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.yc.ycutilslibrary.common;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;

import com.yc.yclibrary.YcInit;
import com.yc.ycutilslibrary.YcUtilsInit;

/**
*
*/
Expand All @@ -28,4 +38,57 @@ public static void hideStatusBar(Window window, boolean enable) {
window.setAttributes(p);
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

/**
* 将dp值转换为px值
*/
public static int dpToPx(float dp) {
return (int) (YcUtilsInit.getResources().getDisplayMetrics().density * dp + 0.5f);
}

/**
* 将px值转换为dp值
*/
public static int pxToDp(float px) {
return (int) (px / YcUtilsInit.getResources().getDisplayMetrics().density + 0.5f);
}

/**
* sp转px
*/
public static int spToPx(float sp) {
return (int) (sp * YcUtilsInit.getResources().getDisplayMetrics().scaledDensity + 0.5f);
}

/**
* px转sp
*/
public static int pxToSp(float px) {
return (int) (YcUtilsInit.getResources().getDisplayMetrics().scaledDensity / px + 0.5f);
}

/**
* 获取屏幕宽度 像素值
*/
public static int getScreenWidth() {
return getDisplayMetrics().widthPixels;
}

/**
* 获取屏幕高度 像素值
*/
public static int getScreenHegith() {
return getDisplayMetrics().heightPixels;
}

public static DisplayMetrics getDisplayMetrics() {
return getDisplayMetrics(YcUtilsInit.getApplication());
}

public static DisplayMetrics getDisplayMetrics(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public enum YcPrefHelper {
private SharedPreferences mPre;//SharedPreferences数据存储

YcPrefHelper() {
if (YcUtilsInit.mApplication == null) {
if (YcUtilsInit.getApplication() == null) {
Log.e("YcUtils", "请在Application的onCreate()里调用YcUtilsInit.init(application)进行初始化");
} else {
mPre = YcUtilsInit.mApplication.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
mPre = YcUtilsInit.getApplication().getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

public class YcUtilVersion {
public static int getVersionCode() {
if (YcUtilsInit.mApplication == null) {
if (YcUtilsInit.getApplication() == null) {
YcLog.e("请先初始化,YcUtilsInit.init(Application)");
return -1;
}
return getVersionCode(YcUtilsInit.mApplication);
return getVersionCode(YcUtilsInit.getApplication());
}

/**
Expand All @@ -47,11 +47,11 @@ public static int getVersionCode(Context context) {
}

public static String getVersionName() {
if (YcUtilsInit.mApplication == null) {
if (YcUtilsInit.getApplication() == null) {
YcLog.e("请先初始化,YcUtilsInit.init(Application)");
return "";
}
return getVersionName(YcUtilsInit.mApplication);
return getVersionName(YcUtilsInit.getApplication());
}

/**
Expand All @@ -73,11 +73,11 @@ public static String getVersionName(Context context) {
}

public static String getPackageName() {
if (YcUtilsInit.mApplication == null) {
if (YcUtilsInit.getApplication() == null) {
YcLog.e("请先初始化,YcUtilsInit.init(Application)");
return "";
}
return getPackageName(YcUtilsInit.mApplication);
return getPackageName(YcUtilsInit.getApplication());
}

/**
Expand Down
Loading

0 comments on commit 9cc69ad

Please sign in to comment.