This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
4 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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/example/datainsert/exagear/test/LorieView.java
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,51 @@ | ||
package com.example.datainsert.exagear.test; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
import android.util.AttributeSet; | ||
import android.view.SurfaceView; | ||
|
||
public class LorieView extends SurfaceView { | ||
public LorieView(Context context) { | ||
super(context); | ||
} | ||
|
||
public LorieView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public LorieView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public LorieView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
try { | ||
// SharedPreferences sp = getContext().getSharedPreferences("com.eltechs.ed.CONTAINER_CONFIG_0",Context.MODE_PRIVATE); | ||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext()); | ||
String ratioStr = sp.getString("full_screen_with_ratio",""); | ||
if(ratioStr!=null && ratioStr.contains(":") ){ | ||
String[] strings1 = ratioStr.split(":"); | ||
float ratio = Integer.parseInt(strings1[0])*1f/Integer.parseInt(strings1[1]); | ||
int width = MeasureSpec.getSize(widthMeasureSpec); | ||
int height = MeasureSpec.getSize(heightMeasureSpec); | ||
//左右黑边 | ||
if(width*1f/height > ratio){ | ||
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (width/ratio), MeasureSpec.EXACTLY); | ||
} | ||
//上下黑边 | ||
else{ | ||
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) (height*ratio), MeasureSpec.EXACTLY); | ||
} | ||
} | ||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
} | ||
} |
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
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/textView2" | ||
android:layout_width="0dp" | ||
android:layout_height="100dp" | ||
android:text="TextView" | ||
app:layout_constraintDimensionRatio="25:9" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</android.support.constraint.ConstraintLayout> |
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