Skip to content

Feat/code style android #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi

SCRIPT_DIR=$(dirname "$0")
SCRIPT_ABS_PATH=`cd "$SCRIPT_DIR"; pwd`


ANDROID_DIFF_FILES=`git diff --cached --name-only --diff-filter=ACM -- '*' | grep 'Android'`
if [[ "$ANDROID_DIFF_FILES" != "" ]]
then
cd Android/APIExample
echo "precommit >> current paht = $(pwd), diff files = $ANDROID_DIFF_FILES"
./gradlew -Dorg.gradle.project.commit_diff_files="$ANDROID_DIFF_FILES" checkstyle detekt
if [ $? -eq 0 ]; then
echo "precommit >> checkstyle detekt OK."
else
echo "precommit >> checkstyle detekt Failed."
exit 1
fi
else
echo "precommit >> No changing android files."
fi


1 change: 1 addition & 0 deletions Android/APIExample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "${rootDir.absolutePath}/git-hooks.gradle"

def localSdkPath= "${rootProject.projectDir.absolutePath}/../../sdk"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import io.agora.api.example.common.model.GlobalSettings;
import io.agora.api.example.utils.ClassUtils;

/**
* The type Main application.
*/
public class MainApplication extends Application {

private GlobalSettings globalSettings;
Expand All @@ -34,14 +37,18 @@ private void initExamples() {
}
}
Examples.sortItem();
}
catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Gets global settings.
*
* @return the global settings
*/
public GlobalSettings getGlobalSettings() {
if(globalSettings == null){
if (globalSettings == null) {
globalSettings = new GlobalSettings();
}
return globalSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
* interface.
*/
public class MainFragment extends Fragment {
// TODO: Customize parameter argument names
// Customize parameter argument names
private static final String ARG_COLUMN_COUNT = "column-count";
// TODO: Customize parameters
// Customize parameters
private int mColumnCount = 1;
private OnListFragmentInteractionListener mListener;

Expand All @@ -44,7 +44,12 @@ public class MainFragment extends Fragment {
public MainFragment() {
}

// TODO: Customize parameter initialization
/**
* New instance main fragment.
*
* @param columnCount the column count
* @return the main fragment
*/
@SuppressWarnings("unused")
public static MainFragment newInstance(int columnCount) {
MainFragment fragment = new MainFragment();
Expand Down Expand Up @@ -114,7 +119,11 @@ public void onDetach() {
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
/**
* Update argument type and name.
*
* @param item the item
*/
void onListFragmentInteraction(Example item);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if(actionBar != null){
if (actionBar != null) {
actionBar.setTitle(exampleBean.getName());
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
Expand Down Expand Up @@ -106,8 +106,7 @@ private void runOnPermissionGranted(@NonNull Runnable runnable) {
// Request permission
AndPermission.with(this).runtime().permission(
permissionArray
).onGranted(permissions ->
{
).onGranted(permissions -> {
// Permissions Granted
runnable.run();
}).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author cjw
*/
public class SettingActivity extends AppCompatActivity{
public class SettingActivity extends AppCompatActivity {
private static final String TAG = SettingActivity.class.getSimpleName();

private ActivitySettingLayoutBinding mBinding;
Expand All @@ -31,24 +31,24 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mBinding.sdkVersion.setText(String.format(getString(R.string.sdkversion1), RtcEngine.getSdkVersion()));
String[] mItems = getResources().getStringArray(R.array.orientations);
String[] labels = new String[mItems.length];
for(int i = 0;i<mItems.length;i++){
int resId = getResources().getIdentifier( mItems[i], "string", getPackageName() );
for (int i = 0; i < mItems.length; i++) {
int resId = getResources().getIdentifier(mItems[i], "string", getPackageName());
labels[i] = getString(resId);
}
ArrayAdapter<String> arrayAdapter =new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, labels);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, labels);
mBinding.orientationSpinner.setAdapter(arrayAdapter);
fetchGlobalSettings();
}

private void fetchGlobalSettings(){
GlobalSettings globalSettings = ((MainApplication)getApplication()).getGlobalSettings();
private void fetchGlobalSettings() {
GlobalSettings globalSettings = ((MainApplication) getApplication()).getGlobalSettings();

String[] mItems = getResources().getStringArray(R.array.orientations);
String selectedItem = globalSettings.getVideoEncodingOrientation();
int i = 0;
if(selectedItem!=null){
for(String item : mItems){
if(selectedItem.equals(item)){
if (selectedItem != null) {
for (String item : mItems) {
if (selectedItem.equals(item)) {
break;
}
i++;
Expand All @@ -58,9 +58,9 @@ private void fetchGlobalSettings(){
mItems = getResources().getStringArray(R.array.fps);
selectedItem = globalSettings.getVideoEncodingFrameRate();
i = 0;
if(selectedItem!=null){
for(String item : mItems){
if(selectedItem.equals(item)){
if (selectedItem != null) {
for (String item : mItems) {
if (selectedItem.equals(item)) {
break;
}
i++;
Expand All @@ -70,9 +70,9 @@ private void fetchGlobalSettings(){
mItems = getResources().getStringArray(R.array.dimensions);
selectedItem = globalSettings.getVideoEncodingDimension();
i = 0;
if(selectedItem!=null){
for(String item : mItems){
if(selectedItem.equals(item)){
if (selectedItem != null) {
for (String item : mItems) {
if (selectedItem.equals(item)) {
break;
}
i++;
Expand All @@ -82,9 +82,9 @@ private void fetchGlobalSettings(){
mItems = getResources().getStringArray(R.array.areaCode);
selectedItem = globalSettings.getAreaCodeStr();
i = 0;
if(selectedItem!=null){
for(String item : mItems){
if(selectedItem.equals(item)){
if (selectedItem != null) {
for (String item : mItems) {
if (selectedItem.equals(item)) {
break;
}
i++;
Expand All @@ -111,7 +111,7 @@ public boolean onCreateOptionsMenu(@NonNull Menu menu) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == saveMenu.getItemId()) {
GlobalSettings globalSettings = ((MainApplication)getApplication()).getGlobalSettings();
GlobalSettings globalSettings = ((MainApplication) getApplication()).getGlobalSettings();
globalSettings.privateCloudIp = mBinding.privateCloudLayout.etIpAddress.getText().toString();
globalSettings.privateCloudLogReportEnable = mBinding.privateCloudLayout.swLogReport.isChecked();
globalSettings.privateCloudLogServerDomain = mBinding.privateCloudLayout.etLogServerDomain.getText().toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.agora.api.example.annotation;

import android.os.Parcelable;

import java.io.Serializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import io.agora.api.example.R;
import io.agora.api.example.databinding.FragmentBaseBrowserBinding;

/**
* The type Base browser fragment.
*/
public abstract class BaseBrowserFragment extends BaseFragment {

private FragmentBaseBrowserBinding mBinding;
Expand Down Expand Up @@ -122,7 +125,7 @@ public void handleOnBackPressed() {
// 不使用缓存,只从网络获取数据
// LOAD_CACHE_ONLY:
// 不使用网络,只读取本地缓存数据
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);// 设置缓存模式
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); // 设置缓存模式


// js 相关
Expand Down Expand Up @@ -153,7 +156,7 @@ public void handleOnBackPressed() {
// 支持同时打开https和http
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

mWebView.setWebChromeClient(new WebChromeClient(){
mWebView.setWebChromeClient(new WebChromeClient() {

@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Expand All @@ -175,7 +178,7 @@ public boolean onJsAlert(WebView view, String url, String message, JsResult resu

@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if(!request.getUrl().toString().equals(getBrowserUrl())){
if (!request.getUrl().toString().equals(getBrowserUrl())) {
openWithDefaultBrowser(request.getUrl().toString());
return true;
}
Expand Down Expand Up @@ -212,7 +215,7 @@ public void onReceivedError(WebView view, WebResourceRequest request, WebResourc
mWebView.setWebContentsDebuggingEnabled(true);
}

private void releaseWebView(){
private void releaseWebView() {
try {
Field sConfigCallback = Class.forName("android.webkit.BrowserFrame").getDeclaredField("sConfigCallback");
if (sConfigCallback != null) {
Expand Down Expand Up @@ -261,6 +264,11 @@ private void openWithDefaultBrowser(String url) {
startActivity(intent);
}

/**
* Gets browser url.
*
* @return the browser url
*/
protected abstract String getBrowserUrl();

}
Loading