AcharKit Framework
compile project(':acharkit-release-x.x.x')
or
implementation project(':acharkit-release-x.x.x')
Note : Helper classes have many methods that may not be used here
Note : after 0.1.1 version migrate from appcompat to androidx
Use AbstractActivity
yourActivity extends AbstractActivity
Use AbstractFragment
yourFragment extends AbstractFragment
Use your fragment
useFragment = new UseFragment();
useFragment.setTagId("tagId");
useFragment.actionFragment(R.id.frameLayout, AbstractFragment.TYPE_REPLACE / AbstractFragment.TYPE_ADD, addToBackStack);
Remove fragment from backStack
useFragment.removeFragmentPopBackStack();
Use TabPager
final TabPager tab = new TabPager(activity, R.id.viewPager, R.id.tabLayout);
tab.setOffscreenPageLimit(3); // optional
tab.setIndicatorColor(0xffffdd33); // optional
tab.setIndicatorHeight(4); // optional
tab.setTabItemColor(0xffff0033, 0xff00ee11); // optional
tab.add(useFragment0.setTagId(0), "One", R.mipmap.ic_launcher);
tab.add(useFragment1.setTagId(1), "Two", R.mipmap.ic_launcher);
tab.add(useFragment2.setTagId(2), "Three", R.mipmap.ic_launcher);
Use Tag
TagView tagView = findViewById(R.id.tag_view);
tagView.setGravity(Gravity.LEFT);
TestTagAdapter testTagAdapter = new TestTagAdapter(this);
final Tag tag = new Tag(this, R.id.tag_view, testTagAdapter);
for (int i = 0; i < 15; i++) {
j = i;
TestTagModel tagModel = new TestTagModel();
tagModel.setId(i);
tagModel.setTitle("# " + i);
arrayList.add(tagModel);
}
tag.addAll(arrayList);
Use BadgeView
badgeView = new BadgeView(context);
badgeView.setParentView(view);
badgeView.setNumber(54);
badgeView.setBadgeColor(Colour.RED, Colour.WHITE);
badgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
badgeView.setFont("OpenSans.ttf", Typeface.NORMAL);
badgeView.show();
Use BottomTab
BottomTab bottomTab = new BottomTab(this, R.id.frameLayout, R.id.bottom_tab);
UseFragment useFragment0 = new UseFragment();
UseFragment useFragment1 = new UseFragment();
UseFragment useFragment2 = new UseFragment();
useFragment0.setTags("First");
useFragment1.setTags("Second");
useFragment2.setTags("Third");
bottomTab.setEnableType(BottomTab.EnableType.TEXT_ANIMATION);
bottomTab.setFont("OpenSans.ttf", Typeface.BOLD);
bottomTab.setBackground(Color.LTGRAY);
bottomTab.setTabItemColor(Color.BLUE, Color.WHITE);
bottomTab.add(useFragment0, "test", android.R.drawable.stat_notify_more);
bottomTab.add(useFragment1, "test", android.R.drawable.stat_notify_chat);
bottomTab.add(useFragment2, "test", android.R.drawable.stat_notify_sync);
bottomTab.setDefaultTab(1);
Use DialogView
builder = new DialogView.Builder(TestDialog.this);
builder.setBackgroundColor(0xFF232323, 8)
.setBackgroundResource(R.mipmap.ic_launcher)
.setSize(0.8f, 0.8f)
.setFont("OpenSans.ttf", Typeface.NORMAL)
.setTitle("title", 5, 0xFFFFFFFF)
.setMessage("message", 5, 0xFFFFFFFF)
.setButtonsViewOrientation(LinearLayout.HORIZONTAL)
.addButton("button1", 5, 0xFF0A8A12, 0xFFFFFFFF, onClicklistenerOne(), Gravity.CENTER, 8)
.addDismissButton("dismiss", 5, 0xFFFF0000, 0xFFFFFFFF, Gravity.CENTER, 8)
.setCancelable(true)
.setCanceledOnTouchOutside(false)
.setOnCancelListener(onCancelListener())
.setOnDismissListener(onDismissListener())
.show();
Use Log
Log.setDebugMode(true);
Log.setAcharkitLog(true);
Log.i("tag","info");
Log.d("tag","debug");
Log.w("tag",throwable);
Log.e("tag",throwable,"error");
Use Permission Request
PermissionRequest permissionRequest = new PermissionRequest(fragment / activity, Manifest.permission.EXAMPLE);
permissionRequest.send();
Use Cache
Cache.setContext(context);
Cache.put("test_key", "test value");
Cache.get("test_key", "");
Use Crypt
Crypt crypt = new Crypt("yourKeyMustBeHave24Character");
String encrypted = crypt.encrypt("data");
String decrypted = crypt.decrypt(encrypted);
Use Connection Request
new ConnectionRequest.Builder(this, ConnectionRequest.Method.POST, "https://jsonplaceholder.typicode.com/posts")
.setHeader(header)
.setParameters(parameter)
.setTimeOut(60 * 2000)
.setOnRequestListener(new OnRequestListener() {
@Override
public void onSuccess(String response) {
Logger.d(TAG, "onSuccess: " + response);
Util.showToast(getApplicationContext(), response, Toast.LENGTH_SHORT);
}
@Override
public void onError(String error) {
Logger.d(TAG, "onError: " + error);
Util.showToast(getApplicationContext(), error, Toast.LENGTH_SHORT);
}
@Override
public void onCancel() {
Logger.d(TAG, "onCancel: " + "request cancelled");
Util.showToast(getApplicationContext(), "request cancelled", Toast.LENGTH_SHORT);
}
}).build().sendRequest();
Use Downloader
Map<String, String> header = new HashMap<>();
header.put("Access-Token", "1234567890ABC");
downloader = new Downloader.Builder(getApplicationContext(), "https://dl3.android30t.com/apps/Q-U/Instagram-v79.0.0.21.101(Android30t.Com).apk")
.setDownloadDir(String.valueOf(getExternalFilesDir("download")))
.setTimeOut(60 * 2000)
.setFileName("test_application", "apk")
.setHeader(header)
.setDownloadListener(new OnDownloadListener() {
@Override
public void onCompleted(File file) {
Logger.d(TAG, "onCompleted:");
Util.showToast(getApplicationContext(), "onCompleted", Toast.LENGTH_LONG);
}
@Override
public void onFailure(String reason) {
Logger.d(TAG, "onFailure:" + reason);
Util.showToast(getApplicationContext(), "onFailure:" + reason, Toast.LENGTH_LONG);
}
@Override
public void progressUpdate(int percent, int downloadedSize, int totalSize) {
Logger.d(TAG, "progressUpdate:" + percent);
}
@Override
public void onCancel() {
Logger.d(TAG, "onCancel:" + "canceled");
Util.showToast(getApplicationContext(), "onCancel:" + "canceled", Toast.LENGTH_LONG);
}
}).build();
startDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (checkNetworkAvailable(getActivity())) {
downloader.download();
}
}
});
stopDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (downloader != null) downloader.cancelDownload();
}
});
pauseDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (downloader != null) downloader.pauseDownload();
}
});
resumeDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (checkNetworkAvailable(getActivity())) {
downloader.resumeDownload();
}
}
});
Use ImageLoader
mageLoader.setImageLoaderListener(new OnImageLoaderListener() {
@Override
public void onStart(ImageView imageView, String url) {
Logger.d(TAG, "onStart:-- " + "imageView: " + imageView + "url: " + url);
}
@Override
public void onCompleted(ImageView imageView, String url, Bitmap bitmap) {
Logger.d(TAG, "onCompleted:-- " + "image: " + image.toString() + "response: " + imageView.toString());
}
@Override
public void onFailure(String reason) {
Logger.d(TAG, "onFailure:-- " + reason);
}
}).build().load(image, "http://www.xsjjys.com/data/out/60/WHDQ-512049955.png");
Use Progress
<ir.acharkit.android.component.progress.FadeProgress
android:id="@+id/fadeProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center" />
fadeProgress = findViewById(R.id.fadeProgress);
final Progress fade = new Progress(context)
.setProgress(fadeProgress)
.setColor(Progress.DEFAULT_COLOR);
fade.load();
Use GifView
<ir.acharkit.android.component.GifView
android:id="@+id/gifView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:GifHeight="1000"
app:GifWidth="1000"
app:repeatCount="-1" <-- infinity -->
app:src="@drawable/linux" />
final GifView gifView = findViewById(R.id.gifView);
gifView.loadResource(R.drawable.linux)
.setRepeatCount(GifView.INFINITE)
.setFullScreen(false);
Use Internet Connection
public boolean checkNetworkAvailable(Context context) {
return ConnectChecker.isInternetAvailable(context);
}
public int connectionType(Context context) {
return ConnectChecker.connectionType(context);
}
public String connectionTypeChecker(int connectionType) {
return ConnectChecker.connectionTypeChecker(connectionType);
}
Use Font
Font.fromAsset(context, "font.ttf", Typeface.NORMAL, view);
Font.setFontViewGroup(viewGroup, context, "font.ttf", Typeface.NORMAL);
Use Indicator Pager
<ir.acharkit.android.component.indicator.ViewPagerIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
...
...
app:delimiterSize="8dp"
app:itemIcon="@mipmap/ic_launcher"
app:itemSize="8dp"/>
final IndicatorPager indicatorPager = new IndicatorPager(this, R.id.viewPager, R.id.indicator);
indicatorPager.setOffscreenPageLimit(3);
indicatorPager.add(useFragment0.setTagId("0"));
Use Roster
<ir.acharkit.android.component.roster.RosterView
android:id="@+id/roster"
android:layout_width="match_parent"
android:layout_height="match_parent" />
TestRosterAdapter adapter = new TestRosterAdapter(this);
roster = new Carousel(this, R.id.roster, adapter);
roster.setOrientation(RosterView.HORIZONTAL, true);
roster.setAutoScroll(true, 5000, true);
roster.setScaleView(true);
for(int i = 0; i < 10; i++) {
TestRosterModel model = new TestRosterModel();
...
...
...
roster.add(model);
}
Use ConvertHelper
ConvertHelper.dpToPx(context, 5);
ConvertHelper.pixelsToDp(context, 5);
ConvertHelper.pxToSp(context, 5);
ConvertHelper.spToPx(context, 5);
ConvertHelper.stringToByte("data");
ConvertHelper.byteToString(new byte[16]);
Use Database
Database.init(this);
Database.getInstance().prepareDB("db.sqlite", 1);
Use DateTimeHelper
DateTimeHelper.currentDateTime("UTC");
DateTimeHelper.millisToStringDate(1509663266000L);
DateTimeHelper.dateStringToMillis("2017/11/02 22:54:26");
Use StringHelper
StringHelper.capitalizeString("this is test");
StringHelper.isEmpty("this is test");
StringHelper.isEmpty("");
StringHelper.isNotEmpty("this is test");
StringHelper.isNotEmpty("");
StringHelper.upperCaseFirst("this is test");
StringHelper.lowerCaseFirst("This is test");
StringHelper.SHA1("this is test");
Use ViewHelper
ViewHelper.setMargins(context, view, left, top, right, bottom);
ViewHelper.setFullScreen(activity);
Arrays.toString(ViewHelper.getScreenSize(activity));
ViewHelper.getScreenSize(activity);
ViewHelper.getScreenHeight(activity);
ViewHelper.getScreenWidth(activity);
ViewHelper.getSleepDuration(activity);
ViewHelper.isScreenLock(activity);
ViewHelper.isPortrait(activity);
ViewHelper.isLandscape(activity);
ViewHelper.isTablet(activity);
Use MimeHelper
MimeHelper.getFileExtensionFromUrl("image.test.jpg");
MimeHelper.hasExtension("jpg");
MimeHelper.hasMimeType("audio/aac");
MimeHelper.guessMimeTypeFromExtension(MimeHelper.getFileExtensionFromUrl("image.test.jpg"));
Use Util
Util.copyToClipboard(activity, "test", "clipboard copyToClipboard");
Util.isValidateEmail("test@example.com");
Util.arabicToDecimal("٠١٢٣٤٥٦٧٨٩");
Util.isValidPhoneNumberIran("09101234567");
Util.showToast(context, "show toast test", Toast.LENGTH_SHORT, backgroundColor, messageColor, Typeface.ITALIC, "OpenSans.ttf");
Util.showToast(context, "show toast test", Toast.LENGTH_SHORT, Typeface.ITALIC, "OpenSans.ttf");
Util.showToast(context, "show toast test", Toast.LENGTH_SHORT);