file_name stringlengths 6 86 | file_path stringlengths 45 249 | content stringlengths 47 6.26M | file_size int64 47 6.26M | language stringclasses 1 value | extension stringclasses 1 value | repo_name stringclasses 767 values | repo_stars int64 8 14.4k | repo_forks int64 0 1.17k | repo_open_issues int64 0 788 | repo_created_at stringclasses 767 values | repo_pushed_at stringclasses 767 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ProteusHorizontalProgressBar.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalProgressBar.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* HorizontalProgressBar
*
* @author aditya.sharat
*/
public class ProteusHorizontalProgressBar
extends com.flipkart.android.proteus.view.custom.HorizontalProgressBar implements ProteusView {
private Manager viewManager;
public ProteusHorizontalProgressBar(Context context) {
super(context);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,375 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusCheckBox.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusCheckBox.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* CheckBox
*
* @author aditya.sharat
*/
public class ProteusCheckBox extends android.widget.CheckBox implements ProteusView {
private Manager viewManager;
public ProteusCheckBox(Context context) {
super(context);
}
public ProteusCheckBox(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusCheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusCheckBox(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,814 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusFixedRatingBar.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusFixedRatingBar.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* FixedRatingBar
*
* @author aditya.sharat
*/
public class ProteusFixedRatingBar extends com.flipkart.android.proteus.view.custom.FixedRatingBar
implements ProteusView {
private Manager viewManager;
public ProteusFixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public ProteusFixedRatingBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusFixedRatingBar(Context context) {
super(context);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,617 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
UnknownViewGroup.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/UnknownViewGroup.java | package com.flipkart.android.proteus.view;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
public class UnknownViewGroup extends FrameLayout implements ProteusView {
private Manager manager;
private final UnknownView mView;
public UnknownViewGroup(@NonNull Context context) {
this(context, "");
}
public UnknownViewGroup(@NonNull Context context, String className) {
super(context);
mView = new UnknownView(context, className);
addView(mView, new LayoutParams(-2, -2, Gravity.CENTER));
}
@Override
public void addView(View child) {
super.addView(child);
mView.bringToFront();
}
@Override
public void addView(View child, int index) {
super.addView(child, index);
mView.bringToFront();
}
@Override
public void addView(View child, ViewGroup.LayoutParams params) {
super.addView(child, params);
mView.bringToFront();
}
@Override
public void addView(View child, int width, int height) {
super.addView(child, width, height);
mView.bringToFront();
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
mView.bringToFront();
}
@Override
public Manager getViewManager() {
return manager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.manager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,639 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusAndroidView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusAndroidView.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* View
*
* @author aditya.sharat
*/
public class ProteusAndroidView extends android.view.View implements ProteusView {
Manager viewManager;
public ProteusAndroidView(Context context) {
super(context);
}
public ProteusAndroidView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusAndroidView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusAndroidView(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,818 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusProgressBar.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusProgressBar.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* ProgressBar
*
* @author aditya.sharat
*/
public class ProteusProgressBar extends android.widget.ProgressBar implements ProteusView {
private Manager viewManager;
public ProteusProgressBar(Context context) {
super(context);
}
public ProteusProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusProgressBar(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,842 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusTextView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusTextView.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* TextView
*
* @author aditya.sharat
*/
public class ProteusTextView extends android.widget.TextView implements ProteusView {
private Manager viewManager;
public ProteusTextView(Context context) {
super(context);
}
public ProteusTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,814 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusLinearLayout.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusLinearLayout.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* LinearLayout
*
* @author aditya.sharat
*/
public class ProteusLinearLayout extends android.widget.LinearLayout implements ProteusView {
private Manager viewManager;
public ProteusLinearLayout(Context context) {
super(context);
}
public ProteusLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusLinearLayout(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,849 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusScrollView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusScrollView.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* ScrollView
*
* @author aditya.sharat
*/
public class ProteusScrollView extends android.widget.ScrollView implements ProteusView {
private Manager viewManager;
public ProteusScrollView(Context context) {
super(context);
}
public ProteusScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,828 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
UnknownView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/UnknownView.java | package com.flipkart.android.proteus.view;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
public class UnknownView extends TextView implements ProteusView {
private Manager mManager;
public UnknownView(Context context) {
this(context, "");
}
public UnknownView(Context context, String message) {
super(context);
setGravity(Gravity.CENTER);
setText(message);
}
@Override
public Manager getViewManager() {
return mManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
mManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 795 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusHorizontalScrollView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusHorizontalScrollView.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* HorizontalScrollView
*
* @author aditya.sharat
*/
public class ProteusHorizontalScrollView extends android.widget.HorizontalScrollView
implements ProteusView {
private Manager viewManager;
public ProteusHorizontalScrollView(Context context) {
super(context);
}
public ProteusHorizontalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusHorizontalScrollView(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,909 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusRelativeLayout.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusRelativeLayout.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* RelativeLayout
*
* @author aditya.sharat
*/
public class ProteusRelativeLayout extends android.widget.RelativeLayout implements ProteusView {
private Manager viewManager;
public ProteusRelativeLayout(Context context) {
super(context);
}
public ProteusRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusRelativeLayout(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,863 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusImageButton.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageButton.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* ImageButton
*
* @author aditya.sharat
*/
public class ProteusImageButton extends android.widget.ImageButton implements ProteusView {
private Manager viewManager;
public ProteusImageButton(Context context) {
super(context);
}
public ProteusImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusImageButton(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,842 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusWebView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusWebView.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* WebView
*
* @author aditya.sharat
*/
public class ProteusWebView extends android.webkit.WebView implements ProteusView {
private Manager viewManager;
public ProteusWebView(Context context) {
super(context);
}
public ProteusWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,807 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusImageView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/ProteusImageView.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusView;
/**
* ImageView
*
* @author aditya.sharat
*/
public class ProteusImageView extends android.widget.ImageView implements ProteusView {
private Manager viewManager;
public ProteusImageView(Context context) {
super(context);
}
public ProteusImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ProteusImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return viewManager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.viewManager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
}
| 1,821 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
HorizontalProgressBar.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/HorizontalProgressBar.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view.custom;
import android.content.Context;
import android.widget.ProgressBar;
/**
* HorizontalProgressBar
*
* @author Aditya Sharat
*/
public class HorizontalProgressBar extends ProgressBar {
public HorizontalProgressBar(Context context) {
super(context, null, android.R.attr.progressBarStyleHorizontal);
}
}
| 974 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
FixedRatingBar.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/FixedRatingBar.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view.custom;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.graphics.drawable.shapes.Shape;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.RatingBar;
/**
* Rating bar code is full of bugs. For width of rating bar to be set correctly, sample tile width
* should be set But since tilefy method is private and we are doing tile-fication ourselves, sample
* tile should be maintained by us Created by kirankumar on 04/12/14.
*/
public class FixedRatingBar extends RatingBar {
private Bitmap sampleTile;
public FixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public FixedRatingBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public FixedRatingBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FixedRatingBar(Context context) {
super(context);
}
public void setSampleTile(Bitmap bitmap) {
this.sampleTile = bitmap;
}
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (sampleTile != null) {
final int width = sampleTile.getWidth() * getNumStars();
setMeasuredDimension(resolveSize(width, widthMeasureSpec), getMeasuredHeight());
}
}
Shape getDrawableShape() {
final float[] roundedCorners = new float[] {5, 5, 5, 5, 5, 5, 5, 5};
return new RoundRectShape(roundedCorners, null, null);
}
/**
* Taken from AOSP !! Converts a drawable to a tiled version of itself. It will recursively
* traverse layer and state list drawables.
*/
public Drawable getTiledDrawable(Drawable drawable, boolean clip) {
if (drawable instanceof LayerDrawable) {
LayerDrawable background = (LayerDrawable) drawable;
final int N = background.getNumberOfLayers();
Drawable[] outDrawables = new Drawable[N];
for (int i = 0; i < N; i++) {
int id = background.getId(i);
outDrawables[i] =
getTiledDrawable(
background.getDrawable(i),
(id == android.R.id.progress || id == android.R.id.secondaryProgress));
}
LayerDrawable newBg = new LayerDrawable(outDrawables);
for (int i = 0; i < N; i++) {
newBg.setId(i, background.getId(i));
}
return newBg;
} else if (drawable instanceof BitmapDrawable) {
final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
if (sampleTile == null) {
sampleTile = tileBitmap;
}
final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
final BitmapShader bitmapShader =
new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
shapeDrawable.getPaint().setShader(bitmapShader);
return (clip)
? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL)
: shapeDrawable;
}
return drawable;
}
}
| 4,224 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusListView.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/ProteusListView.java | package com.flipkart.android.proteus.view.custom;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.UnknownView;
public class ProteusListView extends ListView implements ProteusView {
private Manager manager;
private String mLayoutPreviewName;
public ProteusListView(Context context) {
super(context);
}
public ProteusListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ProteusListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public ProteusListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public Manager getViewManager() {
return manager;
}
@Override
public void setViewManager(@NonNull Manager manager) {
this.manager = manager;
}
@NonNull
@Override
public View getAsView() {
return this;
}
public void setListItem(String layoutName) {
mLayoutPreviewName = layoutName;
setAdapter(new Adapter());
}
private class Adapter implements ListAdapter {
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public boolean isEnabled(int i) {
return true;
}
@Override
public void registerDataSetObserver(DataSetObserver dataSetObserver) {}
@Override
public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {}
@Override
public int getCount() {
if (mLayoutPreviewName == null) {
return 0;
}
return 12;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 1;
}
@Override
public boolean hasStableIds() {
return true;
}
@SuppressLint("ViewHolder")
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ProteusContext context = manager.getContext();
if (mLayoutPreviewName.equals(
manager.getDataContext().getData().getAsString("layout_name"))) {
return new UnknownView(context, "Unable to find layout: " + mLayoutPreviewName);
}
Layout layout = context.getLayout(mLayoutPreviewName);
if (layout == null) {
return new UnknownView(context, "Unable to find layout: " + mLayoutPreviewName);
}
return context.getInflater().inflate(layout, new ObjectValue()).getAsView();
}
@Override
public int getItemViewType(int i) {
return 0;
}
@Override
public int getViewTypeCount() {
return 1;
}
@Override
public boolean isEmpty() {
return mLayoutPreviewName == null;
}
}
}
| 3,224 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
AspectRatioFrameLayout.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/view/custom/AspectRatioFrameLayout.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.view.custom;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/** Created by kiran.kumar on 13/05/14. */
public class AspectRatioFrameLayout extends FrameLayout {
private int mAspectRatioWidth;
private int mAspectRatioHeight;
public AspectRatioFrameLayout(Context context) {
super(context);
}
public AspectRatioFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AspectRatioFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public AspectRatioFrameLayout(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (mAspectRatioHeight > 0 && mAspectRatioWidth > 0) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int originalWidth = getMeasuredWidth();
int originalHeight = getMeasuredHeight();
int finalWidth, finalHeight;
if (originalHeight == 0) {
finalHeight = originalWidth * mAspectRatioHeight / mAspectRatioWidth;
finalWidth = originalWidth;
} else if (originalWidth == 0) {
finalWidth = originalHeight * mAspectRatioWidth / mAspectRatioHeight;
finalHeight = originalHeight;
} else {
finalHeight = originalHeight;
finalWidth = originalWidth;
}
super.onMeasure(
MeasureSpec.makeMeasureSpec(finalWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY));
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setAspectRatioWidth(int mAspectRatioWidth) {
this.mAspectRatioWidth = mAspectRatioWidth;
}
public void setAspectRatioHeight(int mAspectRatioHeight) {
this.mAspectRatioHeight = mAspectRatioHeight;
}
}
| 2,738 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ParseHelper.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ParseHelper.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.value.Primitive;
import com.flipkart.android.proteus.value.Value;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
/**
* @author kiran.kumar
*/
public class ParseHelper {
private static final String TAG = "ParseHelper";
private static final String FALSE = "false";
private static final String VISIBLE = "visible";
private static final String INVISIBLE = "invisible";
private static final String GONE = "gone";
private static final String CENTER = "center";
private static final String CENTER_HORIZONTAL = "center_horizontal";
private static final String CENTER_VERTICAL = "center_vertical";
private static final String LEFT = "left";
private static final String RIGHT = "right";
private static final String TOP = "top";
private static final String BOTTOM = "bottom";
private static final String START = "start";
private static final String END = "end";
private static final String MIDDLE = "middle";
private static final String BEGINNING = "beginning";
private static final String MARQUEE = "marquee";
private static final String BOLD = "bold";
private static final String ITALIC = "italic";
private static final String BOLD_ITALIC = "bold|italic";
private static final String TEXT_ALIGNMENT_INHERIT = "inherit";
private static final String TEXT_ALIGNMENT_GRAVITY = "gravity";
private static final String TEXT_ALIGNMENT_CENTER = "center";
private static final String TEXT_ALIGNMENT_TEXT_START = "start";
private static final String TEXT_ALIGNMENT_TEXT_END = "end";
private static final String TEXT_ALIGNMENT_VIEW_START = "viewStart";
private static final String TEXT_ALIGNMENT_VIEW_END = "viewEnd";
private static final String TWEEN_LOCAL_RESOURCE_STR = "@anim/";
private static final String ID_STRING_START_PATTERN = "@+id/";
private static final String ID_STRING_START_PATTERN1 = "@id/";
private static final String ID_STRING_NORMALIZED_PATTERN = ":id/";
private static final Map<Integer, Primitive> sVisibilityMap = new HashMap<>();
private static final Map<String, Primitive> sGravityMap = new HashMap<>();
private static final Map<String, Integer> sDividerMode = new HashMap<>();
private static final Map<String, Enum> sEllipsizeMode = new HashMap<>();
private static final Map<String, Integer> sVisibilityMode = new HashMap<>();
private static final Map<String, Integer> sTextAlignment = new HashMap<>();
private static final Map<String, ImageView.ScaleType> sImageScaleType = new HashMap<>();
static {
sVisibilityMap.put(View.VISIBLE, new Primitive(View.VISIBLE));
sVisibilityMap.put(View.INVISIBLE, new Primitive(View.INVISIBLE));
sVisibilityMap.put(View.GONE, new Primitive(View.GONE));
sGravityMap.put(LEFT, new Primitive(Gravity.LEFT));
sGravityMap.put(RIGHT, new Primitive(Gravity.RIGHT));
sGravityMap.put(TOP, new Primitive(Gravity.TOP));
sGravityMap.put(BOTTOM, new Primitive(Gravity.BOTTOM));
sGravityMap.put(START, new Primitive(Gravity.START));
sGravityMap.put(END, new Primitive(Gravity.END));
sGravityMap.put(CENTER, new Primitive(Gravity.CENTER));
sGravityMap.put(CENTER_HORIZONTAL, new Primitive(Gravity.CENTER_HORIZONTAL));
sGravityMap.put(CENTER_VERTICAL, new Primitive(Gravity.CENTER_VERTICAL));
sDividerMode.put(END, LinearLayout.SHOW_DIVIDER_END);
sDividerMode.put(MIDDLE, LinearLayout.SHOW_DIVIDER_MIDDLE);
sDividerMode.put(BEGINNING, LinearLayout.SHOW_DIVIDER_BEGINNING);
sEllipsizeMode.put(END, TextUtils.TruncateAt.END);
sEllipsizeMode.put(START, TextUtils.TruncateAt.START);
sEllipsizeMode.put(MARQUEE, TextUtils.TruncateAt.MARQUEE);
sEllipsizeMode.put(MIDDLE, TextUtils.TruncateAt.MIDDLE);
sVisibilityMode.put(VISIBLE, View.VISIBLE);
sVisibilityMode.put(INVISIBLE, View.INVISIBLE);
sVisibilityMode.put(GONE, View.GONE);
sImageScaleType.put(CENTER, ImageView.ScaleType.CENTER);
sImageScaleType.put("center_crop", ImageView.ScaleType.CENTER_CROP);
sImageScaleType.put("center_inside", ImageView.ScaleType.CENTER_INSIDE);
sImageScaleType.put("fitCenter", ImageView.ScaleType.FIT_CENTER);
sImageScaleType.put("fit_xy", ImageView.ScaleType.FIT_XY);
sImageScaleType.put("matrix", ImageView.ScaleType.MATRIX);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
sTextAlignment.put(TEXT_ALIGNMENT_INHERIT, View.TEXT_ALIGNMENT_INHERIT);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
sTextAlignment.put(TEXT_ALIGNMENT_GRAVITY, View.TEXT_ALIGNMENT_GRAVITY);
sTextAlignment.put(TEXT_ALIGNMENT_CENTER, View.TEXT_ALIGNMENT_CENTER);
sTextAlignment.put(TEXT_ALIGNMENT_TEXT_START, View.TEXT_ALIGNMENT_TEXT_START);
sTextAlignment.put(TEXT_ALIGNMENT_TEXT_END, View.TEXT_ALIGNMENT_TEXT_END);
sTextAlignment.put(TEXT_ALIGNMENT_VIEW_START, View.TEXT_ALIGNMENT_VIEW_START);
sTextAlignment.put(TEXT_ALIGNMENT_VIEW_END, View.TEXT_ALIGNMENT_VIEW_END);
}
}
public static int parseInt(String attributeValue) {
int number;
if (ProteusConstants.DATA_NULL.equals(attributeValue)) {
return 0;
}
try {
number = Integer.parseInt(attributeValue);
} catch (NumberFormatException e) {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage());
}
number = 0;
}
return number;
}
public static IntResult parseIntUnsafe(String s) {
if (s == null) {
return new IntResult("null string");
}
int num;
final int len = s.length();
final char ch = s.charAt(0);
int d = ch - '0';
if (d < 0 || d > 9) {
return new IntResult("Malformed: " + s);
}
num = d;
int i = 1;
while (i < len) {
d = s.charAt(i++) - '0';
if (d < 0 || d > 9) {
return new IntResult("Malformed: " + s);
}
num *= 10;
num += d;
}
return new IntResult(null, num);
}
public static float parseFloat(String value) {
float number = 0;
if (null != value && value.length() > 0) {
try {
number = Float.parseFloat(value);
} catch (NumberFormatException e) {
number = 0;
}
}
return number;
}
public static float parseFloat(Value v) {
String value;
if (v.isPrimitive()) {
value = v.toString();
} else {
return 0;
}
return parseFloat(value);
}
public static double parseDouble(String attributeValue) {
double number;
if (ProteusConstants.DATA_NULL.equals(attributeValue)) {
return 0;
}
try {
number = Double.parseDouble(attributeValue);
} catch (NumberFormatException e) {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, attributeValue + " is NAN. Error: " + e.getMessage());
}
number = 0;
}
return number;
}
public static String parseViewId(String id) {
if (id.startsWith(ID_STRING_START_PATTERN)) {
return id.substring(ID_STRING_START_PATTERN.length());
}
if (id.startsWith(ID_STRING_START_PATTERN1)) {
return id.substring(ID_STRING_START_PATTERN1.length());
}
return id;
}
public static int parseGravity(String value) {
String[] gravities = value.split("\\|");
int returnGravity = Gravity.NO_GRAVITY;
for (String gravity : gravities) {
Primitive gravityValue = sGravityMap.get(gravity);
if (null != gravityValue) {
returnGravity |= gravityValue.getAsInt();
}
}
return returnGravity;
}
public static com.flipkart.android.proteus.value.Gravity getGravity(String value) {
return new com.flipkart.android.proteus.value.Gravity(parseGravity(value));
}
public static int parseDividerMode(String attributeValue) {
Integer returnValue = sDividerMode.get(attributeValue);
return returnValue == null ? LinearLayout.SHOW_DIVIDER_NONE : returnValue;
}
public static Enum parseEllipsize(String attributeValue) {
Enum returnValue = sEllipsizeMode.get(attributeValue);
return returnValue == null ? TextUtils.TruncateAt.END : returnValue;
}
public static int parseVisibility(@Nullable Value value) {
Integer returnValue = null;
if (null != value && value.isPrimitive()) {
String attributeValue = value.getAsString();
returnValue = sVisibilityMode.get(attributeValue);
if (null == returnValue
&& (attributeValue.isEmpty()
|| FALSE.equals(attributeValue)
|| ProteusConstants.DATA_NULL.equals(attributeValue))) {
returnValue = View.GONE;
}
} else //noinspection ConstantConditions
if (value.isNull()) {
returnValue = View.GONE;
}
return returnValue == null ? View.VISIBLE : returnValue;
}
public static Primitive getVisibility(int visibility) {
Primitive value = sVisibilityMap.get(visibility);
return null != value ? value : sVisibilityMap.get(View.GONE);
}
public static int parseColor(String color) {
try {
return Color.parseColor(color);
} catch (IllegalArgumentException ex) {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "Invalid color : " + color + ". Using #000000");
}
return Color.BLACK;
}
}
public static boolean parseBoolean(@Nullable Value value) {
// TODO: we should consider 0 as false too.
return null != value && value.isPrimitive() && value.getAsPrimitive().isBoolean()
? value.getAsBoolean()
: null != value && !value.isNull() && Boolean.parseBoolean(value.getAsString());
}
public static int parseRelativeLayoutBoolean(boolean value) {
return value ? RelativeLayout.TRUE : 0;
}
public static void addRelativeLayoutRule(View view, int verb, int anchor) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams instanceof RelativeLayout.LayoutParams) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layoutParams;
params.addRule(verb, anchor);
view.setLayoutParams(params);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "cannot add relative layout rules when container is not relative");
}
}
}
public static int parseTextStyle(String attributeValue) {
int typeface = Typeface.NORMAL;
if (attributeValue != null) {
attributeValue = attributeValue.toLowerCase();
switch (attributeValue) {
case BOLD:
typeface = Typeface.BOLD;
break;
case ITALIC:
typeface = Typeface.ITALIC;
break;
case BOLD_ITALIC:
typeface = Typeface.BOLD_ITALIC;
break;
default:
typeface = Typeface.NORMAL;
break;
}
}
return typeface;
}
public static boolean isTweenAnimationResource(String attributeValue) {
return attributeValue.startsWith(TWEEN_LOCAL_RESOURCE_STR);
}
/**
* Uses reflection to fetch the R.id from the given class. This method is faster than using {@link
* android.content.res.Resources#getResourceName(int)}
*
* @param variableName the name of the variable
* @param с The class
* @return resource id
*/
public static int getResId(String variableName, Class<?> с) {
Field field;
int resId = 0;
try {
field = с.getField(variableName);
resId = field.getInt(null);
} catch (Exception e) {
e.printStackTrace();
}
return resId;
}
/**
* Get int resource id, by just passing the string value of android:id from xml file. Note : This
* method only works for @android:id or @+android:id right now
*
* @param fullResIdString the string id of the view
* @return the number id of the view
*/
public static int getAndroidXmlResId(String fullResIdString) {
if (fullResIdString != null) {
int i = fullResIdString.indexOf("/");
if (i >= 0) {
String idString = fullResIdString.substring(i + 1);
return getResId(idString, android.R.id.class);
}
}
return View.NO_ID;
}
/**
* Parses a image view scale type
*
* @param attributeValue value of the scale type attribute
* @return {@link android.widget.ImageView.ScaleType} enum
*/
public static ImageView.ScaleType parseScaleType(String attributeValue) {
return !TextUtils.isEmpty(attributeValue) ? sImageScaleType.get(attributeValue) : null;
}
/**
* parses Text Alignment
*
* @param attributeValue value of the typeface attribute
* @return the text alignment value
*/
public static Integer parseTextAlignment(String attributeValue) {
return !TextUtils.isEmpty(attributeValue) ? sTextAlignment.get(attributeValue) : null;
}
public static class IntResult {
@Nullable public final String error;
public final int result;
public IntResult(@Nullable String error, int result) {
this.error = error;
this.result = result;
}
public IntResult(@Nullable String error) {
this.error = error;
this.result = -1;
}
}
}
| 14,182 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
MarginHelper.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/MarginHelper.java | package com.flipkart.android.proteus.parser;
import android.view.View;
import android.view.ViewGroup;
import java.util.HashMap;
import java.util.Map;
public class MarginHelper {
public static class Margins {
public int left;
public int top;
public int right;
public int bottom;
}
private static final Map<String, Margins> sMarginMap = new HashMap<>();
public static void setMarginLeft(View view, int d) {
sMarginMap.compute(
view.toString(),
(s, margins) -> {
if (margins == null) {
margins = new Margins();
}
margins.left = d;
return margins;
});
setMargins(view);
}
public static void setMarginTop(View view, int d) {
sMarginMap.compute(
view.toString(),
(s, margins) -> {
if (margins == null) {
margins = new Margins();
}
margins.top = d;
return margins;
});
setMargins(view);
}
public static void setMarginRight(View view, int d) {
sMarginMap.compute(
view.toString(),
(s, margins) -> {
if (margins == null) {
margins = new Margins();
}
margins.right = d;
return margins;
});
setMargins(view);
}
public static void setMarginBottom(View view, int d) {
sMarginMap.compute(
view.toString(),
(s, margins) -> {
if (margins == null) {
margins = new Margins();
}
margins.bottom = d;
return margins;
});
setMargins(view);
}
private static void setMargins(View view) {
Margins margins = sMarginMap.get(view.toString());
if (margins == null) {
return;
}
ViewGroup.MarginLayoutParams layoutParams =
(ViewGroup.MarginLayoutParams) view.getLayoutParams();
layoutParams.leftMargin = margins.left;
layoutParams.topMargin = margins.top;
layoutParams.rightMargin = margins.right;
layoutParams.bottomMargin = margins.bottom;
}
}
| 2,048 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
IncludeParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/IncludeParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.exceptions.ProteusInflateException;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Value;
import com.flipkart.android.proteus.view.UnknownView;
/**
* IncludeParser
*
* <p>TODO: merge the attributes into the included layout
*
* @author aditya.sharat
*/
public class IncludeParser<V extends View> extends ViewTypeParser<V> {
@NonNull
@Override
public String getType() {
return "include";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout include,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
if (include.extras == null) {
throw new IllegalArgumentException("required attribute 'layout' missing.");
}
Value type = include.extras.get(ProteusConstants.LAYOUT);
if (null == type || !type.isPrimitive()) {
throw new ProteusInflateException("required attribute 'layout' missing or is not a string");
}
String layoutName = type.getAsString();
if (layoutName.startsWith("@layout/")) {
layoutName = layoutName.substring("@layout/".length());
if (layoutName.equals(data.getAsString("layout_name"))) {
return new UnknownView(context, layoutName);
}
Layout layout = context.getLayout(layoutName);
if (null == layout) {
throw new ProteusInflateException("Layout '" + layoutName + "' not found");
}
return context.getInflater().inflate(layout.merge(include), data, parent, dataIndex);
} else {
throw new ProteusInflateException("Unknown value: " + layoutName);
}
}
@Override
protected void addAttributeProcessors() {}
}
| 2,889 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/ViewParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser;
import android.annotation.SuppressLint;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.Animation;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.AttributeProcessor;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.ColorResourceProcessor;
import com.flipkart.android.proteus.processor.DimensionAttributeProcessor;
import com.flipkart.android.proteus.processor.DrawableResourceProcessor;
import com.flipkart.android.proteus.processor.EventProcessor;
import com.flipkart.android.proteus.processor.GravityAttributeProcessor;
import com.flipkart.android.proteus.processor.ShapeAppearanceProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.processor.StyleResourceProcessor;
import com.flipkart.android.proteus.processor.TweenAnimationResourceProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Primitive;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
import com.flipkart.android.proteus.view.ProteusAndroidView;
import com.google.android.material.shape.ShapeAppearanceModel;
import com.google.android.material.shape.Shapeable;
import java.util.Map;
/**
* @author kiran.kumar
*/
public class ViewParser<V extends View> extends ViewTypeParser<V> {
private static final String TAG = "ViewParser";
private static final String ID_STRING_START_PATTERN = "@+id/";
private static final String ID_STRING_START_PATTERN1 = "@id/";
private static final String ID_STRING_NORMALIZED_PATTERN = ":id/";
@NonNull
@Override
public String getType() {
return "android.view.View";
}
@Nullable
@Override
public String getParentType() {
return null;
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusAndroidView(context);
}
@Override
protected void addAttributeProcessors() {
addLayoutParamsAttributeProcessor(
Attributes.View.Width,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams != null) {
layoutParams.width = (int) dimension;
view.setLayoutParams(layoutParams);
}
}
});
addLayoutParamsAttributeProcessor(
Attributes.View.Height,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams != null) {
layoutParams.height = (int) dimension;
view.setLayoutParams(layoutParams);
}
}
});
addAttributeProcessor(
"android:outlineProvider",
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
switch (value) {
case "bounds":
view.setOutlineProvider(ViewOutlineProvider.BOUNDS);
break;
case "paddedBounds":
view.setOutlineProvider(ViewOutlineProvider.PADDED_BOUNDS);
break;
case "background":
view.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
break;
}
}
});
addAttributeProcessor(
Attributes.View.Activated,
new BooleanAttributeProcessor<V>() {
@Override
public void setBoolean(V view, boolean value) {
view.setActivated(value);
}
});
addAttributeProcessor(
Attributes.View.OnClick,
new EventProcessor<V>() {
@Override
public void setOnEventListener(final V view, final Value value) {
view.setOnClickListener(
v -> trigger(Attributes.View.OnClick, value, (ProteusView) view));
}
});
addAttributeProcessor(
Attributes.View.OnLongClick,
new EventProcessor<V>() {
@Override
public void setOnEventListener(final V view, final Value value) {
view.setOnLongClickListener(
v -> {
trigger(Attributes.View.OnLongClick, value, (ProteusView) view);
return true;
});
}
});
addAttributeProcessor(
Attributes.View.OnTouch,
new EventProcessor<V>() {
@SuppressLint("ClickableViewAccessibility")
@Override
public void setOnEventListener(final V view, final Value value) {
view.setOnTouchListener(
(v, event) -> {
trigger(Attributes.View.OnTouch, value, (ProteusView) view);
return true;
});
}
});
addAttributeProcessor(
Attributes.View.Background,
new DrawableResourceProcessor<V>() {
@Override
public void setDrawable(V view, Drawable drawable) {
view.setBackground(drawable);
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
ProteusView proteusView = ((ProteusView) view);
Value value =
proteusView
.getViewManager()
.getContext()
.obtainStyledAttribute(parent, view, attribute.getName());
if (value == null) {
value = attribute;
}
Drawable evaluate = DrawableResourceProcessor.evaluate(value, view);
setDrawable(view, evaluate);
}
});
addAttributeProcessor(
Attributes.View.LayoutGravity,
new GravityAttributeProcessor<V>() {
@Override
public void setGravity(V view, @Gravity int gravity) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (layoutParams instanceof LinearLayout.LayoutParams) {
LinearLayout.LayoutParams linearLayoutParams =
(LinearLayout.LayoutParams) layoutParams;
linearLayoutParams.gravity = gravity;
view.setLayoutParams(layoutParams);
} else if (layoutParams instanceof FrameLayout.LayoutParams) {
FrameLayout.LayoutParams linearLayoutParams = (FrameLayout.LayoutParams) layoutParams;
linearLayoutParams.gravity = gravity;
view.setLayoutParams(layoutParams);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "'layout_gravity' is only supported for LinearLayout and FrameLayout");
}
}
}
});
addAttributeProcessor(
Attributes.View.Padding,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setPadding((int) dimension, (int) dimension, (int) dimension, (int) dimension);
}
});
addAttributeProcessor(
Attributes.View.PaddingLeft,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setPadding(
(int) dimension,
view.getPaddingTop(),
view.getPaddingRight(),
view.getPaddingBottom());
}
});
addAttributeProcessor(
Attributes.View.PaddingTop,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setPadding(
view.getPaddingLeft(),
(int) dimension,
view.getPaddingRight(),
view.getPaddingBottom());
}
});
addAttributeProcessor(
Attributes.View.PaddingRight,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setPadding(
view.getPaddingLeft(),
view.getPaddingTop(),
(int) dimension,
view.getPaddingBottom());
}
});
addAttributeProcessor(
Attributes.View.PaddingBottom,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setPadding(
view.getPaddingLeft(),
view.getPaddingTop(),
view.getPaddingRight(),
(int) dimension);
}
});
addAttributeProcessor(
Attributes.View.Margin,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams layoutParams;
layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
layoutParams.setMargins(
(int) dimension, (int) dimension, (int) dimension, (int) dimension);
view.setLayoutParams(layoutParams);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "margins can only be applied to views with parent ViewGroup");
}
}
}
});
addAttributeProcessor(
Attributes.View.MarginLeft,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
MarginHelper.setMarginLeft(view, (int) dimension);
}
}
});
addAttributeProcessor(
"android:layout_marginStart",
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
MarginHelper.setMarginLeft(view, (int) dimension);
}
}
});
addAttributeProcessor(
Attributes.View.MarginTop,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams layoutParams;
layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
layoutParams.setMargins(
layoutParams.leftMargin,
(int) dimension,
layoutParams.rightMargin,
layoutParams.bottomMargin);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "margins can only be applied to views with parent ViewGroup");
}
}
}
});
addAttributeProcessor(
Attributes.View.MarginRight,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
MarginHelper.setMarginRight(view, (int) dimension);
}
}
});
addAttributeProcessor(
"android:layout_marginEnd",
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
MarginHelper.setMarginRight(view, (int) dimension);
}
}
});
addAttributeProcessor(
Attributes.View.MarginBottom,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
MarginHelper.setMarginBottom(view, (int) dimension);
}
}
});
addAttributeProcessor(
Attributes.View.MinHeight,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setMinimumHeight((int) dimension);
}
});
addAttributeProcessor(
Attributes.View.MinWidth,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
view.setMinimumWidth((int) dimension);
}
});
addAttributeProcessor(
Attributes.View.Elevation,
new DimensionAttributeProcessor<V>() {
@Override
public void setDimension(V view, float dimension) {
ViewCompat.setElevation(view, dimension);
}
});
addAttributeProcessor(
Attributes.View.Alpha,
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
view.setAlpha(ParseHelper.parseFloat(value));
}
});
addAttributeProcessor(
Attributes.View.Visibility,
new AttributeProcessor<V>() {
@Override
public void handleValue(View parent, V view, Value value) {
if (value.isPrimitive() && value.getAsPrimitive().isNumber()) {
view.setVisibility(value.getAsInt());
} else {
process(
(View) view.getParent(),
view,
precompile(
value,
ProteusHelper.getProteusContext(view),
ProteusHelper.getProteusContext(view).getFunctionManager()));
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {
Integer visibility = resource.getInteger(ProteusHelper.getProteusContext(view));
view.setVisibility(null != visibility ? visibility : View.GONE);
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
TypedArray a = attribute.apply(ProteusHelper.getProteusContext(view));
view.setVisibility(a.getInt(0, View.GONE));
}
@Override
public void handleStyle(View parent, V view, Style style) {
Value gone = style.getValue(Attributes.View.Visibility, new Primitive("gone"));
if (view instanceof ProteusView) {
((ProteusView) view)
.getViewManager()
.updateAttribute(Attributes.View.Visibility, gone.toString());
}
}
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
int visibility = ParseHelper.parseVisibility(value);
return ParseHelper.getVisibility(visibility);
}
});
addAttributeProcessor(
Attributes.View.Id,
new StringAttributeProcessor<V>() {
@Override
public void setString(final V view, String value) {
ProteusContext context = ProteusHelper.getProteusContext(view);
view.setId(context.getInflater().getUniqueViewId(ParseHelper.parseViewId(value)));
// set view id resource name
final String resourceName = value;
view.setAccessibilityDelegate(
new View.AccessibilityDelegate() {
@Override
public void onInitializeAccessibilityNodeInfo(
View host, AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(host, info);
String normalizedResourceName;
if (!TextUtils.isEmpty(resourceName)) {
String id;
if (resourceName.startsWith(ID_STRING_START_PATTERN)) {
id = resourceName.substring(ID_STRING_START_PATTERN.length());
} else if (resourceName.startsWith(ID_STRING_START_PATTERN1)) {
id = resourceName.substring(ID_STRING_START_PATTERN1.length());
} else {
id = resourceName;
}
normalizedResourceName =
view.getContext().getPackageName() + ID_STRING_NORMALIZED_PATTERN + id;
} else {
normalizedResourceName = "";
}
info.setViewIdResourceName(normalizedResourceName);
}
});
}
});
addAttributeProcessor(
Attributes.View.ContentDescription,
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
view.setContentDescription(value);
}
});
addAttributeProcessor(
Attributes.View.Clickable,
new BooleanAttributeProcessor<V>() {
@Override
public void setBoolean(V view, boolean value) {
view.setClickable(value);
}
});
addAttributeProcessor(
Attributes.View.Tag,
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
view.setTag(value);
}
});
addAttributeProcessor(
Attributes.View.Enabled,
new BooleanAttributeProcessor<V>() {
@Override
public void setBoolean(V view, boolean value) {
view.setEnabled(value);
}
});
addAttributeProcessor(
Attributes.View.Selected,
new BooleanAttributeProcessor<V>() {
@Override
public void setBoolean(V view, boolean value) {
view.setSelected(value);
}
});
addAttributeProcessor(
Attributes.View.TransitionName,
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
view.setTransitionName(value);
}
});
addAttributeProcessor(
Attributes.View.RequiresFadingEdge,
new StringAttributeProcessor<V>() {
private final String NONE = "none";
private final String BOTH = "both";
private final String VERTICAL = "vertical";
private final String HORIZONTAL = "horizontal";
@Override
public void setString(V view, String value) {
switch (value) {
case BOTH:
view.setVerticalFadingEdgeEnabled(true);
view.setHorizontalFadingEdgeEnabled(true);
break;
case VERTICAL:
view.setVerticalFadingEdgeEnabled(true);
view.setHorizontalFadingEdgeEnabled(false);
break;
case HORIZONTAL:
view.setVerticalFadingEdgeEnabled(false);
view.setHorizontalFadingEdgeEnabled(true);
break;
case NONE:
default:
view.setVerticalFadingEdgeEnabled(false);
view.setHorizontalFadingEdgeEnabled(false);
break;
}
}
});
addAttributeProcessor(
Attributes.View.FadingEdgeLength,
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
view.setFadingEdgeLength(ParseHelper.parseInt(value));
}
});
addAttributeProcessor(
Attributes.View.Animation,
new TweenAnimationResourceProcessor<V>() {
@Override
public void setAnimation(V view, Animation animation) {
view.setAnimation(animation);
}
});
addAttributeProcessor(
Attributes.View.TextAlignment,
new StringAttributeProcessor<V>() {
@Override
public void setString(V view, String value) {
Integer textAlignment = ParseHelper.parseTextAlignment(value);
if (null != textAlignment) {
//noinspection ResourceType
view.setTextAlignment(textAlignment);
}
}
});
// AppCompat Attributes
addAttributeProcessor(
"app:backgroundTint",
new ColorResourceProcessor<V>() {
@Override
public void setColor(V view, int color) {
ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(color));
}
@Override
public void setColor(V view, ColorStateList colors) {
ViewCompat.setBackgroundTintList(view, colors);
}
});
addAttributeProcessor(
Attributes.View.Style,
new StyleResourceProcessor<V>() {
@Override
public void handleStyle(View parent, View view, Style style) {
style.applyStyle(parent, (ProteusView) view, false);
}
});
addAttributeProcessor(
"android:theme",
new StyleResourceProcessor<V>() {
@Override
public void handleStyle(View parent, View view, Style style) {
ProteusView proteusView = (ProteusView) view;
ProteusView.Manager viewManager = proteusView.getViewManager();
// if the view has already a theme set, then its most likely that this is
// a theme overlay, we just override the values from the existing theme
Style currentTheme = viewManager.getTheme();
Style currentStyle = viewManager.getStyle();
if (currentTheme != null) {
currentTheme = currentTheme.copy().getAsStyle();
for (Map.Entry<String, Value> entry : style.getValues().entrySet()) {
currentTheme.addValue(entry.getKey(), entry.getValue());
if (currentStyle != null) {
currentStyle.addValue(entry.getKey(), entry.getValue());
}
}
currentTheme.applyTheme(parent, (ProteusView) view, true);
if (viewManager.getStyle() != null) {
viewManager.getStyle().applyStyle(parent, (ProteusView) view, false);
}
} else {
style.applyTheme(parent, (ProteusView) view, true);
}
}
});
addAttributeProcessor(
"materialThemeOverlay",
new StyleResourceProcessor<V>() {
@Override
public void handleStyle(View parent, View view, Style style) {
ProteusView proteusView = (ProteusView) view;
ProteusView.Manager viewManager = proteusView.getViewManager();
// // wait for the other attributes to be applied
//// view.post(() -> {
if (viewManager.getTheme() != null) {
Style currentTheme = viewManager.getTheme().copy().getAsStyle();
currentTheme.getValues().remove("materialThemeOverlay");
for (Map.Entry<String, Value> entry : style.getValues().entrySet()) {
currentTheme.addValue(entry.getKey(), entry.getValue());
}
currentTheme.applyTheme(parent, (ProteusView) view, false);
} else {
style.applyTheme(parent, (ProteusView) view, false);
}
// });
}
});
// addAttributeProcessor("app:elevation", new DimensionAttributeProcessor<V>() {
// @Override
// public void setDimension(V view, float dimension) {
// ViewCompat.setElevation(view, dimension);
// }
// });
addAttributeProcessor(
"app:shapeAppearance",
new ShapeAppearanceProcessor<V>() {
@Override
public void setShapeAppearance(View view, ShapeAppearanceModel model) {
if (view instanceof Shapeable) {
((Shapeable) view).setShapeAppearanceModel(model);
}
}
});
addAttributeProcessor(
"app:shapeAppearanceOverlay",
new ShapeAppearanceProcessor<V>() {
@Override
public void setShapeAppearance(View view, ShapeAppearanceModel model) {
if (view instanceof Shapeable) {
((Shapeable) view).setShapeAppearanceModel(model);
}
}
});
}
@Override
public boolean handleChildren(V view, Value children) {
return false;
}
@Override
public boolean addView(ProteusView parent, ProteusView view) {
return false;
}
}
| 26,805 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ScrollViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ScrollViewParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusScrollView;
/** Created by kiran.kumar on 12/05/14. */
public class ScrollViewParser<T extends View> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return ScrollView.class.getName();
}
@Nullable
@Override
public String getParentType() {
return FrameLayout.class.getName();
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusScrollView(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.HorizontalScrollView.FillViewPort,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
if (view instanceof ScrollView) {
((ScrollView) view).setFillViewport(value);
}
}
});
addAttributeProcessor(
Attributes.ScrollView.Scrollbars,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if ("none".equals(value)) {
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(false);
} else if ("horizontal".equals(value)) {
view.setHorizontalScrollBarEnabled(true);
view.setVerticalScrollBarEnabled(false);
} else if ("vertical".equals(value)) {
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(true);
} else {
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(false);
}
}
});
}
}
| 3,211 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
EditTextParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/EditTextParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.ViewGroup;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.StyleResourceProcessor;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusEditText;
/** Created by kirankumar on 25/11/14. */
public class EditTextParser<T extends EditText> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.EditText";
}
@Nullable
@Override
public String getParentType() {
return "android.widget.TextView";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusEditText(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor("android:editTextBackground", new StyleResourceProcessor<>());
}
}
| 1,914 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
CheckBoxParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/CheckBoxParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.CheckBox;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.DrawableResourceProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusCheckBox;
/** Created by prateek.dixit on 1/8/15. */
public class CheckBoxParser<T extends CheckBox> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.CheckBox";
}
@Nullable
@Override
public String getParentType() {
return "android.widget.Button";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusCheckBox(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.CheckBox.Button,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
view.setButtonDrawable(drawable);
}
});
addAttributeProcessor(
Attributes.CheckBox.Checked,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setChecked(Boolean.parseBoolean(value));
}
});
}
}
| 2,527 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
HorizontalProgressBarParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalProgressBarParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusHorizontalProgressBar;
import com.flipkart.android.proteus.view.custom.HorizontalProgressBar;
/**
* HorizontalProgressBarParser
*
* @author Aditya Sharat
*/
public class HorizontalProgressBarParser<T extends HorizontalProgressBar>
extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.HorizontalProgressBar";
}
@Nullable
@Override
public String getParentType() {
return "android.widget.ProgressBar";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusHorizontalProgressBar(context);
}
@Override
protected void addAttributeProcessors() {}
}
| 1,888 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
RelativeLayoutParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RelativeLayoutParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.AttributeProcessor;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.GravityAttributeProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusRelativeLayout;
/** Created by kirankumar on 10/07/14. */
public class RelativeLayoutParser<T extends View> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.RelativeLayout";
}
@Nullable
@Override
public String getParentType() {
return "android.view.ViewGroup";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusRelativeLayout(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.View.Gravity,
new GravityAttributeProcessor<T>() {
@Override
public void setGravity(T view, @Gravity int gravity) {
if (view instanceof RelativeLayout) {
((RelativeLayout) view).setGravity(gravity);
}
}
});
addLayoutParamsAttributeProcessor(
Attributes.View.Above, createRelativeLayoutRuleProcessor(RelativeLayout.ABOVE));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignBaseline,
createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_BASELINE));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignBottom,
createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_BOTTOM));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignLeft, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_LEFT));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignRight, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_RIGHT));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignTop, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_TOP));
addLayoutParamsAttributeProcessor(
Attributes.View.Below, createRelativeLayoutRuleProcessor(RelativeLayout.BELOW));
addLayoutParamsAttributeProcessor(
Attributes.View.ToLeftOf, createRelativeLayoutRuleProcessor(RelativeLayout.LEFT_OF));
addLayoutParamsAttributeProcessor(
Attributes.View.ToRightOf, createRelativeLayoutRuleProcessor(RelativeLayout.RIGHT_OF));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignEnd, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_END));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignStart, createRelativeLayoutRuleProcessor(RelativeLayout.ALIGN_START));
addLayoutParamsAttributeProcessor(
Attributes.View.ToEndOf, createRelativeLayoutRuleProcessor(RelativeLayout.END_OF));
addLayoutParamsAttributeProcessor(
Attributes.View.ToStartOf, createRelativeLayoutRuleProcessor(RelativeLayout.START_OF));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignParentTop,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_TOP));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignParentRight,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_RIGHT));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignParentBottom,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_BOTTOM));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignParentLeft,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_LEFT));
addLayoutParamsAttributeProcessor(
Attributes.View.CenterHorizontal,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_HORIZONTAL));
addLayoutParamsAttributeProcessor(
Attributes.View.CenterVertical,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_VERTICAL));
addLayoutParamsAttributeProcessor(
Attributes.View.CenterInParent,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.CENTER_IN_PARENT));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignParentStart,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_START));
addLayoutParamsAttributeProcessor(
Attributes.View.AlignParentEnd,
createRelativeLayoutBooleanRuleProcessor(RelativeLayout.ALIGN_PARENT_END));
}
private AttributeProcessor<T> createRelativeLayoutRuleProcessor(final int rule) {
return new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (view instanceof ProteusView) {
int id =
((ProteusView) view)
.getViewManager()
.getContext()
.getInflater()
.getUniqueViewId(ParseHelper.parseViewId(value));
ParseHelper.addRelativeLayoutRule(view, rule, id);
}
}
};
}
private AttributeProcessor<T> createRelativeLayoutBooleanRuleProcessor(final int rule) {
return new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
int trueOrFalse = ParseHelper.parseRelativeLayoutBoolean(value);
ParseHelper.addRelativeLayoutRule(view, rule, trueOrFalse);
}
};
}
}
| 6,730 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProgressBarParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ProgressBarParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.os.Build;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.AttributeProcessor;
import com.flipkart.android.proteus.processor.ColorResourceProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
import com.flipkart.android.proteus.view.ProteusProgressBar;
/**
* @author Aditya Sharat
*/
public class ProgressBarParser<T extends ProgressBar> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.ProgressBar";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusProgressBar(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.ProgressBar.Max,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setMax((int) ParseHelper.parseDouble(value));
}
});
addAttributeProcessor(
Attributes.ProgressBar.Progress,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setProgress((int) ParseHelper.parseDouble(value));
}
});
addAttributeProcessor(
Attributes.ProgressBar.ProgressTint,
new AttributeProcessor<T>() {
@Override
public void handleValue(View parent, T view, Value value) {
if (!value.isObject()) {
return;
}
int background = Color.TRANSPARENT;
int progress = Color.TRANSPARENT;
ObjectValue object = value.getAsObject();
String string = object.getAsString("background");
if (string != null) {
background = ParseHelper.parseColor(string);
}
string = object.getAsString("progress");
if (string != null) {
progress = ParseHelper.parseColor(string);
}
view.setProgressDrawable(getLayerDrawable(progress, background));
}
@Override
public void handleResource(View parent, T view, Resource resource) {
Drawable d = resource.getDrawable(ProteusHelper.getProteusContext(view));
view.setProgressDrawable(d);
}
@Override
public void handleAttributeResource(View parent, T view, AttributeResource attribute) {
TypedArray a = attribute.apply(view.getContext());
view.setProgressDrawable(a.getDrawable(0));
}
@Override
public void handleStyle(View parent, T view, Style style) {}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
addAttributeProcessor(
Attributes.ProgressBar.SecondaryProgressTint,
new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {}
@Override
public void setColor(T view, ColorStateList colors) {
//noinspection AndroidLintNewApi
view.setSecondaryProgressTintList(colors);
}
});
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
addAttributeProcessor(
Attributes.ProgressBar.IndeterminateTint,
new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {}
@Override
public void setColor(T view, ColorStateList colors) {
//noinspection AndroidLintNewApi
view.setIndeterminateTintList(colors);
}
});
}
}
Drawable getLayerDrawable(int progress, int background) {
ShapeDrawable shape = new ShapeDrawable();
shape.getPaint().setStyle(Paint.Style.FILL);
shape.getPaint().setColor(background);
ShapeDrawable shapeD = new ShapeDrawable();
shapeD.getPaint().setStyle(Paint.Style.FILL);
shapeD.getPaint().setColor(progress);
ClipDrawable clipDrawable = new ClipDrawable(shapeD, Gravity.LEFT, ClipDrawable.HORIZONTAL);
return new LayerDrawable(new Drawable[] {shape, clipDrawable});
}
}
| 6,243 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ListViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ListViewParser.java | package com.flipkart.android.proteus.parser.custom;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.custom.ProteusListView;
public class ListViewParser<T extends View> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.ListView";
}
@Nullable
@Override
public String getParentType() {
return "android.view.ViewGroup";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusListView(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
"tools:listitem",
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
String layoutName = value.replace("@layout/", "");
if (view instanceof ProteusListView) {
((ProteusListView) view).setListItem(layoutName);
}
}
});
}
}
| 1,558 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
RatingBarParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/RatingBarParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.DimensionAttributeProcessor;
import com.flipkart.android.proteus.processor.DrawableResourceProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusFixedRatingBar;
import com.flipkart.android.proteus.view.custom.FixedRatingBar;
/** Created by kiran.kumar on 12/05/14. */
public class RatingBarParser<T extends FixedRatingBar> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.RatingBar";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusFixedRatingBar(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.RatingBar.NumStars,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setNumStars(ParseHelper.parseInt(value));
}
});
addAttributeProcessor(
Attributes.RatingBar.Rating,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setRating(ParseHelper.parseFloat(value));
}
});
addAttributeProcessor(
Attributes.RatingBar.IsIndicator,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setIsIndicator(value);
}
});
addAttributeProcessor(
Attributes.RatingBar.StepSize,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setStepSize(ParseHelper.parseFloat(value));
}
});
addAttributeProcessor(
Attributes.RatingBar.MinHeight,
new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setMinimumHeight((int) dimension);
}
});
addAttributeProcessor(
Attributes.RatingBar.ProgressDrawable,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
drawable = view.getTiledDrawable(drawable, false);
view.setProgressDrawable(drawable);
}
});
}
}
| 3,923 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ImageViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageViewParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.DrawableResourceProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusImageView;
/** Created by kiran.kumar on 12/05/14. */
public class ImageViewParser<T extends ImageView> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.ImageView";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusImageView(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.ImageView.Src,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
view.setImageDrawable(drawable);
}
});
addAttributeProcessor(
"app:srcCompat",
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
view.setImageDrawable(drawable);
}
});
addAttributeProcessor(
Attributes.ImageView.ScaleType,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
ProteusImageView.ScaleType scaleType;
scaleType = ParseHelper.parseScaleType(value);
if (scaleType != null) view.setScaleType(scaleType);
}
});
addAttributeProcessor(
Attributes.ImageView.AdjustViewBounds,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if ("true".equals(value)) {
view.setAdjustViewBounds(true);
} else {
view.setAdjustViewBounds(false);
}
}
});
}
}
| 3,338 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ImageButtonParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ImageButtonParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.ViewGroup;
import android.widget.ImageButton;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusImageButton;
/** Created by kirankumar on 25/11/14. */
public class ImageButtonParser<T extends ImageButton> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.ImageButton";
}
@Nullable
@Override
public String getParentType() {
return "android.widget.ImageView";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusImageButton(context);
}
@Override
protected void addAttributeProcessors() {}
}
| 1,771 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
WebViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/WebViewParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.ViewGroup;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusWebView;
/** Created by kiran.kumar on 12/05/14. */
public class WebViewParser<T extends WebView> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.webkit.WebView";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusWebView(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.WebView.Url,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.loadUrl(value);
}
});
addAttributeProcessor(
Attributes.WebView.HTML,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.loadData(value, "text/html", "UTF-8");
}
});
}
}
| 2,369 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
TextViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/TextViewParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.annotation.SuppressLint;
import android.content.res.ColorStateList;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Html;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.ColorResourceProcessor;
import com.flipkart.android.proteus.processor.DimensionAttributeProcessor;
import com.flipkart.android.proteus.processor.DrawableResourceProcessor;
import com.flipkart.android.proteus.processor.GravityAttributeProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.processor.StyleResourceProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusTextView;
/** Created by kiran.kumar on 12/05/14. */
public class TextViewParser<T extends TextView> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.TextView";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusTextView(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.TextView.HTML,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view.setText(Html.fromHtml(value, Html.FROM_HTML_MODE_LEGACY));
} else {
//noinspection deprecation
view.setText(Html.fromHtml(value));
}
}
});
addAttributeProcessor(
Attributes.TextView.Text,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setText(value);
}
});
addAttributeProcessor(
"tools:text",
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setText(value);
}
});
addAttributeProcessor(
Attributes.TextView.DrawablePadding,
new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setCompoundDrawablePadding((int) dimension);
}
});
addAttributeProcessor(
Attributes.TextView.TextSize,
new DimensionAttributeProcessor<T>() {
@Override
public void setDimension(T view, float dimension) {
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimension);
}
});
addAttributeProcessor(
Attributes.TextView.Gravity,
new GravityAttributeProcessor<T>() {
@Override
public void setGravity(T view, @Gravity int gravity) {
view.setGravity(gravity);
}
});
addAttributeProcessor(
Attributes.TextView.TextColor,
new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {
view.setTextColor(color);
}
@Override
public void setColor(T view, ColorStateList colors) {
view.setTextColor(colors);
}
});
addAttributeProcessor(
Attributes.TextView.TextColorHint,
new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {
view.setHintTextColor(color);
}
@Override
public void setColor(T view, ColorStateList colors) {
view.setHintTextColor(colors);
}
});
addAttributeProcessor(
Attributes.TextView.TextColorLink,
new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {
view.setLinkTextColor(color);
}
@Override
public void setColor(T view, ColorStateList colors) {
view.setLinkTextColor(colors);
}
});
addAttributeProcessor(
Attributes.TextView.TextColorHighLight,
new ColorResourceProcessor<T>() {
@Override
public void setColor(T view, int color) {
view.setHighlightColor(color);
}
@Override
public void setColor(T view, ColorStateList colors) {
//
}
});
addAttributeProcessor(
Attributes.TextView.DrawableLeft,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
Drawable[] compoundDrawables = view.getCompoundDrawables();
view.setCompoundDrawablesWithIntrinsicBounds(
drawable, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]);
}
});
addAttributeProcessor(
Attributes.TextView.DrawableTop,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
Drawable[] compoundDrawables = view.getCompoundDrawables();
view.setCompoundDrawablesWithIntrinsicBounds(
compoundDrawables[0], drawable, compoundDrawables[2], compoundDrawables[3]);
}
});
addAttributeProcessor(
Attributes.TextView.DrawableRight,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
Drawable[] compoundDrawables = view.getCompoundDrawables();
view.setCompoundDrawablesWithIntrinsicBounds(
drawable, compoundDrawables[1], drawable, compoundDrawables[3]);
}
});
addAttributeProcessor(
Attributes.TextView.DrawableBottom,
new DrawableResourceProcessor<T>() {
@Override
public void setDrawable(T view, Drawable drawable) {
Drawable[] compoundDrawables = view.getCompoundDrawables();
view.setCompoundDrawablesWithIntrinsicBounds(
drawable, compoundDrawables[1], compoundDrawables[2], drawable);
}
});
addAttributeProcessor(
Attributes.TextView.MaxLines,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setMaxLines(ParseHelper.parseInt(value));
}
});
addAttributeProcessor(
Attributes.TextView.Ellipsize,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
Enum ellipsize = ParseHelper.parseEllipsize(value);
view.setEllipsize((android.text.TextUtils.TruncateAt) ellipsize);
}
});
addAttributeProcessor(
Attributes.TextView.PaintFlags,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (value.equals("strike"))
view.setPaintFlags(view.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
});
addAttributeProcessor(
Attributes.TextView.Prefix,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setText(value + view.getText());
}
});
addAttributeProcessor(
Attributes.TextView.Suffix,
new StringAttributeProcessor<T>() {
@SuppressLint("SetTextI18n")
@Override
public void setString(T view, String value) {
view.setText(view.getText() + value);
}
});
addAttributeProcessor(
Attributes.TextView.TextStyle,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
int typeface = ParseHelper.parseTextStyle(value);
view.setTypeface(Typeface.defaultFromStyle(typeface));
}
});
addAttributeProcessor(
Attributes.TextView.SingleLine,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setSingleLine(value);
}
});
addAttributeProcessor(
Attributes.TextView.TextAllCaps,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setAllCaps(value);
}
});
addAttributeProcessor(
Attributes.TextView.Hint,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
view.setHint(value);
}
});
addAttributeProcessor("android:textAppearance", new StyleResourceProcessor<>());
}
}
| 10,389 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
LinearLayoutParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/LinearLayoutParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.DimensionAttributeProcessor;
import com.flipkart.android.proteus.processor.DrawableResourceProcessor;
import com.flipkart.android.proteus.processor.GravityAttributeProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusLinearLayout;
/** Created by kiran.kumar on 12/05/14. */
public class LinearLayoutParser<T extends View> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.LinearLayout";
}
@Nullable
@Override
public String getParentType() {
return "android.view.ViewGroup";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusLinearLayout(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.LinearLayout.Orientation,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (view instanceof LinearLayout) {
if ("horizontal".equals(value)) {
((LinearLayout) view).setOrientation(ProteusLinearLayout.HORIZONTAL);
} else {
((LinearLayout) view).setOrientation(ProteusLinearLayout.VERTICAL);
}
}
}
});
addAttributeProcessor(
Attributes.View.Gravity,
new GravityAttributeProcessor<T>() {
@Override
public void setGravity(T view, @Gravity int gravity) {
if (view instanceof LinearLayout) {
((LinearLayout) view).setGravity(gravity);
}
}
});
addAttributeProcessor(
Attributes.LinearLayout.Divider,
new DrawableResourceProcessor<T>() {
@SuppressLint("NewApi")
@Override
public void setDrawable(T view, Drawable drawable) {
if (view instanceof LinearLayout) {
((LinearLayout) view).setDividerDrawable(drawable);
}
}
});
addAttributeProcessor(
Attributes.LinearLayout.DividerPadding,
new DimensionAttributeProcessor<T>() {
@SuppressLint("NewApi")
@Override
public void setDimension(T view, float dimension) {
if (view instanceof LinearLayout) {
((LinearLayout) view).setDividerPadding((int) dimension);
}
}
});
addAttributeProcessor(
Attributes.LinearLayout.ShowDividers,
new StringAttributeProcessor<T>() {
@SuppressLint("NewApi")
@Override
public void setString(T view, String value) {
int dividerMode = ParseHelper.parseDividerMode(value);
// noinspection ResourceType
if (view instanceof LinearLayout) {
((LinearLayout) view).setShowDividers(dividerMode);
}
}
});
addAttributeProcessor(
Attributes.LinearLayout.WeightSum,
new StringAttributeProcessor<T>() {
@SuppressLint("NewApi")
@Override
public void setString(T view, String value) {
if (view instanceof LinearLayout) {
((LinearLayout) view).setWeightSum(ParseHelper.parseFloat(value));
}
}
});
addLayoutParamsAttributeProcessor(
Attributes.View.Weight,
new StringAttributeProcessor<T>() {
@Override
public void setString(View view, String value) {
LinearLayout.LayoutParams layoutParams;
if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
layoutParams.weight = ParseHelper.parseFloat(value);
view.setLayoutParams(layoutParams);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e("LinearLayoutParser", "'weight' is only supported for LinearLayouts");
}
}
}
});
}
}
| 5,644 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ViewGroupParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ViewGroupParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.DataContext;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusLayoutInflater;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.exceptions.ProteusInflateException;
import com.flipkart.android.proteus.managers.ViewGroupManager;
import com.flipkart.android.proteus.processor.AttributeProcessor;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Binding;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.NestedBinding;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
import com.flipkart.android.proteus.view.ProteusAspectRatioFrameLayout;
import java.util.Iterator;
public class ViewGroupParser<T extends ViewGroup> extends ViewTypeParser<T> {
private static final String LAYOUT_MODE_CLIP_BOUNDS = "clipBounds";
private static final String LAYOUT_MODE_OPTICAL_BOUNDS = "opticalBounds";
@NonNull
@Override
public String getType() {
return "android.view.ViewGroup";
}
@Nullable
@Override
public String getParentType() {
return "android.view.View";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusAspectRatioFrameLayout(context);
}
@NonNull
@Override
public ProteusView.Manager createViewManager(
@NonNull ProteusContext context,
@NonNull ProteusView view,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewTypeParser caller,
@Nullable ViewGroup parent,
int dataIndex) {
DataContext dataContext = createDataContext(context, layout, data, parent, dataIndex);
return new ViewGroupManager(
context, null != caller ? caller : this, view.getAsView(), layout, dataContext);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.ViewGroup.ClipChildren,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setClipChildren(value);
}
});
addAttributeProcessor(
Attributes.ViewGroup.ClipToPadding,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setClipToPadding(value);
}
});
addAttributeProcessor(
Attributes.ViewGroup.LayoutMode,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
if (LAYOUT_MODE_CLIP_BOUNDS.equals(value)) {
view.setLayoutMode(ViewGroup.LAYOUT_MODE_CLIP_BOUNDS);
} else if (LAYOUT_MODE_OPTICAL_BOUNDS.equals(value)) {
view.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS);
}
}
}
});
addAttributeProcessor(
Attributes.ViewGroup.SplitMotionEvents,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
view.setMotionEventSplittingEnabled(value);
}
});
addAttributeProcessor(
Attributes.ViewGroup.Children,
new AttributeProcessor<T>() {
@Override
public void handleBinding(View parent, T view, Binding value) {
handleDataBoundChildren(view, value);
}
@Override
public void handleValue(View parent, T view, Value value) {
handleChildren(view, value);
}
@Override
public void handleResource(View parent, T view, Resource resource) {
throw new IllegalArgumentException("children cannot be a resource");
}
@Override
public void handleAttributeResource(View parent, T view, AttributeResource attribute) {
throw new IllegalArgumentException("children cannot be a resource");
}
@Override
public void handleStyle(View parent, T view, Style style) {
throw new IllegalArgumentException("children cannot be a style attribute");
}
});
}
@Override
public boolean handleChildren(T view, Value children) {
ProteusContext context = ProteusHelper.getProteusContext(view);
ProteusLayoutInflater layoutInflater = context.getInflater();
ObjectValue data = new ObjectValue();
int dataIndex = -1;
if (view instanceof ProteusView) {
if (((ProteusView) view).getViewManager() != null) {
data = ((ProteusView) view).getViewManager().getDataContext().getData();
dataIndex = ((ProteusView) view).getViewManager().getDataContext().getIndex();
}
}
if (children.isArray()) {
ProteusView child;
Iterator<Value> iterator = children.getAsArray().iterator();
Value element;
while (iterator.hasNext()) {
element = iterator.next();
if (!element.isLayout()) {
throw new ProteusInflateException(
"attribute 'children' must be an array of 'Layout' objects");
}
child = layoutInflater.inflate(element.getAsLayout(), data, view, dataIndex);
addView(view, child.getAsView());
}
}
return true;
}
protected void handleDataBoundChildren(T view, Binding value) {
ProteusView parent = ((ProteusView) view);
ViewGroupManager manager = (ViewGroupManager) parent.getViewManager();
DataContext dataContext = manager.getDataContext();
ObjectValue config = ((NestedBinding) value).getValue().getAsObject();
Binding collection = config.getAsBinding(ProteusConstants.COLLECTION);
Layout layout = config.getAsLayout(ProteusConstants.LAYOUT);
manager.hasDataBoundChildren = true;
if (null == layout || null == collection) {
throw new ProteusInflateException(
"'collection' and 'layout' are mandatory for attribute:'children'");
}
Value dataset =
collection
.getAsBinding()
.evaluate(
(ProteusContext) view.getContext(), dataContext.getData(), dataContext.getIndex());
if (dataset.isNull()) {
return;
}
if (!dataset.isArray()) {
throw new ProteusInflateException(
"'collection' in attribute:'children' must be NULL or Array");
}
int length = dataset.getAsArray().size();
int count = view.getChildCount();
ObjectValue data = dataContext.getData();
ProteusLayoutInflater inflater = manager.getContext().getInflater();
ProteusView child;
View temp;
if (count > length) {
while (count > length) {
count--;
view.removeViewAt(count);
}
}
for (int index = 0; index < length; index++) {
if (index < count) {
temp = view.getChildAt(index);
if (temp instanceof ProteusView) {
((ProteusView) temp).getViewManager().update(data);
}
} else {
//noinspection ConstantConditions : We want to throw an exception if the layout is null
child = inflater.inflate(layout, data, view, index);
addView(parent, child);
}
}
}
@Override
public boolean addView(ProteusView parent, ProteusView view) {
if (parent instanceof ViewGroup) {
((ViewGroup) parent).addView(view.getAsView());
return true;
}
return false;
}
public boolean addView(ProteusView parent, View view) {
if (parent instanceof ViewGroup) {
((ViewGroup) parent).addView(view);
return true;
}
return false;
}
public boolean addView(View parent, View view) {
if (parent instanceof ViewGroup) {
((ViewGroup) parent).addView(view);
return true;
}
return false;
}
}
| 9,369 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
HorizontalScrollViewParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/HorizontalScrollViewParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.processor.BooleanAttributeProcessor;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusHorizontalScrollView;
/**
* @author kiran.kumar
* @author adityasharat
*/
public class HorizontalScrollViewParser<T extends View> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return HorizontalScrollView.class.getName();
}
@Nullable
@Override
public String getParentType() {
return FrameLayout.class.getName();
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusHorizontalScrollView(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.HorizontalScrollView.FillViewPort,
new BooleanAttributeProcessor<T>() {
@Override
public void setBoolean(T view, boolean value) {
if (view instanceof HorizontalScrollView) {
((HorizontalScrollView) view).setFillViewport(value);
}
}
});
addAttributeProcessor(
Attributes.ScrollView.Scrollbars,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if ("none".equals(value)) {
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(false);
} else if ("horizontal".equals(value)) {
view.setHorizontalScrollBarEnabled(true);
view.setVerticalScrollBarEnabled(false);
} else if ("vertical".equals(value)) {
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(true);
} else {
view.setHorizontalScrollBarEnabled(false);
view.setVerticalScrollBarEnabled(false);
}
}
});
}
}
| 3,292 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ButtonParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/ButtonParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusButton;
/** Created by kiran.kumar on 12/05/14. */
public class ButtonParser<T extends Button> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.Button";
}
@Nullable
@Override
public String getParentType() {
return "android.widget.TextView";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusButton(context);
}
@Override
protected void addAttributeProcessors() {}
}
| 1,741 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
FrameLayoutParser.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/parser/custom/FrameLayoutParser.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.parser.custom;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.processor.StringAttributeProcessor;
import com.flipkart.android.proteus.toolbox.Attributes;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.view.ProteusAspectRatioFrameLayout;
import com.flipkart.android.proteus.view.custom.AspectRatioFrameLayout;
/** Created by kiran.kumar on 12/05/14. */
public class FrameLayoutParser<T extends View> extends ViewTypeParser<T> {
@NonNull
@Override
public String getType() {
return "android.widget.FrameLayout";
}
@Nullable
@Override
public String getParentType() {
return "android.view.ViewGroup";
}
@NonNull
@Override
public ProteusView createView(
@NonNull ProteusContext context,
@NonNull Layout layout,
@NonNull ObjectValue data,
@Nullable ViewGroup parent,
int dataIndex) {
return new ProteusAspectRatioFrameLayout(context);
}
@Override
protected void addAttributeProcessors() {
addAttributeProcessor(
Attributes.FrameLayout.HeightRatio,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (view instanceof AspectRatioFrameLayout) {
((AspectRatioFrameLayout) view).setAspectRatioHeight(ParseHelper.parseInt(value));
}
}
});
addAttributeProcessor(
Attributes.FrameLayout.WidthRatio,
new StringAttributeProcessor<T>() {
@Override
public void setString(T view, String value) {
if (view instanceof AspectRatioFrameLayout) {
((AspectRatioFrameLayout) view).setAspectRatioWidth(ParseHelper.parseInt(value));
}
}
});
}
}
| 2,802 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
BiMap.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/BiMap.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.Map;
import java.util.Set;
/**
* BiMap
*
* @author adityasharat
*/
public interface BiMap<K, V> {
@Nullable
V put(@Nullable K key, @Nullable V value);
@Nullable
V put(@Nullable K key, @Nullable V value, boolean force);
@Nullable
V getValue(@NonNull K key);
@Nullable
K getKey(@NonNull V value);
void putAll(@NonNull Map<? extends K, ? extends V> map);
@NonNull
Set<V> values();
@NonNull
BiMap<V, K> inverse();
}
| 1,199 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ProteusHelper.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ProteusHelper.java | package com.flipkart.android.proteus.toolbox;
import android.content.Context;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.ViewTypeParser;
import com.flipkart.android.proteus.value.Array;
import com.flipkart.android.proteus.value.Layout;
import com.google.android.material.textfield.TextInputLayout;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ProteusHelper {
/**
* Sometimes other views such as {@link TextInputLayout} wraps the context, thus making the
* ProteusContext inaccessible
*
* @return the {@link ProteusContext} for a specified view
*/
public static ProteusContext getProteusContext(View view) {
if (view instanceof ProteusView) {
ProteusView.Manager viewManager = ((ProteusView) view).getViewManager();
if (viewManager != null) {
return viewManager.getContext();
}
}
Context context = view.getContext();
if (context instanceof ProteusContext) {
return (ProteusContext) context;
}
if (context instanceof ContextThemeWrapper) {
return (ProteusContext) ((ContextThemeWrapper) context).getBaseContext();
}
throw new IllegalArgumentException("View argument is not using a ProteusContext");
}
public static boolean isAttributeFromView(ProteusView view, String name, int id) {
String attributeName = getAttributeName(view, id, false);
return name.equals(attributeName);
}
public static void addChildToLayout(ProteusView parent, ProteusView child) {
Layout.Attribute attribute = getChildrenAttribute(parent);
if (attribute == null) {
return;
}
int index = ((ViewGroup) parent).indexOfChild(child.getAsView());
Array array = attribute.value.getAsArray();
array.add(index, child.getViewManager().getLayout());
}
public static void removeChildFromLayout(ProteusView parent, ProteusView child) {
Layout.Attribute attribute = getChildrenAttribute(parent);
if (attribute == null) {
return;
}
Array array = attribute.value.getAsArray();
array.remove(child.getViewManager().getLayout());
}
public static String getAttributeName(ProteusView view, int id, boolean extra) {
if (view == null) {
return "Unknown";
}
String layoutType = view.getViewManager().getLayout().type;
String attributeName = "Unknown";
String attributeNameFromParent = "Unknown";
if (view.getAsView().getParent() instanceof ProteusView) {
attributeNameFromParent = getAttributeName((ProteusView) view.getAsView().getParent(), id);
}
ViewTypeParser<View> parser = view.getViewManager().getContext().getParser(layoutType);
if (parser != null) {
attributeName = getAttributeName(parser.getAttributeSet(), id);
}
if (extra && !"Unknown".equals(attributeNameFromParent)) {
return attributeNameFromParent;
}
return attributeName;
}
public static String getAttributeName(
ProteusContext context, Layout parentLayout, String layoutType, int id) {
ViewTypeParser<View> parser = context.getParser(layoutType);
if (parser != null) {
return getAttributeName(parser.getAttributeSet(), id);
}
if (parentLayout == null) {
return "Unknown";
}
String attributeName = "Unknown";
parser = context.getParser(parentLayout.type);
if (parser != null) {
attributeName = getAttributeName(parser.getAttributeSet(), id);
}
if ("Unknown".equals(attributeName)) {
parser = context.getParser("android.view.View");
if (parser != null) {
attributeName = getAttributeName(parser.getAttributeSet(), id);
}
}
return attributeName;
}
public static String getAttributeName(ProteusView view, int id) {
if (view == null) {
return "Unknown";
}
String layoutType = view.getViewManager().getLayout().type;
String attributeName = "Unknown";
String attributeNameFromParent = "Unknown";
if (view.getAsView().getParent() instanceof ProteusView) {
attributeNameFromParent = getAttributeName((ProteusView) view.getAsView().getParent(), id);
}
ViewTypeParser<View> parser = view.getViewManager().getContext().getParser(layoutType);
if (parser != null) {
attributeName = getAttributeName(parser.getAttributeSet(), id);
}
if ("Unknown".equals(attributeName)) {
return attributeNameFromParent;
}
return attributeName;
}
@SuppressWarnings({"unchecked", "CastCanBeRemovedNarrowingVariableType"})
public static ViewTypeParser<View> getViewTypeParser(
@NonNull ProteusView view, String attributeName, boolean isExtra) {
ProteusView.Manager viewManager = view.getViewManager();
int id = viewManager.getViewTypeParser().getAttributeId(attributeName);
ViewTypeParser<?> parser = null;
if (id != -1) {
parser = viewManager.getViewTypeParser();
}
ViewTypeParser<?> parentParser = null;
if (view.getAsView().getParent() instanceof ProteusView) {
ProteusView parent = (ProteusView) view.getAsView().getParent();
parentParser = parent.getViewManager().getViewTypeParser();
}
if (parser != null && parentParser != null) {
if (isExtra) {
//noinspection unchecked
return (ViewTypeParser<View>) parentParser;
} else {
return (ViewTypeParser<View>) parser;
}
}
if (parser != null) {
return (ViewTypeParser<View>) parser;
} else {
return (ViewTypeParser<View>) parentParser;
}
}
public static ViewTypeParser<View> getViewTypeParser(
@NonNull ProteusView view, String attributeName) {
ProteusView.Manager viewManager = view.getViewManager();
int id = viewManager.getViewTypeParser().getAttributeId(attributeName);
if (id != -1) {
//noinspection unchecked
return viewManager.getViewTypeParser();
}
if (view.getAsView().getParent() instanceof ProteusView) {
ProteusView parent = (ProteusView) view.getAsView().getParent();
//noinspection unchecked
return parent.getViewManager().getViewTypeParser();
}
return null;
}
public static int getAttributeId(@NonNull ProteusView view, String attributeName) {
ProteusView.Manager viewManager = view.getViewManager();
int id = viewManager.getViewTypeParser().getAttributeId(attributeName);
if (id != -1) {
return id;
}
if (view.getAsView().getParent() instanceof ProteusView) {
ProteusView parent = (ProteusView) view.getAsView().getParent();
ViewTypeParser<?> parser = parent.getViewManager().getViewTypeParser();
return parser.getAttributeId(attributeName);
}
return -1;
}
private static String getAttributeName(ViewTypeParser.AttributeSet attrs, int id) {
for (Map.Entry<String, ViewTypeParser.AttributeSet.Attribute> entry :
attrs.getLayoutParamsAttributes().entrySet()) {
String k = entry.getKey();
ViewTypeParser.AttributeSet.Attribute v = entry.getValue();
if (v.id == id) {
return k;
}
}
for (Map.Entry<String, ViewTypeParser.AttributeSet.Attribute> entry :
attrs.getAttributes().entrySet()) {
String k = entry.getKey();
ViewTypeParser.AttributeSet.Attribute v = entry.getValue();
if (v.id == id) {
return k;
}
}
return "Unknown";
}
private static Layout.Attribute getChildrenAttribute(ProteusView view) {
List<Layout.Attribute> attributes = view.getViewManager().getLayout().attributes;
if (attributes == null) {
attributes = new ArrayList<>();
}
ViewTypeParser.AttributeSet.Attribute attribute =
view.getViewManager().getAvailableAttributes().get("children");
if (attribute == null) {
return null;
}
for (Layout.Attribute attr : attributes) {
if (attribute.id == attr.id) {
return attr;
}
}
Layout.Attribute layoutAttribute = new Layout.Attribute(attribute.id, new Array());
attributes.add(layoutAttribute);
view.getViewManager().getLayout().attributes = attributes;
return layoutAttribute;
}
}
| 8,326 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
Result.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Result.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.value.Null;
import com.flipkart.android.proteus.value.Value;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Result class hold the return status and the data
*
* @author aditya.sharat
*/
public class Result {
/** Indicates that a valid {@link Value} was found at the specified data path. */
public static final int RESULT_SUCCESS = 0;
/** Indicates that the object does not have the specified data path. */
public static final int RESULT_NO_SUCH_DATA_PATH_EXCEPTION = -1;
/**
* Indicates that the data path specified is invalid. As an example, looking for a property inside
* a {@link com.flipkart.android.proteus.value.Primitive} or {@link
* com.flipkart.android.proteus.value.Array}.
*/
public static final int RESULT_INVALID_DATA_PATH_EXCEPTION = -2;
/**
* Indicates that the data path prematurely led to a {@link
* com.flipkart.android.proteus.value.Null}
*/
public static final int RESULT_NULL_EXCEPTION = -3;
/** singleton for No Such Data Path Exception. */
public static final Result NO_SUCH_DATA_PATH_EXCEPTION =
new Result(Result.RESULT_NO_SUCH_DATA_PATH_EXCEPTION, Null.INSTANCE);
/** singleton for Invalid Data Path Exception. */
public static final Result INVALID_DATA_PATH_EXCEPTION =
new Result(Result.RESULT_INVALID_DATA_PATH_EXCEPTION, Null.INSTANCE);
/** singleton for Null Exception. */
public static final Result NULL_EXCEPTION =
new Result(Result.RESULT_NULL_EXCEPTION, Null.INSTANCE);
/**
* Indicates the return status of the method for a given data path. The return value will be
* {@code RESULT_SUCCESS} if and only if the data path exists and contains a valid {@link
* com.flipkart.android.proteus.value.Value}.
*/
@ResultCode public final int RESULT_CODE;
/**
* The value at the specified data path. {@code value} will be null if {@code RESULT_CODE} !=
* {@code RESULT_SUCCESS}
*/
@NonNull public final Value value;
public Result(@ResultCode int RESULT_CODE, @NonNull Value value) {
this.RESULT_CODE = RESULT_CODE;
this.value = value;
}
/**
* This method return a {@link Result} object with {@code RESULT_CODE} == {@code RESULT_SUCCESS}
* and {@code Result#value} == {@code value}.
*
* @param value The {@link Value} to be wrapped.
* @return A {@link Result} object with with {@code RESULT_CODE} == {@code RESULT_SUCCESS}.
*/
public static Result success(Value value) {
return new Result(RESULT_SUCCESS, value);
}
/**
* @return true if and only if {@code RESULT_CODE} == {@code RESULT_SUCCESS}.
*/
public boolean isSuccess() {
return this.RESULT_CODE == RESULT_SUCCESS;
}
@IntDef({
RESULT_INVALID_DATA_PATH_EXCEPTION,
RESULT_NO_SUCH_DATA_PATH_EXCEPTION,
RESULT_SUCCESS,
RESULT_NULL_EXCEPTION
})
@Retention(RetentionPolicy.SOURCE)
public @interface ResultCode {}
}
| 3,692 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
Attributes.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Attributes.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
/**
* @author kirankumar
* @author aditya.sharat
*/
public class Attributes {
public static class View {
public static final String Above = "android:layout_above";
public static final String Activated = "android:activated";
public static final String AlignBaseline = "android:layout_alignBaseline";
public static final String AlignBottom = "android:layout_alignBottom";
public static final String AlignEnd = "android:layout_alignEnd";
public static final String AlignLeft = "android:layout_alignLeft";
public static final String AlignParentBottom = "android:layout_alignParentBottom";
public static final String AlignParentEnd = "android:layout_alignParentEnd";
public static final String AlignParentLeft = "android:layout_alignParentLeft";
public static final String AlignParentRight = "android:layout_alignParentRight";
public static final String AlignParentStart = "android:layout_alignParentStart";
public static final String AlignParentTop = "android:layout_alignParentTop";
public static final String AlignRight = "android:layout_alignRight";
public static final String AlignStart = "android:layout_alignStart";
public static final String AlignTop = "android:layout_alignTop";
public static final String Alpha = "android:alpha";
public static final String Animation = "android:animation";
public static final String Background = "android:background";
public static final String BackgroundTint = "android:backgroundTint";
public static final String BackgroundTintMode = "android:backgroundTintMode";
public static final String Below = "android:layout_below";
public static final String CenterHorizontal = "android:layout_centerHorizontal";
public static final String CenterInParent = "android:layout_centerInParent";
public static final String CenterVertical = "android:layout_centerVertical";
public static final String Clickable = "android:clickable";
public static final String ContentDescription = "android:contentDescription";
public static final String ContextClickable = "android:contextClickable";
public static final String DrawingCacheQuality = "android:drawingCacheQuality";
public static final String Elevation = "android:elevation";
public static final String Enabled = "android:enabled";
public static final String FadeScrollbars = "android:fadeScrollbars";
public static final String FadingEdgeLength = "android:fadingEdgeLength";
public static final String FilterTouchesWhenObscured = "android:filterTouchesWhenObscured";
public static final String FitsSystemWindows = "android:fitsSystemWindows";
public static final String Focusable = "android:focusable";
public static final String FocusableInTouchMode = "android:focusableInTouchMode";
public static final String ForceHasOverlappingRendering =
"android:forceHasOverlappingRendering";
public static final String Foreground = "android:foreground";
public static final String ForegroundGravity = "android:foregroundGravity";
public static final String ForegroundTint = "android:foregroundTint";
public static final String ForegroundTintMode = "android:foregroundTintMode";
public static final String Gravity = "android:gravity";
public static final String HapticFeedbackEnabled = "android:hapticFeedbackEnabled";
public static final String Height = "android:layout_height";
public static final String Id = "android:id";
public static final String IsScrollContainer = "android:isScrollContainer";
public static final String KeepScreenOn = "android:keepScreenOn";
public static final String LayerType = "android:layerType";
public static final String LayoutDirection = "android:layoutDirection";
public static final String LayoutGravity = "android:layout_gravity";
public static final String LongClickable = "android:longClickable";
public static final String Margin = "android:layout_margin";
public static final String MarginBottom = "android:layout_marginBottom";
public static final String MarginLeft = "android:layout_marginLeft";
public static final String MarginRight = "android:layout_marginRight";
public static final String MarginTop = "android:layout_marginTop";
public static final String MinHeight = "android:minHeight";
public static final String MinWidth = "android:minWidth";
public static final String NextFocusDown = "android:nextFocusDown";
public static final String NextFocusForward = "android:nextFocusForward";
public static final String NextFocusLeft = "android:nextFocusLeft";
public static final String NextFocusRight = "android:nextFocusRight";
public static final String NextFocusUp = "android:nextFocusUp";
public static final String OnClick = "android:onClick";
public static final String OnLongClick = "android:onLongClick";
public static final String OnTouch = "android:onTouch";
public static final String Padding = "android:padding";
public static final String PaddingBottom = "android:paddingBottom";
public static final String PaddingEnd = "android:paddingEnd";
public static final String PaddingLeft = "android:paddingLeft";
public static final String PaddingRight = "android:paddingRight";
public static final String PaddingStart = "android:paddingStart";
public static final String PaddingTop = "android:paddingTop";
public static final String RequiresFadingEdge = "android:requiresFadingEdge";
public static final String Rotation = "android:rotation";
public static final String RotationX = "android:rotationX";
public static final String RotationY = "android:rotationY";
public static final String SaveEnabled = "android:saveEnabled";
public static final String ScaleX = "android:scaleX";
public static final String ScaleY = "android:scaleY";
public static final String ScrollIndicators = "android:scrollIndicators";
public static final String ScrollbarDefaultDelayBeforeFade =
"android:scrollbarDefaultDelayBeforeFade";
public static final String ScrollbarFadeDuration = "android:scrollbarFadeDuration";
public static final String ScrollbarSize = "android:scrollbarSize";
public static final String ScrollbarStyle = "android:scrollbarStyle";
public static final String Selected = "android:selected";
public static final String SoundEffectsEnabled = "android:soundEffectsEnabled";
public static final String Style = "style";
public static final String Tag = "android:tag";
public static final String TextAlignment = "android:textAlignment";
public static final String TextDirection = "android:textDirection";
public static final String ToEndOf = "android:layout_toEndOf";
public static final String ToLeftOf = "android:layout_toLeftOf";
public static final String ToRightOf = "android:layout_toRightOf";
public static final String ToStartOf = "android:layout_toStartOf";
public static final String TransformPivotX = "android:transformPivotX";
public static final String TransformPivotY = "android:transformPivotY";
public static final String TransitionName = "android:transitionName";
public static final String TranslationX = "android:translationX";
public static final String TranslationY = "android:translationY";
public static final String TranslationZ = "android:translationZ";
public static final String Visibility = "android:visibility";
public static final String Weight = "android:layout_weight";
public static final String Width = "android:layout_width";
}
public static class WebView {
public static final String Url = "android:url";
public static final String HTML = "android:html";
}
public static class RatingBar {
public static final String NumStars = "android:numStars";
public static final String Rating = "android:rating";
public static final String IsIndicator = "android:isIndicator";
public static final String StepSize = "android:stepSize";
public static final String ProgressDrawable = "android:progressDrawable";
public static final String MinHeight = "android:minHeight";
}
public static class TextView {
public static final String Gravity = "android:gravity";
public static final String Text = "android:text";
public static final String HTML = "android:html";
public static final String TextSize = "android:textSize";
public static final String TextColor = "android:textColor";
public static final String TextColorHint = "android:textColorHint";
public static final String TextColorLink = "android:textColorLink";
public static final String TextColorHighLight = "android:textColorHighlight";
public static final String DrawableLeft = "android:drawableLeft";
public static final String DrawableRight = "android:drawableRight";
public static final String DrawableTop = "android:drawableTop";
public static final String DrawableBottom = "android:drawableBottom";
public static final String DrawablePadding = "android:drawablePadding";
public static final String MaxLines = "android:maxLines";
public static final String Ellipsize = "android:ellipsize";
public static final String PaintFlags = "android:paintFlags";
public static final String Prefix = "android:prefix";
public static final String Suffix = "android:suffix";
public static final String TextStyle = "android:textStyle";
public static final String SingleLine = "android:singleLine";
public static final String TextAllCaps = "android:textAllCaps";
public static final String Hint = "android:hint";
}
public static class CheckBox {
public static final String Checked = "android:checked";
public static final String Button = "android:button";
}
public static class FrameLayout {
public static final String HeightRatio = "android:heightRatio";
public static final String WidthRatio = "android:widthRatio";
}
public static class ImageView {
public static final String Src = "android:src";
public static final String ScaleType = "android:scaleType";
public static final String AdjustViewBounds = "android:adjustViewBounds";
}
public static class ViewGroup {
public static final String Children = "children";
public static final String ClipChildren = "android:clipChildren";
public static final String ClipToPadding = "android:clipToPadding";
public static final String LayoutMode = "android:layoutMode";
public static final String SplitMotionEvents = "android:splitMotionEvents";
}
public static class LinearLayout {
public static final String Orientation = "android:orientation";
public static final String Divider = "android:divider";
public static final String DividerPadding = "android:dividerPadding";
public static final String ShowDividers = "android:showDividers";
public static final String WeightSum = "android:weightSum";
}
public static class ScrollView {
public static final String Scrollbars = "android:scrollbars";
}
public static class HorizontalScrollView {
public static final String FillViewPort = "android:fillViewPort";
}
public static class ProgressBar {
public static final String Progress = "android:progress";
public static final String Max = "android:max";
public static final String ProgressTint = "android:progressTint";
public static final String IndeterminateTint = "android:indeterminateTint";
public static final String SecondaryProgressTint = "android:secondaryProgressTint";
}
}
| 12,273 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
SimpleArrayIterator.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/SimpleArrayIterator.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import java.util.Iterator;
/**
* SimpleArrayIterator
*
* @author adityasharat
*/
public class SimpleArrayIterator<E> implements Iterator<E> {
private final E[] elements;
private int cursor;
public SimpleArrayIterator(E[] elements) {
this.elements = elements;
cursor = 0;
}
public static Iterator<Integer> createIntArrayIterator(final int[] elements) {
return new Iterator<Integer>() {
private int cursor;
@Override
public boolean hasNext() {
return cursor < elements.length;
}
@Override
public Integer next() {
Integer e = elements[cursor];
cursor++;
return e;
}
};
}
@Override
public boolean hasNext() {
return cursor < elements.length;
}
@Override
public E next() {
E e = elements[cursor];
cursor++;
return e;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove() is not allowed.");
}
}
| 1,633 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
Utils.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/Utils.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.value.Array;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Primitive;
import com.flipkart.android.proteus.value.Value;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Map;
/**
* @author Aditya Sharat
*/
public class Utils {
public static final String LIB_NAME = "proteus";
public static final String VERSION = "5.0.0-SNAPSHOT";
public static final int STYLE_NONE = 0;
public static final int STYLE_SINGLE = 1;
public static final int STYLE_DOUBLE = 2;
public static ObjectValue addAllEntries(
@NonNull ObjectValue destination, @NonNull ObjectValue source) {
for (Map.Entry<String, Value> entry : source.entrySet()) {
if (destination.get(entry.getKey()) != null) {
continue;
}
destination.add(entry.getKey(), entry.getValue());
}
return destination;
}
public static String join(String[] array, String delimiter) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; i++) {
sb.append(array[i]);
if (i < array.length - 1) {
sb.append(delimiter);
}
}
return sb.toString();
}
public static String join(Array array, String delimiter, @QuoteStyle int style) {
StringBuilder sb = new StringBuilder();
Value value;
for (int i = 0; i < array.size(); i++) {
value = array.get(i);
if (value.isPrimitive()) {
Primitive primitive = value.getAsPrimitive();
String string;
switch (style) {
case STYLE_NONE:
string = primitive.getAsString();
break;
case STYLE_SINGLE:
string = primitive.getAsSingleQuotedString();
break;
case STYLE_DOUBLE:
string = primitive.getAsDoubleQuotedString();
break;
default:
string = primitive.getAsString();
}
sb.append(string);
} else {
sb.append(value.toString());
}
if (i < array.size() - 1) {
sb.append(delimiter);
}
}
return sb.toString();
}
public static String join(Array array, String delimiter) {
return join(array, delimiter, STYLE_NONE);
}
public static String join(Value[] array, String delimiter, @QuoteStyle int style) {
return join(new Array(array), delimiter, style);
}
public static String join(Value[] array, String delimiter) {
return join(new Array(array), delimiter);
}
public static String getVersion() {
return LIB_NAME + ":" + VERSION;
}
@Retention(RetentionPolicy.SOURCE)
@IntDef({STYLE_NONE, STYLE_SINGLE, STYLE_DOUBLE})
public @interface QuoteStyle {}
}
| 3,479 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ManagerWrapper.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/ManagerWrapper.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.DataContext;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.value.Layout;
import com.flipkart.android.proteus.value.ObjectValue;
/**
* ManagerWrapper
*
* <p>Proxies the implementation of {@link ProteusView.Manager} that simply delegates all of its
* calls to another Manager. Can be subclassed to modify or to add new behavior without changing the
* original Manager.
*
* @author adityasharat
*/
public class ManagerWrapper implements ProteusView.Manager {
private final ProteusView.Manager base;
public ManagerWrapper(ProteusView.Manager base) {
this.base = base;
}
@Override
public void update(@Nullable ObjectValue data) {
base.update(data);
}
@Nullable
@Override
public View findViewById(@NonNull String id) {
return base.findViewById(id);
}
@NonNull
@Override
public ProteusContext getContext() {
return base.getContext();
}
@NonNull
@Override
public Layout getLayout() {
return base.getLayout();
}
@NonNull
@Override
public DataContext getDataContext() {
return base.getDataContext();
}
@Nullable
@Override
public Object getExtras() {
return base.getExtras();
}
@Override
public void setExtras(@Nullable Object extras) {
base.setExtras(extras);
}
public ProteusView.Manager getBaseManager() {
return base;
}
}
| 2,217 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
HashBiMap.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/HashBiMap.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* HashBiMap
*
* @author adityasharat
*/
public class HashBiMap<K, V> implements BiMap<K, V> {
private final HashMap<K, V> map;
private final HashMap<V, K> inverse;
public HashBiMap() {
map = new HashMap<>();
inverse = new HashMap<>();
}
public HashBiMap(int initialCapacity) {
map = new HashMap<>(initialCapacity);
inverse = new HashMap<>(initialCapacity);
}
public HashBiMap(int initialCapacity, float loadFactor) {
map = new HashMap<>(initialCapacity, loadFactor);
inverse = new HashMap<>(initialCapacity, loadFactor);
}
@Nullable
@Override
public V put(@Nullable K key, @Nullable V value) {
return put(key, value, false);
}
@Nullable
@Override
public V put(@Nullable K key, @Nullable V value, boolean force) {
if (force && inverse.containsKey(value)) {
throw new IllegalStateException(value + " is already exists!");
}
inverse.put(value, key);
return map.put(key, value);
}
@Nullable
@Override
public V getValue(@NonNull K key) {
return map.get(key);
}
@Nullable
@Override
public K getKey(@NonNull V value) {
return inverse.get(value);
}
@Override
public void putAll(@NonNull Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
@NonNull
@Override
public Set<V> values() {
return inverse.keySet();
}
@NonNull
@Override
public BiMap<V, K> inverse() {
BiMap<V, K> temp = new HashBiMap<>(inverse.size());
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
temp.put(entry.getValue(), entry.getKey());
}
return temp;
}
}
| 2,519 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
LazilyParsedNumber.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/LazilyParsedNumber.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import java.math.BigDecimal;
/**
* LazilyParsedNumber
*
* <p>This class is copied from Google's implementation of LazilyParsedNumber which can be found at
* the following link @{link
* https://github.com/google/gson/blob/master/gson/src/main/java/com/google/gson/internal/LazilyParsedNumber.java}
*
* @author adityasharat
*/
public class LazilyParsedNumber extends Number {
private final String value;
/**
* @param value must not be null
*/
public LazilyParsedNumber(String value) {
this.value = value;
}
@Override
public int intValue() {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
try {
return (int) Long.parseLong(value);
} catch (NumberFormatException nfe) {
return new BigDecimal(value).intValue();
}
}
}
@Override
public long longValue() {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
return new BigDecimal(value).longValue();
}
}
@Override
public float floatValue() {
return Float.parseFloat(value);
}
@Override
public double doubleValue() {
return Double.parseDouble(value);
}
@Override
public String toString() {
return value;
}
@Override
public int hashCode() {
return value.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LazilyParsedNumber) {
LazilyParsedNumber other = (LazilyParsedNumber) obj;
//noinspection StringEquality
return value == other.value || value.equals(other.value);
}
return false;
}
}
| 2,311 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
AnimationUtils.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/toolbox/AnimationUtils.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.toolbox;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.CycleInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.PathInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Value;
import java.util.Iterator;
/** Defines common utilities for working with animations. */
public class AnimationUtils {
private static final String TAG = "AnimationUtils";
private static final String LINEAR_INTERPOLATOR = "linearInterpolator";
private static final String ACCELERATE_INTERPOLATOR = "accelerateInterpolator";
private static final String DECELERATE_INTERPOLATOR = "decelerateInterpolator";
private static final String ACCELERATE_DECELERATE_INTERPOLATOR =
"accelerateDecelerateInterpolator";
private static final String CYCLE_INTERPOLATOR = "cycleInterpolator";
private static final String ANTICIPATE_INTERPOLATOR = "anticipateInterpolator";
private static final String OVERSHOOT_INTERPOLATOR = "overshootInterpolator";
private static final String ANTICIPATE_OVERSHOOT_INTERPOLATOR = "anticipateOvershootInterpolator";
private static final String BOUNCE_INTERPOLATOR = "bounceInterpolator";
private static final String PATH_INTERPOLATOR = "pathInterpolator";
private static final String TYPE = "type";
private static final String SET = "set";
private static final String ALPHA = "alpha";
private static final String SCALE = "scale";
private static final String ROTATE = "rotate";
private static final String TRANSLATE = "translate";
private static final String PERCENT_SELF = "%";
private static final String PERCENT_RELATIVE_PARENT = "%p";
/**
* Loads an {@link Animation} object from a resource
*
* @param context Application context used to access resources
* @param value JSON representation of the Animation
* @return The animation object reference by the specified id
* @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded
*/
public static Animation loadAnimation(Context context, Value value)
throws Resources.NotFoundException {
Animation anim = null;
if (value.isPrimitive()) {
anim = handleString(context, value.getAsPrimitive().getAsString());
} else if (value.isObject()) {
anim = handleElement(context, value.getAsObject());
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "Could not load animation for : " + value.toString());
}
}
return anim;
}
private static Animation handleString(Context c, String value) {
Animation anim = null;
if (ParseHelper.isTweenAnimationResource(value)) {
try {
Resources r = c.getResources();
int animationId = r.getIdentifier(value, "anim", c.getPackageName());
anim = android.view.animation.AnimationUtils.loadAnimation(c, animationId);
} catch (Exception ex) {
System.out.println("Could not load local resource " + value);
}
}
return anim;
}
private static Animation handleElement(Context context, ObjectValue value) {
Animation anim = null;
String type = value.getAsString(TYPE);
AnimationProperties animationProperties = null;
if (SET.equalsIgnoreCase(type)) {
animationProperties = new AnimationSetProperties(value);
} else if (ALPHA.equalsIgnoreCase(type)) {
animationProperties = new AlphaAnimProperties(value);
} else if (SCALE.equalsIgnoreCase(type)) {
animationProperties = new ScaleAnimProperties(value);
} else if (ROTATE.equalsIgnoreCase(type)) {
animationProperties = new RotateAnimProperties(value);
} else if (TRANSLATE.equalsIgnoreCase(type)) {
animationProperties = new TranslateAnimProperties(value);
}
if (null != animationProperties) {
anim = animationProperties.instantiate(context);
}
return anim;
}
/**
* Loads an {@link Interpolator} object from a resource
*
* @param context Application context used to access resources
* @param value Json representation of the Interpolator
* @return The animation object reference by the specified id
* @throws android.content.res.Resources.NotFoundException
*/
public static Interpolator loadInterpolator(Context context, Value value)
throws Resources.NotFoundException {
Interpolator interpolator = null;
if (value.isPrimitive()) {
interpolator = handleStringInterpolator(context, value.getAsString());
} else if (value.isObject()) {
interpolator = handleElementInterpolator(context, value.getAsObject());
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "Could not load interpolator for : " + value.toString());
}
}
return interpolator;
}
private static Interpolator handleStringInterpolator(Context c, String value) {
Interpolator interpolator = null;
if (ParseHelper.isTweenAnimationResource(value)) {
try {
Resources r = c.getResources();
int interpolatorID = r.getIdentifier(value, "anim", c.getPackageName());
interpolator = android.view.animation.AnimationUtils.loadInterpolator(c, interpolatorID);
} catch (Exception ex) {
System.out.println("Could not load local resource " + value);
}
}
return interpolator;
}
private static Interpolator handleElementInterpolator(Context c, ObjectValue value) {
Interpolator interpolator = null;
String type = value.getAsString("type");
InterpolatorProperties interpolatorProperties = null;
if (LINEAR_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolator = new LinearInterpolator();
} else if (ACCELERATE_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolator = new AccelerateInterpolator();
} else if (DECELERATE_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolator = new DecelerateInterpolator();
} else if (ACCELERATE_DECELERATE_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolator = new AccelerateDecelerateInterpolator();
} else if (CYCLE_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolatorProperties = new CycleInterpolatorProperties(value);
} else if (ANTICIPATE_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolatorProperties = new AnticipateInterpolatorProperties(value);
} else if (OVERSHOOT_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolatorProperties = new OvershootInterpolatorProperties(value);
} else if (ANTICIPATE_OVERSHOOT_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolatorProperties = new AnticipateOvershootInterpolatorProperties(value);
} else if (BOUNCE_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolator = new BounceInterpolator();
} else if (PATH_INTERPOLATOR.equalsIgnoreCase(type)) {
interpolatorProperties = new PathInterpolatorProperties(value);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(TAG, "Unknown interpolator name: " + type);
}
throw new RuntimeException("Unknown interpolator name: " + type);
}
if (null != interpolatorProperties) {
interpolator = interpolatorProperties.createInterpolator(c);
}
return interpolator;
}
/** Utility class to parse a string description of a size. */
private static class Description {
/** One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT. */
public int type;
/** The absolute or relative dimension for this Description. */
public float value;
/**
* Size descriptions can appear in three forms:
*
* <ol>
* <li>An absolute size. This is represented by a number.
* <li>A size relative to the size of the object being animated. This is represented by a
* number followed by "%". *
* <li>A size relative to the size of the parent of object being animated. This is represented
* by a number followed by "%p".
* </ol>
*
* @param value The Json value to parse
* @return The parsed version of the description
*/
static Description parseValue(Value value) {
Description d = new Description();
d.type = Animation.ABSOLUTE;
d.value = 0;
if (value != null && value.isPrimitive()) {
if (value.getAsPrimitive().isNumber()) {
d.type = Animation.ABSOLUTE;
d.value = value.getAsPrimitive().getAsFloat();
} else {
String stringValue = value.getAsPrimitive().getAsString();
if (stringValue.endsWith(PERCENT_SELF)) {
stringValue = stringValue.substring(0, stringValue.length() - PERCENT_SELF.length());
d.value = Float.parseFloat(stringValue) / 100;
d.type = Animation.RELATIVE_TO_SELF;
} else if (stringValue.endsWith(PERCENT_RELATIVE_PARENT)) {
stringValue =
stringValue.substring(0, stringValue.length() - PERCENT_RELATIVE_PARENT.length());
d.value = Float.parseFloat(stringValue) / 100;
d.type = Animation.RELATIVE_TO_PARENT;
} else {
d.type = Animation.ABSOLUTE;
d.value = value.getAsPrimitive().getAsFloat();
}
}
}
return d;
}
}
private abstract static class AnimationProperties {
public static final String DETACH_WALLPAPER = "detachWallpaper";
public static final String DURATION = "duration";
public static final String FILL_AFTER = "fillAfter";
public static final String FILL_BEFORE = "fillBefore";
public static final String FILL_ENABLED = "fillEnabled";
public static final String INTERPOLATOR = "interpolator";
public static final String REPEAT_COUNT = "repeatCount";
public static final String REPEAT_MODE = "repeatMode";
public static final String START_OFFSET = "startOffset";
public static final String Z_ADJUSTMENT = "zAdjustment";
Boolean detachWallpaper;
Long duration;
Boolean fillAfter;
Boolean fillBefore;
Boolean fillEnabled;
Value interpolator;
Integer repeatCount;
Integer repeatMode;
Long startOffset;
Integer zAdjustment;
public AnimationProperties(ObjectValue value) {
detachWallpaper = value.getAsBoolean(DETACH_WALLPAPER);
duration = value.getAsLong(DURATION);
fillAfter = value.getAsBoolean(FILL_AFTER);
fillBefore = value.getAsBoolean(FILL_BEFORE);
fillEnabled = value.getAsBoolean(FILL_ENABLED);
interpolator = value.get(INTERPOLATOR);
repeatCount = value.getAsInteger(REPEAT_COUNT);
repeatMode = value.getAsInteger(REPEAT_MODE);
startOffset = value.getAsLong(START_OFFSET);
zAdjustment = value.getAsInteger(Z_ADJUSTMENT);
}
public Animation instantiate(Context c) {
Animation anim = createAnimation(c);
if (null != anim) {
if (null != detachWallpaper) {
anim.setDetachWallpaper(detachWallpaper);
}
if (null != duration) {
anim.setDuration(duration);
}
if (null != fillAfter) {
anim.setFillAfter(fillAfter);
}
if (null != fillBefore) {
anim.setFillBefore(fillBefore);
}
if (null != fillEnabled) {
anim.setFillEnabled(fillEnabled);
}
if (null != interpolator) {
Interpolator i = loadInterpolator(c, interpolator);
if (null != i) {
anim.setInterpolator(i);
}
}
if (null != repeatCount) {
anim.setRepeatCount(repeatCount);
}
if (null != repeatMode) {
anim.setRepeatMode(repeatMode);
}
if (null != startOffset) {
anim.setStartOffset(startOffset);
}
if (null != zAdjustment) {
anim.setZAdjustment(zAdjustment);
}
}
return anim;
}
abstract Animation createAnimation(Context c);
}
private static class AnimationSetProperties extends AnimationProperties {
public static final String SHARE_INTERPOLATOR = "shareInterpolator";
public static final String CHILDREN = "children";
Boolean shareInterpolator;
Value children;
public AnimationSetProperties(ObjectValue value) {
super(value);
shareInterpolator = value.getAsBoolean(SHARE_INTERPOLATOR);
children = value.get(CHILDREN);
}
@Override
Animation createAnimation(Context c) {
AnimationSet animationSet =
new AnimationSet(shareInterpolator == null ? true : shareInterpolator);
if (null != children) {
if (children.isArray()) {
Iterator<Value> iterator = children.getAsArray().iterator();
while (iterator.hasNext()) {
Animation animation = loadAnimation(c, iterator.next());
if (null != animation) {
animationSet.addAnimation(animation);
}
}
} else if (children.isObject() || children.isPrimitive()) {
Animation animation = loadAnimation(c, children);
if (null != animation) {
animationSet.addAnimation(animation);
}
}
}
return animationSet;
}
}
private static class AlphaAnimProperties extends AnimationProperties {
public static final String FROM_ALPHA = "fromAlpha";
public static final String TO_ALPHA = "toAlpha";
public Float fromAlpha;
public Float toAlpha;
public AlphaAnimProperties(ObjectValue value) {
super(value);
fromAlpha = value.getAsFloat(FROM_ALPHA);
toAlpha = value.getAsFloat(TO_ALPHA);
}
@Override
Animation createAnimation(Context c) {
return null == fromAlpha || null == toAlpha ? null : new AlphaAnimation(fromAlpha, toAlpha);
}
}
private static class ScaleAnimProperties extends AnimationProperties {
public static final String FROM_X_SCALE = "fromXScale";
public static final String TO_X_SCALE = "toXScale";
public static final String FROM_Y_SCALE = "fromYScale";
public static final String TO_Y_SCALE = "toYScale";
public static final String PIVOT_X = "pivotX";
public static final String PIVOT_Y = "pivotY";
public Float fromXScale;
public Float toXScale;
public Float fromYScale;
public Float toYScale;
public Value pivotX;
public Value pivotY;
public ScaleAnimProperties(ObjectValue value) {
super(value);
fromXScale = value.getAsFloat(FROM_X_SCALE);
toXScale = value.getAsFloat(TO_X_SCALE);
fromYScale = value.getAsFloat(FROM_Y_SCALE);
toYScale = value.getAsFloat(TO_Y_SCALE);
pivotX = value.get(PIVOT_X);
pivotY = value.get(PIVOT_Y);
}
@Override
Animation createAnimation(Context c) {
if (pivotX != null && pivotY != null) {
Description pivotXDesc = Description.parseValue(pivotX);
Description pivotYDesc = Description.parseValue(pivotY);
return new ScaleAnimation(
fromXScale,
toXScale,
fromYScale,
toYScale,
pivotXDesc.type,
pivotXDesc.value,
pivotYDesc.type,
pivotYDesc.value);
} else {
return new ScaleAnimation(fromXScale, toXScale, fromYScale, toYScale);
}
}
}
private static class TranslateAnimProperties extends AnimationProperties {
public static final String FROM_X_DELTA = "fromXDelta";
public static final String TO_X_DELTA = "toXDelta";
public static final String FROM_Y_DELTA = "fromYDelta";
public static final String TO_Y_DELTA = "toYDelta";
public Value fromXDelta;
public Value toXDelta;
public Value fromYDelta;
public Value toYDelta;
public TranslateAnimProperties(ObjectValue value) {
super(value);
fromXDelta = value.get(FROM_X_DELTA);
toXDelta = value.get(TO_X_DELTA);
fromXDelta = value.get(FROM_Y_DELTA);
toYDelta = value.get(TO_Y_DELTA);
}
@Override
Animation createAnimation(Context c) {
Description fromXDeltaDescription = Description.parseValue(fromXDelta);
Description toXDeltaDescription = Description.parseValue(toXDelta);
Description fromYDeltaDescription = Description.parseValue(fromYDelta);
Description toYDeltaDescription = Description.parseValue(toYDelta);
return new TranslateAnimation(
fromXDeltaDescription.type,
fromXDeltaDescription.value,
toXDeltaDescription.type,
toXDeltaDescription.value,
fromYDeltaDescription.type,
fromYDeltaDescription.value,
toYDeltaDescription.type,
toYDeltaDescription.value);
}
}
private static class RotateAnimProperties extends AnimationProperties {
public static final String FROM_DEGREES = "fromDegrees";
public static final String TO_DEGREES = "toDegrees";
public static final String PIVOT_X = "pivotX";
public static final String PIVOT_Y = "pivotY";
public Float fromDegrees;
public Float toDegrees;
public Value pivotX;
public Value pivotY;
public RotateAnimProperties(ObjectValue value) {
super(value);
fromDegrees = value.getAsFloat(FROM_DEGREES);
toDegrees = value.getAsFloat(TO_DEGREES);
pivotX = value.get(PIVOT_X);
pivotY = value.get(PIVOT_Y);
}
@Override
Animation createAnimation(Context c) {
if (null != pivotX && null != pivotY) {
Description pivotXDesc = Description.parseValue(pivotX);
Description pivotYDesc = Description.parseValue(pivotY);
return new RotateAnimation(
fromDegrees,
toDegrees,
pivotXDesc.type,
pivotXDesc.value,
pivotYDesc.type,
pivotYDesc.value);
} else {
return new RotateAnimation(fromDegrees, toDegrees);
}
}
}
private abstract static class InterpolatorProperties {
public InterpolatorProperties(Value value) {}
abstract Interpolator createInterpolator(Context c);
}
private static class PathInterpolatorProperties extends InterpolatorProperties {
public static final String CONTROL_X1 = "controlX1";
public static final String CONTROL_Y1 = "controlY1";
public static final String CONTROL_X2 = "controlX2";
public static final String CONTROL_Y2 = "controlY2";
public Float controlX1;
public Float controlY1;
public Float controlX2;
public Float controlY2;
public PathInterpolatorProperties(ObjectValue parser) {
super(parser);
controlX1 = parser.getAsFloat(CONTROL_X1);
controlY1 = parser.getAsFloat(CONTROL_Y1);
controlX2 = parser.getAsFloat(CONTROL_X2);
controlY2 = parser.getAsFloat(CONTROL_Y2);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
Interpolator createInterpolator(Context c) {
if (null != controlX2 && null != controlY2) {
return new PathInterpolator(controlX1, controlY1, controlX2, controlY2);
} else {
return new PathInterpolator(controlX1, controlY1);
}
}
}
private static class AnticipateInterpolatorProperties extends InterpolatorProperties {
public static final String TENSION = "tension";
public Float tension;
public AnticipateInterpolatorProperties(ObjectValue parser) {
super(parser);
tension = parser.getAsFloat(TENSION);
}
Interpolator createInterpolator(Context c) {
return new AnticipateInterpolator(tension);
}
}
private static class OvershootInterpolatorProperties extends InterpolatorProperties {
public static final String TENSION = "tension";
public Float tension;
public OvershootInterpolatorProperties(ObjectValue parser) {
super(parser);
tension = parser.getAsFloat(TENSION);
}
Interpolator createInterpolator(Context c) {
return tension == null ? new OvershootInterpolator() : new OvershootInterpolator(tension);
}
}
private static class AnticipateOvershootInterpolatorProperties extends InterpolatorProperties {
public static final String TENSION = "tension";
public static final String EXTRA_TENSION = "extraTension";
public Float tension;
public Float extraTension;
public AnticipateOvershootInterpolatorProperties(ObjectValue parser) {
super(parser);
tension = parser.getAsFloat(TENSION);
extraTension = parser.getAsFloat(EXTRA_TENSION);
}
Interpolator createInterpolator(Context c) {
return null == tension
? new AnticipateOvershootInterpolator()
: (null == extraTension
? new AnticipateOvershootInterpolator(tension)
: new AnticipateOvershootInterpolator(tension, extraTension));
}
}
private static class CycleInterpolatorProperties extends InterpolatorProperties {
public static final String CYCLES = "cycles";
public Float cycles;
public CycleInterpolatorProperties(ObjectValue parser) {
super(parser);
cycles = parser.getAsFloat(CYCLES);
}
Interpolator createInterpolator(Context c) {
return new CycleInterpolator(cycles);
}
}
}
| 22,694 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
TweenAnimationResourceProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/TweenAnimationResourceProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.toolbox.AnimationUtils;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* TweenAnimationResourceProcessor
*
* <p>TODO: implement pre compiling animation blocks
*
* @author yasirmhd
*/
public abstract class TweenAnimationResourceProcessor<V extends View>
extends AttributeProcessor<V> {
private static final String TAG = "TweenAnimationResource";
@Override
public void handleValue(View parent, V view, Value value) {
Animation animation = AnimationUtils.loadAnimation(view.getContext(), value);
if (null != animation) {
setAnimation(view, animation);
} else {
if (ProteusConstants.isLoggingEnabled()) {
Log.e(
TAG,
"Animation Resource must be a primitive or an object. value -> " + value.toString());
}
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {}
@Override
public void handleStyle(View parent, V view, Style style) {}
public abstract void setAnimation(V view, Animation animation);
}
| 2,137 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
DrawableResourceProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DrawableResourceProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusLayoutInflater;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Color;
import com.flipkart.android.proteus.value.DrawableValue;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* Use this as the base processor for references like @drawable or remote resources with http://
* urls.
*/
public abstract class DrawableResourceProcessor<V extends View> extends AttributeProcessor<V> {
@Nullable
public static Drawable evaluate(Value value, View view) {
if (null == value) {
return null;
}
final Drawable[] d = new Drawable[1];
DrawableResourceProcessor<View> processor =
new DrawableResourceProcessor<View>() {
@Override
public void setDrawable(View view, Drawable drawable) {
d[0] = drawable;
}
};
processor.process((View) view.getParent(), view, value);
return d[0];
}
public static Value staticCompile(@Nullable Value value, ProteusContext context) {
if (null == value) {
return DrawableValue.ColorValue.BLACK;
}
if (value.isDrawable()) {
return value;
} else if (value.isPrimitive()) {
Value precompiled =
AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null);
if (null != precompiled) {
return precompiled;
}
return DrawableValue.valueOf(value.getAsString(), context);
} else if (value.isObject()) {
return DrawableValue.valueOf(value.getAsObject(), context);
} else {
return DrawableValue.ColorValue.BLACK;
}
}
@Override
public void handleValue(View parent, final V view, Value value) {
if (value.isDrawable()) {
DrawableValue d = value.getAsDrawable();
if (null != d) {
ProteusContext context = ProteusHelper.getProteusContext(view);
ProteusLayoutInflater.ImageLoader loader = context.getLoader();
d.apply(
view,
context,
loader,
drawable -> {
setDrawable(view, drawable);
});
}
} else {
if (value.isPrimitive() && value.toString().equals("@null")) {
setDrawable(view, null);
} else {
process(
parent,
view,
precompile(
value,
ProteusHelper.getProteusContext(view),
(ProteusHelper.getProteusContext(view)).getFunctionManager()));
}
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {
ProteusContext context = ProteusHelper.getProteusContext(view);
DrawableValue drawableValue = resource.getProteusDrawable(context);
if (drawableValue == null) {
Drawable d = resource.getDrawable(context);
if (d == null) {
Color color = resource.getColor(context);
if (color != null) {
d = new ColorDrawable(color.apply(parent, view).color);
}
}
if (null != d) {
setDrawable(view, d);
}
} else {
drawableValue.apply(
view,
context,
context.getLoader(),
drawable -> {
setDrawable(view, drawable);
});
}
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
TypedArray a = attribute.apply(view.getContext());
set(view, a);
}
@Override
public void handleStyle(View parent, V view, Style style) {
// TypedArray a = style.apply(view.getContext());
// set(view, a);
}
private void set(V view, TypedArray a) {
Drawable d = a.getDrawable(0);
if (null != d) {
setDrawable(view, d);
}
}
public abstract void setDrawable(V view, Drawable drawable);
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
return staticCompile(value, context);
}
}
| 5,002 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
NumberAttributeProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/NumberAttributeProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.view.View;
import androidx.annotation.NonNull;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* NumberAttributeProcessor
*
* @author adityasharat
*/
public abstract class NumberAttributeProcessor<V extends View> extends AttributeProcessor<V> {
@Override
public void handleValue(View parent, V view, Value value) {
if (value.isPrimitive()) {
setNumber(view, value.getAsPrimitive().getAsNumber());
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {
Integer number = resource.getInteger(view.getContext());
setNumber(view, null != number ? number : 0);
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
setNumber(view, attribute.apply(view.getContext()).getFloat(0, 0f));
}
@Override
public void handleStyle(View parent, V view, Style style) {
// setNumber(view, style.apply(view.getContext()).getFloat(0, 0f));
}
public abstract void setNumber(V view, @NonNull Number value);
}
| 1,871 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
AttributeProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/AttributeProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.view.View;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.DataContext;
import com.flipkart.android.proteus.FunctionManager;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Binding;
import com.flipkart.android.proteus.value.Gravity;
import com.flipkart.android.proteus.value.NestedBinding;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Primitive;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* @author kirankumar
* @author adityasharat
*/
public abstract class AttributeProcessor<V extends View> {
public static Value evaluate(
final ProteusContext context,
final View parent,
final Value input,
final Value data,
final int index) {
final Value[] output = new Value[1];
AttributeProcessor processor =
new AttributeProcessor<View>() {
@Override
public void handleBinding(View parent, View view, Binding binding) {
output[0] = binding.evaluate(context, data, index);
}
@Override
public void handleValue(View parent, View view, Value value) {
output[0] = value;
}
@Override
public void handleResource(View parent, View view, Resource resource) {
output[0] = new Primitive(resource.getString(context));
}
@Override
public void handleAttributeResource(View parent, View view, AttributeResource attribute) {
output[0] = new Primitive(attribute.apply(context).getString(0));
}
@Override
public void handleStyle(View parent, View view, Style style) {
output[0] = style;
}
};
//noinspection unchecked
processor.process(parent, null, input);
return output[0];
}
@Nullable
public static Value staticPreCompile(
Primitive value, ProteusContext context, FunctionManager manager) {
String string = value.getAsString();
if (Gravity.isGravity(string)) {
return Gravity.of(ParseHelper.parseGravity(string));
} else if (Binding.isBindingValue(string)) {
return Binding.valueOf(string, context, manager);
} else if (Resource.isResource(string)) {
return Resource.valueOf(string, context);
} else if (AttributeResource.isAttributeResource(string)) {
return AttributeResource.valueOf(string);
} else if (Style.isStyle(string)) {
return Style.valueOf(string, context);
}
return null;
}
@Nullable
public static Value staticPreCompile(
ObjectValue object, ProteusContext context, FunctionManager manager) {
Value binding = object.get(NestedBinding.NESTED_BINDING_KEY);
if (null != binding) {
return NestedBinding.valueOf(binding);
}
return null;
}
@Nullable
public static Value staticPreCompile(
Value value, ProteusContext context, FunctionManager manager) {
Value compiled = null;
if (value.isPrimitive()) {
compiled = staticPreCompile(value.getAsPrimitive(), context, manager);
} else if (value.isObject()) {
compiled = staticPreCompile(value.getAsObject(), context, manager);
} else if (value.isBinding()
|| value.isResource()
|| value.isAttributeResource()
|| value.isStyle()) {
return value;
}
return compiled;
}
public void process(View parent, V view, Value value) {
if (value.isBinding()) {
handleBinding(parent, view, value.getAsBinding());
} else if (value.isResource()) {
handleResource(parent, view, value.getAsResource());
} else if (value.isAttributeResource()) {
handleAttributeResource(parent, view, value.getAsAttributeResource());
} else if (value.isStyle()) {
handleStyle(parent, view, value.getAsStyle());
} else {
handleValue(parent, view, value);
}
}
public void handleBinding(View parent, V view, Binding value) {
DataContext dataContext = ((ProteusView) view).getViewManager().getDataContext();
Value resolved =
evaluate(
value,
ProteusHelper.getProteusContext(view),
dataContext.getData(),
dataContext.getIndex());
handleValue(parent, view, resolved);
}
public abstract void handleValue(View parent, V view, Value value);
public abstract void handleResource(View parent, V view, Resource resource);
public abstract void handleAttributeResource(View parent, V view, AttributeResource attribute);
public abstract void handleStyle(View parent, V view, Style style);
public Value precompile(Value value, ProteusContext context, FunctionManager manager) {
Value compiled = staticPreCompile(value, context, manager);
return null != compiled ? compiled : compile(value, context);
}
public Value compile(@Nullable Value value, ProteusContext context) {
return value;
}
protected Value evaluate(Binding binding, ProteusContext context, Value data, int index) {
return binding.evaluate(context, data, index);
}
}
| 6,094 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
DimensionAttributeProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/DimensionAttributeProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.content.res.TypedArray;
import android.view.View;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Dimension;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/** */
public abstract class DimensionAttributeProcessor<T extends View> extends AttributeProcessor<T> {
public static float evaluate(Value value, View view) {
if (value == null) {
return Dimension.ZERO.apply(view.getContext());
}
final float[] result = new float[1];
DimensionAttributeProcessor<View> processor =
new DimensionAttributeProcessor<View>() {
@Override
public void setDimension(View view, float dimension) {
result[0] = dimension;
}
};
processor.process((View) view.getParent(), view, value);
return result[0];
}
public static Value staticCompile(@Nullable Value value, ProteusContext context) {
if (null == value || !value.isPrimitive()) {
return Dimension.ZERO;
}
if (value.isDimension()) {
return value;
}
Value precompiled = staticPreCompile(value.getAsPrimitive(), context, null);
if (null != precompiled) {
return precompiled;
}
return Dimension.valueOf(value.getAsString());
}
@Override
public final void handleValue(View parent, T view, Value value) {
if (value.isDimension()) {
setDimension(view, value.getAsDimension().apply(view.getContext()));
} else if (value.isPrimitive()) {
process(
parent,
view,
precompile(
value,
ProteusHelper.getProteusContext(view),
(ProteusHelper.getProteusContext(view)).getFunctionManager()));
}
}
@Override
public void handleResource(View parent, T view, Resource resource) {
Dimension dimension = resource.getDimension(ProteusHelper.getProteusContext(view));
setDimension(
view, null == dimension ? 0 : dimension.apply(ProteusHelper.getProteusContext(view)));
}
@Override
public void handleAttributeResource(View parent, T view, AttributeResource attribute) {
TypedArray a = attribute.apply(view.getContext());
setDimension(view, a.getDimensionPixelSize(0, 0));
}
@Override
public void handleStyle(View parent, T view, Style style) {
System.out.println("Handle style: " + style);
// TypedArray a = style.apply(view.getContext());
// setDimension(view, a.getDimensionPixelSize(0, 0));
}
/**
* @param view View
*/
public abstract void setDimension(T view, float dimension);
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
return staticCompile(value, context);
}
}
| 3,627 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
BooleanAttributeProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/BooleanAttributeProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.content.res.TypedArray;
import android.view.View;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* BooleanAttributeProcessor
*
* @author aditya.sharat
*/
public abstract class BooleanAttributeProcessor<V extends View> extends AttributeProcessor<V> {
@Override
public void handleValue(View parent, V view, Value value) {
if (value.isPrimitive() && value.getAsPrimitive().isBoolean()) {
setBoolean(view, value.getAsPrimitive().getAsBoolean());
} else {
process(
parent,
view,
precompile(
value,
(ProteusContext) view.getContext(),
ProteusHelper.getProteusContext(view).getFunctionManager()));
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {
Boolean bool = resource.getBoolean(view.getContext());
setBoolean(view, null != bool ? bool : false);
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
TypedArray a = attribute.apply(view.getContext());
setBoolean(view, a.getBoolean(0, false));
}
@Override
public void handleStyle(View parent, V view, Style style) {
// TypedArray a = style.apply(view.getContext());
// setBoolean(view, a.getBoolean(0, false));
}
public abstract void setBoolean(V view, boolean value);
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
return ParseHelper.parseBoolean(value) ? ProteusConstants.TRUE : ProteusConstants.FALSE;
}
}
| 2,642 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
EventProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EventProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.view.View;
import com.flipkart.android.proteus.ProteusLayoutInflater;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* EventProcessor
*
* <p>
*
* <p>Use this Attribute Processor to get event callbacks on the {@link
* com.flipkart.android.proteus.ProteusLayoutInflater.Callback#onEvent(String, Value, ProteusView)}
*
* @author adityasharat
*/
public abstract class EventProcessor<T extends View> extends AttributeProcessor<T> {
@Override
public void handleValue(View parent, T view, Value value) {
setOnEventListener(view, value);
}
@Override
public void handleResource(View parent, T view, Resource resource) {
setOnEventListener(view, resource);
}
@Override
public void handleAttributeResource(View parent, T view, AttributeResource attribute) {
setOnEventListener(view, attribute);
}
@Override
public void handleStyle(View parent, T view, Style style) {
setOnEventListener(view, style);
}
public abstract void setOnEventListener(T view, Value value);
/**
* @param event
* @param value
* @param view
*/
public void trigger(String event, Value value, ProteusView view) {
ProteusLayoutInflater.Callback callback = view.getViewManager().getContext().getCallback();
if (null != callback) {
callback.onEvent(event, value, view);
}
}
}
| 2,218 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ColorResourceProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ColorResourceProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.view.View;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Color;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
public abstract class ColorResourceProcessor<V extends View> extends AttributeProcessor<V> {
public static Color.Result evaluate(Value value, View view) {
final Color.Result[] result = new Color.Result[1];
ColorResourceProcessor<View> processor =
new ColorResourceProcessor<View>() {
@Override
public void setColor(View view, int color) {
result[0] = Color.Result.color(color);
}
@Override
public void setColor(View view, ColorStateList colors) {
result[0] = Color.Result.colors(colors);
}
};
processor.process((View) view.getParent(), view, value);
return result[0];
}
public static Value staticCompile(@Nullable Value value, ProteusContext context) {
if (null == value) {
return Color.Int.getDefaultColor();
}
if (value.isColor()) {
return value;
} else if (value.isObject()) {
return Color.valueOf(value.getAsObject(), context);
} else if (value.isPrimitive()) {
if ("@null".equals(value.toString())) {
return Color.Int.valueOf(android.graphics.Color.TRANSPARENT);
}
Value precompiled = staticPreCompile(value.getAsPrimitive(), context, null);
if (null != precompiled) {
return precompiled;
}
return Color.valueOf(value.getAsString(), Color.Int.getDefaultColor());
} else {
return Color.Int.getDefaultColor();
}
}
@Override
public void handleValue(View parent, final V view, Value value) {
if (value.isColor()) {
apply(parent, view, value.getAsColor());
} else if (value.isResource()) {
handleResource(parent, view, value.getAsResource());
} else if (value.isPrimitive()) {
process(
parent,
view,
precompile(
value,
ProteusHelper.getProteusContext(view),
(ProteusHelper.getProteusContext(view)).getFunctionManager()));
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {
ColorStateList colors = resource.getColorStateList(parent, view);
if (null != colors) {
setColor(view, colors);
} else {
Color color = resource.getColor(ProteusHelper.getProteusContext(view));
setColor(view, null == color ? Color.Int.getDefaultColor().value : color.getAsInt());
}
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
String name = attribute.getName();
ProteusView.Manager viewManager = ((ProteusView) view).getViewManager();
ProteusContext context = viewManager.getContext();
Value value = context.obtainStyledAttribute(parent, view, name);
process(parent, view, value != null ? value : Color.Int.getDefaultColor());
}
@Override
public void handleStyle(View parent, V view, Style style) {
// TypedArray a = style.apply(view.getContext());
// set(view, a);
}
private void set(V view, TypedArray a) {
ColorStateList colors = a.getColorStateList(0);
if (null != colors) {
setColor(view, colors);
} else {
setColor(view, a.getColor(0, Color.Int.getDefaultColor().value));
}
}
// private void apply(ProteusContext context, V view, Value value) {
// if (value.isResource()) {
// value = value.getAsResource().getColor(context);
// }
// if (value != null) {
// apply(parent, view, value.getAsColor());
// }
// }
private void apply(View parent, V view, Color color) {
Color.Result result = color.apply(parent, view);
if (null != result.colors) {
setColor(view, result.colors);
} else {
setColor(view, result.color);
}
}
public abstract void setColor(V view, int color);
public abstract void setColor(V view, ColorStateList colors);
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
return staticCompile(value, context);
}
}
| 5,199 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
EnumProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/EnumProcessor.java | package com.flipkart.android.proteus.processor;
import android.view.View;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
import java.util.Map;
public abstract class EnumProcessor<V extends View> extends AttributeProcessor<V> {
private final Map<String, Integer> values;
public EnumProcessor(Map<String, Integer> values) {
this.values = values;
}
@Override
public void handleValue(View parent, V view, Value value) {
String name = value.getAsString();
Integer integer = values.get(name);
if (integer != null) {
apply(view, integer);
} else {
applyOther(view, name);
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {}
@Override
public void handleStyle(View parent, V view, Style style) {}
public abstract void apply(V view, int value);
public abstract void applyOther(V view, String value);
}
| 1,161 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
StringAttributeProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StringAttributeProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import android.content.res.TypedArray;
import android.util.Log;
import android.view.View;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusConstants;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
/**
* @author kirankumar
* @author aditya.sharat
*/
public abstract class StringAttributeProcessor<V extends View> extends AttributeProcessor<V> {
/**
* @param parent
* @param view View
* @param value
*/
@Override
public void handleValue(View parent, V view, Value value) {
if (value.isPrimitive() || value.isNull()) {
setString(view, value.getAsString());
} else {
setString(view, "[Object]");
}
}
@Override
public void handleResource(View parent, V view, Resource resource) {
String string = resource.getString(ProteusHelper.getProteusContext(view));
setString(view, null == string ? ProteusConstants.EMPTY : string);
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
TypedArray a = attribute.apply(view.getContext());
setString(view, a.getString(0));
}
@Override
public void handleStyle(View parent, V view, Style style) {
Log.d("TEST", "Handle style called: " + style.toString());
// TypedArray a = style.apply(view.getContext());
// setString(view, a.getString(0));
}
/**
* @param view View
*/
public abstract void setString(V view, String value);
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
if (null == value || value.isNull()) {
return ProteusConstants.EMPTY_STRING;
}
return value;
}
}
| 2,584 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
GravityAttributeProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/GravityAttributeProcessor.java | /*
* Copyright 2019 Flipkart Internet Pvt. Ltd.
*
* 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.flipkart.android.proteus.processor;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import android.content.res.TypedArray;
import android.view.View;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.parser.ParseHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* GravityAttributeProcessor
*
* @author aditya.sharat
*/
public abstract class GravityAttributeProcessor<V extends View> extends AttributeProcessor<V> {
public static final com.flipkart.android.proteus.value.Gravity NO_GRAVITY =
new com.flipkart.android.proteus.value.Gravity(android.view.Gravity.NO_GRAVITY);
@Override
public void handleValue(View parent, V view, Value value) {
int gravity = android.view.Gravity.NO_GRAVITY;
if (value instanceof com.flipkart.android.proteus.value.Gravity) {
gravity = value.getAsInt();
} else {
if (value.isPrimitive() && value.getAsPrimitive().isNumber()) {
gravity = value.getAsInt();
} else if (value.isPrimitive()) {
gravity = ParseHelper.parseGravity(value.getAsString());
}
}
//noinspection WrongConstant
setGravity(view, gravity);
}
@Override
public void handleResource(View parent, V view, Resource resource) {
Integer gravity = resource.getInteger(view.getContext());
//noinspection WrongConstant
setGravity(view, null != gravity ? gravity : android.view.Gravity.NO_GRAVITY);
}
@Override
public void handleAttributeResource(View parent, V view, AttributeResource attribute) {
TypedArray a = attribute.apply(view.getContext());
set(view, a);
}
@Override
public void handleStyle(View parent, V view, Style style) {
// TypedArray a = style.apply(view.getContext());
// set(view, a);
}
private void set(V view, TypedArray a) {
setGravity(view, a.getInt(0, android.view.Gravity.NO_GRAVITY));
}
public abstract void setGravity(V view, @Gravity int gravity);
@Override
public Value compile(@Nullable Value value, ProteusContext context) {
if (null == value) {
return NO_GRAVITY;
}
return ParseHelper.getGravity(value.getAsString());
}
@IntDef({
android.view.Gravity.NO_GRAVITY,
android.view.Gravity.TOP,
android.view.Gravity.BOTTOM,
android.view.Gravity.LEFT,
android.view.Gravity.RIGHT,
android.view.Gravity.START,
android.view.Gravity.END,
android.view.Gravity.CENTER_VERTICAL,
android.view.Gravity.FILL_VERTICAL,
android.view.Gravity.CENTER_HORIZONTAL,
android.view.Gravity.FILL_HORIZONTAL,
android.view.Gravity.CENTER,
android.view.Gravity.FILL
})
@Retention(RetentionPolicy.SOURCE)
@Target({FIELD, METHOD, PARAMETER, LOCAL_VARIABLE, TYPE})
public @interface Gravity {}
}
| 3,979 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
ShapeAppearanceProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/ShapeAppearanceProcessor.java | package com.flipkart.android.proteus.processor;
import android.view.View;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Dimension;
import com.flipkart.android.proteus.value.ObjectValue;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
import com.google.android.material.shape.CornerFamily;
import com.google.android.material.shape.ShapeAppearanceModel;
public abstract class ShapeAppearanceProcessor<V extends View> extends AttributeProcessor<V> {
@Override
public void handleValue(View parent, View view, Value value) {
if (value.isStyle()) {
handleStyle(parent, view, value.getAsStyle());
} else if (value.isAttributeResource()) {
handleAttributeResource(parent, view, value.getAsAttributeResource());
} else if (value.isResource()) {
handleResource(parent, view, value.getAsResource());
} else if (value.isPrimitive()) {
ProteusContext context = ProteusHelper.getProteusContext(view);
value = staticPreCompile(value, context, context.getFunctionManager());
if (value != null) {
handleValue(parent, view, value);
}
}
}
@Override
public void handleResource(View parent, View view, Resource resource) {
System.out.println("resource: " + resource);
}
@Override
public void handleAttributeResource(View parent, View view, AttributeResource attribute) {
ProteusContext context = ProteusHelper.getProteusContext(view);
String name = attribute.getName();
Style style = context.getStyle();
Value value = style.getValue(name, context, null);
if (value != null) {
handleValue(parent, view, value);
}
}
@Override
public void handleStyle(View parent, View view, Style style) {
ProteusContext context = ProteusHelper.getProteusContext(view);
ObjectValue values = style.getValues();
if (values != null) {
ShapeAppearanceModel.Builder builder = ShapeAppearanceModel.builder();
int cornerFamilyInt = CornerFamily.ROUNDED;
Value cornerFamily = values.get("cornerFamily");
if (cornerFamily != null) {
String name = cornerFamily.toString();
if ("cut".equals(name)) {
cornerFamilyInt = CornerFamily.CUT;
}
}
Value cornerSize = values.get("cornerSize");
if (cornerSize != null) {
cornerSize = DimensionAttributeProcessor.staticCompile(cornerSize, context);
}
if (cornerSize != null) {
if (!cornerSize.isDimension()) {
cornerSize = resolveDimension(cornerSize, view, context);
}
builder.setAllCorners(cornerFamilyInt, cornerSize.getAsDimension().apply(context));
}
setShapeAppearance(view, builder.build());
}
}
private Dimension resolveDimension(Value resource, View view, ProteusContext context) {
if (resource.isDimension()) {
return resource.getAsDimension();
}
if (resource.isResource()) {
return resource.getAsResource().getDimension(context);
}
if (resource.isAttributeResource()) {
return resolveDimension(
resource.getAsAttributeResource().resolve((View) view.getParent(), view, context),
view,
context);
}
return null;
}
public abstract void setShapeAppearance(View view, ShapeAppearanceModel model);
}
| 3,540 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
StyleResourceProcessor.java | /FileExtraction/Java_unseen/Deenu488_CodeAssist-Unofficial/proteus-core/src/main/java/com/flipkart/android/proteus/processor/StyleResourceProcessor.java | package com.flipkart.android.proteus.processor;
import android.view.View;
import com.flipkart.android.proteus.ProteusContext;
import com.flipkart.android.proteus.ProteusView;
import com.flipkart.android.proteus.toolbox.ProteusHelper;
import com.flipkart.android.proteus.value.AttributeResource;
import com.flipkart.android.proteus.value.Resource;
import com.flipkart.android.proteus.value.Style;
import com.flipkart.android.proteus.value.Value;
public class StyleResourceProcessor<V extends View> extends AttributeProcessor<V> {
@Override
public void handleValue(View parent, View view, Value value) {
if (value.isStyle()) {
handleStyle(parent, view, value.getAsStyle());
} else {
if (value.isPrimitive()) {
ProteusContext context = ProteusHelper.getProteusContext(view);
Value value1 = Style.valueOf(value.toString(), context);
if (value1 != null && value1.isStyle()) {
handleStyle(parent, view, value1.getAsStyle());
}
}
}
}
@Override
public void handleResource(View parent, View view, Resource resource) {}
@Override
public void handleAttributeResource(View parent, View view, AttributeResource attribute) {
ProteusContext context = ProteusHelper.getProteusContext(view);
String name = attribute.getName();
Value value = context.obtainStyledAttribute(parent, view, name);
if (value != null) {
if (value.isStyle()) {
handleStyle(parent, view, value.getAsStyle());
} else if (value.isPrimitive()) {
String styleName = value.toString();
Style style1 = context.getStyle(styleName);
if (style1 != null) {
handleStyle(parent, view, style1);
}
}
}
}
@Override
public void handleStyle(View parent, View view, Style style) {
style.applyStyle(parent, (ProteusView) view, false);
}
}
| 1,868 | Java | .java | Deenu488/CodeAssist-Unofficial | 122 | 27 | 2 | 2022-12-13T08:34:02Z | 2024-05-08T01:27:41Z |
MediaButtonIntentReceiver.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/MediaButtonIntentReceiver.java | package cz.martykan.webtube;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
public class MediaButtonIntentReceiver extends BroadcastReceiver {
public MediaButtonIntentReceiver() {
super();
}
@Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
return;
}
KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
Log.i("Key", event.getKeyCode() + " pressed");
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PAUSE || event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || event.getKeyCode() == 79) {
try {
MainActivity.toggleVideo();
} catch (Exception e) {
// Activity is not running
e.printStackTrace();
}
}
}
}
}
| 1,165 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
NotificationCloser.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/NotificationCloser.java | package cz.martykan.webtube;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
public class NotificationCloser extends AppCompatActivity {
public static final String NOTIFICATION_ID = "NOTIFICATION_ID";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("CLOSED", "closing");
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.cancel(getIntent().getIntExtra(NOTIFICATION_ID, -1));
try {
MainActivity.pauseVideo();
} catch (Exception e) {
// Activity is not running
}
finish(); // since finish() is called in onCreate(), onDestroy() will be called immediately
}
public static PendingIntent getDismissIntent(int notificationId, Context context) {
Intent intent = new Intent(context, NotificationCloser.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(NOTIFICATION_ID, notificationId);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
}
| 1,372 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
WebTubeChromeClient.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/WebTubeChromeClient.java | package cz.martykan.webtube;
import android.os.Build;
import androidx.drawerlayout.widget.DrawerLayout;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
public class WebTubeChromeClient extends WebChromeClient {
View mCustomView;
ProgressBar progress;
WebView webView;
FrameLayout customViewContainer;
DrawerLayout drawerLayout;
View decorView;
public WebTubeChromeClient(WebView webView, ProgressBar progress, FrameLayout customViewContainer, DrawerLayout drawerLayout, View decorView) {
this.webView = webView;
this.progress = progress;
this.customViewContainer = customViewContainer;
this.drawerLayout = drawerLayout;
this.decorView = decorView;
}
// Fullscreen playback
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
mCustomView = view;
webView.loadUrl("javascript:(function() { document.body.style.overflowX = 'hidden'; })();");
webView.loadUrl("javascript:(function() { window.scrollTo(0, 0); })();");
drawerLayout.setVisibility(View.GONE);
customViewContainer.setVisibility(View.VISIBLE);
customViewContainer.addView(view);
// Hide the status bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
if (mCustomView == null)
return;
webView.loadUrl("javascript:(function() { window.scrollTo(0, 0); })();");
webView.loadUrl("javascript:(function() { document.body.style.overflowX = 'scroll'; })();");
drawerLayout.setVisibility(View.VISIBLE);
customViewContainer.setVisibility(View.GONE);
mCustomView.setVisibility(View.GONE);
customViewContainer.removeView(mCustomView);
mCustomView = null;
// Show the status bar.
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
// Progressbar
public void onProgressChanged(WebView view, int percentage) {
progress.setVisibility(View.VISIBLE);
progress.setProgress(percentage);
// For more advanced loading status
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
progress.setIndeterminate(percentage == 100);
view.evaluateJavascript("(function() { return document.readyState == \"complete\"; })();",
value -> {
if (value.equals("true")) {
progress.setVisibility(View.INVISIBLE);
} else {
onProgressChanged(webView, 100);
}
});
} else {
if (percentage == 100) {
progress.setVisibility(View.GONE);
}
}
}
}
| 3,397 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
BookmarkManager.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/BookmarkManager.java | package cz.martykan.webtube;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;
import com.google.android.material.navigation.NavigationView;
import android.view.Menu;
import android.webkit.WebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class BookmarkManager {
private List<String> bookmarkUrls;
private List<String> bookmarkTitles;
Context context;
WebView webView;
NavigationView navigationView;
SharedPreferences sp;
public BookmarkManager(Context context, WebView webView) {
this.context = context;
this.webView = webView;
sp = PreferenceManager.getDefaultSharedPreferences(context);
}
public void initializeBookmarks(NavigationView navigationView) {
this.navigationView = navigationView;
bookmarkUrls = new ArrayList<>();
List<String> bookmarkTimelessUrls = new ArrayList<>();
bookmarkTitles = new ArrayList<>();
final Menu menu = navigationView.getMenu();
menu.clear();
String result = sp.getString("bookmarks", "[]");
try {
JSONArray bookmarksArray = new JSONArray(result);
for (int i = 0; i < bookmarksArray.length(); i++) {
JSONObject bookmark = bookmarksArray.getJSONObject(i);
menu.add(bookmark.getString("title")).setIcon(R.drawable.ic_star_grey600_24dp);
bookmarkTitles.add(bookmark.getString("title"));
bookmarkUrls.add(bookmark.getString("url"));
String timeless = bookmark.getString("url");
if (timeless.contains("&t=")) {
timeless = timeless.substring(0, timeless.indexOf("&t="));
}
bookmarkTimelessUrls.add(timeless);
}
} catch (JSONException e) {
e.printStackTrace();
}
try {
String url = webView.getUrl();
if (url.contains("&t=")) {
url = url.substring(0, url.indexOf("&t="));
}
if (url.contains("/results")) {
url = url.replace("+", "%20");
}
if (bookmarkUrls.contains(webView.getUrl())
|| bookmarkTitles.contains(webView.getTitle().replace("'", "\\'"))
|| bookmarkTimelessUrls.contains(url)) {
menu.add(context.getString(R.string.removePage)).setIcon(R.drawable.ic_close_grey600_24dp);
} else {
menu.add(context.getString(R.string.addPage)).setIcon(R.drawable.ic_plus_grey600_24dp);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void addBookmark(String title, String url) {
String result = sp.getString("bookmarks", "[]");
try {
JSONArray bookmarksArray = new JSONArray(result);
bookmarksArray.put(new JSONObject("{'title':'" + title.replace("'", "\\'") + "','url':'" + url + "'}"));
SharedPreferences.Editor editor = sp.edit();
editor.putString("bookmarks", bookmarksArray.toString());
editor.apply();
} catch (JSONException e) {
e.printStackTrace();
}
initializeBookmarks(navigationView);
}
public void removeBookmark(String title) {
String result = sp.getString("bookmarks", "[]");
try {
JSONArray bookmarksArray = new JSONArray(result);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
bookmarksArray.remove(bookmarkTitles.indexOf(title));
} else {
final List<JSONObject> objs = asList(bookmarksArray);
objs.remove(bookmarkTitles.indexOf(title));
final JSONArray out = new JSONArray();
for (final JSONObject obj : objs) {
out.put(obj);
}
bookmarksArray = out;
}
SharedPreferences.Editor editor = sp.edit();
editor.putString("bookmarks", bookmarksArray.toString());
editor.apply();
} catch (JSONException e) {
e.printStackTrace();
}
initializeBookmarks(navigationView);
}
public String getUrl(String title) {
return bookmarkUrls.get(bookmarkTitles.indexOf(title));
}
public static List<JSONObject> asList(final JSONArray ja) {
final int len = ja.length();
final ArrayList<JSONObject> result = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
final JSONObject obj = ja.optJSONObject(i);
if (obj != null) {
result.add(obj);
}
}
return result;
}
}
| 4,901 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
MenuHelper.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/MenuHelper.java | package cz.martykan.webtube;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.ActionMenuView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import info.guardianproject.netcipher.proxy.OrbotHelper;
public class MenuHelper implements ActionMenuView.OnMenuItemClickListener {
Context context;
WebView webView;
TorHelper torHelper;
BackgroundPlayHelper backgroundPlayHelper;
View appWindow;
ActionMenuView actionMenu;
SharedPreferences sp;
DrawerLayout drawerLayout;
View bookmarksPanel;
public static final String PREF_COOKIES_ENABLED = "cookiesEnabled";
public MenuHelper(Context context, WebView webView, TorHelper torHelper, BackgroundPlayHelper backgroundPlayHelper, View appWindow) {
this.context = context;
this.webView = webView;
this.torHelper = torHelper;
this.backgroundPlayHelper = backgroundPlayHelper;
this.appWindow = appWindow;
sp = PreferenceManager.getDefaultSharedPreferences(context);
}
public void homepageTutorial() {
if (!sp.getBoolean("homepageLearned", false)) {
AlertDialog dialog = new AlertDialog.Builder(context).create();
dialog.setTitle(context.getString(R.string.home));
dialog.setMessage(context.getString(R.string.homePageHelp));
dialog.setCancelable(false);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
(dialog1, buttonId) -> {
dialog1.dismiss();
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("homepageLearned", true);
editor.apply();
});
dialog.show();
}
}
public void setUpMenu(final ActionMenuView actionMenu, final DrawerLayout drawerLayout, final View bookmarksPanel) {
this.drawerLayout = drawerLayout;
this.bookmarksPanel = bookmarksPanel;
this.actionMenu = actionMenu;
actionMenu.setOnMenuItemClickListener(this);
// Enable special buttons
Menu menu = actionMenu.getMenu();
PackageManager pm = context.getPackageManager();
menu.findItem(R.id.action_backgroundPlay).setChecked(sp.getBoolean(BackgroundPlayHelper.PREF_BACKGROUND_PLAY_ENABLED, true));
menu.findItem(R.id.action_accept_cookies).setChecked(sp.getBoolean(PREF_COOKIES_ENABLED, true));
// Tor button
if (OrbotHelper.isOrbotInstalled(context.getApplicationContext())) {
menu.findItem(R.id.action_tor)
.setEnabled(true)
.setChecked(sp.getBoolean(TorHelper.PREF_TOR_ENABLED, false));
}
// Add Kodi button
try {
pm.getPackageInfo("org.xbmc.kore", PackageManager.GET_ACTIVITIES);
menu.findItem(R.id.action_cast_to_kodi).setEnabled(true);
} catch (PackageManager.NameNotFoundException e) {
/* Kodi is not installed */
}
}
private void show_noVideo_dialog() {
AlertDialog dialog = new AlertDialog.Builder(context/**/).create();
dialog.setTitle(context.getString(R.string.error_no_video));
dialog.setMessage(context.getString(R.string.error_select_video_and_retry));
dialog.setCancelable(true);
dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok).toUpperCase(),
(dialog1, buttonId) -> dialog1.dismiss());
dialog.show();
}
@Override
public boolean onMenuItemClick(final MenuItem item) {
switch (item.getItemId()) {
case R.id.action_web:
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webView.getUrl())));
return true;
case R.id.action_refresh:
webView.reload();
return true;
case R.id.action_home:
homepageTutorial();
webView.loadUrl(sp.getString("homepage", "https://m.youtube.com/"));
return true;
case R.id.action_set_as_home:
Snackbar.make(appWindow, context.getString(R.string.homePageSet), Snackbar.LENGTH_LONG).show();
SharedPreferences.Editor editor = sp.edit();
editor.putString("homepage", webView.getUrl());
editor.apply();
return true;
case R.id.action_bookmarks:
drawerLayout.openDrawer(bookmarksPanel);
return true;
case R.id.action_share:
if (!webView.getUrl().contains("/watch")) {
show_noVideo_dialog();
} else {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
shareIntent.setType("text/plain");
context.startActivity(Intent.createChooser(shareIntent, context.getResources().getText(R.string.share_with)));
}
return true;
case R.id.action_cast_to_kodi:
if (!webView.getUrl().contains("/watch")) {
show_noVideo_dialog();
} else {
try {
/* The following code is based on an extract from the source code of NewPipe (v0.7.2) (https://github.com/theScrabi/NewPipe),
which is also licenced under version 3 of the GNU General Public License as published by the Free Software Foundation.
The copyright owner of the original code is Christian Schabesberger <chris.schabesberger@mailbox.org>.
All modifications were made on 06-Jan-2016 */
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("org.xbmc.kore");
intent.setData(Uri.parse(webView.getUrl().replace("https", "http")));
context.startActivity(intent);
/* End of the modified NewPipe code extract */
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
case R.id.action_backgroundPlay:
if (sp.getBoolean(BackgroundPlayHelper.PREF_BACKGROUND_PLAY_ENABLED, true)) {
backgroundPlayHelper.disableBackgroundPlay();
item.setChecked(false);
} else {
backgroundPlayHelper.enableBackgroundPlay();
item.setChecked(true);
}
return true;
case R.id.action_tor:
final MenuItem cookieItem = actionMenu.getMenu().findItem(R.id.action_accept_cookies);
try {
if (sp.getBoolean(TorHelper.PREF_TOR_ENABLED, false)) {
torHelper.torDisable();
item.setChecked(false);
cookieItem.setChecked(sp.getBoolean(PREF_COOKIES_ENABLED, true)).setEnabled(true);
} else {
AlertDialog alert = new AlertDialog.Builder(context).create();
alert.setTitle(context.getString(R.string.enableTor) + "?");
alert.setMessage(context.getString(R.string.torWarning));
alert.setCancelable(false);
alert.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.enable),
(dialog, buttonId) -> {
torHelper.torEnable();
item.setChecked(true);
cookieItem.setChecked(false).setEnabled(false);
});
alert.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel),
(dialog, buttonId) -> item.setChecked(false));
alert.show();
}
} catch (Exception e) {
Log.d("WebTube", e.getMessage());
}
return true;
case R.id.action_download:
if (!webView.getUrl().contains("/watch")) {
show_noVideo_dialog();
} else {
new Downloader(context).download(webView.getUrl());
}
return true;
case R.id.action_accept_cookies:
if (sp.getBoolean(PREF_COOKIES_ENABLED, true)) {
CookieHelper.acceptCookies(webView, false);
CookieHelper.deleteCookies();
item.setChecked(false);
} else {
CookieHelper.acceptCookies(webView, true);
item.setChecked(true);
}
SharedPreferences.Editor spEdit = sp.edit();
spEdit.putBoolean(PREF_COOKIES_ENABLED, !sp.getBoolean(PREF_COOKIES_ENABLED, true));
spEdit.apply();
return true;
}
return false;
}
}
| 9,804 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
MainActivity.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/MainActivity.java | package cz.martykan.webtube;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import com.google.android.material.navigation.NavigationView;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.ActionMenuView;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
private static final String LOG_TAG = "webTube";
private static WebView webView;
String time;
private NavigationView navigationView;
private SharedPreferences sp;
private BroadcastReceiver headSetReceiver;
// For the snackbar with error message
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
webView.loadUrl(sp.getString("homepage", "https://m.youtube.com/"));
}
};
private Context mApplicationContext;
TorHelper torHelper;
BackgroundPlayHelper backgroundPlayHelper;
BookmarkManager bookmarkManager;
MenuHelper menuHelper;
public static void toggleVideo() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript("(function() { return document.getElementsByTagName('video')[0].paused; })();",
value -> {
if (value.equals("true")) {
playVideo();
} else {
pauseVideo();
}
});
} else {
pauseVideo();
}
}
public static void pauseVideo() {
webView.loadUrl("javascript:document.getElementsByTagName('video')[0].pause();");
}
public static void playVideo() {
webView.loadUrl("javascript:document.getElementsByTagName('video')[0].play();");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
mApplicationContext = getApplicationContext();
// Set HW acceleration flags
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
View appWindow = findViewById(R.id.appWindow);
ProgressBar progress = findViewById(R.id.progress);
FrameLayout customViewContainer = findViewById(R.id.customViewContainer);
sp = PreferenceManager.getDefaultSharedPreferences(this);
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.bookmarks_panel);
// Set up media button receiver
((AudioManager) getSystemService(AUDIO_SERVICE)).registerMediaButtonEventReceiver(
new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));
// Set up WebChromeClient
webView.setWebChromeClient(new WebTubeChromeClient(webView, progress, customViewContainer, drawerLayout, getWindow().getDecorView()));
// Set up WebViewClient
webView.setWebViewClient(new WebTubeWebViewClient(this, appWindow, clickListener, findViewById(R.id.statusBarSpace), findViewById(R.id.menu_main)));
// Set up WebView
setUpWebview();
// Initialize bookmarks panel
bookmarkManager = new BookmarkManager(this, webView);
bookmarkManager.initializeBookmarks(navigationView);
drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
bookmarkManager.initializeBookmarks(navigationView);
}
@Override
public void onDrawerOpened(View drawerView) {
bookmarkManager.initializeBookmarks(navigationView);
}
@Override
public void onDrawerClosed(View drawerView) {
/* Nothing */
}
@Override
public void onDrawerStateChanged(int newState) {
/* Nothing */
}
});
navigationView.setNavigationItemSelectedListener(new BookmarkSelectedListener(this, webView, bookmarkManager, drawerLayout));
// Tor
torHelper = new TorHelper(mApplicationContext, webView);
torHelper.setUpTor();
backgroundPlayHelper = new BackgroundPlayHelper(mApplicationContext, webView);
// Menu helper
ActionMenuView actionMenu = findViewById(R.id.menu_main);
menuHelper = new MenuHelper(this, webView, torHelper, backgroundPlayHelper, appWindow);
getMenuInflater().inflate(R.menu.menu_main, actionMenu.getMenu());
menuHelper.setUpMenu(actionMenu, drawerLayout, findViewById(R.id.bookmarks_panel));
actionMenu.setOverflowIcon(getResources().getDrawable(R.drawable.ic_dots_vertical_white_24dp));
// Load the page
if (!loadUrlFromIntent(getIntent())) {
webView.loadUrl(sp.getString("homepage", "https://m.youtube.com/"));
}
//Unplug Headphone detector
headSetReceiver = new HeadSetReceiver();
}
@Override
public void onPause() {
super.onPause();
if (backgroundPlayHelper.isBackgroundPlayEnabled()) {
backgroundPlayHelper.playInBackground();
} else {
pauseVideo();
}
}
@Override
public void onResume() {
super.onResume();
backgroundPlayHelper.hideBackgroundPlaybackNotification();
IntentFilter filter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
registerReceiver(headSetReceiver, filter);
}
@Override
public void onDestroy() {
super.onDestroy();
backgroundPlayHelper.hideBackgroundPlaybackNotification();
((AudioManager) getSystemService(AUDIO_SERVICE)).unregisterMediaButtonEventReceiver(
new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()));
}
@Override
protected void onNewIntent(final Intent intent) {
super.onNewIntent(intent);
loadUrlFromIntent(intent);
}
private boolean loadUrlFromIntent(final Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null) {
final String url = intent.getData().toString();
if (!url.equals(webView.getUrl())) {
webView.loadUrl(url);
}
return true;
} else {
return false;
}
}
public void setUpWebview() {
// To save login info
CookieHelper.acceptCookies(webView, true);
// Some settings
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
webSettings.setAllowFileAccess(false);
webSettings.setDatabaseEnabled(true);
String cachePath = mApplicationContext
.getDir("cache", Context.MODE_PRIVATE).getPath();
webSettings.setAppCachePath(cachePath);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webView.setHorizontalScrollBarEnabled(false);
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
webView.setBackgroundColor(Color.WHITE);
webView.setScrollbarFadingEnabled(true);
webView.setNetworkAvailable(true);
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
finish();
}
}
}
| 8,367 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
HeadSetReceiver.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/HeadSetReceiver.java | package cz.martykan.webtube;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class HeadSetReceiver extends BroadcastReceiver {
private boolean headphonePlug = false;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
switch (state) {
case 0:
if (headphonePlug) {
MainActivity.pauseVideo();
headphonePlug = false;
}
Log.i("Value", "Headset unplugged");
break;
case 1:
headphonePlug = true;
Log.i("Value", "Headset plugged");
break;
default:
break;
}
}
}
}
| 992 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
TorHelper.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/TorHelper.java | package cz.martykan.webtube;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.webkit.CookieManager;
import android.webkit.WebView;
import info.guardianproject.netcipher.proxy.OrbotHelper;
import info.guardianproject.netcipher.webkit.WebkitProxy;
public class TorHelper {
public static final String PREF_TOR_ENABLED = "torEnabled";
private static final int PORT_TOR = 8118;
Context mApplicationContext;
WebView webView;
SharedPreferences sp;
public TorHelper(Context mApplicationContext, WebView webView) {
this.mApplicationContext = mApplicationContext;
this.webView = webView;
sp = PreferenceManager.getDefaultSharedPreferences(mApplicationContext);
}
public void setUpTor() {
// Tor
if (OrbotHelper.isOrbotInstalled(mApplicationContext)) {
if (sp.getBoolean(PREF_TOR_ENABLED, false)) {
torEnable();
}
}
}
public void torEnable() {
CookieHelper.acceptCookies(webView, false);
CookieHelper.deleteCookies();
//Make sure that all cookies are really deleted
if (!CookieManager.getInstance().hasCookies()) {
if (!OrbotHelper.isOrbotRunning(mApplicationContext))
OrbotHelper.requestStartTor(mApplicationContext);
try {
WebkitProxy.setProxy(MainActivity.class.getName(), mApplicationContext, null, "localhost", PORT_TOR);
SharedPreferences.Editor spEdit = sp.edit();
spEdit.putBoolean(PREF_TOR_ENABLED, true);
spEdit.apply();
} catch (Exception e) {
e.printStackTrace();
}
}
webView.reload();
}
public void torDisable() {
CookieHelper.deleteCookies();
//Make sure that all cookies are really deleted
if (!CookieManager.getInstance().hasCookies()) {
try {
WebkitProxy.resetProxy(MainActivity.class.getName(), mApplicationContext);
SharedPreferences.Editor spEdit = sp.edit();
spEdit.putBoolean(PREF_TOR_ENABLED, false);
spEdit.apply();
CookieHelper.acceptCookies(webView, true);
} catch (Exception e) {
e.printStackTrace();
}
}
Intent mStartActivity = new Intent(mApplicationContext, MainActivity.class);
PendingIntent mPendingIntent = PendingIntent.getActivity(mApplicationContext, 12374, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) mApplicationContext.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);
}
}
| 2,956 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
BackgroundPlayHelper.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/BackgroundPlayHelper.java | package cz.martykan.webtube;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import androidx.core.app.NotificationCompat;
import android.util.Log;
import android.webkit.WebView;
public class BackgroundPlayHelper {
public static final String PREF_BACKGROUND_PLAY_ENABLED = "backgroundPlayEnabled";
private static final int NOTIFICATION_ID = 1337 - 420 * 69;
Context context;
WebView webView;
SharedPreferences sp;
public BackgroundPlayHelper(Context context, WebView webView) {
this.context = context;
this.webView = webView;
sp = PreferenceManager.getDefaultSharedPreferences(context);
}
public void enableBackgroundPlay() {
SharedPreferences.Editor spedit = sp.edit();
spedit.putBoolean(PREF_BACKGROUND_PLAY_ENABLED, true);
spedit.apply();
}
public void disableBackgroundPlay() {
SharedPreferences.Editor spedit = sp.edit();
spedit.putBoolean(PREF_BACKGROUND_PLAY_ENABLED, false);
spedit.apply();
}
public boolean isBackgroundPlayEnabled() {
return sp.getBoolean(PREF_BACKGROUND_PLAY_ENABLED, true);
}
public void playInBackground() {
try {
if (webView.getUrl().contains("/watch")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript("(function() { if(document.getElementsByTagName('video')[0].paused == false) { return 'playing'; } else { return 'stopped'; } })();", value -> {
Log.i("VALUE", value);
if (value.equals("\"playing\"")) {
showBackgroundPlaybackNotification();
}
});
} else {
showBackgroundPlaybackNotification();
}
}
} catch (Exception e) {
// When the WebView is not loaded, it crashes (but that can be ignored)
e.printStackTrace();
}
}
public void showBackgroundPlaybackNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_headphones_white_24dp)
.setOngoing(true)
.setColor(Color.parseColor("#E62118"))
.addAction(R.drawable.ic_pause_grey600_24dp, "PAUSE", NotificationCloser.getDismissIntent(NOTIFICATION_ID, context))
.setContentTitle(context.getString(R.string.app_name))
.setContentText(webView.getTitle().replace(" - YouTube", ""))
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(
context,
NOTIFICATION_ID,
new Intent(context, MainActivity.class)
.setAction(Intent.ACTION_VIEW)
.setData(Uri.parse(webView.getUrl())),
PendingIntent.FLAG_UPDATE_CURRENT));
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ID, builder.build());
}
public void hideBackgroundPlaybackNotification() {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(NOTIFICATION_ID);
}
}
| 3,686 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
WebTubeWebViewClient.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/WebTubeWebViewClient.java | package cz.martykan.webtube;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar;
import androidx.core.content.ContextCompat;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebTubeWebViewClient extends WebViewClient {
Context context;
View.OnClickListener clickListener;
View appWindow;
View statusBarSpace;
View bottomBar;
public WebTubeWebViewClient(Context context, View appWindow, View.OnClickListener clickListener, View statusBarSpace, View bottomBar) {
this.context = context;
this.clickListener = clickListener;
this.appWindow = appWindow;
this.statusBarSpace = statusBarSpace;
this.bottomBar = bottomBar;
}
// Open links in a browser window (except for sign-in dialogs and YouTube URLs)
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http") && !url.contains("accounts.google.") && !url.contains("youtube.")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
return false;
}
public void onLoadResource(WebView view, String url) {
if (!url.contains(".jpg") && !url.contains(".ico") && !url.contains(".css") && !url.contains(".js") && !url.contains("complete/search")) {
// Remove all iframes (to prevent WebRTC exploits)
view.loadUrl("javascript:(function() {" +
"var iframes = document.getElementsByTagName('iframe');" +
"for(i=0;i<=iframes.length;i++){" +
"if(typeof iframes[0] != 'undefined')" +
"iframes[0].outerHTML = '';" +
"}})()");
// Gets rid of orange outlines
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
String css = "*, *:focus { " +
" outline: none !important; -webkit-tap-highlight-color: rgba(255,255,255,0) !important; -webkit-tap-highlight-color: transparent !important; }" +
" ._mfd { padding-top: 2px !important; } ";
view.loadUrl("javascript:(function() {" +
"if(document.getElementById('webTubeStyle') == null){" +
"var parent = document.getElementsByTagName('head').item(0);" +
"var style = document.createElement('style');" +
"style.id = 'webTubeStyle';" +
"style.type = 'text/css';" +
"style.innerHTML = '" + css + "';" +
"parent.appendChild(style);" +
"}})()");
}
// To adapt the statusbar color
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
statusBarSpace.setVisibility(View.VISIBLE);
view.evaluateJavascript("(function() { if(document.getElementById('player').style.visibility == 'hidden' || document.getElementById('player').innerHTML == '') { return 'not_video'; } else { return 'video'; } })();",
value -> {
int colorId = value.contains("not_video") ? R.color.colorPrimary : R.color.colorWatch;
statusBarSpace.setBackgroundColor(ContextCompat.getColor(context, colorId));
bottomBar.setBackgroundColor(ContextCompat.getColor(context, colorId));
});
}
}
}
// Deal with error messages
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if (description.contains("NETWORK_CHANGED")) {
view.loadUrl(PreferenceManager.getDefaultSharedPreferences(view.getContext()).getString("homepage", "https://m.youtube.com/"));
} else if (description.contains("NAME_NOT_RESOLVED")) {
Snackbar.make(appWindow, context.getString(R.string.errorNoInternet), Snackbar.LENGTH_INDEFINITE).setAction(context.getString(R.string.refresh), clickListener).show();
} else if (description.contains("PROXY_CONNECTION_FAILED")) {
Snackbar.make(appWindow, context.getString(R.string.errorTor), Snackbar.LENGTH_INDEFINITE).setAction(context.getString(R.string.refresh), clickListener).show();
} else {
Snackbar.make(appWindow, context.getString(R.string.error) + " " + description, Snackbar.LENGTH_INDEFINITE).
setAction(context.getString(R.string.refresh), clickListener).show();
}
}
}
| 4,830 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
Downloader.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/Downloader.java | package cz.martykan.webtube;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.net.URLEncoder;
public class Downloader {
Context context;
public Downloader(Context context) {
this.context = context;
}
// Minimal effort solution, to be improved
public void download(String url) {
String encodedURL = url;
try {
encodedURL = URLEncoder.encode(url, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://dirpy.com/studio?url=" + encodedURL)));
}
}
| 669 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
CookieHelper.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/CookieHelper.java | package cz.martykan.webtube;
import android.os.Build;
import android.webkit.CookieManager;
import android.webkit.WebView;
public class CookieHelper {
public static void acceptCookies(WebView webView, boolean accept) {
CookieManager.getInstance().setAcceptCookie(accept);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, accept);
}
}
public static void deleteCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().removeAllCookies(null);
}
CookieManager.getInstance().removeAllCookie();
}
}
| 703 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
BookmarkSelectedListener.java | /FileExtraction/Java_unseen/martykan_webTube/app/src/main/java/cz/martykan/webtube/BookmarkSelectedListener.java | package cz.martykan.webtube;
import android.content.Context;
import android.os.Build;
import com.google.android.material.navigation.NavigationView;
import androidx.drawerlayout.widget.DrawerLayout;
import android.util.Log;
import android.view.MenuItem;
import android.webkit.WebView;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
public class BookmarkSelectedListener implements NavigationView.OnNavigationItemSelectedListener {
WebView webView;
Context context;
String time;
BookmarkManager bookmarkManager;
DrawerLayout drawerLayout;
public BookmarkSelectedListener(Context context, WebView webView, BookmarkManager bookmarkManager, DrawerLayout drawerLayout) {
this.webView = webView;
this.context = context;
this.bookmarkManager = bookmarkManager;
this.drawerLayout = drawerLayout;
}
@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
final String menuItemTitle = menuItem.getTitle().toString();
if (menuItemTitle.equals(context.getString(R.string.addPage))) {
if (!webView.getTitle().equals("YouTube")) {
if (webView.getUrl().contains("/watch") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
time = "0";
webView.evaluateJavascript("(function() { return document.getElementsByTagName('video')[0].currentTime; })();", value -> {
Log.i("VALUE", value);
time = value;
String url = webView.getUrl();
try {
time = time.substring(0, time.indexOf("."));
} catch (Exception e) {
e.printStackTrace();
time = "0";
}
if (url.contains("&t=")) {
url = url.substring(0, url.indexOf("&t="));
}
bookmarkManager.addBookmark(webView.getTitle().replace(" - YouTube", ""), url + "&t=" + time);
});
} else {
bookmarkManager.addBookmark(webView.getTitle().replace(" - YouTube", ""), webView.getUrl());
}
} else if (webView.getUrl().contains("/results")) {
int startPosition = webView.getUrl().indexOf("q=") + "q=".length();
int endPosition = webView.getUrl().indexOf("&", startPosition);
String title = webView.getUrl().substring(startPosition, endPosition);
try {
title = URLDecoder.decode(title, "UTF-8");
} catch (UnsupportedEncodingException e) {
title = URLDecoder.decode(title);
}
bookmarkManager.addBookmark(title + " - Search", webView.getUrl());
}
} else if (menuItemTitle.equals(context.getString(R.string.removePage))) {
if (webView.getUrl().contains("/results")) {
int startPosition = webView.getUrl().indexOf("q=") + "q=".length();
int endPosition = webView.getUrl().indexOf("&", startPosition);
String title = webView.getUrl().substring(startPosition, endPosition);
try {
title = URLDecoder.decode(title, "UTF-8");
} catch (UnsupportedEncodingException e) {
title = URLDecoder.decode(title);
}
bookmarkManager.removeBookmark(title + " - Search");
} else {
try {
bookmarkManager.removeBookmark(webView.getTitle().replace(" - YouTube", ""));
} catch (Exception e) {
// To prevent crashing when page is not loaded
}
}
} else {
webView.loadUrl(bookmarkManager.getUrl(menuItemTitle));
drawerLayout.closeDrawers();
}
return true;
}
}
| 4,057 | Java | .java | martykan/webTube | 96 | 40 | 56 | 2015-12-31T15:05:47Z | 2021-03-28T09:59:24Z |
Attach.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/Attach.java | package io.mvvm.halo.plugins.email;
import lombok.Builder;
import lombok.Data;
import org.springframework.core.io.InputStreamSource;
/**
* Attach.
*
* @author: pan
**/
@Data
@Builder
public class Attach {
/**
* 文件名称(含后缀,例如:xxx.png)
*/
private String name;
/**
* 文件类型(可选)
*/
private String contentType;
/**
* 文件。
* <p>
* 例如读取系统路径文件:{@link org.springframework.core.io.FileSystemResource}
*/
private InputStreamSource source;
}
| 567 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailPublisher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailPublisher.java | package io.mvvm.halo.plugins.email;
/**
* MailPublisher.
*
* @author: pan
**/
public interface MailPublisher {
void publish(MailMessage message);
}
| 159 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailPlugin.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailPlugin.java | package io.mvvm.halo.plugins.email;
import lombok.extern.slf4j.Slf4j;
import org.pf4j.PluginWrapper;
import org.springframework.stereotype.Component;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.plugin.BasePlugin;
/**
* @author guqing
* @since 2.0.0
*/
@Slf4j
@Component
public class MailPlugin extends BasePlugin {
private final ReactiveExtensionClient client;
private final MailWatcher mailWatcher;
public MailPlugin(PluginWrapper wrapper,
ReactiveExtensionClient client,
MailWatcher mailWatcher) {
super(wrapper);
this.client = client;
this.mailWatcher = mailWatcher;
}
@Override
public void start() {
client.watch(mailWatcher);
}
@Override
public void stop() {
}
} | 823 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailSender.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailSender.java | package io.mvvm.halo.plugins.email;
import io.mvvm.halo.plugins.email.support.MailSenderFactory;
import io.mvvm.halo.plugins.email.support.MailServerConfig;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.lang.NonNull;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;
/**
* MailSender.
*
* @author: pan
**/
@Slf4j
public class MailSender {
private final JavaMailSender sender;
private MailSender(JavaMailSender sender) {
this.sender = sender;
}
public static MailSender createSender(MailServerConfig config) {
MailSenderFactory mailSenderFactory = new MailSenderFactory();
JavaMailSender sender = mailSenderFactory.getMailSender(getMailProperties(config));
return new MailSender(sender);
}
@NonNull
private static synchronized MailProperties getMailProperties(MailServerConfig config) {
MailProperties mailProperties = new MailProperties();
mailProperties.setHost(config.getHost());
mailProperties.setPort(config.getPort());
mailProperties.setUsername(config.getUsername());
mailProperties.setPassword(config.getPassword());
mailProperties.setProtocol(config.getProtocol());
if (config.isEnableTls()) {
mailProperties.getProperties().put("mail.smtp.starttls.enable", "true");
mailProperties.getProperties().put("mail.smtp.auth", "true");
}
return mailProperties;
}
public boolean testConnection() {
try {
if (sender instanceof JavaMailSenderImpl mailSender) {
mailSender.testConnection();
log.debug("连接初始化成功: {}", this.sender);
}
return Boolean.TRUE;
} catch (Exception ex) {
log.error("连接初始化失败: {}", ex.getMessage(), ex);
throw new RuntimeException(ex);
}
}
public Boolean send(MailMessage message) {
if (!message.checkParams()) {
return Boolean.FALSE;
}
log.debug("准备发送邮件: {}", message);
try {
List<Attach> attaches = message.attaches();
MimeMessageHelper messageHelper;
if (null == attaches || attaches.isEmpty()) {
messageHelper = new MimeMessageHelper(sender.createMimeMessage());
} else {
messageHelper = new MimeMessageHelper(sender.createMimeMessage(), true);
attaches.forEach(attach -> {
if (null != attach.getSource()) {
try {
if (StringUtils.hasLength(attach.getContentType())) {
messageHelper.addAttachment(attach.getName(), attach.getSource(), attach.getContentType());
} else {
messageHelper.addAttachment(attach.getName(), attach.getSource());
}
} catch (MessagingException e) {
log.error("邮件添加附件失败, {}", e.getMessage(), e);
throw new RuntimeException(e);
}
}
});
}
// set from-name
messageHelper.setFrom(getFromAddress(sender, message.fromName()));
// handle message set separately
messageHelper.setTo(message.to());
messageHelper.setSubject(message.subject());
messageHelper.setText(message.content(), true);
// get mime message
MimeMessage mimeMessage = messageHelper.getMimeMessage();
// send email
sender.send(mimeMessage);
log.info("Sent an email to [{}] successfully, subject: [{}], sent date: [{}]",
Arrays.toString(mimeMessage.getAllRecipients()),
mimeMessage.getSubject(),
mimeMessage.getSentDate());
return Boolean.TRUE;
} catch (Exception e) {
log.error("邮件发送失败,请检查 SMTP 服务配置是否正确, {}", e.getMessage(), e);
}
return Boolean.FALSE;
}
/**
* Get from-address.
*
* @param javaMailSender java mail sender.
* @return from-name internet address
* @throws UnsupportedEncodingException throws when you give a wrong character encoding
*/
private synchronized InternetAddress getFromAddress(@NonNull JavaMailSender javaMailSender, String fromName)
throws UnsupportedEncodingException {
Assert.notNull(javaMailSender, "Java mail sender must not be null");
if (javaMailSender instanceof JavaMailSenderImpl mailSender) {
// get user name(email)
String username = mailSender.getUsername();
// build internet address
return new InternetAddress(username, fromName, mailSender.getDefaultEncoding());
}
throw new UnsupportedOperationException(
"Unsupported java mail sender: " + javaMailSender.getClass().getName());
}
}
| 5,631 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailWatcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailWatcher.java | package io.mvvm.halo.plugins.email;
import io.mvvm.halo.plugins.email.comment.CommentSender;
import org.springframework.stereotype.Component;
import run.halo.app.core.extension.content.Comment;
import run.halo.app.core.extension.content.Reply;
import run.halo.app.extension.Extension;
import run.halo.app.extension.Watcher;
/**
* MailWatcher.
*
* @author: pan
**/
@Component
public class MailWatcher implements Watcher {
private final CommentSender commentSender;
public MailWatcher(CommentSender commentSender) {
this.commentSender = commentSender;
}
@Override
public void onAdd(Extension extension) {
Watcher.super.onAdd(extension);
if (extension instanceof Comment comment) {
commentSender.pipeline(comment).subscribe();
}
if (extension instanceof Reply reply) {
commentSender.pipeline(reply).subscribe();
}
}
@Override
public void onUpdate(Extension oldExtension, Extension newExtension) {
Watcher.super.onUpdate(oldExtension, newExtension);
// TODO 目前无法在此处感知操作是否是审核通过
// if ("Comment".equals(oldExtension.getKind())) {
// Comment oldComment = JsonUtils.jsonToObject(JsonUtils.objectToJson(oldExtension), Comment.class);
// Comment newComment = JsonUtils.jsonToObject(JsonUtils.objectToJson(newExtension), Comment.class);
// commentSender.pipeline(oldComment, newComment).subscribe();
// } else if ("Reply".equals(oldExtension.getKind())) {
// Reply oldReply = JsonUtils.jsonToObject(JsonUtils.objectToJson(oldExtension), Reply.class);
// Reply newReply = JsonUtils.jsonToObject(JsonUtils.objectToJson(newExtension), Reply.class);
// commentSender.pipeline(oldReply, newReply).subscribe();
// }
}
@Override
public void dispose() {
}
}
| 1,911 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailMessage.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailMessage.java | package io.mvvm.halo.plugins.email;
import io.mvvm.halo.plugins.email.support.SimpleMailMessage;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* Message.
*
* @author: pan
**/
public interface MailMessage {
Pattern EMAIL_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$");
static SimpleMailMessage of(String to) {
return new SimpleMailMessage(to);
}
String to();
String subject();
String content();
String fromName();
default List<Attach> attaches() {
return new ArrayList<>();
}
void setTo(String to);
void setSubject(String subject);
void setContent(String content);
default void addAttachment(Attach attach) {
}
default boolean checkParams() {
return StringUtils.hasLength(to()) && EMAIL_PATTERN.matcher(to()).matches();
}
}
| 967 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailService.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailService.java | package io.mvvm.halo.plugins.email;
import io.mvvm.halo.plugins.email.support.MailServerConfig;
/**
* MailSender.
*
* @author: pan
**/
public interface MailService {
Boolean connection(MailServerConfig config);
boolean send(MailMessage message);
}
| 265 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailHelper.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailHelper.java | package io.mvvm.halo.plugins.email;
import lombok.NonNull;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* MailHelper.
*
* @author: pan
**/
public class MailHelper implements ApplicationContextAware {
private static MailPublisher publisher;
public static void publish(MailMessage message) {
MailHelper.publisher.publish(message);
}
@Override
public void setApplicationContext(@NonNull ApplicationContext ctx) throws BeansException {
MailHelper.publisher = ctx.getBean(MailPublisher.class);
}
}
| 665 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailEndpoint.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailEndpoint.java | package io.mvvm.halo.plugins.email;
import io.mvvm.halo.plugins.email.support.MailEnvironmentFetcher;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
/**
* MailEndpoint.
*
* @author: pan
**/
@Component
public class MailEndpoint {
private final MailService mailService;
private final MailEnvironmentFetcher environmentFetcher;
public MailEndpoint(MailService mailService, MailEnvironmentFetcher environmentFetcher) {
this.mailService = mailService;
this.environmentFetcher = environmentFetcher;
}
@Bean
public RouterFunction<ServerResponse> testConnectionRouter() {
return route(GET("/apis/io.mvvm.halo.plugins.email/testConnection"),
request -> testConnection().flatMap(result -> ServerResponse.ok().bodyValue(result)));
}
Mono<Object> testConnection() {
return environmentFetcher.fetchMailServer()
.switchIfEmpty(Mono.defer(() -> Mono.error(new RuntimeException("暂无配置,请前往插件设置中配置后重试"))))
.flatMap(setting -> {
try {
Boolean connection = mailService.connection(setting);
return Mono.just(connection ? "配置成功" : "配置失败");
} catch (Exception ex) {
return Mono.error(ex);
}
});
}
}
| 1,809 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailConfig.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/MailConfig.java | package io.mvvm.halo.plugins.email;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MailConfig.
*
* @author: pan
**/
@Configuration
public class MailConfig {
@Bean
public MailHelper mailHelper() {
return new MailHelper();
}
}
| 333 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
CommentContext.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/CommentContext.java | package io.mvvm.halo.plugins.email.comment;
import io.mvvm.halo.plugins.email.support.MailServerConfig;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import run.halo.app.core.extension.User;
import run.halo.app.core.extension.content.Comment;
import run.halo.app.core.extension.content.Post;
import run.halo.app.core.extension.content.Reply;
import run.halo.app.extension.Extension;
import run.halo.app.infra.SystemSetting;
/**
* CommentContext.
*
* @author: pan
**/
@Data
@SuperBuilder
public class CommentContext {
private Base base;
private CommentRef commentRef;
private ReplyRef replyRef;
private CommentSubject commentSubject;
public Base getBase() {
if (null == this.base) {
this.base = Base.builder().build();
}
return base;
}
public CommentRef getCommentRef() {
if (null == this.commentRef) {
this.commentRef = CommentRef.builder().build();
}
return commentRef;
}
public ReplyRef getReplyRef() {
if (null == this.replyRef) {
this.replyRef = ReplyRef.builder().build();
}
return replyRef;
}
public CommentSubject getCommentSubject() {
if (null == this.commentSubject) {
this.commentSubject = CommentSubject.builder().build();
}
return commentSubject;
}
@Data
@SuperBuilder
public static class Base {
/**
* 评论系统设置
*/
private SystemSetting.Comment commentSetting;
/**
* 邮件服务器配置
*/
private MailServerConfig serverConfig;
/**
* @return 是否需要审核评论
*/
public boolean requireReviewForNew() {
return null != this.commentSetting
&& Boolean.TRUE.equals(this.commentSetting.getRequireReviewForNew());
}
}
@Data
@SuperBuilder
public static class CommentRef {
/**
* 评论内容
*/
private Comment comment;
/**
* 评论用户
*/
private User owner;
}
@Data
@SuperBuilder
public static class ReplyRef {
/**
* 回复评论
*/
private Reply reply;
/**
* 回复用户
*/
private User owner;
}
@Data
@SuperBuilder
public static class CommentSubject {
/**
* {@link Post#KIND}
* <p>
* {@link run.halo.app.core.extension.content.SinglePage#KIND}
*/
private String kind;
private Extension original;
/**
* 标题
*/
private String title;
/**
* 作者
*/
private User owner;
/**
* 永久链接
*/
private String permalink;
}
}
| 2,884 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
CommentSender.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/CommentSender.java | package io.mvvm.halo.plugins.email.comment;
import io.mvvm.halo.plugins.email.MailHelper;
import io.mvvm.halo.plugins.email.comment.fetcher.BaseFetcher;
import io.mvvm.halo.plugins.email.comment.fetcher.CommentFetcher;
import io.mvvm.halo.plugins.email.comment.fetcher.SenderFetcher;
import io.mvvm.halo.plugins.email.comment.fetcher.SubjectFetcher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.content.Comment;
import run.halo.app.core.extension.content.Reply;
/**
* 新评论发布邮件通知.
*
* @author: pan
**/
@Slf4j
@Component
public class CommentSender {
private final CommentFetcher commentFetcher;
private final BaseFetcher baseFetcher;
private final SubjectFetcher subjectFetcher;
private final SenderFetcher senderFetcher;
public CommentSender(CommentFetcher commentFetcher,
BaseFetcher baseFetcher,
SubjectFetcher subjectFetcher,
SenderFetcher senderFetcher) {
this.commentFetcher = commentFetcher;
this.baseFetcher = baseFetcher;
this.subjectFetcher = subjectFetcher;
this.senderFetcher = senderFetcher;
}
/**
* 新评论.
*/
public Mono<Void> pipeline(Comment comment) {
return Mono.just(CommentContext.builder()
.commentRef(CommentContext.CommentRef.builder().comment(comment).build())
.build())
// 加载基础设置
.flatMap(baseFetcher::fetch)
// 加载评论信息
.flatMap(commentFetcher::fetch)
// 加载评论主题
.flatMap(subjectFetcher::fetch)
// 构建待发送通知列表
.flatMapMany(senderFetcher::fetch)
// 执行发送
.doOnNext(MailHelper::publish)
.then();
}
/**
* 新回复.
*/
public Mono<Void> pipeline(Reply reply) {
return Mono.just(CommentContext.builder()
.replyRef(CommentContext.ReplyRef.builder().reply(reply).build())
.build())
// 加载基础设置
.flatMap(baseFetcher::fetch)
// 加载回复信息
.flatMap(commentFetcher::fetchReply)
// 加载评论信息
.flatMap(commentFetcher::fetch)
// 加载评论主题
.flatMap(subjectFetcher::fetch)
// 构建待发送通知列表
.flatMapMany(senderFetcher::fetch)
// 执行发送
.doOnNext(MailHelper::publish)
.then();
}
//
// /**
// * 评论审核通过
// *
// * @param comment 修改前的评论
// * @param newComment 修改后的评论
// */
// public Mono<Void> pipeline(Comment comment, Comment newComment) {
// // 修改前状态是未审核,修改后状态是已审核才是审核通过
// if (!comment.getSpec().getApproved()
// && newComment.getSpec().getApproved()
// && null == comment.getSpec().getApprovedTime()
// && null != newComment.getSpec().getApprovedTime()) {
// return Mono.just(ReplyCommentContext.builder().comment(newComment).build())
// // 加载评论设置
// .flatMap(pipelines.commentSetting::loader)
// // 加载邮件服务配置
// .flatMap(pipelines.mailServerConfig::loader)
// // 加载评论人
// .flatMap(pipelines.commentUser::loader)
// // 加载评论主题
// .flatMap(pipelines.commentSubject::loader)
// // 通知评论创建人审核通过
// .flatMap(pipelines.commentUserAuditSuccessMailSender::loader)
// // 文章作者通知
// .flatMap(pipelines.commentPostOwnerMailSender::loader)
// .subscribeOn(Schedulers.boundedElastic())
// .then();
// }
// return Mono.empty();
// }
//
// /**
// * 回复审核通过
// *
// * @param reply 修改前的回复
// * @param newReply 修改后的回复
// */
// public Mono<Void> pipeline(Reply reply, Reply newReply) {
// if (!reply.getSpec().getApproved()
// && newReply.getSpec().getApproved()
// && null == reply.getSpec().getApprovedTime()
// && null != newReply.getSpec().getApprovedTime()) {
// return Mono.just(ReplyCommentContext.builder().replyComment(newReply).build())
// // 加载邮件服务配置
// .flatMap(pipelines.mailServerConfig::loader)
// // 加载评论设置
// .flatMap(pipelines.commentSetting::loader)
// // 加载回复人
// .flatMap(pipelines.replyUser::loader)
// // 加载回复的评论
// .flatMap(pipelines.replyTargetComment::loader)
// // 加载评论人
// .flatMap(pipelines.commentUser::loader)
// // 加载评论主题
// .flatMap(pipelines.commentSubject::loader)
// // 通知回复人审核通过
// .flatMap(pipelines.commentUserAuditSuccessMailSender::loader)
// // 评论/回复邮件通知文章作者
// .flatMap(pipelines.commentPostOwnerMailSender::loader)
// // 通知被回复的评论人
// .flatMap(pipelines.replyTargetCommentUserMailSender::loader)
// .subscribeOn(Schedulers.boundedElastic())
// .then();
// }
// return Mono.empty();
// }
}
| 6,027 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
CommentTemplateType.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/CommentTemplateType.java | package io.mvvm.halo.plugins.email.comment;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 评论模板.
*
* @author: pan
**/
@AllArgsConstructor
public enum CommentTemplateType {
/**
* 评论模板
*/
Comment(new MailTemplateDefinition("评论模板", "您的文章有新的评论!", "template/comment.html")),
/**
* 回复模板
*/
Reply(new MailTemplateDefinition("评论回复模板", "您的评论有新的回复!", "template/reply.html")),
/**
* 审核模板
*/
Audit(new MailTemplateDefinition("评论审核模板", "您的博客日志有了新的评论需要审核!", "template/audit.html")),
/**
* 审核通过模板
*/
AuditSuccess(new MailTemplateDefinition("评论审核通过模板", "您的评论审核已通过!", "template/auditSuccess.html")),
// /**
// * 审核拒绝模板
// */
// AuditReject(new MailTemplateDefinition("auditReject", "评论审核拒绝模板", "评论审核拒绝后通知评论评论人")),
;
@Getter
private final MailTemplateDefinition definition;
public record MailTemplateDefinition(String name, String subject, String path) {
}
} | 1,214 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
BaseFetcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/fetcher/BaseFetcher.java | package io.mvvm.halo.plugins.email.comment.fetcher;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import io.mvvm.halo.plugins.email.support.MailEnvironmentFetcher;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
/**
* BaseFetcher.
*
* @author: pan
**/
@Component
public class BaseFetcher {
private final MailEnvironmentFetcher environmentFetcher;
public BaseFetcher(MailEnvironmentFetcher environmentFetcher) {
this.environmentFetcher = environmentFetcher;
}
public Mono<CommentContext> fetch(CommentContext context) {
return environmentFetcher.fetchComment()
.doOnNext(e -> context.getBase().setCommentSetting(e))
.flatMap(e -> environmentFetcher.fetchMailServer()
.switchIfEmpty(Mono.defer(() -> Mono.error(new RuntimeException("暂无邮件服务器配置"))))
.doOnNext(x -> context.getBase().setServerConfig(x)))
.map(e -> context);
}
}
| 1,031 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
SenderFetcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/fetcher/SenderFetcher.java | package io.mvvm.halo.plugins.email.comment.fetcher;
import io.mvvm.halo.plugins.email.MailMessage;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import io.mvvm.halo.plugins.email.comment.CommentTemplateType;
import io.mvvm.halo.plugins.email.support.SimpleMailMessage;
import io.mvvm.halo.plugins.email.template.TemplateResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.User;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* SenderFetcher.
*
* @author: pan
**/
@Slf4j
@Component
public class SenderFetcher {
private final TemplateResolver resolver;
public SenderFetcher(TemplateResolver resolver) {
this.resolver = resolver;
}
public Flux<MailMessage> fetch(CommentContext context) {
Consumer<FluxSink<Mono<MailMessage>>> consumer = sink -> {
// 通知 <管理员审核>
adminReview(context, sink);
// 通知 <文章作者>
subjectAuthor(context, sink);
// 通知 <评论的创建人>
replyComment(context, sink);
sink.complete();
};
return Flux.create(consumer).flatMap(Function.identity());
}
private void adminReview(CommentContext context, FluxSink<Mono<MailMessage>> sink) {
CommentContext.Base base = context.getBase();
log.debug("SenderFetcher.adminReview requireReviewForNew: {}", base.requireReviewForNew());
// 通知 <管理员审核>
if (base.requireReviewForNew()) {
if (StringUtils.hasLength(base.getServerConfig().getAdminMail())) {
log.debug("SenderFetcher.adminReview. 通知管理员邮箱: {}", base.getServerConfig().getAdminMail());
sink.next(resolver.process(CommentTemplateType.Audit.getDefinition().path(), context)
.map(html -> SimpleMailMessage.builder()
.to(base.getServerConfig().getAdminMail())
.content(html)
.subject(CommentTemplateType.Audit.getDefinition().subject())
.fromName(base.getServerConfig().getFromName())
.build()));
}
}
}
private void subjectAuthor(CommentContext context, FluxSink<Mono<MailMessage>> sink) {
// 通知 <文章作者>
CommentContext.Base base = context.getBase();
if (!base.requireReviewForNew()) {
User owner = context.getCommentRef().getOwner();
User subjectOwner = context.getCommentSubject().getOwner();
User replyOwner = context.getReplyRef().getOwner();
if (null == context.getReplyRef().getReply()) {
// 新评论: 主题作者的邮箱 == 评论人的邮箱
if (subjectOwner.getSpec().getEmail().equals(owner.getSpec().getEmail())) {
log.debug("SenderFetcher.subjectAuthor. 通知 <文章作者>. 新评论: 主题作者的邮箱[{}] == 评论人的邮箱[{}].",
subjectOwner.getSpec().getEmail(), owner.getSpec().getEmail());
return;
}
} else {
// 新回复: 主题作者的邮箱 == 回复人的邮箱
if (subjectOwner.getSpec().getEmail().equals(replyOwner.getSpec().getEmail())) {
log.debug("SenderFetcher.subjectAuthor. 通知 <文章作者>. 新回复: 主题作者的邮箱[{}] == 回复人的邮箱[{}]",
subjectOwner.getSpec().getEmail(), owner.getSpec().getEmail());
return;
}
}
log.debug("SenderFetcher.subjectAuthor. 通知 {} 作者: {}",
context.getCommentSubject().getKind(), subjectOwner.getSpec().getEmail());
sink.next(resolver.process(CommentTemplateType.Comment.getDefinition().path(), context)
.map(html -> SimpleMailMessage.builder()
.to(subjectOwner.getSpec().getEmail())
.content(html)
.subject(CommentTemplateType.Comment.getDefinition().subject())
.fromName(base.getServerConfig().getFromName())
.build()));
}
}
private void replyComment(CommentContext context, FluxSink<Mono<MailMessage>> sink) {
// 通知 <评论的创建人>
CommentContext.Base base = context.getBase();
if (!base.requireReviewForNew()) {
User owner = context.getCommentRef().getOwner();
User replyOwner = context.getReplyRef().getOwner();
if (null == replyOwner) {
return;
}
// 评论人邮箱 == 回复人邮箱
if (owner.getSpec().getEmail().equals(replyOwner.getSpec().getEmail())) {
log.debug("SenderFetcher.replyComment. 通知 <评论的创建人>. 新回复: 评论人邮箱[{}] == 回复人邮箱[{}]",
owner.getSpec().getEmail(), replyOwner.getSpec().getEmail());
return;
}
log.debug("SenderFetcher.replyComment. 通知评论人: {}", owner.getSpec().getEmail());
sink.next(resolver.process(CommentTemplateType.Reply.getDefinition().path(), context)
.map(html -> SimpleMailMessage.builder()
.to(owner.getSpec().getEmail())
.content(html)
.subject(CommentTemplateType.Reply.getDefinition().subject())
.fromName(base.getServerConfig().getFromName())
.build()));
}
}
}
| 5,986 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
UserFetcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/fetcher/UserFetcher.java | package io.mvvm.halo.plugins.email.comment.fetcher;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.User;
import run.halo.app.core.extension.content.Comment;
import run.halo.app.extension.ReactiveExtensionClient;
/**
* UserFetcher.
*
* @author: pan
**/
@Component
public class UserFetcher {
private final ReactiveExtensionClient client;
public UserFetcher(ReactiveExtensionClient client) {
this.client = client;
}
public Mono<User> fetch(Comment.CommentOwner owner) {
return buildEmailUser(owner)
.switchIfEmpty(Mono.defer(() -> client.fetch(User.class, owner.getName())));
}
private Mono<User> buildEmailUser(Comment.CommentOwner owner) {
if (!Comment.CommentOwner.KIND_EMAIL.equals(owner.getKind())) {
return Mono.empty();
}
User user = new User();
User.UserSpec spec = new User.UserSpec();
spec.setDisplayName(owner.getDisplayName());
spec.setEmail(owner.getName());
spec.setAvatar(owner.getAnnotation(Comment.CommentOwner.AVATAR_ANNO));
user.setSpec(spec);
return Mono.just(user);
}
}
| 1,216 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
ReplyFetcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/fetcher/ReplyFetcher.java | package io.mvvm.halo.plugins.email.comment.fetcher;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.content.Reply;
import run.halo.app.extension.ReactiveExtensionClient;
/**
* ReplyFetcher.
*
* @author: pan
**/
@Component
public class ReplyFetcher {
private final ReactiveExtensionClient client;
private final UserFetcher userFetcher;
public ReplyFetcher(ReactiveExtensionClient client, UserFetcher userFetcher) {
this.client = client;
this.userFetcher = userFetcher;
}
public Mono<CommentContext> fetch(CommentContext context) {
return client.fetch(Reply.class, context.getCommentRef().getComment().getMetadata().getName())
.switchIfEmpty(Mono.defer(() -> Mono.error(new RuntimeException("暂无此评论"))))
.flatMap(reply -> {
context.getReplyRef().setReply(reply);
return userFetcher.fetch(reply.getSpec().getOwner())
.doOnNext(commentUser -> context.getCommentRef().setOwner(commentUser));
})
.map(e -> context);
}
}
| 1,243 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
SubjectFetcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/fetcher/SubjectFetcher.java | package io.mvvm.halo.plugins.email.comment.fetcher;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import io.mvvm.halo.plugins.email.comment.subject.MailCommentSubject;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.halo.app.extension.Ref;
import java.util.List;
/**
* SubjectFetcher.
*
* @author: pan
**/
@Component
public class SubjectFetcher {
private final List<MailCommentSubject> commentSubjects;
public SubjectFetcher(List<MailCommentSubject> commentSubjects) {
this.commentSubjects = commentSubjects;
}
@SuppressWarnings("unchecked")
public Mono<CommentContext> fetch(CommentContext context) {
Ref ref = context.getCommentRef().getComment().getSpec().getSubjectRef();
return commentSubjects.stream()
.filter(commentSubject -> commentSubject.supports(ref))
.findFirst()
.map(commentSubject -> commentSubject.get(context))
.orElseGet(Mono::empty)
.thenReturn(context);
}
}
| 1,078 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
CommentFetcher.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/fetcher/CommentFetcher.java | package io.mvvm.halo.plugins.email.comment.fetcher;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.content.Comment;
import run.halo.app.core.extension.content.Reply;
import run.halo.app.extension.Metadata;
import run.halo.app.extension.ReactiveExtensionClient;
/**
* CommentFetcher.
*
* @author: pan
**/
@Component
public class CommentFetcher {
private final ReactiveExtensionClient client;
private final UserFetcher userFetcher;
public CommentFetcher(ReactiveExtensionClient client, UserFetcher userFetcher) {
this.client = client;
this.userFetcher = userFetcher;
}
public Mono<CommentContext> fetch(CommentContext context) {
if (null != context.getReplyRef().getReply()) {
Comment comment = new Comment();
Metadata metadata = new Metadata();
metadata.setName(context.getReplyRef().getReply().getSpec().getCommentName());
comment.setMetadata(metadata);
context.getCommentRef().setComment(comment);
}
if (null == context.getCommentRef().getComment()) {
return Mono.error(new RuntimeException("暂无评论内容"));
}
return client.fetch(Comment.class, context.getCommentRef().getComment().getMetadata().getName())
.switchIfEmpty(Mono.defer(() -> Mono.error(new RuntimeException("暂无此评论"))))
.doOnNext(comment -> context.getCommentRef().setComment(comment))
.flatMap(comment -> userFetcher.fetch(comment.getSpec().getOwner())
.doOnNext(commentUser -> context.getCommentRef().setOwner(commentUser)))
.map(e -> context);
}
public Mono<CommentContext> fetchReply(CommentContext context) {
CommentContext.ReplyRef replyRef = context.getReplyRef();
if (null == replyRef.getReply()) {
return Mono.error(new RuntimeException("暂无回复内容"));
}
return client.fetch(Reply.class, replyRef.getReply().getMetadata().getName())
.switchIfEmpty(Mono.defer(() -> Mono.error(new RuntimeException("暂无此回复"))))
.doOnNext(reply -> context.getReplyRef().setReply(reply))
.flatMap(reply -> userFetcher.fetch(reply.getSpec().getOwner())
.doOnNext(replyUser -> context.getReplyRef().setOwner(replyUser)))
.map(e -> context);
}
}
| 2,552 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailCommentSubject.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/subject/MailCommentSubject.java | package io.mvvm.halo.plugins.email.comment.subject;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import org.pf4j.ExtensionPoint;
import reactor.core.publisher.Mono;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.Ref;
/**
* Comment subject.
*
* @author guqing
* @since 2.0.0
*/
public interface MailCommentSubject<T extends AbstractExtension> extends ExtensionPoint {
Mono<T> get(CommentContext context);
boolean supports(Ref ref);
}
| 495 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
PostCommentSubject.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/subject/PostCommentSubject.java | package io.mvvm.halo.plugins.email.comment.subject;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.User;
import run.halo.app.core.extension.content.Post;
import run.halo.app.extension.GroupVersionKind;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.extension.Ref;
/**
* Comment subject for post.
*
* @author guqing
* @since 2.0.0
*/
@Component
public class PostCommentSubject implements MailCommentSubject<Post> {
private final ReactiveExtensionClient client;
public PostCommentSubject(ReactiveExtensionClient client) {
this.client = client;
}
@Override
public Mono<Post> get(CommentContext context) {
Ref ref = context.getCommentRef().getComment().getSpec().getSubjectRef();
return client.fetch(Post.class, ref.getName())
.doOnNext(post -> {
context.getCommentSubject().setKind(Post.KIND);
context.getCommentSubject().setTitle(post.getSpec().getTitle());
context.getCommentSubject().setPermalink(post.getStatus().getPermalink());
context.getCommentSubject().setOriginal(post);
})
.flatMap(post -> client.fetch(User.class, post.getSpec().getOwner())
.doOnNext(user -> context.getCommentSubject().setOwner(user))
.thenReturn(post));
}
@Override
public boolean supports(Ref ref) {
Assert.notNull(ref, "Subject ref must not be null.");
GroupVersionKind groupVersionKind =
new GroupVersionKind(ref.getGroup(), ref.getVersion(), ref.getKind());
return GroupVersionKind.fromExtension(Post.class).equals(groupVersionKind);
}
}
| 1,902 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
SinglePageCommentSubject.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/comment/subject/SinglePageCommentSubject.java | package io.mvvm.halo.plugins.email.comment.subject;
import io.mvvm.halo.plugins.email.comment.CommentContext;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;
import run.halo.app.core.extension.User;
import run.halo.app.core.extension.content.SinglePage;
import run.halo.app.extension.GroupVersionKind;
import run.halo.app.extension.ReactiveExtensionClient;
import run.halo.app.extension.Ref;
/**
* Comment subject for {@link SinglePage}.
*
* @author guqing
* @since 2.0.0
*/
@Component
public class SinglePageCommentSubject implements MailCommentSubject<SinglePage> {
private final ReactiveExtensionClient client;
public SinglePageCommentSubject(ReactiveExtensionClient client) {
this.client = client;
}
@Override
public Mono<SinglePage> get(CommentContext context) {
Ref ref = context.getCommentRef().getComment().getSpec().getSubjectRef();
return client.fetch(SinglePage.class, ref.getName())
.doOnNext(page -> {
context.getCommentSubject().setKind(SinglePage.KIND);
context.getCommentSubject().setTitle(page.getSpec().getTitle());
context.getCommentSubject().setPermalink(page.getStatus().getPermalink());
context.getCommentSubject().setOriginal(page);
})
.flatMap(page -> client.fetch(User.class, page.getSpec().getOwner())
.doOnNext(user -> context.getCommentSubject().setOwner(user))
.thenReturn(page));
}
@Override
public boolean supports(Ref ref) {
Assert.notNull(ref, "Subject ref must not be null.");
GroupVersionKind groupVersionKind =
new GroupVersionKind(ref.getGroup(), ref.getVersion(), ref.getKind());
return GroupVersionKind.fromExtension(SinglePage.class).equals(groupVersionKind);
}
}
| 1,968 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
SimpleMailMessage.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/support/SimpleMailMessage.java | package io.mvvm.halo.plugins.email.support;
import io.mvvm.halo.plugins.email.Attach;
import io.mvvm.halo.plugins.email.MailMessage;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* SimpleMessage.
*
* @author: pan
**/
@Setter
@SuperBuilder
public class SimpleMailMessage implements MailMessage {
private String to;
private String subject;
private String content;
private String fromName;
private List<Attach> attaches;
public SimpleMailMessage(String to) {
this.to = to;
}
@Override
public String to() {
return this.to;
}
@Override
public String subject() {
return this.subject;
}
@Override
public String content() {
return this.content;
}
@Override
public String fromName() {
return this.fromName;
}
@Override
public List<Attach> attaches() {
return this.attaches;
}
@Override
public void addAttachment(Attach attach) {
if (null == this.attaches) {
this.attaches = new ArrayList<>();
}
if (!StringUtils.hasLength(attach.getName())) {
throw new RuntimeException("附件名称不能为空");
}
if (null == attach.getSource()) {
throw new RuntimeException("附件不能为空");
}
this.attaches.add(attach);
}
}
| 1,492 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
MailSenderFactory.java | /FileExtraction/Java_unseen/pannanxu_halo-plugin-email/src/main/java/io/mvvm/halo/plugins/email/support/MailSenderFactory.java | package io.mvvm.halo.plugins.email.support;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.lang.NonNull;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.Properties;
/**
* Java mail sender factory.
*
* @author johnniang
*/
public class MailSenderFactory {
/**
* Get mail sender.
*
* @param mailProperties mail properties must not be null
* @return java mail sender
*/
@NonNull
public JavaMailSender getMailSender(@NonNull MailProperties mailProperties) {
Assert.notNull(mailProperties, "Mail properties must not be null");
// create mail sender
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
// set properties
setProperties(mailSender, mailProperties);
return mailSender;
}
private void setProperties(@NonNull JavaMailSenderImpl mailSender,
@NonNull MailProperties mailProperties) {
mailSender.setHost(mailProperties.getHost());
mailSender.setPort(mailProperties.getPort());
mailSender.setUsername(mailProperties.getUsername());
mailSender.setPassword(mailProperties.getPassword());
mailSender.setProtocol(mailProperties.getProtocol());
mailSender.setDefaultEncoding(mailProperties.getDefaultEncoding().name());
if (!CollectionUtils.isEmpty(mailProperties.getProperties())) {
Properties properties = new Properties();
properties.putAll(mailProperties.getProperties());
mailSender.setJavaMailProperties(properties);
}
}
} | 1,770 | Java | .java | pannanxu/halo-plugin-email | 17 | 0 | 4 | 2022-10-14T12:23:00Z | 2023-03-01T12:22:46Z |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.