应用风格架构基本完成

This commit is contained in:
ZhanGSKen
2025-02-12 13:27:37 +08:00
parent 49d300dd33
commit 13510f45cf
14 changed files with 260 additions and 98 deletions

View File

@@ -26,5 +26,7 @@ android {
}
dependencies {
api 'androidx.appcompat:appcompat:1.0.0'
api fileTree(dir: 'libs', include: ['*.jar'])
}

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Tue Feb 11 13:11:17 HKT 2025
#Wed Feb 12 05:28:02 GMT 2025
stageCount=1
libraryProject=libappbase
baseVersion=1.3
publishVersion=1.3.0
buildCount=0
buildCount=41
baseBetaVersion=1.3.1

View File

@@ -21,19 +21,18 @@ import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.R;
import androidx.appcompat.app.AppCompatActivity;
public final class GlobalCrashActivity extends Activity implements MenuItem.OnMenuItemClickListener {
public final class GlobalCrashActivity extends AppCompatActivity implements MenuItem.OnMenuItemClickListener {
private static final int MENUITEM_COPY = 0;
private static final int MENUITEM_RESTART = 1;
GlobalCrashReportView mGlobalCrashReportView;
String mLog;
int colorTittle;
int colorTittleBackground;
int colorText;
int colorTextBackground;
public static final String TAG = "GlobalCrashActivity";
@@ -44,31 +43,14 @@ public final class GlobalCrashActivity extends Activity implements MenuItem.OnMe
mLog = getIntent().getStringExtra(CrashHandler.EXTRA_CRASH_INFO);
//setTheme(android.R.style.Theme_Holo_Light_NoActionBar);
setTheme(R.style.APPBaseTheme);
//setTheme(R.style.APPBaseTheme);
setContentView(R.layout.activity_globalcrash);
TypedArray a = obtainStyledAttributes(R.styleable.GlobalCrashActivity);
colorTittle = a.getColor(R.styleable.GlobalCrashActivity_colorTittle, Color.WHITE);
colorTittleBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTittleBackgound, Color.BLACK);
colorText = a.getColor(R.styleable.GlobalCrashActivity_colorText, Color.RED);
colorTextBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTextBackgound, Color.RED);
// 返回一个绑定资源结束的信号给资源
a.recycle();
LinearLayout llMain = findViewById(R.id.activityglobalcrashLinearLayout1);
llMain.setBackgroundColor(colorTextBackground);
Toolbar toolbar = findViewById(R.id.activityglobalcrashToolbar1);
toolbar.setBackgroundColor(colorTittleBackground);
toolbar.setTitleTextColor(colorTittle);
toolbar.setSubtitleTextColor(colorTittle);
setActionBar(toolbar);
TextView tvLog = findViewById(R.id.activityglobalcrashTextView1);
tvLog.setText(mLog);
tvLog.setTextColor(colorText);
tvLog.setBackgroundColor(colorTextBackground);
getActionBar().setTitle(CrashHandler.TITTLE);
getActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
mGlobalCrashReportView = findViewById(R.id.activityglobalcrashGlobalCrashReportView1);
mGlobalCrashReportView.setReport(mLog);
setSupportActionBar(mGlobalCrashReportView.getToolbar());
getSupportActionBar().setTitle(CrashHandler.TITTLE);
getSupportActionBar().setSubtitle(GlobalApplication.getAppName(getApplicationContext()));
}
@Override
@@ -113,15 +95,9 @@ public final class GlobalCrashActivity extends Activity implements MenuItem.OnMe
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, MENUITEM_RESTART, 0, "Restart").setOnMenuItemClickListener(this)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
// 设置菜单文本颜色
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
SpannableString spanString = new SpannableString(item.getTitle().toString());
spanString.setSpan(new ForegroundColorSpan(colorTittle), 0, spanString.length(), 0);
item.setTitle(spanString);
}
// 更新菜单文字风格
mGlobalCrashReportView.updateMenuStyle();
return true;
}

View File

