-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Aftermoon-dev/develop-SimpleView
Manage constructor and change pattern to Singleton
- Loading branch information
Showing
6 changed files
with
168 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
view404/src/main/java/com/bluecat/view404/View404CustomLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.bluecat.view404 | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import kotlinx.android.synthetic.main.view404_customlayout.view.* | ||
|
||
class View404CustomLayout private constructor() { | ||
|
||
private lateinit var layoutInflater: LayoutInflater | ||
private lateinit var customLayout: View | ||
|
||
/** option area */ | ||
var bgColor: Int = R.color.custom_background_default | ||
var errMsg: String = "" | ||
var errImg: Int? = null | ||
|
||
/** Static area */ | ||
companion object { | ||
@SuppressLint("InflateParams") | ||
@JvmStatic | ||
fun getInstance(context: Context) = View404CustomLayout().apply { | ||
layoutInflater = | ||
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater | ||
customLayout = layoutInflater.inflate(R.layout.view404_customlayout, null).apply { | ||
layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.MATCH_PARENT | ||
) | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun getInstance( | ||
context: Context, | ||
bgColor: Int = R.color.custom_background_default, | ||
errMsg: String = "", | ||
errImg: Int? = null | ||
) = getInstance(context).apply { | ||
this.bgColor = bgColor | ||
this.errMsg = errMsg | ||
this.errImg = errImg | ||
} | ||
} | ||
|
||
|
||
fun inflate(): View = customLayout.apply { | ||
setBackgroundColor(bgColor) | ||
errorText.text = errMsg | ||
errImg?.let { errorImage.setImageResource(it) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2019 Team Mulro in BlueCat-Community | ||
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. | ||
--> | ||
|
||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#ffffff"> | ||
|
||
<ImageView | ||
android:id="@+id/errorImage" | ||
android:layout_width="64dp" | ||
android:layout_height="64dp" | ||
android:scaleType="fitXY" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerInParent="true" | ||
android:src="@drawable/ic_error_outline" /> | ||
|
||
<TextView | ||
android:id="@+id/errorText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textAlignment="center" | ||
android:gravity="center" | ||
android:textSize="15sp" | ||
android:textStyle="bold" | ||
android:layout_below="@+id/errorImage" | ||
android:text="Error!" /> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="custom_background_default">#ffffff</color> | ||
|
||
</resources> |