BasicUsage - TonnyL/Charles GitHub Wiki
Start CharlesActivity from current Activity
or Fragment
:
Charles.from(this@MainActivity)
.choose()
.maxSelectable(9)
.progressRate(true)
.theme(R.style.Charles)
.imageEngine(GlideEngine())
.restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
.forResult(REQUEST_CODE_CHOOSE)
In onActivityResult()
callback of the starting Activity
or Fragment
:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == Activity.RESULT_OK) {
val uris = Charles.obtainResult(data)
val paths = Charles.obtainPathResult(data)
mAdapter.setData(uris, paths)
Log.d("uris", "$uris")
Log.d("paths", "$paths")
}
}
You can launch Matisse from Activity
or Fragment
. Meanwhile you should receive results in the corresponding onActivityResult()
callback.
Use maxSelectable(maxSelectable: Int)
to limit maximum selectable number.
Use progressRate(toShow: Boolean)
to show current selected progress rate or not.
Use restrictOrientation(orientation: Int)
to set the desired orientation of file selecting Activity. All the possible values are placed in class android.content.pm.ActivityInfo
.
Here are the details:
/**
* Constant corresponding to <code>unspecified</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_UNSPECIFIED = -1;
/**
* Constant corresponding to <code>landscape</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_LANDSCAPE = 0;
/**
* Constant corresponding to <code>portrait</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_PORTRAIT = 1;
/**
* Constant corresponding to <code>user</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_USER = 2;
/**
* Constant corresponding to <code>behind</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_BEHIND = 3;
/**
* Constant corresponding to <code>sensor</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_SENSOR = 4;
/**
* Constant corresponding to <code>nosensor</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_NOSENSOR = 5;
/**
* Constant corresponding to <code>sensorLandscape</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_SENSOR_LANDSCAPE = 6;
/**
* Constant corresponding to <code>sensorPortrait</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_SENSOR_PORTRAIT = 7;
/**
* Constant corresponding to <code>reverseLandscape</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8;
/**
* Constant corresponding to <code>reversePortrait</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9;
/**
* Constant corresponding to <code>fullSensor</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_FULL_SENSOR = 10;
/**
* Constant corresponding to <code>userLandscape</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_USER_LANDSCAPE = 11;
/**
* Constant corresponding to <code>userPortrait</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_USER_PORTRAIT = 12;
/**
* Constant corresponding to <code>fullUser</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_FULL_USER = 13;
/**
* Constant corresponding to <code>locked</code> in
* the {@link android.R.attr#screenOrientation} attribute.
*/
public static final int SCREEN_ORIENTATION_LOCKED = 14;