@@ -0,0 +1,138 @@
package cc.winboll.studio.libappbase;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/02/11 20:18:30
* @Describe 应用崩溃报告视图
*/
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.R;
public class GlobalCrashReportView extends LinearLayout {
public static final String TAG = "GlobalCrashReportView";
Context mContext;
Toolbar mToolbar;
int colorTittle;
int colorTittleBackground;
int colorText;
int colorTextBackground;
TextView mtvReport;
public GlobalCrashReportView(Context context) {
super(context);
mContext = context;
//initView();
}
public GlobalCrashReportView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
initView(attrs);
}
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
//initView();
}
public GlobalCrashReportView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mContext = context;
//initView();
}
public void setColorTittle(int colorTittle) {
this.colorTittle = colorTittle;
}
public int getColorTittle() {
return colorTittle;
}
public void setColorTittleBackground(int colorTittleBackground) {
this.colorTittleBackground = colorTittleBackground;
}
public int getColorTittleBackground() {
return colorTittleBackground;
}
public void setColorText(int colorText) {
this.colorText = colorText;
}
public int getColorText() {
return colorText;
}
public void setColorTextBackground(int colorTextBackground) {
this.colorTextBackground = colorTextBackground;
}
public int getColorTextBackground() {
return colorTextBackground;
}
void initView(AttributeSet attrs) {
TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.GlobalCrashActivity, R.attr.themeGlobalCrashActivity, 0);
this.colorTittle = a.getColor(R.styleable.GlobalCrashActivity_colorTittle, Color.WHITE);
this.colorTittleBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTittleBackgound, Color.BLACK);
this.colorText = a.getColor(R.styleable.GlobalCrashActivity_colorText, Color.BLACK);
this.colorTextBackground = a.getColor(R.styleable.GlobalCrashActivity_colorTextBackgound, Color.WHITE);
// 返回一个绑定资源结束的信号给资源
a.recycle();
/*this.colorTittle = Color.WHITE;
this.colorTittleBackground = Color.BLACK;
this.colorText = Color.BLACK;
this.colorTextBackground = Color.WHITE;
*/
inflate(mContext, R.layout.view_globalcrashreport, this);
LinearLayout llMain = findViewById(R.id.viewglobalcrashreportLinearLayout1);
llMain.setBackgroundColor(this.colorTextBackground);
mToolbar = findViewById(R.id.viewglobalcrashreportToolbar1);
mToolbar.setBackgroundColor(this.colorTittleBackground);
mToolbar.setTitleTextColor(this.colorTittle);
mToolbar.setSubtitleTextColor(this.colorTittle);
mtvReport = findViewById(R.id.viewglobalcrashreportTextView1);
mtvReport.setTextColor(this.colorText);
mtvReport.setBackgroundColor(this.colorTextBackground);
}
public void setReport(String report) {
mtvReport.setText(report);
}
public Toolbar getToolbar() {
return mToolbar;
}
//
// 更新菜单文字风格
//
public void updateMenuStyle() {
// 设置菜单文本颜色
Menu menu = mToolbar.getMenu();
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
SpannableString spanString = new SpannableString(item.getTitle().toString());
spanString.setSpan(new ForegroundColorSpan(this.colorTittle), 0, spanString.length(), 0);
item.setTitle(spanString);
}
}
}

View File

@@ -2,35 +2,14 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activityglobalcrashLinearLayout1"
style="@style/APPBaseTheme">
android:layout_height="match_parent">
<android.widget.Toolbar
<cc.winboll.studio.libappbase.GlobalCrashReportView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activityglobalcrashToolbar1"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activityglobalcrashTextView1"
android:background="#FFFFFFFF"/>
</HorizontalScrollView>
</ScrollView>
android:layout_height="match_parent"
android:id="@+id/activityglobalcrashGlobalCrashReportView1"/>
</LinearLayout>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewglobalcrashreportLinearLayout1">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/viewglobalcrashreportToolbar1"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.0">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
android:id="@+id/viewglobalcrashreportTextView1"/>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="globalCrashActivity" format="reference"/>
<attr name="themeGlobalCrashActivity" format="reference"/>
<declare-styleable name="GlobalCrashActivity">
<attr name="colorTittle" format="color" />
@@ -9,4 +9,5 @@
<attr name="colorText" format="color" />
<attr name="colorTextBackgound" format="color" />
</declare-styleable>
</resources>

View File

@@ -1,9 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="APPBaseTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
<style name="APPBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="themeGlobalCrashActivity">@style/GlobalCrashActivityTheme</item>
</style>
<style name="GlobalCrashActivityTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<item name="colorTittle">#FFFFF600</item>
<item name="colorTittleBackgound">#FF00B322</item>
<item name="colorText">#FF00B322</item>
<item name="colorTextBackgound">#FF000000</item>
</style>
</resources>